A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mixed-global-routing.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 */
16
17// This script exercises global routing code in a mixed point-to-point
18// and csma/cd environment
19//
20// Network topology
21//
22// n0
23// \ p-p
24// \ (shared csma/cd)
25// n2 -------------------------n3
26// / | |
27// / p-p n4 n5 ---------- n6
28// n1 p-p
29//
30// - CBR/UDP flows from n0 to n6
31// - Tracing of queues and packet receptions to file "mixed-global-routing.tr"
32
33#include "ns3/applications-module.h"
34#include "ns3/core-module.h"
35#include "ns3/csma-module.h"
36#include "ns3/internet-module.h"
37#include "ns3/network-module.h"
38#include "ns3/point-to-point-module.h"
39
40#include <cassert>
41#include <fstream>
42#include <iostream>
43#include <string>
44
45using namespace ns3;
46
47NS_LOG_COMPONENT_DEFINE("MixedGlobalRoutingExample");
48
49int
50main(int argc, char* argv[])
51{
52 Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(210));
53 Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue("448kb/s"));
54
55 // Allow the user to override any of the defaults and the above
56 // Bind ()s at run-time, via command-line arguments
57 CommandLine cmd(__FILE__);
58 cmd.Parse(argc, argv);
59
60 NS_LOG_INFO("Create nodes.");
62 c.Create(7);
65 NodeContainer n5n6 = NodeContainer(c.Get(5), c.Get(6));
66 NodeContainer n2345 = NodeContainer(c.Get(2), c.Get(3), c.Get(4), c.Get(5));
67
69 internet.Install(c);
70
71 // We create the channels first without any IP addressing information
72 NS_LOG_INFO("Create channels.");
74 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
75 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
76 NetDeviceContainer d0d2 = p2p.Install(n0n2);
77
78 NetDeviceContainer d1d2 = p2p.Install(n1n2);
79
80 p2p.SetDeviceAttribute("DataRate", StringValue("1500kbps"));
81 p2p.SetChannelAttribute("Delay", StringValue("10ms"));
82 NetDeviceContainer d5d6 = p2p.Install(n5n6);
83
84 // We create the channels first without any IP addressing information
86 csma.SetChannelAttribute("DataRate", StringValue("5Mbps"));
87 csma.SetChannelAttribute("Delay", StringValue("2ms"));
88 NetDeviceContainer d2345 = csma.Install(n2345);
89
90 // Later, we add IP addresses.
91 NS_LOG_INFO("Assign IP Addresses.");
93 ipv4.SetBase("10.1.1.0", "255.255.255.0");
94 ipv4.Assign(d0d2);
95
96 ipv4.SetBase("10.1.2.0", "255.255.255.0");
97 ipv4.Assign(d1d2);
98
99 ipv4.SetBase("10.1.3.0", "255.255.255.0");
100 Ipv4InterfaceContainer i5i6 = ipv4.Assign(d5d6);
101
102 ipv4.SetBase("10.250.1.0", "255.255.255.0");
103 ipv4.Assign(d2345);
104
105 // Create router nodes, initialize routing database and set up the routing
106 // tables in the nodes.
108
109 // Create the OnOff application to send UDP datagrams of size
110 // 210 bytes at a rate of 448 Kb/s
111 NS_LOG_INFO("Create Applications.");
112 uint16_t port = 9; // Discard port (RFC 863)
113 OnOffHelper onoff("ns3::UdpSocketFactory", InetSocketAddress(i5i6.GetAddress(1), port));
114 onoff.SetConstantRate(DataRate("300bps"));
115 onoff.SetAttribute("PacketSize", UintegerValue(50));
116
117 ApplicationContainer apps = onoff.Install(c.Get(0));
118 apps.Start(Seconds(1.0));
119 apps.Stop(Seconds(10.0));
120
121 AsciiTraceHelper ascii;
122 Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream("mixed-global-routing.tr");
123 p2p.EnableAsciiAll(stream);
124 csma.EnableAsciiAll(stream);
125
126 p2p.EnablePcapAll("mixed-global-routing");
127 csma.EnablePcapAll("mixed-global-routing", false);
128
129 NS_LOG_INFO("Run Simulation.");
132 NS_LOG_INFO("Done.");
133
134 return 0;
135}
NodeContainer n1n2
Nodecontainer n1 + n2.
NodeContainer n0n2
Nodecontainer n0 + n2.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
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.
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
Class for representing data rates.
Definition: data-rate.h:89
an Inet address class
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.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:37
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
Hold variables of type string.
Definition: string.h:56
Hold an unsigned integer type.
Definition: uinteger.h:45
uint16_t port
Definition: dsdv-manet.cc:44
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:894
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:40
ns csma
Definition: second.py:63