23 except ModuleNotFoundError:
25 "Error: ns3 Python module not found;"
26 " Python bindings may not be enabled"
27 " or your PYTHONPATH might not be properly configured"
32 ns.core.CommandLine().Parse(argv)
39 ns.core.GlobalValue.Bind(
40 "SimulatorImplementationType", ns.core.StringValue(
"ns3::RealtimeSimulatorImpl")
42 ns.core.GlobalValue.Bind(
"ChecksumEnabled", ns.core.BooleanValue(
True))
49 nodes = ns.network.NodeContainer()
55 wifi = ns.wifi.WifiHelper()
56 wifi.SetStandard(ns.wifi.WIFI_STANDARD_80211a)
57 wifi.SetRemoteStationManager(
58 "ns3::ConstantRateWifiManager",
"DataMode", ns.core.StringValue(
"OfdmRate54Mbps")
64 wifiMac = ns.wifi.WifiMacHelper()
65 wifiMac.SetType(
"ns3::AdhocWifiMac")
70 wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
71 wifiPhy = ns.wifi.YansWifiPhyHelper()
72 wifiPhy.SetChannel(wifiChannel.Create())
77 devices = wifi.Install(wifiPhy, wifiMac, nodes)
83 mobility = ns.mobility.MobilityHelper()
84 positionAlloc = ns.mobility.ListPositionAllocator()
85 positionAlloc.Add(ns.core.Vector(0.0, 0.0, 0.0))
86 positionAlloc.Add(ns.core.Vector(5.0, 0.0, 0.0))
87 mobility.SetPositionAllocator(positionAlloc)
88 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel")
89 mobility.Install(nodes)
99 tapBridge = ns.tap_bridge.TapBridgeHelper()
100 tapBridge.SetAttribute(
"Mode", ns.core.StringValue(
"UseLocal"))
101 tapBridge.SetAttribute(
"DeviceName", ns.core.StringValue(
"tap-left"))
102 tapBridge.Install(nodes.Get(0), devices.Get(0))
108 tapBridge.SetAttribute(
"DeviceName", ns.core.StringValue(
"tap-right"))
109 tapBridge.Install(nodes.Get(1), devices.Get(1))
114 ns.core.Simulator.Stop(ns.core.Seconds(600))
115 ns.core.Simulator.Run()
116 ns.core.Simulator.Destroy()
120 if __name__ ==
"__main__":
121 sys.exit(main(sys.argv))