ns-3 is a powerful network simulator. This is a note for learning how ns-3 works.
official tutorial at here.
changing queue disciplines
there are 2 types of queues in ns3
- qos queue before ip layer:
- PFifoFastQueueDisc: The default maximum size is 1000 packets //default
- FifoQueueDisc: The default maximum size is 1000 packets
- RedQueueDisc: The default maximum size is 25 packets
- CoDelQueueDisc: The default maximum size is 1500 kilobytes
- FqCoDelQueueDisc: The default maximum size is 10024 packets
- PieQueueDisc: The default maximum size is 25 packets
- MqQueueDisc: This queue disc has no limits on its capacity
- TbfQueueDisc: The default maximum size is 1000 packets
- device queue according to phy link:
- PointToPointNetDevice: The default configuration (as set by the helper) is to install a DropTail queue of default size (100 packets)
- CsmaNetDevice: The default configuration (as set by the helper) is to install a DropTail queue of default size (100 packets)
- WiFiNetDevice: The default configuration is to install a DropTail queue of default size (100 packets) for non-QoS stations and four DropTail queues of default size (100 packets) for QoS stations
- SimpleNetDevice: The default configuration is to install a DropTail queue of default size (100 packets)
- LTENetDevice: Queueing occurs at the RLC layer (RLC UM default buffer is 10 * 1024 bytes, RLC AM does not have a buffer limit).
- UanNetDevice: There is a default 10 packet queue at the MAC layer
We can modify them like:
1 | PointToPointHelper p2p; |
1 | TrafficControlHelper tch; |
BQL can be enabled on a device that supports it through the traffic control helper:
1 | TrafficControlHelper tch; |
advanced tracing system
Tracing source is used to collect data, and tracing sink is used to deal with the data.
tracing source
tracing source is predefined associated with the target variable. When the target variable changes, system will call the callback function we connect.
for example, in the following script we define a tracing source. the kernel code is addtracesource
. the first argument is the source name. the second is a help string. the third one make a class member be the traced value. the last one is a typedef for the traced value type, which we will use to generate the correct callback function.
1 | class MyObject : public Object |
tracing sink
tracing sink is a callback function to do what we want. the parameter should be related to the type of the traced value.
1 | void |
connect the source and sink
normally we use an object’s method the connect the source and sink.
1 | int |
then if the traced value changes, ns3 will call the callback function already registered.
Note that we need to first create the object, and then hook it. I.e. first create the tcpsocket, then trace the cwnd.
additional sink function parameter
we can add parameter to the sink function
1 | static void |
1 | AsciiTraceHelper asciiTraceHelper; |
create an application
we can use the class application
.
1 | class MyApp : public Application |
we need to implement how to start and stop application. Then in the main function we can set start and stop time. the node list will automatically call the startapplication
and stopapplication
.
1 | Ptr<MyApp> app = CreateObject<MyApp> (); |
a receive-no-reply server application
1 | uint16_t sinkPort = 8080; |
trace helper
we can use trace helper to trace either net device or protocol, in ascii and pcap ways.
i.e. for net device object, there are several overrides:
1 | void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false); |
note if we use implicit filename, the prefix would be the filename. default filename would be
similar with protocol. default filename would be
1 | void EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename = false); |