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:
- netanim animation file:
filename:
rip_overhead.xml
must show
all nodes clearly arranged (grid layout)
must show
packet flow
- trace file:
ascii trace
(.tr file)
enable
using asciitracehelper
- data files for graphs
(.dat):
overhead.dat
for routing overhead vs time
txrate.dat for
packet transmission rate vs time
Routing protocol: use RIP
(distance vector routing)
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:
- Initialize
the simulation by setting a seed value and creating 50 nodes to simulate a
large enterprise network.
- Install
the internet stack on all nodes and configure the RIP routing protocol
using RipHelper.
- Arrange
the nodes in a grid layout using MobilityHelper to ensure proper
visualization in NetAnim.
- 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
- Assign
IP addresses to each link using Ipv4AddressHelper with different subnets.
- 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
- Install
PacketSink applications at destination nodes to receive data.
- Enable
ASCII tracing using AsciiTraceHelper to capture packet-level details.
- Connect
a callback function (TxTrace) to count transmitted packets and calculate
metrics.
- Log
routing overhead and transmission rate at regular time intervals and store
the values in:
- overhead.dat
- txrate.dat
- Generate
a NetAnim XML file (rip_overhead.xml) using AnimationInterface for
visualization.
- Run
the simulation for 30 seconds and collect all outputs.
- 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/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 |
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
Post a Comment