A Discrete-Event Network Simulator
API
dpdk-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 NITK Surathkal
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Harsh Patel <thadodaharsh10@gmail.com>
19  * Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
20  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21  */
22 
23 #ifndef DPDK_NET_DEVICE_H
24 #define DPDK_NET_DEVICE_H
25 
26 #include "fd-net-device.h"
27 
28 #include <rte_ring.h>
29 #include <rte_mempool.h>
30 #include <rte_cycles.h>
31 
32 struct rte_eth_dev_tx_buffer;
33 struct rte_mbuf;
34 
35 namespace ns3
36 {
37 
48 class DpdkNetDevice : public FdNetDevice
49 {
50 public:
55  static TypeId GetTypeId (void);
56 
60  DpdkNetDevice ();
61 
65  ~DpdkNetDevice ();
66 
71  void CheckAllPortsLinkStatus (void);
72 
81  void InitDpdk (int argc, char **argv, std::string dpdkDriver);
82 
88  void SetDeviceName (std::string deviceName);
89 
95  static void SignalHandler (int signum);
96 
100  static int LaunchCore (void *arg);
101 
105  void HandleTx ();
106 
110  void HandleRx ();
111 
116  bool IsLinkUp (void) const;
117 
121  virtual void FreeBuffer (uint8_t* buf);
122 
126  virtual uint8_t* AllocateBuffer (size_t len);
127 
128 protected:
135  ssize_t Write (uint8_t *buffer, size_t length);
136 
140  uint16_t m_portId;
141 
145  std::string m_deviceName;
146 
147 private:
148  void DoFinishStoppingDevice (void);
152  static volatile bool m_forceQuit;
153 
157  struct rte_mempool *m_mempool;
158 
162  struct rte_eth_dev_tx_buffer *m_txBuffer;
163 
167  struct rte_eth_dev_tx_buffer *m_rxBuffer;
168 
173 
178 
182  uint32_t m_maxRxPktBurst;
183 
187  uint32_t m_maxTxPktBurst;
188 
193 
197  uint16_t m_nbRxDesc;
198 
202  uint16_t m_nbTxDesc;
203 };
204 
205 } //
206 
207 #endif /* DPDK_NET_DEVICE_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Time m_txTimeout
The time to wait before transmitting burst from Tx buffer.
struct rte_eth_dev_tx_buffer * m_rxBuffer
Buffer to handle burst reception.
ssize_t Write(uint8_t *buffer, size_t length)
Write packet data to device.
void SetDeviceName(std::string deviceName)
Set device name.
void HandleRx()
Receive packets in burst from the nic to the rx_buffer.
uint16_t m_nbRxDesc
Number of Rx descriptors.
uint16_t m_nbTxDesc
Number of Tx descriptors.
bool IsLinkUp(void) const
Check the status of the link.
static void SignalHandler(int signum)
A signal handler for SIGINT and SIGTERM signals.
uint32_t m_maxRxPktBurst
Size of Rx burst.
DpdkNetDevice()
Constructor for the DpdkNetDevice.
EventId m_txEvent
Event for stale packet transmission.
static volatile bool m_forceQuit
Condition variable for Dpdk to stop.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t m_portId
The port number of the device to be used.
virtual uint8_t * AllocateBuffer(size_t len)
Allocate packet buffer.
static int LaunchCore(void *arg)
A function to handle rx & tx operations.
virtual void FreeBuffer(uint8_t *buf)
Free the given packet buffer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
struct rte_mempool * m_mempool
Packet memory pool.
struct rte_eth_dev_tx_buffer * m_txBuffer
Buffer to handle burst transmission.
void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
~DpdkNetDevice()
Destructor for the DpdkNetDevice.
std::string m_deviceName
The device name;.
An identifier for simulation events.
Definition: event-id.h:53
void CheckAllPortsLinkStatus(void)
Check the link status of all ports in up to 9s and print them finally.
uint32_t m_mempoolCacheSize
Mempool cache size.
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:84
void InitDpdk(int argc, char **argv, std::string dpdkDriver)
Initialize Dpdk.
uint32_t m_maxTxPktBurst
Size of Tx burst.
a unique identifier for an interface.
Definition: type-id.h:58
a NetDevice to read/write network traffic from/into a Dpdk enabled port.
void HandleTx()
Transmit packets in burst from the tx_buffer to the nic.