How to Simulate MANET Projects Using NS2

To simulate Mobile Ad-hoc Network (MANET) projects within NS2 (Network Simulator 2) that includes setting up mobile nodes, wireless communication protocols, and mobility models to replicate dynamic, infrastructure-less networks. MANETs use routing protocols such as AODV, DSR, DSDV, and TORA to handle the dynamic topology triggered by node mobility.

Below is a step-by-step method to simulate MANET projects using NS2:

Steps for Simulating MANET Projects in NS2

  1. Install NS2: Make certain that NS2 is installed on the system. On Linux, we can install NS2 using the below command:

sudo apt-get install ns2

Verify that NS2 is installed by typing:

ns -version

  1. Understand NS2 MANET Components: In the simulation platformNS2, Mobile Nodes (i.e., wireless nodes) are utilized to replicate ad-hoc networks. The key modules in a MANET simulation contain:
    • MobileNode: Denotes wireless nodes capable of communicating without any fixed infrastructure.
    • WirelessChannel: Signifies the shared communication medium.
    • Routing Protocols: General MANET routing protocols such as AODV, DSR, DSDV, and TORA.
    • Mobility Models: Models such as Random Waypoint or Random Walk to replicate the movement of nodes in the network.
  2. Create a MANET Scenario Using a Tcl Script: The following is a Tcl script for a simple MANET simulation using AODV (Ad-hoc On-demand Distance Vector) as the routing protocol.

Example Tcl Script for a Simple MANET Simulation

# Create a new simulator object

set ns [new Simulator]

# Open trace and NAM files for output

set tracefile [open manet_out.tr w]

$ns trace-all $tracefile

set namfile [open manet_out.nam w]

$ns namtrace-all-wireless $namfile 500 500

# Define the wireless channel and propagation model for the MANET

set val(chan) Channel/WirelessChannel        ;# Channel type

set val(prop) Propagation/TwoRayGround       ;# Propagation model

set val(netif) Phy/WirelessPhy               ;# Network interface type

set val(mac) Mac/802_11                      ;# MAC type (Wi-Fi)

set val(ifq) Queue/DropTail/PriQueue         ;# Interface Queue

set val(ll) LL                               ;# Link Layer

set val(ant) Antenna/OmniAntenna             ;# Antenna model

set val(ifqlen) 50                           ;# Interface Queue length

set val(nn) 5                                ;# Number of mobile nodes

set val(rp) AODV                             ;# Routing protocol (AODV)

set val(x) 500                               ;# X dimension of the simulation area

set val(y) 500                               ;# Y dimension of the simulation area

# Define the topology object

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

# Configure the simulation parameters for mobile nodes

$ns node-config -adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON

# Create the mobile nodes (nodes will move according to mobility models)

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

$node_($i) random-motion 0   ;# Disable random motion initially

}

# Set initial positions for mobile nodes

$node_(0) set X_ 100.0

$node_(0) set Y_ 100.0

$node_(1) set X_ 200.0

$node_(1) set Y_ 200.0

$node_(2) set X_ 300.0

$node_(2) set Y_ 300.0

$node_(3) set X_ 400.0

$node_(3) set Y_ 400.0

$node_(4) set X_ 500.0

$node_(4) set Y_ 500.0

# Define UDP traffic over the MANET

set udp [new Agent/UDP]

$ns attach-agent $node_(0) $udp

set null [new Agent/Null]

$ns attach-agent $node_(4) $null

$ns connect $udp $null

# Create CBR traffic source (Constant Bit Rate) for the UDP connection

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.1    ;# 10 packets per second

$cbr attach-agent $udp

# Schedule traffic start and stop times

$ns at 1.0 “$cbr start”

$ns at 4.5 “$cbr stop”

# Mobility: Node 0 moves to a new position

$ns at 1.0 “$node_(0) setdest 400.0 400.0 10.0”

# Define the end of the simulation

$ns at 6.0 “finish”

# Define finish procedure to close files and launch NAM

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam manet_out.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Tcl Script:

  1. Simulator Object:
    • The line set ns [new Simulator] makes an NS2 simulation object.
  2. Wireless Channel Configuration:
    • The WirelessChannel denotes the shared medium for communication among the nodes.
    • AODV is selected as the ad-hoc routing protocol, however we can also use DSR, DSDV, or TORA.
  3. Node Creation and Mobility:
    • Five mobile nodes (node_(0) to node_(4)) are made and located in a 500×500 simulation area.
    • Mobility is launched using the setdest command that moves node_(0) to a new position (400, 400) at a speed of 10 units for each second.
  4. Traffic Model (UDP over CBR):
    • A UDP agent is connected to node_(0), and a Null agent is connected to node_(4) (receiver).
    • CBR (Constant Bit Rate) traffic is generated among the two nodes that replicating 512-byte packets being transmitted every 100ms.
  5. Simulation End:
    • The simulation stops at 6.0 seconds, and the finish procedure closes files and introduces NAM for visualization.
  1. Running the Simulation:

We can save the script as manet_simulation.tcl and then we run it using NS2:

ns manet_simulation.tcl

After the simulation, we can envision the node movements and traffic in NAM:

nam manet_out.nam

  1. Analyzing the Results:
  • The trace file (manet_out.tr) records all the packet transmissions, receptions, and routing decisions. We can investigate this trace file to collect significant performance parameters like:
    • Throughput
    • Packet Delivery Ratio
    • End-to-end Delay
    • Packet Loss
    • Routing Overhead

Extending the Simulation:

  1. Experiment with Different Routing Protocols:
    • We can substitute AODV with other MANET routing protocols such as DSDV, DSR, or TORA by modifying the rp parameter in the script:

set val(rp) DSR

  1. Use Different Mobility Models:
    • Change the mobility behaviour by utilizing models such as Random Waypoint, Random Walk, or Gauss-Markov to replicate node movement more realistically. It can be done using mobility trace files or by modifying the setdest commands.
  2. Simulate Larger Networks:
    • Maximizes the amount of mobile nodes and enlarge the simulation area (increase val(x) and val(y) dimensions) to mimic larger MANETs.
  3. Traffic Variations:
    • Launch other traffic patterns like FTP over TCP, HTTP, or multicast traffic to mimic distinct kinds of communication in the MANET.
  4. Performance Metrics:
    • Process the trace files using AWK scripts or other tools to compute performance parameters such as throughput, delay, packet delivery ratio, and routing overhead.

Example AWK script to calculate throughput:

BEGIN {

packet_count = 0;

start_time = 0;

end_time = 0;

}

{

if ($1 == “r” && $4 == “AGT”) {

packet_count++;

if (start_time == 0) {

start_time = $2;

}

end_time = $2;

}

}

END {

duration = end_time – start_time;

throughput = (packet_count * 512 * 8) / (duration * 1000);  # kbps

printf(“Throughput: %.2f kbps\n”, throughput);

}

Above simulation procedure were offered to replicate and analyse the MANET Projects with the support of sample snippets and NS2 simulation platform. Should further details be needed we are prepared to offer a more thorough exploration of this topic. Obtain optimal guidance on routing protocols including AODV, DSR, DSDV, and TORA for your projects through our services. We also provide support in project evaluation. At phdprime.com, we will assist you in achieving superior simulation results and offer the most suitable MANET project ideas tailored to your interests by collaborating with us.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2