23except ModuleNotFoundError:
25 "Error: ns3 Python module not found;"
26 " Python bindings may not be enabled"
27 " or your PYTHONPATH might not be properly configured"
30ns.LogComponentEnable(
"BriteTopologyHelper", ns.LOG_LEVEL_ALL)
35confFile =
"src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"
40bth = ns.BriteTopologyHelper(confFile)
43p2p = ns.PointToPointHelper()
45stack = ns.InternetStackHelper()
47nixRouting = ns.Ipv4NixVectorHelper()
48stack.SetRoutingHelper(nixRouting)
50address = ns.Ipv4AddressHelper()
51address.SetBase(
"10.0.0.0",
"255.255.255.252")
53bth.BuildBriteTopology(stack)
54bth.AssignIpv4Addresses(address)
56print(f
"Number of AS created {bth.GetNAs()}")
61client = ns.NodeContainer()
62server = ns.NodeContainer()
68numLeafNodesInAsZero = bth.GetNLeafNodesForAs(0)
69client.Add(bth.GetLeafNodeForAs(0, numLeafNodesInAsZero - 1))
75numLeafNodesInAsOne = bth.GetNLeafNodesForAs(1)
76server.Add(bth.GetLeafNodeForAs(1, numLeafNodesInAsOne - 1))
78p2p.SetDeviceAttribute(
"DataRate", ns.StringValue(
"5Mbps"))
79p2p.SetChannelAttribute(
"Delay", ns.StringValue(
"2ms"))
81p2pClientDevices = p2p.Install(client)
82p2pServerDevices = p2p.Install(server)
84address.SetBase(
"10.1.0.0",
"255.255.0.0")
85clientInterfaces = address.Assign(p2pClientDevices)
87address.SetBase(
"10.2.0.0",
"255.255.0.0")
88serverInterfaces = ns.Ipv4InterfaceContainer()
89serverInterfaces = address.Assign(p2pServerDevices)
91echoServer = ns.UdpEchoServerHelper(9)
92serverApps = echoServer.Install(server.Get(0))
93serverApps.Start(ns.Seconds(1.0))
94serverApps.Stop(ns.Seconds(5.0))
96echoClient = ns.UdpEchoClientHelper(serverInterfaces.GetAddress(0).ConvertTo(), 9)
97echoClient.SetAttribute(
"MaxPackets", ns.UintegerValue(1))
98echoClient.SetAttribute(
"Interval", ns.TimeValue(ns.Seconds(1.0)))
99echoClient.SetAttribute(
"PacketSize", ns.UintegerValue(1024))
101clientApps = echoClient.Install(client.Get(0))
102clientApps.Start(ns.Seconds(2.0))
103clientApps.Stop(ns.Seconds(5.0))
105asciiTrace = ns.AsciiTraceHelper()
106p2p.EnableAsciiAll(asciiTrace.CreateFileStream(
"briteLeaves.tr"))
109ns.Simulator.Stop(ns.Seconds(6.0))
111ns.Simulator.Destroy()