54 import ns.applications
87 ns.core.Config.SetDefault(
"ns3::OnOffApplication::PacketSize", ns.core.StringValue(
"210"))
88 ns.core.Config.SetDefault(
"ns3::OnOffApplication::DataRate", ns.core.StringValue(
"448kb/s"))
95 cmd = ns.core.CommandLine()
117 backbone = ns.network.NodeContainer()
118 backbone.Create(backboneNodes)
123 wifi = ns.wifi.WifiHelper()
124 mac = ns.wifi.NqosWifiMacHelper.Default()
125 mac.SetType(
"ns3::AdhocWifiMac")
126 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
127 "DataMode", ns.core.StringValue(
"OfdmRate54Mbps"))
128 wifiPhy = ns.wifi.YansWifiPhyHelper.Default()
129 wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
130 wifiPhy.SetChannel(wifiChannel.Create())
131 backboneDevices = wifi.Install(wifiPhy, mac, backbone)
135 print "Enabling OLSR routing on all backbone nodes"
136 internet = ns.internet.InternetStackHelper()
137 olsr = ns.olsr.OlsrHelper()
138 internet.SetRoutingHelper(olsr);
139 internet.Install(backbone);
146 ipAddrs = ns.internet.Ipv4AddressHelper()
147 ipAddrs.SetBase(ns.network.Ipv4Address(
"192.168.0.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
148 ipAddrs.Assign(backboneDevices)
154 mobility = ns.mobility.MobilityHelper()
155 positionAlloc = ns.mobility.ListPositionAllocator()
157 for i
in range(backboneNodes):
158 positionAlloc.Add(ns.core.Vector(x, 0.0, 0.0))
160 mobility.SetPositionAllocator(positionAlloc)
161 mobility.SetMobilityModel(
"ns3::RandomDirection2dMobilityModel",
162 "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(0, 1000, 0, 1000)),
163 "Speed", ns.core.StringValue (
"ns3::ConstantRandomVariable[Constant=2000]"),
164 "Pause", ns.core.StringValue (
"ns3::ConstantRandomVariable[Constant=0.2]"))
165 mobility.Install(backbone)
175 ipAddrs.SetBase(ns.network.Ipv4Address(
"172.16.0.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
177 for i
in range(backboneNodes):
178 print "Configuring local area network for backbone node ", i
184 newLanNodes = ns.network.NodeContainer()
185 newLanNodes.Create(lanNodes - 1)
187 lan = ns.network.NodeContainer(ns.network.NodeContainer(backbone.Get(i)), newLanNodes)
192 csma = ns.csma.CsmaHelper()
193 csma.SetChannelAttribute(
"DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000)))
194 csma.SetChannelAttribute(
"Delay", ns.core.TimeValue(ns.core.MilliSeconds(2)))
195 lanDevices = csma.Install(lan)
199 internet.Install(newLanNodes)
204 ipAddrs.Assign(lanDevices)
219 ipAddrs.SetBase(ns.network.Ipv4Address(
"10.0.0.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
221 for i
in range(backboneNodes):
222 print "Configuring wireless network for backbone node ", i
228 stas = ns.network.NodeContainer()
229 stas.Create(infraNodes - 1)
231 infra = ns.network.NodeContainer(ns.network.NodeContainer(backbone.Get(i)), stas)
235 ssid = ns.wifi.Ssid(
'wifi-infra' + str(i))
236 wifiInfra = ns.wifi.WifiHelper.Default()
237 wifiPhy.SetChannel(wifiChannel.Create())
238 wifiInfra.SetRemoteStationManager(
'ns3::ArfWifiManager')
239 macInfra = ns.wifi.NqosWifiMacHelper.Default();
240 macInfra.SetType(
"ns3::StaWifiMac",
241 "Ssid", ns.wifi.SsidValue(ssid),
242 "ActiveProbing", ns.core.BooleanValue(
False))
245 staDevices = wifiInfra.Install(wifiPhy, macInfra, stas)
247 macInfra.SetType(
"ns3::ApWifiMac",
248 "Ssid", ns.wifi.SsidValue(ssid),
249 "BeaconGeneration", ns.core.BooleanValue(
True),
250 "BeaconInterval", ns.core.TimeValue(ns.core.Seconds(2.5)))
251 apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i))
253 infraDevices = ns.network.NetDeviceContainer(apDevices, staDevices)
257 internet.Install(stas)
262 ipAddrs.Assign(infraDevices)
272 subnetAlloc = ns.mobility.ListPositionAllocator()
273 for j
in range(infra.GetN()):
274 subnetAlloc.Add(ns.core.Vector(0.0, j, 0.0))
276 mobility.PushReferenceMobilityModel(backbone.Get(i))
277 mobility.SetPositionAllocator(subnetAlloc)
278 mobility.SetMobilityModel(
"ns3::RandomDirection2dMobilityModel",
279 "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(-25, 25, -25, 25)),
280 "Speed", ns.core.StringValue (
"ns3::ConstantRandomVariable[Constant=30]"),
281 "Pause", ns.core.StringValue (
"ns3::ConstantRandomVariable[Constant=0.4]"))
282 mobility.Install(infra)
292 print "Create Applications."
297 assert(lanNodes >= 5)
298 appSource = ns.network.NodeList.GetNode(11)
299 appSink = ns.network.NodeList.GetNode(13)
300 remoteAddr = ns.network.Ipv4Address(
"172.16.0.5")
302 onoff = ns.applications.OnOffHelper(
"ns3::UdpSocketFactory",
303 ns.network.Address(ns.network.InetSocketAddress(remoteAddr, port)))
304 onoff.SetConstantRate (ns.network.DataRate (
"10kb/s"))
305 apps = onoff.Install(ns.network.NodeContainer(appSource))
306 apps.Start(ns.core.Seconds(3.0))
307 apps.Stop(ns.core.Seconds(20.0))
310 sink = ns.applications.PacketSinkHelper(
"ns3::UdpSocketFactory",
311 ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port))
312 apps = sink.Install(ns.network.NodeContainer(appSink))
313 apps.Start(ns.core.Seconds(3.0))
321 print "Configure Tracing."
330 print "(tracing not done for Python)"
336 wifiPhy.EnablePcap(
"mixed-wireless", backboneDevices)
338 csma = ns.csma.CsmaHelper()
339 csma.EnablePcapAll(
"mixed-wireless",
False)
353 print "Run Simulation."
354 ns.core.Simulator.Stop(ns.core.Seconds(stopTime))
355 ns.core.Simulator.Run()
356 ns.core.Simulator.Destroy()
359 if __name__ ==
'__main__':