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
32struct rte_eth_dev_tx_buffer;
33struct rte_mbuf;
34
35namespace ns3
36{
37
49{
50public:
55 static TypeId GetTypeId (void);
56
61
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
102 static int LaunchCore (void *arg);
103
107 void HandleTx ();
108
112 void HandleRx ();
113
118 bool IsLinkUp (void) const;
119
124 virtual void FreeBuffer (uint8_t* buf);
125
131 virtual uint8_t* AllocateBuffer (size_t len);
132
133protected:
140 ssize_t Write (uint8_t *buffer, size_t length);
141
145 uint16_t m_portId;
146
150 std::string m_deviceName;
151
152private:
153 void DoFinishStoppingDevice (void);
157 static volatile bool m_forceQuit;
158
162 struct rte_mempool *m_mempool;
163
167 struct rte_eth_dev_tx_buffer *m_txBuffer;
168
172 struct rte_eth_dev_tx_buffer *m_rxBuffer;
173
178
183
188
193
198
202 uint16_t m_nbRxDesc;
203
207 uint16_t m_nbTxDesc;
208};
209
210} //
211
212#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.
virtual void FreeBuffer(uint8_t *buf)
Free the given packet buffer.
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.
~DpdkNetDevice()
Destructor for the DpdkNetDevice.
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.
EventId m_txEvent
Event for stale packet transmission.
std::string m_deviceName
The device name;.
static volatile bool m_forceQuit
Condition variable for Dpdk to stop.
void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
uint16_t m_nbTxDesc
Number of Tx descriptors.
uint16_t m_nbRxDesc
Number of Rx descriptors.
bool IsLinkUp(void) const
Check the status of the link.
struct rte_mempool * m_mempool
Packet memory pool.
uint16_t m_portId
The port number of the device to be used.
virtual uint8_t * AllocateBuffer(size_t len)
Allocate packet buffer.
DpdkNetDevice()
Constructor for the DpdkNetDevice.
void HandleRx()
Receive packets in burst from the nic to the rx_buffer.
void CheckAllPortsLinkStatus(void)
Check the link status of all ports in up to 9s and print them finally.
Time m_txTimeout
The time to wait before transmitting burst from Tx buffer.
ssize_t Write(uint8_t *buffer, size_t length)
Write packet data to device.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_mempoolCacheSize
Mempool cache size.
An identifier for simulation events.
Definition: event-id.h:54
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:86
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.