How to Implement Mobile Cloud Computing in ns2

To implement the Mobile Cloud Computing (MCC) in ns2 has some complexities because of ns2’s inherent restriction that was mainly developed for simulating lower-layer networking protocols instead of the application layer services like cloud computing. Though, you can replicate a basic version of MCC by prototyping the mobile devices while the nodes unload tasks to a cloud server indicated as another node within the network.

We delivered the implementation guide of MCC using ns2 in the following below:

Step-by-Step Implementation:

Step 1: Conceptualizing the Simulation

In a Mobile Cloud Computing scenario, mobile devices (nodes) unload computational tasks to a cloud server. The basic idea is to simulate:

  1. Mobile Nodes: Indicate mobile devices that travel inside the network.
  2. Cloud Server: A stationary node that signifies the cloud service provider.
  3. Task Offloading: The process where mobile nodes send tasks (data) to the cloud server for processing.

Step 2: Create the Tcl Script

Below is a basic Tcl script that simulates a basic MCC scenario where mobile nodes offload tasks to a cloud server. The cloud server processes the tasks and sends the output back to the mobile nodes.

Example Tcl Script for Simulating Mobile Cloud Computing

# 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 4  # Number of nodes (3 mobile nodes + 1 cloud server)

# Configure the mobile nodes and cloud server

$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 mcc_out.tr w]

$ns trace-all $tracefile

set namfile [open mcc_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 mcc_out.nam &

exit 0

}

# Create mobile nodes (representing mobile devices)

set mn0 [$ns node]

set mn1 [$ns node]

set mn2 [$ns node]

# Set initial positions for mobile nodes

$mn0 set X_ 100.0

$mn0 set Y_ 200.0

$mn0 set Z_ 0.0

$mn1 set X_ 300.0

$mn1 set Y_ 400.0

$mn1 set Z_ 0.0

$mn2 set X_ 500.0

$mn2 set Y_ 600.0

$mn2 set Z_ 0.0

# Create the cloud server node

set cloud [$ns node]

# Set the position for the cloud server (stationary)

$cloud set X_ 800.0

$cloud set Y_ 800.0

$cloud set Z_ 0.0

# Define node movements to simulate mobile devices moving

$ns at 5.0 “$mn0 setdest 600.0 700.0 10.0”

$ns at 10.0 “$mn1 setdest 700.0 500.0 10.0”

$ns at 15.0 “$mn2 setdest 900.0 300.0 10.0”

# Define the task offloading process (mobile nodes offload tasks to the cloud)

proc task_offload {mobile cloud data_size processing_time} {

global ns

# Simulate the offloading of a task

set tcp [new Agent/TCP]

$ns attach-agent $mobile $tcp

set sink [new Agent/TCPSink]

$ns attach-agent $cloud $sink

$ns connect $tcp $sink

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set maxpkts_ $data_size

$ftp start

# Simulate processing time at the cloud server

$ns at [expr $ns now + $processing_time] “$cloud send-data-back $mobile $data_size”

}

# Define a procedure for the cloud server to send the result back to the mobile node

proc send-data-back {mobile data_size} {

global ns cloud

set tcp_back [new Agent/TCP]

$ns attach-agent $cloud $tcp_back

set sink_back [new Agent/TCPSink]

$ns attach-agent $mobile $sink_back

$ns connect $tcp_back $sink_back

set ftp_back [new Application/FTP]

$ftp_back attach-agent $tcp_back

$ftp_back set maxpkts_ $data_size

$ftp_back start

}

# Schedule task offloading from each mobile node to the cloud

task_offload $mn0 $cloud 1024 2.0

task_offload $mn1 $cloud 2048 3.0

task_offload $mn2 $cloud 512 1.5

# Schedule the end of the simulation

$ns at 20.0 “finish”

# Run the simulation

$ns run

Step 3: Run the Tcl Script

Save the Tcl script with a .tcl extension like mcc_simulation.tcl. Execute the script using the given command in your terminal:

ns mcc_simulation.tcl

Step 4: Visualize the Simulation

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

nam mcc_out.nam

It will show the mobile nodes, the cloud server, and the replicated task offloading process.

Script Explanation

  • Mobile Nodes (mn0, mn1, mn2): These denote mobile devices that travel through the network and offload tasks to the cloud server.
  • Cloud Server (cloud): This node indicates the cloud computing resource that processes tasks unloaded by the mobile nodes.
  • Task Offloading: The task_offload approach simulates mobile nodes directing tasks (data) to the cloud server. The cloud processes the tasks and routes the results back to the mobile nodes.
  • Node Mobility: The mobile nodes transfer over the network, recreating the dynamic nature of mobile devices in a real MCC situation.

Customization

  • More Mobile Nodes: Recreate a larger network with several devices unloading tasks to the cloud by attaching more mobile nodes.
  • Complex Task Offloading: Execute more difficult task offloading logic includes task partitioning, various processing times, and changing data sizes.
  • Dynamic Cloud Server: Rather than a stationary cloud server, you could simulate numerous cloud servers with various potentials and dynamic load balancing.
  • Interference and Handover: Present scenarios where mobile nodes travel amongst various base stations or experience network intrusion during task offloading.

Limitations

  • Simplified Model: This simulation is a high-level abstraction and does not contain detailed modeling of cloud computing services or difficult task offloading algorithms.
  • No Real Cloud Simulation: it is indicated as a basic node that has no real cloud computing abilities.
  • Lack of Application-Layer Protocols: ns2 lacks support application-layer protocols like HTTP, which would be used in a realistic cloud computing environment.

Above demonstration will help you to implement the MCC in ns2 by simulating the mobile nodes, cloud servers and performing computational tasks. We can custom the network however it also has some limitations.. Whenever, you need details regarding this script, you can get them from us.

Are you interested in implementing Mobile Cloud Computing using the ns2 tool? please feel free to contact us. We are available to support you with your comparative analysis. By providing us with your project details, you can achieve optimal simulation results.