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:
|
|
Animation Details
|
|
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 |
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.
- 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.
- 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
Post a Comment