BowserFlash13

Untitled

Jun 26th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  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.  
  7. using namespace ns3;
  8.  
  9. int main ()
  10. {
  11.  
  12. LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
  13. LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
  14.  
  15. NodeContainer nodes;
  16. nodes.Create (14);
  17. NodeContainer nodes01 (allNodes.Get (0), allNodes.Get (1));
  18. NodeContainer nodes14 (allNodes.Get (1), allNodes.Get (4));
  19. NodeContainer nodes24 (allNodes.Get (2), allNodes.Get (4));
  20. NodeContainer nodes34 (allNodes.Get (3), allNodes.Get (4));
  21. NodeContainer nodes45 (allNodes.Get (4), allNodes.Get (5));
  22. NodeContainer nodes56 (allNodes.Get (5), allNodes.Get (6));
  23. NodeContainer nodes511 (allNodes.Get (5), allNodes.Get (11));
  24. NodeContainer nodes512 (allNodes.Get (5), allNodes.Get (12));
  25. NodeContainer nodes67 (allNodes.Get (6), allNodes.Get (7));
  26. NodeContainer nodes78 (allNodes.Get (7), allNodes.Get (8));
  27. NodeContainer nodes69 (allNodes.Get (6), allNodes.Get (9));
  28. NodeContainer nodes910 (allNodes.Get (9), allNodes.Get (10));
  29. NodeContainer nodes1213 (allNodes.Get (12), allNodes.Get (13));
  30. NodeContainer nodes1214 (allNodes.Get (12), allNodes.Get (14));
  31.  
  32. PointToPointHelper pointToPoint;
  33. pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("15Mbps"));
  34. pointToPoint.SetChannelAttribute ("Delay", StringValue ("6ms"));
  35.  
  36. NetDeviceContainer devices;
  37. devices = pointToPoint.Install (nodes);
  38. devices01 = pointToPoint.Install (nodes01);
  39. devices14 = pointToPoint.Install (nodes14);
  40. devices24 = pointToPoint.Install (nodes24);
  41. devices34 = pointToPoint.Install (nodes34);
  42. devices45 = pointToPoint.Install (nodes45);
  43. devices56 = pointToPoint.Install (nodes56);
  44. devices67 = pointToPoint.Install (nodes67);
  45. devices78 = pointToPoint.Install (nodes78);
  46. devices69 = pointToPoint.Install (nodes69);
  47. devices910 = pointToPoint.Install (nodes910);
  48. devices511 = pointToPoint.Install (nodes511);
  49. devices512 = pointToPoint.Install (nodes512);
  50. devices1213 = pointToPoint.Install (nodes1213);
  51. devices1214 = pointToPoint.Install (nodes1214);
  52.  
  53. InternetStackHelper stack;
  54. stack.Install (nodes);
  55.  
  56.  
  57. Ipv4AddressHelper address;
  58. address.SetBase ("192.168.0.1", "255.255.0.0");
  59. Ipv4InterfaceContainer interfaces12 = address.Assign (devices01);
  60.  
  61. address.SetBase ("192.168.0.2", "255.255.0.0");
  62. Ipv4InterfaceContainer interfaces12 = address.Assign (devices14);
  63.  
  64. address.SetBase ("192.168.0.3", "255.255.0.0");
  65. Ipv4InterfaceContainer interfaces12 = address.Assign (devices24);
  66.  
  67. address.SetBase ("192.168.0.4", "255.255.0.0");
  68. Ipv4InterfaceContainer interfaces12 = address.Assign (devices34);
  69.  
  70. address.SetBase ("192.168.0.5", "255.255.0.0");
  71. Ipv4InterfaceContainer interfaces12 = address.Assign (devices45);
  72.  
  73. address.SetBase ("192.168.0.6", "255.255.0.0");
  74. Ipv4InterfaceContainer interfaces12 = address.Assign (devices56);
  75.  
  76. address.SetBase ("192.168.0.7", "255.255.0.0");
  77. Ipv4InterfaceContainer interfaces12 = address.Assign (devices67);
  78.  
  79. address.SetBase ("192.168.0.8", "255.255.0.0");
  80. Ipv4InterfaceContainer interfaces12 = address.Assign (devices78);
  81.  
  82. address.SetBase ("192.168.0.9", "255.255.0.0");
  83. Ipv4InterfaceContainer interfaces12 = address.Assign (devices69);
  84.  
  85. address.SetBase ("192.168.0.10", "255.255.0.0");
  86. Ipv4InterfaceContainer interfaces12 = address.Assign (devices910);
  87.  
  88. address.SetBase ("192.168.0.11", "255.255.0.0");
  89. Ipv4InterfaceContainer interfaces12 = address.Assign (devices511);
  90.  
  91. address.SetBase ("192.168.0.12", "255.255.0.0");
  92. Ipv4InterfaceContainer interfaces12 = address.Assign (devices512);
  93.  
  94. address.SetBase ("192.168.0.13", "255.255.0.0");
  95. Ipv4InterfaceContainer interfaces12 = address.Assign (devices1213);
  96.  
  97. address.SetBase ("192.168.0.14", "255.255.0.0");
  98. Ipv4InterfaceContainer interfaces12 = address.Assign (devices1214);
  99.  
  100. PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
  101. ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (14));
  102. sinkApps.Start (Seconds (4.));
  103. sinkApps.Stop (Seconds (42.));
  104.  
  105. OnOffHelper onOffApp ("ns3::TcpSocketFactory", InetSocketAddress (interfaces.GetAddress (0), 9));
  106. onOffApp.SetAttribute ("DataRate", StringValue ("8Mbps"));
  107. onOffApp.SetAttribute ("PacketSize", UintegerValue (12500));
  108. onOffApp.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=2.5]"));
  109. onOffApp.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=4.0|Max=11.0]"));
  110.  
  111. PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
  112. ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (2));
  113. sinkApps.Start (Seconds (3.));
  114. sinkApps.Stop (Seconds (45.));
  115.  
  116. OnOffHelper onOffApp ("ns3::TcpSocketFactory", InetSocketAddress (interfaces.GetAddress (10), 9));
  117. onOffApp.SetAttribute ("DataRate", StringValue ("4Mbps"));
  118. onOffApp.SetAttribute ("PacketSize", UintegerValue (6500));
  119. onOffApp.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=4.0]"));
  120. onOffApp.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=3.0|Max=6.0]"));
  121.  
  122. ApplicationContainer clientApps = onOffApp.Install (nodes.Get (0));
  123. clientApps.Start (Seconds (2.0));
  124. clientApps.Stop (Seconds (10.0));
  125.  
  126.  
  127. Simulator::Run ();
  128. Simulator::Destroy ();
  129.  
  130. return 0;
  131. }
Add Comment
Please, Sign In to add comment