A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
first.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*/
16
17
#include "ns3/core-module.h"
18
#include "ns3/network-module.h"
19
#include "ns3/internet-module.h"
20
#include "ns3/point-to-point-module.h"
21
#include "ns3/applications-module.h"
22
23
// Default Network Topology
24
//
25
// 10.1.1.0
26
// n0 -------------- n1
27
// point-to-point
28
//
29
30
using namespace
ns3
;
31
32
NS_LOG_COMPONENT_DEFINE
(
"FirstScriptExample"
);
33
34
int
35
main (
int
argc,
char
*argv[])
36
{
37
CommandLine
cmd
(__FILE__);
38
cmd
.Parse (argc, argv);
39
40
Time::SetResolution
(
Time::NS
);
41
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_INFO
);
42
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_INFO
);
43
44
NodeContainer
nodes
;
45
nodes
.Create (2);
46
47
PointToPointHelper
pointToPoint
;
48
pointToPoint
.SetDeviceAttribute (
"DataRate"
,
StringValue
(
"5Mbps"
));
49
pointToPoint
.SetChannelAttribute (
"Delay"
,
StringValue
(
"2ms"
));
50
51
NetDeviceContainer
devices
;
52
devices
=
pointToPoint
.Install (
nodes
);
53
54
InternetStackHelper
stack
;
55
stack
.Install (
nodes
);
56
57
Ipv4AddressHelper
address
;
58
address
.SetBase (
"10.1.1.0"
,
"255.255.255.0"
);
59
60
Ipv4InterfaceContainer
interfaces
=
address
.Assign (
devices
);
61
62
UdpEchoServerHelper
echoServer
(9);
63
64
ApplicationContainer
serverApps
=
echoServer
.Install (
nodes
.Get (1));
65
serverApps
.Start (
Seconds
(1.0));
66
serverApps
.Stop (
Seconds
(10.0));
67
68
UdpEchoClientHelper
echoClient
(
interfaces
.GetAddress (1), 9);
69
echoClient
.SetAttribute (
"MaxPackets"
,
UintegerValue
(1));
70
echoClient
.SetAttribute (
"Interval"
,
TimeValue
(
Seconds
(1.0)));
71
echoClient
.SetAttribute (
"PacketSize"
,
UintegerValue
(1024));
72
73
ApplicationContainer
clientApps
=
echoClient
.Install (
nodes
.Get (0));
74
clientApps
.Start (
Seconds
(2.0));
75
clientApps
.Stop (
Seconds
(10.0));
76
77
Simulator::Run
();
78
Simulator::Destroy
();
79
return
0;
80
}
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition:
application-container.h:43
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:229
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition:
internet-stack-helper.h:88
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition:
ipv4-address-helper.h:48
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition:
ipv4-interface-container.h:55
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition:
net-device-container.h:42
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:39
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition:
point-to-point-helper.h:45
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:136
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition:
simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition:
string.h:41
ns3::Time::NS
@ NS
nanosecond
Definition:
nstime.h:117
ns3::Time::SetResolution
static void SetResolution(enum Unit resolution)
Definition:
time.cc:213
ns3::TimeValue
AttributeValue implementation for Time.
Definition:
nstime.h:1308
ns3::UdpEchoClientHelper
Create an application which sends a UDP packet and waits for an echo of this packet.
Definition:
udp-echo-helper.h:107
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:38
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:44
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1244
first.echoClient
echoClient
Definition:
first.py:56
first.address
address
Definition:
first.py:44
first.serverApps
serverApps
Definition:
first.py:52
first.pointToPoint
pointToPoint
Definition:
first.py:35
first.echoServer
echoServer
Definition:
first.py:50
first.clientApps
clientApps
Definition:
first.py:61
first.devices
devices
Definition:
first.py:39
first.stack
stack
Definition:
first.py:41
first.nodes
nodes
Definition:
first.py:32
first.interfaces
interfaces
Definition:
first.py:48
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::LOG_LEVEL_INFO
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition:
log.h:107
ns3::LogComponentEnable
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition:
log.cc:361
second.cmd
cmd
Definition:
second.py:35
examples
tutorial
first.cc
Generated on Tue Feb 6 2024 19:21:14 for ns-3 by
1.9.1