A Discrete-Event Network Simulator
API
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/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 (__FILE__);
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 
65 
66 
68 
69  if (nix)
70  {
71  Ipv4NixVectorHelper nixRouting;
72  stack.SetRoutingHelper (nixRouting);
73  }
74 
76  address.SetBase ("10.0.0.0", "255.255.255.252");
77 
78  bth.BuildBriteTopology (stack);
79  bth.AssignIpv4Addresses (address);
80 
81  NS_LOG_INFO ("Number of AS created " << bth.GetNAs ());
82 
83  //The BRITE topology generator generates a topology of routers. Here we create
84  //two subnetworks which we attach to router leaf nodes generated by BRITE
85  //Any NS3 topology may be used to attach to the BRITE leaf nodes but here we
86  //use just one node
87 
88  NodeContainer client;
89  NodeContainer server;
90 
91  client.Create (1);
92  stack.Install (client);
93 
94  //install client node on last leaf node of AS 0
95  int numLeafNodesInAsZero = bth.GetNLeafNodesForAs (0);
96  client.Add (bth.GetLeafNodeForAs (0, numLeafNodesInAsZero - 1));
97 
98  server.Create (1);
99  stack.Install (server);
100 
101  //install server node on last leaf node on AS 1
102  int numLeafNodesInAsOne = bth.GetNLeafNodesForAs (1);
103  server.Add (bth.GetLeafNodeForAs (1, numLeafNodesInAsOne - 1));
104 
105  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
106  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
107 
108  NetDeviceContainer p2pClientDevices;
109  NetDeviceContainer p2pServerDevices;
110 
111  p2pClientDevices = p2p.Install (client);
112  p2pServerDevices = p2p.Install (server);
113 
114  address.SetBase ("10.1.0.0", "255.255.0.0");
115  Ipv4InterfaceContainer clientInterfaces;
116  clientInterfaces = address.Assign (p2pClientDevices);
117 
118  address.SetBase ("10.2.0.0", "255.255.0.0");
119  Ipv4InterfaceContainer serverInterfaces;
120  serverInterfaces = address.Assign (p2pServerDevices);
121 
123  ApplicationContainer serverApps = echoServer.Install (server.Get (0));
124  serverApps.Start (Seconds (1.0));
125  serverApps.Stop (Seconds (5.0));
126 
127  UdpEchoClientHelper echoClient (serverInterfaces.GetAddress (0), 9);
128  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
129  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
130  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
131 
132  ApplicationContainer clientApps = echoClient.Install (client.Get (0));
133  clientApps.Start (Seconds (2.0));
134  clientApps.Stop (Seconds (5.0));
135 
136  if (!nix)
137  {
139  }
140 
141  if (tracing)
142  {
143  AsciiTraceHelper ascii;
144  p2p.EnableAsciiAll (ascii.CreateFileStream ("briteLeaves.tr"));
145  }
146  // Run the simulator
147  Simulator::Stop (Seconds (6.0));
148  Simulator::Run ();
150 
151  return 0;
152 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
ns3::AsciiTraceHelperForDevice::EnableAsciiAll
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Definition: trace-helper.cc:586
tracing
bool tracing
Flag to enable/disable generation of tracing files.
Definition: wifi-bianchi.cc:85
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::PointToPointHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
Definition: point-to-point-helper.cc:69
ns3::PointToPointHelper::SetChannelAttribute
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Definition: point-to-point-helper.cc:75
ns3::UdpEchoClientHelper
Create an application which sends a UDP packet and waits for an echo of this packet.
Definition: udp-echo-helper.h:107
ns3::LOG_LEVEL_ALL
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
ns3::LogComponentEnable
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
ns3::PointToPointHelper::Install
NetDeviceContainer Install(NodeContainer c)
Definition: point-to-point-helper.cc:222
ns3::BriteTopologyHelper
Interface with BRITE, the Boston university Representative Internet Topology gEnerator.
Definition: brite-topology-helper.h:60
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::NodeContainer::Add
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Definition: node-container.cc:114
ns3::NixVectorHelper
Helper class that adds Nix-vector routing to nodes.
Definition: nix-vector-helper.h:51
ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Definition: ipv4-global-routing-helper.cc:61
first.stack
stack
Definition: first.py:41
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
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:191
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
first.address
address
Definition: first.py:44
second.cmd
cmd
Definition: second.py:35
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
first.echoClient
echoClient
Definition: first.py:56
ns3::AsciiTraceHelper
Manage ASCII trace files for device models.
Definition: trace-helper.h:163
first.clientApps
clientApps
Definition: first.py:61
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
first.serverApps
serverApps
Definition: first.py:52
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition: point-to-point-helper.h:45
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
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:38
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
first.echoServer
echoServer
Definition: first.py:50