32#include "ns3/applications-module.h"
33#include "ns3/core-module.h"
34#include "ns3/fd-net-device-module.h"
35#include "ns3/internet-apps-module.h"
36#include "ns3/internet-module.h"
37#include "ns3/ipv4-list-routing-helper.h"
38#include "ns3/ipv4-static-routing-helper.h"
39#include "ns3/network-module.h"
40#include "ns3/traffic-control-module.h"
58 int packets = 10000000;
67 ssize_t len = (size_t)packet->GetSize();
68 uint8_t* buffer = (uint8_t*)malloc(len);
69 packet->CopyData(buffer, len);
75 if (emuMode ==
"netmap")
78 ndq = ndqi->GetTxQueue(0);
81 std::cout << ((level == 0) ?
"Writing" :
"Sending") << std::endl;
84 std::chrono::milliseconds period(1000);
86 auto t1 = std::chrono::high_resolution_clock::now();
94 while (ndq->IsStopped())
102 if (!device->SendFrom(packet, sender, receiver, 0))
107 packet->RemoveHeader(header);
112 if (device->Write(buffer, len) != len)
119 auto t2 = std::chrono::high_resolution_clock::now();
121 if (t2 - t1 >= period)
124 std::chrono::duration<double, std::milli> dur = (t2 - t1);
125 double estimatedThr = ((sent - failed) * packetsSize * 8) / 1000000;
126 std::cout << sent <<
" packets sent in " << dur.count() <<
" ms, failed " << failed
127 <<
" (" << estimatedThr <<
" Mbps estimated throughput)" << std::endl;
130 t1 = std::chrono::high_resolution_clock::now();
137main(
int argc,
char* argv[])
139 std::string deviceName(
"eno1");
143 std::string emuMode(
"raw");
145 std::string emuMode(
"netmap");
149 cmd.AddValue(
"deviceName",
"Device name", deviceName);
150 cmd.AddValue(
"level",
"Enable send (1) or write (0) level test", level);
151 cmd.AddValue(
"emuMode",
"Emulation mode in {raw, netmap}", emuMode);
153 cmd.Parse(argc, argv);
167 if (emuMode ==
"raw")
174#ifdef HAVE_NETMAP_USER_H
175 if (emuMode ==
"netmap")
183 if (helper ==
nullptr)
AttributeValue implementation for Boolean.
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.
AttributeValue implementation for 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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.