Skip to main content

Simulation of Selective Repeat ARQ and Go-Back-N under High Error Rates using ns3 | NS3 Project 13

Simulation of Selective Repeat ARQ and Go-Back-N under High Error Rates using ns-3 | NS3 Project 13

To simulate Selective Repeat (SR) and Go-Back-N (GBN) ARQ protocols using ns-3 and compare their performance under high error rates in terms of throughput, delay, and packet loss.

LLM + PROMPT (VERY IMPORTANT)

LLM Used: ChatGPT (OpenAI GPT-5.3)

Prompt Used:

“Simulate Selective Repeat ARQ and compare its performance with Go-Back-N under high error rates using ns-3. Provide complete code, steps, and graph generation.”

NETWORK TOPOLOGY

  • Two nodes:
    • Node 0 → Sender
    • Node 1 → Receiver
  • Connected using Point-to-Point link

Parameters:

  • Bandwidth: 5 Mbps
  • Delay: 2 ms
  • Error Rate: High (e.g., 1e-3)

PROTOCOL MAPPING

  • GBN → TCP Tahoe
  • SR → TCP NewReno

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/error-model.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/netanim-module.h"

using namespace ns3;

int main(int argc, char *argv[])
{
  std::string tcpType = "TcpNewReno"; // default
  double errorRate = 1e-3;

  CommandLine cmd;
  cmd.AddValue("tcpType", "Tcp Variant", tcpType);
  cmd.AddValue("errorRate", "Error rate", errorRate);
  cmd.Parse(argc, argv);

  if (tcpType == "TcpNewReno")
  {
    Config::SetDefault("ns3::TcpL4Protocol::SocketType",
                       TypeIdValue(TcpNewReno::GetTypeId()));
  }
  else
  {
    Config::SetDefault("ns3::TcpL4Protocol::SocketType",
                       TypeIdValue(TcpHighSpeed::GetTypeId()));
  }

  NodeContainer nodes;
  nodes.Create(2);

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

  NetDeviceContainer devices = p2p.Install(nodes);
  p2p.EnablePcapAll("sr_vs_gbn");

  Ptr<RateErrorModel> em = CreateObject<RateErrorModel>();
  em->SetAttribute("ErrorRate", DoubleValue(errorRate));
  devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue(em));

  InternetStackHelper stack;
  stack.Install(nodes);

  Ipv4AddressHelper address;
  address.SetBase("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer interfaces = address.Assign(devices);

  uint16_t port = 5000;
  PacketSinkHelper sink("ns3::TcpSocketFactory",
                        InetSocketAddress(Ipv4Address::GetAny(), port));
  ApplicationContainer sinkApp = sink.Install(nodes.Get(1));
  sinkApp.Start(Seconds(0.0));
  sinkApp.Stop(Seconds(20.0));

  BulkSendHelper source("ns3::TcpSocketFactory",
                        InetSocketAddress(interfaces.GetAddress(1), port));
  source.SetAttribute("MaxBytes", UintegerValue(0));
  ApplicationContainer sourceApp = source.Install(nodes.Get(0));
  sourceApp.Start(Seconds(1.0));
  sourceApp.Stop(Seconds(20.0));

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

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

  monitor->CheckForLostPackets();
  auto stats = monitor->GetFlowStats();
  for (auto &flow : stats)
  {
    double throughput = flow.second.rxBytes * 8.0 /
      (flow.second.timeLastRxPacket.GetSeconds() -
       flow.second.timeFirstTxPacket.GetSeconds()) / 1024;
    std::cout << "Throughput: " << throughput << " Kbps\n";
    std::cout << "Lost Packets: " << flow.second.lostPackets << "\n";
    std::cout << "Delay: " << flow.second.delaySum.GetSeconds() << " sec\n";
  }

  monitor->SerializeToXmlFile("sr_vs_gbn.xml", true, true);
  AnimationInterface anim("sr_vs_gbn.xml");

  Simulator::Destroy();
  return 0;
}

Output:

i) Selective Repeat ARQ (3, 4, 5)

Selective Repeat ARQ Output

→ IO Graph Using Wireshark

Wireshark IO Graph for Selective Repeat

→ NetAnim

NetAnim Screenshot for Selective Repeat
NetAnim

→ Go-Back-N (3, 4, 5)

Go-Back-N Output

→ IO Graph Using Wireshark

Wireshark IO Graph for Go-Back-N

→ NetAnim

NetAnim Screenshot for Go-Back-N
NetAnim

SR vs GBN

Throughput Difference

Throughput Comparison: Selective Repeat vs Go-Back-N

OBSERVATION

1. Go-Back-N (TCP Tahoe)

  • Retransmits multiple packets after loss
  • High packet loss
  • Lower throughput
  • Higher delay

2. Selective Repeat (TCP NewReno)

  • Retransmits only lost packets
  • Efficient bandwidth usage
  • Higher throughput
  • Lower delay

RESULT

Selective Repeat ARQ performs better than Go-Back-N under high error conditions due to selective retransmission, resulting in improved throughput and reduced delay.

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