25 import ns.applications
30 import ns.point_to_point
80 mobility = node.GetObject(ns.mobility.MobilityModel.GetTypeId())
81 mobility.SetPosition(position)
85 mobility = node.GetObject(ns.mobility.MobilityModel.GetTypeId())
86 return mobility.GetPosition()
94 ns.core.Simulator.Schedule(ns.core.Seconds(1.0), AdvancePosition, node)
98 ns.core.CommandLine().Parse(argv)
100 ns.network.Packet.EnablePrinting();
102 wifi = ns.wifi.WifiHelper()
103 mobility = ns.mobility.MobilityHelper()
104 stas = ns.network.NodeContainer()
105 ap = ns.network.NodeContainer()
107 packetSocket = ns.network.PacketSocketHelper()
113 packetSocket.Install(stas)
114 packetSocket.Install(ap)
116 wifiPhy = ns.wifi.YansWifiPhyHelper()
117 wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
118 wifiPhy.SetChannel(wifiChannel.Create())
120 ssid = ns.wifi.Ssid(
"wifi-default")
121 wifi.SetRemoteStationManager(
"ns3::ArfWifiManager")
122 wifiMac = ns.wifi.WifiMacHelper()
125 wifiMac.SetType(
"ns3::StaWifiMac",
126 "Ssid", ns.wifi.SsidValue(ssid))
127 staDevs = wifi.Install(wifiPhy, wifiMac, stas)
129 wifiMac.SetType(
"ns3::ApWifiMac",
130 "Ssid", ns.wifi.SsidValue(ssid))
131 wifi.Install(wifiPhy, wifiMac, ap)
134 mobility.Install(stas)
137 ns.core.Simulator.Schedule(ns.core.Seconds(1.0), AdvancePosition, ap.Get(0))
139 socket = ns.network.PacketSocketAddress()
140 socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
141 socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
142 socket.SetProtocol(1)
144 onoff = ns.applications.OnOffHelper(
"ns3::PacketSocketFactory", ns.network.Address(socket))
145 onoff.SetConstantRate (ns.network.DataRate (
"500kb/s"))
147 apps = onoff.Install(ns.network.NodeContainer(stas.Get(0)))
148 apps.Start(ns.core.Seconds(0.5))
149 apps.Stop(ns.core.Seconds(43.0))
151 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))
def AdvancePosition(node)
def SetPosition(node, position)