How to Simulate VANET Protocols Projects Using NS2

To simulate Vehicular Ad-Hoc Network (VANET) protocols in NS2, we want to set up both the mobility of vehicles and the interaction among them. VANET protocols, like Ad-hoc On-demand Distance Vector (AODV), Dynamic Source Routing (DSR), and others, are usually utilized to replicate communication among the vehicles in highly dynamic scenarios. To achieve optimal results in simulation assistance, please maintain communication with us.

Below is a step-by-step guide to help you simulate VANET protocols using NS2.

Steps to Simulate VANET Protocols in NS2

  1. Install NS2

Make sure that NS2 is installed on the system. Download NS2 from the official NS2 website.

  1. Use Mobility Models for VANET

VANET simulations need vehicle mobility. The NS2 mobility model supports random and pre-configured movement patterns. But, for realistic vehicular movement, we need to utilize SUMO (Simulation of Urban MObility) or other traffic simulators to create mobility patterns and export them to NS2.

Option 1: Use Predefined Mobility in NS2

We need to utilize NS2’s built-in mobility models to replicate basic vehicle movement.

set val(x) 1000             ;# X-axis dimension of the topology

set val(y) 1000             ;# Y-axis dimension of the topology

# Configure mobility for each vehicle (node)

for {set i 0} {$i < 10} {incr i} {

set n($i) [$ns node]

$n($i) random-motion 1  ;# Enable random motion

}

# Set initial positions and destinations for vehicles

$n(0) set X_ 50

$n(0) set Y_ 50

$n(0) set Z_ 0.0

# Move node 0 to a new destination

$ns at 5.0 “$n(0) setdest 100 300 20.0”

$ns at 5.0 “$n(1) setdest 200 500 15.0”

Option 2: Use External Mobility Traces from SUMO

To generate realistic vehicle mobility, utilize SUMO, export the trace as a mobility file, and use it in NS2.

  1. Generate Mobility File: Utilize SUMO or any traffic simulator to create the mobility trace.
  2. Convert to NS2 Format: Convert the mobility trace to NS2 format.
  3. Integrate Mobility in NS2: In NS2 TCL script, load the mobility file.

# Load external mobility trace generated by SUMO

proc load_mobility_trace {file} {

set f [open $file r]

while {[gets $f line] >= 0} {

eval $line

}

close $f

}

# Load the SUMO mobility trace file

load_mobility_trace “sumo_mobility_file.tcl”

  1. Set up VANET Communication Using Routing Protocols

We need to utilize a variety of routing protocols for VANET communication like AODV, DSR, GPSR, or OLSR.

Example of Configuring AODV in NS2 for VANET:

# Create a new simulator instance

set ns [new Simulator]

# Define trace and nam files for logging and visualization

set tracefile [open vanet_aodv.tr w]

$ns trace-all $tracefile

set namfile [open vanet_aodv.nam w]

$ns namtrace-all $namfile

# Set up nodes and configure AODV protocol

for {set i 0} {$i < 10} {incr i} {

set n($i) [$ns node]

}

$ns node-config -adhocRouting AODV

# Define wireless channel parameters (specific to VANET)

set val(chan) Channel/WirelessChannel

set val(prop) Propagation/TwoRayGround

set val(netif) Phy/WirelessPhy

set val(mac) Mac/802_11

set val(ifq) Queue/DropTail/PriQueue

set val(ll) LL

set val(ant) Antenna/OmniAntenna

# Configure wireless links

for {set i 0} {$i < 9} {incr i} {

$ns duplex-link $n($i) $n([expr $i + 1]) 2Mb 10ms DropTail

}

# Define traffic: TCP communication between vehicles

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n(0) $tcp0

$ns attach-agent $n(9) $sink0

$ns connect $tcp0 $sink0

# Start traffic generation

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 2.0 “$ftp0 start”

# Stop simulation at 50 seconds

$ns at 50.0 “finish”

# Run the simulation

$ns run

  1. Set up Traffic Sources (TCP/UDP)

In VANET simulations, we usually replicate numerous kinds of data traffic, like emergency messages or infotainment services, using TCP or UDP traffic. Here’s an instance of how to generate CBR (Constant Bit Rate) traffic over UDP:

# Set up UDP communication

set udp0 [new Agent/UDP]

$ns attach-agent $n(0) $udp0

set null0 [new Agent/Null]

$ns attach-agent $n(9) $null0

# Connect the UDP agent to the null agent

$ns connect $udp0 $null0

# Generate CBR traffic over UDP

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.01

$cbr0 attach-agent $udp0

$ns at 1.0 “$cbr0 start”

  1. Visualize the Simulation

Once TCL script is configured, NS2 will generate two files:

  • Trace file (.tr): Logs all network events for evaluation.
  • NAM file (.nam): Utilized for envisioning the network behaviour.

To execute the simulation, save the TCL script as vanet_simulation.tcl and process it using NS2:

ns vanet_simulation.tcl

We can then open the .nam file in the Network Animator (NAM) to envision vehicle movement and communication.

  1. Analyse Simulation Results

We need to evaluate key VANET parameters like:

  • Packet Delivery Ratio (PDR)
  • End-to-End Delay
  • Routing Overhead
  • Throughput

Utilize AWK or Python scripts to run the trace file and estimate these parameters. Here’s an example AWK script for Packet Delivery Ratio:

BEGIN { sent = 0; received = 0; }

{

if ($1 == “s” && $4 == “AGT”) { sent++; }

if ($1 == “r” && $4 == “AGT”) { received++; }

}

END { print “Packet Delivery Ratio = “, received/sent*100, “%”; }

  1. Advanced VANET Protocols

We can execute advanced protocols explicitly intended for VANETs, such as:

  • GPSR (Greedy Perimeter Stateless Routing): A geographical routing protocol appropriate for VANETs.
  • GSR (Geographic Source Routing): Another location-based routing protocol often used in vehicular networks.

If these protocols are not available by default, we can execute or download patches from the research community.

Example VANET Projects

  1. Performance Comparison of AODV and GPSR in VANET:
    • Relate the performance of AODV and GPSR based on packet delivery ratio, end-to-end delay, and routing overhead in a high-mobility vehicular environment.
  2. Impact of Node Density on VANET Routing Protocols:
    • Measure on how the performance of VANET protocols such as AODV and DSR changes as vehicle density increases in a city environment.
  3. Emergency Message Broadcasting in VANETs:
    • Replicate emergency message dissemination in VANETs using broadcasting approaches and measure the latency and delivery ratio in dense traffic conditions.
  4. VANETs for Smart City Traffic Management:
    • Replicate VANET protocols for traffic management in smart cities, concentrates on minimize congestion and enhancing traffic flow.

From the demonstration, we completely delivered the fundamental approach that supported by example coding for Vehicular Ad-Hoc Network was simulated and evaluated using ns2 tool. We provide the brief procedure, sample snippets and example ideas to simulate this project. Further specific details will be added later.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2