16 import ns.applications
 
   20 import ns.point_to_point
 
   22 ns.core.LogComponentEnable(
"UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
 
   23 ns.core.LogComponentEnable(
"UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
 
   25 nodes = ns.network.NodeContainer()
 
   28 pointToPoint = ns.point_to_point.PointToPointHelper()
 
   29 pointToPoint.SetDeviceAttribute(
"DataRate", ns.core.StringValue(
"5Mbps"))
 
   30 pointToPoint.SetChannelAttribute(
"Delay", ns.core.StringValue(
"2ms"))
 
   32 devices = pointToPoint.Install(nodes)
 
   34 stack = ns.internet.InternetStackHelper()
 
   37 address = ns.internet.Ipv4AddressHelper()
 
   38 address.SetBase(ns.network.Ipv4Address(
"10.1.1.0"),
 
   39                 ns.network.Ipv4Mask(
"255.255.255.0"))
 
   41 interfaces = address.Assign(devices)
 
   43 echoServer = ns.applications.UdpEchoServerHelper(9)
 
   45 serverApps = echoServer.Install(nodes.Get(1))
 
   46 serverApps.Start(ns.core.Seconds(1.0))
 
   47 serverApps.Stop(ns.core.Seconds(10.0))
 
   49 echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
 
   50 echoClient.SetAttribute(
"MaxPackets", ns.core.UintegerValue(1))
 
   51 echoClient.SetAttribute(
"Interval", ns.core.TimeValue(ns.core.Seconds(1.0)))
 
   52 echoClient.SetAttribute(
"PacketSize", ns.core.UintegerValue(1024))
 
   54 clientApps = echoClient.Install(nodes.Get(0))
 
   55 clientApps.Start(ns.core.Seconds(2.0))
 
   56 clientApps.Stop(ns.core.Seconds(10.0))
 
   58 ns.core.Simulator.Run()
 
   59 ns.core.Simulator.Destroy()