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