28except ModuleNotFoundError:
30 "Error: ns3 Python module not found;"
31 " Python bindings may not be enabled"
32 " or your PYTHONPATH might not be properly configured"
41 cmd = ns.CommandLine()
48 ns.GlobalValue.Bind(
"SimulatorImplementationType", ns.StringValue(
"ns3::RealtimeSimulatorImpl"))
53 print(
"Create nodes.")
54 n = ns.NodeContainer()
57 internet = ns.InternetStackHelper()
63 print(
"Create channels.")
64 csma = ns.CsmaHelper()
65 csma.SetChannelAttribute(
"DataRate", ns.DataRateValue(ns.DataRate(5000000)))
66 csma.SetChannelAttribute(
"Delay", ns.TimeValue(ns.MilliSeconds(2)))
67 csma.SetDeviceAttribute(
"Mtu", ns.UintegerValue(1400))
73 print(
"Assign IP Addresses.")
74 ipv4 = ns.Ipv4AddressHelper()
75 ipv4.SetBase(ns.Ipv4Address(
"10.1.1.0"), ns.Ipv4Mask(
"255.255.255.0"))
78 print(
"Create Applications.")
84 server = ns.UdpEchoServerHelper(port)
85 apps = server.Install(n.Get(1))
86 apps.Start(ns.Seconds(1.0))
87 apps.Stop(ns.Seconds(10.0))
95 interPacketInterval = ns.Seconds(0.01)
96 client = ns.UdpEchoClientHelper(i.GetAddress(1).ConvertTo(), port)
97 client.SetAttribute(
"MaxPackets", ns.UintegerValue(maxPacketCount))
98 client.SetAttribute(
"Interval", ns.TimeValue(interPacketInterval))
99 client.SetAttribute(
"PacketSize", ns.UintegerValue(packetSize))
100 apps = client.Install(n.Get(0))
101 apps.Start(ns.Seconds(2.0))
102 apps.Stop(ns.Seconds(10.0))
104 ascii = ns.AsciiTraceHelper()
105 csma.EnableAsciiAll(ascii.CreateFileStream(
"realtime-udp-echo.tr"))
106 csma.EnablePcapAll(
"realtime-udp-echo",
False)
111 print(
"Run Simulation.")
112 ns.Simulator.Stop(ns.Seconds(10))
114 ns.Simulator.Destroy()
118if __name__ ==
"__main__":