Skip to main content

Simulate and trace TCP Slow-Start, Congestion Avoidance, and Fast Recovery phases | NS3 Project 29

Analysis of TCP Congestion Control Phases

Simulating TCP NewReno on a Dumbbell Topology in NS-3

1. Project Overview

This project simulates a Dumbbell Topology to observe how TCP NewReno manages network congestion. By creating a bottleneck link with limited bandwidth (1 Mbps), we force the TCP protocol to transition through its three primary phases: Slow-Start, Congestion Avoidance, and Fast Recovery.

2. LLM Source Documentation

To develop the source code (24bps1052.cc), the following AI assistant was utilised:

  • LLM Used: Gemini 3 Flash (Google)
  • Prompt Provided:
    "Hey, can you help me write an ns-3.44 script for my networking lab? I need to save it as scratch/23bps1xxx.cc. I need a Dumbbell Topology with 4 nodes: Node 0 and 1 connect to Node 2 (the router), and Node 2 connects to Node 3. Set the link between 2 and 3 to 1Mbps so it becomes a bottleneck. Use TCP NewReno for the simulation. I need to generate a trace file called cwnd_trace.dat for Gnuplot and an XML file called tcp_variants.xml for NetAnim. Make sure the code runs with the command ./ns3 run scratch/24bps1052.cc and lasts for about 20 seconds."

3. Network Visualization (Animation)

The screenshots show the 4 nodes and the packets moving across the links:

NetAnim Topology View

Animation Details

NetAnim Execution Trace

The animation window confirms the Dumbbell Topology. Nodes 0 and 1 act as traffic generators, while Node 2 serves as the gateway/router. Because the link between Node 2 and Node 3 is restricted to 1 Mbps (while the access links are 10 Mbps), we can visually observe packet queuing and drops at Node 2 once the aggregated transmission rate exceeds bottleneck link capacity.

4. Result Analysis (Gnuplot Graph)

final_graph.png Screenshot
final_graph.png Screenshot

Information about the Graph & Phase Analysis

The graph depicts the Congestion Window (Cwnd) over time. The following operational phases are clearly identifiable:

  • Phase 1: Slow-Start (Exponential Growth): During the first few seconds, Cwnd grows exponentially (doubling every RTT). This is the probing phase where TCP attempts to discover the maximum available path bandwidth.
  • Phase 2: Congestion Avoidance (Linear Growth): Once Cwnd reaches the slow-start threshold (ssthresh), growth shifts to a linear progression (+1 MSS per RTT). This follows the AIMD (Additive Increase Multiplicative Decrease) algorithm to delay buffer saturation.
  • Phase 3: Fast Recovery (Multiplicative Decrease): When the bottleneck link saturates and a packet drop occurs, TCP NewReno receives 3 duplicate ACKs. Rather than dropping the window back to 1 MSS, it performs Multiplicative Decrease (halving the congestion window). This keeps network throughput high while the bottleneck queue clears.

5. Technical Inference

AIMD Stability: The characteristic "sawtooth" waveform validates the stability of the NewReno implementation, maximizing link utilization while preventing persistent congestion collapse.

  1. Bottleneck Impact: Restricting the bottleneck link to 1 Mbps successfully induced packet drops and triggered the Fast Retransmit mechanism. Without an intentional bottleneck, the window would exhibit a monotonic linear ramp without exercising recovery phases.
  2. Trace Accuracy: The Gnuplot curves align with theoretical TCP NewReno dynamics, verifying that the configured link rates (1 Mbps bottleneck, 10 Mbps access) and propagation delays (10 ms vs. 2 ms) were properly enforced by the simulator.

6. Source Code

Save the simulation script below inside your local scratch/congestion.cc (or scratch/24bps1052.cc) file:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("TcpVariantsComparison");

// Function to trace Cwnd changes
static void
CwndChange (Ptr<OutputStreamWrapper> stream, uint32_t oldCwnd, uint32_t newCwnd)
{
  *stream->GetStream () << Simulator::Now ().GetSeconds () << "\t" << newCwnd << std::endl;
}

int main (int argc, char *argv[])
{
  Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue ("ns3::TcpNewReno"));

  NodeContainer nodes;
  nodes.Create (4);

  PointToPointHelper p2p;
  p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));

  NetDeviceContainer devices02 = p2p.Install (nodes.Get (0), nodes.Get (2));
  NetDeviceContainer devices12 = p2p.Install (nodes.Get (1), nodes.Get (2));

  p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps")); 
  p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
  NetDeviceContainer devices23 = p2p.Install (nodes.Get (2), nodes.Get (3));

  InternetStackHelper stack;
  stack.Install (nodes);

  Ipv4AddressHelper address;
  address.SetBase ("10.1.1.0", "255.255.255.0");
  address.Assign (devices02);
 
  address.SetBase ("10.1.2.0", "255.255.255.0");
  address.Assign (devices12);

  address.SetBase ("10.1.3.0", "255.255.255.0");
  Ipv4InterfaceContainer interfaces23 = address.Assign (devices23);

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

  uint16_t port = 8080;
  Address sinkAddress (InetSocketAddress (interfaces23.GetAddress (1), port));
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
  ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (3));
  sinkApps.Start (Seconds (0.0));
  sinkApps.Stop (Seconds (20.0));

  OnOffHelper clientHelper ("ns3::TcpSocketFactory", sinkAddress);
  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
  clientHelper.SetAttribute ("DataRate", StringValue ("2Mbps"));
  clientHelper.SetAttribute ("PacketSize", uint32_t (1024));

  ApplicationContainer clientApps = clientHelper.Install (nodes.Get (0));
  clientApps.Start (Seconds (1.0));
  clientApps.Stop (Seconds (15.0));

  // CWND TRACING
  AsciiTraceHelper asciiTraceHelper;
  Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("cwnd_trace.dat");
  Simulator::Schedule (Seconds (1.1), &Config::ConnectWithoutContext, 
                       "/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", 
                       MakeBoundCallback (&CwndChange, stream));

  // ANIMATION
  AnimationInterface anim ("tcp_variants.xml");
  anim.SetConstantPosition (nodes.Get (0), 10.0, 10.0);
  anim.SetConstantPosition (nodes.Get (1), 10.0, 30.0);
  anim.SetConstantPosition (nodes.Get (2), 30.0, 20.0);
  anim.SetConstantPosition (nodes.Get (3), 50.0, 20.0);

  Simulator::Stop (Seconds (20.0));
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

7. Conclusion

The simulation successfully achieved all objectives. The dumbbell topology was modeled and visualized in NetAnim, and the TCP congestion control stages were traced and verified via Gnuplot. The results illustrate how TCP NewReno sustains link utilization during packet drop events by engaging Fast Recovery rather than resorting to a full Slow-Start reset.

Comments

Popular posts from this blog

How to Create Ubuntu 24.04 Bootable USB Using Rufus [Step-by-Step Guide]

How to Create Ubuntu 24.04 Bootable USB Using Rufus [Step-by-Step Guide] Are you planning to install or try Ubuntu 24.04 LTS ? The easiest and most reliable method is to create a bootable USB drive using Rufus on a Windows system. This detailed guide will help you create a Ubuntu 24.04 USB bootloader using Rufus with easy-to-follow steps and screenshots (optional). Here is the complete video of the bootloader creation and OS installation in Windows 11. 🧰 Requirements A USB flash drive (minimum 8GB recommended) A Windows PC Ubuntu 24.04 LTS ISO file Rufus USB creation tool 🧾 Steps to Create a Ubuntu 24.04 Bootable USB Using Rufus ✅ Step 1: Download Ubuntu 24.04 ISO Visit the official Ubuntu website and download the Ubuntu 24.04 LTS ISO file . ✅ Step 2: Download and Run Rufus Head to Rufus official site and download the latest version. Open the executable file (no installation required). ✅ Step 3: Insert USB Drive Plug in your USB drive. Rufus ...

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libc...

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update Since, it...