1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3
* Copyright (c) 2009 Strasbourg University
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;
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.
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
18
* Author: David Gross <gdavid.devel@gmail.com>
25
// // +------------+ |---| Router 1 |---|
26
// // | Host 0 |--| | [------------] |
27
// // [------------] | | |
28
// // | +------------+ |
29
// // +--| | +------------+
30
// // | Router 0 | | Router 2 |
31
// // +--| | [------------]
32
// // | [------------] |
33
// // +------------+ | | |
34
// // | Host 1 |--| | +------------+ |
35
// // [------------] |---| Router 3 |---|
39
// // - Tracing of queues and packet receptions to file "loose-routing-ipv6.tr"
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"
49
NS_LOG_COMPONENT_DEFINE ("LooseRoutingIpv6Example");
51
int main (int argc, char **argv)
54
LogComponentEnable ("Ipv6ExtensionLooseRouting", LOG_LEVEL_ALL);
55
LogComponentEnable ("Ipv6Extension", LOG_LEVEL_ALL);
56
LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
57
LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
58
LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
59
LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
60
LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
64
cmd.Parse (argc, argv);
66
NS_LOG_INFO ("Create nodes.");
67
Ptr<Node> h0 = CreateObject<Node> ();
68
Ptr<Node> h1 = CreateObject<Node> ();
69
Ptr<Node> r0 = CreateObject<Node> ();
70
Ptr<Node> r1 = CreateObject<Node> ();
71
Ptr<Node> r2 = CreateObject<Node> ();
72
Ptr<Node> r3 = CreateObject<Node> ();
74
NodeContainer net1 (h0, r0);
75
NodeContainer net2 (h1, r0);
76
NodeContainer net3 (r0, r1);
77
NodeContainer net4 (r1, r2);
78
NodeContainer net5 (r2, r3);
79
NodeContainer net6 (r3, r0);
88
NS_LOG_INFO ("Create IPv6 Internet Stack");
89
InternetStackHelper internetv6;
90
internetv6.Install (all);
92
NS_LOG_INFO ("Create channels.");
94
csma.SetDeviceAttribute ("Mtu", UintegerValue (1500));
95
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
96
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
97
NetDeviceContainer d1 = csma.Install (net1);
98
NetDeviceContainer d2 = csma.Install (net2);
99
NetDeviceContainer d3 = csma.Install (net3);
100
NetDeviceContainer d4 = csma.Install (net4);
101
NetDeviceContainer d5 = csma.Install (net5);
102
NetDeviceContainer d6 = csma.Install (net6);
104
NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
105
Ipv6AddressHelper ipv6;
107
ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
108
Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
109
i1.SetRouter (1, true);
111
ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
112
Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
113
i2.SetRouter (1, true);
115
ipv6.NewNetwork (Ipv6Address ("2001:3::"), 64);
116
Ipv6InterfaceContainer i3 = ipv6.Assign (d3);
117
i3.SetRouter (0, true);
118
i3.SetRouter (1, true);
120
ipv6.NewNetwork (Ipv6Address ("2001:4::"), 64);
121
Ipv6InterfaceContainer i4 = ipv6.Assign (d4);
122
i4.SetRouter (0, true);
123
i4.SetRouter (1, true);
125
ipv6.NewNetwork (Ipv6Address ("2001:5::"), 64);
126
Ipv6InterfaceContainer i5 = ipv6.Assign (d5);
127
i5.SetRouter (0, true);
128
i5.SetRouter (1, true);
130
ipv6.NewNetwork (Ipv6Address ("2001:6::"), 64);
131
Ipv6InterfaceContainer i6 = ipv6.Assign (d6);
132
i6.SetRouter (0, true);
133
i6.SetRouter (1, true);
135
NS_LOG_INFO ("Create Applications.");
138
* ICMPv6 Echo from h0 to h1 port 7
140
uint32_t packetSize = 1024;
141
uint32_t maxPacketCount = 1;
142
Time interPacketInterval = Seconds (1.0);
144
std::vector<Ipv6Address> routersAddress;
145
routersAddress.push_back (i3.GetAddress (1, 1));
146
routersAddress.push_back (i4.GetAddress (1, 1));
147
routersAddress.push_back (i5.GetAddress (1, 1));
148
routersAddress.push_back (i6.GetAddress (1, 1));
149
routersAddress.push_back (i2.GetAddress (0, 1));
152
/* remote address is first routers in RH0 => source routing */
153
client.SetRemote (i1.GetAddress (1, 1));
154
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
155
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
156
client.SetAttribute ("PacketSize", UintegerValue (packetSize));
157
client.SetRoutersAddress (routersAddress);
158
ApplicationContainer apps = client.Install (h0);
159
apps.Start (Seconds (1.0));
160
apps.Stop (Seconds (10.0));
162
AsciiTraceHelper ascii;
163
csma.EnableAsciiAll (ascii.CreateFileStream ("loose-routing-ipv6.tr"));
164
csma.EnablePcapAll ("loose-routing-ipv6", true);
166
NS_LOG_INFO ("Run Simulation.");
168
Simulator::Destroy ();
169
NS_LOG_INFO ("Done.");