12except ModuleNotFoundError:
14 "Error: ns3 Python module not found;"
15 " Python bindings may not be enabled"
16 " or your PYTHONPATH might not be properly configured"
19ns.LogComponentEnable(
"BriteTopologyHelper", ns.LOG_LEVEL_ALL)
24confFile =
"src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"
29bth = ns.BriteTopologyHelper(confFile)
32p2p = ns.PointToPointHelper()
34stack = ns.InternetStackHelper()
36nixRouting = ns.Ipv4NixVectorHelper()
37stack.SetRoutingHelper(nixRouting)
39address = ns.Ipv4AddressHelper()
40address.SetBase(
"10.0.0.0",
"255.255.255.252")
42bth.BuildBriteTopology(stack)
43bth.AssignIpv4Addresses(address)
45print(f
"Number of AS created {bth.GetNAs()}")
50client = ns.NodeContainer()
51server = ns.NodeContainer()
57numLeafNodesInAsZero = bth.GetNLeafNodesForAs(0)
58client.Add(bth.GetLeafNodeForAs(0, numLeafNodesInAsZero - 1))
64numLeafNodesInAsOne = bth.GetNLeafNodesForAs(1)
65server.Add(bth.GetLeafNodeForAs(1, numLeafNodesInAsOne - 1))
67p2p.SetDeviceAttribute(
"DataRate", ns.StringValue(
"5Mbps"))
68p2p.SetChannelAttribute(
"Delay", ns.StringValue(
"2ms"))
70p2pClientDevices = p2p.Install(client)
71p2pServerDevices = p2p.Install(server)
73address.SetBase(
"10.1.0.0",
"255.255.0.0")
74clientInterfaces = address.Assign(p2pClientDevices)
76address.SetBase(
"10.2.0.0",
"255.255.0.0")
77serverInterfaces = ns.Ipv4InterfaceContainer()
78serverInterfaces = address.Assign(p2pServerDevices)
80echoServer = ns.UdpEchoServerHelper(9)
81serverApps = echoServer.Install(server.Get(0))
82serverApps.Start(ns.Seconds(1.0))
83serverApps.Stop(ns.Seconds(5.0))
85echoClient = ns.UdpEchoClientHelper(serverInterfaces.GetAddress(0).ConvertTo(), 9)
86echoClient.SetAttribute(
"MaxPackets", ns.UintegerValue(1))
87echoClient.SetAttribute(
"Interval", ns.TimeValue(ns.Seconds(1.0)))
88echoClient.SetAttribute(
"PacketSize", ns.UintegerValue(1024))
90clientApps = echoClient.Install(client.Get(0))
91clientApps.Start(ns.Seconds(2.0))
92clientApps.Stop(ns.Seconds(5.0))
94asciiTrace = ns.AsciiTraceHelper()
95p2p.EnableAsciiAll(asciiTrace.CreateFileStream(
"briteLeaves.tr"))
98ns.Simulator.Stop(ns.Seconds(6.0))
100ns.Simulator.Destroy()