How to Start Ad Hoc Protocols Projects Using NS2

To start Ad Hoc Protocol Projects using NS2, which needs to replicate the protocols that are created for dynamic, decentralized, and mobile networks like MANETs (Mobile Ad Hoc Networks). While NS2 environment supports numerous ad hoc routing protocols with AODV, DSDV, DSR, and TORA that we need to utilise or prolong for making custom projects.

Below is a comprehensive instruction to get started ad hoc protocol projects in NS2:

Steps to Start Ad Hoc Protocols Projects in NS2

  1. Understand Ad Hoc Protocols

Ad hoc protocols are characterized in 3 types:

  • Proactive Protocols (Table-Driven):
    • Example: DSDV (Destination-Sequenced Distance-Vector)
    • Nodes sustain the present routing tables that contains routes to every node.
  • Reactive Protocols (On-Demand):
    • Example: AODV (Ad Hoc On-Demand Distance Vector), DSR (Dynamic Source Routing) are reactive protocols.
    • These routes are exposed only as required and it helps to minimize the overhead.
  • Hybrid Protocols:
    • Example: ZRP (Zone Routing Protocol) is one of the hybrid protocols.
    • It integrates the proactive and reactive mechanisms for efficiency.
  1. Define Your Project Goals

We can describe the project objectives like:

  1. Performance Analysis:
    • Equate the performance parameters such as throughput, delay, PDR (Packet Delivery Ratio), and overhead for various protocols.
  2. Protocol Enhancements:
    • Enhance the protocols which is intended for energy efficiency, mobility, or scalability.
  3. Security Mechanisms:
    • Replicate the security attacks such as blackhole, wormhole and intend its solutions.
  4. Application Scenarios:
    • Experiment the protocols within IoT, VANET (Vehicular Ad Hoc Networks), or disaster retrieval application scenarios.
  1. Set Up NS2
  1. Install NS2:
    • We should install the NS2 on the system to utilise NS2.35, since it has support for ad hoc protocols by default.
    • Execute on a Linux-based system for compatibility.
  2. Verify Installation:
    • Verify installation with a simple simulation, making sure that NS2 is installed properly.
  1. Create a Simulation Script

Replicate the ad hoc protocol project applying TCL script.

Example: A Basic AODV Simulation

  1. Set Up the Network Topology:

set ns [new Simulator]

# Trace and animation files

set tracefile [open adhoc.tr w]

$ns trace-all $tracefile

set namfile [open adhoc.nam w]

$ns namtrace-all $namfile

# Create nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

# Create links

$ns duplex-link $n0 $n1 2Mb 10ms DropTail

$ns duplex-link $n1 $n2 2Mb 10ms DropTail

$ns duplex-link $n2 $n3 2Mb 10ms DropTail

  1. Specify the Ad Hoc Protocol:
    • Define the Ad Hoc protocols such as AODV, DSDV, or any other protocol which is a routing protocol.

set val(rp) AODV ;# Ad hoc routing protocol

  1. Add Traffic Sources:
    • Set traffic sources like TCP or UDPfor data transfer:

set udp [new Agent/UDP]

$ns attach-agent $n0 $udp

set null [new Agent/Null]

$ns attach-agent $n3 $null

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.1

$cbr attach-agent $udp

  1. Define Mobility:
    • Replicate the dynamic topology, integrating the mobility models:

$ns at 5.0 “$n0 setdest 100 200 10.0”

$ns at 10.0 “$n1 setdest 200 100 15.0”

  1. Run the Simulation:

$ns at 50.0 “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam adhoc.nam &

exit 0

}

$ns run

  1. Analyze Simulation Results

We can examine the trace file as adhoc.tr, measuring the performance parameters.

Metrics to Evaluate:

  1. Packet Delivery Ratio (PDR):
    • Compute the percentage of packets that are effectively distributed to total transmitted packets:

awk ‘{if ($1 == “r” && $4 == “AGT”) recd++; if ($1 == “s” && $4 == “AGT”) sent++} END {print “PDR:”, recd/sent*100 “%”}’ adhoc.tr

  1. End-to-End Delay:
    • Estimate the average time attaining its destination nodes for packets.
  2. Routing Overhead:
    • Measure the total volume of control packets which are transmitted during the simulation:

awk ‘{if ($7 == “AODV” || $7 == “DSDV”) count++} END {print “Routing Overhead:”, count}’ adhoc.tr

  1. Throughput:
    • Calculate the volume of data that are distributed for each unit of time.
  1. Visualize the Simulation
  1. Use NAM (Network Animator):
    • Envision the node mobility and packet flow to apply nam.

nam adhoc.nam

  1. Plot Metrics:
    • Envision the performance parameters such as PDR, delay, and overhead vs. mobility or node density to utilise the tools like Python, MATLAB, or Excel.
  1. Extend or Modify Protocols

Example: Adding Energy Awareness to AODV

  1. Fine-tune AODV source code (aodv.cc) with energy parameters:

double remaining_energy = node->energy();

if (remaining_energy > threshold) {

// Prefer routes with higher energy

}

  1. Recompile NS2:

make clean

make

File Locations:

  • Protocol Files:
    • AODV: ns-2.35/adhoc/aodv/
    • DSR: ns-2.35/adhoc/dsr/
    • DSDV: ns-2.35/adhoc/dsdv/
  • Packet Structures:
    • Packet structures is described within packet.h.
  1. Advanced Features
  1. Security Enhancements:
    • Replicate the security attacks such as blackhole, wormhole and then we can execute the defenses.
  2. Energy-Efficient Routing:
    • Launch the power-aware parameters for route selection.
  3. Hybrid Protocols:
    • Integrate the hybrid proactive and reactive protocols for advanced scalability.
  4. IoT and VANET Scenarios:
    • Experiment the VANET and IoT scenarios-based protocols that are utilised in application-specific networks.
  5. QoS Metrics:
    • Fine-tune protocols for Quality of Service parameters such as bandwidth, latency.
  1. Compare Ad Hoc Protocols

Replicate several Ad Hoc protocols like AODV, DSR, DSDV in the similar network conditions and equate these protocols:

  • Energy consumption
  • Throughput
  • Packet delivery ratio
  • Scalability
  1. Document Your Project

It offers in-depth report or documentation that contains:

  1. Define clear objectives and scope.
  2. Create network topology and simulation configuration.
  3. Measure the outcomes and analysis.
  4. Finally, it provides conclusions and potential enhancements.

Example Project Ideas

  1. Performance Analysis of AODV and DSR:
    • Equate the performance analysis of AODV and DSR in diverse mobility and traffic models.
  2. Energy-Aware AODV:
    • Improve the AODV for minimizing power utilization within MANETs.
  3. Ad Hoc Protocols in IoT:
    • Replicate the ad hoc protocols including constrained devices for IoT applications.
  4. Security in Ad Hoc Networks:
    • Execute the defenses versus blackhole or wormhole attacks within Ad Hoc networks for security.
  5. Hybrid Protocol Simulation:
    • Integrate the hybrid proactive and reactive mechanisms for enhancing the simulation performance.

You can get more information about the simulation of Ad Hoc Protocols projects that were simulated and executed using this simple procedure in NS2. Additional information to be included in another manual.