A Discrete-Event Network Simulator
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
67  bth.AssignStreams(3);
68 
70 
72 
73  if (nix)
74  {
76  stack.SetRoutingHelper(nixRouting);
77  }
78 
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 
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 
114 
115  p2pClientDevices = p2p.Install(client);
116  p2pServerDevices = p2p.Install(server);
117 
118  address.SetBase("10.1.0.0", "255.255.0.0");
121 
122  address.SetBase("10.2.0.0", "255.255.0.0");
125 
128  serverApps.Start(Seconds(1.0));
129  serverApps.Stop(Seconds(5.0));
130 
132  echoClient.SetAttribute("MaxPackets", UintegerValue(1));
133  echoClient.SetAttribute("Interval", TimeValue(Seconds(1.)));
134  echoClient.SetAttribute("PacketSize", UintegerValue(1024));
135 
137  clientApps.Start(Seconds(2.0));
138  clientApps.Stop(Seconds(5.0));
139 
140  if (!nix)
141  {
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();
154 
155  return 0;
156 }
holds a vector of ns3::Application pointers.
Manage ASCII trace files for device models.
Definition: trace-helper.h:174
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.
Definition: command-line.h:232
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:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Hold variables of type string.
Definition: string.h:56
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:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
echoClient
Definition: first.py:59
address
Definition: first.py:47
serverApps
Definition: first.py:54
echoServer
Definition: first.py:52
clientApps
Definition: first.py:64
stack
Definition: first.py:44
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:302
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
cmd
Definition: second.py:40
bool tracing
Flag to enable/disable generation of tracing files.