How to Implement Mobile Computing in ns2

To implement the Mobile Computing in ns2, we need to simulate the mobile nodes (like smartphones, tablets or laptops) that travel through the described area as they interacting with one another or with fixed structures (such as base station or access points). These computing in ns2 can be used to learn the influence of mobility on network performance, the efficiency of routing protocols and the actions of different network services in various mobility models.

We focus on nodes related to your projects. Are you interested in using Mobile Computing with the ns2 tool for your projects? Feel free to contact ns2project.com for the best outcomes.

Follow the implementation guide provide below:

Step-by-Step Implementation:

Conceptual Overview

In a mobile computing network:

  1. Mobile Nodes: These are devices that travel inside the stated area, communicating with one another or with fixed infrastructure.
  2. Fixed Infrastructure: This can contain base stations, access points, or servers that mobile nodes link to for data transmission.
  3. Mobility Models: These models replicate the movement of mobile nodes, impacting their connectivity and communication patterns.
  4. Routing Protocols: Ad-hoc or infrastructure-based routing protocols handle communication amongst nodes.

Step 1: Conceptualize the Mobile Computing Simulation

In this simulation, we will generate an environment that has mobile nodes which travel around in a predefined area, communicating with one another with the help of ad-hoc routing protocol like AODV (Ad Hoc On-Demand Distance Vector).

Step 2: Create the Tcl Script

Below is a sample Tcl script that simulates a basic mobile computing situation in ns2.

Example Tcl Script for Simulating Mobile Computing in ns2

# Create a simulator object

set ns [new Simulator]

# Define the topography object (for a larger area to allow mobility)

set topo [new Topography]

$topo load_flatgrid 1500 1500  # 1.5km x 1.5km area

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

create-god 6  # Number of nodes (5 mobile nodes + 1 fixed node)

# Configure the nodes for the mobile computing network using 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 \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace OFF

# Open trace and NAM files for recording the simulation

set tracefile [open mobile_out.tr w]

$ns trace-all $tracefile

set namfile [open mobile_out.nam w]

$ns namtrace-all-wireless $namfile 1500 1500

# 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 mobile_out.nam &

exit 0

}

# Create mobile nodes

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

set node5 [$ns node]

# Create a fixed node (e.g., a base station or server)

set fixed_node [$ns node]

# Set initial positions for mobile nodes and the fixed node

$node1 set X_ 100.0

$node1 set Y_ 200.0

$node1 set Z_ 0.0

$node2 set X_ 300.0

$node2 set Y_ 400.0

$node2 set Z_ 0.0

$node3 set X_ 500.0

$node3 set Y_ 600.0

$node3 set Z_ 0.0

$node4 set X_ 700.0

$node4 set Y_ 800.0

$node4 set Z_ 0.0

$node5 set X_ 900.0

$node5 set Y_ 1000.0

$node5 set Z_ 0.0

$fixed_node set X_ 750.0

$fixed_node set Y_ 750.0

$fixed_node set Z_ 0.0

# Define mobility for the mobile nodes (Random Waypoint Mobility Model)

$ns at 1.0 “$node1 setdest 1200.0 1200.0 20.0”

$ns at 2.0 “$node2 setdest 1000.0 500.0 20.0”

$ns at 3.0 “$node3 setdest 300.0 900.0 20.0”

$ns at 4.0 “$node4 setdest 400.0 700.0 20.0”

$ns at 5.0 “$node5 setdest 1500.0 1500.0 20.0”

# Define a custom procedure for simulating data transmission between nodes

proc send_data {src dst packetSize rate} {

global ns

# Create a UDP agent to simulate data traffic

set udp [new Agent/UDP]

$ns attach-agent $src $udp

set null [new Agent/Null]

$ns attach-agent $dst $null

$ connect $udp $null

# Generate data traffic using a CBR application

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ $packetSize

$cbr set rate_ $rate

$cbr start

}

# Simulate data transmission between mobile nodes and the fixed node

$ns at 2.0 “send_data $node1 $fixed_node 512 100Kb”

$ns at 4.0 “send_data $node2 $fixed_node 512 100Kb”

$ns at 6.0 “send_data $node3 $fixed_node 512 100Kb”

$ns at 8.0 “send_data $node4 $fixed_node 512 100Kb”

$ns at 10.0 “send_data $node5 $fixed_node 512 100Kb”

# Schedule the end of the simulation

$ns at 20.0 “finish”

# Run the simulation

$ns run

Step 3: Run the Tcl Script

Save the script with a .tcl extension like, mobile_simulation.tcl. Then, give the following command into the terminal to execute the script:

ns mobile_simulation.tcl

Step 4: Visualize the Simulation

To visualize the simulation, open the generated NAM file using:

nam mobile_out.nam

Script Explanation

  • Mobile Nodes: The nodes node1 to node5 indicate mobile devices that travel inside the simulation area based on a random waypoint mobility model.
  • Fixed Node: The fixed_node signifies a stationary node like a base station or server, that mobile nodes can interact with.
  • Mobility: The setdest commands replicate the movement of mobile nodes to random destinations at a speed of 20 units per second.
  • Data Transmission: The send_data procedure simulates data transmission from the mobile nodes to the fixed node using UDP, which is regular in many mobile applications because its simplicity and low overhead.

Customization

  • Different Mobility Models: Research with other mobility models (like Random Waypoint, Manhattan Grid) to imitate various kinds of movement patterns for the mobile nodes.
  • Varying Data Rates: Replicate the various mobile applications like video streaming, messaging or file transfer by modifying the data rates and packet sizes.
  • Multiple Fixed Nodes: Simulate a more difficult mobile network with handovers and changing connectivity by attaching more fixed nodes (such as server base stations).
  • QoS: Execute Quality of Service (QoS) configurations to simulate the changing demands of various mobile applications.

Limitations

  • Simplified Mobility: The Random Waypoint mobility model used in this sample is basic and may not precisely reflect real-world mobility patterns.
  • Limited Protocol Support: ns2 has restricted help for modern mobile communication protocols, which may limit the realism of the simulation.
  • No Physical Layer Simulation: It does not simulate physical layer characteristics specific to mobile networks like signal degradation, intrusion, or multipath effects.

Through this approach, we successfully covered concept on how to accomplish the mobile computing environment by providing an example using ns2. You can customize according to the requirements. If you any doubts about this script, we will guide you through another simulation.