A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
mixed-global-routing.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
*/
5
6
// This script exercises global routing code in a mixed point-to-point
7
// and csma/cd environment
8
//
9
// Network topology
10
//
11
// n0
12
// \ p-p
13
// \ (shared csma/cd)
14
// n2 -------------------------n3
15
// / | |
16
// / p-p n4 n5 ---------- n6
17
// n1 p-p
18
//
19
// - CBR/UDP flows from n0 to n6
20
// - Tracing of queues and packet receptions to file "mixed-global-routing.tr"
21
22
#include "ns3/applications-module.h"
23
#include "ns3/core-module.h"
24
#include "ns3/csma-module.h"
25
#include "ns3/internet-module.h"
26
#include "ns3/network-module.h"
27
#include "ns3/point-to-point-module.h"
28
29
#include <cassert>
30
#include <fstream>
31
#include <iostream>
32
#include <string>
33
34
using namespace
ns3
;
35
36
NS_LOG_COMPONENT_DEFINE
(
"MixedGlobalRoutingExample"
);
37
38
int
39
main(
int
argc
,
char
*
argv
[])
40
{
41
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(210));
42
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(
"448kb/s"
));
43
44
// Allow the user to override any of the defaults and the above
45
// Bind ()s at run-time, via command-line arguments
46
CommandLine
cmd
(
__FILE__
);
47
cmd
.Parse(
argc
,
argv
);
48
49
NS_LOG_INFO
(
"Create nodes."
);
50
NodeContainer
c
;
51
c
.
Create
(7);
52
NodeContainer
n0n2
=
NodeContainer
(
c
.Get(0),
c
.Get(2));
53
NodeContainer
n1n2
=
NodeContainer
(
c
.Get(1),
c
.Get(2));
54
NodeContainer
n5n6
=
NodeContainer
(
c
.Get(5),
c
.Get(6));
55
NodeContainer
n2345
=
NodeContainer
(
c
.Get(2),
c
.Get(3),
c
.Get(4),
c
.Get(5));
56
57
InternetStackHelper
internet
;
58
internet
.Install(
c
);
59
60
// We create the channels first without any IP addressing information
61
NS_LOG_INFO
(
"Create channels."
);
62
PointToPointHelper
p2p
;
63
p2p
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
64
p2p
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
65
NetDeviceContainer
d0d2
=
p2p
.Install(
n0n2
);
66
67
NetDeviceContainer
d1d2
=
p2p
.Install(
n1n2
);
68
69
p2p
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"1500kbps"
));
70
p2p
.SetChannelAttribute(
"Delay"
,
StringValue
(
"10ms"
));
71
NetDeviceContainer
d5d6
=
p2p
.Install(
n5n6
);
72
73
// We create the channels first without any IP addressing information
74
CsmaHelper
csma
;
75
csma
.SetChannelAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
76
csma
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
77
NetDeviceContainer
d2345
=
csma
.Install(
n2345
);
78
79
// Later, we add IP addresses.
80
NS_LOG_INFO
(
"Assign IP Addresses."
);
81
Ipv4AddressHelper
ipv4
;
82
ipv4
.SetBase(
"10.1.1.0"
,
"255.255.255.0"
);
83
ipv4
.Assign(
d0d2
);
84
85
ipv4
.SetBase(
"10.1.2.0"
,
"255.255.255.0"
);
86
ipv4
.Assign(
d1d2
);
87
88
ipv4
.SetBase(
"10.1.3.0"
,
"255.255.255.0"
);
89
Ipv4InterfaceContainer
i5i6
=
ipv4
.Assign(
d5d6
);
90
91
ipv4
.SetBase(
"10.250.1.0"
,
"255.255.255.0"
);
92
ipv4
.Assign(
d2345
);
93
94
// Create router nodes, initialize routing database and set up the routing
95
// tables in the nodes.
96
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
97
98
// Create the OnOff application to send UDP datagrams of size
99
// 210 bytes at a rate of 448 Kb/s
100
NS_LOG_INFO
(
"Create Applications."
);
101
uint16_t
port
= 9;
// Discard port (RFC 863)
102
OnOffHelper
onoff
(
"ns3::UdpSocketFactory"
,
InetSocketAddress
(
i5i6
.GetAddress(1),
port
));
103
onoff
.SetConstantRate(
DataRate
(
"300bps"
));
104
onoff
.SetAttribute(
"PacketSize"
,
UintegerValue
(50));
105
106
ApplicationContainer
apps
=
onoff
.Install(
c
.Get(0));
107
apps
.Start(
Seconds
(1));
108
apps
.Stop(
Seconds
(10));
109
110
AsciiTraceHelper
ascii
;
111
Ptr<OutputStreamWrapper>
stream =
ascii
.CreateFileStream(
"mixed-global-routing.tr"
);
112
p2p
.EnableAsciiAll(stream);
113
csma
.EnableAsciiAll(stream);
114
115
p2p
.EnablePcapAll(
"mixed-global-routing"
);
116
csma
.EnablePcapAll(
"mixed-global-routing"
,
false
);
117
118
NS_LOG_INFO
(
"Run Simulation."
);
119
Simulator::Run
();
120
Simulator::Destroy
();
121
NS_LOG_INFO
(
"Done."
);
122
123
return
0;
124
}
n1n2
NodeContainer n1n2
Nodecontainer n1 + n2.
Definition
adaptive-red-tests.cc:79
n0n2
NodeContainer n0n2
Nodecontainer n0 + n2.
Definition
adaptive-red-tests.cc:78
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition
application-container.h:33
ns3::AsciiTraceHelper
Manage ASCII trace files for device models.
Definition
trace-helper.h:163
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition
csma-helper.h:37
ns3::DataRate
Class for representing data rates.
Definition
data-rate.h:78
ns3::InetSocketAddress
an Inet address class
Definition
inet-socket-address.h:31
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition
internet-stack-helper.h:81
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition
ipv4-address-helper.h:38
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:50
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition
ipv4-interface-container.h:45
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition
net-device-container.h:32
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
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:73
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition
on-off-helper.h:26
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition
point-to-point-helper.h:33
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
port
uint16_t port
Definition
dsdv-manet.cc:33
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition
config.cc:883
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
brite-generic-example.p2p
p2p
Definition
brite-generic-example.py:32
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nsclick-simple-lan.ipv4
ipv4
Definition
nsclick-simple-lan.py:46
nsclick-simple-lan.internet
internet
Definition
nsclick-simple-lan.py:34
openflow-switch.onoff
onoff
Definition
openflow-switch.py:59
second.csma
csma
Definition
second.py:52
second.cmd
cmd
Definition
second.py:29
examples
routing
mixed-global-routing.cc
Generated on Mon Dec 15 2025 15:21:47 for ns-3 by
1.9.8