|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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)
holds a vector of ns3::NetDevice pointers
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Parse command-line arguments.
AttributeValue implementation for Boolean.
Ptr< NetDeviceQueue > GetTxQueue(std::size_t i) const
Get the i-th transmission queue of the device.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void SetDeviceName(std::string deviceName)
Set the device name of this device.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
AttributeValue implementation for Mac48Address.
build a set of FdNetDevice objects attached to a physical network interface
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void SetDeviceName(std::string deviceName)
Set the device name of this device.
static void Run(void)
Run the simulation.
Hold variables of type string.
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...
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Network device transmission queue interface.
build a set of FdNetDevice objects Normally we eschew multiple inheritance, however,...
Time Seconds(double value)
Construct a Time in the indicated unit.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
build a set of FdNetDevice objects attached to a physical network interface
virtual ssize_t Write(uint8_t *buffer, size_t length)
Write packet data to device.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.