MdSadmanSiraj

performance.cc

Dec 3rd, 2022
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.12 KB | None | 0 0
  1.  
  2. // Performance calculation in NS3 without using software
  3.     SentPackets
  4.     ReceivedPackets
  5.     LostPackets
  6.     Packet Loss ratio << "%"
  7.     Packet delivery ratio << "%"
  8.     AvgThroughput<< "Kbps"
  9.     End to End Delay <<"ns"
  10.     End to End Jitter delay <<"ns"
  11.  
  12.  
  13. // OS : ubuntu 16.04 LTS
  14. // NS version ns-3.29
  15. //Explain example with MANET-routing-compare.cc which is available in the /home/logu/ns-allinone-3.29/ns-3.29/examples/routing/
  16.  
  17.  
  18. //step 1:Add header file
  19.  
  20. #include "ns3/flow-monitor-module.h"
  21.  
  22. //step 2: variable declaration after m_protocolName = "protocol" in the
  23. //void RoutingExperiment::Run (int nSinks, double txp, std::string CSVfileName)
  24.  
  25. uint32_t SentPackets = 0;
  26. uint32_t ReceivedPackets = 0;
  27. uint32_t LostPackets = 0;
  28.  
  29.  
  30.  
  31. //step 3:Install FlowMonitor on all nodes
  32.   FlowMonitorHelper flowmon;
  33.   Ptr<FlowMonitor> monitor = flowmon.InstallAll();
  34.  
  35.  
  36. // step 4: Add below code after Simulator::Run ();
  37. ///////////////////////////////////// Network Perfomance Calculation /////////////////////////////////////
  38.  
  39. int j=0;
  40. float AvgThroughput = 0;
  41. Time Jitter;
  42. Time Delay;
  43.  
  44. Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
  45.   std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
  46.  
  47.   for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter = stats.begin (); iter != stats.end (); ++iter)
  48.     {
  49.       Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (iter->first);
  50.  
  51. NS_LOG_UNCOND("----Flow ID:" <<iter->first);
  52. NS_LOG_UNCOND("Src Addr" <<t.sourceAddress << "Dst Addr "<< t.destinationAddress);
  53. NS_LOG_UNCOND("Sent Packets=" <<iter->second.txPackets);
  54. NS_LOG_UNCOND("Received Packets =" <<iter->second.rxPackets);
  55. NS_LOG_UNCOND("Lost Packets =" <<iter->second.txPackets-iter->second.rxPackets);
  56. NS_LOG_UNCOND("Packet delivery ratio =" <<iter->second.rxPackets*100/iter->second.txPackets << "%");
  57. NS_LOG_UNCOND("Packet loss ratio =" << (iter->second.txPackets-iter->second.rxPackets)*100/iter->second.txPackets << "%");
  58. NS_LOG_UNCOND("Delay =" <<iter->second.delaySum);
  59. NS_LOG_UNCOND("Jitter =" <<iter->second.jitterSum);
  60. NS_LOG_UNCOND("Throughput =" <<iter->second.rxBytes * 8.0/(iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/1024<<"Kbps");
  61.  
  62. SentPackets = SentPackets +(iter->second.txPackets);
  63. ReceivedPackets = ReceivedPackets + (iter->second.rxPackets);
  64. LostPackets = LostPackets + (iter->second.txPackets-iter->second.rxPackets);
  65. AvgThroughput = AvgThroughput + (iter->second.rxBytes * 8.0/(iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/1024);
  66. Delay = Delay + (iter->second.delaySum);
  67. Jitter = Jitter + (iter->second.jitterSum);
  68.  
  69. j = j + 1;
  70.  
  71. }
  72.  
  73. AvgThroughput = AvgThroughput/j;
  74. NS_LOG_UNCOND("--------Total Results of the simulation----------"<<std::endl);
  75. NS_LOG_UNCOND("Total sent packets  =" << SentPackets);
  76. NS_LOG_UNCOND("Total Received Packets =" << ReceivedPackets);
  77. NS_LOG_UNCOND("Total Lost Packets =" << LostPackets);
  78. NS_LOG_UNCOND("Packet Loss ratio =" << ((LostPackets*100)/SentPackets)<< "%");
  79. NS_LOG_UNCOND("Packet delivery ratio =" << ((ReceivedPackets*100)/SentPackets)<< "%");
  80. NS_LOG_UNCOND("Average Throughput =" << AvgThroughput<< "Kbps");
  81. NS_LOG_UNCOND("End to End Delay =" << Delay);
  82. NS_LOG_UNCOND("End to End Jitter delay =" << Jitter);
  83. NS_LOG_UNCOND("Total Flod id " << j);
  84. monitor->SerializeToXmlFile("manet-routing.xml", true, true);
  85.  
  86. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  87.  
  88.  
  89.  
  90. // Step 5: Run the program
  91.  
  92. $ cd ns-allinone-3.29/ns-3.29/
  93.  
  94. $ ./waf --run scratch/manet-routing-compare
  95.  
  96. // you can get the following results//
  97. //--------Total Results of the simulation----------//
  98.  
  99. Total sent packets  =1649
  100. Total Received Packets =1377
  101. Total Lost Packets =272
  102. Packet Loss ratio =16%
  103. Packet delivery ratio =83%
  104. Average Throughput =5.56209Kbps
  105. End to End Delay =+110104125435.0ns
  106. End to End Jitter delay =+43338866355.0ns
  107. Total Flod id 182
  108. ////////////////////////////////////////////////////////
  109.  
  110.  
  111. Thank you... subcribe channel... //Technosilent
  112.  
Add Comment
Please, Sign In to add comment