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 |
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
Post a Comment