A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
brite-generic-example.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*
16
*/
17
18
#include <string>
19
#include "ns3/core-module.h"
20
#include "ns3/network-module.h"
21
#include "ns3/internet-module.h"
22
#include "ns3/point-to-point-module.h"
23
#include "ns3/mobility-module.h"
24
#include "ns3/applications-module.h"
25
#include "ns3/brite-module.h"
26
#include "ns3/ipv4-nix-vector-helper.h"
27
#include <iostream>
28
#include <fstream>
29
30
using namespace
ns3;
31
32
NS_LOG_COMPONENT_DEFINE
(
"BriteExample"
);
33
34
int
35
main
(
int
argc,
char
*argv[])
36
{
37
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_ALL
);
38
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_ALL
);
39
40
LogComponentEnable
(
"BriteExample"
,
LOG_LEVEL_ALL
);
41
42
// BRITE needs a configuration file to build its graph. By default, this
43
// example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others
44
// which can be found in the BRITE/conf_files directory
45
std::string confFile =
"src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"
;
46
bool
tracing =
false
;
47
bool
nix =
false
;
48
49
CommandLine
cmd;
50
cmd.
AddValue
(
"confFile"
,
"BRITE conf file"
, confFile);
51
cmd.
AddValue
(
"tracing"
,
"Enable or disable ascii tracing"
, tracing);
52
cmd.
AddValue
(
"nix"
,
"Enable or disable nix-vector routing"
, nix);
53
54
cmd.
Parse
(argc,argv);
55
56
nix =
false
;
57
58
// Invoke the BriteTopologyHelper and pass in a BRITE
59
// configuration file and a seed file. This will use
60
// BRITE to build a graph from which we can build the ns-3 topology
61
BriteTopologyHelper
bth (confFile);
62
bth.
AssignStreams
(3);
63
64
PointToPointHelper
p2p;
65
66
Ipv4StaticRoutingHelper
staticRouting;
67
Ipv4GlobalRoutingHelper
globalRouting;
68
Ipv4ListRoutingHelper
listRouting;
69
Ipv4NixVectorHelper
nixRouting;
70
71
InternetStackHelper
stack;
72
73
if
(nix)
74
{
75
listRouting.
Add
(staticRouting, 0);
76
listRouting.
Add
(nixRouting, 10);
77
}
78
else
79
{
80
listRouting.
Add
(staticRouting, 0);
81
listRouting.
Add
(globalRouting, 10);
82
}
83
84
stack.
SetRoutingHelper
(listRouting);
85
86
Ipv4AddressHelper
address;
87
address.
SetBase
(
"10.0.0.0"
,
"255.255.255.252"
);
88
89
bth.
BuildBriteTopology
(stack);
90
bth.
AssignIpv4Addresses
(address);
91
92
NS_LOG_INFO
(
"Number of AS created "
<< bth.
GetNAs
());
93
94
//The BRITE topology generator generates a topology of routers. Here we create
95
//two subnetworks which we attach to router leaf nodes generated by BRITE
96
//Any NS3 topology may be used to attach to the BRITE leaf nodes but here we
97
//use just one node
98
99
NodeContainer
client;
100
NodeContainer
server;
101
102
client.
Create
(1);
103
stack.
Install
(client);
104
105
//install client node on last leaf node of AS 0
106
int
numLeafNodesInAsZero = bth.
GetNLeafNodesForAs
(0);
107
client.Add (bth.
GetLeafNodeForAs
(0, numLeafNodesInAsZero - 1));
108
109
server.
Create
(1);
110
stack.
Install
(server);
111
112
//install server node on last leaf node on AS 1
113
int
numLeafNodesInAsOne = bth.
GetNLeafNodesForAs
(1);
114
server.
Add
(bth.
GetLeafNodeForAs
(1, numLeafNodesInAsOne - 1));
115
116
p2p.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
117
p2p.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"2ms"
));
118
119
NetDeviceContainer
p2pClientDevices;
120
NetDeviceContainer
p2pServerDevices;
121
122
p2pClientDevices = p2p.
Install
(client);
123
p2pServerDevices = p2p.
Install
(server);
124
125
address.
SetBase
(
"10.1.0.0"
,
"255.255.0.0"
);
126
Ipv4InterfaceContainer
clientInterfaces;
127
clientInterfaces = address.
Assign
(p2pClientDevices);
128
129
address.
SetBase
(
"10.2.0.0"
,
"255.255.0.0"
);
130
Ipv4InterfaceContainer
serverInterfaces;
131
serverInterfaces = address.
Assign
(p2pServerDevices);
132
133
UdpEchoServerHelper
echoServer (9);
134
ApplicationContainer
serverApps = echoServer.
Install
(server.
Get
(0));
135
serverApps.
Start
(
Seconds
(1.0));
136
serverApps.
Stop
(
Seconds
(5.0));
137
138
UdpEchoClientHelper
echoClient (serverInterfaces.
GetAddress
(0), 9);
139
echoClient.
SetAttribute
(
"MaxPackets"
,
UintegerValue
(1));
140
echoClient.SetAttribute (
"Interval"
,
TimeValue
(
Seconds
(1.)));
141
echoClient.SetAttribute (
"PacketSize"
,
UintegerValue
(1024));
142
143
ApplicationContainer
clientApps = echoClient.Install (client.Get (0));
144
clientApps.
Start
(
Seconds
(2.0));
145
clientApps.
Stop
(
Seconds
(5.0));
146
147
if
(!nix)
148
{
149
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
150
}
151
152
if
(tracing)
153
{
154
AsciiTraceHelper
ascii;
155
p2p.
EnableAsciiAll
(ascii.
CreateFileStream
(
"briteLeaves.tr"
));
156
}
157
// Run the simulator
158
Simulator::Stop
(
Seconds
(6.0));
159
Simulator::Run
();
160
Simulator::Destroy
();
161
162
return
0;
163
}
src
brite
examples
brite-generic-example.cc
Generated on Tue May 14 2013 11:08:16 for ns-3 by
1.8.1.2