How to Implement MANET in ns2

To implement the Mobile Ad-Hoc Network (MANET) in ns2, we need to configure a dynamic wireless network that contains nodes which are mobile and interact with one another without depending on any fixed structure. These networks are usually use routing protocols like AODV, DSDV, DSR, and TORA to handle the routing of packets amongst nodes.

Below is a step-by-step guide on how to implement a basic MANET in ns2:

Step-by-Step Implementation:

Step 1: Create the Tcl Script

Start by generating a Tcl script that configures the MANET environment and the routing protocol, states the network topology and replicated node mobility.

Example Tcl Script for MANET with AODV Routing

# Create a simulator object

set ns [new Simulator]

# Define the topography object

set topo [new Topography]

$topo load_flatgrid 1000 1000

# Create the General Operations Director (GOD) for wireless simulations

create-god 10  # Number of nodes in the network

# Configure node settings for MANET with AODV routing protocol

$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 \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace ON

 

# Open trace and NAM files for recording the simulation

set tracefile [open manet_out.tr w]

$ns trace-all $tracefile

set namfile [open manet_out.nam w]

$ns namtrace-all-wireless $namfile 1000 1000

# Define a finish procedure to close files and end the simulation

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam manet_out.nam &

exit 0

}

# Create MANET nodes

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

set node_($i) [$ns node]

}

# Set initial positions and movements for the nodes

$node_(0) set X_ 100.0

$node_(0) set Y_ 200.0

$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0

$node_(1) set Y_ 300.0

$node_(1) set Z_ 0.0

$node_(2) set X_ 300.0

$node_(2) set Y_ 400.0

$node_(2) set Z_ 0.0

# … (set initial positions for other nodes similarly)

# Define node movements (mobility) to simulate a dynamic MANET

$ns at 5.0 “$node_(0) setdest 500.0 500.0 20.0”

$ns at 5.0 “$node_(1) setdest 600.0 600.0 20.0”

$ns at 5.0 “$node_(2) setdest 700.0 700.0 20.0”

# … (set movements for other nodes similarly)

# Define traffic in the MANET

# TCP Traffic from node 0 to node 9

set tcp0 [new Agent/TCP]

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

set sink0 [new Agent/TCPSink]

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

$ns connect $tcp0 $sink0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 start

# UDP Traffic from node 1 to node 8

set udp1 [new Agent/UDP]

$ns attach-agent $node_(1) $udp1

set null1 [new Agent/Null]

$ns attach-agent $node_(8) $null1

$ns connect $udp1 $null1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 512

$cbr1 set rate_ 1Mb

$cbr1 start 2.0

# Schedule the end of the simulation

$ns at 100.0 “finish”

# Run the simulation

$ns run

Step 2: Run the Tcl Script

Save the Tcl script with a .tcl extension (for instance: manet_simulation.tcl). Open a terminal and execute the script by entering the given command:

ns manet_simulation.tcl

This will create a trace file (manet_out.tr) and a NAM file (manet_out.nam).

Step 3: Visualize the MANET Simulation

To visualize the network topology, node mobility, and routing activity, open the NAM file with the following command:

nam manet_out.nam

This will exposed the NAM graphical interface, permitting you to monitor how nodes travel and how the AODV protocol manages routing when nodes move inside the network.

Script Explanation

  • Simulator Object: $ns [new Simulator] generate the simulator sample.
  • Topography: The topography object ($topo) states the simulation area, fix to 1000×1000.
  • Node Configuration: $ns node-config sets the wireless node parameters as well as the routing protocol (AODV), MAC type (802.11), and antenna type (OmniAntenna).
  • Node Placement: Nodes are positioned at certain (X, Y, Z) coordinates initially.
  • Node Mobility: The setdest command is used to replicate node movement, stating destination coordinates and speed.
  • Traffic Definition: TCP and UDP connections are described amongst nodes to recreate network traffic. FTP traffic is sent through TCP, and CBR (Constant Bit Rate) traffic is sent over UDP.
  • Finish Procedure: Once the simulation is done, it finished approach cleans up and closes files.

Customization

  • Change Routing Protocol: You can shift AODV with other MANET routing protocols like DSDV, DSR, or TORA by altering the -adhocRouting option.
  • Increase Node Count: Replicate a bigger MANET by attaching more nodes.
  • Adjust Mobility: Change the setdest parameter or attach new movement patterns to execute various different mobility models.
  • Vary Traffic Patterns: Experiment with numerous traffic types, packet sizes, and rates to recreate several network situations.
  • Simulate Real-World Scenarios: Tailor the node movements and traffic patterns to mirror real-world MANET applications like disaster retrieval or military communication.

Advanced Features

  • Routing Protocol Comparison: Replicate and compare the performance of various routing protocols in several network conditions.
  • Metrics Analysis: Evaluate routing metrics like packet delivery ratio, end-to-end delay, and routing overhead by parsing the trace file.
  • Scalability: Improve the count of nodes and monitor how the routing protocol works to examine the scalability of the MANET.

Through this comprehensive, we can guide and to help you get started by defining network topology and then simulating a basic MANET in ns2 and its advanced features. You can also customize the simulation. If you need any details for further references, we can provide you.

Our developers have organized the implementation of MANET in ns2 really well. We have top-notch tools and resources to ensure your project is completed with high quality.