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
first.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/internet-module.h"
8
#include "ns3/network-module.h"
9
#include "ns3/point-to-point-module.h"
10
11
// Default Network Topology
12
//
13
// 10.1.1.0
14
// n0 -------------- n1
15
// point-to-point
16
//
17
18
using namespace
ns3
;
19
20
NS_LOG_COMPONENT_DEFINE
(
"FirstScriptExample"
);
21
22
int
23
main(
int
argc,
char
* argv[])
24
{
25
CommandLine
cmd
(__FILE__);
26
cmd
.Parse(argc, argv);
27
28
Time::SetResolution
(
Time::NS
);
29
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_INFO
);
30
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_INFO
);
31
32
NodeContainer
nodes
;
33
nodes
.
Create
(2);
34
35
PointToPointHelper
pointToPoint
;
36
pointToPoint
.SetDeviceAttribute(
"DataRate"
,
StringValue
(
"5Mbps"
));
37
pointToPoint
.SetChannelAttribute(
"Delay"
,
StringValue
(
"2ms"
));
38
39
NetDeviceContainer
devices
;
40
devices
=
pointToPoint
.Install(
nodes
);
41
42
InternetStackHelper
stack
;
43
stack
.Install(
nodes
);
44
45
Ipv4AddressHelper
address
;
46
address
.SetBase(
"10.1.1.0"
,
"255.255.255.0"
);
47
48
Ipv4InterfaceContainer
interfaces
=
address
.Assign(devices);
49
50
UdpEchoServerHelper
echoServer
(9);
51
52
ApplicationContainer
serverApps
=
echoServer
.Install(
nodes
.
Get
(1));
53
serverApps
.Start(
Seconds
(1.0));
54
serverApps
.Stop(
Seconds
(10.0));
55
56
UdpEchoClientHelper
echoClient
(
interfaces
.GetAddress(1), 9);
57
echoClient
.SetAttribute(
"MaxPackets"
,
UintegerValue
(1));
58
echoClient
.SetAttribute(
"Interval"
,
TimeValue
(
Seconds
(1.0)));
59
echoClient
.SetAttribute(
"PacketSize"
,
UintegerValue
(1024));
60
61
ApplicationContainer
clientApps
=
echoClient
.Install(
nodes
.
Get
(0));
62
clientApps
.Start(
Seconds
(2.0));
63
clientApps
.Stop(
Seconds
(10.0));
64
65
Simulator::Run
();
66
Simulator::Destroy
();
67
return
0;
68
}
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::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::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::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:67
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::Time::NS
@ NS
nanosecond
Definition
nstime.h:108
ns3::Time::SetResolution
static void SetResolution(Unit resolution)
Definition
time.cc:202
ns3::TimeValue
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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
nodes
NodeContainer nodes
Definition
lr-wpan-bootstrap.cc:43
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.devices
devices
Definition
first.py:31
first.stack
stack
Definition
first.py:33
first.interfaces
interfaces
Definition
first.py:39
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.cmd
cmd
Definition
second.py:29
examples
tutorial
first.cc
Generated on Fri Nov 8 2024 13:58:58 for ns-3 by
1.11.0