27except ModuleNotFoundError:
29 "Error: ns3 Python module not found;"
30 " Python bindings may not be enabled"
31 " or your PYTHONPATH might not be properly configured"
84 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
85 Vector pos = mob->GetPosition();
89 mob->SetPosition(pos);
90 Simulator::Schedule(Seconds(1.0), AdvancePosition, node);
96 ns.CommandLine().Parse(argv)
98 ns.Packet.EnablePrinting()
100 wifi = ns.WifiHelper()
101 mobility = ns.MobilityHelper()
102 stas = ns.NodeContainer()
103 ap = ns.NodeContainer()
105 packetSocket = ns.PacketSocketHelper()
111 packetSocket.Install(stas)
112 packetSocket.Install(ap)
114 wifiPhy = ns.YansWifiPhyHelper()
115 wifiChannel = ns.YansWifiChannelHelper.Default()
116 wifiPhy.SetChannel(wifiChannel.Create())
118 ssid = ns.Ssid(
"wifi-default")
119 wifiMac = ns.WifiMacHelper()
125 ns.BooleanValue(
True),
129 staDevs = wifi.Install(wifiPhy, wifiMac, stas)
131 wifiMac.SetType(
"ns3::ApWifiMac",
"Ssid", ns.SsidValue(ssid))
132 wifi.Install(wifiPhy, wifiMac, ap)
135 mobility.Install(stas)
138 ns.Simulator.Schedule(ns.Seconds(1.0), ns.cppyy.gbl.AdvancePosition, ap.Get(0))
140 socket = ns.PacketSocketAddress()
141 socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
142 socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
143 socket.SetProtocol(1)
145 onoff = ns.OnOffHelper(
"ns3::PacketSocketFactory", socket.ConvertTo())
146 onoff.SetConstantRate(ns.DataRate(
"500kb/s"))
148 apps = onoff.Install(ns.NodeContainer(stas.Get(0)))
149 apps.Start(ns.Seconds(0.5))
150 apps.Stop(ns.Seconds(43.0))
152 ns.Simulator.Stop(ns.Seconds(44.0))
162 ns.Simulator.Destroy()
167if __name__ ==
"__main__":
168 sys.exit(main(sys.argv))
static void AdvancePosition(Ptr< Node > node)
Move a node position by 5m on the x axis every second, up to 210m.