fork download
  1. #include "ns3/core-module.h"
  2. #include "ns3/network-module.h"
  3. #include "ns3/internet-module.h"
  4. #include "ns3/point-to-point-module.h"
  5. #include "ns3/applications-module.h"
  6. #include "ns3/flow-monitor-module.h"
  7. #include "ns3/netanim-module.h"
  8. #include "ns3/mobility-module.h"
  9.  
  10. using namespace ns3;
  11.  
  12. NS_LOG_COMPONENT_DEFINE ("nisha-lab1");
  13.  
  14. int
  15. main (int argc, char *argv[])
  16. {
  17. CommandLine cmd;
  18. cmd.Parse (argc, argv);
  19.  
  20. Time::SetResolution (Time::NS);
  21.  
  22. LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
  23. LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
  24.  
  25. NodeContainer nodes;
  26. nodes.Create (2);
  27.  
  28. PointToPointHelper pointToPoint;
  29. pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  30. pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
  31.  
  32. NetDeviceContainer devices;
  33.  
  34. devices = pointToPoint.Install (nodes);
  35.  
  36. InternetStackHelper stack;
  37. stack.Install (nodes);
  38.  
  39. Ipv4AddressHelper address;
  40. address.SetBase ("10.1.1.0", "255.255.255.0");
  41.  
  42. Ipv4InterfaceContainer interfaces = address.Assign (devices);
  43.  
  44.  
  45. //Position
  46. MobilityHelper mobility;
  47. Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
  48. positionAlloc->Add(Vector(0,0,0));
  49. positionAlloc->Add(Vector(0,50,0));
  50. mobility.SetPositionAllocator(positionAlloc);
  51. mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  52. mobility.Install(nodes);
  53.  
  54. UdpServerHelper Server1 (9);
  55.  
  56. ApplicationContainer server1Apps = Server1.Install (nodes.Get (1));
  57. server1Apps.Start (Seconds (1.0));
  58. server1Apps.Stop (Seconds (10.0));
  59.  
  60. UdpServerHelper Server2 (5);
  61.  
  62. ApplicationContainer server2Apps = Server2.Install (nodes.Get (0));
  63. server2Apps.Start (Seconds (1.0));
  64. server2Apps.Stop (Seconds (10.0));
  65.  
  66. UdpClientHelper Client1 (interfaces.GetAddress (1), 9);
  67. Client1.SetAttribute ("MaxPackets", UintegerValue (1));
  68. Client1.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  69. Client1.SetAttribute ("PacketSize", UintegerValue (1024));
  70.  
  71. UdpClientHelper Client2 (interfaces.GetAddress (0), 5);
  72. Client2.SetAttribute ("MaxPackets", UintegerValue (1));
  73. Client2.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  74. Client2.SetAttribute ("PacketSize", UintegerValue (1024));
  75.  
  76. ApplicationContainer client1Apps = Client1.Install (nodes.Get (0));
  77. client1Apps.Start (Seconds (2.0));
  78. client1Apps.Stop (Seconds (10.0));
  79. ApplicationContainer client2Apps = Client2.Install (nodes.Get (1));
  80. client2Apps.Start (Seconds (3.0));
  81. client2Apps.Stop (Seconds (8.0));
  82.  
  83. //For ASCII tracing::
  84. AsciiTraceHelper ascii;
  85. pointToPoint.EnableAsciiAll(ascii.CreateFileStream("nishalab1.tr"));
  86.  
  87. //For pcap tracing::
  88. pointToPoint.EnablePcapAll("nishalab1");
  89.  
  90.  
  91. //For animation::
  92. AnimationInterface anim ("nishalab1.xml");
  93.  
  94. //Flow monitoring
  95.  
  96. FlowMonitorHelper flowmon;
  97. Ptr<FlowMonitor> monitor = flowmon.InstallAll();
  98.  
  99. Simulator::Stop (Seconds(10.0));
  100. Simulator::Run ();
  101.  
  102. //Print per flow statistics
  103. monitor->CheckForLostPackets ();
  104. Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
  105. std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
  106.  
  107. for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter = stats.begin (); iter != stats.end (); ++iter)
  108. {
  109. Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (iter->first);
  110.  
  111. if ((t.sourceAddress == Ipv4Address("10.1.1.1") && t.destinationAddress == Ipv4Address("10.1.1.2")) || (t.sourceAddress == Ipv4Address("10.1.1.2") && t.destinationAddress == Ipv4Address("10.1.1.1")))
  112. {
  113. NS_LOG_UNCOND("Flow ID: " << iter->first << " Source Addr " << t.sourceAddress << " Destination Addr " << t.destinationAddress);
  114. NS_LOG_UNCOND("Transmitted Packets = " << iter->second.txPackets);
  115. NS_LOG_UNCOND("Received Packets = " << iter->second.rxPackets);
  116. NS_LOG_UNCOND("Delay Sum = " << iter->second.delaySum);
  117. NS_LOG_UNCOND("Jitter Sum = " << iter->second.jitterSum);
  118. NS_LOG_UNCOND("Lost Packets = " << iter->second.lostPackets);
  119. NS_LOG_UNCOND("Throughput: " << iter->second.rxBytes * 8.0 / (8*1024) << " Kbps");
  120. }
  121. }
  122. monitor->SerializeToXmlFile("first-lab", true, true);
  123.  
  124. Simulator::Destroy ();
  125. return 0;
  126. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: ns3/core-module.h: No such file or directory
 #include "ns3/core-module.h"
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty