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
second.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*/
4
5
#include "ns3/applications-module.h"
6
#include "ns3/core-module.h"
7
#include "ns3/csma-module.h"
8
#include "ns3/internet-module.h"
9
#include "ns3/ipv4-global-routing-helper.h"
10
#include "ns3/network-module.h"
11
#include "ns3/point-to-point-module.h"
12
13
// Default Network Topology
14
//
15
// 10.1.1.0
16
// n0 -------------- n1 n2 n3 n4
17
// point-to-point | | | |
18
// ================
19
// LAN 10.1.2.0
20
21
using namespace
ns3
;
22
23
NS_LOG_COMPONENT_DEFINE
(
"SecondScriptExample"
);
24
25
int
26
main(
int
argc,
char
* argv[])
27
{
28
bool
verbose
=
true
;
29
uint32_t
nCsma
= 3;
30
31
CommandLine
cmd
(__FILE__);
32
cmd
.AddValue(
"nCsma"
,
"Number of \"extra\" CSMA nodes/devices"
, nCsma);
33
cmd
.AddValue(
"verbose"
,
"Tell echo applications to log if true"
,
verbose
);
34
35
cmd
.Parse(argc, argv);
36
37
if
(
verbose
)
38
{
39
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_INFO
);
40
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_INFO
);
41
}
42
43
nCsma
=
nCsma
== 0 ? 1 :
nCsma
;
44
45
NodeContainer
p2pNodes
;
46
p2pNodes
.Create(2);
47
48
NodeContainer
csmaNodes
;
49
csmaNodes
.Add(
p2pNodes
.Get(1));
50
csmaNodes
.Create(nCsma);
51
52
PointToPointHelper
pointToPoint
;
53
pointToPoint
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
54
pointToPoint
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
55
56
NetDeviceContainer
p2pDevices
;
57
p2pDevices
=
pointToPoint
.Install(p2pNodes);
58
59
CsmaHelper
csma
;
60
csma
.SetChannelAttribute(
"DataRate"
,
StringValue
(
"100Mbps"
));
61
csma
.SetChannelAttribute(
"Delay"
,
TimeValue
(
NanoSeconds
(6560)));
62
63
NetDeviceContainer
csmaDevices
;
64
csmaDevices
=
csma
.Install(csmaNodes);
65
66
InternetStackHelper
stack
;
67
stack
.Install(
p2pNodes
.Get(0));
68
stack
.Install(csmaNodes);
69
70
Ipv4AddressHelper
address
;
71
address
.SetBase(
"10.1.1.0"
,
"255.255.255.0"
);
72
Ipv4InterfaceContainer
p2pInterfaces
;
73
p2pInterfaces
=
address
.Assign(p2pDevices);
74
75
address
.SetBase(
"10.1.2.0"
,
"255.255.255.0"
);
76
Ipv4InterfaceContainer
csmaInterfaces
;
77
csmaInterfaces
=
address
.Assign(csmaDevices);
78
79
UdpEchoServerHelper
echoServer
(9);
80
81
ApplicationContainer
serverApps
=
echoServer
.Install(
csmaNodes
.Get(nCsma));
82
serverApps
.Start(
Seconds
(1.0));
83
serverApps
.Stop(
Seconds
(10.0));
84
85
UdpEchoClientHelper
echoClient
(
csmaInterfaces
.GetAddress(nCsma), 9);
86
echoClient
.SetAttribute(
"MaxPackets"
,
UintegerValue
(1));
87
echoClient
.SetAttribute(
"Interval"
,
TimeValue
(
Seconds
(1.0)));
88
echoClient
.SetAttribute(
"PacketSize"
,
UintegerValue
(1024));
89
90
ApplicationContainer
clientApps
=
echoClient
.Install(
p2pNodes
.Get(0));
91
clientApps
.Start(
Seconds
(2.0));
92
clientApps
.Stop(
Seconds
(10.0));
93
94
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
95
96
pointToPoint
.EnablePcapAll(
"second"
);
97
csma
.EnablePcap(
"second"
,
csmaDevices
.Get(1),
true
);
98
99
Simulator::Run
();
100
Simulator::Destroy
();
101
return
0;
102
}
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition
application-container.h:33
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::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::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition
point-to-point-helper.h:33
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::TimeValue
AttributeValue implementation for Time.
Definition
nstime.h:1395
ns3::UdpEchoClientHelper
Create an application which sends a UDP packet and waits for an echo of this packet.
Definition
udp-echo-helper.h:41
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:25
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
ns3::NanoSeconds
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
first.echoClient
echoClient
Definition
first.py:48
first.address
address
Definition
first.py:36
first.serverApps
serverApps
Definition
first.py:43
first.pointToPoint
pointToPoint
Definition
first.py:27
first.echoServer
echoServer
Definition
first.py:41
first.clientApps
clientApps
Definition
first.py:53
first.stack
stack
Definition
first.py:33
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:291
ns3::LOG_LEVEL_INFO
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition
log.h:93
second.p2pNodes
p2pNodes
Definition
second.py:39
second.p2pInterfaces
p2pInterfaces
Definition
second.py:64
second.csmaInterfaces
csmaInterfaces
Definition
second.py:67
second.csmaNodes
csmaNodes
Definition
second.py:42
second.csma
csma
Definition
second.py:52
second.p2pDevices
p2pDevices
Definition
second.py:50
second.nCsma
nCsma
Definition
second.py:27
second.cmd
cmd
Definition
second.py:29
second.csmaDevices
csmaDevices
Definition
second.py:56
verbose
bool verbose
Definition
openflow-switch.cc:42
examples
tutorial
second.cc
Generated on Thu Oct 3 2024 18:32:28 for ns-3 by
1.11.0