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

Static Public Member Functions

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

Private Member Functions

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

Private Attributes

struct netmap_if * m_nifp
 Netmap interface representation.
 
uint32_t m_nRxRings
 Number of receiver rings.
 
uint32_t m_nRxRingsSlots
 Number of slots in the receiver rings.
 
uint32_t m_nTxRings
 Number of transmission rings.
 
uint32_t m_nTxRingsSlots
 Number of slots in the transmission rings.
 
Ptr< NetDeviceQueuem_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.
 
std::thread m_syncAndNotifyQueueThread
 Thread used to perform the flow control.
 
std::atomic< bool > m_syncAndNotifyQueueThreadRun
 Running flag of the flow control thread.
 
uint32_t m_totalQueuedBytes
 Total queued bytes.
 

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) ()
 TracedCallback signature for link changed event.
 
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 &, 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.
 
void DoDispose () override
 Destructor implementation.
 
void DoInitialize () override
 Method Initialization for start and stop attributes.
 
virtual void FreeBuffer (uint8_t *buf)
 Free the given packet buffer.
 
int GetFileDescriptor () const
 Get the associated file descriptor.
 
void ReceiveCallback (uint8_t *buf, ssize_t len)
 Callback to invoke when a new frame is received.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 
- 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.
 
std::mutex m_pendingReadMutex
 Mutex to increase pending read counter.
 

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 127 of file netmap-net-device.h.

Constructor & Destructor Documentation

◆ NetmapNetDevice()

ns3::NetmapNetDevice::NetmapNetDevice ( )

◆ ~NetmapNetDevice()

ns3::NetmapNetDevice::~NetmapNetDevice ( )
virtual

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

References m_nifp, m_queue, and NS_LOG_FUNCTION.

Member Function Documentation

◆ DoCreateFdReader()

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

Create the FdReader object.

Returns
the created FdReader object

Reimplemented from ns3::FdNetDevice.

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

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

+ Here is the call graph for this function:

◆ DoFinishStartingDevice()

void ns3::NetmapNetDevice::DoFinishStartingDevice ( )
privatevirtual

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

Reimplemented from ns3::FdNetDevice.

Definition at line 213 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 ( )
privatevirtual

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

Reimplemented from ns3::FdNetDevice.

Definition at line 222 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 237 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 296 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 ( )
static

Get the type ID.

Returns
the object TypeId

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

References m_syncAndNotifyQueuePeriod, ns3::MakeUintegerAccessor(), ns3::MakeUintegerChecker(), 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 262 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 270 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 287 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 278 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 308 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 349 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 199 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 200 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 197 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 198 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 205 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 203 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 204 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 202 of file netmap-net-device.h.

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


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