111 #include "ns3/core-module.h" 112 #include "ns3/network-module.h" 113 #include "ns3/internet-module.h" 114 #include "ns3/applications-module.h" 115 #include "ns3/config-store-module.h" 116 #include "ns3/fd-net-device-module.h" 123 main (
int argc,
char *argv[])
125 uint16_t sinkPort = 8000;
127 std::string dataRate (
"1000Mb/s");
128 bool serverMode =
false;
130 std::string deviceName (
"eth0");
131 std::string client (
"10.1.1.1");
132 std::string server (
"10.1.1.2");
133 std::string netmask (
"255.255.255.0");
134 std::string macClient (
"00:00:00:00:00:01");
135 std::string macServer (
"00:00:00:00:00:02");
136 std::string transportProt =
"Tcp";
137 std::string socketType;
139 std::string emuMode (
"raw");
140 #elif HAVE_NETMAP_USER_H 141 std::string emuMode (
"netmap");
142 #else // HAVE_DPDK_USER_H is true (otherwise this example is not compiled) 143 std::string emuMode (
"dpdk");
147 cmd.AddValue (
"deviceName",
"Device name (in raw, netmap mode) or Device address (in dpdk mode, eg: 0000:00:1f.6). Use `lspci` to find device address.", deviceName);
148 cmd.AddValue (
"client",
"Local IP address (dotted decimal only please)", client);
149 cmd.AddValue (
"server",
"Remote IP address (dotted decimal only please)", server);
150 cmd.AddValue (
"localmask",
"Local mask address (dotted decimal only please)", netmask);
151 cmd.AddValue (
"serverMode",
"1:true, 0:false, default client", serverMode);
152 cmd.AddValue (
"mac-client",
"Mac Address for Server Client : 00:00:00:00:00:01", macClient);
153 cmd.AddValue (
"mac-server",
"Mac Address for Server Default : 00:00:00:00:00:02", macServer);
154 cmd.AddValue (
"data-rate",
"Data rate defaults to 1000Mb/s", dataRate);
155 cmd.AddValue (
"transportProt",
"Transport protocol to use: Tcp, Udp", transportProt);
156 cmd.AddValue (
"emuMode",
"Emulation mode in {raw, netmap}", emuMode);
157 cmd.Parse (argc, argv);
159 if (transportProt.compare (
"Tcp") == 0)
161 socketType =
"ns3::TcpSocketFactory";
165 socketType =
"ns3::UdpSocketFactory";
187 Ipv4Mask localMask (netmask.c_str ());
200 if (emuMode ==
"raw")
207 #ifdef HAVE_NETMAP_USER_H 208 if (emuMode ==
"netmap")
215 #ifdef HAVE_DPDK_USER_H 216 if (emuMode ==
"dpdk")
231 if (helper ==
nullptr)
243 internetStackHelper.
Install (node);
247 uint32_t
interface = ipv4->AddInterface (device);
251 ipv4->
SetUp (interface);
267 onoff.SetAttribute (
"Remote", remoteAddress);
268 onoff.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
269 onoff.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
holds a vector of ns3::Application pointers.
AttributeValue implementation for Boolean.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Hold variables of type string.
a class to represent an Ipv4 address mask
static const uint32_t packetSize
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
build a set of FdNetDevice objects Normally we eschew multiple inheritance, however, the classes PcapUserHelperForDevice and AsciiTraceUserHelperForDevice are treated as "mixins".
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
a polymophic address class
build a DpdkNetDevice object attached to a physical network interface
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
virtual void SetUp(uint32_t interface)=0
Hold an unsigned integer type.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
holds a vector of ns3::NetDevice pointers
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void SetDeviceName(std::string deviceName)
Set the device name of this device.
build a set of FdNetDevice objects attached to a physical network interface
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Ipv4 addresses are stored in host order in this class.
AttributeValue implementation for Address.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
void SetDeviceName(std::string deviceName)
Set the device name of this device.
a class to store IPv4 address information on an interface
AttributeValue implementation for DataRate.
AttributeValue implementation for Mac48Address.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
void SetDpdkDriver(std::string dpdkDriver)
Sets DPDK Driver to bind NIC to.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
void SetPmdLibrary(std::string pmdLibrary)
Sets PMD Library to be used for the NIC.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
build a set of FdNetDevice objects attached to a physical network interface