Skip to main content

Simulation of a Hybrid Point-to-Point and CSMA Network using NS3 | NS3 Project 3


1. Objective

To design and simulate a Wide Area Network (WAN) consisting of 5 routers interconnected via Point-to-Point links, configured with the Routing Information Protocol (RIP) for dynamic routing, and to observe routing table convergence, packet transmission, and link failure recovery using NS-3 and NetAnim.

2. LLM Tool Used

LLM Used: ChatGPT (OpenAI, GPT-4o)

The following prompts were used to generate and refine the simulation code:

1.    "How to simulate WAN with 5 routers using RIP in ns-3?"

2.    "How to introduce link failure in ns-3 simulation?"

3.    "Step by step guide to execute the code and visualise using NetAnim"

4.    "Fix errors related to NetDevice SetLinkDown in ns-3"

 

3. Simulation Design

3.1 Network Topology

The simulation implements a linear WAN topology with 5 routers (Node 0 through Node 4) connected via 4 Point-to-Point links in a chain. Each link is configured with a data rate of 5 Mbps and a propagation delay of 2 ms. RIP (Routing Information Protocol) is deployed across all routers for dynamic route discovery and convergence.

Router 0 — Router 1 — Router 2 — Router 3 — Router 4

3.2 IP Addressing Scheme

Link

Subnet

Router A IP

Router B IP

R0 — R1

10.0.1.0/24

10.0.1.1

10.0.1.2

R1 — R2

10.0.2.0/24

10.0.2.1

10.0.2.2

R2 — R3

10.0.3.0/24

10.0.3.1

10.0.3.2

R3 — R4

10.0.4.0/24

10.0.4.1

10.0.4.2

 

3.3 Traffic Configuration

       Protocol: UDP Echo (Client-Server)

       Server: Router 4 (Node 4), Port 9

       Client: Router 0 (Node 0)

       Packet Size: 1024 bytes

       Interval: 1 second, Max Packets: 100

       Simulation Duration: 0 - 25 seconds

 

3.4 Link Failure Simulation

A deliberate link failure is introduced at t = 10 seconds by bringing down the R1-R2 interface on both Router 1 (interface 2) and Router 2 (interface 1). This forces RIP to re-converge and update routing tables across all nodes, demonstrating the protocol's fault-tolerance mechanism.

4. Source Code

The complete NS-3 C++ simulation code is provided below:

#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/rip-helper.h"
#include "ns3/netanim-module.h"   // NetAnim
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("RipWanExample");
int main (int argc, char *argv[])
{
  LogComponentEnable ("RipWanExample", LOG_LEVEL_INFO);
  // Create 5 routers
  NodeContainer routers;
  routers.Create (5);
  // Point-to-point links
  PointToPointHelper p2p;
  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
  NetDeviceContainer d1 = p2p.Install (routers.Get (0), routers.Get (1));
  NetDeviceContainer d2 = p2p.Install (routers.Get (1), routers.Get (2));
  NetDeviceContainer d3 = p2p.Install (routers.Get (2), routers.Get (3));
  NetDeviceContainer d4 = p2p.Install (routers.Get (3), routers.Get (4));
  // Install RIP
  RipHelper rip;
  Ipv4ListRoutingHelper list;
  list.Add (rip, 0);
  InternetStackHelper stack;
  stack.SetRoutingHelper (list);
  stack.Install (routers);
  // Assign IPs
  Ipv4AddressHelper address;
  address.SetBase ("10.0.1.0", "255.255.255.0");
  Ipv4InterfaceContainer i1 = address.Assign (d1);
  address.SetBase ("10.0.2.0", "255.255.255.0");
  Ipv4InterfaceContainer i2 = address.Assign (d2);
  address.SetBase ("10.0.3.0", "255.255.255.0");
  Ipv4InterfaceContainer i3 = address.Assign (d3);
  address.SetBase ("10.0.4.0", "255.255.255.0");
  Ipv4InterfaceContainer i4 = address.Assign (d4);
  // UDP Traffic (R0 -> R4)
  UdpEchoServerHelper server (9);
  ApplicationContainer serverApp = server.Install (routers.Get (4));
  serverApp.Start (Seconds (1.0));
  serverApp.Stop (Seconds (25.0));
  UdpEchoClientHelper client (i4.GetAddress (1), 9);
  client.SetAttribute ("MaxPackets", UintegerValue (100));
  client.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  client.SetAttribute ("PacketSize", UintegerValue (1024));
  ApplicationContainer clientApp = client.Install (routers.Get (0));
  clientApp.Start (Seconds (2.0));
  clientApp.Stop (Seconds (25.0));
  // Print routing tables at t=5s, 12s, 20s
  Ptr<OutputStreamWrapper> stream = Create<OutputStreamWrapper> (&std::cout);
  rip.PrintRoutingTableAllAt (Seconds (5), stream);
  rip.PrintRoutingTableAllAt (Seconds (12), stream);
  rip.PrintRoutingTableAllAt (Seconds (20), stream);
  // Link Failure (R1-R2) at t=10s
  Ptr<Ipv4> ipv4_r2 = routers.Get(1)->GetObject<Ipv4>();
  Ptr<Ipv4> ipv4_r3 = routers.Get(2)->GetObject<Ipv4>();
  uint32_t interface_r2 = 2;
  uint32_t interface_r3 = 1;
  Simulator::Schedule (Seconds (10.0), &Ipv4::SetDown, ipv4_r2, interface_r2);
  Simulator::Schedule (Seconds (10.0), &Ipv4::SetDown, ipv4_r3, interface_r3);
  // NetAnim configuration
  AnimationInterface anim("rip-wan.xml");
  anim.SetConstantPosition(routers.Get(0),   0, 0);
  anim.SetConstantPosition(routers.Get(1),  50, 0);
  anim.SetConstantPosition(routers.Get(2), 100, 0);
  anim.SetConstantPosition(routers.Get(3), 150, 0);
  anim.SetConstantPosition(routers.Get(4), 200, 0);
  NS_LOG_INFO ("Starting Simulation...");
  Simulator::Stop (Seconds (25.0));
  Simulator::Run ();
  Simulator::Destroy ();
  NS_LOG_INFO ("Simulation Finished.");
  return 0;
}


 

5. Steps to Execute

5.    Place the file rip-wan.cc in the ns-3-dev/scratch/ directory.

6.    Open a terminal and navigate to the ns-3 root directory: cd ns-3-dev

7.    Build the project: ./ns3 build

8.    Run the simulation: ./ns3 run scratch/rip-wan

9.    Open NetAnim and load the generated rip-wan.xml file to visualize the simulation.

 

6. Terminal Output (Build & Run)

The following screenshots show the NS-3 build process and the simulation execution output:

 

Figure 1: NS-3 Build Process (0% to 7%)

Figure 2: Build Completion (98%-100%) and Simulation Start

7. Routing Table Output

Routing tables were printed at three simulation timestamps: t = 5s (initial convergence), t = 12s (after link failure at t = 10s), and t = 20s (post-failure steady state). These illustrate RIP route convergence and failure recovery.

 

Figure 4: Routing Tables at t=5s and t=12s (Pre and Post Link Failure)

Figure 5: Routing Tables at t=20s (Post-Failure Convergence)

8. Routing Table Analysis

At t = 5s (Pre-Failure — Initial Convergence)

All nodes have discovered the full network topology via RIP advertisements. Node 0 routes to 10.0.2.0, 10.0.3.0, and 10.0.4.0 via gateway 10.0.1.2. Node 4 routes to 10.0.1.0 through multiple hops (metric = 4), confirming full convergence across 5 routers.

At t = 12s (Post Link Failure — R1-R2 Link Down)

After the R1-R2 link is brought down at t = 10s, RIP begins re-convergence. Node 1's routing table is reduced — routes to 10.0.3.0 and 10.0.4.0 are temporarily withdrawn. Nodes 3 and 4 retain partial tables as RIP propagates updated topology information. This shows the expected RIP convergence delay (up to 30 seconds in the worst case).

At t = 20s (Stable Post-Failure State)

With the R1-R2 link permanently down, remaining nodes stabilize with restricted routes. Node 0 can only see 10.0.1.0 (its own subnet). Nodes 3 and 4 can reach each other's subnets. The network is now partitioned, and RIP correctly reflects the unreachable destinations by removing stale routes.

 

9. NetAnim Visualization

The following screenshots from NetAnim show the animated packet flow and node activity during the simulation:

NetAnim
NetAnim


10. Conclusion

This simulation successfully demonstrated the deployment of RIP over a multi-hop WAN topology in NS-3. Key observations include:

       RIP converges across all 5 nodes within approximately 5 seconds of simulation start.

       Routing tables accurately reflect hop counts (metrics) and gateway selection consistent with the Bellman-Ford algorithm used by RIP.

       A simulated link failure at t = 10s between Router 1 and Router 2 triggered RIP re-convergence, with routing tables updating by t = 20s.

       NetAnim visualisation confirmed animated packet exchanges across the linear topology.

       The use of IPv4::SetDown () was an effective method to simulate realistic link failure scenarios in NS-3.

 

The LLM-assisted prompt engineering significantly accelerated code development and debugging, particularly for resolving NS-3 API-related issues such as the SetLinkDown method and NetAnim integration.

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