Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * UdpEchoClient UdpEchoServer
- * 10.1.1.0 10.1.2.0
- * n1 ------------------n2------------------n3
- * point-to-point point-to-point
- */
- #include <ns3/core-module.h>
- #include <ns3/network-module.h>
- #include <ns3/internet-module.h>
- #include <ns3/point-to-point-module.h>
- #include <ns3/applications-module.h>
- using namespace ns3;
- int main ()
- {
- LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
- LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
- NodeContainer allNodes, nodes12, nodes23;
- allNodes.Create (3);
- nodes12.Add (allNodes.Get (0));
- nodes12.Add (allNodes.Get (1));
- nodes23.Add (allNodes.Get (1));
- nodes23.Add (allNodes.Get (2));
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("15Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("44ms"));
- NetDeviceContainer devices12, devices23;
- devices12 = pointToPoint.Install (nodes12);
- devices23 = pointToPoint.Install (nodes23);
- // pointToPoint.EnablePcapAll ("vjezba-udp-echo-neizravna-veza");
- InternetStackHelper stack;
- stack.Install (allNodes);
- Ipv4AddressHelper address;
- address.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices12);
- address.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer interfaces23 = address.Assign (devices23);
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
- UdpEchoServerHelper echoServer (9);
- ApplicationContainer serverApps = echoServer.Install (allNodes.Get (2));
- serverApps.Start (Seconds (1.0));
- serverApps.Stop (Seconds (10.0));
- UdpEchoClientHelper echoClient (interfaces23.GetAddress (1), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
- ApplicationContainer clientApps = echoClient.Install (allNodes.Get (0));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
- }
Add Comment
Please, Sign In to add comment