A Discrete-Event Network Simulator
API
dpdk-net-device-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 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  * Authors: Harsh Patel <thadodaharsh10@gmail.com>
19  * Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
20  */
21 
22 #include "dpdk-net-device-helper.h"
23 
24 #include "ns3/dpdk-net-device.h"
25 
26 namespace ns3 {
27 
28 NS_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 
39 void
40 DpdkNetDeviceHelper::SetLCoreList (std::string lCoreList)
41 {
42  m_lCoreList = lCoreList;
43 }
44 
45 void
46 DpdkNetDeviceHelper::SetPmdLibrary (std::string pmdLibrary)
47 {
48  m_pmdLibrary = pmdLibrary;
49 }
50 
51 void
52 DpdkNetDeviceHelper::SetDpdkDriver (std::string dpdkDriver)
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
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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.