Skip to main content

Simulate a dumbbell topology (10 senders + 10 receivers) with bottleneck link and study queue drop | NS3 Project 19

 Simulate a dumbbell topology (10 senders + 10 receivers) with a bottleneck link and study the queue drop

Objective

To simulate a dumbbell network topology with 10 senders and 10 receivers connected via two central routers, creating a bottleneck link. The objective is to analyse network congestion and TCP traffic behaviour, and study packet drops resulting from queue overflow at the bottleneck link.

Introduction

A dumbbell topology describes a network structure consisting of two clusters of nodes connected by a single, shared link, resembling a dumbbell. This architecture is widely used in network simulations to study congestion control mechanisms. When multiple senders transmit data simultaneously across the shared 'bottleneck' link, the incoming aggregate bandwidth often exceeds the link's capacity. As the bottleneck router's queue fills up, any excess packets are dropped, demonstrating congestion and triggering TCP backoff algorithms.

Methodology

1. Initialise the NS-3 simulator and parse command-line arguments.
2. Create 10 sender nodes, 10 receiver nodes, and 2 router nodes.
3. Configure high-speed Point-to-Point access links (100 Mbps, 1ms delay) connecting senders to Router 1, and receivers to Router 2.
4. Establish a low-bandwidth bottleneck link (10 Mbps, 20ms delay) between Router 1 and Router 2, strictly limiting its queue capacity to force packet drops.
5. Install the Internet stack on all nodes and appropriately assign IP addresses.
6. Populate global routing tables so that nodes can reach each other.
7. Install PacketSink applications on receivers and BulkSend (TCP) applications on senders, staggering start times to simulate realistic traffic.
8. Integrate FlowMonitor for traffic analysis and NetAnim for XML animation generation.
9. Execute the simulation for 10 seconds and serialize output files.

Explanation of the Source Code

The code defines a structure containing senders, receivers, and routers. We define two types of links using PointToPointHelper: high-speed access links and a restrictive bottleneck link with a strict DropTailQueue limit. We assign distinct IPv4 subnets to every interface and leverage IPv4GlobalRoutingHelper to automatically route packets. BulkSendHelper initiates long-lived TCP flows from senders, while PacketSinkHelper catches them. NetAnim logs visual states, and FlowMonitor tracks metrics like throughput and queue drops into an XML output file.

Prompt Used

Generate a complete NS-3 script in C++ simulating a dumbbell topology with 10 senders and 10 receivers communicating over a bottleneck link via two routers. Include NS-3 flow-monitor and NetAnim setups, restrict the bottleneck queue size to induce network drops, and provide the methodology, objective, and a plotting script to visualize the congestion output.

LLM Used

ChatGPT (Anti-Gravity)

Full Source Code

#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/ipv4-global-routing-helper.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/netanim-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("DumbbellTopology");

int main (int argc, char *argv[])
{
  uint32_t nSenders = 10;
  uint32_t nReceivers = 10;

  CommandLine cmd;
  cmd.Parse (argc, argv);

  // Nodes
  NodeContainer senders;
  senders.Create (nSenders);

  NodeContainer receivers;
  receivers.Create (nReceivers);

  NodeContainer routers;
  routers.Create (2); // Two routers for dumbbell

  // Links
  PointToPointHelper p2pAccess;
  p2pAccess.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
  p2pAccess.SetChannelAttribute ("Delay", StringValue ("1ms"));

  PointToPointHelper p2pBottleneck;
  p2pBottleneck.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
  p2pBottleneck.SetChannelAttribute ("Delay", StringValue ("20ms"));
  // Queue limit to force drops
  p2pBottleneck.SetQueue ("ns3::DropTailQueue", "MaxSize", StringValue ("50p"));

  // Topology connections
  std::vector<NetDeviceContainer> senderDevices;
  for (uint32_t i = 0; i < nSenders; ++i)
    {
      senderDevices.push_back (p2pAccess.Install (senders.Get (i), routers.Get (0)));
    }

  NetDeviceContainer bottleneckDevices;
  bottleneckDevices = p2pBottleneck.Install (routers.Get (0), routers.Get (1));

  std::vector<NetDeviceContainer> receiverDevices;
  for (uint32_t i = 0; i < nReceivers; ++i)
    {
      receiverDevices.push_back (p2pAccess.Install (routers.Get (1), receivers.Get (i)));
    }

  // Internet Stack
  InternetStackHelper stack;
  stack.Install (senders);
  stack.Install (receivers);
  stack.Install (routers);

  // IP Assignments
  Ipv4AddressHelper address;
 
  std::vector<Ipv4InterfaceContainer> senderInterfaces;
  for (uint32_t i = 0; i < nSenders; ++i)
    {
      std::ostringstream subnet;
      subnet << "10.1." << i + 1 << ".0";
      address.SetBase (subnet.str ().c_str (), "255.255.255.0");
      senderInterfaces.push_back (address.Assign (senderDevices[i]));
    }

  address.SetBase ("10.2.1.0", "255.255.255.0");
  Ipv4InterfaceContainer bottleneckInterfaces = address.Assign (bottleneckDevices);

  std::vector<Ipv4InterfaceContainer> receiverInterfaces;
  for (uint32_t i = 0; i < nReceivers; ++i)
    {
      std::ostringstream subnet;
      subnet << "10.3." << i + 1 << ".0";
      address.SetBase (subnet.str ().c_str (), "255.255.255.0");
      receiverInterfaces.push_back (address.Assign (receiverDevices[i]));
    }

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

  // Applications
  uint16_t port = 9;
  for (uint32_t i = 0; i < nReceivers; ++i)
    {
      PacketSinkHelper sink ("ns3::TcpSocketFactory",
                             InetSocketAddress (Ipv4Address::GetAny (), port));
      ApplicationContainer sinkApp = sink.Install (receivers.Get (i));
      sinkApp.Start (Seconds (0.0));
      sinkApp.Stop (Seconds (10.0));
    }

  for (uint32_t i = 0; i < nSenders; ++i)
    {
      BulkSendHelper source ("ns3::TcpSocketFactory",
                             InetSocketAddress (receiverInterfaces[i].GetAddress (1), port));
      source.SetAttribute ("MaxBytes", UintegerValue (0));
      ApplicationContainer sourceApp = source.Install (senders.Get (i));
      sourceApp.Start (Seconds (1.0 + i * 0.1)); // Stagger start times
      sourceApp.Stop (Seconds (10.0));
    }

  // Flow Monitor
  FlowMonitorHelper flowmon;
  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();

  // NetAnim
  AnimationInterface anim ("dumbbell-animation.xml");
  for (uint32_t i = 0; i < nSenders; ++i)
    {
      anim.SetConstantPosition (senders.Get (i), 10.0, 10.0 + i * 5);
    }
  anim.SetConstantPosition (routers.Get (0), 30.0, 30.0);
  anim.SetConstantPosition (routers.Get (1), 60.0, 30.0);
  for (uint32_t i = 0; i < nReceivers; ++i)
    {
      anim.SetConstantPosition (receivers.Get (i), 80.0, 10.0 + i * 5);
    }

  Simulator::Stop (Seconds (10.0));
  Simulator::Run ();

  monitor->SerializeToXmlFile ("flowmon-results.xml", true, true);

  Simulator::Destroy ();
  return 0;
}

OUTPUTS

The following figures show the simulation animation and the corresponding congestion graph.

Figure 1: Dumbbell Topology Animation Showing Packet Flow



Figure 2: Graph Showing Packet Drop / Throughput Behavior Under Congestion


Explanation of Graph

The packet drops occur directly due to the strict buffer limitation (50 packets) configured at the bottleneck DropTail queue. Because the dumbbell topology channels ten high-speed (100 Mbps) connections into a single constrained bottleneck link (10 Mbps), the aggregate incoming bandwidth severely exceeds what the hardware can process. This extreme disparity forces the central router to hold packets in its queue until fully saturated. Upon reaching this threshold, the bottleneck link immediately discards any excess arriving packets, triggering simultaneous loss events per connection. The observed trend across the graph illustrates high-volume random drops varying per flow, confirming the chaotic nature of congestion and resulting TCP window backoffs.

Execution Command

./ns3 run scratch/23bps1xxx.cc

Explanation

- This command runs the NS-3 simulation.

- It generates animation and flow monitoring output files.

Screenshot Procedure

- Open NetAnim using the generated XML file.

- Capture animation screenshot.

- Capture graph screenshot.

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...

NS2 (NS-2.35) Installation in Ubuntu 11.10

This post will help you in installing Network Simulator 2 version NS2.35 in Ubuntu 11.10 Instructions Install Ubuntu Download NS-2.35 ( http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download ) Unzip or untar it to any folder (recommended is /home/ loginname) using the following commands one by one sudo apt-get update sudo apt-get install build-essential autoconf automake libxmu-dev tar zxvf ns-allinone-2.35.tar.gz cd ns-allinone-2.35 ./install Once installed the PATH information will be provided to you. Copy the PATH and LD_LIBRARY_PATH Variable to .bashrc (see a dot in the beginning) Input the path information in .bashrc file like this export PATH=$PATH:<Place your paths here> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: <place the LD_LIBRARY_PATHS> here. Once done, save the file and close execute the command source .bashrc try ns or nam to see whether your installation succeeded.