A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
brite-generic-example.py
Go to the documentation of this file.
2# Copyright (c) 2012 The Georgia Institute of Technology
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6# Author: Brian Swenson <bswenson3@gatech.edu>
7# Modified by: Gabriel Ferreira <gabrielcarvfer@gmail.com>
8#
9
10try:
11 from ns import ns
12except ModuleNotFoundError:
13 raise SystemExit(
14 "Error: ns3 Python module not found;"
15 " Python bindings may not be enabled"
16 " or your PYTHONPATH might not be properly configured"
17 )
18
19ns.LogComponentEnable("BriteTopologyHelper", ns.LOG_LEVEL_ALL)
20
21# BRITE needs a configuration file to build its graph. By default, this
22# example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others
23# which can be found in the BRITE/conf_files directory
24confFile = "src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"
25
26# Invoke the BriteTopologyHelper and pass in a BRITE
27# configuration file and a seed file. This will use
28# BRITE to build a graph from which we can build the ns-3 topology
29bth = ns.BriteTopologyHelper(confFile)
30bth.AssignStreams(3)
31
32p2p = ns.PointToPointHelper()
33
34stack = ns.InternetStackHelper()
35
36nixRouting = ns.Ipv4NixVectorHelper()
37stack.SetRoutingHelper(nixRouting)
38
39address = ns.Ipv4AddressHelper()
40address.SetBase("10.0.0.0", "255.255.255.252")
41
42bth.BuildBriteTopology(stack)
43bth.AssignIpv4Addresses(address)
44
45print(f"Number of AS created {bth.GetNAs()}")
46
47# The BRITE topology generator generates a topology of routers. Here we create
48# two subnetworks which we attach to router leaf nodes generated by BRITE
49# use just one node
50client = ns.NodeContainer()
51server = ns.NodeContainer()
52
53client.Create(1)
54stack.Install(client)
55
56# install client node on last leaf node of AS 0
57numLeafNodesInAsZero = bth.GetNLeafNodesForAs(0)
58client.Add(bth.GetLeafNodeForAs(0, numLeafNodesInAsZero - 1))
59
60server.Create(1)
61stack.Install(server)
62
63# install server node on last leaf node on AS 1
64numLeafNodesInAsOne = bth.GetNLeafNodesForAs(1)
65server.Add(bth.GetLeafNodeForAs(1, numLeafNodesInAsOne - 1))
66
67p2p.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps"))
68p2p.SetChannelAttribute("Delay", ns.StringValue("2ms"))
69
70p2pClientDevices = p2p.Install(client)
71p2pServerDevices = p2p.Install(server)
72
73address.SetBase("10.1.0.0", "255.255.0.0")
74clientInterfaces = address.Assign(p2pClientDevices)
75
76address.SetBase("10.2.0.0", "255.255.0.0")
77serverInterfaces = ns.Ipv4InterfaceContainer()
78serverInterfaces = address.Assign(p2pServerDevices)
79
80echoServer = ns.UdpEchoServerHelper(9)
81serverApps = echoServer.Install(server.Get(0))
82serverApps.Start(ns.Seconds(1.0))
83serverApps.Stop(ns.Seconds(5.0))
84
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))
89
90clientApps = echoClient.Install(client.Get(0))
91clientApps.Start(ns.Seconds(2.0))
92clientApps.Stop(ns.Seconds(5.0))
93
94asciiTrace = ns.AsciiTraceHelper()
95p2p.EnableAsciiAll(asciiTrace.CreateFileStream("briteLeaves.tr"))
96
97# Run the simulator
98ns.Simulator.Stop(ns.Seconds(6.0))
99ns.Simulator.Run()
100ns.Simulator.Destroy()