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