A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
using namespace
ns3;
24
25
NS_LOG_COMPONENT_DEFINE
(
"FirstScriptExample"
);
26
27
int
28
main
(
int
argc,
char
*argv[])
29
{
30
Time::SetResolution
(
Time::NS
);
31
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_INFO
);
32
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_INFO
);
33
34
NodeContainer
nodes
;
35
nodes.
Create
(2);
36
37
PointToPointHelper
pointToPoint
;
38
pointToPoint.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
39
pointToPoint.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"2ms"
));
40
41
NetDeviceContainer
devices
;
42
devices = pointToPoint.
Install
(nodes);
43
44
InternetStackHelper
stack
;
45
stack.
Install
(nodes);
46
47
Ipv4AddressHelper
address
;
48
address.
SetBase
(
"10.1.1.0"
,
"255.255.255.0"
);
49
50
Ipv4InterfaceContainer
interfaces
= address.
Assign
(devices);
51
52
UdpEchoServerHelper
echoServer
(9);
53
54
ApplicationContainer
serverApps
= echoServer.
Install
(nodes.
Get
(1));
55
serverApps.
Start
(Seconds (1.0));
56
serverApps.
Stop
(Seconds (10.0));
57
58
UdpEchoClientHelper
echoClient
(interfaces.
GetAddress
(1), 9);
59
echoClient
.SetAttribute (
"MaxPackets"
,
UintegerValue
(1));
60
echoClient
.SetAttribute (
"Interval"
,
TimeValue
(Seconds (1.0)));
61
echoClient
.SetAttribute (
"PacketSize"
,
UintegerValue
(1024));
62
63
ApplicationContainer
clientApps
=
echoClient
.Install (nodes.
Get
(0));
64
clientApps.
Start
(Seconds (2.0));
65
clientApps.
Stop
(Seconds (10.0));
66
67
Simulator::Run
();
68
Simulator::Destroy
();
69
return
0;
70
}
examples
tutorial
first.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2