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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Harsh Patel <thadodaharsh10@gmail.com>
7 * Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 */
10
11#ifndef DPDK_NET_DEVICE_H
12#define DPDK_NET_DEVICE_H
13
14#include "fd-net-device.h"
15
16#include <rte_cycles.h>
17#include <rte_mempool.h>
18#include <rte_ring.h>
19
20struct rte_eth_dev_tx_buffer;
21struct rte_mbuf;
22
23namespace ns3
24{
25
26/**
27 * \ingroup fd-net-device
28 *
29 * \brief a NetDevice to read/write network traffic from/into a
30 * Dpdk enabled port.
31 *
32 * A DpdkNetDevice object will read and write frames/packets
33 * from/to a Dpdk enabled port.
34 *
35 */
37{
38 public:
39 /**
40 * \brief Get the type ID.
41 * \return the object TypeId
42 */
43 static TypeId GetTypeId();
44
45 /**
46 * Constructor for the DpdkNetDevice.
47 */
49
50 /**
51 * Destructor for the DpdkNetDevice.
52 */
53 ~DpdkNetDevice() override;
54
55 /**
56 * Check the link status of all ports in up to 9s
57 * and print them finally
58 */
60
61 /**
62 * Initialize Dpdk.
63 * Initializes EAL.
64 *
65 * \param argc Dpdk EAL args count.
66 * \param argv Dpdk EAL args list.
67 * \param dpdkDriver Dpdk Driver to bind NIC to.
68 */
69 void InitDpdk(int argc, char** argv, std::string dpdkDriver);
70
71 /**
72 * Set device name.
73 *
74 * \param deviceName The device name.
75 */
76 void SetDeviceName(std::string deviceName);
77
78 /**
79 * A signal handler for SIGINT and SIGTERM signals.
80 *
81 * \param signum The signal number.
82 */
83 static void SignalHandler(int signum);
84
85 /**
86 * A function to handle rx & tx operations.
87 * \param arg a pointer to the DpdkNetDevice
88 * \return zero on failure or exit.
89 */
90 static int LaunchCore(void* arg);
91
92 /**
93 * Transmit packets in burst from the tx_buffer to the nic.
94 */
95 void HandleTx();
96
97 /**
98 * Receive packets in burst from the nic to the rx_buffer.
99 */
100 void HandleRx();
101
102 /**
103 * Check the status of the link.
104 * \return Status of the link - up/down as true/false.
105 */
106 bool IsLinkUp() const override;
107
108 /**
109 * Free the given packet buffer.
110 * \param buf the pointer to the buffer to be freed
111 */
112 void FreeBuffer(uint8_t* buf) override;
113
114 /**
115 * Allocate packet buffer.
116 * \param len the length of the buffer
117 * \return A pointer to the newly created buffer.
118 */
119 uint8_t* AllocateBuffer(size_t len) override;
120
121 protected:
122 /**
123 * Write packet data to device.
124 * \param buffer The data.
125 * \param length The data length.
126 * \return The size of data written.
127 */
128 ssize_t Write(uint8_t* buffer, size_t length) override;
129
130 /**
131 * The port number of the device to be used.
132 */
133 uint16_t m_portId;
134
135 /**
136 * The device name;
137 */
138 std::string m_deviceName;
139
140 private:
141 void DoFinishStoppingDevice() override;
142 /**
143 * Condition variable for Dpdk to stop
144 */
145 static volatile bool m_forceQuit;
146
147 /**
148 * Packet memory pool
149 */
150 struct rte_mempool* m_mempool;
151
152 /**
153 * Buffer to handle burst transmission
154 */
155 struct rte_eth_dev_tx_buffer* m_txBuffer;
156
157 /**
158 * Buffer to handle burst reception
159 */
160 struct rte_eth_dev_tx_buffer* m_rxBuffer;
161
162 /**
163 * Event for stale packet transmission
164 */
166
167 /**
168 * The time to wait before transmitting burst from Tx buffer
169 */
171
172 /**
173 * Size of Rx burst
174 */
176
177 /**
178 * Size of Tx burst
179 */
181
182 /**
183 * Mempool cache size
184 */
186
187 /**
188 * Number of Rx descriptors.
189 */
190 uint16_t m_nbRxDesc;
191
192 /**
193 * Number of Tx descriptors.
194 */
195 uint16_t m_nbTxDesc;
196};
197
198} // namespace ns3
199
200#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:45
a NetDevice to read/write network traffic from/into a file descriptor.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.