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 ns3 | 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:

o   Node 0 → Sender

o   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"; // defau2lt
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)

6405001986d89337b3af25a5d415f611.png

→ IO grahp Using Wireshark

4108dba455c853553106c0f2445be43e.png

→ Net Anim

NetAnim


 

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

935b431ffd4d3ec562e2e2a777b15379.png

→ IO grahp Using Wireshark

821c3d2c261d687096f48ec22a66bef8.png

→ Net Anim

NetAnim


 SRQ vs GBN

Throughput Difference 

677483599754fbd212324ea2decaadb6.png

 

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

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.