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();
103 ns.core.Config.SetDefault(
"ns3::WifiRemoteStationManager::RtsCtsThreshold", ns.core.StringValue(
"0"))
105 ns.core.Config.SetDefault(
"ns3::WifiRemoteStationManager::FragmentationThreshold", ns.core.StringValue(
"2200"))
107 wifi = ns.wifi.WifiHelper()
108 mobility = ns.mobility.MobilityHelper()
109 stas = ns.network.NodeContainer()
110 ap = ns.network.NodeContainer()
112 packetSocket = ns.network.PacketSocketHelper()
118 packetSocket.Install(stas)
119 packetSocket.Install(ap)
121 wifiPhy = ns.wifi.YansWifiPhyHelper.Default()
122 wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
123 wifiPhy.SetChannel(wifiChannel.Create())
125 ssid = ns.wifi.Ssid(
"wifi-default")
126 wifi.SetRemoteStationManager(
"ns3::ArfWifiManager")
127 wifiMac = ns.wifi.WifiMacHelper()
130 wifiMac.SetType(
"ns3::StaWifiMac",
131 "Ssid", ns.wifi.SsidValue(ssid))
132 staDevs = wifi.Install(wifiPhy, wifiMac, stas)
134 wifiMac.SetType(
"ns3::ApWifiMac",
135 "Ssid", ns.wifi.SsidValue(ssid),
136 "BeaconInterval", ns.core.TimeValue(ns.core.Seconds(2.5)))
137 wifi.Install(wifiPhy, wifiMac, ap)
140 mobility.Install(stas)
143 ns.core.Simulator.Schedule(ns.core.Seconds(1.0), AdvancePosition, ap.Get(0))
145 socket = ns.network.PacketSocketAddress()
146 socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
147 socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
148 socket.SetProtocol(1)
150 onoff = ns.applications.OnOffHelper(
"ns3::PacketSocketFactory", ns.network.Address(socket))
151 onoff.SetConstantRate (ns.network.DataRate (
"500kb/s"))
153 apps = onoff.Install(ns.network.NodeContainer(stas.Get(0)))
154 apps.Start(ns.core.Seconds(0.5))
155 apps.Stop(ns.core.Seconds(43.0))
157 ns.core.Simulator.Stop(ns.core.Seconds(44.0))
167 ns.core.Simulator.Run()
168 ns.core.Simulator.Destroy()
173 if __name__ ==
'__main__':
174 sys.exit(main(sys.argv))
def AdvancePosition(node)
def SetPosition(node, position)