A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dpdk-net-device-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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 * Authors: Harsh Patel <thadodaharsh10@gmail.com>
18 * Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
19 */
20
22
23#include "ns3/dpdk-net-device.h"
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("DpdkNetDeviceHelper");
29
31 : m_lCoreList("0,1"),
32 m_pmdLibrary("librte_pmd_e1000.so"),
33 m_dpdkDriver("uio_pci_generic")
34{
35 NS_LOG_FUNCTION(this);
36 SetTypeId("ns3::DpdkNetDevice");
37}
38
39void
41{
42 m_lCoreList = lCoreList;
43}
44
45void
47{
48 m_pmdLibrary = pmdLibrary;
49}
50
51void
53{
54 m_dpdkDriver = dpdkDriver;
55}
56
59{
60 NS_LOG_FUNCTION(this);
62 Ptr<DpdkNetDevice> dpdkDevice = DynamicCast<DpdkNetDevice>(device);
63 dpdkDevice->SetDeviceName(m_deviceName);
64
65 // Set EAL arguments
66 char** ealArgv = new char*[20];
67
68 // arg[0] is program name (optional)
69 ealArgv[0] = new char[20];
70 strcpy(ealArgv[0], "");
71
72 // Logical core usage
73 ealArgv[1] = new char[20];
74 strcpy(ealArgv[1], "-l");
75 ealArgv[2] = new char[20];
76 strcpy(ealArgv[2], m_lCoreList.c_str());
77
78 // Load library
79 ealArgv[3] = new char[20];
80 strcpy(ealArgv[3], "-d");
81 ealArgv[4] = new char[50];
82 strcpy(ealArgv[4], m_pmdLibrary.c_str());
83
84 // Use mempool ring library
85 ealArgv[5] = new char[20];
86 strcpy(ealArgv[5], "-d");
87 ealArgv[6] = new char[50];
88 strcpy(ealArgv[6], "librte_mempool_ring.so");
89
90 dpdkDevice->InitDpdk(7, ealArgv, m_dpdkDriver);
91 return dpdkDevice;
92}
93
94} // namespace ns3
void SetPmdLibrary(std::string pmdLibrary)
Sets PMD Library to be used for the NIC.
std::string m_lCoreList
Logical cores to use.
void SetDpdkDriver(std::string dpdkDriver)
Sets DPDK Driver to bind NIC to.
std::string m_dpdkDriver
DPDK Driver to bind NIC to.
std::string m_pmdLibrary
PMD Library to be used for NIC.
void SetLCoreList(std::string lCoreList)
Sets list of logical cores to use.
Ptr< NetDevice > InstallPriv(Ptr< Node > node) const override
This method creates an ns3::FdNetDevice attached to a physical network interface.
DpdkNetDeviceHelper()
Construct a DpdkNetDeviceHelper and initialize DPDK EAL.
std::string m_deviceName
The Unix/Linux name of the underlying device (e.g., eth0)
virtual Ptr< NetDevice > InstallPriv(Ptr< Node > node) const
This method creates an ns3::FdNetDevice and associates it to a node.
void SetTypeId(std::string type)
Set the TypeId of the Objects to be created by this helper.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.