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"
72 void AdvancePosition(Ptr<Node> node){
73 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
74 Vector pos = mob->GetPosition();
78 mob->SetPosition(pos);
79 Simulator::Schedule(Seconds(1.0), AdvancePosition, node);
85 ns.CommandLine().Parse(argv)
87 ns.Packet.EnablePrinting()
89 wifi = ns.WifiHelper()
90 mobility = ns.MobilityHelper()
91 stas = ns.NodeContainer()
92 ap = ns.NodeContainer()
94 packetSocket = ns.PacketSocketHelper()
100 packetSocket.Install(stas)
101 packetSocket.Install(ap)
103 wifiPhy = ns.YansWifiPhyHelper()
104 wifiChannel = ns.YansWifiChannelHelper.Default()
105 wifiPhy.SetChannel(wifiChannel.Create())
107 ssid = ns.Ssid(
"wifi-default")
108 wifiMac = ns.WifiMacHelper()
114 ns.BooleanValue(
True),
118 staDevs = wifi.Install(wifiPhy, wifiMac, stas)
120 wifiMac.SetType(
"ns3::ApWifiMac",
"Ssid", ns.SsidValue(ssid))
121 wifi.Install(wifiPhy, wifiMac, ap)
124 mobility.Install(stas)
127 ns.Simulator.Schedule(ns.Seconds(1.0), ns.cppyy.gbl.AdvancePosition, ap.Get(0))
129 socket = ns.PacketSocketAddress()
130 socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
131 socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
132 socket.SetProtocol(1)
134 onoff = ns.OnOffHelper(
"ns3::PacketSocketFactory", socket.ConvertTo())
135 onoff.SetConstantRate(ns.DataRate(
"500kb/s"))
137 apps = onoff.Install(ns.NodeContainer(stas.Get(0)))
138 apps.Start(ns.Seconds(0.5))
139 apps.Stop(ns.Seconds(43.0))
141 ns.Simulator.Stop(ns.Seconds(44.0))
151 ns.Simulator.Destroy()
156if __name__ ==
"__main__":
157 sys.exit(main(sys.argv))