How to Create Fog Nodes with Heterogeneous Configurations in IFogSim?
Share
Condition for Create Fog Nodes with Heterogeneous Configurations in IFogSim
Description: Creating fog nodes with heterogeneous configurations involves setting up devices with varying resources to represent different layers of a fog computing environment. It starts with a cloud server, offering high processing power and resources, which serves as the parent device. Proxy servers act as intermediaries, balancing resources while introducing network latency. Departmental gateways are added to manage localized data processing, connected to higher-tier devices. Mobile devices like sensors and actuators are incorporated with lower processing power, simulating IoT devices. Each node is assigned specific resource configurations based on its role, ensuring an efficient and scalable fog network.
Sample Code
package fogsamples;
import org.cloudbus.cloudsim.core.CloudSim;
import org.fog.entities.*;
import org.fog.utils.FogUtils;
import org.fog.entities.FogBroker;
import org.fog.application.Application;
import org.fog.policy.AppModuleAllocationPolicy;
import org.fog.scheduler.StreamOperatorScheduler;
import org.fog.utils.FogLinearPowerModel;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.power.PowerHost;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
import org.cloudbus.cloudsim.sdn.overbooking.BwProvisionerOverbooking;
import org.cloudbus.cloudsim.sdn.overbooking.PeProvisionerOverbooking;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.fog.utils.distribution.DeterministicDistribution;
public class HeterogeneousFogNodes {
static List fogDevices = new ArrayList();
static List sensors = new ArrayList();
static List actuators = new ArrayList();
static boolean CLOUD = false;
static int numOfDepts = 4;
static int numOfMobilesPerDept = 6;
public static void main(String[] args) {
try {
Log.disable();
int num_user = 1;
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false;
CloudSim.init(num_user, calendar, trace_flag);
String appId = "IoTFog_Apps";
FogBroker broker = new FogBroker("broker");
Application application = createApplication(appId, broker.getId());
application.setUserId(broker.getId());
createFogDevices(broker.getId(), appId);
// Print out heterogeneous fog device details (excluding gateway devices)
printHeterogeneousFogDeviceDetails();
// Simulation will proceed after device creation
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error while creating fog devices: " + e.getMessage());
}
}
private static void createFogDevices(int userId, String appId) {
// Cloud device
FogDevice cloud = createFogDevice("cloud", 44800, 40000, 100, 10000, 0, 0.01, 16 * 103, 16 * 83.25);
cloud.setParentId(-1);
// Proxy device
FogDevice proxy = createFogDevice("proxy-server", 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333);
proxy.setParentId(cloud.getId());
proxy.setUplinkLatency(100);
fogDevices.add(cloud);
fogDevices.add(proxy);
// Create departments (gateway devices)
for (int i = 0; i < numOfDepts; i++) {
addGw(i + "", userId, appId, proxy.getId());
}
}
// Method to create a gateway (department) fog device
private static FogDevice addGw(String id, int userId, String appId, int parentId) {
// Create department gateway
FogDevice dept = createFogDevice("d-" + id, 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333);
fogDevices.add(dept);
dept.setParentId(parentId);
dept.setUplinkLatency(4);
// Create mobile devices (e.g., IoT devices)
for (int i = 0; i < numOfMobilesPerDept; i++) {
String mobileId = id + "-" + i;
FogDevice mobile = addMobile(mobileId, userId, appId, dept.getId());
mobile.setUplinkLatency(2);
fogDevices.add(mobile);
}
return dept;
}
// Method to create a mobile (sensor/actuator) device
private static FogDevice addMobile(String id, int userId, String appId, int parentId) {
FogDevice mobile = createFogDevice(id, 500, 512, 1000, 1000, 2, 0.0, 0.0, 0.0);
mobile.setParentId(parentId);
// Add sensors and actuators
Sensor sensor = new Sensor("s-" + id, "CAMERA", userId, appId, new DeterministicDistribution(5));
sensors.add(sensor);
Actuator actuator = new Actuator("ptz-" + id, userId, appId, "PTZ_CONTROL");
actuators.add(actuator);
sensor.setGatewayDeviceId(mobile.getId());
sensor.setLatency(1.0); // latency between sensor and mobile
actuator.setGatewayDeviceId(mobile.getId());
actuator.setLatency(1.0); // latency between actuator and mobile
return mobile;
}
// Method to create a fog device (both gateway and mobile)
private static FogDevice createFogDevice(String nodeName, long mips, int ram, long upBw, long downBw, int level,
double ratePerMips, double busyPower, double idlePower) {
List peList = new ArrayList();
peList.add(new Pe(0, new PeProvisionerOverbooking(mips)));
int hostId = FogUtils.generateEntityId();
long storage = 1000000;
int bw = 10000;
PowerHost host = new PowerHost(hostId,
new RamProvisionerSimple(ram),
new BwProvisionerOverbooking(bw),
storage, peList, new StreamOperatorScheduler(peList),
new FogLinearPowerModel(busyPower, idlePower));
List hostList = new ArrayList();
hostList.add(host);
String arch = "x86";
String os = "Linux";
String vmm = "Xen";
double time_zone = 10.0;
double cost = 3.0;
double costPerMem = 0.05;
double costPerStorage = 0.001;
double costPerBw = 0.0;
LinkedList storageList = new LinkedList();
FogDeviceCharacteristics characteristics = new FogDeviceCharacteristics(arch, os, vmm, host, time_zone, cost,
costPerMem, costPerStorage, costPerBw);
FogDevice fogdevice = null;
try {
fogdevice = new FogDevice(nodeName, characteristics,
new AppModuleAllocationPolicy(hostList), storageList, 10, upBw, downBw, 0, ratePerMips);
} catch (Exception e) {
e.printStackTrace();
}
fogdevice.setLevel(level);
return fogdevice;
}
// Method to print details of heterogeneous fog devices (excluding gateways)
private static void printHeterogeneousFogDeviceDetails() {
System.out.println("Heterogeneous Fog Devices Details (Excluding Gateways):");
for (FogDevice device : fogDevices) {
// Print only non-gateway (level > 1) devices
if (device.getLevel() > 1) {
System.out.println("Device Name: " + device.getName());
System.out.println("Device ID: " + device.getId());
System.out.println("Parent ID: " + device.getParentId());
System.out.println("Uplink Latency: " + device.getUplinkLatency());
System.out.println("Level: " + device.getLevel());
System.out.println("MIPS: " + device.getCharacteristics().getMips());
System.out.println("Storage: " + device.getCharacteristics().getCostPerStorage());
System.out.println("Bandwidth: " + device.getCharacteristics().getCostPerBw());
System.out.println("------------------------------------------------");
}
}
}
// Additional methods for creating application modules, sensors, and actuators can go here
private static Application createApplication(String appId, int userId) {
// Replace this with actual application creation logic
return new Application(appId, userId);
}
}