22 #include "ns3/uinteger.h"
23 #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> ());
211 fdReader->SetBufferSize (
GetMtu () + 22);
212 fdReader->SetNetmapIfp (
m_nifp);
246 struct netmap_ring *txring;
247 txring = NETMAP_TXRING (
m_nifp, 0);
249 int tail = txring->tail;
254 uint32_t bytesInQueue = 0;
256 for (
int i = 1; i < inQueue; i++)
258 bytesInQueue += txring->slot[tail].len;
305 struct netmap_ring *txring;
306 txring = NETMAP_TXRING (
m_nifp, 0);
308 return nm_ring_space (txring);
317 struct netmap_ring *txring = NETMAP_TXRING (
m_nifp, 0);
319 uint32_t prevTotalTransmittedBytes = 0;
329 uint32_t deltaBytes = totalTransmittedBytes - prevTotalTransmittedBytes;
330 NS_LOG_DEBUG (deltaBytes <<
" delta transmitted bytes");
331 prevTotalTransmittedBytes = totalTransmittedBytes;
334 m_queue->NotifyTransmittedBytes (deltaBytes);
347 NS_LOG_DEBUG (
"Space in the netmap ring of " << nm_ring_space (txring) <<
" packets");
359 struct netmap_ring *txring;
362 txring = NETMAP_TXRING (
m_nifp, 0);
372 if (!nm_ring_empty (txring))
375 uint32_t i = txring->cur;
376 uint8_t *buf = (uint8_t *) NETMAP_BUF (txring, txring->slot[i].buf_idx);
378 memcpy (buf, buffer, length);
379 txring->slot[i].len = length;
381 txring->head = txring->cur = nm_ring_next (txring, i);
387 m_queue->NotifyQueuedBytes (length);
390 if (nm_ring_space (txring) == 0)
a NetDevice to read/write network traffic from/into a file descriptor.
virtual uint16_t GetMtu(void) const
int GetFileDescriptor(void) const
Get the associated file descriptor.
int m_fd
The file descriptor to read from.
Network device transmission queue.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue.
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 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.
Network device transmission queue with lock.
static TypeId GetTypeId(void)
Get the type ID.
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.
std::mutex m_mutex
Mutex to serialize the operations performed on the queue.
virtual void Start(void)
Called by the device to start this device transmission queue.
virtual void Stop(void)
Called by the device to stop this device transmission queue.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue.
virtual ~NetDeviceQueueLock()
FdReader::Data DoRead(void)
The read implementation.
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
void SetNetmapIfp(struct netmap_if *nifp)
Set netmap interface representation.
NetmapNetDeviceFdReader()
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.
static TypeId GetTypeId(void)
Get the type ID.
virtual ~NetmapNetDevice()
void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
void SetNetmapInterfaceRepresentation(struct netmap_if *nifp)
Set the netmap interface representation.
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.
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.
void DoFinishStartingDevice(void)
Complete additional actions, if any, to spin up down the device.
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.
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(void)
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.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A structure representing data read.