How to Implement NAMO in NS2

To implement the NAMO (Node Movement Object) is a mobility model that utilised in the simulation NS2 (Network Simulator 2) to simulate node movement within mobile wireless networks. This permits to make and replicate the various movement patters for the nodes like linear, random, or group mobility. In the simulation NS2, nodes mobility is necessary for simulating the situation such as Mobile Ad Hoc Networks (MANETs) and other dynamic wireless systems. We presented stepwise procedure on how to execute the NAMO in NS2 for simulating node mobility.

Steps to Implement NAMO in NS2

  1. Ensure NS2 is Installed and Set Up

If NS2 is not already installed, we can download and install it using the below commands:

wget https://sourceforge.net/projects/nsnam/files/latest/download -O ns-allinone-2.35.tar.gz

tar -xzvf ns-allinone-2.35.tar.gz

cd ns-allinone-2.35

./install

  1. Understanding Node Movement Object (NAMO)

In the simulation NS2, NAMO is utilized to describe the movement of nodes in a simulation and also we can use NAMO to specify node mobility models like:

  • Random Movement: These nodes are move in a random direction.
  • Linear Movement: Nodes are follow a linear path.
  • Group Movement: This nodes are move together in groups.

These mobility patterns are support to emulate the real-world scenarios like mobile users moving in urban areas or vehicular networks.

  1. Design the Topology and Create Mobile Nodes

In NS2, we will require to make the nodes which will move based on the NAMO mobility model. The below steps are show how to make mobile nodes and describe their movement.

3.1 Create Mobile Nodes

In the OTcl script, we define the mobile nodes which will use the NAMO mobility model.

# Create a simulator object

set ns [new Simulator]

# Open a NAM trace file for visualization

set nf [open out.nam w]

$ns namtrace-all $nf

# =======================

# Create Mobile Nodes

# =======================

# Create 5 mobile nodes

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

set node($i) [$ns node]

$node($i) random-motion 1  ;# Enable random motion

}

# Define the wireless channel type

set chan_1_ [new Channel/WirelessChannel]

# Configure the node properties (like position and energy model)

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

$node($i) set X_ [expr rand()*500]  ;# Set random X position within 500×500 grid

$node($i) set Y_ [expr rand()*500]  ;# Set random Y position

$node($i) set Z_ 0  ;# Z-axis (height) is fixed at 0

}

Here, five mobile nodes are created with random motion enabled. The random-motion command makes the nodes move randomly across the defined area (500×500 grid).

  1. Define Mobility Model Using NAMO

We can utilise the NAMO to specify the movement of nodes by describing the particular movement models such as random, linear, or group.

4.1 Random Waypoint Mobility Model

The random waypoint model is generally used to replicate the node mobility within wireless networks. These nodes are move randomly among the waypoints in this model.

# Define a random waypoint mobility model for node 0

$ns at 1.0 “$node(0) setdest 300 400 10”  ;# Node 0 moves to destination (300, 400) at 10 m/s

$ns at 5.0 “$node(0) setdest 100 200 5”   ;# Node 0 moves to destination (100, 200) at 5 m/s

In this sample, node 0 moves to the position (300, 400) at a speed of 10 m/s at time 1.0, and the later moves to (100, 200) at a speed of 5 m/s at time 5.0.

4.2 Group Mobility Model

The group mobility model can be mimicked scenarios in which groups of nodes are move together, like vehicles in a convoy or soldiers in formation.

# Group Mobility: Move nodes in a group (node 0, node 1, node 2)

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

$ns at 1.0 “$node($i) setdest 400 400 5”  ;# All nodes move to the same destination (400, 400)

}

In this instance, nodes 0, 1, and 2 are move together as a group to the position (400, 400) at a speed of 5 m/s.

4.3 Linear Movement Model

The linear movement model is helpful while the nodes are follow a straight way, like vehicles on a highway.

# Linear movement: Node 3 moves in a straight line

$ns at 2.0 “$node(3) setdest 500 500 15”  ;# Node 3 moves in a straight line to (500, 500) at 15 m/s

Node 3 moves to the position (500, 500) at a speed of 15 m/s, following a linear path.

  1. Simulate Communication between Mobile Nodes

When the mobility models are stated, we can replicate the communication among the mobile nodes using agents such as TCP or UDP.

5.1 Set up Communication between Nodes

We can describe agents for communication among the nodes and mimic packet transmission as the nodes move.

# Set up communication between node 0 and node 4 using UDP

set udp0 [new Agent/UDP]

$ns attach-agent $node(0) $udp0

set sink [new Agent/Null]

$ns attach-agent $node(4) $sink

$ns connect $udp0 $sink

# Generate traffic

set traffic [new Application/Traffic/CBR]

$traffic attach-agent $udp0

$traffic set packetSize_ 500  ;# Packet size of 500 bytes

$traffic set rate_ 1Mb        ;# Data rate of 1 Mbps

# Start traffic at time 2.0

$ns at 2.0 “$traffic start”

In this example:

  • Node 0 sends UDP packets to Node 4.
  • The traffic is produced at a rate of 1 Mbps with a packet size of 500 bytes.
  • Traffic starts at time 2.0 seconds.
  1. Enable Trace Files and Visualization Using NAM

We can make trace files to capture the simulation’s performance and we envision the node movement using NAM (Network Animator).

6.1 Enable Trace Files:

# Enable trace file generation

set tracefile [open “out.tr” w]

$ns trace-all $tracefile

6.2 Run the Simulation and View in NAM:

When the mobility and communication scenarios are described, then run the simulation and visualize it in NAM.

ns your_script.tcl

nam out.nam

We can visualize the movement of the nodes and how they communicate as they move based on the mobility models are defined in the NAM.

  1. End the Simulation

We should end the simulation when a specific time, after setting up mobility and communication.

# End the simulation at time 10.0

$ns at 10.0 “finish”

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exit 0

}

$ns run

  1. Analyse the Results

When the simulation is comprehensive, we can evaluate the trace files to collect information regarding:

  • Packet delivery: How packets were delivered among the mobile nodes.
  • End-to-end delay: Compute how long it takes for packets to reach their end.
  • Node mobility patterns: Monitor how the nodes are moved and communicated while the simulation.

We can use tools such as AWK or Python scripts to parse the trace files and collect related metrics.

Throughput this procedure, you can get to know more about how the NAMO will be executed and functions including some examples. We offered the entire instructions of the implementation of the NAMO in the NS2 simulation tool. You can customize the simulation as per your requirements.

We’re here to help you implement NAMO in NS2 with timely support, so keep in touch for fresh assistance. Check out ns2project.com for the best guidance!