How to Implement UAS based VANET in ns2
To implement an Unmanned Aerial Systems (UAS) based Vehicular Ad-Hoc Network (VANET) in NS2 has need to follow the series of steps that includes emulate a network in which UAS (drones) communicate with vehicles on the ground. UAS can be used to improve VANETs by deliver aerial views, relaying information, and enhancing communication coverage. The below is the detailed approach to implement a basic UAS-based VANET in NS2:
Step-by-Step Implementation:
- Set Up the NS2 Environment:
- Make sure NS2 is installed on system with support for wireless simulations.
- Get to know with writing TCL scripts, as NS2 simulations are controlled through TCL.
- Define the Network Topology:
- Generate a topology that has includes vehicles (ground nodes) and UAS (aerial nodes). The vehicles will interact with each other and with the UAS.
# Define the simulator
set ns [new Simulator]
# Create a trace file for analysis
set tracefile [open out.tr w]
$ns trace-all $tracefile
# Create a NAM file for animation
set namfile [open out.nam w]
$ns namtrace-all-wireless $namfile 10
# Set up the wireless network parameters
set opt(chan) Channel/WirelessChannel ;# Channel type
set opt(prop) Propagation/TwoRayGround ;# Radio-propagation model
set opt(netif) Phy/WirelessPhy ;# Network interface type
set opt(mac) Mac/802_11 ;# MAC type
set opt(ifq) Queue/DropTail/PriQueue ;# Interface queue type
set opt(ll) LL ;# Link layer type
set opt(ant) Antenna/OmniAntenna ;# Antenna model
set opt(ifqlen) 50 ;# Max packet in ifq
set opt(x) 1000 ;# X dimension of the topography
set opt(y) 1000 ;# Y dimension of the topography
set opt(adhocRouting) AODV ;# Routing protocol for VANET
# Create a topography object
create-god 30
# Configure the nodes
$ns node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
# Create nodes: UAS and vehicles
set uas1 [$ns node] ;# UAS 1 (aerial node)
set uas2 [$ns node] ;# UAS 2 (aerial node)
set vehicle1 [$ns node] ;# Vehicle 1 (ground node)
set vehicle2 [$ns node] ;# Vehicle 2 (ground node)
set vehicle3 [$ns node] ;# Vehicle 3 (ground node)
# Set initial positions for the UAS and vehicles
$uas1 set X_ 500.0
$uas1 set Y_ 800.0
$uas1 set Z_ 300.0 ;# Higher Z coordinate indicates altitude
$uas2 set X_ 600.0
$uas2 set Y_ 900.0
$uas2 set Z_ 300.0 ;# Higher Z coordinate indicates altitude
$vehicle1 set X_ 200.0
$vehicle1 set Y_ 200.0
$vehicle1 set Z_ 0.0 ;# Ground level
$vehicle2 set X_ 300.0
$vehicle2 set Y_ 300.0
$vehicle2 set Z_ 0.0 ;# Ground level
$vehicle3 set X_ 400.0
$vehicle3 set Y_ 400.0
$vehicle3 set Z_ 0.0 ;# Ground level
- Define Mobility Models:
- Configure mobility for both the UAS and the vehicles. UAS will have diverse mobility patterns compared to vehicles.
# Define mobility for UAS 1
$ns at 1.0 “$uas1 setdest 700.0 900.0 20.0”
$ns at 3.0 “$uas1 setdest 400.0 600.0 20.0”
# Define mobility for UAS 2
$ns at 1.0 “$uas2 setdest 500.0 800.0 25.0”
$ns at 3.0 “$uas2 setdest 600.0 900.0 25.0”
# Define mobility for Vehicle 1
$ns at 1.0 “$vehicle1 setdest 300.0 300.0 15.0”
$ns at 3.0 “$vehicle1 setdest 400.0 400.0 15.0”
# Define mobility for Vehicle 2
$ns at 1.0 “$vehicle2 setdest 400.0 400.0 15.0”
$ns at 3.0 “$vehicle2 setdest 500.0 500.0 15.0”
# Define mobility for Vehicle 3
$ns at 1.0 “$vehicle3 setdest 500.0 500.0 15.0”
$ns at 3.0 “$vehicle3 setdest 600.0 600.0 15.0”
- Simulate Communication Between Nodes:
- Configure communication among the UAS and vehicles using TCP or UDP agents. The UAS can communicate information among vehicles or deliver data to them.
# Vehicle 1 sends data to UAS 1
set udp_vehicle1 [new Agent/UDP]
$ns attach-agent $vehicle1 $udp_vehicle1
set udp_uas1 [new Agent/UDP]
$ns attach-agent $uas1 $udp_uas1
$ns connect $udp_vehicle1 $udp_uas1
# Vehicle 2 sends data to UAS 2
set udp_vehicle2 [new Agent/UDP]
$ns attach-agent $vehicle2 $udp_vehicle2
set udp_uas2 [new Agent/UDP]
$ns attach-agent $uas2 $udp_uas2
$ns connect $udp_vehicle2 $udp_uas2
# Vehicle 3 sends data to Vehicle 1 through UAS 1
set udp_vehicle3 [new Agent/UDP]
$ns attach-agent $vehicle3 $udp_vehicle3
set udp_vehicle1_sink [new Agent/UDP]
$ns attach-agent $vehicle1 $udp_vehicle1_sink
$ns connect $udp_vehicle3 $udp_vehicle1_sink
# Start sending traffic
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 512
$cbr1 set interval_ 0.05
$cbr1 attach-agent $udp_vehicle1
$ns at 2.0 “$cbr1 start”
set cbr2 [new Application/Traffic/CBR]
$cbr2 set packetSize_ 512
$cbr2 set interval_ 0.05
$cbr2 attach-agent $udp_vehicle2
$ns at 2.5 “$cbr2 start”
set cbr3 [new Application/Traffic/CBR]
$cbr3 set packetSize_ 512
$cbr3 set interval_ 0.05
$cbr3 attach-agent $udp_vehicle3
$ns at 3.0 “$cbr3 start”
- Run the Simulation:
- Describe as they the simulation should terminate and executed it. The finish procedure will close the trace files and take-off NAM for visualization.
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
# Schedule the finish procedure at 10 seconds
$ns at 10.0 “finish”
# Run the simulation
$ns run
- Analyse the Results:
- Use the trace file (out.tr) to evaluate the packet delivery, delays, throughput, and other performance metrics.
- Open the NAM file (out.nam) to visualize the network operations and track the communication among UAS and vehicles.
- Customize and Extend:
- We can customize the simulation by:
- Adding more UAS and vehicles, changing their mobility patterns.
- Executing the particular routing protocols that intended for VANETs with UAS involvement.
- Establish scenarios like traffic congestion, obstacles, or network failures to see how the UAS can help in enhancing communication.
- Replicate emergency response scenarios in which UAS help in delivering real-time data to vehicles.
Example Summary:
This sample configure a simple UAS-based VANET simulation in NS2. UAS (drones) interact with vehicles on the ground, and they support in relaying information among vehicles or deliver additional data coverage. The simulation has contain simple mobility and communication among the UAS and vehicles.
Advanced Considerations:
- For more complex scenarios, we need to discover adaptive routing protocols in which UAS dynamically adapts routes based on network conditions.
- Execute multi-UAS coordination to handle interaction over larger areas, that could contain task distribution, load balancing, and failure recovery.
Debugging and Optimization:
- Use the trace-all command to debug the simulation and evaluate packet flows.
- Enhance the simulation by decontaminating mobility models, that modify the communication protocols, and tuning network parameters.
This module demonstrates how to setup and manage the communication over a vehicle to ground network using the ns2 simulator. Further details will be provided about how the Unmanned Aerial Systems (UAS) based Vehicular Ad-Hoc Network (VANET) will be performing in other simulation tool. Rely on our developers to execute the UAS-based VANET within the ns2 application. Share the details of your research with us, and we will offer you exceptional performance analysis support.