List of Topics:
Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Check Sensors with Different Tuple Emission Rate in IFogSim?

Sensors with Different Tuple Emission Rate in IFogSim

Condition for Sensors with Different Tuple Emission Rate in IFogSim

  • Description:
    In iFogSim, sensors with different tuple emission rates enable the simulation of diverse IoT applications where data generation patterns vary. The emission rate of a sensor determines how frequently it sends tuples, representing data to be processed. iFogSim allows customizing this rate using various probability distributions, such as deterministic, exponential, or uniform, which simulate real-world scenarios like periodic data updates, burst traffic, or irregular events. By associating each sensor with a unique emission rate and distribution, developers can model complex environments, including scenarios where multiple devices generate data at different frequencies. This flexibility ensures realistic simulation of latency, bandwidth, and computational load, essential for analyzing performance and resource allocation strategies in fog and edge computing systems.
Sample Code
  • Main.java:
    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */
    package rapid;
    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.Log;
    import org.cloudbus.cloudsim.Pe;
    import org.cloudbus.cloudsim.Storage;
    import org.cloudbus.cloudsim.core.CloudSim;
    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.AppEdge;
    import org.fog.application.AppLoop;
    import org.fog.application.Application;
    import org.fog.application.selectivity.FractionalSelectivity;
    import org.fog.entities.Actuator;
    import org.fog.entities.FogBroker;
    import org.fog.entities.FogDevice;
    import org.fog.entities.FogDeviceCharacteristics;
    import org.fog.entities.Sensor;
    import org.fog.entities.Tuple;
    import org.fog.placement.Controller;
    import org.fog.placement.ModuleMapping;
    import org.fog.placement.ModulePlacementEdgewards;
    import org.fog.placement.ModulePlacementMapping;
    import org.fog.placement.ModulePlacementOnlyCloud;
    import org.fog.policy.AppModuleAllocationPolicy;
    import org.fog.scheduler.StreamOperatorScheduler;
    import org.fog.utils.FogLinearPowerModel;
    import org.fog.utils.FogUtils;
    import org.fog.utils.TimeKeeper;
    import org.fog.utils.distribution.DeterministicDistribution;
    public class Main {

    static List fogDevices = new ArrayList();
    static List sensors = new ArrayList();
    static List actuators = new ArrayList();
    static int numOfFogColony;
    static int numOfFogCell;
    static int numOfNode_S;
    static int numOfNode_M;
    static int numOfWearable;
    static int numOfHealthCenter;

    private static boolean CLOUD = true;

    public Main(int fogclny, int fogcl, int fognod, int wear, int hcenter) {
    setFogColony(fogclny);
    setFogCell(fogcl);
    setFogNodeStatic(fognod / 2);
    setFogNodeMobile(fognod / 2);
    setWearable(wear);
    setActuator(hcenter);
    }

    public void process() {
    Log.printLine("RAPID Starting of IABO...");

    try {
    Log.disable();
    int num_user = 1; // number of cloud users
    Calendar calendar = Calendar.getInstance();
    boolean trace_flag = false; // mean trace events

    CloudSim.init(num_user, calendar, trace_flag);

    String appId = "rapid"; // identifier of the application

    FogBroker broker = new FogBroker("broker");

    Application application = createApplication1(appId, broker.getId());

    application.setUserId(broker.getId());

    createFogDevices(broker.getId(), appId);

    RapidController rapidcontroller = null;

    ModuleMapping moduleMapping = ModuleMapping.createModuleMapping(); // initializing a module mapping

    for (FogDevice device : fogDevices) {

    if (device.getName().startsWith("fm")) {
    moduleMapping.addModuleToDevice("health_data_receiver", device.getName());
    moduleMapping.addModuleToDevice("report_analyser", device.getName());
    moduleMapping.addModuleToDevice("nomad_tracker", device.getName());
    } else if (device.getName().startsWith("hlth-care")) {
    moduleMapping.addModuleToDevice("health_caretaker", device.getName());
    } else if (device.getName().startsWith("ns") || device.getName().startsWith("nm")) { // names of all Nodes Static and Mobile start with 'ns' and 'nm'
    moduleMapping.addModuleToDevice("healthcare_analyser", device.getName()); // fixing 1 instance of the health_analyser module to each nodes
    } else if (device.getName().startsWith("fc")) {
    moduleMapping.addModuleToDevice("request_receiver", device.getName());
    // moduleMapping.addModuleToDevice("patient_locator_dw", device.getName());
    // moduleMapping.addModuleToDevice("patient_locator_uw", device.getName());
    // moduleMapping.addModuleToDevice("health_locator", device.getName());
    } else if (device.getName().startsWith("iot-gateway")) {
    moduleMapping.addModuleToDevice("stream_receiver", device.getName());
    //moduleMapping.addModuleToDevice("patient_tracker_dw", device.getName());
    //moduleMapping.addModuleToDevice("patient_tracker_uw", device.getName());
    moduleMapping.addModuleToDevice("alert_center", device.getName());
    } else if (device.getName().startsWith("isp-GW")) {
    moduleMapping.addModuleToDevice("isp_transport", device.getName());
    }
    }
    if (CLOUD) {
    // if the mode of deployment is cloud-based
    moduleMapping.addModuleToDevice("patient_tracker_dw", "cloud");
    moduleMapping.addModuleToDevice("patient_tracker_uw", "cloud");
    moduleMapping.addModuleToDevice("healthcare_analyser", "cloud"); // placing all instances of Object Detector module in the Cloud
    }
    rapidcontroller = new RapidController("master-controller", fogDevices, sensors,
    actuators);
    rapidcontroller.submitApplication(application,
    (CLOUD) ? (new ModulePlacementMapping(fogDevices, application, moduleMapping))
    : (new RapidModulePlacement(fogDevices, sensors, actuators, application, moduleMapping)));
    TimeKeeper.getInstance().setSimulationStartTime(Calendar.getInstance().getTimeInMillis());

    CloudSim.startSimulation();

    CloudSim.stopSimulation();

    Log.printLine("Rapid-IABO finished!");
    } catch (Exception e) {
    e.printStackTrace();
    Log.printLine("Unwanted errors happen");
    }
    }

    /**
    * Function to create the Health care wearable application in the DDF model.
    *
    * @param appId unique identifier of the application
    * @param userId identifier of the user of the application
    * @return Application model
    */
    @SuppressWarnings({"serial"})
    private Application createApplication1(String appId, int userId) {

    Application application1 = Application.createApplication(appId, userId);
    /*
    * Adding modules (vertices) to the application model (directed graph)
    */
    application1.addAppModule("stream_receiver", 100); // iot
    application1.addAppModule("health_data_receiver", 100); //fm
    application1.addAppModule("isp_transport", 100); //isp

    application1.addAppModule("health_caretaker", 100); //hct

    application1.addAppModule("request_receiver", 100);//fogcl

    application1.addAppModule("healthcare_analyser", 100); //fn,cl

    application1.addAppModule("report_analyser", 100); //fm
    application1.addAppModule("patient_tracker_dw", 100); //iot

    application1.addAppModule("patient_tracker_uw", 100); //iot
    application1.addAppModule("nomad_tracker", 100); //fm

    application1.addAppModule("alert_center", 100); //iot

    /*
    * Defining the input-output relationships (represented by selectivity) of the application modules.
    */
    application1.addTupleMapping("stream_receiver", "WEARABLE", "STREAM_DATA", new FractionalSelectivity(1.0));

    application1.addTupleMapping("health_data_receiver", "STREAM_DATA", "HEALTH_SENSED_DATA", new FractionalSelectivity(0.5));
    application1.addTupleMapping("health_data_receiver", "STREAM_DATA", "DATA_REQUEST", new FractionalSelectivity(0.5));

    application1.addTupleMapping("request_receiver", "HEALTH_SENSED_DATA", "HEALTH_SENSED_DATA", new FractionalSelectivity(1.0));

    application1.addTupleMapping("healthcare_analyser", "HEALTH_SENSED_DATA", "HEALTH_REPORT", new FractionalSelectivity(1.0));
    application1.addTupleMapping("isp_transport", "DATA_REQUEST", "SEND_REQUEST", new FractionalSelectivity(1.0));
    application1.addTupleMapping("health_caretaker", "SEND_REQUEST", "REPLY_DATA", new FractionalSelectivity(1.0));
    application1.addTupleMapping("isp_transport", "REPLY_DATA", "UNIVERSAL_DATA", new FractionalSelectivity(1.0));
    application1.addTupleMapping("report_analyser", "UNIVERSAL_DATA", "PATIENT_REPORT", new FractionalSelectivity(0.5));

    application1.addTupleMapping("report_analyser", "HEALTH_REPORT", "PATIENT_REPORT", new FractionalSelectivity(0.5));

    application1.addTupleMapping("patient_tracker_dw", "PATIENT_REPORT", "PATIENT_PRESENCE", new FractionalSelectivity(1.0));
    application1.addTupleMapping("patient_tracker_uw", "PATIENT_PRESENCE", "PATIENT_REACH", new FractionalSelectivity(1.0));
    application1.addTupleMapping("nomad_tracker", "PATIENT_REACH", "PATIENT_STATUS", new FractionalSelectivity(0.5));
    application1.addTupleMapping("alert_center", "PATIENT_STATUS", "PATIENT_HEALTH_LOCATION", new FractionalSelectivity(1.0));


    /*
    * Connecting the application modules (vertices) in the application model (directed graph) with edges
    */
    //sensor from wearable
    application1.addAppEdge("WEARABLE", "stream_receiver", 1000, 2000, "WEARABLE", Tuple.UP, AppEdge.SENSOR);
    //from iot-gateway
    application1.addAppEdge("stream_receiver", "health_data_receiver", 100, 20000, "STREAM_DATA", Tuple.UP, AppEdge.MODULE);

    //from fm to fog node and cloud
    application1.addAppEdge("health_data_receiver", "request_receiver", 1000, 20000, "HEALTH_SENSED_DATA", Tuple.DOWN, AppEdge.MODULE); // DOWN to fog nodes

    application1.addAppEdge("request_receiver", "healthcare_analyser", 1000, 20000, "HEALTH_SENSED_DATA", Tuple.DOWN, AppEdge.MODULE); // DOWN to fog nodes

    //fm to isp
    application1.addAppEdge("health_data_receiver", "isp_transport", 100, 20000, "DATA_REQUEST", Tuple.UP, AppEdge.MODULE);
    //isp to hct
    application1.addAppEdge("isp_transport", "health_caretaker", 100, 20000, "SEND_REQUEST", Tuple.DOWN, AppEdge.MODULE); // down
    //hct to isp
    application1.addAppEdge("health_caretaker", "isp_transport", 1000, 20000, "REPLY_DATA", Tuple.UP, AppEdge.MODULE); // up
    //isp to fm
    application1.addAppEdge("isp_transport", "report_analyser", 1000, 20000, "UNIVERSAL_DATA", Tuple.DOWN, AppEdge.MODULE); //
    // fm to fm
    //from fog node and cloud to fm
    application1.addAppEdge("healthcare_analyser", "report_analyser", 500, 20000, "HEALTH_REPORT", Tuple.UP, AppEdge.MODULE); // UP from fog node.
    }
    }
    // fm to fc
    application1.addAppEdge("report_analyser", "patient_tracker_dw", 1000, 1000, "PATIENT_REPORT", Tuple.DOWN, AppEdge.MODULE); //
    // patient identification fc to iot
    application1.addAppEdge("patient_tracker_dw", "patient_tracker_uw", 1000, 1000, "PATIENT_PRESENCE", Tuple.UP, AppEdge.MODULE); //
    // iot to fc
    application1.addAppEdge("patient_tracker_uw", "nomad_tracker", 1000, 1000, "PATIENT_REACH", Tuple.UP, AppEdge.MODULE); //
    // fm to fc
    application1.addAppEdge("nomad_tracker", "alert_center", 1000, 1000, "PATIENT_STATUS", Tuple.DOWN, AppEdge.MODULE); //
    // fc to iot
    // iot to actuator
    application1.addAppEdge("alert_center", "HEALTHCENTER", 1000, 500, "PATIENT_HEALTH_LOCATION", Tuple.DOWN, AppEdge.ACTUATOR);
    /*
    * Defining application loops (maybe incomplete loops) to monitor the latency of.
    * Here, we add two loops for monitoring : Motion Detector -> Object Detector -> Object Tracker and Object Tracker -> PTZ Control
    */
    final AppLoop loop1 = new AppLoop(new ArrayList() {
    {
    add("WEARABLE");
    add("stream_receiver");
    add("health_data_receiver");
    add("isp_transport");
    add("health_caretaker");
    add("isp_transport");
    add("report_analyser");
    }
    });
    final AppLoop loop2 = new AppLoop(new ArrayList() {
    {
    add("health_data_receiver");
    add("request_receiver");
    add("healthcare_analyser");
    add("report_analyser");
    add("patient_tracker_dw");
    add("patient_tracker_uw");
    add("nomad_tracker");
    add("alert_center");
    }
    });
    final AppLoop loop3 = new AppLoop(new ArrayList() {
    {
    add("alert_center");
    add("HEALTHCENTER");
    }
    });
    List loops = new ArrayList() {
    {
    add(loop1);
    add(loop2);
    add(loop3);
    }
    };
    application1.setLoops(loops);
    return application1;
    /**
    * Creates a vanilla fog device
    *
    * @param nodeName name of the device to be used in simulation
    * @param mips MIPS
    * @param ram RAM
    * @param upBw uplink bandwidth
    * @param downBw downlink bandwidth
    * @param level hierarchy level of the device
    * @param ratePerMips cost rate per MIPS used
    * @param busyPower
    * @param idlePower
    * @return
    */
    private FogDevice createFogDevice(String nodeName, long mips,
    int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
    List peList = new ArrayList();
    // 3. Create PEs and add these into a list.
    peList.add(new Pe(0, new PeProvisionerOverbooking(mips))); // need to store Pe id and MIPS Rating
    int hostId = FogUtils.generateEntityId();
    long storage = 1000000; // host storage
    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"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this resource
    double costPerMem = 0.05; // the cost of using memory in this resource
    double costPerStorage = 0.001; // the cost of using storage in this
    // resource
    double costPerBw = 0.0; // the cost of using bw in this resource
    LinkedList storageList = new LinkedList(); // we are not adding SAN
    // devices by now
    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;
    }
    private FogManager createFogManager(String nodeName, long mips,
    int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
    List peList = new ArrayList();
    // 3. Create PEs and add these into a list.
    peList.add(new Pe(0, new PeProvisionerOverbooking(mips))); // need to store Pe id and MIPS Rating
    int hostId = FogUtils.generateEntityId();
    long storage = 1000000; // host storage
    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"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this resource
    double costPerMem = 0.05; // the cost of using memory in this resource
    double costPerStorage = 0.001; // the cost of using storage in this
    // resource
    double costPerBw = 0.0; // the cost of using bw in this resource
    LinkedList storageList = new LinkedList(); // we are not adding SAN
    // devices by now
    FogDeviceCharacteristics characteristics = new FogDeviceCharacteristics(
    arch, os, vmm, host, time_zone, cost, costPerMem,
    costPerStorage, costPerBw);
    FogManager fogdevice = null;
    try {
    fogdevice = new FogManager(nodeName, characteristics,
    new AppModuleAllocationPolicy(hostList), storageList, 10, upBw, downBw, 0, ratePerMips);
    } catch (Exception e) {
    e.printStackTrace();
    }
    fogdevice.setLevel(level);
    return fogdevice;
    }
    private FogCell createFogCell(String nodeName, long mips,
    int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
    List peList = new ArrayList();
    // 3. Create PEs and add these into a list.
    peList.add(new Pe(0, new PeProvisionerOverbooking(mips))); // need to store Pe id and MIPS Rating
    int hostId = FogUtils.generateEntityId();
    long storage = 1000000; // host storage
    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"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this resource
    double costPerMem = 0.05; // the cost of using memory in this resource
    double costPerStorage = 0.001; // the cost of using storage in this
    // resource
    double costPerBw = 0.0; // the cost of using bw in this resource
    LinkedList storageList = new LinkedList(); // we are not adding SAN
    // devices by now
    FogDeviceCharacteristics characteristics = new FogDeviceCharacteristics(
    arch, os, vmm, host, time_zone, cost, costPerMem,
    costPerStorage, costPerBw);
    FogCell fogdevice = null;
    try {
    fogdevice = new FogCell(nodeName, characteristics,
    new AppModuleAllocationPolicy(hostList), storageList, 10, upBw, downBw, 0, ratePerMips);
    } catch (Exception e) {
    e.printStackTrace();
    }
    fogdevice.setLevel(level);
    return fogdevice;
    }
    private FogNodeS createFogNodes(String nodeName, long mips,
    int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
    List peList = new ArrayList();
    // 3. Create PEs and add these into a list.
    peList.add(new Pe(0, new PeProvisionerOverbooking(mips))); // need to store Pe id and MIPS Rating
    int hostId = FogUtils.generateEntityId();
    long storage = 1000000; // host storage
    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"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this resource
    double costPerMem = 0.05; // the cost of using memory in this resource
    double costPerStorage = 0.001; // the cost of using storage in this
    // resource
    double costPerBw = 0.0; // the cost of using bw in this resource
    LinkedList storageList = new LinkedList(); // we are not adding SAN
    // devices by now
    FogDeviceCharacteristics characteristics = new FogDeviceCharacteristics(
    arch, os, vmm, host, time_zone, cost, costPerMem,
    costPerStorage, costPerBw);
    FogNodeS fogdevice = null;
    try {
    fogdevice = new FogNodeS(nodeName, characteristics,
    new AppModuleAllocationPolicy(hostList), storageList, 10, upBw, downBw, 0, ratePerMips);
    } catch (Exception e) {
    e.printStackTrace();
    }
    fogdevice.setLevel(level);
    return fogdevice;
    }
    /**
    * Creates the fog devices in the physical topology of the simulation.
    *
    * @param userId
    * @param appId
    */
    private 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);
    fogDevices.add(cloud);
    FogDevice gateway = createFogDevice("isp-GW", 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333);
    gateway.setParentId(cloud.getId());
    gateway.setUplinkLatency(100); // latency of connection between proxy server and cloud is 100 ms
    fogDevices.add(gateway);
    FogDevice careTaker = createFogDevice("hlth-care", 2800, 4000, 100, 10000, 2, 0.0, 107.339, 83.43333);
    careTaker.setParentId(gateway.getId());
    careTaker.setUplinkLatency(15);
    fogDevices.add(careTaker);
    for (int i = 0; i < getFogColony(); i++) {
    addFogColony(i + "", userId, appId, gateway.getId());
    }
    }
    private FogManager addFogColony(String id, int userId, String appId, int parentId) {
    FogManager fogManager = createFogManager("fm-" + id, 22400, 32000, 10000, 10000, 2, 0.0, 107.339 * 10, 83.4333 * 10);
    fogDevices.add(fogManager);
    fogManager.setUplinkLatency(2); // latency of connection between router and proxy server is 2 ms
    List listofcells = new ArrayList();
    for (int i = 0; i < getFogCell(); i++) {
    String fogcellId = id + "-" + i;
    FogCell fogcell = addFogCell(fogcellId, userId, appId, fogManager.getId());
    listofcells.add(new Cells(fogcell.getName(), fogcell));
    }
    fogManager.setFogCells(listofcells);
    fogManager.setParentId(parentId);
    return fogManager;
    }
    private FogCell addFogCell(String id, int userId, String appId, int parentId) {
    FogCell fogCell = createFogCell("fc-" + id, 22400, 32000, 10000, 10000, 3, 0.0, 107.339 * 10, 83.4333 * 10);
    fogDevices.add(fogCell);
    fogCell.setUplinkLatency(2); // latency of connection between fog Cell and Fog Manager is 2 ms
    List nodeSlist = new ArrayList();
    for (int i = 0; i < getFogNodeStatic(); i++) {
    String nodeSId = id + "-" + i;
    FogDevice nodeS = addNodeStatic(nodeSId, userId, appId, fogCell.getId());
    nodeSlist.add(new Nodes(nodeS.getName(), nodeS));
    }
    fogCell.setStaticNodes(nodeSlist);
    List nodeMlist = new ArrayList();
    for (int i = 0; i < getFogNodeMobile(); i++) {
    String nodeMId = id + "-" + i;
    FogDevice nodeM = addNodeMobile(nodeMId, userId, appId, fogCell.getId());
    nodeMlist.add(new Nodes(nodeM.getName(), nodeM));
    }
    fogCell.setMobileNodes(nodeMlist);
    FogDevice iotDevice = addIotDevice(id, userId, appId, fogCell.getId());
    fogCell.setIotDevice(new Nodes(iotDevice.getName(), iotDevice));
    fogCell.setParentId(parentId);
    return fogCell;
    }
    private FogDevice addNodeStatic(String id, int userId, String appId, int parentId) {
    FogDevice nodes = createFogDevice("ns-" + id, 11200, 16000, 10000, 10000, 4, 0.0, 107.339, 83.4333);
    fogDevices.add(nodes);
    nodes.setUplinkLatency(2); // latency of connection between fog Cell and Fog Nodes is 2 ms
    nodes.setParentId(parentId);
    return nodes;
    }
    private FogDevice addNodeMobile(String id, int userId, String appId, int parentId) {
    FogDevice nodem = createFogDevice("nm-" + id, 11200, 16000, 10000, 10000, 4, 0.0, 107.339, 83.4333);
    fogDevices.add(nodem);
    nodem.setUplinkLatency(2); // latency of connection between fog Cell and Fog Nodes is 2 ms
    nodem.setParentId(parentId);
    return nodem;
    }
    private FogDevice addIotDevice(String id, int userId, String appId, int parentId) {
    FogDevice iotGateway = createFogDevice("iot-gateway" + id, 28000, 40000, 10000, 10000, 4, 0.0, 87.53, 82.44);
    // FogDevice iotGateway = createFogDevice("iot-gateway" + id, 500, 1000, 10000, 10000, 4, 0.0, 87.53, 82.44);
    fogDevices.add(iotGateway);
    iotGateway.setUplinkLatency(2);
    for (int i = 0; i < getWearable(); i++) {
    Sensor wearable = new Sensor("w-" + id + "-" + i, "WEARABLE", userId, appId, new DeterministicDistribution(5)); // inter-transmission time of wearable (sensor) follows a deterministic distribution
    sensors.add(wearable);
    wearable.setGatewayDeviceId(iotGateway.getId());
    wearable.setLatency(1.0); // latency of connection between wearable (sensor) and the parent iotGateway is 1 ms
    }
    for (int j = 0; j < getActuator(); j++) {
    Actuator healthcenter = new Actuator("hc-" + id + "-" + j, userId, appId, "HEALTHCENTER");
    actuators.add(healthcenter);
    healthcenter.setGatewayDeviceId(iotGateway.getId());
    healthcenter.setLatency(1.0); // latency of connection between healthcenter and the parent iotGateway is 1 ms
    }
    iotGateway.setParentId(parentId);
    return iotGateway;
    }
    public static void setFogColony(int fcolony) {
    numOfFogColony = fcolony;
    }
    public static void setFogCell(int fcell) {
    numOfFogCell = fcell;
    }
    public static void setFogNodeStatic(int fnodes) {
    numOfNode_S = fnodes;
    }
    public static void setFogNodeMobile(int fnodem) {
    numOfNode_M = fnodem;
    }
    public static void setWearable(int wearable) {
    numOfWearable = wearable;
    }
    public static void setActuator(int actuator) {
    numOfHealthCenter = actuator;
    }
    public static int getFogColony() {
    return numOfFogColony;
    }
    public static int getFogCell() {
    return numOfFogCell;
    }
    public static int getFogNodeStatic() {
    return numOfNode_S;
    }
    public static int getFogNodeMobile() {
    return numOfNode_M;
    }
    public static int getWearable() {
    return numOfWearable;
    }
    public static int getActuator() {
    return numOfHealthCenter;
    }
    }
  • Sensor.java:
    package org.fog.entities;
    import java.util.ArrayList;
    import org.cloudbus.cloudsim.UtilizationModelFull;
    import org.cloudbus.cloudsim.core.CloudSim;
    import org.cloudbus.cloudsim.core.SimEntity;
    import org.cloudbus.cloudsim.core.SimEvent;
    import org.fog.application.AppEdge;
    import org.fog.application.AppLoop;
    import org.fog.application.Application;
    import org.fog.utils.FogEvents;
    import org.fog.utils.FogUtils;
    import org.fog.utils.GeoLocation;
    import org.fog.utils.Logger;
    import org.fog.utils.TimeKeeper;
    import org.fog.utils.distribution.Distribution;
    public class Sensor extends SimEntity {
    private int gatewayDeviceId;
    private GeoLocation geoLocation;
    private long outputSize;
    private String appId;
    private int userId;
    private String tupleType;
    private String sensorName;
    private String destModuleName;
    private Distribution transmitDistribution;
    private int controllerId;
    private Application app;
    private double latency;
    public Sensor(String name, int userId, String appId, int gatewayDeviceId, double latency, GeoLocation geoLocation,
    Distribution transmitDistribution, int cpuLength, int nwLength, String tupleType, String destModuleName) {
    super(name);
    this.setAppId(appId);
    this.gatewayDeviceId = gatewayDeviceId;
    this.geoLocation = geoLocation;
    this.outputSize = 3;
    this.setTransmitDistribution(transmitDistribution);
    setUserId(userId);
    setDestModuleName(destModuleName);
    setTupleType(tupleType);
    setSensorName(sensorName);
    setLatency(latency);
    }
    public Sensor(String name, int userId, String appId, int gatewayDeviceId, double latency, GeoLocation geoLocation,
    Distribution transmitDistribution, String tupleType) {
    super(name);
    this.setAppId(appId);
    this.gatewayDeviceId = gatewayDeviceId;
    this.geoLocation = geoLocation;
    this.outputSize = 3;
    this.setTransmitDistribution(transmitDistribution);
    setUserId(userId);
    setTupleType(tupleType);
    setSensorName(sensorName);
    setLatency(latency);
    }
    /**
    * This constructor is called from the code that generates PhysicalTopology
    * from JSON
    *
    * @param name
    * @param tupleType
    * @param string
    * @param userId
    * @param appId
    * @param transmitDistribution
    */
    public Sensor(String name, String tupleType, int userId, String appId, Distribution transmitDistribution) {
    super(name);
    this.setAppId(appId);
    this.setTransmitDistribution(transmitDistribution);
    setTupleType(tupleType);
    setSensorName(tupleType);
    setUserId(userId);
    }
    public void transmit() {
    AppEdge _edge = null;
    for (AppEdge edge : getApp().getEdges()) {
    if (edge.getSource().equals(getTupleType())) {
    _edge = edge;
    }
    }
    long cpuLength = (long) _edge.getTupleCpuLength();
    long nwLength = (long) _edge.getTupleNwLength();
    Tuple tuple = new Tuple(getAppId(), FogUtils.generateTupleId(), Tuple.UP, cpuLength, 1, nwLength, outputSize,
    new UtilizationModelFull(), new UtilizationModelFull(), new UtilizationModelFull());
    tuple.setUserId(getUserId());
    tuple.setTupleType(getTupleType());
    tuple.setDestModuleName(_edge.getDestination());
    tuple.setSrcModuleName(getSensorName());
    Logger.debug(getName(), "Sending tuple with tupleId " + tuple.getCloudletId());
    int actualTupleId = updateTimings(getSensorName(), tuple.getDestModuleName());
    System.out.println();
    System.out.print("Sensor(transmit): tuple id #" + tuple.getCloudletId() + ", actual id #" + actualTupleId);
    System.out.println(", src :" + getSensorName() + ", dest :" + _edge.getDestination() + ", tuple type :" + getTupleType());
    tuple.setActualTupleId(actualTupleId);
    tuple.setGatewayDeviceId(getGatewayDeviceId());
    send(gatewayDeviceId, getLatency(), FogEvents.TUPLE_ARRIVAL, tuple);
    }
    private int updateTimings(String src, String dest) {
    Application application = getApp();
    for (AppLoop loop : application.getLoops()) {
    if (loop.hasEdge(src, dest)) {
    int tupleId = TimeKeeper.getInstance().getUniqueId();
    // System.out.println("fogdevice " + String.format("%.2f", CloudSim.clock()) + " actual tuple id #" + tupleId);
    if (!TimeKeeper.getInstance().getLoopIdToTupleIds().containsKey(loop.getLoopId())) {
    TimeKeeper.getInstance().getLoopIdToTupleIds().put(loop.getLoopId(), new ArrayList());
    }
    TimeKeeper.getInstance().getLoopIdToTupleIds().get(loop.getLoopId()).add(tupleId);
    TimeKeeper.getInstance().getEmitTimes().put(tupleId, CloudSim.clock());
    System.out.println("emit time :" + String.format("%.2f", CloudSim.clock()) + " apploop id " + loop.getLoopId() + " tuple id #" + tupleId);
    return tupleId;
    }
    }
    return -1;
    }
    }
    @Override
    public void startEntity() {
    send(gatewayDeviceId, CloudSim.getMinTimeBetweenEvents(), FogEvents.SENSOR_JOINED, geoLocation);
    send(getId(), getTransmitDistribution().getNextValue(), FogEvents.EMIT_TUPLE);
    }
    @Override
    public void processEvent(SimEvent ev) {
    switch (ev.getTag()) {
    case FogEvents.TUPLE_ACK:
    //transmit(transmitDistribution.getNextValue());
    break;
    case FogEvents.EMIT_TUPLE:
    System.out.println("Sensor Transmit starts ...");
    transmit();
    send(getId(), getTransmitDistribution().getNextValue(), FogEvents.EMIT_TUPLE);
    break;
    }
    }
    @Override
    public void shutdownEntity() {
    }
    public int getGatewayDeviceId() {
    return gatewayDeviceId;
    }
    public void setGatewayDeviceId(int gatewayDeviceId) {
    this.gatewayDeviceId = gatewayDeviceId;
    }
    public GeoLocation getGeoLocation() {
    return geoLocation;
    }
    public void setGeoLocation(GeoLocation geoLocation) {
    this.geoLocation = geoLocation;
    }
    public int getUserId() {
    return userId;
    }
    public void setUserId(int userId) {
    this.userId = userId;
    }
    public String getTupleType() {
    return tupleType;
    }
    public void setTupleType(String tupleType) {
    this.tupleType = tupleType;
    }
    public String getSensorName() {
    return sensorName;
    }
    public void setSensorName(String sensorName) {
    this.sensorName = sensorName;
    }
    public String getAppId() {
    return appId;
    }
    public void setAppId(String appId) {
    this.appId = appId;
    }
    public String getDestModuleName() {
    return destModuleName;
    }
    public void setDestModuleName(String destModuleName) {
    this.destModuleName = destModuleName;
    }
    public Distribution getTransmitDistribution() {
    return transmitDistribution;
    }
    public void setTransmitDistribution(Distribution transmitDistribution) {
    this.transmitDistribution = transmitDistribution;
    }
    public int getControllerId() {
    return controllerId;
    }
    public void setControllerId(int controllerId) {
    this.controllerId = controllerId;
    }
    public Application getApp() {
    return app;
    }
    public void setApp(Application app) {
    this.app = app;
    }
    public Double getLatency() {
    return latency;
    }
    public void setLatency(Double latency) {
    this.latency = latency;
    }
ScreenShots
  • Sensor With Emission1
  • Sensor With Emission2
  • Sensor With Emission3