To simulate Mobile Cloud Computing (MCC) projects using NS2 (Network Simulator 2) that wants modeling a system in which mobile devices are offload computational tasks to cloud servers through a wireless network. In Mobile Cloud Computing, mobile devices leverage cloud resources to overcome their limitations like limited processing power, memory, and battery life.
To simulate an MCC environment in NS2, we want to model the following key modules:
- Mobile Devices (Clients): Mobile nodes, which generate requests and offload tasks to cloud servers.
- Cloud Servers: Centralized or distributed servers that manage the computation offloaded from mobile devices.
- Wireless Network: The communication infrastructure among mobile devices and cloud servers.
- Task Offloading: The process in which mobile devices are offload their computational tasks to the cloud.
- Performance Metrics: Estimating parameters like offloading delay, network latency, energy savings, and throughput.
The following is an instruction on how to simulate Mobile Cloud Computing projects using NS2.
Steps for Simulating Mobile Cloud Computing in NS2
- Install NS2: If NS2 is not installed on the system we can install it using the following command:
sudo apt-get install ns2
Verify the installation by typing:
ns -version
- Understand the Key Components:
- Mobile Nodes: These denote mobile devices like smartphones, tablets, or IoT devices.
- Cloud Server Node: This node performs as the cloud server or data center where offloaded tasks are implemented.
- Wireless Network: A wireless channel, which permits mobile nodes to communicate with the cloud server.
- Offloading Mechanism: The process by which mobile devices send computational tasks to the cloud server.
- Create a Mobile Cloud Computing Scenario Using a Tcl Script: The following is an instance Tcl script to replicate a simple MCC environment in which mobile nodes (clients) offload their computational tasks to a cloud server via a wireless network.
Example Tcl Script for Simulating Mobile Cloud Computing in NS2
# Create a new simulator object
set ns [new Simulator]
# Open trace and NAM files for output
set tracefile [open mcc_out.tr w]
$ns trace-all $tracefile
set namfile [open mcc_out.nam w]
$ns namtrace-all-wireless $namfile 500 500
# Define the wireless channel and propagation model for MCC
set val(chan) Channel/WirelessChannel ;# Wireless channel type
set val(prop) Propagation/TwoRayGround ;# Propagation model
set val(netif) Phy/WirelessPhy ;# Wireless PHY layer
set val(mac) Mac/802_11 ;# MAC type (Wi-Fi)
set val(ifq) Queue/DropTail/PriQueue ;# Interface Queue
set val(ll) LL ;# Link Layer
set val(ant) Antenna/OmniAntenna ;# Antenna model
set val(ifqlen) 50 ;# Interface Queue length
set val(nn) 3 ;# Number of mobile nodes (clients)
set val(x) 500 ;# X dimension of the topology
set val(y) 500 ;# Y dimension of the topology
# Define the network topology object for MCC simulation
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Configure node settings for mobile devices
$ns node-config -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 \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
# Create mobile nodes (clients) and cloud server
set mobile_0 [$ns node] ;# Mobile device 1
set mobile_1 [$ns node] ;# Mobile device 2
set mobile_2 [$ns node] ;# Mobile device 3
set cloud_server [$ns node] ;# Cloud server
# Set initial positions for mobile nodes (clients) and cloud server
$mobile_0 set X_ 100.0
$mobile_0 set Y_ 200.0
$mobile_1 set X_ 200.0
$mobile_1 set Y_ 300.0
$mobile_2 set X_ 300.0
$mobile_2 set Y_ 400.0
$cloud_server set X_ 250.0
$cloud_server set Y_ 250.0
# Create UDP agents for task offloading from mobile nodes to cloud server
set udp_mobile_0 [new Agent/UDP]
$ns attach-agent $mobile_0 $udp_mobile_0
set udp_mobile_1 [new Agent/UDP]
$ns attach-agent $mobile_1 $udp_mobile_1
set udp_mobile_2 [new Agent/UDP]
$ns attach-agent $mobile_2 $udp_mobile_2
# Create a Null agent to act as a sink on the cloud server (to receive tasks)
set null_server [new Agent/Null]
$ns attach-agent $cloud_server $null_server
# Connect mobile devices (clients) to the cloud server (offloading tasks)
$ns connect $udp_mobile_0 $null_server
$ns connect $udp_mobile_1 $null_server
$ns connect $udp_mobile_2 $null_server
# Create CBR (Constant Bit Rate) applications to simulate task offloading traffic
set cbr_mobile_0 [new Application/Traffic/CBR]
$cbr_mobile_0 set packetSize_ 512
$cbr_mobile_0 set interval_ 0.05 ;# Frequent task offloading from mobile_0
$cbr_mobile_0 attach-agent $udp_mobile_0
set cbr_mobile_1 [new Application/Traffic/CBR]
$cbr_mobile_1 set packetSize_ 1024 ;# Larger tasks offloaded from mobile_1
$cbr_mobile_1 set interval_ 0.1 ;# Offloading occurs less frequently
$cbr_mobile_1 attach-agent $udp_mobile_1
set cbr_mobile_2 [new Application/Traffic/CBR]
$cbr_mobile_2 set packetSize_ 512
$cbr_mobile_2 set interval_ 0.02 ;# Frequent task offloading from mobile_2
$cbr_mobile_2 attach-agent $udp_mobile_2
# Schedule the task offloading traffic
$ns at 1.0 “$cbr_mobile_0 start”
$ns at 1.0 “$cbr_mobile_1 start”
$ns at 1.0 “$cbr_mobile_2 start”
# Simulation ends at 10 seconds
$ns at 10.0 “finish”
# Define finish procedure to close trace files and run NAM
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam mcc_out.nam &
exit 0
}
# Run the simulation
$ns run
Explanation of the Tcl Script:
- Simulator Object:
- The set ns [new Simulator] command initializes the NS2 simulation engine.
- Mobile Nodes and Cloud Server:
- Three mobile nodes (mobile_0, mobile_1, mobile_2) are denote mobile clients, and one cloud server node (cloud_server) performs as the offloading destination.
- Task Offloading Simulation (UDP over CBR):
- UDP agents are connected to the mobile nodes to mimic the offloading of tasks to the cloud server.
- CBR (Constant Bit Rate) applications denote task offloading traffic in which distinct packet sizes and intervals replicate changing task sizes and offloading frequencies.
- Task Offloading Scheduling:
- Task offloading begins at 1.0 seconds and continues for 10 seconds, after which the simulation stops.
- Traffic Behavior:
- Mobile_0 offloads smaller tasks often, even though mobile_1 offloads larger tasks less often that signifying distinct offloading patterns.
- Simulation End:
- The simulation stops at 10.0 seconds, and the finish procedure closes files and intoduces NAM for visualizing the simulation.
- Running the Simulation:
We can save the script as mcc_simulation.tcl and then run it using NS2:
ns mcc_simulation.tcl
After the simulation completes, open NAM to visualize the network:
nam mcc_out.nam
- Analyzing the Results:
- The trace file (mcc_out.tr) records all the task offloading activities and network events like packet transmissions, receptions, and drops. We can investigate the trace file to extract parameters such as:
- Task offloading delay (end-to-end delay)
- Throughput of the offloaded tasks
- Network latency among mobile devices and the cloud server
- Energy consumption (can be estimated indirectly according to offloading frequency and network usage)
- Example AWK script to calculate throughput:
BEGIN {
total_packets = 0;
start_time = 0;
end_time = 0;
}
{
if ($1 == “r” && $4 == “AGT”) {
total_packets++;
if (start_time == 0) {
start_time = $2;
}
end_time = $2;
}
}
END {
duration = end_time – start_time;
throughput = (total_packets * 512 * 8) / (duration * 1000); # kbps
printf(“Throughput: %.2f kbps\n”, throughput);
}
Extending the Simulation:
- Advanced Cloud Computing Models:
- Launch several cloud servers or edge computing nodes are nearer to mobile users to mimic task offloading to distributed cloud resources.
- Energy Consumption Modeling:
- Execute energy models for mobile nodes to replicate
- Offloading Decision Algorithms: energy consumption in the course of task offloading and compare it to local computation.
- Execute decision algorithms for mobile nodes to find out whether a task should be offloaded rely on factors such as task size, network conditions, and energy availability.
- Task Offloading with Different Wireless Networks:
- Replicate task offloading over distinct wireless networks, like Wi-Fi, LTE, or 5G, to estimate how distinct networks influence offloading performance.
- Realistic Mobility Models:
- Launch mobility models for the mobile nodes to replicate mobile offloading while the devices move across the network.
We outlined simulation steps to model and execute the Mobile Cloud Computing projects using NS2 simulation platform. If asked, we can dive deeper into subject and provide thorough explanations.
Get top-notch guidance on routing protocols like AODV, DSR, DSDV, and TORA for your projects with our expert support. We also provide assistance in project evaluation. At phdprime.com, we deliver exceptional Mobile Cloud Computing simulation results and offer customized project ideas that align with your interests when you collaborate with us.