32 #include "ns3/abort.h" 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")
82 std::cout << ((level == 0) ?
"Writing" :
"Sending") << std::endl;
85 std::chrono::milliseconds period (1000);
87 auto t1 = std::chrono::high_resolution_clock::now ();
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 ();
137 main (
int argc,
char *argv[])
139 std::string deviceName (
"eno1");
143 std::string emuMode (
"raw");
144 #else // HAVE_NETMAP_USER_H is true (otherwise this example is not compiled) 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)
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for Boolean.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
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.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
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.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
virtual ssize_t Write(uint8_t *buffer, size_t length)
Write packet data to device.
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
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...
Network device transmission queue interface.
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
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 SetDeviceName(std::string deviceName)
Set the device name of this device.
AttributeValue implementation for Mac48Address.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< NetDeviceQueue > GetTxQueue(std::size_t i) const
Get the i-th transmission queue of the 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