A Discrete-Event Network Simulator
API
loose-routing-ipv6.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 Strasbourg University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: David Gross <gdavid.devel@gmail.com>
18 */
19
20// Network topology
21// //
22// //
23// // +------------+
24// // +------------+ |---| Router 1 |---|
25// // | Host 0 |--| | [------------] |
26// // [------------] | | |
27// // | +------------+ |
28// // +--| | +------------+
29// // | Router 0 | | Router 2 |
30// // +--| | [------------]
31// // | [------------] |
32// // +------------+ | | |
33// // | Host 1 |--| | +------------+ |
34// // [------------] |---| Router 3 |---|
35// // [------------]
36// //
37// //
38// // - Tracing of queues and packet receptions to file "loose-routing-ipv6.tr"
39
40#include "ns3/core-module.h"
41#include "ns3/csma-module.h"
42#include "ns3/internet-apps-module.h"
43#include "ns3/internet-module.h"
44#include "ns3/ipv6-header.h"
45
46#include <fstream>
47
48using namespace ns3;
49
50NS_LOG_COMPONENT_DEFINE("LooseRoutingIpv6Example");
51
52int
53main(int argc, char** argv)
54{
55 bool verbose = false;
56
57 CommandLine cmd(__FILE__);
58 cmd.AddValue("verbose", "turn on log components", verbose);
59 cmd.Parse(argc, argv);
60
61 if (verbose)
62 {
63 LogComponentEnable("Ipv6ExtensionLooseRouting", LOG_LEVEL_ALL);
64 LogComponentEnable("Ipv6Extension", LOG_LEVEL_ALL);
65 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
66 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
67 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
68 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
69 LogComponentEnable("NdiscCache", LOG_LEVEL_ALL);
70 }
71
72 NS_LOG_INFO("Create nodes.");
73 Ptr<Node> h0 = CreateObject<Node>();
74 Ptr<Node> h1 = CreateObject<Node>();
75 Ptr<Node> r0 = CreateObject<Node>();
76 Ptr<Node> r1 = CreateObject<Node>();
77 Ptr<Node> r2 = CreateObject<Node>();
78 Ptr<Node> r3 = CreateObject<Node>();
79
80 NodeContainer net1(h0, r0);
81 NodeContainer net2(h1, r0);
82 NodeContainer net3(r0, r1);
83 NodeContainer net4(r1, r2);
84 NodeContainer net5(r2, r3);
85 NodeContainer net6(r3, r0);
86 NodeContainer all;
87 all.Add(h0);
88 all.Add(h1);
89 all.Add(r0);
90 all.Add(r1);
91 all.Add(r2);
92 all.Add(r3);
93
94 NS_LOG_INFO("Create IPv6 Internet Stack");
95 InternetStackHelper internetv6;
96 internetv6.Install(all);
97
98 NS_LOG_INFO("Create channels.");
100 csma.SetDeviceAttribute("Mtu", UintegerValue(1500));
101 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
102 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
103 NetDeviceContainer d1 = csma.Install(net1);
104 NetDeviceContainer d2 = csma.Install(net2);
105 NetDeviceContainer d3 = csma.Install(net3);
106 NetDeviceContainer d4 = csma.Install(net4);
107 NetDeviceContainer d5 = csma.Install(net5);
108 NetDeviceContainer d6 = csma.Install(net6);
109
110 NS_LOG_INFO("Create networks and assign IPv6 Addresses.");
112
113 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
114 Ipv6InterfaceContainer i1 = ipv6.Assign(d1);
115 i1.SetForwarding(1, true);
117
118 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
119 Ipv6InterfaceContainer i2 = ipv6.Assign(d2);
120 i2.SetForwarding(1, true);
122
123 ipv6.SetBase(Ipv6Address("2001:3::"), Ipv6Prefix(64));
124 Ipv6InterfaceContainer i3 = ipv6.Assign(d3);
125 i3.SetForwarding(0, true);
127 i3.SetForwarding(1, true);
129
130 ipv6.SetBase(Ipv6Address("2001:4::"), Ipv6Prefix(64));
131 Ipv6InterfaceContainer i4 = ipv6.Assign(d4);
132 i4.SetForwarding(0, true);
134 i4.SetForwarding(1, true);
136
137 ipv6.SetBase(Ipv6Address("2001:5::"), Ipv6Prefix(64));
138 Ipv6InterfaceContainer i5 = ipv6.Assign(d5);
139 i5.SetForwarding(0, true);
141 i5.SetForwarding(1, true);
143
144 ipv6.SetBase(Ipv6Address("2001:6::"), Ipv6Prefix(64));
145 Ipv6InterfaceContainer i6 = ipv6.Assign(d6);
146 i6.SetForwarding(0, true);
148 i6.SetForwarding(1, true);
150
151 NS_LOG_INFO("Create Applications.");
152
156 uint32_t packetSize = 1024;
157 uint32_t maxPacketCount = 1;
158 Time interPacketInterval = Seconds(1.0);
159
160 std::vector<Ipv6Address> routersAddress;
161 routersAddress.push_back(i3.GetAddress(1, 1));
162 routersAddress.push_back(i4.GetAddress(1, 1));
163 routersAddress.push_back(i5.GetAddress(1, 1));
164 routersAddress.push_back(i6.GetAddress(1, 1));
165 routersAddress.push_back(i2.GetAddress(0, 1));
166
167 Ping6Helper client;
168 /* remote address is first routers in RH0 => source routing */
169 client.SetRemote(i1.GetAddress(1, 1));
170 client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
171 client.SetAttribute("Interval", TimeValue(interPacketInterval));
172 client.SetAttribute("PacketSize", UintegerValue(packetSize));
173 client.SetRoutersAddress(routersAddress);
174 ApplicationContainer apps = client.Install(h0);
175 apps.Start(Seconds(1.0));
176 apps.Stop(Seconds(10.0));
177
178 AsciiTraceHelper ascii;
179 csma.EnableAsciiAll(ascii.CreateFileStream("loose-routing-ipv6.tr"));
180 csma.EnablePcapAll("loose-routing-ipv6", true);
181
182 NS_LOG_INFO("Run Simulation.");
183 Simulator::Run();
184 Simulator::Destroy();
185 NS_LOG_INFO("Done.");
186
187 return 0;
188}
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
Definition: trace-helper.h:173
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
AttributeValue implementation for DataRate.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:50
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ping6 application helper.
Definition: ping6-helper.h:38
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:41
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:53
void SetRoutersAddress(std::vector< Ipv6Address > routers)
Set routers addresses for routing type 0.
Definition: ping6-helper.cc:77
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:47
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1425
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
void LogComponentEnable(const char *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:358
csma
Definition: second.py:56
cmd
Definition: second.py:33
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.