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
37/**
38 * \ingroup fd-net-device
39 *
40 * \brief a NetDevice to read/write network traffic from/into a
41 * Dpdk enabled port.
42 *
43 * A DpdkNetDevice object will read and write frames/packets
44 * from/to a Dpdk enabled port.
45 *
46 */
48{
49 public:
50 /**
51 * \brief Get the type ID.
52 * \return the object TypeId
53 */
54 static TypeId GetTypeId();
55
56 /**
57 * Constructor for the DpdkNetDevice.
58 */
60
61 /**
62 * Destructor for the DpdkNetDevice.
63 */
64 ~DpdkNetDevice() override;
65
66 /**
67 * Check the link status of all ports in up to 9s
68 * and print them finally
69 */
71
72 /**
73 * Initialize Dpdk.
74 * Initializes EAL.
75 *
76 * \param argc Dpdk EAL args count.
77 * \param argv Dpdk EAL args list.
78 * \param dpdkDriver Dpdk Driver to bind NIC to.
79 */
80 void InitDpdk(int argc, char** argv, std::string dpdkDriver);
81
82 /**
83 * Set device name.
84 *
85 * \param deviceName The device name.
86 */
87 void SetDeviceName(std::string deviceName);
88
89 /**
90 * A signal handler for SIGINT and SIGTERM signals.
91 *
92 * \param signum The signal number.
93 */
94 static void SignalHandler(int signum);
95
96 /**
97 * A function to handle rx & tx operations.
98 * \param arg a pointer to the DpdkNetDevice
99 * \return zero on failure or exit.
100 */
101 static int LaunchCore(void* arg);
102
103 /**
104 * Transmit packets in burst from the tx_buffer to the nic.
105 */
106 void HandleTx();
107
108 /**
109 * Receive packets in burst from the nic to the rx_buffer.
110 */
111 void HandleRx();
112
113 /**
114 * Check the status of the link.
115 * \return Status of the link - up/down as true/false.
116 */
117 bool IsLinkUp() const override;
118
119 /**
120 * Free the given packet buffer.
121 * \param buf the pointer to the buffer to be freed
122 */
123 void FreeBuffer(uint8_t* buf) override;
124
125 /**
126 * Allocate packet buffer.
127 * \param len the length of the buffer
128 * \return A pointer to the newly created buffer.
129 */
130 uint8_t* AllocateBuffer(size_t len) override;
131
132 protected:
133 /**
134 * Write packet data to device.
135 * \param buffer The data.
136 * \param length The data length.
137 * \return The size of data written.
138 */
139 ssize_t Write(uint8_t* buffer, size_t length) override;
140
141 /**
142 * The port number of the device to be used.
143 */
144 uint16_t m_portId;
145
146 /**
147 * The device name;
148 */
149 std::string m_deviceName;
150
151 private:
152 void DoFinishStoppingDevice() override;
153 /**
154 * Condition variable for Dpdk to stop
155 */
156 static volatile bool m_forceQuit;
157
158 /**
159 * Packet memory pool
160 */
161 struct rte_mempool* m_mempool;
162
163 /**
164 * Buffer to handle burst transmission
165 */
166 struct rte_eth_dev_tx_buffer* m_txBuffer;
167
168 /**
169 * Buffer to handle burst reception
170 */
171 struct rte_eth_dev_tx_buffer* m_rxBuffer;
172
173 /**
174 * Event for stale packet transmission
175 */
177
178 /**
179 * The time to wait before transmitting burst from Tx buffer
180 */
182
183 /**
184 * Size of Rx burst
185 */
187
188 /**
189 * Size of Tx burst
190 */
192
193 /**
194 * Mempool cache size
195 */
197
198 /**
199 * Number of Rx descriptors.
200 */
201 uint16_t m_nbRxDesc;
202
203 /**
204 * Number of Tx descriptors.
205 */
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.