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
loose-routing-ipv6.cc
Go to the documentation of this file.
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 Strasbourg University
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: David Gross <gdavid.devel@gmail.com>
19
*/
20
21
// Network topology
22
// //
23
// //
24
// // +------------+
25
// // +------------+ |---| Router 1 |---|
26
// // | Host 0 |--| | [------------] |
27
// // [------------] | | |
28
// // | +------------+ |
29
// // +--| | +------------+
30
// // | Router 0 | | Router 2 |
31
// // +--| | [------------]
32
// // | [------------] |
33
// // +------------+ | | |
34
// // | Host 1 |--| | +------------+ |
35
// // [------------] |---| Router 3 |---|
36
// // [------------]
37
// //
38
// //
39
// // - Tracing of queues and packet receptions to file "loose-routing-ipv6.tr"
40
41
#include <fstream>
42
#include "ns3/core-module.h"
43
#include "ns3/internet-module.h"
44
#include "ns3/csma-module.h"
45
#include "ns3/applications-module.h"
46
#include "ns3/ipv6-header.h"
47
using namespace
ns3;
48
49
NS_LOG_COMPONENT_DEFINE
(
"LooseRoutingIpv6Example"
);
50
51
int
main
(
int
argc,
char
**argv)
52
{
53
bool
verbose
=
false
;
54
55
CommandLine
cmd;
56
cmd.
AddValue
(
"verbose"
,
"turn on log components"
, verbose);
57
cmd.
Parse
(argc, argv);
58
59
if
(verbose)
60
{
61
LogComponentEnable
(
"Ipv6ExtensionLooseRouting"
,
LOG_LEVEL_ALL
);
62
LogComponentEnable
(
"Ipv6Extension"
,
LOG_LEVEL_ALL
);
63
LogComponentEnable
(
"Ipv6L3Protocol"
,
LOG_LEVEL_ALL
);
64
LogComponentEnable
(
"Ipv6StaticRouting"
,
LOG_LEVEL_ALL
);
65
LogComponentEnable
(
"Ipv6Interface"
,
LOG_LEVEL_ALL
);
66
LogComponentEnable
(
"Ipv6Interface"
,
LOG_LEVEL_ALL
);
67
LogComponentEnable
(
"NdiscCache"
,
LOG_LEVEL_ALL
);
68
}
69
70
NS_LOG_INFO
(
"Create nodes."
);
71
Ptr<Node>
h0 = CreateObject<Node> ();
72
Ptr<Node>
h1 = CreateObject<Node> ();
73
Ptr<Node>
r0 = CreateObject<Node> ();
74
Ptr<Node>
r1 = CreateObject<Node> ();
75
Ptr<Node>
r2 = CreateObject<Node> ();
76
Ptr<Node>
r3 = CreateObject<Node> ();
77
78
NodeContainer
net1 (h0, r0);
79
NodeContainer
net2 (h1, r0);
80
NodeContainer
net3 (r0, r1);
81
NodeContainer
net4 (r1, r2);
82
NodeContainer
net5 (r2, r3);
83
NodeContainer
net6 (r3, r0);
84
NodeContainer
all;
85
all.
Add
(h0);
86
all.
Add
(h1);
87
all.
Add
(r0);
88
all.
Add
(r1);
89
all.
Add
(r2);
90
all.
Add
(r3);
91
92
NS_LOG_INFO
(
"Create IPv6 Internet Stack"
);
93
InternetStackHelper
internetv6;
94
internetv6.
Install
(all);
95
96
NS_LOG_INFO
(
"Create channels."
);
97
CsmaHelper
csma;
98
csma.
SetDeviceAttribute
(
"Mtu"
,
UintegerValue
(1500));
99
csma.
SetChannelAttribute
(
"DataRate"
,
DataRateValue
(5000000));
100
csma.
SetChannelAttribute
(
"Delay"
,
TimeValue
(MilliSeconds (2)));
101
NetDeviceContainer
d1 = csma.
Install
(net1);
102
NetDeviceContainer
d2 = csma.
Install
(net2);
103
NetDeviceContainer
d3 = csma.
Install
(net3);
104
NetDeviceContainer
d4 = csma.
Install
(net4);
105
NetDeviceContainer
d5 = csma.
Install
(net5);
106
NetDeviceContainer
d6 = csma.
Install
(net6);
107
108
NS_LOG_INFO
(
"Create networks and assign IPv6 Addresses."
);
109
Ipv6AddressHelper
ipv6;
110
111
ipv6.
SetBase
(
Ipv6Address
(
"2001:1::"
),
Ipv6Prefix
(64));
112
Ipv6InterfaceContainer
i1 = ipv6.
Assign
(d1);
113
i1.
SetForwarding
(1,
true
);
114
i1.
SetDefaultRouteInAllNodes
(1);
115
116
ipv6.
SetBase
(
Ipv6Address
(
"2001:2::"
),
Ipv6Prefix
(64));
117
Ipv6InterfaceContainer
i2 = ipv6.
Assign
(d2);
118
i2.
SetForwarding
(1,
true
);
119
i2.
SetDefaultRouteInAllNodes
(1);
120
121
ipv6.
SetBase
(
Ipv6Address
(
"2001:3::"
),
Ipv6Prefix
(64));
122
Ipv6InterfaceContainer
i3 = ipv6.
Assign
(d3);
123
i3.
SetForwarding
(0,
true
);
124
i3.
SetDefaultRouteInAllNodes
(0);
125
i3.
SetForwarding
(1,
true
);
126
i3.
SetDefaultRouteInAllNodes
(1);
127
128
ipv6.
SetBase
(
Ipv6Address
(
"2001:4::"
),
Ipv6Prefix
(64));
129
Ipv6InterfaceContainer
i4 = ipv6.
Assign
(d4);
130
i4.
SetForwarding
(0,
true
);
131
i4.
SetDefaultRouteInAllNodes
(0);
132
i4.
SetForwarding
(1,
true
);
133
i4.
SetDefaultRouteInAllNodes
(1);
134
135
ipv6.
SetBase
(
Ipv6Address
(
"2001:5::"
),
Ipv6Prefix
(64));
136
Ipv6InterfaceContainer
i5 = ipv6.
Assign
(d5);
137
i5.
SetForwarding
(0,
true
);
138
i5.
SetDefaultRouteInAllNodes
(0);
139
i5.
SetForwarding
(1,
true
);
140
i5.
SetDefaultRouteInAllNodes
(1);
141
142
ipv6.
SetBase
(
Ipv6Address
(
"2001:6::"
),
Ipv6Prefix
(64));
143
Ipv6InterfaceContainer
i6 = ipv6.
Assign
(d6);
144
i6.
SetForwarding
(0,
true
);
145
i6.
SetDefaultRouteInAllNodes
(0);
146
i6.
SetForwarding
(1,
true
);
147
i6.
SetDefaultRouteInAllNodes
(1);
148
149
NS_LOG_INFO
(
"Create Applications."
);
150
154
uint32_t packetSize = 1024;
155
uint32_t maxPacketCount = 1;
156
Time
interPacketInterval = Seconds (1.0);
157
158
std::vector<Ipv6Address> routersAddress;
159
routersAddress.push_back (i3.
GetAddress
(1, 1));
160
routersAddress.push_back (i4.
GetAddress
(1, 1));
161
routersAddress.push_back (i5.
GetAddress
(1, 1));
162
routersAddress.push_back (i6.
GetAddress
(1, 1));
163
routersAddress.push_back (i2.
GetAddress
(0, 1));
164
165
Ping6Helper
client;
166
/* remote address is first routers in RH0 => source routing */
167
client.
SetRemote
(i1.
GetAddress
(1, 1));
168
client.
SetAttribute
(
"MaxPackets"
,
UintegerValue
(maxPacketCount));
169
client.
SetAttribute
(
"Interval"
,
TimeValue
(interPacketInterval));
170
client.
SetAttribute
(
"PacketSize"
,
UintegerValue
(packetSize));
171
client.
SetRoutersAddress
(routersAddress);
172
ApplicationContainer
apps = client.
Install
(h0);
173
apps.
Start
(Seconds (1.0));
174
apps.
Stop
(Seconds (10.0));
175
176
AsciiTraceHelper
ascii;
177
csma.
EnableAsciiAll
(ascii.
CreateFileStream
(
"loose-routing-ipv6.tr"
));
178
csma.
EnablePcapAll
(
"loose-routing-ipv6"
,
true
);
179
180
NS_LOG_INFO
(
"Run Simulation."
);
181
Simulator::Run
();
182
Simulator::Destroy
();
183
NS_LOG_INFO
(
"Done."
);
184
}
185
examples
ipv6
loose-routing-ipv6.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2