A Discrete-Event Network Simulator
API
ns3::NetmapNetDevice Class Reference

a NetDevice to read/write network traffic from/into a netmap file descriptor. More...

#include "netmap-net-device.h"

+ Inheritance diagram for ns3::NetmapNetDevice:
+ Collaboration diagram for ns3::NetmapNetDevice:

Public Member Functions

 NetmapNetDevice ()
 
virtual ~NetmapNetDevice ()
 
uint32_t GetBytesInNetmapTxRing ()
 Get the number of bytes currently in the netmap transmission ring. More...
 
int GetSpaceInNetmapTxRing () const
 Get the number of slots currently available in the netmap transmission ring. More...
 
void SetNetDeviceQueue (Ptr< NetDeviceQueue > queue)
 Set the NetDeviceQueue. More...
 
void SetNetmapInterfaceRepresentation (struct netmap_if *nifp)
 Set the netmap interface representation. More...
 
void SetRxRingsInfo (uint32_t nRxRings, uint32_t nRxRingsSlots)
 Set the netmap receiver rings info. More...
 
void SetTxRingsInfo (uint32_t nTxRings, uint32_t nTxRingsSlots)
 Set the netmap transmission rings info. More...
 
virtual ssize_t Write (uint8_t *buffer, size_t length)
 The function Writes a packet into the netmap transmission ring. More...
 
- Public Member Functions inherited from ns3::FdNetDevice
 FdNetDevice ()
 Constructor for the FdNetDevice. More...
 
 FdNetDevice (FdNetDevice const &)=delete
 
virtual ~FdNetDevice ()
 Destructor for the FdNetDevice. More...
 
virtual void AddLinkChangeCallback (Callback< void > callback)
 
virtual Address GetAddress (void) const
 
virtual Address GetBroadcast (void) const
 
virtual Ptr< ChannelGetChannel (void) const
 
FdNetDevice::EncapsulationMode GetEncapsulationMode (void) const
 Get the link layer encapsulation mode of this device. More...
 
virtual uint32_t GetIfIndex (void) const
 
virtual uint16_t GetMtu (void) const
 
virtual Address GetMulticast (Ipv4Address multicastGroup) const
 Make and return a MAC multicast address using the provided multicast group. More...
 
virtual Address GetMulticast (Ipv6Address addr) const
 Get the MAC multicast address corresponding to the IPv6 address provided. More...
 
virtual Ptr< NodeGetNode (void) const
 
virtual bool IsBridge (void) const
 Return true if the net device is acting as a bridge. More...
 
virtual bool IsBroadcast (void) const
 
virtual bool IsLinkUp (void) const
 
virtual bool IsMulticast (void) const
 
virtual bool IsPointToPoint (void) const
 Return true if the net device is on a point-to-point link. More...
 
virtual bool NeedsArp (void) const
 
virtual bool Send (Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
 
virtual bool SendFrom (Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
 
virtual void SetAddress (Address address)
 Set the address of this interface. More...
 
void SetEncapsulationMode (FdNetDevice::EncapsulationMode mode)
 Set the link layer encapsulation mode of this device. More...
 
void SetFileDescriptor (int fd)
 Set the associated file descriptor. More...
 
virtual void SetIfIndex (const uint32_t index)
 
virtual void SetIsBroadcast (bool broadcast)
 Set if the NetDevice is able to send Broadcast messages. More...
 
virtual void SetIsMulticast (bool multicast)
 Set if the NetDevice is able to send Multicast messages. More...
 
virtual bool SetMtu (const uint16_t mtu)
 
virtual void SetNode (Ptr< Node > node)
 
virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
 
virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb)
 
void Start (Time tStart)
 Set a start time for the device. More...
 
void Stop (Time tStop)
 Set a stop time for the device. More...
 
virtual bool SupportsSendFrom () const
 
- Public Member Functions inherited from ns3::NetDevice
virtual ~NetDevice ()
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose (void)
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator (void) const
 Get an iterator to the Objects aggregated to this one. More...
 
virtual TypeId GetInstanceTypeId (void) const
 Get the most derived TypeId for this Object. More...
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (void) const
 Get a pointer to the requested aggregated Object. More...
 
void Initialize (void)
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized (void) const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o[[maybe_unused]])
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= ([[maybe_unused]] const SimpleRefCount &o)
 Assignment operator. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising erros. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::FdNetDevice
static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::NetDevice
static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId (void)
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId (void)
 Get the type ID. More...
 

Private Member Functions

Ptr< FdReaderDoCreateFdReader (void)
 Create the FdReader object. More...
 
void DoFinishStartingDevice (void)
 Complete additional actions, if any, to spin up down the device. More...
 
void DoFinishStoppingDevice (void)
 Complete additional actions, if any, to tear down the device. More...
 
virtual void SyncAndNotifyQueue ()
 This function syncs netmap ring and notifies netdevice queue. More...
 

Private Attributes

struct netmap_if * m_nifp
 Netmap interface representation. More...
 
uint32_t m_nRxRings
 Number of receiver rings. More...
 
uint32_t m_nRxRingsSlots
 Number of slots in the receiver rings. More...
 
uint32_t m_nTxRings
 Number of transmission rings. More...
 
uint32_t m_nTxRingsSlots
 Number of slots in the transmission rings. More...
 
Ptr< NetDeviceQueuem_queue
 NetDevice queue. More...
 
uint8_t m_syncAndNotifyQueuePeriod
 The period of time in us after which the device syncs the netmap ring and notifies queue status. More...
 
std::thread m_syncAndNotifyQueueThread
 Thread used to perform the flow control. More...
 
std::atomic< bool > m_syncAndNotifyQueueThreadRun
 Running flag of the flow control thread. More...
 
uint32_t m_totalQueuedBytes
 Total queued bytes. More...
 

Additional Inherited Members

- Public Types inherited from ns3::FdNetDevice
enum  EncapsulationMode { DIX , LLC , DIXPI }
 Enumeration of the types of frames supported in the class. More...
 
- Public Types inherited from ns3::NetDevice
typedef void(* LinkChangeTracedCallback) (void)
 TracedCallback signature for link changed event. More...
 
enum  PacketType {
  PACKET_HOST = 1 , NS3_PACKET_HOST = PACKET_HOST , PACKET_BROADCAST , NS3_PACKET_BROADCAST = PACKET_BROADCAST ,
  PACKET_MULTICAST , NS3_PACKET_MULTICAST = PACKET_MULTICAST , PACKET_OTHERHOST , NS3_PACKET_OTHERHOST = PACKET_OTHERHOST
}
 Packet types are used as they are in Linux. More...
 
typedef Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketTypePromiscReceiveCallback
 
typedef Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
 
- Protected Member Functions inherited from ns3::FdNetDevice
virtual uint8_t * AllocateBuffer (size_t len)
 Allocate packet buffer. More...
 
virtual void DoDispose (void)
 Destructor implementation. More...
 
virtual void DoInitialize (void)
 Method Initialization for start and stop attributes. More...
 
virtual void FreeBuffer (uint8_t *buf)
 Free the given packet buffer. More...
 
int GetFileDescriptor (void) const
 Get the associated file descriptor. More...
 
void ReceiveCallback (uint8_t *buf, ssize_t len)
 Callback to invoke when a new frame is received. More...
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object. More...
 
virtual void NotifyNewAggregate (void)
 Notify all Objects aggregated to this one of a new Object being aggregated. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes. More...
 
virtual void NotifyConstructionCompleted (void)
 Notifier called once the ObjectBase is fully constructed. More...
 
- Protected Attributes inherited from ns3::FdNetDevice
std::queue< std::pair< uint8_t *, ssize_t > > m_pendingQueue
 Number of packets that were received and scheduled for read but not yet read. More...
 
std::mutex m_pendingReadMutex
 Mutex to increase pending read counter. More...
 

Detailed Description

a NetDevice to read/write network traffic from/into a netmap file descriptor.

A NetmapNetDevice object will read and write packets from/to a netmap file descriptor.

Definition at line 136 of file netmap-net-device.h.

Constructor & Destructor Documentation

◆ NetmapNetDevice()

ns3::NetmapNetDevice::NetmapNetDevice ( )

◆ ~NetmapNetDevice()

ns3::NetmapNetDevice::~NetmapNetDevice ( )
virtual

Definition at line 197 of file netmap-net-device.cc.

References m_nifp, m_queue, and NS_LOG_FUNCTION.

Member Function Documentation

◆ DoCreateFdReader()

Ptr< FdReader > ns3::NetmapNetDevice::DoCreateFdReader ( void  )
privatevirtual

Create the FdReader object.

Returns
the created FdReader object

Reimplemented from ns3::FdNetDevice.

Definition at line 205 of file netmap-net-device.cc.

References ns3::FdNetDevice::GetMtu(), m_nifp, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DoFinishStartingDevice()

void ns3::NetmapNetDevice::DoFinishStartingDevice ( void  )
privatevirtual

Complete additional actions, if any, to spin up down the device.

Reimplemented from ns3::FdNetDevice.

Definition at line 217 of file netmap-net-device.cc.

References m_syncAndNotifyQueueThread, m_syncAndNotifyQueueThreadRun, NS_LOG_FUNCTION, and SyncAndNotifyQueue().

+ Here is the call graph for this function:

◆ DoFinishStoppingDevice()

void ns3::NetmapNetDevice::DoFinishStoppingDevice ( void  )
privatevirtual

Complete additional actions, if any, to tear down the device.

Reimplemented from ns3::FdNetDevice.

Definition at line 227 of file netmap-net-device.cc.

References m_queue, m_syncAndNotifyQueueThread, m_syncAndNotifyQueueThreadRun, and NS_LOG_FUNCTION.

◆ GetBytesInNetmapTxRing()

uint32_t ns3::NetmapNetDevice::GetBytesInNetmapTxRing ( )

Get the number of bytes currently in the netmap transmission ring.

Returns
the number of bytes in the netmap transmission ring.

Definition at line 242 of file netmap-net-device.cc.

References m_nifp, m_nTxRingsSlots, and NS_LOG_FUNCTION.

Referenced by SyncAndNotifyQueue().

+ Here is the caller graph for this function:

◆ GetSpaceInNetmapTxRing()

int ns3::NetmapNetDevice::GetSpaceInNetmapTxRing ( ) const

Get the number of slots currently available in the netmap transmission ring.

Returns
the number of slots currently available in the netmap transmission ring.

Definition at line 301 of file netmap-net-device.cc.

References m_nifp, and NS_LOG_FUNCTION.

Referenced by SyncAndNotifyQueue().

+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::NetmapNetDevice::GetTypeId ( void  )
static

Get the type ID.

Returns
the object TypeId

Definition at line 170 of file netmap-net-device.cc.

References m_syncAndNotifyQueuePeriod, ns3::MakeUintegerAccessor(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ SetNetDeviceQueue()

void ns3::NetmapNetDevice::SetNetDeviceQueue ( Ptr< NetDeviceQueue queue)

Set the NetDeviceQueue.

Parameters
queuethe NetDeviceQueue

Definition at line 267 of file netmap-net-device.cc.

References m_queue, and NS_LOG_FUNCTION.

◆ SetNetmapInterfaceRepresentation()

void ns3::NetmapNetDevice::SetNetmapInterfaceRepresentation ( struct netmap_if *  nifp)

Set the netmap interface representation.

Parameters
nifpthe pointer to netmap interface representation

Definition at line 275 of file netmap-net-device.cc.

References m_nifp, and NS_LOG_FUNCTION.

◆ SetRxRingsInfo()

void ns3::NetmapNetDevice::SetRxRingsInfo ( uint32_t  nRxRings,
uint32_t  nRxRingsSlots 
)

Set the netmap receiver rings info.

Parameters
nRxRingsthe number of receiver rings
nRxRingsSlotsthe number of slots for each receiver ring

Definition at line 292 of file netmap-net-device.cc.

References m_nRxRings, m_nRxRingsSlots, and NS_LOG_FUNCTION.

◆ SetTxRingsInfo()

void ns3::NetmapNetDevice::SetTxRingsInfo ( uint32_t  nTxRings,
uint32_t  nTxRingsSlots 
)

Set the netmap transmission rings info.

Parameters
nTxRingsthe number of transmission rings
nTxRingsSlotsthe number of slots for each transmission ring

Definition at line 283 of file netmap-net-device.cc.

References m_nTxRings, m_nTxRingsSlots, and NS_LOG_FUNCTION.

◆ SyncAndNotifyQueue()

void ns3::NetmapNetDevice::SyncAndNotifyQueue ( )
privatevirtual

This function syncs netmap ring and notifies netdevice queue.

This function runs in a separate thread.

Definition at line 313 of file netmap-net-device.cc.

References GetBytesInNetmapTxRing(), ns3::FdNetDevice::GetFileDescriptor(), GetSpaceInNetmapTxRing(), m_nifp, m_queue, m_syncAndNotifyQueuePeriod, m_syncAndNotifyQueueThreadRun, m_totalQueuedBytes, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by DoFinishStartingDevice().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Write()

ssize_t ns3::NetmapNetDevice::Write ( uint8_t *  buffer,
size_t  length 
)
virtual

The function Writes a packet into the netmap transmission ring.

Parameters
bufferthe pointer to packet
lengththe packet length
Returns
the number of written bytes

Reimplemented from ns3::FdNetDevice.

Definition at line 355 of file netmap-net-device.cc.

References m_nifp, m_queue, m_totalQueuedBytes, and NS_LOG_FUNCTION.

Member Data Documentation

◆ m_nifp

struct netmap_if* ns3::NetmapNetDevice::m_nifp
private

◆ m_nRxRings

uint32_t ns3::NetmapNetDevice::m_nRxRings
private

Number of receiver rings.

Definition at line 208 of file netmap-net-device.h.

Referenced by NetmapNetDevice(), and SetRxRingsInfo().

◆ m_nRxRingsSlots

uint32_t ns3::NetmapNetDevice::m_nRxRingsSlots
private

Number of slots in the receiver rings.

Definition at line 209 of file netmap-net-device.h.

Referenced by NetmapNetDevice(), and SetRxRingsInfo().

◆ m_nTxRings

uint32_t ns3::NetmapNetDevice::m_nTxRings
private

Number of transmission rings.

Definition at line 206 of file netmap-net-device.h.

Referenced by NetmapNetDevice(), and SetTxRingsInfo().

◆ m_nTxRingsSlots

uint32_t ns3::NetmapNetDevice::m_nTxRingsSlots
private

Number of slots in the transmission rings.

Definition at line 207 of file netmap-net-device.h.

Referenced by NetmapNetDevice(), GetBytesInNetmapTxRing(), and SetTxRingsInfo().

◆ m_queue

Ptr<NetDeviceQueue> ns3::NetmapNetDevice::m_queue
private

◆ m_syncAndNotifyQueuePeriod

uint8_t ns3::NetmapNetDevice::m_syncAndNotifyQueuePeriod
private

The period of time in us after which the device syncs the netmap ring and notifies queue status.

Definition at line 214 of file netmap-net-device.h.

Referenced by GetTypeId(), and SyncAndNotifyQueue().

◆ m_syncAndNotifyQueueThread

std::thread ns3::NetmapNetDevice::m_syncAndNotifyQueueThread
private

Thread used to perform the flow control.

Definition at line 212 of file netmap-net-device.h.

Referenced by DoFinishStartingDevice(), and DoFinishStoppingDevice().

◆ m_syncAndNotifyQueueThreadRun

std::atomic<bool> ns3::NetmapNetDevice::m_syncAndNotifyQueueThreadRun
private

Running flag of the flow control thread.

Definition at line 213 of file netmap-net-device.h.

Referenced by NetmapNetDevice(), DoFinishStartingDevice(), DoFinishStoppingDevice(), and SyncAndNotifyQueue().

◆ m_totalQueuedBytes

uint32_t ns3::NetmapNetDevice::m_totalQueuedBytes
private

Total queued bytes.

Definition at line 211 of file netmap-net-device.h.

Referenced by NetmapNetDevice(), SyncAndNotifyQueue(), and Write().


The documentation for this class was generated from the following files: