16except ModuleNotFoundError:
18 "Error: ns3 Python module not found;"
19 " Python bindings may not be enabled"
20 " or your PYTHONPATH might not be properly configured"
71 void AdvancePosition(Ptr<Node> node){
72 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
73 Vector pos = mob->GetPosition();
77 mob->SetPosition(pos);
78 Simulator::Schedule(Seconds(1), AdvancePosition, node);
83 ns.CommandLine().Parse(argv)
85 ns.Packet.EnablePrinting()
87 wifi = ns.WifiHelper()
88 mobility = ns.MobilityHelper()
89 stas = ns.NodeContainer()
90 ap = ns.NodeContainer()
92 packetSocket = ns.PacketSocketHelper()
98 packetSocket.Install(stas)
99 packetSocket.Install(ap)
101 wifiPhy = ns.YansWifiPhyHelper()
102 wifiChannel = ns.YansWifiChannelHelper.Default()
103 wifiPhy.SetChannel(wifiChannel.Create())
105 ssid = ns.Ssid(
"wifi-default")
106 wifiMac = ns.WifiMacHelper()
112 ns.BooleanValue(
True),
116 staDevs = wifi.Install(wifiPhy, wifiMac, stas)
118 wifiMac.SetType(
"ns3::ApWifiMac",
"Ssid", ns.SsidValue(ssid))
119 wifi.Install(wifiPhy, wifiMac, ap)
122 mobility.Install(stas)
125 ns.Simulator.Schedule(ns.Seconds(1), ns.cppyy.gbl.AdvancePosition, ap.Get(0))
127 socket = ns.PacketSocketAddress()
128 socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
129 socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
130 socket.SetProtocol(1)
132 onoff = ns.OnOffHelper(
"ns3::PacketSocketFactory", socket.ConvertTo())
133 onoff.SetConstantRate(ns.DataRate(
"500kb/s"))
135 apps = onoff.Install(ns.NodeContainer(stas.Get(0)))
136 apps.Start(ns.Seconds(0.5))
137 apps.Stop(ns.Seconds(43))
139 ns.Simulator.Stop(ns.Seconds(44))
149 ns.Simulator.Destroy()
154if __name__ ==
"__main__":
155 sys.exit(main(sys.argv))