How to Simulate Mobile Computing Projects Using NS2

To simulate Mobile Computing projects in NS2 have includes configuring a network with mobile nodes, simulating their movement, and introducing communication among these nodes over wireless channels. Mobile computing projects usually concentrate on mobility models, routing protocols, and the effects of mobility on communication. Send to phdprime.com all your project details we will share with you best simulation outcomes.

Here is a step-by-step guide on how to simulate mobile computing projects using NS2:

Steps to Simulate Mobile Computing Projects in NS2

  1. Install NS2
  • Download and install NS2 from the official NS2 website.
  • Make sure that we have the essential libraries (Tcl/Tk, OTcl, NAM) for composing simulation scripts and envision the outcomes.
  1. Understand Key Concepts in Mobile Computing
  • Mobile Nodes (MNs): Devices that move and interact with each other in a wireless ad-hoc network such as laptops, smartphones.
  • Mobility Models: Simulating the movement of nodes in the network. Examples that contain the Random Waypoint Model, Random Walk Model, Manhattan Grid Model, etc.
  • Routing Protocols: The communication among mobile nodes is usually managed by routing protocols such as AODV (Ad-Hoc On-Demand Distance Vector), DSR (Dynamic Source Routing), or others.
  • Wireless Communication: Mobile nodes communicate wirelessly, usually using protocols such as IEEE 802.11.
  1. Set up the Mobile Network Topology

In mobile computing simulations, we want to describe a set of mobile nodes and specify their movement. NS2 has built-in support for describing mobility models.

Example OTcl Code to Define Mobile Topology:

# Create a simulator instance

set ns [new Simulator]

# Define the topography (flat grid) for the mobile nodes

set topo [new Topography]

$topo load_flatgrid 1000 1000  ;# Grid of 1000×1000 meters

# Define the number of mobile nodes

set num_nodes 10

# Create nodes and set their mobility

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

set node($i) [$ns node]

$node($i) set X_ [expr rand() * 1000]

$node($i) set Y_ [expr rand() * 1000]

$node($i) set Z_ 0.0

$node($i) random-motion 0   ;# Disable random motion until mobility model is set

}

# Set wireless communication parameters

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

set val(prop)           Propagation/TwoRayGround     ;# Radio Propagation Model

set val(netif)          Phy/WirelessPhy              ;# Network Interface Type

set val(mac)            Mac/802_11                   ;# MAC Type (Wireless)

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

set val(ll)             LL                           ;# Link Layer Type

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

set val(ifqlen)         50                           ;# Max Packet in IFQ

set val(nn)             10                           ;# Number of Mobile Nodes

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

# Create the wireless network configuration

$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

In this example:

  • A wireless ad-hoc network is configured with 10 mobile nodes.
  • Each node is start at a random position within a 1000×1000 grid.
  • Wireless communication parameters are configured using the IEEE 802.11 protocol, and the AODV routing protocol is chosen.
  1. Implement Mobility Models

NS2 supports numerous mobility models to replicate the movement of mobile nodes. The Random Waypoint Model is one of the most frequent mobility models.

Example of Random Waypoint Mobility Model:

# Set Random Waypoint Mobility for each mobile node

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

setdest $node($i) [expr rand() * 1000] [expr rand() * 1000] 10.0

}

In this example, each node is randomly allocated a destination in the 1000×1000 grid, moving at a speed of 10 meters per second.

  1. Simulate Traffic in Mobile Network

Mobile nodes usually interchange the data using UDP or TCP protocols. We can create traffic flows among nodes using NS2’s traffic generation capabilities.

Example UDP Traffic Configuration:

# Define UDP agents and attach them to nodes

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

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

$ns attach-agent $node(1) $null0

$ns connect $udp0 $null0

# Create a Constant Bit Rate (CBR) traffic generator

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 1Mb

$cbr0 attach-agent $udp0

# Start CBR traffic at time 1.0 seconds

$ns at 1.0 “$cbr0 start”

In this example:

  • A UDP agent is attached to node 0, and a null agent is attached to node 1.
  • Constant Bit Rate (CBR) traffic is created and sent from node 0 to node 1 at a rate of 1 Mb/s.
  1. Run the Simulation

Save simulation script as mobile_computing.tcl and execute it in NS2 using the following command:

ns mobile_computing.tcl

  1. Analyse the Results

NS2 creates a trace file that records all events in the course of the simulation. We can process this trace file to measure numerous parameters like throughput, delay, and packet delivery ratio.

Example Trace File Analysis Using Awk:

awk -f analyze_trace.awk mobile_computing.tr

  1. Visualize the Simulation with NAM

We can utilize Network Animator (NAM) to envision the movement of mobile nodes and their communication. NAM deliver a graphical interface to monitor the simulation.

nam mobile_computing.nam

  1. Advanced Mobility Models

We can simulate more complex mobility models for certain scenarios:

  • Random Walk Mobility Model: Nodes move randomly in any direction.
  • Manhattan Grid Mobility Model: Nodes move along predefined paths (useful for urban simulations).
  • Gauss-Markov Mobility Model: Replicate realistic movement with velocity and direction changes.

Example of Manhattan Grid Mobility:

# Use the Manhattan Grid Mobility Model

set grid [new God]

$grid set-destination $node(0) 100 100 5.0

$grid set-destination $node(1) 200 200 5.0

  1. Advanced Routing Protocols for Mobile Networks

NS2 supports multiple ad-hoc routing protocols. we can simulate diverse routing protocols like:

  • AODV (Ad-hoc On-demand Distance Vector): A reactive routing protocol that introduces routes only when required.
  • DSR (Dynamic Source Routing): A source routing protocol that sustains a route cache.
  • DSDV (Destination-Sequenced Distance-Vector Routing): A proactive routing protocol that updates routing tables occasionally.

To utilize a diverse routing protocol, simply adapt the rp value in the node configuration:

set val(rp) DSR   ;# Use DSR routing protocol

Example Simulation Script Outline for Mobile Computing:

# Simulation script for Mobile Computing in NS2

set ns [new Simulator]

set topo [new Topography]

$topo load_flatgrid 1000 1000  ;# Define a 1000×1000 meter area for mobile nodes

# Define the number of mobile nodes

set num_nodes 10

# Create mobile nodes and set their initial positions

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

set node($i) [$ns node]

$node($i) set X_ [expr rand() * 1000]

$node($i) set Y_ [expr rand() * 1000]

$node($i) set Z_ 0.0

$node($i) random-motion 0  ;# Disable random motion for now

}

# Wireless communication parameters (802.11 and AODV)

$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

# Set mobility model (Random Waypoint)

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

setdest $node($i) [expr rand() * 1000] [expr rand() * 1000] 10.0

}

# Define UDP traffic between nodes

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

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

$ns attach-agent $node(1) $null0

$ns connect $udp0 $null0

# CBR traffic generator

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 1Mb

$cbr0 attach-agent $udp0

# Start traffic at 1.0 seconds

$ns at 1.0 “$cbr0 start”

# End simulation at 100 seconds

$ns at 100.0 “finish”

# Run the simulation

$ns run

Key Points:

  • Mobility Models: Apply numerous mobility models such as Random Waypoint or Random Walk to replicate realistic movement of mobile nodes.
  • Routing Protocols: Utilize reactive or proactive routing protocols to manage communication in mobile ad-hoc networks.
  • Traffic Generation: Replicate communication among mobile nodes using UDP or TCP protocols.
  • Visualization: Utilize NAM to envision the movement and communication of mobile nodes.

In the overall demonstration, we had seen and taught about the simulation procedures with example code snippets with detailed explanation regarding the mobile computing projects using the tool of ns2. If needed, we deliver more details regarding mobile computing project.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2