26 import ns.applications
37 cmd = ns.core.CommandLine()
44 ns.core.GlobalValue.Bind(
"SimulatorImplementationType", ns.core.StringValue(
"ns3::RealtimeSimulatorImpl"))
49 print (
"Create nodes.")
50 n = ns.network.NodeContainer()
53 internet = ns.internet.InternetStackHelper()
59 print (
"Create channels.")
60 csma = ns.csma.CsmaHelper()
61 csma.SetChannelAttribute(
"DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000)))
62 csma.SetChannelAttribute(
"Delay", ns.core.TimeValue(ns.core.MilliSeconds(2)));
63 csma.SetDeviceAttribute(
"Mtu", ns.core.UintegerValue(1400))
69 print (
"Assign IP Addresses.")
70 ipv4 = ns.internet.Ipv4AddressHelper()
71 ipv4.SetBase(ns.network.Ipv4Address(
"10.1.1.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
74 print (
"Create Applications.")
80 server = ns.applications.UdpEchoServerHelper(port)
81 apps = server.Install(n.Get(1))
82 apps.Start(ns.core.Seconds(1.0))
83 apps.Stop(ns.core.Seconds(10.0))
91 interPacketInterval = ns.core.Seconds(0.01)
92 client = ns.applications.UdpEchoClientHelper(i.GetAddress (1), port)
93 client.SetAttribute(
"MaxPackets", ns.core.UintegerValue(maxPacketCount))
94 client.SetAttribute(
"Interval", ns.core.TimeValue(interPacketInterval))
95 client.SetAttribute(
"PacketSize", ns.core.UintegerValue(packetSize))
96 apps = client.Install(n.Get(0))
97 apps.Start(ns.core.Seconds(2.0))
98 apps.Stop(ns.core.Seconds(10.0))
100 ascii = ns.network.AsciiTraceHelper()
101 csma.EnableAsciiAll(ascii.CreateFileStream(
"realtime-udp-echo.tr"))
102 csma.EnablePcapAll(
"realtime-udp-echo",
False)
107 print (
"Run Simulation.")
108 ns.core.Simulator.Run()
109 ns.core.Simulator.Destroy()
112 if __name__ ==
'__main__':