27 except ModuleNotFoundError:
29 "Error: ns3 Python module not found;"
30 " Python bindings may not be enabled"
31 " or your PYTHONPATH might not be properly configured"
83 void AdvancePosition(Ptr<Node> node){
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.core.CommandLine().Parse(argv)
98 ns.network.Packet.EnablePrinting()
100 wifi = ns.wifi.WifiHelper()
101 mobility = ns.mobility.MobilityHelper()
102 stas = ns.network.NodeContainer()
103 ap = ns.network.NodeContainer()
105 packetSocket = ns.network.PacketSocketHelper()
111 packetSocket.Install(stas)
112 packetSocket.Install(ap)
114 wifiPhy = ns.wifi.YansWifiPhyHelper()
115 wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
116 wifiPhy.SetChannel(wifiChannel.Create())
118 ssid = ns.wifi.Ssid(
"wifi-default")
119 wifiMac = ns.wifi.WifiMacHelper()
125 ns.core.BooleanValue(
True),
127 ns.wifi.SsidValue(ssid),
129 staDevs = wifi.Install(wifiPhy, wifiMac, stas)
131 wifiMac.SetType(
"ns3::ApWifiMac",
"Ssid", ns.wifi.SsidValue(ssid))
132 wifi.Install(wifiPhy, wifiMac, ap)
135 mobility.Install(stas)
138 ns.core.Simulator.Schedule(ns.core.Seconds(1.0), ns.cppyy.gbl.AdvancePosition, ap.Get(0))
140 socket = ns.network.PacketSocketAddress()
141 socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
142 socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
143 socket.SetProtocol(1)
145 onoff = ns.applications.OnOffHelper(
"ns3::PacketSocketFactory", socket.ConvertTo())
146 onoff.SetConstantRate(ns.network.DataRate(
"500kb/s"))
148 apps = onoff.Install(ns.network.NodeContainer(stas.Get(0)))
149 apps.Start(ns.core.Seconds(0.5))
150 apps.Stop(ns.core.Seconds(43.0))
152 ns.core.Simulator.Stop(ns.core.Seconds(44.0))
161 ns.core.Simulator.Run()
162 ns.core.Simulator.Destroy()
167 if __name__ ==
"__main__":
168 sys.exit(main(sys.argv))