A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
brite-generic-example.cc
Go to the documentation of this file.
1/*
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 */
8
9#include "Brite.h"
10
11#include "ns3/applications-module.h"
12#include "ns3/brite-module.h"
13#include "ns3/core-module.h"
14#include "ns3/internet-module.h"
15#include "ns3/mobility-module.h"
16#include "ns3/network-module.h"
17#include "ns3/nix-vector-helper.h"
18#include "ns3/point-to-point-module.h"
19
20#include <fstream>
21#include <iostream>
22#include <string>
23
24using namespace ns3;
25
26NS_LOG_COMPONENT_DEFINE("BriteExample");
27
28int
29main(int argc, char* argv[])
30{
31 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
32 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
33
34 LogComponentEnable("BriteExample", LOG_LEVEL_ALL);
35
36 // BRITE needs a configuration file to build its graph. By default, this
37 // example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others
38 // which can be found in the BRITE/conf_files directory
39 std::string confFile = "src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf";
40 bool tracing = false;
41 bool nix = false;
42
43 CommandLine cmd(__FILE__);
44 cmd.AddValue("confFile", "BRITE conf file", confFile);
45 cmd.AddValue("tracing", "Enable or disable ascii tracing", tracing);
46 cmd.AddValue("nix", "Enable or disable nix-vector routing", nix);
47
48 cmd.Parse(argc, argv);
49
50 nix = false;
51
52 // Invoke the BriteTopologyHelper and pass in a BRITE
53 // configuration file and a seed file. This will use
54 // BRITE to build a graph from which we can build the ns-3 topology
55 BriteTopologyHelper bth(confFile);
56 bth.AssignStreams(3);
57
59
61
62 if (nix)
63 {
65 stack.SetRoutingHelper(nixRouting);
66 }
67
69 address.SetBase("10.0.0.0", "255.255.255.252");
70
71 bth.BuildBriteTopology(stack);
72 bth.AssignIpv4Addresses(address);
73
74 NS_LOG_INFO("Number of AS created " << bth.GetNAs());
75
76 // The BRITE topology generator generates a topology of routers. Here we create
77 // two subnetworks which we attach to router leaf nodes generated by BRITE
78 // Any NS3 topology may be used to attach to the BRITE leaf nodes but here we
79 // use just one node
80
83
84 client.Create(1);
85 stack.Install(client);
86
87 // install client node on last leaf node of AS 0
88 int numLeafNodesInAsZero = bth.GetNLeafNodesForAs(0);
89 client.Add(bth.GetLeafNodeForAs(0, numLeafNodesInAsZero - 1));
90
91 server.Create(1);
92 stack.Install(server);
93
94 // install server node on last leaf node on AS 1
95 int numLeafNodesInAsOne = bth.GetNLeafNodesForAs(1);
96 server.Add(bth.GetLeafNodeForAs(1, numLeafNodesInAsOne - 1));
97
98 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
99 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
100
103
104 p2pClientDevices = p2p.Install(client);
105 p2pServerDevices = p2p.Install(server);
106
107 address.SetBase("10.1.0.0", "255.255.0.0");
109 clientInterfaces = address.Assign(p2pClientDevices);
110
111 address.SetBase("10.2.0.0", "255.255.0.0");
113 serverInterfaces = address.Assign(p2pServerDevices);
114
117 serverApps.Start(Seconds(1.0));
118 serverApps.Stop(Seconds(5.0));
119
121 echoClient.SetAttribute("MaxPackets", UintegerValue(1));
122 echoClient.SetAttribute("Interval", TimeValue(Seconds(1.)));
123 echoClient.SetAttribute("PacketSize", UintegerValue(1024));
124
126 clientApps.Start(Seconds(2.0));
127 clientApps.Stop(Seconds(5.0));
128
129 if (!nix)
130 {
132 }
133
134 if (tracing)
135 {
136 AsciiTraceHelper ascii;
137 p2p.EnableAsciiAll(ascii.CreateFileStream("briteLeaves.tr"));
138 }
139 // Run the simulator
143
144 return 0;
145}
holds a vector of ns3::Application pointers.
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Interface with BRITE, the Boston university Representative Internet Topology gEnerator.
Parse command-line arguments.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
holds a vector of ns3::NetDevice pointers
Helper class that adds Nix-vector routing to nodes.
keep track of a set of node pointers.
Build a set of PointToPointNetDevice objects.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
echoClient
Definition first.py:48
address
Definition first.py:36
serverApps
Definition first.py:43
echoServer
Definition first.py:41
clientApps
Definition first.py:53
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:291
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
bool tracing
Flag to enable/disable generation of tracing files.