Skip to main content

Simulation of a large enterprise network with RIP and generate routing trace metrics | NS3 Project 7

Simulate a large enterprise network (40 nodes) with RIP and generate routing trace metrics

Prompt :

Prompt (Claude):

You are an expert in ns-3 simulation and network protocol analysis.

i need a complete, error-free, fully functional NS-3 C++ program for the following experiment:

Title:

RIP routing overhead analysis in a large enterprise network

Objective:

to simulate a large enterprise network (minimum 40 nodes) using the rip routing protocol and analyze routing overhead using trace metrics. strict requirements (non-negotiable):

Output requirements:

The program must generate:

  1. netanim animation file:

filename: rip_overhead.xml

must show all nodes clearly arranged (grid layout)

must show packet flow

  1. trace file:

ascii trace (.tr file)

enable using asciitracehelper

  1. data files for graphs (.dat):

overhead.dat for routing overhead vs time

txrate.dat for packet transmission rate vs time

 Network topology:

 minimum 40 nodes (preferably 50 for safety) use point to point links must allow multiple paths (enterprise-like)

 Routing protocol: use RIP (distance vector routing)

 The code should run using ./ns3 not ./waf

 THEORY

Routing protocols are essential in computer networks for determining the optimal path for data transmission between nodes. One of the fundamental routing protocols used in enterprise networks is the Routing Information Protocol (RIP), which is a distance vector routing protocol.

RIP operates by allowing routers (nodes) to exchange routing tables periodically. Each node shares its routing information with neighboring nodes, and based on this information, it updates its own routing table. The metric used in RIP is hop count, where the best path is the one with the minimum number of hops. The maximum allowable hop count in RIP is 15, making it suitable for small to medium-sized networks.

In this experiment, a large enterprise network with 50 nodes is simulated using NS-3. The network is designed with multiple paths to mimic real-world enterprise topology. RIP is used as the routing protocol, and its performance is evaluated using routing overhead metrics.

Routing overhead refers to the extra control traffic generated by routing protocols (such as periodic updates). High overhead can reduce network efficiency. Therefore, analyzing routing overhead is important for understanding protocol performance.

To evaluate the performance, the following metrics are collected:

  • Routing overhead vs time
  • Packet transmission rate vs time

The simulation also generates:

  • A NetAnim XML file for visualization
  • An ASCII trace file for packet-level analysis
  • Data files for plotting graphs

 PROCEDURE:

  1. Initialize the simulation by setting a seed value and creating 50 nodes to simulate a large enterprise network.
  2. Install the internet stack on all nodes and configure the RIP routing protocol using RipHelper.
  3. Arrange the nodes in a grid layout using MobilityHelper to ensure proper visualization in NetAnim.
  4. Create the network topology using PointToPointHelper:
    • Connect nodes linearly (node i to node i+1)
    • Add extra links every 5 nodes to create multiple paths
  5. Assign IP addresses to each link using Ipv4AddressHelper with different subnets.
  6. Configure traffic using OnOffApplication:
    • Generate UDP traffic between selected source and destination nodes
    • Set data rate to 500 Kbps
    • Define start and stop times for applications
  7. Install PacketSink applications at destination nodes to receive data.
  8. Enable ASCII tracing using AsciiTraceHelper to capture packet-level details.
  9. Connect a callback function (TxTrace) to count transmitted packets and calculate metrics.
  10. Log routing overhead and transmission rate at regular time intervals and store the values in:
    • overhead.dat
    • txrate.dat
  11. Generate a NetAnim XML file (rip_overhead.xml) using AnimationInterface for visualization.
  12. Run the simulation for 30 seconds and collect all outputs.
  13. Close all files and destroy the simulator after execution.

 

TOOLS USED:

Tool / Component

Purpose

Why Used

NS-3 Simulator

Network simulation

Provides accurate packet-level simulation of real networks

C++ Programming

Implementation language

NS-3 is primarily based on C++

RIP Helper (ns3::RipHelper)

Routing protocol setup

Enables RIP routing in simulation

PointToPointHelper

Link creation

Used to connect nodes with configurable bandwidth and delay

MobilityHelper

Node positioning

Helps arrange nodes in grid layout for visualization

NetAnim

Visualization tool

Generates animation file (rip_overhead.xml)

AsciiTraceHelper

Packet tracing

Generates .tr file for detailed packet analysis

OnOffApplication

Traffic generation

Simulates UDP traffic between nodes

PacketSink

Data receiver

Receives transmitted packets

ofstream (C++)

File handling

Used to store graph data (.dat files)

 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/rip-helper.h"
#include "ns3/mobility-module.h"
#include "ns3/netanim-module.h"
#include <fstream>
using namespace ns3;
// -------- METRICS --------
uint64_t txPackets = 0;
uint64_t prevTx = 0;
std::ofstream overheadFile, txrateFile;
// -------- TRACE CALLBACK --------
void TxTrace(Ptr<const Packet>)
{
    txPackets++;
}
// -------- LOG FUNCTION --------
void LogMetrics(double time)
{
    uint64_t delta = txPackets - prevTx;
    prevTx = txPackets;
    overheadFile << time << " " << delta << std::endl;
    txrateFile << time << " " << delta << std::endl;
}
int main()
{
    SeedManager::SetSeed(12345);
    // -------- NODES --------
    NodeContainer nodes;
    nodes.Create(50);
    // -------- RIP STACK --------
    RipHelper rip;
    rip.Set("UnsolicitedRoutingUpdate", TimeValue(Seconds(2)));
    InternetStackHelper stack;
    stack.SetRoutingHelper(rip);
    stack.Install(nodes);
    // -------- GRID POSITION --------
    MobilityHelper mobility;
    Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
    for (int i = 0; i < 50; i++)
        pos->Add(Vector((i % 10) * 20, (i / 10) * 20, 0));
    mobility.SetPositionAllocator(pos);
    mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
    mobility.Install(nodes);
    // -------- NETWORK --------
    PointToPointHelper p2p;
    p2p.SetDeviceAttribute("DataRate", StringValue("2Mbps"));
    p2p.SetChannelAttribute("Delay", StringValue("5ms"));
    std::vector<NetDeviceContainer> links;
    std::vector<Ipv4InterfaceContainer> interfaces;
    Ipv4AddressHelper addr;
    // -------- LINEAR LINKS --------
    for (int i = 0; i < 49; i++)
    {
        NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(i + 1));
        links.push_back(link);
        std::ostringstream subnet;
        subnet << "10." << i+1 << ".0.0";
        addr.SetBase(subnet.str().c_str(), "255.255.255.0");
        interfaces.push_back(addr.Assign(link));
    }
    // -------- EXTRA LINKS --------
    for (int i = 0; i < 45; i += 5)
    {
        NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(i + 5));
        links.push_back(link);
        std::ostringstream subnet;
        subnet << "192." << i+1 << ".0.0";
        addr.SetBase(subnet.str().c_str(), "255.255.255.0");
        addr.Assign(link);
    }
    // -------- ASCII TRACE (FIXED + LIMITED SIZE) --------
    AsciiTraceHelper ascii;
    Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream("rip_trace.tr");
    // ONLY trace first 10 links → small file
    for (int i = 0; i < 10; i++)
    {
        p2p.EnableAscii(stream, links[i]);
    }
    // -------- TRAFFIC --------
    uint16_t port = 9;
    for (int i = 0; i < 10; i++)
    {
        int src = i;
        int dst = 49 - i;
        Ipv4Address dstAddr = interfaces[48 - i].GetAddress(1);
        OnOffHelper onoff("ns3::UdpSocketFactory",
                          InetSocketAddress(dstAddr, port));
        // Reduced rate → prevents huge trace file
        onoff.SetConstantRate(DataRate("500Kbps"));
        auto app = onoff.Install(nodes.Get(src));
        app.Start(Seconds(1 + (i % 5)));
        app.Stop(Seconds(30));
        PacketSinkHelper sink("ns3::UdpSocketFactory",
                              InetSocketAddress(Ipv4Address::GetAny(), port));
        auto sinkApp = sink.Install(nodes.Get(dst));
        sinkApp.Start(Seconds(0));
        sinkApp.Stop(Seconds(30));
    }
    // -------- TRACE METRIC --------
    Config::ConnectWithoutContext(
        "/NodeList/*/ApplicationList/*/$ns3::OnOffApplication/Tx",
        MakeCallback(&TxTrace));
    // -------- OUTPUT FILES --------
    overheadFile.open("overhead.dat");
    txrateFile.open("txrate.dat");
    // -------- NETANIM --------
    AnimationInterface anim("rip_overhead.xml");
    // -------- LOGGING --------
    for (double t = 1; t <= 30; t++)
        Simulator::Schedule(Seconds(t), &LogMetrics, t);
    // -------- RUN --------
    Simulator::Stop(Seconds(30));
    Simulator::Run();
    overheadFile.close();
    txrateFile.close();
    Simulator::Destroy();
    return 0;
}

OUTPUT:

1.Code Execution:

 

2. NetAnim Simulation of The Enterprise:

NetAnim

 

 

The NetAnim visualization shows a grid-based network topology where nodes communicate via multiple paths. Initially, there is minimal activity, but as time progresses, packet flows (blue lines) increase, indicating active routing. The diagonal and multi-hop paths suggest RIP dynamically discovers routes across the network. It also shows how traffic propagates across nodes rather than staying localised.

3.Tracemetrics Output:

TraceMetrics
TraceMetrics

 

Throughput values are high across nodes, but goodput varies significantly, meaning not all transmitted data is useful payload. Some nodes show zero goodput, indicating they may only forward packets and not act as destinations. The variation highlights inefficiencies due to routing overhead and control messages. This reflects the typical behaviour of distance vector protocols like RIP.

 

 

 

The simulation processed around 28000 packets with almost equal sent and received packets, indicating highly efficient delivery. The dropped packets are zero, showing no packet loss in the network. The simulation ran for 30 seconds, meaning the routing protocol maintained stable communication throughout. This reflects a well-converged and reliable RIP network.

4. Graph Plots:

 

The graph shows a sudden rise in routing overhead followed by a plateau. The spike corresponds to the route discovery and convergence phase. Once stable, the flat line indicates steady-state routing with periodic updates. This demonstrates RIP’s convergence behaviour and control overhead characteristics.

 

 

 

The graph shows a sharp increase followed by stabilization around ~1200 packets/sec. This indicates that once routing converges, the network sustains a steady transmission rate. The flat region confirms no congestion or packet drops affecting throughput. Overall, it shows efficient and stable network performance under RIP.

CONCLUSION:

In this experiment, a large enterprise network consisting of 50 nodes was successfully simulated using the RIP routing protocol in NS-3. The network topology included multiple paths, making it closer to real-world enterprise environments.

The results demonstrated that RIP generates periodic routing updates, which contribute to routing overhead. By analysing the generated data files (overhead.dat and txrate.dat), it is possible to observe how routing overhead varies over time.

The use of ASCII tracing and NetAnim visualisation helped clarify the packet flow and network behaviour. Although RIP is simple and easy to implement, it incurs overhead from frequent updates and is not highly scalable for very large networks.

Overall, the experiment highlights:

  • The working of distance vector routing
  • The impact of routing overhead
  • The importance of efficient routing in large networks

 

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