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