To Implement Mobile Cloud Computing (MCC) in ns-3 can be done by setting up mobile nodes (user devices), a cloud server, and the communication links which simulates a mobile network where mobile devices can offload computation tasks to a cloud server.
Prerequisites
- ns-3 installed on your system.
- Basic understanding of ns-3 and C++ programming.
Steps to Implement Mobile Cloud Computing in ns-3
- This can be done by setting up mobile nodes (user devices), a cloud server, and the communication links between them Install ns-3: Ensure you have ns-3 installed. You can download it from the official website and follow the installation instructions.
wget https://www.nsnam.org/release/ns-allinone-3.xx.tar.bz2
tar -xjf ns-allinone-3.xx.tar.bz2
cd ns-allinone-3.xx
./build.py –enable-examples –enable-tests
Include Necessary Headers: Include the required headers for the network modules, mobility, and internet.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/wifi-module.h”
Create Network Topology: Create nodes for mobile devices and the cloud server. Set up communication links between them using WiFi for mobile devices and a point-to-point link for the cloud server.
NodeContainer mobileNodes;
mobileNodes.Create(3);
NodeContainer cloudServerNode;
cloudServerNode.Create(1);
NodeContainer apNode;
apNode.Create(1);
Set Up WiFi Communication: Configure WiFi communication for the mobile devices and access point.
WifiHelper wifi;
wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(Ssid(“ns-3-ssid”)),
               “ActiveProbing”, BooleanValue(false));
NetDeviceContainer mobileDevices;
mobileDevices = wifi.Install(wifiPhy, wifiMac, mobileNodes);
wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(Ssid(“ns-3-ssid”)));
NetDeviceContainer apDevice;
apDevice = wifi.Install(wifiPhy, wifiMac, apNode);
Set Up Point-to-Point Link: Configure a point-to-point link between the access point and the cloud server.
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Gbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install(apNode.Get(0), cloudServerNode.Get(0));
Install Internet Stack: Install the internet stack on all nodes.
InternetStackHelper stack;
stack.Install(mobileNodes);
stack.Install(cloudServerNode);
stack.Install(apNode);
Assign IP Addresses: Assign IP addresses to the devices.
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer mobileInterfaces;
mobileInterfaces = address.Assign(mobileDevices);
address.SetBase(“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer apInterface;
apInterface = address.Assign(apDevice);
address.SetBase(“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer cloudInterface;
cloudInterface = address.Assign(p2pDevices);
Set Up Mobility Model: Configure the mobility model for the mobile devices to simulate movement.
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
                             “MinX”, DoubleValue(0.0),
                             “MinY”, DoubleValue(0.0),
                             “DeltaX”, DoubleValue(5.0),
                             “DeltaY”, DoubleValue(10.0),
                             “GridWidth”, UintegerValue(3),
                             “LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”,
                         “Bounds”, RectangleValue(Rectangle(-50, 50, -50, 50)));
mobility.Install(mobileNodes);
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(apNode);
mobility.Install(cloudServerNode);
Create Applications: Create and install applications on the mobile devices to simulate offloading tasks to the cloud server.
uint16_t port = 9;
OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(cloudInterface.GetAddress(1), port)));
onoff.SetConstantRate(DataRate(“500kb/s”));
ApplicationContainer app = onoff.Install(mobileNodes.Get(0));
app.Start(Seconds(1.0));
app.Stop(Seconds(10.0));
PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
app = sink.Install(cloudServerNode.Get(0));
app.Start(Seconds(0.0));
app.Stop(Seconds(10.0));
Run the Simulation: Finally, run the simulation and clean up.
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
Example Complete Script
Below is an example complete script:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/wifi-module.h”
using namespace ns3;
int main(int argc, char *argv[])
{
   NodeContainer mobileNodes;
   mobileNodes.Create(3);
   NodeContainer cloudServerNode;
   cloudServerNode.Create(1);
   NodeContainer apNode;
   apNode.Create(1);
   WifiHelper wifi;
   wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);
   YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
   YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
   wifiPhy.SetChannel(wifiChannel.Create());
   WifiMacHelper wifiMac;
   wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(Ssid(“ns-3-ssid”)),
                   “ActiveProbing”, BooleanValue(false));
   NetDeviceContainer mobileDevices;
   mobileDevices = wifi.Install(wifiPhy, wifiMac, mobileNodes);
   wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(Ssid(“ns-3-ssid”)));
   NetDeviceContainer apDevice;
   apDevice = wifi.Install(wifiPhy, wifiMac, apNode);
   PointToPointHelper pointToPoint;
   pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Gbps”));
   pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
   NetDeviceContainer p2pDevices;
   p2pDevices = pointToPoint.Install(apNode.Get(0), cloudServerNode.Get(0));
Â
   InternetStackHelper stack;
   stack.Install(mobileNodes);
   stack.Install(cloudServerNode);
   stack.Install(apNode);
   Ipv4AddressHelper address;
   address.SetBase(“10.1.1.0”, “255.255.255.0”);
   Ipv4InterfaceContainer mobileInterfaces;
   mobileInterfaces = address.Assign(mobileDevices);
   address.SetBase(“10.1.2.0”, “255.255.255.0”);
   Ipv4InterfaceContainer apInterface;
   apInterface = address.Assign(apDevice);
   address.SetBase(“10.1.3.0”, “255.255.255.0”);
   Ipv4InterfaceContainer cloudInterface;
   cloudInterface = address.Assign(p2pDevices);
   MobilityHelper mobility;
   mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
                                 “MinX”, DoubleValue(0.0),
                                 “MinY”, DoubleValue(0.0),
                                 “DeltaX”, DoubleValue(5.0),
                                 “DeltaY”, DoubleValue(10.0),
                                 “GridWidth”, UintegerValue(3),
                                 “LayoutType”, StringValue(“RowFirst”));
Â
   mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”,
                             “Bounds”, RectangleValue(Rectangle(-50, 50, -50, 50)));
   mobility.Install(mobileNodes);
   mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
   mobility.Install(apNode);
   mobility.Install(cloudServerNode);
   uint16_t port = 9;
   OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(cloudInterface.GetAddress(1), port)));
   onoff.SetConstantRate(DataRate(“500kb/s”));
   ApplicationContainer app = onoff.Install(mobileNodes.Get(0));
   app.Start(Seconds(1.0));
   app.Stop(Seconds(10.0));
   PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
   app = sink.Install(cloudServerNode.Get(0));
   app.Start(Seconds(0.0));
   app.Stop(Seconds(10.0));
   Simulator::Stop(Seconds(10.0));
   Simulator::Run();
   Simulator::Destroy();
Â
   return 0;
}
Running the Script
Compile and run the script using the following commands:
./waf configure –enable-examples
./waf build
./waf –run <script-name>
Finally, we all know how to implement the Mobile Cloud Computing in ns-3 get best results by following the above steps .






































