A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
netmap-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Pasquale Imputato <p.imputato@gmail.com>
7 */
8
9#ifndef NETMAP_NET_DEVICE_H
10#define NETMAP_NET_DEVICE_H
11
12#include "fd-net-device.h"
13
14#include "ns3/net-device-queue-interface.h"
15
16#include <atomic>
17#include <mutex>
18#include <net/netmap_user.h>
19#include <thread>
20
21namespace ns3
22{
23
24/**
25 * \ingroup fd-net-device
26 *
27 * \brief Network device transmission queue with lock
28 *
29 * This class stores information about a single transmission queue
30 * of a network device that is exposed to queue discs. This class extends
31 * the NetDeviceQueue base class by introducing a lock for methods which
32 * require mutual exclusion on data access in emulation.
33 */
35{
36 public:
37 /**
38 * \brief Get the type ID.
39 * \return the object TypeId
40 */
41 static TypeId GetTypeId();
42
44 virtual ~NetDeviceQueueLock();
45
46 /**
47 * Called by the device to start this device transmission queue.
48 * This is the analogous to the netif_tx_start_queue function of the Linux kernel.
49 */
50 virtual void Start();
51
52 /**
53 * Called by the device to stop this device transmission queue.
54 * This is the analogous to the netif_tx_stop_queue function of the Linux kernel.
55 */
56 virtual void Stop();
57
58 /**
59 * Called by the device to wake the queue disc associated with this
60 * device transmission queue. This is done by invoking the wake callback.
61 * This is the analogous to the netif_tx_wake_queue function of the Linux kernel.
62 */
63 virtual void Wake();
64
65 /**
66 * \brief Get the status of the device transmission queue.
67 * \return true if the device transmission queue is stopped.
68 *
69 * Called by queue discs to enquire about the status of a given transmission queue.
70 * This is the analogous to the netif_xmit_stopped function of the Linux kernel.
71 */
72 virtual bool IsStopped() const;
73
74 /**
75 * \brief Called by the netdevice to report the number of bytes queued to the device queue
76 * \param bytes number of bytes queued to the device queue
77 */
78 virtual void NotifyQueuedBytes(uint32_t bytes);
79
80 /**
81 * \brief Called by the netdevice to report the number of bytes it is going to transmit
82 * \param bytes number of bytes the device is going to transmit
83 */
84 virtual void NotifyTransmittedBytes(uint32_t bytes);
85
86 private:
87 mutable std::mutex m_mutex; //!< Mutex to serialize the operations performed on the queue
88};
89
90/**
91 * \ingroup fd-net-device
92 *
93 * \brief This class performs the actual data reading from the netmap ring.
94 */
96{
97 public:
99
100 /**
101 * \brief Set size of the read buffer.
102 * \param bufferSize the size of the read buffer
103 */
104 void SetBufferSize(uint32_t bufferSize);
105
106 /**
107 * \brief Set netmap interface representation.
108 * \param nifp the netmap interface representation
109 */
110 void SetNetmapIfp(struct netmap_if* nifp);
111
112 private:
114
115 uint32_t m_bufferSize; //!< size of the read buffer
116 struct netmap_if* m_nifp; //!< Netmap interface representation
117};
118
119/**
120 * \ingroup fd-net-device
121 *
122 * \brief a NetDevice to read/write network traffic from/into a netmap file descriptor.
123 *
124 * A NetmapNetDevice object will read and write packets from/to a netmap file descriptor.
125 *
126 */
128{
129 public:
130 /**
131 * \brief Get the type ID.
132 * \return the object TypeId
133 */
134 static TypeId GetTypeId();
135
137 virtual ~NetmapNetDevice();
138
139 /**
140 * \brief Get the number of bytes currently in the netmap transmission ring.
141 * \return the number of bytes in the netmap transmission ring.
142 */
144
145 /**
146 * \brief Get the number of slots currently available in the netmap transmission ring.
147 * \return the number of slots currently available in the netmap transmission ring.
148 */
149 int GetSpaceInNetmapTxRing() const;
150
151 /**
152 * \brief Set the NetDeviceQueue
153 * \param queue the NetDeviceQueue
154 */
156
157 /**
158 * \brief Set the netmap interface representation
159 * \param nifp the pointer to netmap interface representation
160 */
161 void SetNetmapInterfaceRepresentation(struct netmap_if* nifp);
162
163 /**
164 * \brief Set the netmap transmission rings info
165 * \param nTxRings the number of transmission rings
166 * \param nTxRingsSlots the number of slots for each transmission ring
167 */
168 void SetTxRingsInfo(uint32_t nTxRings, uint32_t nTxRingsSlots);
169
170 /**
171 * \brief Set the netmap receiver rings info
172 * \param nRxRings the number of receiver rings
173 * \param nRxRingsSlots the number of slots for each receiver ring
174 */
175 void SetRxRingsInfo(uint32_t nRxRings, uint32_t nRxRingsSlots);
176
177 /**
178 * \brief The function Writes a packet into the netmap transmission ring.
179 * \param buffer the pointer to packet
180 * \param length the packet length
181 * \return the number of written bytes
182 */
183 virtual ssize_t Write(uint8_t* buffer, size_t length);
184
185 private:
189
190 /**
191 * \brief This function syncs netmap ring and notifies netdevice queue.
192 * This function runs in a separate thread.
193 */
194 virtual void SyncAndNotifyQueue();
195
196 struct netmap_if* m_nifp; //!< Netmap interface representation
197 uint32_t m_nTxRings; //!< Number of transmission rings
198 uint32_t m_nTxRingsSlots; //!< Number of slots in the transmission rings
199 uint32_t m_nRxRings; //!< Number of receiver rings
200 uint32_t m_nRxRingsSlots; //!< Number of slots in the receiver rings
201 Ptr<NetDeviceQueue> m_queue; //!< NetDevice queue
202 uint32_t m_totalQueuedBytes; //!< Total queued bytes
203 std::thread m_syncAndNotifyQueueThread; //!< Thread used to perform the flow control
204 std::atomic<bool> m_syncAndNotifyQueueThreadRun; //!< Running flag of the flow control thread
205 uint8_t m_syncAndNotifyQueuePeriod; //!< The period of time in us after which the device syncs
206 //!< the netmap ring and notifies queue status
207};
208
209} // namespace ns3
210
211#endif /* NETMAP_NET_DEVICE_H */
a NetDevice to read/write network traffic from/into a file descriptor.
A class that asynchronously reads from a file descriptor.
Definition fd-reader.h:46
Network device transmission queue.
Network device transmission queue with lock.
virtual void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
virtual void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue.
virtual bool IsStopped() const
Get the status of the device transmission queue.
virtual void Wake()
Called by the device to wake the queue disc associated with this device transmission queue.
std::mutex m_mutex
Mutex to serialize the operations performed on the queue.
static TypeId GetTypeId()
Get the type ID.
virtual void Stop()
Called by the device to stop this device transmission queue.
virtual void Start()
Called by the device to start this device transmission queue.
This class performs the actual data reading from the netmap ring.
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
FdReader::Data DoRead()
The read implementation.
void SetNetmapIfp(struct netmap_if *nifp)
Set netmap interface representation.
struct netmap_if * m_nifp
Netmap interface representation.
uint32_t m_bufferSize
size of the read buffer
a NetDevice to read/write network traffic from/into a netmap file descriptor.
int GetSpaceInNetmapTxRing() const
Get the number of slots currently available in the netmap transmission ring.
uint32_t m_nRxRings
Number of receiver rings.
void SetRxRingsInfo(uint32_t nRxRings, uint32_t nRxRingsSlots)
Set the netmap receiver rings info.
void SetNetmapInterfaceRepresentation(struct netmap_if *nifp)
Set the netmap interface representation.
void DoFinishStoppingDevice()
Complete additional actions, if any, to tear down the device.
Ptr< NetDeviceQueue > m_queue
NetDevice queue.
uint8_t m_syncAndNotifyQueuePeriod
The period of time in us after which the device syncs the netmap ring and notifies queue status.
void DoFinishStartingDevice()
Complete additional actions, if any, to spin up down the device.
virtual ssize_t Write(uint8_t *buffer, size_t length)
The function Writes a packet into the netmap transmission ring.
uint32_t m_nTxRingsSlots
Number of slots in the transmission rings.
uint32_t GetBytesInNetmapTxRing()
Get the number of bytes currently in the netmap transmission ring.
std::thread m_syncAndNotifyQueueThread
Thread used to perform the flow control.
uint32_t m_nRxRingsSlots
Number of slots in the receiver rings.
struct netmap_if * m_nifp
Netmap interface representation.
uint32_t m_nTxRings
Number of transmission rings.
static TypeId GetTypeId()
Get the type ID.
void SetNetDeviceQueue(Ptr< NetDeviceQueue > queue)
Set the NetDeviceQueue.
uint32_t m_totalQueuedBytes
Total queued bytes.
std::atomic< bool > m_syncAndNotifyQueueThreadRun
Running flag of the flow control thread.
Ptr< FdReader > DoCreateFdReader()
Create the FdReader object.
virtual void SyncAndNotifyQueue()
This function syncs netmap ring and notifies netdevice queue.
void SetTxRingsInfo(uint32_t nTxRings, uint32_t nTxRingsSlots)
Set the netmap transmission rings info.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A structure representing data read.
Definition fd-reader.h:80