How to Simulate VANET Projects Using NS2

To simulate Vehicular Ad-Hoc Networks (VANET) projects in NS2 has needs to set up a network of vehicular nodes that interact wirelessly by way of they move along predefined paths or mobility patterns. VANETs are usually utilized in intelligent transportation systems to replicate vehicle-to-vehicle (V2V) and vehicle-to-infrastructure (V2I) communication.

While NS2 does not have built-in support for vehicle mobility, VANET simulations usually includes the combination of mobility models with NS2. An often used tool for this purpose is Simulation of Urban Mobility (SUMO) that can produce realistic vehicular mobility traces that can be incorporated into NS2.

Here is a step-by-step guide on how to simulate VANET projects using NS2, with or without mobility models.

Steps to Simulate VANET Projects in NS2

  1. Components of a VANET Simulation

A typical VANET simulation in NS2 involves:

  • Vehicular Nodes (Cars): These nodes interact wirelessly in an ad-hoc fashion (V2V or V2I).
  • Base Stations or Roadside Units (RSU): Optional stationary nodes that deliver infrastructure support.
  • Routing Protocols: VANETs often utilize ad-hoc routing protocols such as AODV or DSR.
  • Mobility Model: Describes how vehicles move in the simulation. Tools such as SUMO can deliver realistic mobility traces for vehicles.
  1. Basic VANET Simulation Setup in NS2

To simulate a simple VANET in NS2, we will set up a wireless network with mobile nodes (representing vehicles) and utilize an ad-hoc routing protocol such as AODV. We will also describe the movement of vehicles using basic mobility models in NS2.

Example: Basic VANET Simulation

# Create NS2 simulator instance

set ns [new Simulator]

# Define a wireless channel

set chan [new Channel/WirelessChannel]

# Configure wireless nodes with mobility model (for vehicles)

$ns node-config -adhocRouting AODV -llType LL -macType Mac/802_11 -ifqType Queue/DropTail/PriQueue \

-ifqLen 50 -antType Antenna/OmniAntenna -propType Propagation/TwoRayGround -phyType Phy/WirelessPhy \

-channelType Channel/WirelessChannel

# Create vehicular nodes (representing cars)

set car1 [$ns node]

set car2 [$ns node]

set car3 [$ns node]

# Set initial positions for the vehicles

$car1 set X_ 50.0

$car1 set Y_ 100.0

$car2 set X_ 150.0

$car2 set Y_ 100.0

$car3 set X_ 250.0

$car3 set Y_ 100.0

# Define mobility for the vehicles (constant speed)

$ns at 1.0 “$car1 setdest 300.0 100.0 10.0”  ;# Move car1 to (300, 100) at 10 m/s

$ns at 1.0 “$car2 setdest 400.0 100.0 12.0”  ;# Move car2 to (400, 100) at 12 m/s

$ns at 1.0 “$car3 setdest 500.0 100.0 15.0”  ;# Move car3 to (500, 100) at 15 m/s

# Set up UDP communication between car1 and car3

set udp1 [new Agent/UDP]

set sink1 [new Agent/Null]

$ns attach-agent $car1 $udp1

$ns attach-agent $car3 $sink1

$ns connect $udp1 $sink1

# Set up Constant Bit Rate (CBR) traffic to simulate data communication between vehicles

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 512

$cbr1 set interval_ 0.01

# Start CBR traffic

$ns at 2.0 “$cbr1 start”

$ns at 6.0 “$cbr1 stop”

# Enable tracing for analysis

set tracefile [open vanet_trace.tr w]

$ns trace-all $tracefile

# Define a finish procedure

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Schedule simulation end

$ns at 10.0 “finish”

$ns run

Explanation:

  • Nodes (Cars): We generate three wireless nodes (car1, car2, and car3) that signify vehicles.
  • Mobility: Each vehicle is allocated a mobility pattern using the setdest command, which sets the destination and speed of each vehicle.
  • Routing Protocol: AODV (Ad-hoc On-Demand Distance Vector) routing protocol is used to handle communication between the vehicles.
  • UDP Traffic: We replicate V2V communication by configure UDP traffic between car1 and car3 using CBR (Constant Bit Rate) traffic.
  • Tracing: The simulation records events in the trace file vanet_trace.tr for later evaluation.
  1. Introducing SUMO for Realistic VANET Mobility

To establish more realistic vehicle movements, we utilize SUMO (Simulation of Urban MObility) to create vehicular mobility traces and incorporate them into NS2.

Steps to Integrate SUMO with NS2

  1. Install SUMO: Download and install SUMO from SUMO official website.
  2. Generate SUMO Mobility Trace:
    • Generate a road network and describe vehicle routes using SUMO.
    • Export the mobility trace file (in .tcl format) for utilize in NS2.

Example SUMO configuration file:

<routes>

<vType id=”veh” accel=”1.0″ decel=”1.0″ sigma=”0.5″ length=”5″ maxSpeed=”20″ />

<route id=”route0″ edges=”1 2 3″ />

<vehicle id=”veh0″ type=”veh” route=”route0″ depart=”0″ />

<vehicle id=”veh1″ type=”veh” route=”route0″ depart=”10″ />

</routes>

  1. Generate Mobility Trace: Utilize SUMO to create the mobility trace (output in TCL format) and then incorporate the trace into NS2.
  2. Integrate Mobility Trace into NS2: Load the generated mobility trace in the NS2 simulation script.

# Load the SUMO-generated mobility trace

source “sumo_mobility_trace.tcl”

In this case, SUMO manages the vehicle mobility, and NS2 handles the network simulation.

  1. Simulating V2V and V2I Communication

In a VANET, communication can be between vehicles (V2V) or between vehicles and infrastructure (V2I).

Example: Simulating V2I Communication

In this example, we will simulate vehicles communicating with a Roadside Unit (RSU), which perform as an infrastructure element.

# Create an RSU node (infrastructure node)

set rsu [$ns node]

$rsu set X_ 200.0

$rsu set Y_ 200.0

# Set up UDP communication between car1 and RSU

set udp_rsu [new Agent/UDP]

set sink_rsu [new Agent/Null]

$ns attach-agent $car1 $udp_rsu

$ns attach-agent $rsu $sink_rsu

$ns connect $udp_rsu $sink_rsu

# Set up CBR traffic to simulate V2I communication

set cbr_rsu [new Application/Traffic/CBR]

$cbr_rsu attach-agent $udp_rsu

$cbr_rsu set packetSize_ 512

$cbr_rsu set interval_ 0.01

# Schedule CBR traffic between car1 and RSU

$ns at 3.0 “$cbr_rsu start”

$ns at 6.0 “$cbr_rsu stop”

In this case, we simulate V2I communication, in which vehicle car1 transmit data to the RSU (stationary infrastructure node) over a wireless connection.

  1. Advanced VANET Simulations

We need to expand the simulation to contain more advanced VANET scenarios:

  • Handover: Replicate handover among different RSUs as vehicles move between different infrastructure zones.
  • Multi-hop Communication: Vehicles forward packets to other vehicles or infrastructure in a multi-hop fashion.
  • QoS and Traffic Prioritization: Execute Quality of Service (QoS) policies to select certain kinds of vehicular traffic (e.g., emergency messages).
  • Routing Protocol Comparison: Relate different ad-hoc routing protocols such as AODV, DSR, and OLSR in VANET environment.
  1. Analysing VANET Performance Metrics

After processing the simulation, we can measure parameters such as:

  • Throughput: The rate at which data is successfully routed among vehicles or from vehicles to infrastructure.
  • End-to-End Delay: The time taken for a message to travel from source to destination.
  • Packet Delivery Ratio (PDR): The percentage of packets that are successfully delivered to their destination.
  • Routing Overhead: The overhead created by the routing protocol (such as route discovery messages).

Example: Parsing Trace File for Performance Metrics

We can utilize AWK or Python scripts to measure the trace file created by NS2 to estimate throughput, delay, and packet delivery ratio.

awk ‘{ if ($1 == “r” && $4 == “AGT” && $7 == “udp”) count++; } END { print “Packets received: “, count; }’ vanet_trace.tr

This AWK script counts the number of successfully received packets in the VANET simulation.

  1. Visualizing the VANET Simulation

We can envision the VANET simulation using NAM (Network Animator) to track vehicle mobility and communication:

# Enable NAM trace file

set namfile [open vanet_simulation.nam w]

$ns namtrace-all $namfile

# Open NAM after the simulation ends

proc finish {} {

global ns namfile

$ns flush-trace

close $namfile

exec nam vanet_simulation.nam &

exit 0

}

Through the entire simulation process we get knowledge on how to simulate and evaluate the outcomes for Vehicular Ad-Hoc Networks using ns2 tool and it is used to manage the communication wirelessly. More information regarding this process will be provided later.

Please provide your information, and we will offer you customized simulation support.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2