16 import ns.applications
20 import ns.point_to_point
29 ns.core.LogComponentEnable(
"UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
30 ns.core.LogComponentEnable(
"UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
32 nodes = ns.network.NodeContainer()
35 pointToPoint = ns.point_to_point.PointToPointHelper()
36 pointToPoint.SetDeviceAttribute(
"DataRate", ns.core.StringValue(
"5Mbps"))
37 pointToPoint.SetChannelAttribute(
"Delay", ns.core.StringValue(
"2ms"))
39 devices = pointToPoint.Install(nodes)
41 stack = ns.internet.InternetStackHelper()
44 address = ns.internet.Ipv4AddressHelper()
45 address.SetBase(ns.network.Ipv4Address(
"10.1.1.0"),
46 ns.network.Ipv4Mask(
"255.255.255.0"))
48 interfaces = address.Assign(devices)
50 echoServer = ns.applications.UdpEchoServerHelper(9)
52 serverApps = echoServer.Install(nodes.Get(1))
53 serverApps.Start(ns.core.Seconds(1.0))
54 serverApps.Stop(ns.core.Seconds(10.0))
56 echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
57 echoClient.SetAttribute(
"MaxPackets", ns.core.UintegerValue(1))
58 echoClient.SetAttribute(
"Interval", ns.core.TimeValue(ns.core.Seconds(1.0)))
59 echoClient.SetAttribute(
"PacketSize", ns.core.UintegerValue(1024))
61 clientApps = echoClient.Install(nodes.Get(0))
62 clientApps.Start(ns.core.Seconds(2.0))
63 clientApps.Stop(ns.core.Seconds(10.0))
65 ns.core.Simulator.Run()
66 ns.core.Simulator.Destroy()