/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA n1 ------ n0 ------ n3 (echo server) | | | n2 */ #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; NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); int main (int argc, char *argv[]) { Time::SetResolution (Time::NS); LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); NodeContainer nodes; nodes.Create (4); NodeContainer n0n1 = NodeContainer (nodes.Get(0), nodes.Get(1)); NodeContainer n0n2 = NodeContainer (nodes.Get(0), nodes.Get(2)); NodeContainer n0n3 = NodeContainer (nodes.Get(0), nodes.Get(3)); PointToPointHelper pointToPoint1; pointToPoint1.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint1.SetChannelAttribute ("Delay", StringValue ("2ms")); PointToPointHelper pointToPoint2; pointToPoint2.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint2.SetChannelAttribute ("Delay", StringValue ("2ms")); PointToPointHelper pointToPoint3; pointToPoint3.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint3.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer devices1, devices2, devices3; devices1 = pointToPoint1.Install (n0n1); devices2 = pointToPoint2.Install (n0n2); devices3 = pointToPoint3.Install (n0n3); InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address1, address2, address3; address1.SetBase ("10.1.1.0", "255.255.255.0"); address2.SetBase ("10.1.2.0", "255.255.255.0"); address3.SetBase ("10.1.3.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces1 = address1.Assign (devices1); Ipv4InterfaceContainer interfaces2 = address2.Assign (devices2); Ipv4InterfaceContainer interfaces3 = address3.Assign (devices3); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (0)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (15.0)); //Install echoClient1 in n1 UdpEchoClientHelper echoClient1 (interfaces1.GetAddress (0), 9); echoClient1.SetAttribute ("MaxPackets", UintegerValue (5)); echoClient1.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient1.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps1 = echoClient1.Install (nodes.Get (1)); clientApps1.Start (Seconds (2.0)); clientApps1.Stop (Seconds (15.0)); //Install echoClient2 in n2 UdpEchoClientHelper echoClient2 (interfaces2.GetAddress (0), 9); echoClient2.SetAttribute ("MaxPackets", UintegerValue (5)); echoClient2.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient2.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps2 = echoClient2.Install (nodes.Get (2)); clientApps2.Start (Seconds (7.0)); clientApps2.Stop (Seconds (15.0)); //Install echoClient1 in n1 UdpEchoClientHelper echoClient3 (interfaces3.GetAddress (0), 9); echoClient3.SetAttribute ("MaxPackets", UintegerValue (5)); echoClient3.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient3.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps3 = echoClient3.Install (nodes.Get (3)); clientApps3.Start (Seconds (12.0)); clientApps3.Stop (Seconds (15.0)); Simulator::Run (); Simulator::Destroy (); return 0; }