BowserFlash13

Untitled

Jun 26th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. /*
  2.  * UdpEchoClient                            UdpEchoServer
  3.  *            10.1.1.0               10.1.2.0
  4.  *      n1 ------------------n2------------------n3
  5.  *         point-to-point       point-to-point
  6.  */
  7.  
  8. #include <ns3/core-module.h>
  9. #include <ns3/network-module.h>
  10. #include <ns3/internet-module.h>
  11. #include <ns3/point-to-point-module.h>
  12. #include <ns3/applications-module.h>
  13.  
  14. using namespace ns3;
  15.  
  16. int main ()
  17. {
  18.   LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  19.   LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
  20.  
  21.   NodeContainer allNodes, nodes12, nodes23;
  22.   allNodes.Create (3);
  23.   nodes12.Add (allNodes.Get (0));
  24.   nodes12.Add (allNodes.Get (1));
  25.   nodes23.Add (allNodes.Get (1));
  26.   nodes23.Add (allNodes.Get (2));
  27.  
  28.   PointToPointHelper pointToPoint;
  29.   pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("15Mbps"));
  30.   pointToPoint.SetChannelAttribute ("Delay", StringValue ("44ms"));
  31.  
  32.   NetDeviceContainer devices12, devices23;
  33.   devices12 = pointToPoint.Install (nodes12);
  34.   devices23 = pointToPoint.Install (nodes23);
  35.   // pointToPoint.EnablePcapAll ("vjezba-udp-echo-neizravna-veza");
  36.  
  37.   InternetStackHelper stack;
  38.   stack.Install (allNodes);
  39.  
  40.   Ipv4AddressHelper address;
  41.   address.SetBase ("10.1.1.0", "255.255.255.0");
  42.   Ipv4InterfaceContainer interfaces12 = address.Assign (devices12);
  43.  
  44.   address.SetBase ("10.1.2.0", "255.255.255.0");
  45.   Ipv4InterfaceContainer interfaces23 = address.Assign (devices23);
  46.  
  47.   Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  48.  
  49.   UdpEchoServerHelper echoServer (9);
  50.  
  51.   ApplicationContainer serverApps = echoServer.Install (allNodes.Get (2));
  52.   serverApps.Start (Seconds (1.0));
  53.   serverApps.Stop (Seconds (10.0));
  54.  
  55.   UdpEchoClientHelper echoClient (interfaces23.GetAddress (1), 9);
  56.   echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  57.   echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  58.   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
  59.  
  60.   ApplicationContainer clientApps = echoClient.Install (allNodes.Get (0));
  61.   clientApps.Start (Seconds (2.0));
  62.   clientApps.Stop (Seconds (10.0));
  63.  
  64.   Simulator::Run ();
  65.   Simulator::Destroy ();
  66.   return 0;
  67. }
Add Comment
Please, Sign In to add comment