a NetDevice to read/write network traffic from/into a Dpdk enabled port. More...
#include "dpdk-net-device.h"
Public Member Functions | |
DpdkNetDevice () | |
Constructor for the DpdkNetDevice. | |
~DpdkNetDevice () override | |
Destructor for the DpdkNetDevice. | |
uint8_t * | AllocateBuffer (size_t len) override |
Allocate packet buffer. | |
void | CheckAllPortsLinkStatus () |
Check the link status of all ports in up to 9s and print them finally. | |
void | FreeBuffer (uint8_t *buf) override |
Free the given packet buffer. | |
void | HandleRx () |
Receive packets in burst from the nic to the rx_buffer. | |
void | HandleTx () |
Transmit packets in burst from the tx_buffer to the nic. | |
void | InitDpdk (int argc, char **argv, std::string dpdkDriver) |
Initialize Dpdk. | |
bool | IsLinkUp () const override |
Check the status of the link. | |
void | SetDeviceName (std::string deviceName) |
Set device name. | |
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< Channel > | GetChannel () 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< Node > | GetNode () 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< Object > | GetObject () 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< Object > | GetObject (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. | |
SimpleRefCount & | operator= (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 int | LaunchCore (void *arg) |
A function to handle rx & tx operations. | |
static void | SignalHandler (int signum) |
A signal handler for SIGINT and SIGTERM signals. | |
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. | |
Protected Member Functions | |
ssize_t | Write (uint8_t *buffer, size_t length) override |
Write packet data to device. | |
Protected Member Functions inherited from ns3::FdNetDevice | |
void | DoDispose () override |
Destructor implementation. | |
void | DoInitialize () override |
Method Initialization for start and stop attributes. | |
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 | |
std::string | m_deviceName |
The device name;. | |
uint16_t | m_portId |
The port number of the device to be used. | |
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. | |
Private Member Functions | |
void | DoFinishStoppingDevice () override |
Complete additional actions, if any, to tear down the device. | |
Private Attributes | |
uint32_t | m_maxRxPktBurst |
Size of Rx burst. | |
uint32_t | m_maxTxPktBurst |
Size of Tx burst. | |
struct rte_mempool * | m_mempool |
Packet memory pool. | |
uint32_t | m_mempoolCacheSize |
Mempool cache size. | |
uint16_t | m_nbRxDesc |
Number of Rx descriptors. | |
uint16_t | m_nbTxDesc |
Number of Tx descriptors. | |
struct rte_eth_dev_tx_buffer * | m_rxBuffer |
Buffer to handle burst reception. | |
struct rte_eth_dev_tx_buffer * | m_txBuffer |
Buffer to handle burst transmission. | |
EventId | m_txEvent |
Event for stale packet transmission. | |
Time | m_txTimeout |
The time to wait before transmitting burst from Tx buffer. | |
Static Private Attributes | |
static volatile bool | m_forceQuit = false |
Condition variable for Dpdk to stop. | |
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 &, PacketType > | PromiscReceiveCallback |
typedef Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > | ReceiveCallback |
Related Symbols inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
a NetDevice to read/write network traffic from/into a Dpdk enabled port.
A DpdkNetDevice object will read and write frames/packets from/to a Dpdk enabled port.
Definition at line 36 of file dpdk-net-device.h.
ns3::DpdkNetDevice::DpdkNetDevice | ( | ) |
Constructor for the DpdkNetDevice.
Definition at line 83 of file dpdk-net-device.cc.
References NS_LOG_FUNCTION.
|
override |
Destructor for the DpdkNetDevice.
Definition at line 89 of file dpdk-net-device.cc.
References ns3::Simulator::Cancel(), m_forceQuit, m_portId, m_txEvent, and NS_LOG_FUNCTION.
|
overridevirtual |
Allocate packet buffer.
len | the length of the buffer |
Reimplemented from ns3::FdNetDevice.
Definition at line 394 of file dpdk-net-device.cc.
References m_mempool.
void ns3::DpdkNetDevice::CheckAllPortsLinkStatus | ( | ) |
Check the link status of all ports in up to 9s and print them finally.
Definition at line 109 of file dpdk-net-device.cc.
References CHECK_INTERVAL, m_forceQuit, m_portId, MAX_CHECK_TIME, NS_LOG_FUNCTION, and NS_LOG_INFO.
Referenced by InitDpdk().
|
overrideprivatevirtual |
Complete additional actions, if any, to tear down the device.
Reimplemented from ns3::FdNetDevice.
Definition at line 448 of file dpdk-net-device.cc.
References FreeBuffer(), ns3::FdNetDevice::m_pendingQueue, and ns3::FdNetDevice::m_pendingReadMutex.
|
overridevirtual |
Free the given packet buffer.
buf | the pointer to the buffer to be freed |
Reimplemented from ns3::FdNetDevice.
Definition at line 406 of file dpdk-net-device.cc.
Referenced by DoFinishStoppingDevice().
|
static |
Get the type ID.
Definition at line 43 of file dpdk-net-device.cc.
References m_maxRxPktBurst, m_maxTxPktBurst, m_mempoolCacheSize, m_nbRxDesc, m_nbTxDesc, m_txTimeout, ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::MakeUintegerAccessor(), ns3::MakeUintegerChecker(), ns3::MicroSeconds(), and ns3::TypeId::SetParent().
void ns3::DpdkNetDevice::HandleRx | ( | ) |
Receive packets in burst from the nic to the rx_buffer.
Definition at line 188 of file dpdk-net-device.cc.
References m_maxRxPktBurst, m_portId, and m_rxBuffer.
Referenced by LaunchCore().
void ns3::DpdkNetDevice::HandleTx | ( | ) |
Transmit packets in burst from the tx_buffer to the nic.
Definition at line 181 of file dpdk-net-device.cc.
References m_portId, and m_txBuffer.
Referenced by Write().
void ns3::DpdkNetDevice::InitDpdk | ( | int | argc, |
char ** | argv, | ||
std::string | dpdkDriver ) |
Initialize Dpdk.
Initializes EAL.
argc | Dpdk EAL args count. |
argv | Dpdk EAL args list. |
dpdkDriver | Dpdk Driver to bind NIC to. |
Definition at line 238 of file dpdk-net-device.cc.
References CheckAllPortsLinkStatus(), LaunchCore(), m_deviceName, m_forceQuit, m_maxRxPktBurst, m_maxTxPktBurst, m_mempool, m_mempoolCacheSize, m_nbRxDesc, m_nbTxDesc, m_portId, m_rxBuffer, m_txBuffer, NS_LOG_FUNCTION, NS_LOG_INFO, and SignalHandler().
|
overridevirtual |
Check the status of the link.
Implements ns3::NetDevice.
Definition at line 231 of file dpdk-net-device.cc.
|
static |
A function to handle rx & tx operations.
arg | a pointer to the DpdkNetDevice |
Definition at line 212 of file dpdk-net-device.cc.
References HandleRx(), and m_forceQuit.
Referenced by InitDpdk().
void ns3::DpdkNetDevice::SetDeviceName | ( | std::string | deviceName | ) |
Set device name.
deviceName | The device name. |
Definition at line 101 of file dpdk-net-device.cc.
References m_deviceName, and NS_LOG_FUNCTION.
|
static |
A signal handler for SIGINT and SIGTERM signals.
signum | The signal number. |
Definition at line 171 of file dpdk-net-device.cc.
References m_forceQuit, and NS_LOG_INFO.
Referenced by InitDpdk().
|
overrideprotectedvirtual |
Write packet data to device.
buffer | The data. |
length | The data length. |
Reimplemented from ns3::FdNetDevice.
Definition at line 420 of file dpdk-net-device.cc.
References ns3::Simulator::Cancel(), HandleTx(), m_maxTxPktBurst, m_portId, m_txBuffer, m_txEvent, m_txTimeout, NS_LOG_ERROR, and ns3::Simulator::Schedule().
|
protected |
The device name;.
Definition at line 138 of file dpdk-net-device.h.
Referenced by InitDpdk(), and SetDeviceName().
|
staticprivate |
Condition variable for Dpdk to stop.
Definition at line 145 of file dpdk-net-device.h.
Referenced by ~DpdkNetDevice(), CheckAllPortsLinkStatus(), InitDpdk(), LaunchCore(), and SignalHandler().
|
private |
Size of Rx burst.
Definition at line 175 of file dpdk-net-device.h.
Referenced by GetTypeId(), HandleRx(), and InitDpdk().
|
private |
Size of Tx burst.
Definition at line 180 of file dpdk-net-device.h.
Referenced by GetTypeId(), InitDpdk(), and Write().
|
private |
Packet memory pool.
Definition at line 150 of file dpdk-net-device.h.
Referenced by AllocateBuffer(), and InitDpdk().
|
private |
Mempool cache size.
Definition at line 185 of file dpdk-net-device.h.
Referenced by GetTypeId(), and InitDpdk().
|
private |
Number of Rx descriptors.
Definition at line 190 of file dpdk-net-device.h.
Referenced by GetTypeId(), and InitDpdk().
|
private |
Number of Tx descriptors.
Definition at line 195 of file dpdk-net-device.h.
Referenced by GetTypeId(), and InitDpdk().
|
protected |
The port number of the device to be used.
Definition at line 133 of file dpdk-net-device.h.
Referenced by ~DpdkNetDevice(), CheckAllPortsLinkStatus(), HandleRx(), HandleTx(), InitDpdk(), and Write().
|
private |
Buffer to handle burst reception.
Definition at line 160 of file dpdk-net-device.h.
Referenced by HandleRx(), and InitDpdk().
|
private |
Buffer to handle burst transmission.
Definition at line 155 of file dpdk-net-device.h.
Referenced by HandleTx(), InitDpdk(), and Write().
|
private |
Event for stale packet transmission.
Definition at line 165 of file dpdk-net-device.h.
Referenced by ~DpdkNetDevice(), and Write().
|
private |
The time to wait before transmitting burst from Tx buffer.
Definition at line 170 of file dpdk-net-device.h.
Referenced by GetTypeId(), and Write().