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
21from ns import ns
22
23ns.LogComponentEnable("BriteTopologyHelper", ns.LOG_LEVEL_ALL)
24
25# BRITE needs a configuration file to build its graph. By default, this
26# example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others
27# which can be found in the BRITE/conf_files directory
28confFile = "src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"
29
30# Invoke the BriteTopologyHelper and pass in a BRITE
31# configuration file and a seed file. This will use
32# BRITE to build a graph from which we can build the ns-3 topology
33bth = ns.BriteTopologyHelper(confFile)
34bth.AssignStreams(3)
35
36p2p = ns.PointToPointHelper()
37
38stack = ns.InternetStackHelper()
39
40nixRouting = ns.Ipv4NixVectorHelper()
41stack.SetRoutingHelper(nixRouting)
42
43address = ns.Ipv4AddressHelper()
44address.SetBase("10.0.0.0", "255.255.255.252")
45
46bth.BuildBriteTopology(stack)
47bth.AssignIpv4Addresses(address)
48
49print(f"Number of AS created {bth.GetNAs()}")
50
51# The BRITE topology generator generates a topology of routers. Here we create
52# two subnetworks which we attach to router leaf nodes generated by BRITE
53# use just one node
54client = ns.NodeContainer()
55server = ns.NodeContainer()
56
57client.Create(1)
58stack.Install(client)
59
60# install client node on last leaf node of AS 0
61numLeafNodesInAsZero = bth.GetNLeafNodesForAs(0)
62client.Add(bth.GetLeafNodeForAs(0, numLeafNodesInAsZero - 1))
63
64server.Create(1)
65stack.Install(server)
66
67# install server node on last leaf node on AS 1
68numLeafNodesInAsOne = bth.GetNLeafNodesForAs(1)
69server.Add(bth.GetLeafNodeForAs(1, numLeafNodesInAsOne - 1))
70
71p2p.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps"))
72p2p.SetChannelAttribute("Delay", ns.StringValue("2ms"))
73
74p2pClientDevices = p2p.Install(client)
75p2pServerDevices = p2p.Install(server)
76
77address.SetBase("10.1.0.0", "255.255.0.0")
78clientInterfaces = address.Assign(p2pClientDevices)
79
80address.SetBase("10.2.0.0", "255.255.0.0")
81serverInterfaces = ns.Ipv4InterfaceContainer()
82serverInterfaces = address.Assign(p2pServerDevices)
83
84echoServer = ns.UdpEchoServerHelper(9)
85serverApps = echoServer.Install(server.Get(0))
86serverApps.Start(ns.Seconds(1.0))
87serverApps.Stop(ns.Seconds(5.0))
88
89echoClient = ns.UdpEchoClientHelper(serverInterfaces.GetAddress(0).ConvertTo(), 9)
90echoClient.SetAttribute("MaxPackets", ns.UintegerValue(1))
91echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1.)))
92echoClient.SetAttribute("PacketSize", ns.UintegerValue(1024))
93
94clientApps = echoClient.Install(client.Get(0))
95clientApps.Start(ns.Seconds(2.0))
96clientApps.Stop(ns.Seconds(5.0))
97
98asciiTrace = ns.AsciiTraceHelper()
99p2p.EnableAsciiAll(asciiTrace.CreateFileStream("briteLeaves.tr"))
100
101# Run the simulator
102ns.Simulator.Stop(ns.Seconds(6.0))
103ns.Simulator.Run()
104ns.Simulator.Destroy()