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# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 2 as
6# published by the Free Software Foundation;
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16#
17# Author: Brian Swenson <bswenson3@gatech.edu>
18# Modified by: Gabriel Ferreira <gabrielcarvfer@gmail.com>
19#
20
21try:
22 from ns import ns
23except ModuleNotFoundError:
24 raise SystemExit(
25 "Error: ns3 Python module not found;"
26 " Python bindings may not be enabled"
27 " or your PYTHONPATH might not be properly configured"
28 )
29
30ns.LogComponentEnable("BriteTopologyHelper", ns.LOG_LEVEL_ALL)
31
32# BRITE needs a configuration file to build its graph. By default, this
33# example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others
34# which can be found in the BRITE/conf_files directory
35confFile = "src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"
36
37# Invoke the BriteTopologyHelper and pass in a BRITE
38# configuration file and a seed file. This will use
39# BRITE to build a graph from which we can build the ns-3 topology
40bth = ns.BriteTopologyHelper(confFile)
41bth.AssignStreams(3)
42
43p2p = ns.PointToPointHelper()
44
45stack = ns.InternetStackHelper()
46
47nixRouting = ns.Ipv4NixVectorHelper()
48stack.SetRoutingHelper(nixRouting)
49
50address = ns.Ipv4AddressHelper()
51address.SetBase("10.0.0.0", "255.255.255.252")
52
53bth.BuildBriteTopology(stack)
54bth.AssignIpv4Addresses(address)
55
56print(f"Number of AS created {bth.GetNAs()}")
57
58# The BRITE topology generator generates a topology of routers. Here we create
59# two subnetworks which we attach to router leaf nodes generated by BRITE
60# use just one node
61client = ns.NodeContainer()
62server = ns.NodeContainer()
63
64client.Create(1)
65stack.Install(client)
66
67# install client node on last leaf node of AS 0
68numLeafNodesInAsZero = bth.GetNLeafNodesForAs(0)
69client.Add(bth.GetLeafNodeForAs(0, numLeafNodesInAsZero - 1))
70
71server.Create(1)
72stack.Install(server)
73
74# install server node on last leaf node on AS 1
75numLeafNodesInAsOne = bth.GetNLeafNodesForAs(1)
76server.Add(bth.GetLeafNodeForAs(1, numLeafNodesInAsOne - 1))
77
78p2p.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps"))
79p2p.SetChannelAttribute("Delay", ns.StringValue("2ms"))
80
81p2pClientDevices = p2p.Install(client)
82p2pServerDevices = p2p.Install(server)
83
84address.SetBase("10.1.0.0", "255.255.0.0")
85clientInterfaces = address.Assign(p2pClientDevices)
86
87address.SetBase("10.2.0.0", "255.255.0.0")
88serverInterfaces = ns.Ipv4InterfaceContainer()
89serverInterfaces = address.Assign(p2pServerDevices)
90
91echoServer = ns.UdpEchoServerHelper(9)
92serverApps = echoServer.Install(server.Get(0))
93serverApps.Start(ns.Seconds(1.0))
94serverApps.Stop(ns.Seconds(5.0))
95
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))
100
101clientApps = echoClient.Install(client.Get(0))
102clientApps.Start(ns.Seconds(2.0))
103clientApps.Stop(ns.Seconds(5.0))
104
105asciiTrace = ns.AsciiTraceHelper()
106p2p.EnableAsciiAll(asciiTrace.CreateFileStream("briteLeaves.tr"))
107
108# Run the simulator
109ns.Simulator.Stop(ns.Seconds(6.0))
110ns.Simulator.Run()
111ns.Simulator.Destroy()