How to Implement Network Mobility Handoff in NS2

To implement the Network mobility handoff has needs to encompass, managing the handoff of ongoing connections and simulating the movement of mobile nodes among various network segments such as between different Access Points or Base Stations and within NS2. It is frequently used to replicate the situation in which the mobile nodes modify their point of attachment as they move, like in cellular networks or wireless LANs. Given below is basic process we follow it to execute the network mobility handoff in NS2:

Key Concepts:

  1. Mobile Nodes (MN): These nodes that move among various points of attachment.
  2. Access Points (APs) or Base Stations (BSs): Fixed nodes are distributing network access to the mobile nodes.
  3. Handoff: The procedure of transferring an dynamic connection from one AP or BS to another as the mobile node transfers.

Steps to Implement Network Mobility Handoff in NS2

  1. Install NS2

Make sure that NS2 is installed on the system and we can download NS2 from the NS2 website.

  1. Create a Basic TCL Script for Mobility and Handoff

To replicate the handoff, we will be stated numerous access points or base stations, a mobile node, and a mobility model that transfers the mobile node among various APs. This handoff happens while the mobile node transfers from the coverage area of one AP to another.

Example: Simulating Network Mobility and Handoff between Access Points

# Define a simulator object

set ns [new Simulator]

# Define trace and nam files for output

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define a ‘finish’ procedure to end the simulation and visualize in NAM

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

}

# Create two Access Points (AP1 and AP2)

set AP1 [$ns node]

set AP2 [$ns node]

# Create a mobile node (MN) that moves between AP1 and AP2

set MN [$ns node]

# Set the topography object to define the simulation area

set topo [new Topography]

$topo load_flatgrid 1000 1000

# Create a duplex link between each AP and the mobile node

$ns duplex-link $AP1 $MN 11Mb 10ms DropTail

$ns duplex-link $AP2 $MN 11Mb 10ms DropTail

# Define TCP traffic from AP1 to MN

set tcp [new Agent/TCP]

set sink [new Agent/TCPSink]

$ns attach-agent $AP1 $tcp

$ns attach-agent $MN $sink

$ns connect $tcp $sink

# Create FTP traffic over TCP

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp start 1.0   ;# Start FTP traffic at 1 second

$ftp stop 4.5    ;# Stop FTP traffic at 4.5 seconds

# Set up mobility for the mobile node

$MN set X_ 100  ;# Initially near AP1

$MN set Y_ 100

$MN set Z_ 0

# Move the mobile node from AP1 to AP2’s coverage area

$ns at 2.0 “$MN set X_ 800; $MN set Y_ 800”  ;# Move MN toward AP2 at 2 seconds

# Simulate handoff by re-attaching traffic to AP2 after movement

proc handoff {} {

global ns MN tcp sink AP2

# Detach the current TCP agent from AP1 and reconnect to AP2

$ns detach-agent $MN $sink

$ns detach-agent $AP2 $tcp

# Create new sink at MN and reconnect to AP2 for handoff

set new_sink [new Agent/TCPSink]

$ns attach-agent $MN $new_sink

$ns connect $tcp $new_sink

puts “Handoff complete: Reconnected to AP2”

}

# Schedule handoff at 2.5 seconds

$ns at 2.5 “handoff”

# Schedule the end of the simulation

$ns at 5.0 “finish”

# Run the simulation

$ns run

  1. Explanation of the Script
  • Access Points (AP1 and AP2): These two access points like AP1 and AP2 are made to denote the fixed network setup. They are associated to the mobile node (MN) through the wireless links.
  • Mobile Node (MN): The mobile node moves among the coverage areas of AP1 and AP2. It begins near AP1 and moves to AP2.
  • Traffic Setup: TCP traffic (through FTP) is produced from AP1 to the mobile node (MN). It specifies an ongoing connection which wants to hand off while the node moves to the coverage area of AP2.
  • Mobility: The mobile node is primarily close to AP1 and they moves toward AP2 at time 2.0 seconds.
  • Handoff Procedure: The handoff is replicated by separating the TCP connection from AP1 and reattaching it to AP2 while the mobile node attains the AP2’s coverage area.
  1. Run the Simulation

We can save the script as mobility_handoff.tcl then run it using:

ns mobility_handoff.tcl

It will produce a trace file (out.tr) and a NAM file (out.nam) and we can open the NAM file to envision the mobility and handoff.

  1. Visualize the Handoff in NAM

We can use the NAM file to envision the node movement and handoff:

nam out.nam

We will monitor the mobile node moving among the nodes AP1 and AP2, including the handoff is happens around 2.5 seconds.

  1. Customize the Handoff Criteria

The specimen above executes the handoff according to the node’s position. We can improve the emulation by considering other handoff criteria, like:

  • Signal Strength: Handoff happens rely on the Received Signal Strength Indicator (RSSI) from the access points.
  • Load Balancing: if one AP is overloaded, and the other has more capacity, Handoff happens.
  •  Quality of Service (QoS): Handoff according to the maintaining a minimum QoS level.

Given below is an instances on how we may change the handoff logic depends on the signal strengt (RSSI):

proc handoff_based_on_rssi {} {

global ns MN tcp sink AP1 AP2

# Simulate signal strength for AP1 and AP2

set rssi_ap1 [expr 1000 – [$MN set X_]]   ;# Signal strength decreases as MN moves away from AP1

set rssi_ap2 [expr [$MN set X_] – 500]    ;# Signal strength increases as MN moves closer to AP2

if { $rssi_ap1 < $rssi_ap2 } {

puts “Handoff triggered based on RSSI: Connecting to AP2”

# Detach TCP from AP1 and reconnect to AP2

$ns detach-agent $MN $sink

$ns detach-agent $AP2 $tcp

set new_sink [new Agent/TCPSink]

$ns attach-agent $MN $new_sink

$ns connect $tcp $new_sink

}

}

# Check RSSI at regular intervals for handoff

$ns at 1.5 “handoff_based_on_rssi”

$ns at 2.0 “handoff_based_on_rssi”

$ns at 2.5 “handoff_based_on_rssi”

This logic verifies the RSSI values at intervals and while the mobile node is closer to AP2, activates a handoff.

  1. Analysing the Trace File

When the simulation runs, we can estimate the trace file (out.tr) to monitor packet broadcasts before and after the handoff. We can observe for:

  • Throughput: Calculate the throughput before and after the handoff.
  • Packet Loss: Verify if any packets were dropped while the handoff.
  • Delay: Examine any increase in delay according to the handoff process.

At the end, the above step-by-step techniques was applied to the Network Mobility Handoff with the execution and analysis performed through the simulation platform ns2. If you want further details on this topic, we will be offered. If you need help with your project on Network Mobility Handoff using ns2tool, feel free to reach out to us. We provide top-notch implementation guidance and can also assist you with analysing network performance for your project.