21#include "ns3/applications-module.h"
22#include "ns3/core-module.h"
23#include "ns3/fd-net-device-module.h"
24#include "ns3/internet-apps-module.h"
25#include "ns3/internet-module.h"
26#include "ns3/ipv4-list-routing-helper.h"
27#include "ns3/ipv4-static-routing-helper.h"
28#include "ns3/network-module.h"
29#include "ns3/traffic-control-module.h"
47 int packets = 10000000;
56 ssize_t len = (size_t)packet->GetSize();
57 auto buffer = (uint8_t*)malloc(len);
58 packet->CopyData(buffer, len);
64 if (emuMode ==
"netmap")
67 ndq = ndqi->GetTxQueue(0);
70 std::cout << ((level == 0) ?
"Writing" :
"Sending") << std::endl;
73 std::chrono::milliseconds period(1000);
75 auto t1 = std::chrono::high_resolution_clock::now();
83 while (ndq->IsStopped())
91 if (!device->SendFrom(packet, sender, receiver, 0))
96 packet->RemoveHeader(header);
101 if (device->Write(buffer, len) != len)
108 auto t2 = std::chrono::high_resolution_clock::now();
110 if (t2 - t1 >= period)
113 std::chrono::duration<double, std::milli> dur = (t2 - t1);
114 double estimatedThr = ((sent - failed) * packetsSize * 8) / 1000000;
115 std::cout << sent <<
" packets sent in " << dur.count() <<
" ms, failed " << failed
116 <<
" (" << estimatedThr <<
" Mbps estimated throughput)" << std::endl;
119 t1 = std::chrono::high_resolution_clock::now();
126main(
int argc,
char* argv[])
128 std::string deviceName(
"eno1");
132 std::string emuMode(
"raw");
134 std::string emuMode(
"netmap");
138 cmd.AddValue(
"deviceName",
"Device name", deviceName);
139 cmd.AddValue(
"level",
"Enable send (1) or write (0) level test", level);
140 cmd.AddValue(
"emuMode",
"Emulation mode in {raw, netmap}", emuMode);
142 cmd.Parse(argc, argv);
156 if (emuMode ==
"raw")
163#ifdef HAVE_NETMAP_USER_H
164 if (emuMode ==
"netmap")
172 if (helper ==
nullptr)
Parse command-line arguments.
build a set of FdNetDevice objects attached to a physical network interface
void SetDeviceName(std::string deviceName)
Set the device name of this device.
build a set of FdNetDevice objects Normally we eschew multiple inheritance, however,...
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
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...
static Mac48Address Allocate()
Allocate a new Mac48Address.
holds a vector of ns3::NetDevice pointers
Network device transmission queue interface.
build a set of FdNetDevice objects attached to a physical network interface
void SetDeviceName(std::string deviceName)
Set the device name of this device.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.