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)
→ IO grahp Using Wireshark
→ Net Anim
| NetAnim |
→ Go-Back-N under(3,4,5)
→ IO grahp Using Wireshark
→ Net Anim
| NetAnim |
SRQ vs GBN
Throughput Difference
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
Post a Comment