From 54671db601ff36578abb86ef3b6d235e8d848ada Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Mon, 22 Aug 2016 14:51:06 +0200 Subject: [PATCH] examples: Update the traffic-control example --- examples/traffic-control/traffic-control.cc | 88 ++++++++++++--------- examples/traffic-control/wscript | 2 +- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/examples/traffic-control/traffic-control.cc b/examples/traffic-control/traffic-control.cc index 6e193cd52..44b2a6d6e 100644 --- a/examples/traffic-control/traffic-control.cc +++ b/examples/traffic-control/traffic-control.cc @@ -25,13 +25,14 @@ #include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" #include "ns3/traffic-control-module.h" +#include "ns3/flow-monitor-module.h" // This simple example shows how to use TrafficControlHelper to install a // QueueDisc on a device. // -// The default QueueDisc is a pfifo_fast with max number of packets equal to -// 1000 (as in Linux). However, in this example, we change from the default -// to instead use a ns3::RedQueueDisc with a MaxPackets value of 10000. +// The default QueueDisc is a pfifo_fast with a capacity of 1000 packets (as in +// Linux). However, in this example, we install a RedQueueDisc with a capacity +// of 10000 packets. // // Network topology // @@ -39,38 +40,27 @@ // n0 -------------- n1 // point-to-point // -// The output will consist of a number of traced changes to queue lengths -// such as: +// The output will consist of all the traced changes in the length of the RED +// internal queue and in the length of the netdevice queue: // // DevicePacketsInQueue 0 to 1 -// TcPacketsInQueue 5 to 4 -// TcPacketsInQueue 4 to 5 +// TcPacketsInQueue 7 to 8 +// TcPacketsInQueue 8 to 9 // DevicePacketsInQueue 1 to 0 +// TcPacketsInQueue 9 to 8 // -// and an average throughput: +// plus some statistics collected at the network layer (by the flow monitor) +// and the application layer. Finally, the number of packets dropped by the +// queuing discipline, the number of packets dropped by the netdevice and +// the number of packets requeued by the queuing discipline are reported. // -// Average throughput: 8.72854 Mbit/s -// -// The final output displays the number of drops at the TC layer and the -// netdevice layer. These statistics highlight the fact that for -// PointToPointNetDevice, the drops at the device layer are actually -// requeued at the TC layer, so the true packet drops (39 in this case) -// must be traced at the TC layer. -// -// *** Source stats *** -// Number of packets dropped by the TC layer: 39 -// Number of packets dropped by the netdevice: 3914 -// Number of packets requeued by the TC layer: 3914 -// Number of actually lost packets: 39 -// -// If one were to increase the size of the PointToPointNetDevice's -// DropTailQueue from 1 to a larger number (e.g. 1000), one would observe -// that the number of packets dropped would go to zero, but the latency -// and QoS would not be controllable. This is the so-called bufferbloat -// problem, and illustrates the importance of having a small device queue -// so that the standing queues build in the traffic control layer where -// they can be managed by advanced queue discs rather than in the -// device layer. +// If the size of the DropTail queue of the netdevice were increased from 1 +// to a large number (e.g. 1000), one would observe that the number of dropped +// packets goes to zero, but the latency grows in an uncontrolled manner. This +// is the so-called bufferbloat problem, and illustrates the importance of +// having a small device queue, so that the standing queues build in the traffic +// control layer where they can be managed by advanced queue discs rather than +// in the device layer. using namespace ns3; @@ -169,21 +159,41 @@ main (int argc, char *argv[]) apps.Start (Seconds (1.0)); apps.Stop (Seconds (simulationTime + 0.1)); - Simulator::Stop (Seconds (simulationTime + 0.1)); + FlowMonitorHelper flowmon; + Ptr monitor = flowmon.InstallAll(); + + Simulator::Stop (Seconds (simulationTime + 5)); Simulator::Run (); + + Ptr classifier = DynamicCast (flowmon.GetClassifier ()); + std::map stats = monitor->GetFlowStats (); + std::cout << std::endl << "*** Flow monitor statistics ***" << std::endl; + std::cout << " Tx Packets: " << stats[1].txPackets << std::endl; + std::cout << " Tx Bytes: " << stats[1].txBytes << std::endl; + std::cout << " Offered Load: " << stats[1].txBytes * 8.0 / (stats[1].timeLastTxPacket.GetSeconds () - stats[1].timeFirstTxPacket.GetSeconds ()) / 1000000 << " Mbps" << std::endl; + std::cout << " Rx Packets: " << stats[1].rxPackets << std::endl; + std::cout << " Rx Bytes: " << stats[1].rxBytes << std::endl; + std::cout << " Packets Dropped by Queue Disc: " << stats[1].packetsDropped[Ipv4FlowProbe::DROP_QUEUE_DISC] << std::endl; + std::cout << " Bytes Dropped by Queue Disc: " << stats[1].bytesDropped[Ipv4FlowProbe::DROP_QUEUE_DISC] << std::endl; + std::cout << " Packets Dropped by NetDevice: " << stats[1].packetsDropped[Ipv4FlowProbe::DROP_QUEUE] << std::endl; + std::cout << " Bytes Dropped by NetDevice: " << stats[1].bytesDropped[Ipv4FlowProbe::DROP_QUEUE] << std::endl; + std::cout << " Throughput: " << stats[1].rxBytes * 8.0 / (stats[1].timeLastRxPacket.GetSeconds () - stats[1].timeFirstRxPacket.GetSeconds ()) / 1000000 << " Mbps" << std::endl; + std::cout << " Mean delay: " << stats[1].delaySum.GetSeconds () / stats[1].rxPackets << std::endl; + std::cout << " Mean jitter: " << stats[1].jitterSum.GetSeconds () / (stats[1].rxPackets - 1) << std::endl; + Simulator::Destroy (); + std::cout << std::endl << "*** Application statistics ***" << std::endl; double thr = 0; uint32_t totalPacketsThr = DynamicCast (sinkApp.Get (0))->GetTotalRx (); thr = totalPacketsThr * 8 / (simulationTime * 1000000.0); //Mbit/s - std::cout << "Average throughput: " << thr << " Mbit/s" <GetTotalDroppedPackets () << std::endl; - std::cout << "Number of packets dropped by the netdevice: " << queue->GetTotalDroppedPackets () << std::endl; - std::cout << "Number of packets requeued by the TC layer: " << q->GetTotalRequeuedPackets () << std::endl; - std::cout << "Number of actually lost packets: " << q->GetTotalDroppedPackets () - + queue->GetTotalDroppedPackets () - - q->GetTotalRequeuedPackets () << std::endl; + std::cout << " Rx Bytes: " << totalPacketsThr << std::endl; + std::cout << " Average Goodput: " << thr << " Mbit/s" << std::endl; + std::cout << std::endl << "*** TC Layer statistics ***" << std::endl; + std::cout << " Packets dropped by the TC layer: " << q->GetTotalDroppedPackets () << std::endl; + std::cout << " Bytes dropped by the TC layer: " << q->GetTotalDroppedBytes () << std::endl; + std::cout << " Packets dropped by the netdevice: " << queue->GetTotalDroppedPackets () << std::endl; + std::cout << " Packets requeued by the TC layer: " << q->GetTotalRequeuedPackets () << std::endl; return 0; } diff --git a/examples/traffic-control/wscript b/examples/traffic-control/wscript index 05a8c2a55..b943e56a7 100644 --- a/examples/traffic-control/wscript +++ b/examples/traffic-control/wscript @@ -2,7 +2,7 @@ def build(bld): obj = bld.create_ns3_program('traffic-control', - ['internet', 'point-to-point', 'applications', 'traffic-control']) + ['internet', 'point-to-point', 'applications', 'traffic-control', 'flow-monitor']) obj.source = 'traffic-control.cc' obj = bld.create_ns3_program('queue-discs-benchmark',