22 #include "ns3/system-thread.h" 23 #include "ns3/uinteger.h" 24 #include <sys/ioctl.h> 36 .SetGroupName (
"Network")
97 : m_bufferSize (65536),
126 struct netmap_ring *rxring;
128 uint32_t rxRingIndex = 0;
132 while (rxRingIndex < m_nifp->ni_rx_rings)
134 rxring = NETMAP_RXRING (
m_nifp, rxRingIndex);
136 if (!nm_ring_empty (rxring))
138 uint32_t i = rxring->cur;
139 uint8_t *buffer = (uint8_t *) NETMAP_BUF (rxring, rxring->slot[i].buf_idx);
140 len = rxring->slot[i].len;
141 NS_LOG_DEBUG (
"Received a packet of " << len <<
" bytes");
144 memcpy (buf, buffer, len);
147 rxring->head = rxring->cur = nm_ring_next (rxring, i);
149 ioctl (
m_fd, NIOCRXSYNC, NULL);
174 .SetGroupName (
"FdNetDevice")
176 .AddAttribute (
"SyncAndNotifyQueuePeriod",
177 "The period of time (in number of us) after which the device syncs the netmap ring and notifies queue status.",
180 MakeUintegerChecker<uint8_t> ());
212 fdReader->SetBufferSize (
GetMtu () + 22);
213 fdReader->SetNetmapIfp (
m_nifp);
245 struct netmap_ring *txring;
246 txring = NETMAP_TXRING (
m_nifp, 0);
248 int tail = txring->tail;
253 uint32_t bytesInQueue = 0;
255 for (
int i = 1; i < inQueue; i++)
257 bytesInQueue += txring->slot[tail].len;
304 struct netmap_ring *txring;
305 txring = NETMAP_TXRING (
m_nifp, 0);
307 return nm_ring_space (txring);
316 struct netmap_ring *txring = NETMAP_TXRING (
m_nifp, 0);
318 uint32_t prevTotalTransmittedBytes = 0;
328 uint32_t deltaBytes = totalTransmittedBytes - prevTotalTransmittedBytes;
329 NS_LOG_DEBUG (deltaBytes <<
" delta transmitted bytes");
330 prevTotalTransmittedBytes = totalTransmittedBytes;
333 m_queue->NotifyTransmittedBytes (deltaBytes);
346 NS_LOG_DEBUG (
"Space in the netmap ring of " << nm_ring_space (txring) <<
" packets");
358 struct netmap_ring *txring;
361 txring = NETMAP_TXRING (
m_nifp, 0);
371 if (!nm_ring_empty (txring))
374 uint32_t i = txring->cur;
375 uint8_t *buf = (uint8_t *) NETMAP_BUF (txring, txring->slot[i].buf_idx);
377 memcpy (buf, buffer, length);
378 txring->slot[i].len = length;
380 txring->head = txring->cur = nm_ring_next (txring, i);
386 m_queue->NotifyQueuedBytes (length);
389 if (nm_ring_space (txring) == 0)
struct netmap_if * m_nifp
Netmap interface representation.
int GetSpaceInNetmapTxRing() const
Get the number of slots currently available in the netmap transmission ring.
A structure representing data read.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t m_syncAndNotifyQueuePeriod
The period of time in us after which the device syncs the netmap ring and notifies queue status...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
virtual void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue. ...
virtual ~NetDeviceQueueLock()
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint32_t m_nTxRings
Number of transmission rings.
uint32_t m_nRxRings
Number of receiver rings.
uint32_t GetBytesInNetmapTxRing()
Get the number of bytes currently in the netmap transmission ring.
virtual void SyncAndNotifyQueue()
This function syncs netmap ring and notifies netdevice queue.
std::atomic< bool > m_syncAndNotifyQueueThreadRun
Running flag of the flow control thread.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
uint32_t m_totalQueuedBytes
Total queued bytes.
uint32_t m_bufferSize
size of the read buffer
NetmapNetDeviceFdReader()
Network device transmission queue with lock.
uint32_t m_nRxRingsSlots
Number of slots in the receiver rings.
virtual void Start(void)
Called by the device to start this device transmission queue.
void SetNetmapInterfaceRepresentation(struct netmap_if *nifp)
Set the netmap interface representation.
int m_fd
The file descriptor to read from.
virtual ~NetmapNetDevice()
Hold an unsigned integer type.
struct netmap_if * m_nifp
Netmap interface representation.
virtual void Stop(void)
Called by the device to stop this device transmission queue.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
void SetNetmapIfp(struct netmap_if *nifp)
Set netmap interface representation.
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
virtual void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue. ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Stop(void)
Called by the device to stop this device transmission queue.
virtual void Start(void)
Called by the device to start this device transmission queue.
virtual uint16_t GetMtu(void) const
Ptr< NetDeviceQueue > m_queue
NetDevice queue.
int GetFileDescriptor(void) const
Get the associated file descriptor.
virtual void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
virtual void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
Ptr< SystemThread > m_syncAndNotifyQueueThread
Thread used to perform the flow control.
void DoFinishStartingDevice(void)
Complete additional actions, if any, to spin up down the device.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue...
Ptr< FdReader > DoCreateFdReader(void)
Create the FdReader object.
virtual ssize_t Write(uint8_t *buffer, size_t length)
The function Writes a packet into the netmap transmission ring.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
FdReader::Data DoRead(void)
The read implementation.
uint32_t m_nTxRingsSlots
Number of slots in the transmission rings.
void SetNetDeviceQueue(Ptr< NetDeviceQueue > queue)
Set the NetDeviceQueue.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
a NetDevice to read/write network traffic from/into a file descriptor.
static TypeId GetTypeId(void)
Get the type ID.
static TypeId GetTypeId(void)
Get the type ID.
a NetDevice to read/write network traffic from/into a netmap file descriptor.
Network device transmission queue.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void SetTxRingsInfo(uint32_t nTxRings, uint32_t nTxRingsSlots)
Set the netmap transmission rings info.
a unique identifier for an interface.
void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void SetRxRingsInfo(uint32_t nRxRings, uint32_t nRxRingsSlots)
Set the netmap receiver rings info.
std::mutex m_mutex
Mutex to serialize the operations performed on the queue.
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue...