init
This commit is contained in:
203
src/org/fog/test/perfeval/Birbnetes.java
Normal file
203
src/org/fog/test/perfeval/Birbnetes.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package org.fog.test.perfeval;
|
||||
|
||||
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.*;
|
||||
import org.fog.placement.Controller;
|
||||
import org.fog.placement.ModuleMapping;
|
||||
import org.fog.placement.ModulePlacementEdgewards;
|
||||
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;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Birbnetes {
|
||||
static int numOfFogDevices = 2;
|
||||
static int numOfClientsPerFogDevice = 10;
|
||||
static List<FogDevice> fogDevices = new ArrayList<>();
|
||||
static Map<String, Integer> getIdByName = new HashMap<>();
|
||||
static List<Sensor> sensors = new ArrayList<>();
|
||||
static List<Actuator> actuators = new ArrayList<>();
|
||||
|
||||
private static FogDevice createAFogDevice(String nodeName, long mips,
|
||||
int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
|
||||
List<Pe> 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<Host> 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<Storage> 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();
|
||||
}
|
||||
assert fogdevice != null;
|
||||
fogdevice.setLevel(level);
|
||||
return fogdevice;
|
||||
}
|
||||
|
||||
private static Application createApplication(String appId, int brokerId) {
|
||||
Application application = Application.createApplication(appId, brokerId);
|
||||
application.addAppModule("ClientModule", 10);
|
||||
application.addAppModule("MainModule", 120);
|
||||
application.addAppModule("StorageModule", 120);
|
||||
|
||||
application.addAppEdge("Sensor", "ClientModule", 50, 8800,
|
||||
"Sensor", Tuple.UP, AppEdge.SENSOR);
|
||||
application.addAppEdge("ClientModule", "MainModule", 100,
|
||||
1000, "PreProcessedData", Tuple.UP, AppEdge.MODULE);
|
||||
application.addAppEdge("ClientModule", "StorageModule", 10,
|
||||
8800, "StoreData", Tuple.UP, AppEdge.MODULE);
|
||||
application.addAppEdge("MainModule", "ClientModule", 200,
|
||||
1000, "ProcessedData", Tuple.DOWN, AppEdge.MODULE);
|
||||
application.addAppEdge("ClientModule", "Actuators", 50, 1000,
|
||||
"OutputData", Tuple.DOWN, AppEdge.ACTUATOR);
|
||||
|
||||
application.addTupleMapping("ClientModule", "Sensor", "PreProcessedData", new FractionalSelectivity(1.0));
|
||||
application.addTupleMapping("ClientModule", "Sensor", "StoreData", new FractionalSelectivity(1.0));
|
||||
application.addTupleMapping("MainModule", "PreProcessedData",
|
||||
"ProcessedData", new FractionalSelectivity(1.0));
|
||||
application.addTupleMapping("ClientModule", "ProcessedData",
|
||||
"OutputData", new FractionalSelectivity(1.0));
|
||||
|
||||
final AppLoop loop1 = new AppLoop(new ArrayList<>() {{
|
||||
add("Sensor");
|
||||
add("ClientModule");
|
||||
add("StorageModule");
|
||||
add("MainModule");
|
||||
add("ClientModule");
|
||||
add("Actuator");
|
||||
}});
|
||||
List<AppLoop> loops = new ArrayList<>() {{
|
||||
add(loop1);
|
||||
}};
|
||||
application.setLoops(loops);
|
||||
return application;
|
||||
}
|
||||
|
||||
private static FogDevice addLowLevelFogDevice(String id, int brokerId, String appId, int parentId) {
|
||||
FogDevice lowLevelFogDevice = createAFogDevice("LowLevelFogDevice-" + id, 1000, 1000, 10000, 270, 2, 0, 87.53, 82.44);
|
||||
lowLevelFogDevice.setParentId(parentId);
|
||||
getIdByName.put(lowLevelFogDevice.getName(), lowLevelFogDevice.getId());
|
||||
Sensor sensor = new Sensor("s-" + id, "Sensor", brokerId, appId, new DeterministicDistribution(getValue(5.00)));
|
||||
sensors.add(sensor);
|
||||
Actuator actuator = new Actuator("a-" + id, brokerId, appId,
|
||||
"OutputData");
|
||||
actuators.add(actuator);
|
||||
sensor.setGatewayDeviceId(lowLevelFogDevice.getId());
|
||||
sensor.setLatency(6.0);
|
||||
actuator.setGatewayDeviceId(lowLevelFogDevice.getId());
|
||||
actuator.setLatency(1.0);
|
||||
return lowLevelFogDevice;
|
||||
}
|
||||
|
||||
private static double getValue(double min) {
|
||||
Random rn = new Random();
|
||||
return rn.nextDouble() * 10 + min;
|
||||
}
|
||||
|
||||
private static void createFogDevices(int brokerId, String appId) {
|
||||
FogDevice cloud = createAFogDevice("cloud", 44800, 64000, 10000,
|
||||
10000, 0, 0.01, 16 * 103, 16 * 83.25);
|
||||
cloud.setParentId(-1);
|
||||
fogDevices.add(cloud);
|
||||
getIdByName.put(cloud.getName(), cloud.getId());
|
||||
for (int i = 0; i < numOfFogDevices; i++) {
|
||||
FogDevice device = createAFogDevice("FogDevice-" + i, 4000, 4000,
|
||||
1000, 1000, 1, 0.01,
|
||||
100, 70);
|
||||
device.setParentId(cloud.getId());
|
||||
device.setUplinkLatency(20);
|
||||
for (int j = 0; j < numOfClientsPerFogDevice; j++) {
|
||||
String clientId = i + "-" + j;
|
||||
FogDevice client = addLowLevelFogDevice(clientId, brokerId, appId, device.getId());
|
||||
client.setUplinkLatency(3);
|
||||
fogDevices.add(client);
|
||||
}
|
||||
fogDevices.add(device);
|
||||
getIdByName.put(device.getName(), device.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Log.printLine("Starting Birbnetes...");
|
||||
|
||||
try {
|
||||
Log.disable();
|
||||
int num_user = 1; // number of cloud users
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
CloudSim.init(num_user, calendar, false);
|
||||
|
||||
String appId = "birbnetes"; // identifier of the application
|
||||
|
||||
FogBroker broker = new FogBroker("broker");
|
||||
|
||||
Application application = createApplication(appId, broker.getId());
|
||||
application.setUserId(broker.getId());
|
||||
|
||||
createFogDevices(broker.getId(), appId);
|
||||
|
||||
ModuleMapping moduleMapping = ModuleMapping.createModuleMapping(); // initializing a module mapping
|
||||
|
||||
moduleMapping.addModuleToDevice("MainModule", "cloud");
|
||||
moduleMapping.addModuleToDevice("StorageModule", "cloud");
|
||||
for (FogDevice device : fogDevices) {
|
||||
if (device.getName().startsWith("FogDevice")) {
|
||||
moduleMapping.addModuleToDevice("ClientModule", device.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Controller controller = new Controller("master-controller", fogDevices, sensors,
|
||||
actuators);
|
||||
|
||||
controller.submitApplication(application, 0,
|
||||
new ModulePlacementEdgewards(fogDevices, sensors, actuators, application, moduleMapping));
|
||||
|
||||
TimeKeeper.getInstance().setSimulationStartTime(Calendar.getInstance().getTimeInMillis());
|
||||
|
||||
CloudSim.startSimulation();
|
||||
|
||||
CloudSim.stopSimulation();
|
||||
|
||||
Log.printLine("Birbnetes finished!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.printLine("Unwanted errors happen");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
265
src/org/fog/test/perfeval/DCNSFog.java
Normal file
265
src/org/fog/test/perfeval/DCNSFog.java
Normal file
@@ -0,0 +1,265 @@
|
||||
package org.fog.test.perfeval;
|
||||
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* Simulation setup for case study 2 - Intelligent Surveillance
|
||||
* @author Harshit Gupta
|
||||
*
|
||||
*/
|
||||
public class DCNSFog {
|
||||
static List<FogDevice> fogDevices = new ArrayList<FogDevice>();
|
||||
static List<Sensor> sensors = new ArrayList<Sensor>();
|
||||
static List<Actuator> actuators = new ArrayList<Actuator>();
|
||||
static int numOfAreas = 1;
|
||||
static int numOfCamerasPerArea = 4;
|
||||
|
||||
private static boolean CLOUD = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Log.printLine("Starting DCNS...");
|
||||
|
||||
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 = "dcns"; // identifier of the application
|
||||
|
||||
FogBroker broker = new FogBroker("broker");
|
||||
|
||||
Application application = createApplication(appId, broker.getId());
|
||||
application.setUserId(broker.getId());
|
||||
|
||||
createFogDevices(broker.getId(), appId);
|
||||
|
||||
Controller controller = null;
|
||||
|
||||
ModuleMapping moduleMapping = ModuleMapping.createModuleMapping(); // initializing a module mapping
|
||||
for(FogDevice device : fogDevices){
|
||||
if(device.getName().startsWith("m")){ // names of all Smart Cameras start with 'm'
|
||||
moduleMapping.addModuleToDevice("motion_detector", device.getName()); // fixing 1 instance of the Motion Detector module to each Smart Camera
|
||||
}
|
||||
}
|
||||
moduleMapping.addModuleToDevice("user_interface", "cloud"); // fixing instances of User Interface module in the Cloud
|
||||
if(CLOUD){
|
||||
// if the mode of deployment is cloud-based
|
||||
moduleMapping.addModuleToDevice("object_detector", "cloud"); // placing all instances of Object Detector module in the Cloud
|
||||
moduleMapping.addModuleToDevice("object_tracker", "cloud"); // placing all instances of Object Tracker module in the Cloud
|
||||
}
|
||||
|
||||
controller = new Controller("master-controller", fogDevices, sensors,
|
||||
actuators);
|
||||
|
||||
controller.submitApplication(application,
|
||||
(CLOUD)?(new ModulePlacementMapping(fogDevices, application, moduleMapping))
|
||||
:(new ModulePlacementEdgewards(fogDevices, sensors, actuators, application, moduleMapping)));
|
||||
|
||||
TimeKeeper.getInstance().setSimulationStartTime(Calendar.getInstance().getTimeInMillis());
|
||||
|
||||
CloudSim.startSimulation();
|
||||
|
||||
CloudSim.stopSimulation();
|
||||
|
||||
Log.printLine("VRGame finished!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.printLine("Unwanted errors happen");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the fog devices in the physical topology of the simulation.
|
||||
* @param userId
|
||||
* @param appId
|
||||
*/
|
||||
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);
|
||||
fogDevices.add(cloud);
|
||||
FogDevice proxy = createFogDevice("proxy-server", 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333);
|
||||
proxy.setParentId(cloud.getId());
|
||||
proxy.setUplinkLatency(100); // latency of connection between proxy server and cloud is 100 ms
|
||||
fogDevices.add(proxy);
|
||||
for(int i=0;i<numOfAreas;i++){
|
||||
addArea(i+"", userId, appId, proxy.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private static FogDevice addArea(String id, int userId, String appId, int parentId){
|
||||
FogDevice router = createFogDevice("d-"+id, 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333);
|
||||
fogDevices.add(router);
|
||||
router.setUplinkLatency(2); // latency of connection between router and proxy server is 2 ms
|
||||
for(int i=0;i<numOfCamerasPerArea;i++){
|
||||
String mobileId = id+"-"+i;
|
||||
FogDevice camera = addCamera(mobileId, userId, appId, router.getId()); // adding a smart camera to the physical topology. Smart cameras have been modeled as fog devices as well.
|
||||
camera.setUplinkLatency(2); // latency of connection between camera and router is 2 ms
|
||||
fogDevices.add(camera);
|
||||
}
|
||||
router.setParentId(parentId);
|
||||
return router;
|
||||
}
|
||||
|
||||
private static FogDevice addCamera(String id, int userId, String appId, int parentId){
|
||||
FogDevice camera = createFogDevice("m-"+id, 500, 1000, 10000, 10000, 3, 0, 87.53, 82.44);
|
||||
camera.setParentId(parentId);
|
||||
Sensor sensor = new Sensor("s-"+id, "CAMERA", userId, appId, new DeterministicDistribution(5)); // inter-transmission time of camera (sensor) follows a deterministic distribution
|
||||
sensors.add(sensor);
|
||||
Actuator ptz = new Actuator("ptz-"+id, userId, appId, "PTZ_CONTROL");
|
||||
actuators.add(ptz);
|
||||
sensor.setGatewayDeviceId(camera.getId());
|
||||
sensor.setLatency(1.0); // latency of connection between camera (sensor) and the parent Smart Camera is 1 ms
|
||||
ptz.setGatewayDeviceId(camera.getId());
|
||||
ptz.setLatency(1.0); // latency of connection between PTZ Control and the parent Smart Camera is 1 ms
|
||||
return camera;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 static FogDevice createFogDevice(String nodeName, long mips,
|
||||
int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
|
||||
|
||||
List<Pe> peList = new ArrayList<Pe>();
|
||||
|
||||
// 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<Host> hostList = new ArrayList<Host>();
|
||||
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<Storage> storageList = new LinkedList<Storage>(); // 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to create the Intelligent Surveillance application in the DDF model.
|
||||
* @param appId unique identifier of the application
|
||||
* @param userId identifier of the user of the application
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({"serial" })
|
||||
private static Application createApplication(String appId, int userId){
|
||||
|
||||
Application application = Application.createApplication(appId, userId);
|
||||
/*
|
||||
* Adding modules (vertices) to the application model (directed graph)
|
||||
*/
|
||||
application.addAppModule("object_detector", 10);
|
||||
application.addAppModule("motion_detector", 10);
|
||||
application.addAppModule("object_tracker", 10);
|
||||
application.addAppModule("user_interface", 10);
|
||||
|
||||
/*
|
||||
* Connecting the application modules (vertices) in the application model (directed graph) with edges
|
||||
*/
|
||||
application.addAppEdge("CAMERA", "motion_detector", 1000, 20000, "CAMERA", Tuple.UP, AppEdge.SENSOR); // adding edge from CAMERA (sensor) to Motion Detector module carrying tuples of type CAMERA
|
||||
application.addAppEdge("motion_detector", "object_detector", 2000, 2000, "MOTION_VIDEO_STREAM", Tuple.UP, AppEdge.MODULE); // adding edge from Motion Detector to Object Detector module carrying tuples of type MOTION_VIDEO_STREAM
|
||||
application.addAppEdge("object_detector", "user_interface", 500, 2000, "DETECTED_OBJECT", Tuple.UP, AppEdge.MODULE); // adding edge from Object Detector to User Interface module carrying tuples of type DETECTED_OBJECT
|
||||
application.addAppEdge("object_detector", "object_tracker", 1000, 100, "OBJECT_LOCATION", Tuple.UP, AppEdge.MODULE); // adding edge from Object Detector to Object Tracker module carrying tuples of type OBJECT_LOCATION
|
||||
application.addAppEdge("object_tracker", "PTZ_CONTROL", 100, 28, 100, "PTZ_PARAMS", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Object Tracker to PTZ CONTROL (actuator) carrying tuples of type PTZ_PARAMS
|
||||
|
||||
/*
|
||||
* Defining the input-output relationships (represented by selectivity) of the application modules.
|
||||
*/
|
||||
application.addTupleMapping("motion_detector", "CAMERA", "MOTION_VIDEO_STREAM", new FractionalSelectivity(1.0)); // 1.0 tuples of type MOTION_VIDEO_STREAM are emitted by Motion Detector module per incoming tuple of type CAMERA
|
||||
application.addTupleMapping("object_detector", "MOTION_VIDEO_STREAM", "OBJECT_LOCATION", new FractionalSelectivity(1.0)); // 1.0 tuples of type OBJECT_LOCATION are emitted by Object Detector module per incoming tuple of type MOTION_VIDEO_STREAM
|
||||
application.addTupleMapping("object_detector", "MOTION_VIDEO_STREAM", "DETECTED_OBJECT", new FractionalSelectivity(0.05)); // 0.05 tuples of type MOTION_VIDEO_STREAM are emitted by Object Detector module per incoming tuple of type MOTION_VIDEO_STREAM
|
||||
|
||||
/*
|
||||
* 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<String>(){{add("motion_detector");add("object_detector");add("object_tracker");}});
|
||||
final AppLoop loop2 = new AppLoop(new ArrayList<String>(){{add("object_tracker");add("PTZ_CONTROL");}});
|
||||
List<AppLoop> loops = new ArrayList<AppLoop>(){{add(loop1);add(loop2);}};
|
||||
|
||||
application.setLoops(loops);
|
||||
return application;
|
||||
}
|
||||
}
|
||||
241
src/org/fog/test/perfeval/TestApplication.java
Normal file
241
src/org/fog/test/perfeval/TestApplication.java
Normal file
@@ -0,0 +1,241 @@
|
||||
package org.fog.test.perfeval;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
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.MyApplication;
|
||||
import org.fog.application.selectivity.FractionalSelectivity;
|
||||
import org.fog.entities.FogBroker;
|
||||
import org.fog.entities.FogDeviceCharacteristics;
|
||||
import org.fog.entities.MyActuator;
|
||||
import org.fog.entities.MyFogDevice;
|
||||
import org.fog.entities.MySensor;
|
||||
import org.fog.entities.Tuple;
|
||||
import org.fog.placement.ModuleMapping;
|
||||
import org.fog.placement.MyController;
|
||||
import org.fog.placement.MyModulePlacement;
|
||||
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 TestApplication {
|
||||
static List<MyFogDevice> fogDevices = new ArrayList<MyFogDevice>();
|
||||
static Map<Integer,MyFogDevice> deviceById = new HashMap<Integer,MyFogDevice>();
|
||||
static List<MySensor> sensors = new ArrayList<MySensor>();
|
||||
static List<MyActuator> actuators = new ArrayList<MyActuator>();
|
||||
static List<Integer> idOfEndDevices = new ArrayList<Integer>();
|
||||
static Map<Integer, Map<String, Double>> deadlineInfo = new HashMap<Integer, Map<String, Double>>();
|
||||
static Map<Integer, Map<String, Integer>> additionalMipsInfo = new HashMap<Integer, Map<String, Integer>>();
|
||||
|
||||
static boolean CLOUD = false;
|
||||
|
||||
static int numOfGateways = 2;
|
||||
static int numOfEndDevPerGateway = 3;
|
||||
static double sensingInterval = 5;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Log.printLine("Starting TestApplication...");
|
||||
|
||||
try {
|
||||
Log.disable();
|
||||
int num_user = 1;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
boolean trace_flag = false;
|
||||
CloudSim.init(num_user, calendar, trace_flag);
|
||||
String appId = "test_app";
|
||||
FogBroker broker = new FogBroker("broker");
|
||||
|
||||
createFogDevices(broker.getId(), appId);
|
||||
|
||||
MyApplication application = createApplication(appId, broker.getId());
|
||||
application.setUserId(broker.getId());
|
||||
|
||||
ModuleMapping moduleMapping = ModuleMapping.createModuleMapping();
|
||||
|
||||
moduleMapping.addModuleToDevice("storageModule", "cloud");
|
||||
for(int i=0;i<idOfEndDevices.size();i++)
|
||||
{
|
||||
MyFogDevice fogDevice = deviceById.get(idOfEndDevices.get(i));
|
||||
moduleMapping.addModuleToDevice("clientModule", fogDevice.getName());
|
||||
}
|
||||
|
||||
|
||||
MyController controller = new MyController("master-controller", fogDevices, sensors, actuators);
|
||||
|
||||
controller.submitApplication(application, 0, new MyModulePlacement(fogDevices, sensors, actuators, application, moduleMapping,"mainModule"));
|
||||
|
||||
TimeKeeper.getInstance().setSimulationStartTime(Calendar.getInstance().getTimeInMillis());
|
||||
|
||||
CloudSim.startSimulation();
|
||||
|
||||
CloudSim.stopSimulation();
|
||||
|
||||
Log.printLine("TestApplication finished!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.printLine("Unwanted errors happen");
|
||||
}
|
||||
}
|
||||
|
||||
private static double getvalue(double min, double max)
|
||||
{
|
||||
Random r = new Random();
|
||||
double randomValue = min + (max - min) * r.nextDouble();
|
||||
return randomValue;
|
||||
}
|
||||
|
||||
private static int getvalue(int min, int max)
|
||||
{
|
||||
Random r = new Random();
|
||||
int randomValue = min + r.nextInt()%(max - min);
|
||||
return randomValue;
|
||||
}
|
||||
|
||||
private static void createFogDevices(int userId, String appId) {
|
||||
MyFogDevice cloud = createFogDevice("cloud", 44800, 40000, 100, 10000, 0, 0.01, 16*103, 16*83.25);
|
||||
cloud.setParentId(-1);
|
||||
fogDevices.add(cloud);
|
||||
deviceById.put(cloud.getId(), cloud);
|
||||
|
||||
for(int i=0;i<numOfGateways;i++){
|
||||
addGw(i+"", userId, appId, cloud.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void addGw(String gwPartialName, int userId, String appId, int parentId){
|
||||
MyFogDevice gw = createFogDevice("g-"+gwPartialName, 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333);
|
||||
fogDevices.add(gw);
|
||||
deviceById.put(gw.getId(), gw);
|
||||
gw.setParentId(parentId);
|
||||
gw.setUplinkLatency(4);
|
||||
for(int i=0;i<numOfEndDevPerGateway;i++){
|
||||
String endPartialName = gwPartialName+"-"+i;
|
||||
MyFogDevice end = addEnd(endPartialName, userId, appId, gw.getId());
|
||||
end.setUplinkLatency(2);
|
||||
fogDevices.add(end);
|
||||
deviceById.put(end.getId(), end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static MyFogDevice addEnd(String endPartialName, int userId, String appId, int parentId){
|
||||
MyFogDevice end = createFogDevice("e-"+endPartialName, 3200, 1000, 10000, 270, 2, 0, 87.53, 82.44);
|
||||
end.setParentId(parentId);
|
||||
idOfEndDevices.add(end.getId());
|
||||
MySensor sensor = new MySensor("s-"+endPartialName, "IoTSensor", userId, appId, new DeterministicDistribution(sensingInterval)); // inter-transmission time of EEG sensor follows a deterministic distribution
|
||||
sensors.add(sensor);
|
||||
MyActuator actuator = new MyActuator("a-"+endPartialName, userId, appId, "IoTActuator");
|
||||
actuators.add(actuator);
|
||||
sensor.setGatewayDeviceId(end.getId());
|
||||
sensor.setLatency(6.0); // latency of connection between EEG sensors and the parent Smartphone is 6 ms
|
||||
actuator.setGatewayDeviceId(end.getId());
|
||||
actuator.setLatency(1.0); // latency of connection between Display actuator and the parent Smartphone is 1 ms
|
||||
return end;
|
||||
}
|
||||
|
||||
private static MyFogDevice createFogDevice(String nodeName, long mips,
|
||||
int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
|
||||
List<Pe> peList = new ArrayList<Pe>();
|
||||
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<Host> hostList = new ArrayList<Host>();
|
||||
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<Storage> storageList = new LinkedList<Storage>();
|
||||
FogDeviceCharacteristics characteristics = new FogDeviceCharacteristics(
|
||||
arch, os, vmm, host, time_zone, cost, costPerMem,
|
||||
costPerStorage, costPerBw);
|
||||
|
||||
MyFogDevice fogdevice = null;
|
||||
try {
|
||||
fogdevice = new MyFogDevice(nodeName, characteristics,
|
||||
new AppModuleAllocationPolicy(hostList), storageList, 10, upBw, downBw, 0, ratePerMips);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
fogdevice.setLevel(level);
|
||||
fogdevice.setMips((int) mips);
|
||||
return fogdevice;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"serial" })
|
||||
private static MyApplication createApplication(String appId, int userId){
|
||||
|
||||
MyApplication application = MyApplication.createApplication(appId, userId);
|
||||
application.addAppModule("clientModule",10, 1000, 1000, 100);
|
||||
application.addAppModule("mainModule", 50, 1500, 4000, 800);
|
||||
application.addAppModule("storageModule", 10, 50, 12000, 100);
|
||||
|
||||
application.addAppEdge("IoTSensor", "clientModule", 100, 200, "IoTSensor", Tuple.UP, AppEdge.SENSOR);
|
||||
application.addAppEdge("clientModule", "mainModule", 6000, 600 , "RawData", Tuple.UP, AppEdge.MODULE);
|
||||
application.addAppEdge("mainModule", "storageModule", 1000, 300, "StoreData", Tuple.UP, AppEdge.MODULE);
|
||||
application.addAppEdge("mainModule", "clientModule", 100, 50, "ResultData", Tuple.DOWN, AppEdge.MODULE);
|
||||
application.addAppEdge("clientModule", "IoTActuator", 100, 50, "Response", Tuple.DOWN, AppEdge.ACTUATOR);
|
||||
|
||||
application.addTupleMapping("clientModule", "IoTSensor", "RawData", new FractionalSelectivity(1.0));
|
||||
application.addTupleMapping("mainModule", "RawData", "ResultData", new FractionalSelectivity(1.0));
|
||||
application.addTupleMapping("mainModule", "RawData", "StoreData", new FractionalSelectivity(1.0));
|
||||
application.addTupleMapping("clientModule", "ResultData", "Response", new FractionalSelectivity(1.0));
|
||||
|
||||
|
||||
for(int id:idOfEndDevices)
|
||||
{
|
||||
Map<String,Double>moduleDeadline = new HashMap<String,Double>();
|
||||
moduleDeadline.put("mainModule", getvalue(3.00, 5.00));
|
||||
Map<String,Integer>moduleAddMips = new HashMap<String,Integer>();
|
||||
moduleAddMips.put("mainModule", getvalue(0, 500));
|
||||
deadlineInfo.put(id, moduleDeadline);
|
||||
additionalMipsInfo.put(id,moduleAddMips);
|
||||
}
|
||||
|
||||
final AppLoop loop1 = new AppLoop(new ArrayList<String>(){{add("IoTSensor");add("clientModule");add("mainModule");add("clientModule");add("IoTActuator");}});
|
||||
List<AppLoop> loops = new ArrayList<AppLoop>(){{add(loop1);}};
|
||||
application.setLoops(loops);
|
||||
application.setDeadlineInfo(deadlineInfo);
|
||||
application.setAdditionalMipsInfo(additionalMipsInfo);
|
||||
|
||||
return application;
|
||||
}
|
||||
}
|
||||
355
src/org/fog/test/perfeval/TwoApps.java
Normal file
355
src/org/fog/test/perfeval/TwoApps.java
Normal file
@@ -0,0 +1,355 @@
|
||||
package org.fog.test.perfeval;
|
||||
|
||||
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.ModulePlacementMapping;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Simulation setup for case study 1 - EEG Beam Tractor Game
|
||||
* @author Harshit Gupta
|
||||
*
|
||||
*/
|
||||
public class TwoApps {
|
||||
static List<FogDevice> fogDevices = new ArrayList<FogDevice>();
|
||||
static List<FogDevice> mobiles = new ArrayList<FogDevice>();
|
||||
static List<Sensor> sensors = new ArrayList<Sensor>();
|
||||
static List<Actuator> actuators = new ArrayList<Actuator>();
|
||||
|
||||
static int numOfDepts = 1;
|
||||
static int numOfMobilesPerDept = 4;
|
||||
static double EEG_TRANSMISSION_TIME = 5.1;
|
||||
//static double EEG_TRANSMISSION_TIME = 10;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Log.printLine("Starting TwoApps...");
|
||||
|
||||
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 appId0 = "vr_game_0";
|
||||
String appId1 = "vr_game_1";
|
||||
|
||||
FogBroker broker0 = new FogBroker("broker_0");
|
||||
FogBroker broker1 = new FogBroker("broker_1");
|
||||
|
||||
|
||||
Application application0 = createApplication0(appId0, broker0.getId());
|
||||
Application application1 = createApplication1(appId1, broker1.getId());
|
||||
application0.setUserId(broker0.getId());
|
||||
application1.setUserId(broker1.getId());
|
||||
|
||||
createFogDevices();
|
||||
|
||||
createEdgeDevices0(broker0.getId(), appId0);
|
||||
createEdgeDevices1(broker1.getId(), appId1);
|
||||
|
||||
ModuleMapping moduleMapping_0 = ModuleMapping.createModuleMapping(); // initializing a module mapping
|
||||
ModuleMapping moduleMapping_1 = ModuleMapping.createModuleMapping(); // initializing a module mapping
|
||||
|
||||
moduleMapping_0.addModuleToDevice("connector", "cloud"); // fixing all instances of the Connector module to the Cloud
|
||||
moduleMapping_0.addModuleToDevice("concentration_calculator", "cloud"); // fixing all instances of the Concentration Calculator module to the Cloud
|
||||
moduleMapping_1.addModuleToDevice("connector_1", "cloud"); // fixing all instances of the Connector module to the Cloud
|
||||
moduleMapping_1.addModuleToDevice("concentration_calculator_1", "cloud"); // fixing all instances of the Concentration Calculator module to the Cloud
|
||||
for(FogDevice device : fogDevices){
|
||||
if(device.getName().startsWith("m")){
|
||||
moduleMapping_0.addModuleToDevice("client", device.getName()); // fixing all instances of the Client module to the Smartphones
|
||||
moduleMapping_1.addModuleToDevice("client_1", device.getName()); // fixing all instances of the Client module to the Smartphones
|
||||
}
|
||||
}
|
||||
|
||||
Controller controller = new Controller("master-controller", fogDevices, sensors,
|
||||
actuators);
|
||||
|
||||
controller.submitApplication(application0, new ModulePlacementMapping(fogDevices, application0, moduleMapping_0));
|
||||
controller.submitApplication(application1, 1000, new ModulePlacementMapping(fogDevices, application1, moduleMapping_1));
|
||||
|
||||
TimeKeeper.getInstance().setSimulationStartTime(Calendar.getInstance().getTimeInMillis());
|
||||
|
||||
CloudSim.startSimulation();
|
||||
|
||||
CloudSim.stopSimulation();
|
||||
|
||||
Log.printLine("VRGame finished!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.printLine("Unwanted errors happen");
|
||||
}
|
||||
}
|
||||
|
||||
private static void createEdgeDevices0(int userId, String appId) {
|
||||
for(FogDevice mobile : mobiles){
|
||||
String id = mobile.getName();
|
||||
Sensor eegSensor = new Sensor("s-"+appId+"-"+id, "EEG", userId, appId, new DeterministicDistribution(EEG_TRANSMISSION_TIME)); // inter-transmission time of EEG sensor follows a deterministic distribution
|
||||
sensors.add(eegSensor);
|
||||
Actuator display = new Actuator("a-"+appId+"-"+id, userId, appId, "DISPLAY");
|
||||
actuators.add(display);
|
||||
eegSensor.setGatewayDeviceId(mobile.getId());
|
||||
eegSensor.setLatency(6.0); // latency of connection between EEG sensors and the parent Smartphone is 6 ms
|
||||
display.setGatewayDeviceId(mobile.getId());
|
||||
display.setLatency(1.0); // latency of connection between Display actuator and the parent Smartphone is 1 ms
|
||||
}
|
||||
}
|
||||
|
||||
private static void createEdgeDevices1(int userId, String appId) {
|
||||
for(FogDevice mobile : mobiles){
|
||||
String id = mobile.getName();
|
||||
Sensor eegSensor = new Sensor("s-"+appId+"-"+id, "EEG_1", userId, appId, new DeterministicDistribution(EEG_TRANSMISSION_TIME)); // inter-transmission time of EEG sensor follows a deterministic distribution
|
||||
sensors.add(eegSensor);
|
||||
Actuator display = new Actuator("a-"+appId+"-"+id, userId, appId, "DISPLAY_1");
|
||||
actuators.add(display);
|
||||
eegSensor.setGatewayDeviceId(mobile.getId());
|
||||
eegSensor.setLatency(6.0); // latency of connection between EEG sensors and the parent Smartphone is 6 ms
|
||||
display.setGatewayDeviceId(mobile.getId());
|
||||
display.setLatency(1.0); // latency of connection between Display actuator and the parent Smartphone is 1 ms
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the fog devices in the physical topology of the simulation.
|
||||
* @param userId
|
||||
* @param appId
|
||||
*/
|
||||
private static void createFogDevices() {
|
||||
FogDevice cloud = createFogDevice("cloud", 44800, 40000, 100, 10000, 0, 0.01, 16*103, 16*83.25); // creates the fog device Cloud at the apex of the hierarchy with level=0
|
||||
cloud.setParentId(-1);
|
||||
FogDevice proxy = createFogDevice("proxy-server", 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333); // creates the fog device Proxy Server (level=1)
|
||||
proxy.setParentId(cloud.getId()); // setting Cloud as parent of the Proxy Server
|
||||
proxy.setUplinkLatency(100); // latency of connection from Proxy Server to the Cloud is 100 ms
|
||||
|
||||
fogDevices.add(cloud);
|
||||
fogDevices.add(proxy);
|
||||
|
||||
for(int i=0;i<numOfDepts;i++){
|
||||
addGw(i+"", proxy.getId()); // adding a fog device for every Gateway in physical topology. The parent of each gateway is the Proxy Server
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static FogDevice addGw(String id, 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); // latency of connection between gateways and proxy server is 4 ms
|
||||
for(int i=0;i<numOfMobilesPerDept;i++){
|
||||
String mobileId = id+"-"+i;
|
||||
FogDevice mobile = addMobile(mobileId, dept.getId()); // adding mobiles to the physical topology. Smartphones have been modeled as fog devices as well.
|
||||
|
||||
mobile.setUplinkLatency(2); // latency of connection between the smartphone and proxy server is 4 ms
|
||||
fogDevices.add(mobile);
|
||||
}
|
||||
return dept;
|
||||
}
|
||||
|
||||
private static FogDevice addMobile(String id, int parentId){
|
||||
FogDevice mobile = createFogDevice("m-"+id, 1000, 1000, 10000, 270, 3, 0, 87.53, 82.44);
|
||||
mobile.setParentId(parentId);
|
||||
mobiles.add(mobile);
|
||||
/*Sensor eegSensor = new Sensor("s-"+id, "EEG", userId, appId, new DeterministicDistribution(EEG_TRANSMISSION_TIME)); // inter-transmission time of EEG sensor follows a deterministic distribution
|
||||
sensors.add(eegSensor);
|
||||
Actuator display = new Actuator("a-"+id, userId, appId, "DISPLAY");
|
||||
actuators.add(display);
|
||||
eegSensor.setGatewayDeviceId(mobile.getId());
|
||||
eegSensor.setLatency(6.0); // latency of connection between EEG sensors and the parent Smartphone is 6 ms
|
||||
display.setGatewayDeviceId(mobile.getId());
|
||||
display.setLatency(1.0); // latency of connection between Display actuator and the parent Smartphone is 1 ms
|
||||
*/ return mobile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 static FogDevice createFogDevice(String nodeName, long mips,
|
||||
int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
|
||||
|
||||
List<Pe> peList = new ArrayList<Pe>();
|
||||
|
||||
// 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<Host> hostList = new ArrayList<Host>();
|
||||
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<Storage> storageList = new LinkedList<Storage>(); // 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to create the EEG Tractor Beam game application in the DDF model.
|
||||
* @param appId unique identifier of the application
|
||||
* @param userId identifier of the user of the application
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({"serial" })
|
||||
private static Application createApplication0(String appId, int userId){
|
||||
|
||||
Application application = Application.createApplication(appId, userId); // creates an empty application model (empty directed graph)
|
||||
|
||||
/*
|
||||
* Adding modules (vertices) to the application model (directed graph)
|
||||
*/
|
||||
application.addAppModule("client", 10); // adding module Client to the application model
|
||||
application.addAppModule("concentration_calculator", 10); // adding module Concentration Calculator to the application model
|
||||
application.addAppModule("connector", 10); // adding module Connector to the application model
|
||||
|
||||
/*
|
||||
* Connecting the application modules (vertices) in the application model (directed graph) with edges
|
||||
*/
|
||||
if(EEG_TRANSMISSION_TIME==10)
|
||||
application.addAppEdge("EEG", "client", 2000, 500, "EEG", Tuple.UP, AppEdge.SENSOR); // adding edge from EEG (sensor) to Client module carrying tuples of type EEG
|
||||
else
|
||||
application.addAppEdge("EEG", "client", 3000, 500, "EEG", Tuple.UP, AppEdge.SENSOR);
|
||||
application.addAppEdge("client", "concentration_calculator", 3500, 500, "_SENSOR", Tuple.UP, AppEdge.MODULE); // adding edge from Client to Concentration Calculator module carrying tuples of type _SENSOR
|
||||
application.addAppEdge("concentration_calculator", "connector", 100, 1000, 1000, "PLAYER_GAME_STATE", Tuple.UP, AppEdge.MODULE); // adding periodic edge (period=1000ms) from Concentration Calculator to Connector module carrying tuples of type PLAYER_GAME_STATE
|
||||
application.addAppEdge("concentration_calculator", "client", 14, 500, "CONCENTRATION", Tuple.DOWN, AppEdge.MODULE); // adding edge from Concentration Calculator to Client module carrying tuples of type CONCENTRATION
|
||||
application.addAppEdge("connector", "client", 100, 28, 1000, "GLOBAL_GAME_STATE", Tuple.DOWN, AppEdge.MODULE); // adding periodic edge (period=1000ms) from Connector to Client module carrying tuples of type GLOBAL_GAME_STATE
|
||||
application.addAppEdge("client", "DISPLAY", 1000, 500, "SELF_STATE_UPDATE", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Client module to Display (actuator) carrying tuples of type SELF_STATE_UPDATE
|
||||
application.addAppEdge("client", "DISPLAY", 1000, 500, "GLOBAL_STATE_UPDATE", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Client module to Display (actuator) carrying tuples of type GLOBAL_STATE_UPDATE
|
||||
|
||||
/*
|
||||
* Defining the input-output relationships (represented by selectivity) of the application modules.
|
||||
*/
|
||||
application.addTupleMapping("client", "EEG", "_SENSOR", new FractionalSelectivity(0.9)); // 0.9 tuples of type _SENSOR are emitted by Client module per incoming tuple of type EEG
|
||||
application.addTupleMapping("client", "CONCENTRATION", "SELF_STATE_UPDATE", new FractionalSelectivity(1.0)); // 1.0 tuples of type SELF_STATE_UPDATE are emitted by Client module per incoming tuple of type CONCENTRATION
|
||||
application.addTupleMapping("concentration_calculator", "_SENSOR", "CONCENTRATION", new FractionalSelectivity(1.0)); // 1.0 tuples of type CONCENTRATION are emitted by Concentration Calculator module per incoming tuple of type _SENSOR
|
||||
application.addTupleMapping("client", "GLOBAL_GAME_STATE", "GLOBAL_STATE_UPDATE", new FractionalSelectivity(1.0)); // 1.0 tuples of type GLOBAL_STATE_UPDATE are emitted by Client module per incoming tuple of type GLOBAL_GAME_STATE
|
||||
|
||||
/*
|
||||
* Defining application loops to monitor the latency of.
|
||||
* Here, we add only one loop for monitoring : EEG(sensor) -> Client -> Concentration Calculator -> Client -> DISPLAY (actuator)
|
||||
*/
|
||||
final AppLoop loop1 = new AppLoop(new ArrayList<String>(){{add("EEG");add("client");add("concentration_calculator");add("client");add("DISPLAY");}});
|
||||
List<AppLoop> loops = new ArrayList<AppLoop>(){{add(loop1);}};
|
||||
application.setLoops(loops);
|
||||
|
||||
return application;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"serial" })
|
||||
private static Application createApplication1(String appId, int userId){
|
||||
|
||||
Application application = Application.createApplication(appId, userId); // creates an empty application model (empty directed graph)
|
||||
|
||||
/*
|
||||
* Adding modules (vertices) to the application model (directed graph)
|
||||
*/
|
||||
application.addAppModule("client_1", 10); // adding module Client to the application model
|
||||
application.addAppModule("concentration_calculator_1", 10); // adding module Concentration Calculator to the application model
|
||||
application.addAppModule("connector_1", 10); // adding module Connector to the application model
|
||||
|
||||
/*
|
||||
* Connecting the application modules (vertices) in the application model (directed graph) with edges
|
||||
*/
|
||||
if(EEG_TRANSMISSION_TIME==10)
|
||||
application.addAppEdge("EEG_1", "client_1", 2000, 500, "EEG_1", Tuple.UP, AppEdge.SENSOR); // adding edge from EEG (sensor) to Client module carrying tuples of type EEG
|
||||
else
|
||||
application.addAppEdge("EEG_1", "client_1", 3000, 500, "EEG_1", Tuple.UP, AppEdge.SENSOR);
|
||||
application.addAppEdge("client_1", "concentration_calculator_1", 3500, 500, "_SENSOR_1", Tuple.UP, AppEdge.MODULE); // adding edge from Client to Concentration Calculator module carrying tuples of type _SENSOR
|
||||
application.addAppEdge("concentration_calculator_1", "connector_1", 100, 1000, 1000, "PLAYER_GAME_STATE_1", Tuple.UP, AppEdge.MODULE); // adding periodic edge (period=1000ms) from Concentration Calculator to Connector module carrying tuples of type PLAYER_GAME_STATE
|
||||
application.addAppEdge("concentration_calculator_1", "client_1", 14, 500, "CONCENTRATION_1", Tuple.DOWN, AppEdge.MODULE); // adding edge from Concentration Calculator to Client module carrying tuples of type CONCENTRATION
|
||||
application.addAppEdge("connector_1", "client_1", 100, 28, 1000, "GLOBAL_GAME_STATE_1", Tuple.DOWN, AppEdge.MODULE); // adding periodic edge (period=1000ms) from Connector to Client module carrying tuples of type GLOBAL_GAME_STATE
|
||||
application.addAppEdge("client_1", "DISPLAY_1", 1000, 500, "SELF_STATE_UPDATE_1", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Client module to Display (actuator) carrying tuples of type SELF_STATE_UPDATE
|
||||
application.addAppEdge("client_1", "DISPLAY_1", 1000, 500, "GLOBAL_STATE_UPDATE_1", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Client module to Display (actuator) carrying tuples of type GLOBAL_STATE_UPDATE
|
||||
|
||||
/*
|
||||
* Defining the input-output relationships (represented by selectivity) of the application modules.
|
||||
*/
|
||||
application.addTupleMapping("client_1", "EEG_1", "_SENSOR_1", new FractionalSelectivity(0.9)); // 0.9 tuples of type _SENSOR are emitted by Client module per incoming tuple of type EEG
|
||||
application.addTupleMapping("client_1", "CONCENTRATION_1", "SELF_STATE_UPDATE_1", new FractionalSelectivity(1.0)); // 1.0 tuples of type SELF_STATE_UPDATE are emitted by Client module per incoming tuple of type CONCENTRATION
|
||||
application.addTupleMapping("concentration_calculator_1", "_SENSOR_1", "CONCENTRATION_1", new FractionalSelectivity(1.0)); // 1.0 tuples of type CONCENTRATION are emitted by Concentration Calculator module per incoming tuple of type _SENSOR
|
||||
application.addTupleMapping("client_1", "GLOBAL_GAME_STATE_1", "GLOBAL_STATE_UPDATE_1", new FractionalSelectivity(1.0)); // 1.0 tuples of type GLOBAL_STATE_UPDATE are emitted by Client module per incoming tuple of type GLOBAL_GAME_STATE
|
||||
|
||||
/*
|
||||
* Defining application loops to monitor the latency of.
|
||||
* Here, we add only one loop for monitoring : EEG(sensor) -> Client -> Concentration Calculator -> Client -> DISPLAY (actuator)
|
||||
*/
|
||||
final AppLoop loop1 = new AppLoop(new ArrayList<String>(){{add("EEG_1");add("client_1");add("concentration_calculator_1");add("client_1");add("DISPLAY_1");}});
|
||||
List<AppLoop> loops = new ArrayList<AppLoop>(){{add(loop1);}};
|
||||
application.setLoops(loops);
|
||||
|
||||
return application;
|
||||
}
|
||||
}
|
||||
283
src/org/fog/test/perfeval/VRGameFog.java
Normal file
283
src/org/fog/test/perfeval/VRGameFog.java
Normal file
@@ -0,0 +1,283 @@
|
||||
package org.fog.test.perfeval;
|
||||
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* Simulation setup for case study 1 - EEG Beam Tractor Game
|
||||
* @author Harshit Gupta
|
||||
*
|
||||
*/
|
||||
public class VRGameFog {
|
||||
static List<FogDevice> fogDevices = new ArrayList<FogDevice>();
|
||||
static List<Sensor> sensors = new ArrayList<Sensor>();
|
||||
static List<Actuator> actuators = new ArrayList<Actuator>();
|
||||
|
||||
static boolean CLOUD = false;
|
||||
|
||||
static int numOfDepts = 4;
|
||||
static int numOfMobilesPerDept = 6;
|
||||
static double EEG_TRANSMISSION_TIME = 5.1;
|
||||
//static double EEG_TRANSMISSION_TIME = 10;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Log.printLine("Starting VRGame...");
|
||||
|
||||
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 = "vr_game"; // identifier of the application
|
||||
|
||||
FogBroker broker = new FogBroker("broker");
|
||||
|
||||
Application application = createApplication(appId, broker.getId());
|
||||
application.setUserId(broker.getId());
|
||||
|
||||
createFogDevices(broker.getId(), appId);
|
||||
|
||||
ModuleMapping moduleMapping = ModuleMapping.createModuleMapping(); // initializing a module mapping
|
||||
|
||||
if(CLOUD){
|
||||
// if the mode of deployment is cloud-based
|
||||
/*moduleMapping.addModuleToDevice("connector", "cloud", numOfDepts*numOfMobilesPerDept); // fixing all instances of the Connector module to the Cloud
|
||||
moduleMapping.addModuleToDevice("concentration_calculator", "cloud", numOfDepts*numOfMobilesPerDept); // fixing all instances of the Concentration Calculator module to the Cloud
|
||||
*/ moduleMapping.addModuleToDevice("connector", "cloud"); // fixing all instances of the Connector module to the Cloud
|
||||
moduleMapping.addModuleToDevice("concentration_calculator", "cloud"); // fixing all instances of the Concentration Calculator module to the Cloud
|
||||
for(FogDevice device : fogDevices){
|
||||
if(device.getName().startsWith("m")){
|
||||
//moduleMapping.addModuleToDevice("client", device.getName(), 1); // fixing all instances of the Client module to the Smartphones
|
||||
moduleMapping.addModuleToDevice("client", device.getName()); // fixing all instances of the Client module to the Smartphones
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// if the mode of deployment is cloud-based
|
||||
//moduleMapping.addModuleToDevice("connector", "cloud", numOfDepts*numOfMobilesPerDept); // fixing all instances of the Connector module to the Cloud
|
||||
moduleMapping.addModuleToDevice("connector", "cloud"); // fixing all instances of the Connector module to the Cloud
|
||||
// rest of the modules will be placed by the Edge-ward placement policy
|
||||
}
|
||||
|
||||
|
||||
Controller controller = new Controller("master-controller", fogDevices, sensors,
|
||||
actuators);
|
||||
|
||||
controller.submitApplication(application, 0,
|
||||
(CLOUD)?(new ModulePlacementMapping(fogDevices, application, moduleMapping))
|
||||
:(new ModulePlacementEdgewards(fogDevices, sensors, actuators, application, moduleMapping)));
|
||||
|
||||
TimeKeeper.getInstance().setSimulationStartTime(Calendar.getInstance().getTimeInMillis());
|
||||
|
||||
CloudSim.startSimulation();
|
||||
|
||||
CloudSim.stopSimulation();
|
||||
|
||||
Log.printLine("VRGame finished!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.printLine("Unwanted errors happen");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the fog devices in the physical topology of the simulation.
|
||||
* @param userId
|
||||
* @param appId
|
||||
*/
|
||||
private static void createFogDevices(int userId, String appId) {
|
||||
FogDevice cloud = createFogDevice("cloud", 44800, 40000, 100, 10000, 0, 0.01, 16*103, 16*83.25); // creates the fog device Cloud at the apex of the hierarchy with level=0
|
||||
cloud.setParentId(-1);
|
||||
FogDevice proxy = createFogDevice("proxy-server", 2800, 4000, 10000, 10000, 1, 0.0, 107.339, 83.4333); // creates the fog device Proxy Server (level=1)
|
||||
proxy.setParentId(cloud.getId()); // setting Cloud as parent of the Proxy Server
|
||||
proxy.setUplinkLatency(100); // latency of connection from Proxy Server to the Cloud is 100 ms
|
||||
|
||||
fogDevices.add(cloud);
|
||||
fogDevices.add(proxy);
|
||||
|
||||
for(int i=0;i<numOfDepts;i++){
|
||||
addGw(i+"", userId, appId, proxy.getId()); // adding a fog device for every Gateway in physical topology. The parent of each gateway is the Proxy Server
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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); // latency of connection between gateways and proxy server is 4 ms
|
||||
for(int i=0;i<numOfMobilesPerDept;i++){
|
||||
String mobileId = id+"-"+i;
|
||||
FogDevice mobile = addMobile(mobileId, userId, appId, dept.getId()); // adding mobiles to the physical topology. Smartphones have been modeled as fog devices as well.
|
||||
mobile.setUplinkLatency(2); // latency of connection between the smartphone and proxy server is 4 ms
|
||||
fogDevices.add(mobile);
|
||||
}
|
||||
return dept;
|
||||
}
|
||||
|
||||
private static FogDevice addMobile(String id, int userId, String appId, int parentId){
|
||||
FogDevice mobile = createFogDevice("m-"+id, 1000, 1000, 10000, 270, 3, 0, 87.53, 82.44);
|
||||
mobile.setParentId(parentId);
|
||||
Sensor eegSensor = new Sensor("s-"+id, "EEG", userId, appId, new DeterministicDistribution(EEG_TRANSMISSION_TIME)); // inter-transmission time of EEG sensor follows a deterministic distribution
|
||||
sensors.add(eegSensor);
|
||||
Actuator display = new Actuator("a-"+id, userId, appId, "DISPLAY");
|
||||
actuators.add(display);
|
||||
eegSensor.setGatewayDeviceId(mobile.getId());
|
||||
eegSensor.setLatency(6.0); // latency of connection between EEG sensors and the parent Smartphone is 6 ms
|
||||
display.setGatewayDeviceId(mobile.getId());
|
||||
display.setLatency(1.0); // latency of connection between Display actuator and the parent Smartphone is 1 ms
|
||||
return mobile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 static FogDevice createFogDevice(String nodeName, long mips,
|
||||
int ram, long upBw, long downBw, int level, double ratePerMips, double busyPower, double idlePower) {
|
||||
|
||||
List<Pe> peList = new ArrayList<Pe>();
|
||||
|
||||
// 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<Host> hostList = new ArrayList<Host>();
|
||||
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<Storage> storageList = new LinkedList<Storage>(); // 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to create the EEG Tractor Beam game application in the DDF model.
|
||||
* @param appId unique identifier of the application
|
||||
* @param userId identifier of the user of the application
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({"serial" })
|
||||
private static Application createApplication(String appId, int userId){
|
||||
|
||||
Application application = Application.createApplication(appId, userId); // creates an empty application model (empty directed graph)
|
||||
|
||||
/*
|
||||
* Adding modules (vertices) to the application model (directed graph)
|
||||
*/
|
||||
application.addAppModule("client", 10); // adding module Client to the application model
|
||||
application.addAppModule("concentration_calculator", 10); // adding module Concentration Calculator to the application model
|
||||
application.addAppModule("connector", 10); // adding module Connector to the application model
|
||||
|
||||
/*
|
||||
* Connecting the application modules (vertices) in the application model (directed graph) with edges
|
||||
*/
|
||||
if(EEG_TRANSMISSION_TIME==10)
|
||||
application.addAppEdge("EEG", "client", 2000, 500, "EEG", Tuple.UP, AppEdge.SENSOR); // adding edge from EEG (sensor) to Client module carrying tuples of type EEG
|
||||
else
|
||||
application.addAppEdge("EEG", "client", 3000, 500, "EEG", Tuple.UP, AppEdge.SENSOR);
|
||||
application.addAppEdge("client", "concentration_calculator", 3500, 500, "_SENSOR", Tuple.UP, AppEdge.MODULE); // adding edge from Client to Concentration Calculator module carrying tuples of type _SENSOR
|
||||
application.addAppEdge("concentration_calculator", "connector", 100, 1000, 1000, "PLAYER_GAME_STATE", Tuple.UP, AppEdge.MODULE); // adding periodic edge (period=1000ms) from Concentration Calculator to Connector module carrying tuples of type PLAYER_GAME_STATE
|
||||
application.addAppEdge("concentration_calculator", "client", 14, 500, "CONCENTRATION", Tuple.DOWN, AppEdge.MODULE); // adding edge from Concentration Calculator to Client module carrying tuples of type CONCENTRATION
|
||||
application.addAppEdge("connector", "client", 100, 28, 1000, "GLOBAL_GAME_STATE", Tuple.DOWN, AppEdge.MODULE); // adding periodic edge (period=1000ms) from Connector to Client module carrying tuples of type GLOBAL_GAME_STATE
|
||||
application.addAppEdge("client", "DISPLAY", 1000, 500, "SELF_STATE_UPDATE", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Client module to Display (actuator) carrying tuples of type SELF_STATE_UPDATE
|
||||
application.addAppEdge("client", "DISPLAY", 1000, 500, "GLOBAL_STATE_UPDATE", Tuple.DOWN, AppEdge.ACTUATOR); // adding edge from Client module to Display (actuator) carrying tuples of type GLOBAL_STATE_UPDATE
|
||||
|
||||
/*
|
||||
* Defining the input-output relationships (represented by selectivity) of the application modules.
|
||||
*/
|
||||
application.addTupleMapping("client", "EEG", "_SENSOR", new FractionalSelectivity(0.9)); // 0.9 tuples of type _SENSOR are emitted by Client module per incoming tuple of type EEG
|
||||
application.addTupleMapping("client", "CONCENTRATION", "SELF_STATE_UPDATE", new FractionalSelectivity(1.0)); // 1.0 tuples of type SELF_STATE_UPDATE are emitted by Client module per incoming tuple of type CONCENTRATION
|
||||
application.addTupleMapping("concentration_calculator", "_SENSOR", "CONCENTRATION", new FractionalSelectivity(1.0)); // 1.0 tuples of type CONCENTRATION are emitted by Concentration Calculator module per incoming tuple of type _SENSOR
|
||||
application.addTupleMapping("client", "GLOBAL_GAME_STATE", "GLOBAL_STATE_UPDATE", new FractionalSelectivity(1.0)); // 1.0 tuples of type GLOBAL_STATE_UPDATE are emitted by Client module per incoming tuple of type GLOBAL_GAME_STATE
|
||||
|
||||
/*
|
||||
* Defining application loops to monitor the latency of.
|
||||
* Here, we add only one loop for monitoring : EEG(sensor) -> Client -> Concentration Calculator -> Client -> DISPLAY (actuator)
|
||||
*/
|
||||
final AppLoop loop1 = new AppLoop(new ArrayList<String>(){{add("EEG");add("client");add("concentration_calculator");add("client");add("DISPLAY");}});
|
||||
List<AppLoop> loops = new ArrayList<AppLoop>(){{add(loop1);}};
|
||||
application.setLoops(loops);
|
||||
|
||||
return application;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user