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 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 * Author: David Gross <gdavid.devel@gmail.com>
9 * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
10 * Modified by Akash Mondal <a98mondal@gmail.com>
11 */
12
13// Network topology
14// //
15// // Src n0 r1 n1 r2 n2
16// // | _ | _ |
17// // =========|_|============|_|=========
18// // MTU 5000 2000 1500
19// //
20// // - Tracing of queues and packet receptions to file "fragmentation-ipv6-PMTU.tr"
21
22#include "ns3/applications-module.h"
23#include "ns3/core-module.h"
24#include "ns3/csma-module.h"
25#include "ns3/internet-module.h"
26#include "ns3/ipv6-routing-table-entry.h"
27#include "ns3/ipv6-static-routing-helper.h"
28#include "ns3/network-module.h"
29#include "ns3/point-to-point-module.h"
30
31#include <fstream>
32
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE("FragmentationIpv6PmtuExample");
36
37int
38main(int argc, char** argv)
39{
40 bool verbose = false;
41
42 CommandLine cmd(__FILE__);
43 cmd.AddValue("verbose", "turn on log components", verbose);
44 cmd.Parse(argc, argv);
45
46 if (verbose)
47 {
48 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
49 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
50 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
51 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
52 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
53 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
54 }
55 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
56
57 NS_LOG_INFO("Create nodes.");
63
64 NodeContainer net1(n0, r1);
65 NodeContainer net2(r1, n1, r2);
66 NodeContainer net3(r2, n2);
67 NodeContainer all(n0, r1, n1, r2, n2);
68
69 NS_LOG_INFO("Create IPv6 Internet Stack");
70 InternetStackHelper internetv6;
71 internetv6.Install(all);
72
73 NS_LOG_INFO("Create channels.");
75 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
76 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
77 csma.SetDeviceAttribute("Mtu", UintegerValue(2000));
78 NetDeviceContainer d2 = csma.Install(net2); // CSMA Network with MTU 2000
79
80 csma.SetDeviceAttribute("Mtu", UintegerValue(5000));
81 NetDeviceContainer d1 = csma.Install(net1); // CSMA Network with MTU 5000
82
84 pointToPoint.SetDeviceAttribute("DataRate", DataRateValue(5000000));
85 pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
86 pointToPoint.SetDeviceAttribute("Mtu", UintegerValue(1500));
87 NetDeviceContainer d3 = pointToPoint.Install(net3); // P2P Network with MTU 1500
88
89 NS_LOG_INFO("Create networks and assign IPv6 Addresses.");
91
92 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
93 Ipv6InterfaceContainer i1 = ipv6.Assign(d1);
94 i1.SetForwarding(1, true);
96
97 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
98 Ipv6InterfaceContainer i2 = ipv6.Assign(d2);
99 i2.SetForwarding(0, true);
101 i2.SetForwarding(1, true);
103 i2.SetForwarding(2, true);
105
106 ipv6.SetBase(Ipv6Address("2001:3::"), Ipv6Prefix(64));
107 Ipv6InterfaceContainer i3 = ipv6.Assign(d3);
108 i3.SetForwarding(0, true);
110
111 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>(&std::cout);
112 Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(0), r1, routingStream);
113
114 // Create an UDP Echo server on n2
117 serverApps.Start(Seconds(0.0));
118 serverApps.Stop(Seconds(30.0));
119
120 uint32_t maxPacketCount = 5;
121
122 // Create an UDP Echo client on n1 to send UDP packets to n2 via r1
123 uint32_t packetSizeN1 = 1600; // Packet should fragment as intermediate link MTU is 1500
125 echoClient.SetAttribute("PacketSize", UintegerValue(packetSizeN1));
126 echoClient.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
127 ApplicationContainer clientAppsN1 = echoClient.Install(n1);
128 clientAppsN1.Start(Seconds(2.0));
129 clientAppsN1.Stop(Seconds(10.0));
130
131 // Create an UDP Echo client on n0 to send UDP packets to n2 via r0 and r1
132 uint32_t packetSizeN2 = 4000; // Packet should fragment as intermediate link MTU is 1500
133 echoClient.SetAttribute("PacketSize", UintegerValue(packetSizeN2));
134 echoClient.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
135 ApplicationContainer clientAppsN2 = echoClient.Install(n1);
136 clientAppsN2.Start(Seconds(11.0));
137 clientAppsN2.Stop(Seconds(20.0));
138
139 AsciiTraceHelper ascii;
140 csma.EnableAsciiAll(ascii.CreateFileStream("fragmentation-ipv6-PMTU.tr"));
141 csma.EnablePcapAll(std::string("fragmentation-ipv6-PMTU"), true);
142 pointToPoint.EnablePcapAll(std::string("fragmentation-ipv6-PMTU"), true);
143
144 NS_LOG_INFO("Run Simulation.");
147 NS_LOG_INFO("Done.");
148
149 return 0;
150}
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.
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.
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
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.
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.
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.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
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:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
echoClient
Definition first.py:48
serverApps
Definition first.py:43
pointToPoint
Definition first.py:27
echoServer
Definition first.py:41
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:291
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:93
bool verbose