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
nix-simple.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
#include "ns3/ipv4-static-routing-helper.h"
23
#include "ns3/ipv4-list-routing-helper.h"
24
#include "ns3/ipv4-nix-vector-helper.h"
25
26
/*
27
* Simple point to point links:
28
*
29
* n0 -- n1 -- n2 -- n3
30
*
31
* n0 has UdpEchoClient
32
* n3 has UdpEchoServer
33
*
34
* n0 IP: 10.1.1.1
35
* n1 IP: 10.1.1.2, 10.1.2.1
36
* n2 IP: 10.1.2.2, 10.1.3.1
37
* n3 IP: 10.1.3.2
38
*
39
*/
40
41
using namespace
ns3;
42
43
NS_LOG_COMPONENT_DEFINE
(
"NixSimpleExample"
);
44
45
int
46
main
(
int
argc,
char
*argv[])
47
{
48
LogComponentEnable
(
"UdpEchoClientApplication"
,
LOG_LEVEL_INFO
);
49
LogComponentEnable
(
"UdpEchoServerApplication"
,
LOG_LEVEL_INFO
);
50
51
NodeContainer
nodes12;
52
nodes12.
Create
(2);
53
54
NodeContainer
nodes23;
55
nodes23.
Add
(nodes12.
Get
(1));
56
nodes23.
Create
(1);
57
58
NodeContainer
nodes34;
59
nodes34.
Add
(nodes23.
Get
(1));
60
nodes34.
Create
(1);
61
62
PointToPointHelper
pointToPoint;
63
pointToPoint.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
64
pointToPoint.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"2ms"
));
65
66
NodeContainer
allNodes =
NodeContainer
(nodes12, nodes23.
Get
(1), nodes34.
Get
(1));
67
68
// NixHelper to install nix-vector routing
69
// on all nodes
70
Ipv4NixVectorHelper
nixRouting;
71
Ipv4StaticRoutingHelper
staticRouting;
72
73
Ipv4ListRoutingHelper
list
;
74
list.
Add
(staticRouting, 0);
75
list.
Add
(nixRouting, 10);
76
77
InternetStackHelper
stack;
78
stack.
SetRoutingHelper
(list);
// has effect on the next Install ()
79
stack.
Install
(allNodes);
80
81
NetDeviceContainer
devices12;
82
NetDeviceContainer
devices23;
83
NetDeviceContainer
devices34;
84
devices12 = pointToPoint.
Install
(nodes12);
85
devices23 = pointToPoint.
Install
(nodes23);
86
devices34 = pointToPoint.
Install
(nodes34);
87
88
Ipv4AddressHelper
address1;
89
address1.
SetBase
(
"10.1.1.0"
,
"255.255.255.0"
);
90
Ipv4AddressHelper
address2;
91
address2.
SetBase
(
"10.1.2.0"
,
"255.255.255.0"
);
92
Ipv4AddressHelper
address3;
93
address3.
SetBase
(
"10.1.3.0"
,
"255.255.255.0"
);
94
95
address1.
Assign
(devices12);
96
address2.
Assign
(devices23);
97
Ipv4InterfaceContainer
interfaces = address3.
Assign
(devices34);
98
99
UdpEchoServerHelper
echoServer (9);
100
101
ApplicationContainer
serverApps = echoServer.
Install
(nodes34.
Get
(1));
102
serverApps.
Start
(
Seconds
(1.0));
103
serverApps.
Stop
(
Seconds
(10.0));
104
105
UdpEchoClientHelper
echoClient (interfaces.
GetAddress
(1), 9);
106
echoClient.
SetAttribute
(
"MaxPackets"
,
UintegerValue
(1));
107
echoClient.SetAttribute (
"Interval"
,
TimeValue
(
Seconds
(1.)));
108
echoClient.SetAttribute (
"PacketSize"
,
UintegerValue
(1024));
109
110
ApplicationContainer
clientApps = echoClient.Install (nodes12.
Get
(0));
111
clientApps.
Start
(
Seconds
(2.0));
112
clientApps.
Stop
(
Seconds
(10.0));
113
114
// Trace routing tables
115
Ptr<OutputStreamWrapper>
routingStream = Create<OutputStreamWrapper> (
"nix-simple.routes"
, std::ios::out);
116
nixRouting.PrintRoutingTableAllAt (
Seconds
(8), routingStream);
117
118
Simulator::Run
();
119
Simulator::Destroy
();
120
return
0;
121
}
src
nix-vector-routing
examples
nix-simple.cc
Generated on Tue May 14 2013 11:08:31 for ns-3 by
1.8.1.2