From 054896c3a96e9c3abd91b577ecaf7cbd58828e3f Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Mon, 9 Jan 2017 20:09:27 +0100 Subject: [PATCH] traffic-control: Fix possible crash in the traffic-control example --- examples/traffic-control/traffic-control.cc | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/traffic-control/traffic-control.cc b/examples/traffic-control/traffic-control.cc index 44b2a6d6e..e91876616 100644 --- a/examples/traffic-control/traffic-control.cc +++ b/examples/traffic-control/traffic-control.cc @@ -173,10 +173,24 @@ main (int argc, char *argv[]) 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; + uint32_t packetsDroppedByQueueDisc = 0; + uint64_t bytesDroppedByQueueDisc = 0; + if (stats[1].packetsDropped.size () > Ipv4FlowProbe::DROP_QUEUE_DISC) + { + packetsDroppedByQueueDisc = stats[1].packetsDropped[Ipv4FlowProbe::DROP_QUEUE_DISC]; + bytesDroppedByQueueDisc = stats[1].bytesDropped[Ipv4FlowProbe::DROP_QUEUE_DISC]; + } + std::cout << " Packets Dropped by Queue Disc: " << packetsDroppedByQueueDisc << std::endl; + std::cout << " Bytes Dropped by Queue Disc: " << bytesDroppedByQueueDisc << std::endl; + uint32_t packetsDroppedByNetDevice = 0; + uint64_t bytesDroppedByNetDevice = 0; + if (stats[1].packetsDropped.size () > Ipv4FlowProbe::DROP_QUEUE) + { + packetsDroppedByNetDevice = stats[1].packetsDropped[Ipv4FlowProbe::DROP_QUEUE]; + bytesDroppedByNetDevice = stats[1].bytesDropped[Ipv4FlowProbe::DROP_QUEUE]; + } + std::cout << " Packets Dropped by NetDevice: " << packetsDroppedByNetDevice << std::endl; + std::cout << " Bytes Dropped by NetDevice: " << bytesDroppedByNetDevice << 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;