18 except ModuleNotFoundError:
20 "Error: ns3 Python module not found;"
21 " Python bindings may not be enabled"
22 " or your PYTHONPATH might not be properly configured"
32 ns.core.LogComponentEnable(
"UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
33 ns.core.LogComponentEnable(
"UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
35 nodes = ns.network.NodeContainer()
38 pointToPoint = ns.point_to_point.PointToPointHelper()
39 pointToPoint.SetDeviceAttribute(
"DataRate", ns.core.StringValue(
"5Mbps"))
40 pointToPoint.SetChannelAttribute(
"Delay", ns.core.StringValue(
"2ms"))
42 devices = pointToPoint.Install(nodes)
44 stack = ns.internet.InternetStackHelper()
47 address = ns.internet.Ipv4AddressHelper()
48 address.SetBase(ns.network.Ipv4Address(
"10.1.1.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
50 interfaces = address.Assign(devices)
52 echoServer = ns.applications.UdpEchoServerHelper(9)
54 serverApps = echoServer.Install(nodes.Get(1))
55 serverApps.Start(ns.core.Seconds(1.0))
56 serverApps.Stop(ns.core.Seconds(10.0))
58 address = interfaces.GetAddress(1).ConvertTo()
59 echoClient = ns.applications.UdpEchoClientHelper(address, 9)
60 echoClient.SetAttribute(
"MaxPackets", ns.core.UintegerValue(1))
61 echoClient.SetAttribute(
"Interval", ns.core.TimeValue(ns.core.Seconds(1.0)))
62 echoClient.SetAttribute(
"PacketSize", ns.core.UintegerValue(1024))
64 clientApps = echoClient.Install(nodes.Get(0))
65 clientApps.Start(ns.core.Seconds(2.0))
66 clientApps.Stop(ns.core.Seconds(10.0))
68 ns.core.Simulator.Run()
69 ns.core.Simulator.Destroy()