A Discrete-Event Network Simulator
API
fragmentation-ipv6-PMTU.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008-2009 Strasbourg University
4 * Copyright (c) 2013 Universita' di Firenze
5 * Copyright (c) 2022 Jadavpur University
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: David Gross <gdavid.devel@gmail.com>
21 * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
22 * Modified by Akash Mondal <a98mondal@gmail.com>
23 */
24
25// Network topology
26// //
27// // Src n0 r1 n1 r2 n2
28// // | _ | _ |
29// // =========|_|============|_|=========
30// // MTU 5000 2000 1500
31// //
32// // - Tracing of queues and packet receptions to file "fragmentation-ipv6-PMTU.tr"
33
34#include <fstream>
35#include "ns3/core-module.h"
36#include "ns3/network-module.h"
37#include "ns3/internet-module.h"
38#include "ns3/csma-module.h"
39#include "ns3/point-to-point-module.h"
40#include "ns3/internet-apps-module.h"
41#include "ns3/ipv6-static-routing-helper.h"
42
43#include "ns3/ipv6-routing-table-entry.h"
44
45using namespace ns3;
46
47NS_LOG_COMPONENT_DEFINE ("FragmentationIpv6PmtuExample");
48
49int
50main (int argc, char **argv)
51{
52 bool verbose = false;
53
54 CommandLine cmd (__FILE__);
55 cmd.AddValue ("verbose", "turn on log components", verbose);
56 cmd.Parse (argc, argv);
57
58 if (verbose)
59 {
60 LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
61 LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
62 LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
63 LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
64 LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
65 }
66
67 NS_LOG_INFO ("Create nodes.");
68 Ptr<Node> n0 = CreateObject<Node> ();
69 Ptr<Node> r1 = CreateObject<Node> ();
70 Ptr<Node> n1 = CreateObject<Node> ();
71 Ptr<Node> r2 = CreateObject<Node> ();
72 Ptr<Node> n2 = CreateObject<Node> ();
73
74 NodeContainer net1 (n0, r1);
75 NodeContainer net2 (r1, n1, r2);
76 NodeContainer net3 (r2, n2);
77 NodeContainer all (n0, r1, n1, r2, n2);
78
79 NS_LOG_INFO ("Create IPv6 Internet Stack");
80 InternetStackHelper internetv6;
81 internetv6.Install (all);
82
83 NS_LOG_INFO ("Create channels.");
85 csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
86 csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
87 csma.SetDeviceAttribute ("Mtu", UintegerValue (2000));
88 NetDeviceContainer d2 = csma.Install (net2); // CSMA Network with MTU 2000
89
90 csma.SetDeviceAttribute ("Mtu", UintegerValue (5000));
91 NetDeviceContainer d1 = csma.Install (net1); // CSMA Network with MTU 5000
92
94 pointToPoint.SetDeviceAttribute ("DataRate", DataRateValue (5000000));
95 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
96 pointToPoint.SetDeviceAttribute ("Mtu", UintegerValue (1500));
97 NetDeviceContainer d3 = pointToPoint.Install (net3); // P2P Network with MTU 1500
98
99 NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
101
102 ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
103 Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
104 i1.SetForwarding (1, true);
106
107 ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
108 Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
109 i2.SetForwarding (0, true);
111 i2.SetForwarding (1, true);
113 i2.SetForwarding (2, true);
115
116 ipv6.SetBase (Ipv6Address ("2001:3::"), Ipv6Prefix (64));
117 Ipv6InterfaceContainer i3 = ipv6.Assign (d3);
118 i3.SetForwarding (0, true);
120
121 Ipv6StaticRoutingHelper routingHelper;
122 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> (&std::cout);
123 routingHelper.PrintRoutingTableAt (Seconds (0), r1, routingStream);
124
125 /* Create a Ping6 application to send ICMPv6 echo request from r to n2 */
126 uint32_t packetSize = 1600; // Packet should fragment as intermediate link MTU is 1500
127 uint32_t maxPacketCount = 5;
128 Time interPacketInterval = Seconds (1.0);
129 Ping6Helper ping6;
130
131 ping6.SetLocal (i2.GetAddress (1, 1));
132 ping6.SetRemote (i3.GetAddress (1, 1));
133
134 ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
135 ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
136 ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
137 ApplicationContainer apps = ping6.Install (n1);
138 apps.Start (Seconds (2.0));
139 apps.Stop (Seconds (10.0));
140
141 /* Create a Ping6 application to send ICMPv6 echo request from n0 to n2 */
142 packetSize = 4000;
143 ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
144
145 ping6.SetLocal (i1.GetAddress (0, 1));
146 ping6.SetRemote (i3.GetAddress (1, 1));
147 apps = ping6.Install (n0);
148 apps.Start (Seconds (11.0));
149 apps.Stop (Seconds (20.0));
150
151 AsciiTraceHelper ascii;
152 csma.EnableAsciiAll (ascii.CreateFileStream ("fragmentation-ipv6-PMTU.tr"));
153 csma.EnablePcapAll (std::string ("fragmentation-ipv6-PMTU"), true);
154 pointToPoint.EnablePcapAll (std::string ("fragmentation-ipv6-PMTU"), true);
155
156 NS_LOG_INFO ("Run Simulation.");
157 Simulator::Run ();
158 Simulator::Destroy ();
159 NS_LOG_INFO ("Done.");
160}
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:163
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:229
build a set of CsmaNetDevice objects
Definition: csma-helper.h:47
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
static void PrintRoutingTableAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of a node at a particular time.
Helper class that adds ns3::Ipv6StaticRouting objects.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Ping6 application helper.
Definition: ping6-helper.h:39
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:40
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:50
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:45
void SetLocal(Ipv6Address ip)
Set the local IPv6 address.
Definition: ping6-helper.cc:35
Build a set of PointToPointNetDevice objects.
Hold variables of type string.
Definition: string.h:41
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
pointToPoint
Definition: first.py:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
csma
Definition: second.py:63
cmd
Definition: second.py:35
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.