Advertisement
MdSadmanSiraj

exp_first.cc

Oct 1st, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License version 2 as
  5.  * published by the Free Software Foundation;
  6.  *
  7.  * This program is distributed in the hope that it will be useful,
  8.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  * GNU General Public License for more details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License
  13.  * along with this program; if not, write to the Free Software
  14.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  15.  */
  16.  
  17. #include "ns3/core-module.h"
  18. #include "ns3/network-module.h"
  19. #include "ns3/internet-module.h"
  20. #include "ns3/point-to-point-module.h"
  21. #include "ns3/applications-module.h"
  22. #include "ns3/netanim-module.h"
  23.  
  24. // Default Network Topology
  25. //
  26. //       10.1.1.0
  27. // n0 -------------- n1
  28. //    point-to-point
  29. //
  30.  
  31. using namespace ns3;
  32.  
  33. NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
  34.  
  35. int
  36. main (int argc, char *argv[])
  37. {
  38.   CommandLine cmd (__FILE__);
  39.   cmd.Parse (argc, argv);
  40.  
  41.   Time::SetResolution (Time::NS);
  42.   LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  43.   LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
  44.  
  45.   NodeContainer nodes;
  46.   nodes.Create (2);
  47.  
  48.   PointToPointHelper pointToPoint;
  49.   pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("500Mbps"));
  50.   pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
  51.  
  52.   NetDeviceContainer devices;
  53.   devices = pointToPoint.Install (nodes);
  54.  
  55.   InternetStackHelper stack;
  56.   stack.Install (nodes);
  57.  
  58.   Ipv4AddressHelper address;
  59.   address.SetBase ("10.1.1.0", "255.255.255.0");
  60.  
  61.   Ipv4InterfaceContainer interfaces = address.Assign (devices);
  62.  
  63.   UdpEchoServerHelper echoServer (9);
  64.  
  65.   ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
  66.   serverApps.Start (Seconds (1.0));
  67.   serverApps.Stop (Seconds (101.0));
  68.  
  69.   UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
  70.   echoClient.SetAttribute ("MaxPackets", UintegerValue (100));
  71.   echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  72.   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
  73.  
  74.   ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
  75.   clientApps.Start (Seconds (2.0));
  76.   clientApps.Stop (Seconds (101.0));
  77.  
  78.   Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  79.  
  80.   pointToPoint.EnablePcapAll ("firstP2P");
  81.  
  82.   AnimationInterface anim ("first.xml");
  83.   anim.SetConstantPosition(nodes.Get(0), 30.0, 25.0);
  84.   anim.SetConstantPosition(nodes.Get(1), 10.0, 25.0);
  85.   NS_LOG_INFO ("Run Simulation.");
  86.  
  87.   Simulator::Run ();
  88.   Simulator::Destroy ();
  89.   return 0;
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement