To simulating an Epidemic Routing Protocol in NS2 has needs to design a mobile ad hoc network (MANET) or delay-tolerant network (DTN) in which the nodes spread messages correspondingly to how diseases spread in a population. This kind of routing protocol is helpful in scenarios in which the end-to-end connectivity is not guaranteed, and nodes depend on opportunistic contact with others to forward data.
Here’s a step-by-step guide to simulate an Epidemic Routing Protocol in NS2:
Steps to Simulate Epidemic Protocol Projects in NS2
- Understand Epidemic Routing Protocol
The Epidemic Routing Protocol operates by using the “gossip” approach, in which each node stores a message (packet) and forwards it to any other node it come across that does not have the message. This process endures until the message reaches its destination.
- Set up NS2
Make sure that NS2 is installed and correctly configured on the system. We will need to customize or incorporate Epidemic routing functionality, as it’s not built into NS2 by default. We have to incorporate a module or script that executes the protocol.
- Install Additional Modules
While NS2 does not directly support the Epidemic Routing Protocol, we requires to install additional modules such as NS-MIRACLE or other delay-tolerant networking extensions. In other hand, we adapt the existing NS2 scripts to replicate epidemic-like behavior by managing message dissemination among nodes.
- Model the Network Topology
In an Epidemic routing simulation, we usually simulate a mobile ad hoc network (MANET) in which nodes move allowing to a particular mobility model such as Random Waypoint.
Generate a TCL script for simulation. Below is an instance framework for epidemic routing using a simplified simulation:
- Writing the TCL Simulation Script
Here is an instance of a simple NS2 TCL script for replicating Epidemic Routing. This script outlines how nodes can act as in an opportunistic manner to forward messages.
Example TCL Script for Epidemic Routing Simulation
# Basic Epidemic Routing Simulation in NS2
# Create a simulator object
set ns [new Simulator]
# Open a trace file for recording the simulation
set tracefile [open “epidemic.tr” w]
$ns trace-all $tracefile
# Create NAM file for visualization
set namfile [open “epidemic.nam” w]
$ns namtrace-all $namfile
# Define the number of mobile nodes
set num_nodes 10
# Create nodes
for {set i 0} {$i < $num_nodes} {incr i} {
set node($i) [$ns node]
}
# Setup the wireless channel and MAC layer
set chan [new Channel/WirelessChannel]
$ns node-config -adhocRouting Epidemic -llType LL -macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue -ifqLen 50 \
-antType Antenna/OmniAntenna -propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy -channel $chan \
-topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON
# Setup a simple mobility model (Random Waypoint)
for {set i 0} {$i < $num_nodes} {incr i} {
$ns at 0.0 “$node($i) setdest 100 200 10”
$ns at 10.0 “$node($i) setdest 300 400 15”
}
# Create an Epidemic agent for routing at each node
for {set i 0} {$i < $num_nodes} {incr i} {
set epidemic_agent($i) [new Agent/Epidemic]
$ns attach-agent $node($i) $epidemic_agent($i)
}
# Create UDP application to simulate message transmission
for {set i 0} {$i < $num_nodes} {incr i} {
set udp_app($i) [new Application/Traffic/CBR]
$udp_app($i) attach-agent $epidemic_agent($i)
}
# Schedule traffic: node 0 sends a message to node 5
$ns at 1.0 “$udp_app(0) start”
$ns at 15.0 “$udp_app(5) stop”
# Set simulation end time and close the trace files
$ns at 50.0 “finish”
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exit 0
}
# Run the simulation
$ns run
- Explanation of the Code
- Node Creation: A specified number of nodes are generated to signify mobile devices.
- Wireless Channel Configuration: The wireless environment is configured using standard 802.11 MAC layer parameters and two-ray ground propagation model.
- Mobility Model: Nodes are set up to move using the setdest command, replicates random waypoint movement.
- Epidemic Agent: A custom epidemic agent (Agent/Epidemic) is attached to each node. This agent will manage packet forwarding according to the epidemic routing approaches.
- Traffic Generation: Traffic is created using a CBR (Constant Bit Rate) UDP application to replicate message dissemination.
- Simulation Timing: The traffic initiates at time 1.0 and terminate at 15.0, and the simulation itself stops at 50.0 seconds.
- Finish Procedure: make sure that trace and NAM files are closed after the simulation.
- Implementing the Epidemic Protocol
- We want to appliance the Epidemic protocol in the agent section if it is not delivered.
- This includes generating a C++ class for the epidemic agent. The agent required to store messages and forward them to other nodes when they come into contact (proximity).
- A possible logic could be:
- Maintain a message buffer at each node.
- When two nodes meet, relate their message buffers.
- Transfer messages that the other node does not have.
- Add C++ Code for Epidemic Routing Agent
The Epidemic agent can be executed in C++ within NS2’s source code. We want to adapt or generate files in the ~/ns-2.x/tcl/lib and ~/ns-2.x/queue/ directories.
- Run the Simulation
After writing and saving TCL script (such as epidemic.tcl), we can execute the simulation in NS2 using the following command:
ns epidemic.tcl
- Analyse the Results
- NAM Visualization: The .nam file generated can be utilized to envision the movement of nodes and the dissemination of messages via the network.
- Trace Files: measure the .tr file to assess the performance of the protocol, like the number of messages delivered, average delay, and overhead of the epidemic protocol.
- Performance Metrics
Common parameters to measure Epidemic Routing Protocol performance that contain:
- Delivery Ratio: Ratio of successfully delivered packets to the total packets sent.
- Average Delay: The average time taken for a packet to reach its destination.
- Overhead: The amount of redundant message copies interchanged among nodes.
- Further Extensions
- Optimization: we could enhance the protocol by controlling the buffer size or TTL (Time-to-Live) for messages.
- Energy Consumption: measure the energy efficiency of the protocol.
- Comparison with Other DTN Protocols: Relate Epidemic Routing with protocols such as Spray and Wait or Prophet in NS2.
In this page, we understand the concepts and deliver the clear simulation procedures that will help you to simulate the Epidemic Routing Protocol in ns2 tool. We plan to deliver the more information about how the Epidemic Routing Protocol executed in other simulation tools.
Check out phdprime.com and share your details with us. We promise to provide you with great simulation guidance!