Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How To Implement Fog Computing in Ns3

To implement a fog computing in ns-3 we will simulate a network where computation, storage and networking services that are tailored to the edge of the network and  closely related to the data source. This decreases the latency and enhances the performance for time sensitive applications. We have all the data source available to carry out your implementation.

Now we provide the step by step procedures to set up a fog computing g scenario in ns-3 environment:

Step-by-Step Guide to Implement Fog Computing in ns-3

  1. Set Up Your Development Environment
  1. Install ns-3:
    • Follow the official ns-3 installation guide.
  2. Install Required Modules:
    • Ensure you have all necessary ns-3 modules installed, such as Internet, Point-to-Point, WiFi, and Applications modules.
  1. Create a Basic Fog Computing Simulation Script

Below is the samples script to set up a Fog Computing environment using ns-3:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/wifi-module.h”

#include “ns3/applications-module.h”

#include “ns3/mobility-module.h”

#include “ns3/flow-monitor-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“FogComputingExample”);

int main (int argc, char *argv[])

{

  // Set simulation parameters

  double simTime = 20.0; // Simulation time in seconds

  uint32_t numClients = 3;

  uint32_t numFogNodes = 2;

  uint32_t numCloudServers = 1;

  CommandLine cmd;

  cmd.AddValue(“simTime”, “Simulation time”, simTime);

  cmd.AddValue(“numClients”, “Number of client nodes”, numClients);

  cmd.AddValue(“numFogNodes”, “Number of fog nodes”, numFogNodes);

  cmd.AddValue(“numCloudServers”, “Number of cloud server nodes”, numCloudServers);

  cmd.Parse(argc, argv);

  // Create nodes

  NodeContainer clients;

  clients.Create(numClients);

  NodeContainer fogNodes;

  fogNodes.Create(numFogNodes);

 

  NodeContainer cloudServers;

  cloudServers.Create(numCloudServers);

  NodeContainer backboneRouter;

  backboneRouter.Create(1);

  // Create Wi-Fi network for clients

  WifiHelper wifi;

  wifi.SetStandard(WIFI_PHY_STANDARD_80211ac);

  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

  wifiPhy.SetChannel(wifiChannel.Create());

  WifiMacHelper wifiMac;

  Ssid ssid = Ssid(“fog-computing-network”);

  wifiMac.SetType(“ns3::StaWifiMac”,

                  “Ssid”, SsidValue(ssid),

                  “ActiveProbing”, BooleanValue(false));

  NetDeviceContainer clientDevices;

  clientDevices = wifi.Install(wifiPhy, wifiMac, clients);

  wifiMac.SetType(“ns3::ApWifiMac”,

                  “Ssid”, SsidValue(ssid));

 

  NetDeviceContainer apDevices;

  apDevices = wifi.Install(wifiPhy, wifiMac, fogNodes);

  // Set up point-to-point links between fog nodes, cloud servers, and backbone router

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));

  pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));

  NetDeviceContainer fogDevices, cloudDevices, backboneDevices;

  for (uint32_t i = 0; i < numFogNodes; ++i) {

    NetDeviceContainer link = pointToPoint.Install(fogNodes.Get(i), backboneRouter.Get(0));

    fogDevices.Add(link.Get(0));

    backboneDevices.Add(link.Get(1));

  }

  for (uint32_t i = 0; i < numCloudServers; ++i) {

    NetDeviceContainer link = pointToPoint.Install(cloudServers.Get(i), backboneRouter.Get(0));

    cloudDevices.Add(link.Get(0));

    backboneDevices.Add(link.Get(1));

  }

  // Install the Internet stack on all nodes

  InternetStackHelper stack;

  stack.Install(clients);

  stack.Install(fogNodes);

  stack.Install(cloudServers);

  stack.Install(backboneRouter);

  // Assign IP addresses

  Ipv4AddressHelper address;

  address.SetBase(“10.1.1.0”, “255.255.255.0”);

  Ipv4InterfaceContainer clientInterfaces = address.Assign(clientDevices);

  address.SetBase(“10.1.2.0”, “255.255.255.0”);

  Ipv4InterfaceContainer fogInterfaces = address.Assign(fogDevices);

  address.SetBase(“10.1.3.0”, “255.255.255.0”);

  Ipv4InterfaceContainer cloudInterfaces = address.Assign(cloudDevices);

  address.SetBase(“10.1.4.0”, “255.255.255.0”);

  Ipv4InterfaceContainer apInterfaces = address.Assign(apDevices);

  address.SetBase(“10.1.5.0”, “255.255.255.0”);

  Ipv4InterfaceContainer backboneInterfaces = address.Assign(backboneDevices);

  // Set up mobility

  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::ConstantPositionMobilityModel”);

  mobility.Install(clients);

  mobility.Install(fogNodes);

  mobility.Install(cloudServers);

  // Create applications

  uint16_t port = 8080;

  // Install a UDP echo server on each fog node

  for (uint32_t i = 0; i < numFogNodes; ++i) {

    UdpEchoServerHelper echoServer(port);

    ApplicationContainer serverApp = echoServer.Install(fogNodes.Get(i));

    serverApp.Start(Seconds(1.0));

    serverApp.Stop(Seconds(simTime));

  }

  // Install a UDP echo server on each cloud server node

  for (uint32_t i = 0; i < numCloudServers; ++i) {

    UdpEchoServerHelper echoServer(port);

    ApplicationContainer serverApp = echoServer.Install(cloudServers.Get(i));

    serverApp.Start(Seconds(1.0));

    serverApp.Stop(Seconds(simTime));

  }

  // Install a UDP echo client on each client node

  for (uint32_t i = 0; i < numClients; ++i) {

    UdpEchoClientHelper echoClient(fogInterfaces.GetAddress(i % numFogNodes), port);

    echoClient.SetAttribute(“MaxPackets”, UintegerValue(100));

    echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

    echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

    ApplicationContainer clientApp = echoClient.Install(clients.Get(i));

    clientApp.Start(Seconds(2.0));

    clientApp.Stop(Seconds(simTime));

  }

  // Enable Flow Monitor

  FlowMonitorHelper flowmon;

  Ptr<FlowMonitor> monitor = flowmon.InstallAll();

  // Enable tracing

  wifiPhy.EnablePcap(“fog-computing-example”, apDevices.Get(0));

  pointToPoint.EnablePcapAll(“fog-computing-example”);

  // Run the simulation

  Simulator::Stop(Seconds(simTime));

  Simulator::Run();

 

  // Print flow monitor statistics

  monitor->SerializeToXmlFile(“fog-computing-flowmon.xml”, true, true);

  Simulator::Destroy();

  return 0;

}

Explanation of the Script

Below is the process for the fog computing using ns-3 environment:

  1. Include Necessary Headers:
    • Here we will include headers for ns-3 core, network, internet, point-to-point, WiFi, applications, mobility, and flow monitor modules.
  2. Set Simulation Parameters:
    • Define the simulation time and number of client, fog node, and cloud server nodes.
  3. Create Nodes:
    • Create nodes for clients, fog nodes, cloud servers, and a backbone router using NodeContainer.
  4. Set Up Wi-Fi Network:
    • Configure the Wi-Fi network for client nodes using WifiHelper, YansWifiChannelHelper, YansWifiPhyHelper, and WifiMacHelper.
  5. Set Up Point-to-Point Links:
    • Configure point-to-point links between fog nodes, cloud servers, and the backbone router using PointToPointHelper.
  6. Install Internet Stack:
    • Install the Internet stack on all nodes using InternetStackHelper.
  7. Assign IP Addresses:
    • Assign IP addresses to the devices using Ipv4AddressHelper.
  8. Set Up Mobility:
    • Define the positions and mobility models for the nodes using MobilityHelper.
  9. Create Applications:
    • Install UDP echo servers on each fog node and cloud server node.
    • Install UDP echo clients on each client node to request services from the fog nodes.
  10. Enable Flow Monitor:
    • Install and configure the Flow Monitor to collect and analyze network performance statistics.
  11. Enable Tracing:
    • Enable pcap tracing to capture packet traces for analysis.
  12. Run the Simulation:
    • Set the simulation stop time, run the simulation, print flow monitor statistics, and clean up using Simulator::Stop, Simulator::Run, and Simulator::Destroy.

Further Enhancements

Here the given below are the future work for the fog computing that are

  1. Dynamic Workload Management:
    • Implement dynamic workload distribution and scaling of resources based on demand.
  2. Advanced Mobility Models:
    • Implement more realistic mobility models for mobile clients accessing fog services.
  3. Quality of Service (QoS):
    • Implement QoS mechanisms to prioritize critical applications and ensure timely delivery.
  4. Network Performance Metrics:
    • Collect and analyze performance metrics such as throughput, latency, packet delivery ratio, and resource utilization.
  5. Interference Modeling:
    • Model interference and evaluate its impact on network performance, especially in densely deployed fog networks.
  6. Fault Tolerance and Resilience:
    • Implement and evaluate fault tolerance mechanisms and resilience strategies for fog services.

As we discussed earlier about how the fog computing will perform in ns-3 environment and we help to deliver further information about how the fog computing will get used to in diverse settings.