Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

CE257 DATA COMMUNICATION & NETWORKING 20CE158

Practical-9
AIM: Wireshark packet capture and Measurement of various types of Delay in TCP
---------------------------------------------------------------------------------------------------------------------------
Tools required:
1. Desktop Computer
2. Cisco Packet Tracer
Simulate different scenarios given below in Cisco packet tracker and fill up table.

Note: While applying IP address, student need to allocate IP address as per his/her student
ID. For Example, if student ID is 20ce005 then IP address allocation for first network should
start with 5.0.0.0. For subsequent network, it should start with ID+1 i.e. 6.0.0.0, 7.0.0.0. and
so on.
Submission: After writing answer into this word document, Student need to change name to his ID
followed by practical number. Ex 20ce005_Pr1.docx. Upload on assignment segment.
Rubrics: Nicely drafted document with clarity in answers leads to full marks. Otherwise, submission
carries proportional mark.
Recommended to type, avoid copy-past to increase your typing skill.

Executing fourth.cc
$ cp examples/tutorial/fourth.cc scratch/fourth.cc

Running fourth.cc
$ ./waf --run scratch/fourth

Output will be
$ Traced 0 to 1234

Here fourth.cc is simple program to understand tracing.

Executing fifth.cc
Page 1 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

$ cp examples/tutorial/fifth.cc scratch/fifth.cc

We here want to observe the change in Tcp Congestion window

Here topology in fifth.cc is point-to-point

class MyApp : public Application


{
…..
…..
…..
}
this class inherits from the ns-3 Application class. Which path is
src/network/model/application.h MyApp class is obligated to override the StartApplication and
StopApplication methods. These methods are automatically called when MyApp is required to start
and stop sending data during the simulation.

void
MyApp::SendPacket (void)
{
Ptr<Packet> packet = Create<Packet> (m_packetSize);
m_socket->Send (packet);

Page 2 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

if (++m_packetsSent < m_nPackets)


{
ScheduleTx ();
}
}
In here ScheduleTx is called till all packets are sent.

void
MyApp::ScheduleTx (void)
{
if (m_running)
{
Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this);
}
}

In m_sendEvent SendPacket is called for next packet.

static void
CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
{
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
}
It will show output time and change in Congestion Window Size

static void
RxDrop (Ptr<const Packet> p)
{
NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
}

Page 3 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

It will called when packet are dropped and So after this big change in Congestion Window
size is reduced according to Congestion algorithm defined.

Running fifth.cc
$ ./waf --run scratch/fifth

Our motive is to understand slow-start and additive increase is done in fifth.cc

First We understand different terms used in Tcp Congestion Control

Congestion Window (cwnd) is a TCP state variable that limits the amount of data the TCP can send
into the network before receiving an ACK.

MSS: Maximum Segment Size refers to highest payload size, an end device is ready to accept within
single packet

Slow Start Phase : exponential increment – In this phase after every RTT the congestion window size
increments exponentially.

Initially cwnd = 1
After 1 RTT, cwnd = 2^(1) = 2
2 RTT, cwnd = 2^(2) = 4
3 RTT, cwnd = 2^(3) = 8

Page 4 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

Congestion Avoidance Phase : additive increment – This phase starts after the threshold value also
denoted as ssthresh. The size of cwnd(congestion window) increases additive. After each RTT cwnd =
cwnd + 1.

Initially cwnd = i
After 1 RTT, cwnd = i+1
2 RTT, cwnd = i+2
3 RTT, cwnd = i+3

Congestion Detection Phase : multiplicative decrement – If congestion occurs, the congestion window
size is decreased. The only way a sender can guess that congestion has occurred is the need to
retransmit a segment. Retransmission is needed to recover a missing packet which is assumed to have
been dropped by a router due to congestion. Retransmission can occur in one of two cases: when the
RTO timer times out or when three duplicate ACKs are received.

Case 1 : Retransmission due to Timeout – In this case congestion possibility is high.


(a) ssthresh is reduced to half of the current window size.
(b) set cwnd = 1
(c) start with slow start phase again.

Case 2 : Retransmission due to 3 Acknowledgement Duplicates – In this case congestion possibility is


less.
(a) ssthresh value reduces to half of the current window size.
(b) set cwnd= ssthresh
(c) start with congestion avoidance phase

Page 5 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

Now to See How Congestion Window is changing on Packet Transmission.

Plotting fifth.cc using gnuplot 

$ ./waf --run fifth > cwnd.dat 2>&1

$ gnuplot
gnuplot> set terminal png size 640,480
gnuplot> set output "cwnd.png"
gnuplot> plot "cwnd.dat" using 1:2 title 'Congestion Window' with linespoints
gnuplot> exit

Page 6 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

Here On 0 to 1 second slow-start is happening and Rxdrop is dropped at 1.13 second so it will go
congestion avoidance phase and addictive increase is happened. Rxdrop happens in near 1.4 second
and then additive increase happen and then it repeats.

Make new file of five.cc in scratch folder


/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/

Page 7 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/log.h"
#include "ns3/tcp-socket-base.h"

// Default Network Topology


//
//
// n1 n2 n3 n4
// | | | |
// ================
// LAN 10.1.2.0

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
class MyApp : public Application
{
public:

MyApp ();
virtual ~MyApp();

void Setup (Ptr<Socket> socket, Address address, uint32_t packetSize,


uint32_t nPackets, DataRate dataRate);

private:
virtual void StartApplication (void);
virtual void StopApplication (void);

void ScheduleTx (void);


void SendPacket (void);

Ptr<Socket> m_socket;
Address m_peer;
uint32_t m_packetSize;
uint32_t m_nPackets;
DataRate m_dataRate;
EventId m_sendEvent;
bool m_running;
uint32_t m_packetsSent;
};

MyApp::MyApp ()
: m_socket (0),
m_peer (),
m_packetSize (0),
m_nPackets (0),
m_dataRate (0),
m_sendEvent (),
Page 8 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

m_running (false),
m_packetsSent (0)
{
}

MyApp::~MyApp()
{
m_socket = 0;
}

void
MyApp::Setup (Ptr<Socket> socket, Address address, uint32_t packetSize,
uint32_t nPackets, DataRate dataRate)
{
m_socket = socket;
m_peer = address;
m_packetSize = packetSize;
m_nPackets = nPackets;
m_dataRate = dataRate;
}

void
MyApp::StartApplication (void)
{
m_running = true;
m_packetsSent = 0;
m_socket->Bind ();
m_socket->Connect (m_peer);
SendPacket ();
}

void
MyApp::StopApplication (void)
{
m_running = false;

if (m_sendEvent.IsRunning ())
{
Simulator::Cancel (m_sendEvent);
}

if (m_socket)
{
m_socket->Close ();
}
}

void
MyApp::SendPacket (void)
{
Ptr<Packet> packet = Create<Packet> (m_packetSize);
m_socket->Send (packet);

if (++m_packetsSent < m_nPackets)


{
ScheduleTx ();
}
}

Page 9 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

void
MyApp::ScheduleTx (void)
{
if (m_running)
{
Time tNext (Seconds (m_packetSize * 8 / static_cast<double>
(m_dataRate.GetBitRate ())));
m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket,
this);
}
}

static void
CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
{
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
}

static void
RxDrop (Ptr<const Packet> p)
{
NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
}

int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;

CommandLine cmd;
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices",
nCsma);
cmd.AddValue ("verbose", "Tell echo applications to log if true",
verbose);

cmd.Parse (argc,argv);

Config::SetDefault("ns3::TcpL4Protocol::SocketType",StringValue("ns3::T
cpNewReno"));

Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue
(1500));
Config::SetDefault("ns3::TcpSocket::InitialCwnd", UintegerValue (1));
Config::SetDefault("ns3::TcpSocketBase::MaxWindowSize", UintegerValue
(20*1500));
nCsma = nCsma == 0 ? 1 : nCsma;

NodeContainer csmaNodes;
csmaNodes.Create (nCsma);

CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("10Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (10000)));

NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);

Page 10 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ();


em->SetAttribute ("ErrorRate", DoubleValue (0.00001));
csmaDevices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue
(em));

InternetStackHelper stack;
stack.Install (csmaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);

uint16_t sinkPort = 8080;


Address sinkAddress (InetSocketAddress (csmaInterfaces.GetAddress
(1), sinkPort));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory",
InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps = packetSinkHelper.Install
(csmaNodes.Get (1));
sinkApps.Start (Seconds (0.));
sinkApps.Stop (Seconds (20.));

Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (csmaNodes.Get (0),


TcpSocketFactory::GetTypeId ());
ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow",
MakeCallback (&CwndChange));

Ptr<MyApp> app = CreateObject<MyApp> ();


app->Setup (ns3TcpSocket, sinkAddress, 10000, 1000, DataRate
("1Mbps"));
csmaNodes.Get (0)->AddApplication (app);
app->SetStartTime (Seconds (1.));
app->SetStopTime (Seconds (20.));

csmaDevices.Get (1)->TraceConnectWithoutContext ("PhyRxDrop",


MakeCallback (&RxDrop));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

csma.EnablePcapAll ("fir");
csma.EnablePcap ("fir", csmaDevices.Get (1), true);

Simulator::Run ();
Simulator::Destroy ();
return 0;
}

we can find tcp-congesion-ops.cc in src/internet/model/tcp-congestion-ops

On referring line 165-178 in Tcp-congesion-ops.cc file

uint32_t
TcpNewReno::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)

Page 11 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

{
  NS_LOG_FUNCTION (this << tcb << segmentsAcked);

  if (segmentsAcked >= 1)


    {
      tcb->m_cWnd += tcb->m_segmentSize;
      NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " <<
tcb->m_ssThresh);
      return segmentsAcked - 1;
    }

  return 0;
}

And after Changing values in line 172


tcb->m_cWnd += (2*tcb->m_segmentSize);

use gnuplot to plot graph

And
tcb->m_cWnd += (3*tcb->m_segmentSize);

Printing output to .dat file


./waf --run scratch/five > five1.dat 2>&1

Plotting five.cc

>gnuplot
set terminal png size 640,480
set output "five1.png"
plot "five1.dat" using 1:2 title 'Congestion Window' with linespoints
exit

Page 12 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

tcb->m_cWnd += tcb->m_segmentSize;

Page 13 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

tcb->m_cWnd += (2*tcb->m_segmentSize);

Page 14 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

tcb->m_cWnd += (3*tcb - >m_segmentSize);

Page 15 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

For numbers of in Congestion Window Y-axis 


  
>gnuplot
set terminal png size 640,480
set output "five1x.png"
plot "five1.dat" using ($1):($2/1500) title 'Congestion Window' with linespoints
exit

Page 16 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

Page 17 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

Now for different Congestion algorithm five.cc


Changing string value in line 166 in five.cc
Config::SetDefault("ns3::TcpL4Protocol::SocketType",StringValue("ns3::TcpNewReno"));

We can find different congestion algorithm header in src/internet/model/tcp-bic


And change value and in five.cc and run five.cc file in terminal

$ ./waf --run five

Making dat file of output


$ ./waf --run five > cwnd.dat 2>&1

for plotting graph with using datfile


gnuplot
set terminal png size 640,480
set output "fiveTcpNewReno.png"
plot "fiveTcpNewReno.dat" using 1:2 title 'Congestion Window' with linespoints
exit

Generated Graphs of different Congestion algorithm using gnuplot

1)

Page 18 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpBic

2)

Page 19 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpCubic

3)

Page 20 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpHighSpeed

4)

Page 21 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpHtcp
5)

Page 22 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpLinuxReno

6)

Page 23 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpNewReno

7)

Page 24 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpVegas

8)

Page 25 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpVeno

9)

Page 26 of 27
CE257 DATA COMMUNICATION & NETWORKING 20CE158

TcpWestWood

Page 27 of 27

You might also like