To simulate Ad Hoc Networks using NS2 (Network Simulator 2) that includes making a network of mobile nodes, which communicate directly with each other without any centralized infrastructure (such as a router or access point). Ad Hoc Networks are typified by dynamic topologies, node mobility, and on-demand routing protocols such as AODV (Ad hoc On-Demand Distance Vector) and DSR (Dynamic Source Routing).
Below is a step-by-step guide to simulating Ad Hoc Networks using NS2.
Steps to Simulate Ad Hoc Networks Using NS2
- Install NS2:
Make certain NS2 is installed on the system. We can download it from the NS2 official website. The simulator NS2 already has built-in support for ad hoc network protocols such as AODV and DSR, thus no more packages are needed for simple simulations.
- Define the Ad Hoc Network Topology:
An ad hoc network contains mobile nodes, which move and communicate with each other dynamically. In NS2, each node is treated as a mobile wireless node. We require to set up the nodes and describe how they will communicate.
Example of defining a basic ad hoc network:
set ns [new Simulator]
# Create mobile nodes
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
# Define wireless network parameters
$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 communication links between the nodes (ad hoc network)
$ns duplex-link $node1 $node2 11Mb 10ms DropTail
$ns duplex-link $node2 $node3 11Mb 10ms DropTail
$ns duplex-link $node3 $node4 11Mb 10ms DropTail
Here, we set up the ad hoc network to utilize the AODV routing protocol with 802.11 MAC and a two-ray ground propagation model.
- Set Up Mobility Models:
Since ad hoc networks are dynamic, we want to describe the mobility of the nodes. The simulation platform NS2 supports distinct mobility models, and we can be used random waypoint mobility or other predefined models to mimic the movement of nodes.
Example of configuring random waypoint mobility for mobile nodes:
# Create mobility for the nodes (random waypoint)
setdest -n 4 -p 0.0 -s 10 -t 100 -x 500 -y 500 > mobility.tcl
source mobility.tcl
- -n 4: Number of nodes
- -p 0.0: Pause time between movements
- -s 10: Maximum speed (10 m/s)
- -t 100: Total simulation time (100 seconds)
- -x, -y: Simulation area (500m x 500m)
- Configure Communication Protocols:
In an ad hoc network, communication among the nodes can be replicated using UDP or TCP relying on the application. UDP is frequently utilized for real-time communication such as voice or video, even though TCP is utilized for reliable data transmission.
Example of setting up UDP communication between nodes:
# Attach UDP agents for communication between node1 and node4
set udp1 [new Agent/UDP]
set null1 [new Agent/Null]
$ns attach-agent $node1 $udp1
$ns attach-agent $node4 $null1
$ns connect $udp1 $null1
- Generate Traffic (CBR or FTP):
To mimic data transmission in the ad hoc network, we can be utilized CBR (Constant Bit Rate) for constant traffic or FTP for file transfers over TCP. Traffic generation supports replicate real-world data exchange among the nodes.
Example of generating CBR traffic between node1 and node4:
# Simulate CBR traffic from node1 to node4
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 512 ;# Packet size in bytes
$cbr1 set interval_ 0.1 ;# Send one packet every 0.1 second
$cbr1 attach-agent $udp1
We can similarly set up FTP traffic over TCP if reliable data transfer is required.
- Implement On-Demand Routing Protocol (AODV, DSR):
AODV and DSR are generally used on-demand routing protocols for ad hoc networks. The routing protocol will actively configure routes among the nodes as required.
To use AODV:
$ns node-config -adhocRouting AODV
To use DSR:
$ns node-config -adhocRouting DSR
These protocols will manage the routing automatically, according to the node’s communication needs.
- Simulate Energy Consumption (Optional):
In mobile ad hoc networks (MANETs), nodes are normally energy-constrained. We can be replicated energy consumption using NS2’s energy model in which nodes have a limited battery, and energy is utilized for sending and receiving data.
Example of configuring energy models for nodes:
# Configure energy model for node1
$node1 energy-model EnergyModel
$node1 set energy 100.0 ;# Initial energy in Joules
$node1 set txPower 0.6 ;# Transmission power in Watts
$node1 set rxPower 0.3 ;# Reception power in Watts
Likewise, set up energy models for other nodes, and observe how much energy each node consumes in the course of the simulation.
- Run the Simulation:
When we have set up the network topology, mobility, routing protocol, and traffic then we can run the simulation using NS2.
Example of running the simulation:
ns ad_hoc_simulation.tcl
We can also envision the simulation using NAM (Network Animator):
nam ad_hoc_simulation.nam
- Analyse Results:
After the simulation is finish then we can investigate the performance of the ad hoc network using the generated trace file (*.tr). Important metrics to estimate include:
- Throughput: Assess how much data is effectively delivered.
- Packet Delivery Ratio (PDR): The ratio of effectively delivered packets to the total packets transmitted.
- End-to-End Delay: Calculate the time taken for packets to travel from the source to the destination.
- Routing Overhead: Estimate how much overhead is triggered by the routing protocol.
- Energy Consumption: If energy models are utilized then we examine how much energy each node consumes.
We can be used AWK or Python scripts to process the trace file and compute performance parameters.
Example of analysing packet delivery ratio using AWK:
awk ‘{if ($1==”r” && $4==”AGT” && $7==”CBR”) print $0}’ ad_hoc_simulation.tr
- Advanced Features (Optional):
- Mobility Models: Test with distinct mobility models like random walk, random direction, or Gauss-Markov.
- QoS Protocols: Execute Quality of Service (QoS) mechanisms to prioritize traffic or make certain low latency for particular applications.
- Security: Replicate security protocols for secure routing in the ad hoc network.
- Multicast Routing: Execute multicast routing to replicate group communication in an ad hoc network.
We had illustrated the core concepts and simple steps for Ad Hoc Networks projects that were replicated and analysed using NS2 simulator. We are ready to offer in-depth insights and further details upon your requirements.
Just share the specifics of your Ad Hoc Networks Projects to phdprime.com, where we will provide you with customized support and detailed insights. Our expertise encompasses dynamic topologies, node mobility, and on-demand routing protocols, including AODV (Ad hoc On-Demand Distance Vector) and DSR (Dynamic Source Routing). By sharing all pertinent information, we can offer you effective guidance and concise explanations, ultimately aiding you in attaining the best possible simulation outcomes.