A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
second.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
#include "ns3/applications-module.h"
17
#include "ns3/core-module.h"
18
#include "ns3/csma-module.h"
19
#include "ns3/internet-module.h"
20
#include "ns3/ipv4-global-routing-helper.h"
21
#include "ns3/network-module.h"
22
#include "ns3/point-to-point-module.h"
23
24
// Default Network Topology
25
//
26
// 10.1.1.0
27
// n0 -------------- n1 n2 n3 n4
28
// point-to-point | | | |
29
// ================
30
// LAN 10.1.2.0
31
32
using namespace
ns3
;
33
34
NS_LOG_COMPONENT_DEFINE
(
"SecondScriptExample"
);
35
36
int
37
main(
int
argc,
char
* argv[])
38
{
39
bool
verbose
=
true
;
40
uint32_t
nCsma
= 3;
41
42
CommandLine
cmd
(__FILE__);
43
cmd
.AddValue(
"nCsma"
,
"Number of \"extra\" CSMA nodes/devices"
,
nCsma
);
44
cmd
.AddValue(
"verbose"
,
"Tell echo applications to log if true"
,
verbose
);
45
46
cmd
.Parse(argc, argv);
47
48
if
(
verbose
)
49
{
50
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_INFO
);
51
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_INFO
);
52
}
53
54
nCsma
=
nCsma
== 0 ? 1 :
nCsma
;
55
56
NodeContainer
p2pNodes
;
57
p2pNodes
.Create(2);
58
59
NodeContainer
csmaNodes
;
60
csmaNodes
.Add(
p2pNodes
.Get(1));
61
csmaNodes
.Create(
nCsma
);
62
63
PointToPointHelper
pointToPoint
;
64
pointToPoint
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
65
pointToPoint
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
66
67
NetDeviceContainer
p2pDevices
;
68
p2pDevices
=
pointToPoint
.Install(
p2pNodes
);
69
70
CsmaHelper
csma
;
71
csma
.SetChannelAttribute(
"DataRate"
,
StringValue
(
"100Mbps"
));
72
csma
.SetChannelAttribute(
"Delay"
,
TimeValue
(
NanoSeconds
(6560)));
73
74
NetDeviceContainer
csmaDevices
;
75
csmaDevices
=
csma
.Install(
csmaNodes
);
76
77
InternetStackHelper
stack
;
78
stack
.Install(
p2pNodes
.Get(0));
79
stack
.Install(
csmaNodes
);
80
81
Ipv4AddressHelper
address
;
82
address
.SetBase(
"10.1.1.0"
,
"255.255.255.0"
);
83
Ipv4InterfaceContainer
p2pInterfaces
;
84
p2pInterfaces
=
address
.Assign(
p2pDevices
);
85
86
address
.SetBase(
"10.1.2.0"
,
"255.255.255.0"
);
87
Ipv4InterfaceContainer
csmaInterfaces
;
88
csmaInterfaces
=
address
.Assign(
csmaDevices
);
89
90
UdpEchoServerHelper
echoServer
(9);
91
92
ApplicationContainer
serverApps
=
echoServer
.Install(
csmaNodes
.Get(
nCsma
));
93
serverApps
.Start(
Seconds
(1.0));
94
serverApps
.Stop(
Seconds
(10.0));
95
96
UdpEchoClientHelper
echoClient
(
csmaInterfaces
.GetAddress(
nCsma
), 9);
97
echoClient
.SetAttribute(
"MaxPackets"
,
UintegerValue
(1));
98
echoClient
.SetAttribute(
"Interval"
,
TimeValue
(
Seconds
(1.0)));
99
echoClient
.SetAttribute(
"PacketSize"
,
UintegerValue
(1024));
100
101
ApplicationContainer
clientApps
=
echoClient
.Install(
p2pNodes
.Get(0));
102
clientApps
.Start(
Seconds
(2.0));
103
clientApps
.Stop(
Seconds
(10.0));
104
105
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
106
107
pointToPoint
.EnablePcapAll(
"second"
);
108
csma
.EnablePcap(
"second"
,
csmaDevices
.Get(1),
true
);
109
110
Simulator::Run
();
111
Simulator::Destroy
();
112
return
0;
113
}
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition:
application-container.h:44
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition:
csma-helper.h:48
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition:
internet-stack-helper.h:92
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition:
ipv4-address-helper.h:49
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:61
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition:
ipv4-interface-container.h:56
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition:
net-device-container.h:43
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:40
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition:
point-to-point-helper.h:44
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:140
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:176
ns3::StringValue
Hold variables of type string.
Definition:
string.h:56
ns3::TimeValue
AttributeValue implementation for Time.
Definition:
nstime.h:1423
ns3::UdpEchoClientHelper
Create an application which sends a UDP packet and waits for an echo of this packet.
Definition:
udp-echo-helper.h:108
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:39
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:45
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::NanoSeconds
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1372
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1336
first.echoClient
echoClient
Definition:
first.py:53
first.address
address
Definition:
first.py:40
first.serverApps
serverApps
Definition:
first.py:48
first.pointToPoint
pointToPoint
Definition:
first.py:31
first.echoServer
echoServer
Definition:
first.py:46
first.clientApps
clientApps
Definition:
first.py:58
first.stack
stack
Definition:
first.py:37
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::LogComponentEnable
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition:
log.cc:305
ns3::LOG_LEVEL_INFO
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition:
log.h:107
second.p2pNodes
p2pNodes
Definition:
second.py:43
second.p2pInterfaces
p2pInterfaces
Definition:
second.py:68
second.csmaInterfaces
csmaInterfaces
Definition:
second.py:71
second.csmaNodes
csmaNodes
Definition:
second.py:46
second.csma
csma
Definition:
second.py:56
second.p2pDevices
p2pDevices
Definition:
second.py:54
second.nCsma
nCsma
Definition:
second.py:31
second.cmd
cmd
Definition:
second.py:33
second.csmaDevices
csmaDevices
Definition:
second.py:60
verbose
bool verbose
Definition:
openflow-switch.cc:49
examples
tutorial
second.cc
Generated on Fri Mar 31 2023 13:30:37 for ns-3 by
1.9.1