A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fragmentation-ipv6-PMTU.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Strasbourg University
3 * Copyright (c) 2013 Universita' di Firenze
4 * Copyright (c) 2022 Jadavpur University
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: David Gross <gdavid.devel@gmail.com>
20 * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
21 * Modified by Akash Mondal <a98mondal@gmail.com>
22 */
23
24// Network topology
25// //
26// // Src n0 r1 n1 r2 n2
27// // | _ | _ |
28// // =========|_|============|_|=========
29// // MTU 5000 2000 1500
30// //
31// // - Tracing of queues and packet receptions to file "fragmentation-ipv6-PMTU.tr"
32
33#include "ns3/applications-module.h"
34#include "ns3/core-module.h"
35#include "ns3/csma-module.h"
36#include "ns3/internet-module.h"
37#include "ns3/ipv6-routing-table-entry.h"
38#include "ns3/ipv6-static-routing-helper.h"
39#include "ns3/network-module.h"
40#include "ns3/point-to-point-module.h"
41
42#include <fstream>
43
44using namespace ns3;
45
46NS_LOG_COMPONENT_DEFINE("FragmentationIpv6PmtuExample");
47
48int
49main(int argc, char** argv)
50{
51 bool verbose = false;
52
53 CommandLine cmd(__FILE__);
54 cmd.AddValue("verbose", "turn on log components", verbose);
55 cmd.Parse(argc, argv);
56
57 if (verbose)
58 {
59 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
60 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
61 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
62 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
63 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
64 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
65 }
66 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
67
68 NS_LOG_INFO("Create nodes.");
69 Ptr<Node> n0 = CreateObject<Node>();
70 Ptr<Node> r1 = CreateObject<Node>();
71 Ptr<Node> n1 = CreateObject<Node>();
72 Ptr<Node> r2 = CreateObject<Node>();
73 Ptr<Node> n2 = CreateObject<Node>();
74
75 NodeContainer net1(n0, r1);
76 NodeContainer net2(r1, n1, r2);
77 NodeContainer net3(r2, n2);
78 NodeContainer all(n0, r1, n1, r2, n2);
79
80 NS_LOG_INFO("Create IPv6 Internet Stack");
81 InternetStackHelper internetv6;
82 internetv6.Install(all);
83
84 NS_LOG_INFO("Create channels.");
86 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
87 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
88 csma.SetDeviceAttribute("Mtu", UintegerValue(2000));
89 NetDeviceContainer d2 = csma.Install(net2); // CSMA Network with MTU 2000
90
91 csma.SetDeviceAttribute("Mtu", UintegerValue(5000));
92 NetDeviceContainer d1 = csma.Install(net1); // CSMA Network with MTU 5000
93
95 pointToPoint.SetDeviceAttribute("DataRate", DataRateValue(5000000));
96 pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
97 pointToPoint.SetDeviceAttribute("Mtu", UintegerValue(1500));
98 NetDeviceContainer d3 = pointToPoint.Install(net3); // P2P Network with MTU 1500
99
100 NS_LOG_INFO("Create networks and assign IPv6 Addresses.");
102
103 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
104 Ipv6InterfaceContainer i1 = ipv6.Assign(d1);
105 i1.SetForwarding(1, true);
107
108 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
109 Ipv6InterfaceContainer i2 = ipv6.Assign(d2);
110 i2.SetForwarding(0, true);
112 i2.SetForwarding(1, true);
114 i2.SetForwarding(2, true);
116
117 ipv6.SetBase(Ipv6Address("2001:3::"), Ipv6Prefix(64));
118 Ipv6InterfaceContainer i3 = ipv6.Assign(d3);
119 i3.SetForwarding(0, true);
121
122 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>(&std::cout);
123 Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(0), r1, routingStream);
124
125 // Create an UDP Echo server on n2
128 serverApps.Start(Seconds(0.0));
129 serverApps.Stop(Seconds(30.0));
130
131 uint32_t maxPacketCount = 5;
132
133 // Create an UDP Echo client on n1 to send UDP packets to n2 via r1
134 uint32_t packetSizeN1 = 1600; // Packet should fragment as intermediate link MTU is 1500
136 echoClient.SetAttribute("PacketSize", UintegerValue(packetSizeN1));
137 echoClient.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
138 ApplicationContainer clientAppsN1 = echoClient.Install(n1);
139 clientAppsN1.Start(Seconds(2.0));
140 clientAppsN1.Stop(Seconds(10.0));
141
142 // Create an UDP Echo client on n0 to send UDP packets to n2 via r0 and r1
143 uint32_t packetSizeN2 = 4000; // Packet should fragment as intermediate link MTU is 1500
144 echoClient.SetAttribute("PacketSize", UintegerValue(packetSizeN2));
145 echoClient.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
146 ApplicationContainer clientAppsN2 = echoClient.Install(n1);
147 clientAppsN2.Start(Seconds(11.0));
148 clientAppsN2.Stop(Seconds(20.0));
149
150 AsciiTraceHelper ascii;
151 csma.EnableAsciiAll(ascii.CreateFileStream("fragmentation-ipv6-PMTU.tr"));
152 csma.EnablePcapAll(std::string("fragmentation-ipv6-PMTU"), true);
153 pointToPoint.EnablePcapAll(std::string("fragmentation-ipv6-PMTU"), true);
154
155 NS_LOG_INFO("Run Simulation.");
158 NS_LOG_INFO("Done.");
159
160 return 0;
161}
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
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:174
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.
Definition: data-rate.h:296
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:49
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:455
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.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1406
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
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:1319
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
ns echoServer
Definition: first.py:52
ns serverApps
Definition: first.py:54
ns echoClient
Definition: first.py:59
ns pointToPoint
Definition: first.py:38
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:104
ns cmd
Definition: second.py:40
ns csma
Definition: second.py:63
bool verbose