33#include "ns3/core-module.h"
34#include "ns3/internet-module.h"
35#include "ns3/network-module.h"
36#include "ns3/fd-net-device-module.h"
37#include "ns3/internet-apps-module.h"
38#include "ns3/ipv4-static-routing-helper.h"
39#include "ns3/ipv4-list-routing-helper.h"
40#include "ns3/applications-module.h"
41#include "ns3/traffic-control-module.h"
59 int packets = 10000000;
68 ssize_t len = (size_t) packet->
GetSize ();
69 uint8_t *buffer = (uint8_t*)malloc (len);
76 if (emuMode ==
"netmap")
79 ndq = ndqi->GetTxQueue (0);
82 std::cout << ((level == 0) ?
"Writing" :
"Sending") << std::endl;
85 std::chrono::milliseconds period (1000);
87 auto t1 = std::chrono::high_resolution_clock::now ();
95 while (ndq->IsStopped ())
103 if (device->SendFrom (packet, sender, receiver, 0) ==
false)
113 if (device->Write (buffer, len) != len)
120 auto t2 = std::chrono::high_resolution_clock::now ();
122 if (t2 - t1 >= period)
125 std::chrono::duration<double, std::milli> dur = (t2 - t1);
126 double estimatedThr = ((sent - failed) * packetsSize * 8) / 1000000;
127 std::cout << sent <<
" packets sent in " << dur.count () <<
" ms, failed " << failed <<
" (" << 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);
155 GlobalValue::Bind (
"SimulatorImplementationType",
StringValue (
"ns3::RealtimeSimulatorImpl"));
157 GlobalValue::Bind (
"ChecksumEnabled",
BooleanValue (
true));
167 if (emuMode ==
"raw")
174#ifdef HAVE_NETMAP_USER_H
175 if (emuMode ==
"netmap")
183 if (helper ==
nullptr)
192 Simulator::Schedule (
Seconds (3), &
Send, device, level, emuMode);
195 Simulator::Stop (
Seconds (6.0));
197 Simulator::Destroy ();
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.
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.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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.