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.Default()
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 "BeaconInterval", ns.core.TimeValue(ns.core.Seconds(2.5)))
132 wifi.Install(wifiPhy, wifiMac, ap)
135 mobility.Install(stas)
138 ns.core.Simulator.Schedule(ns.core.Seconds(1.0), 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", ns.network.Address(socket))
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))
162 ns.core.Simulator.Run()
163 ns.core.Simulator.Destroy()
168 if __name__ ==
'__main__':
169 sys.exit(main(sys.argv))
def AdvancePosition(node)
def SetPosition(node, position)