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