Description: Gateways in iFogSim are created to represent the edge devices that connect the fog network to the cloud, enabling data exchange between fog nodes and cloud resources. These gateways are typically located at the edge of the network and have sufficient computational capabilities to handle local data processing tasks while also forwarding data to the cloud when necessary. To create a gateway, an instance of the FogDevice class is typically instantiated with specific configurations, such as processing power, storage capacity, and communication bandwidth. These configurations define the gateway's performance and its ability to handle tasks. Gateways are assigned a unique identifier, and each fog device, including gateways, is connected to other devices via communication links, such as Wi-Fi or Ethernet. The gateway also acts as a resource manager for the local fog network, handling task scheduling, resource allocation, and monitoring for the devices within its range. Once created, the gateway interacts with the rest of the fog infrastructure, processing data locally and offloading tasks to the cloud based on predefined policies or workload conditions.
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.entities.Sensor;
import org.fog.entities.Actuator;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.LinkedList;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
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.fog.application.Application;
import org.fog.policy.AppModuleAllocationPolicy;
import org.fog.scheduler.StreamOperatorScheduler;
import org.fog.utils.FogLinearPowerModel;
public class IotFogApplication {
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);
printGatewayDeviceDetails();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error while creating fog devices: " + e.getMessage());
}
}
private static void createFogDevices(int userId, String appId) {
FogDevice cloud = createFogDevice("cloud", 44800, 40000, 100, 10000, 0, 0.01, 16 * 103, 16 * 83.25);
cloud.setParentId(-1);
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);
for (int i = 0; i < numOfDepts; i++) {
addGw(i + "", userId, appId, proxy.getId());
}
}
private static FogDevice addGw(String id, int userId, String appId, int parentId) {
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);
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;
}
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);
return 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)));
...
}