init
This commit is contained in:
46
src/org/fog/utils/CanBeSentResult.java
Normal file
46
src/org/fog/utils/CanBeSentResult.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class CanBeSentResult {
|
||||
|
||||
private double cpuLoad;
|
||||
private double nwLoad;
|
||||
|
||||
private boolean canBeSent;
|
||||
|
||||
public CanBeSentResult(double cpuLoad, double nwLoad, boolean canBeSent){
|
||||
this.cpuLoad = cpuLoad;
|
||||
this.nwLoad = nwLoad;
|
||||
this.canBeSent = canBeSent;
|
||||
}
|
||||
|
||||
public CanBeSentResult() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public double getCpuLoad() {
|
||||
return cpuLoad;
|
||||
}
|
||||
|
||||
public void setCpuLoad(double cpuLoad) {
|
||||
this.cpuLoad = cpuLoad;
|
||||
}
|
||||
|
||||
public double getNwLoad() {
|
||||
return nwLoad;
|
||||
}
|
||||
|
||||
public void setNwLoad(double nwLoad) {
|
||||
this.nwLoad = nwLoad;
|
||||
}
|
||||
|
||||
public boolean isCanBeSent() {
|
||||
return canBeSent;
|
||||
}
|
||||
|
||||
public void setCanBeSent(boolean canBeSent) {
|
||||
this.canBeSent = canBeSent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
16
src/org/fog/utils/Config.java
Normal file
16
src/org/fog/utils/Config.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static final double RESOURCE_MGMT_INTERVAL = 100;
|
||||
public static int MAX_SIMULATION_TIME = 300;
|
||||
public static int RESOURCE_MANAGE_INTERVAL = 100;
|
||||
public static String FOG_DEVICE_ARCH = "x86";
|
||||
public static String FOG_DEVICE_OS = "Linux";
|
||||
public static String FOG_DEVICE_VMM = "Xen";
|
||||
public static double FOG_DEVICE_TIMEZONE = 10.0;
|
||||
public static double FOG_DEVICE_COST = 3.0;
|
||||
public static double FOG_DEVICE_COST_PER_MEMORY = 0.05;
|
||||
public static double FOG_DEVICE_COST_PER_STORAGE = 0.001;
|
||||
public static double FOG_DEVICE_COST_PER_BW = 0.0;
|
||||
}
|
||||
73
src/org/fog/utils/FogEntityFactory.java
Normal file
73
src/org/fog/utils/FogEntityFactory.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.cloudbus.cloudsim.Host;
|
||||
import org.cloudbus.cloudsim.Pe;
|
||||
import org.cloudbus.cloudsim.Storage;
|
||||
import org.cloudbus.cloudsim.power.PowerHost;
|
||||
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
|
||||
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
|
||||
import org.cloudbus.cloudsim.sdn.overbooking.BwProvisionerOverbooking;
|
||||
import org.cloudbus.cloudsim.sdn.overbooking.PeProvisionerOverbooking;
|
||||
import org.fog.entities.FogDevice;
|
||||
import org.fog.entities.FogDeviceCharacteristics;
|
||||
import org.fog.policy.AppModuleAllocationPolicy;
|
||||
import org.fog.scheduler.StreamOperatorScheduler;
|
||||
|
||||
public class FogEntityFactory {
|
||||
|
||||
public static FogDevice createFogDevice(String name, int mips, double uplinkBandwidth, double downlinkBandwidth, double latency, double ratePerMips) {
|
||||
|
||||
List<Pe> peList = new ArrayList<Pe>();
|
||||
peList.add(new Pe(0, new PeProvisionerOverbooking(mips))); // need to store Pe id and MIPS Rating
|
||||
|
||||
int hostId = FogUtils.generateEntityId();
|
||||
int ram = 2048; // host memory (MB)
|
||||
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 PowerModelLinear(100, 40)
|
||||
);
|
||||
|
||||
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(name, characteristics,
|
||||
new AppModuleAllocationPolicy(hostList), storageList, 10, uplinkBandwidth, downlinkBandwidth, latency, ratePerMips);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return fogdevice;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
31
src/org/fog/utils/FogEvents.java
Normal file
31
src/org/fog/utils/FogEvents.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class FogEvents {
|
||||
private static final int BASE = 50;
|
||||
public static final int TUPLE_ARRIVAL = BASE + 1;
|
||||
public static final int LAUNCH_MODULE = BASE + 2;
|
||||
public static final int RELEASE_OPERATOR = BASE + 3;
|
||||
public static final int SENSOR_JOINED = BASE + 4;
|
||||
public static final int TUPLE_ACK = BASE + 5;
|
||||
public static final int APP_SUBMIT = BASE + 6;
|
||||
public static final int CALCULATE_INPUT_RATE = BASE + 7;
|
||||
public static final int CALCULATE_UTIL = BASE + 8;
|
||||
public static final int UPDATE_RESOURCE_USAGE = BASE + 9;
|
||||
//public static final int UPDATE_TUPLE_QUEUE = BASE + 10;
|
||||
public static final int TUPLE_FINISHED = BASE + 11;
|
||||
public static final int ACTIVE_APP_UPDATE = BASE+12;
|
||||
public static final int CONTROLLER_RESOURCE_MANAGE = BASE+13;
|
||||
public static final int ADAPTIVE_OPERATOR_REPLACEMENT = BASE+14;
|
||||
public static final int GET_RESOURCE_USAGE = BASE+15;
|
||||
public static final int RESOURCE_USAGE = BASE+16;
|
||||
public static final int CONTROL_MSG_ARRIVAL = BASE + 17;
|
||||
public static final int UPDATE_NORTH_TUPLE_QUEUE = BASE+18;
|
||||
public static final int UPDATE_SOUTH_TUPLE_QUEUE = BASE+19;
|
||||
public static final int ACTUATOR_JOINED = BASE+20;
|
||||
public static final int STOP_SIMULATION = BASE + 21;
|
||||
public static final int SEND_PERIODIC_TUPLE = BASE+22;
|
||||
public static final int LAUNCH_MODULE_INSTANCE = BASE+23;
|
||||
public static final int RESOURCE_MGMT = BASE+24;
|
||||
public static final int INITIALIZE_SENSOR = BASE+24;
|
||||
public static final int EMIT_TUPLE = BASE+25;
|
||||
}
|
||||
110
src/org/fog/utils/FogLinearPowerModel.java
Normal file
110
src/org/fog/utils/FogLinearPowerModel.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import org.cloudbus.cloudsim.power.models.PowerModel;
|
||||
|
||||
/**
|
||||
* The Class PowerModelLinear.
|
||||
*
|
||||
* If you are using any algorithms, policies or workload included in the power package, please cite
|
||||
* the following paper:
|
||||
*
|
||||
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
|
||||
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
|
||||
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
|
||||
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
|
||||
*
|
||||
* @author Anton Beloglazov
|
||||
*
|
||||
* @author Anton Beloglazov
|
||||
* @since CloudSim Toolkit 2.0
|
||||
*/
|
||||
public class FogLinearPowerModel implements PowerModel {
|
||||
|
||||
/** The max power. */
|
||||
private double maxPower;
|
||||
|
||||
/** The constant. */
|
||||
private double constant;
|
||||
|
||||
/** The static power. */
|
||||
private double staticPower;
|
||||
|
||||
/**
|
||||
* Instantiates a new linear power model.
|
||||
*
|
||||
* @param maxPower the max power
|
||||
* @param staticPower the static power
|
||||
*/
|
||||
public FogLinearPowerModel(double maxPower, double staticPower) {
|
||||
setMaxPower(maxPower);
|
||||
setStaticPower(staticPower);
|
||||
setConstant((maxPower - getStaticPower()) / 100);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see cloudsim.power.PowerModel#getPower(double)
|
||||
*/
|
||||
@Override
|
||||
public double getPower(double utilization) throws IllegalArgumentException {
|
||||
if (utilization < 0 || utilization > 1) {
|
||||
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
|
||||
}
|
||||
return getStaticPower() + getConstant() * utilization * 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the max power.
|
||||
*
|
||||
* @return the max power
|
||||
*/
|
||||
protected double getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the max power.
|
||||
*
|
||||
* @param maxPower the new max power
|
||||
*/
|
||||
protected void setMaxPower(double maxPower) {
|
||||
this.maxPower = maxPower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the constant.
|
||||
*
|
||||
* @return the constant
|
||||
*/
|
||||
protected double getConstant() {
|
||||
return constant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the constant.
|
||||
*
|
||||
* @param constant the new constant
|
||||
*/
|
||||
protected void setConstant(double constant) {
|
||||
this.constant = constant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the static power.
|
||||
*
|
||||
* @return the static power
|
||||
*/
|
||||
protected double getStaticPower() {
|
||||
return staticPower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the static power.
|
||||
*
|
||||
* @param staticPower the new static power
|
||||
*/
|
||||
protected void setStaticPower(double staticPower) {
|
||||
this.staticPower = staticPower;
|
||||
}
|
||||
|
||||
}
|
||||
33
src/org/fog/utils/FogUtils.java
Normal file
33
src/org/fog/utils/FogUtils.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FogUtils {
|
||||
private static int TUPLE_ID = 1;
|
||||
private static int ENTITY_ID = 1;
|
||||
private static int ACTUAL_TUPLE_ID = 1;
|
||||
|
||||
public static int generateTupleId(){
|
||||
return TUPLE_ID++;
|
||||
}
|
||||
|
||||
public static String getSensorTypeFromSensorName(String sensorName){
|
||||
return sensorName.substring(sensorName.indexOf('-')+1, sensorName.lastIndexOf('-'));
|
||||
}
|
||||
|
||||
public static int generateEntityId(){
|
||||
return ENTITY_ID++;
|
||||
}
|
||||
|
||||
public static int generateActualTupleId(){
|
||||
return ACTUAL_TUPLE_ID++;
|
||||
}
|
||||
|
||||
public static int USER_ID = 1;
|
||||
|
||||
//public static int MAX = 10000000;
|
||||
public static int MAX = 10000000;
|
||||
|
||||
public static Map<String, GeoCoverage> appIdToGeoCoverageMap = new HashMap<String, GeoCoverage>();
|
||||
}
|
||||
56
src/org/fog/utils/GeoCoverage.java
Normal file
56
src/org/fog/utils/GeoCoverage.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class GeoCoverage {
|
||||
|
||||
private double lat_l;
|
||||
private double lat_u;
|
||||
private double long_l;
|
||||
private double long_u;
|
||||
|
||||
public GeoCoverage(double lat_l, double lat_u, double long_l, double long_u){
|
||||
this.lat_l = lat_l;
|
||||
this.lat_u = lat_u;
|
||||
this.long_l = long_l;
|
||||
this.long_u = long_u;
|
||||
}
|
||||
|
||||
public boolean covers(GeoCoverage geo){
|
||||
if(this.lat_l <= geo.lat_l && this.lat_u >= geo.lat_u && this.long_l <= geo.long_l && this.long_u >= geo.long_u)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public double getLat_l() {
|
||||
return lat_l;
|
||||
}
|
||||
|
||||
public void setLat_l(double lat_l) {
|
||||
this.lat_l = lat_l;
|
||||
}
|
||||
|
||||
public double getLat_u() {
|
||||
return lat_u;
|
||||
}
|
||||
|
||||
public void setLat_u(double lat_u) {
|
||||
this.lat_u = lat_u;
|
||||
}
|
||||
|
||||
public double getLong_l() {
|
||||
return long_l;
|
||||
}
|
||||
|
||||
public void setLong_l(double long_l) {
|
||||
this.long_l = long_l;
|
||||
}
|
||||
|
||||
public double getLong_u() {
|
||||
return long_u;
|
||||
}
|
||||
|
||||
public void setLong_u(double long_u) {
|
||||
this.long_u = long_u;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
27
src/org/fog/utils/GeoLocation.java
Normal file
27
src/org/fog/utils/GeoLocation.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class GeoLocation {
|
||||
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
|
||||
public GeoLocation(double latitude, double longitude){
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
244
src/org/fog/utils/JsonToTopology.java
Normal file
244
src/org/fog/utils/JsonToTopology.java
Normal file
@@ -0,0 +1,244 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.cloudbus.cloudsim.Host;
|
||||
import org.cloudbus.cloudsim.Pe;
|
||||
import org.cloudbus.cloudsim.Storage;
|
||||
import org.cloudbus.cloudsim.power.PowerHost;
|
||||
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
|
||||
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
|
||||
import org.cloudbus.cloudsim.sdn.overbooking.BwProvisionerOverbooking;
|
||||
import org.cloudbus.cloudsim.sdn.overbooking.PeProvisionerOverbooking;
|
||||
import org.fog.entities.Actuator;
|
||||
import org.fog.entities.FogDevice;
|
||||
import org.fog.entities.FogDeviceCharacteristics;
|
||||
import org.fog.entities.PhysicalTopology;
|
||||
import org.fog.entities.Sensor;
|
||||
import org.fog.policy.AppModuleAllocationPolicy;
|
||||
import org.fog.scheduler.StreamOperatorScheduler;
|
||||
import org.fog.utils.distribution.DeterministicDistribution;
|
||||
import org.fog.utils.distribution.Distribution;
|
||||
import org.fog.utils.distribution.NormalDistribution;
|
||||
import org.fog.utils.distribution.UniformDistribution;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
public class JsonToTopology {
|
||||
|
||||
private static List<FogDevice> fogDevices = new ArrayList<FogDevice>();
|
||||
private static List<Sensor> sensors = new ArrayList<Sensor>();
|
||||
private static List<Actuator> actuators = new ArrayList<Actuator>();
|
||||
|
||||
private static boolean isFogDevice(String name){
|
||||
for(FogDevice fogDevice : fogDevices){
|
||||
if(fogDevice.getName().equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private static FogDevice getFogDevice(String name){
|
||||
for(FogDevice fogDevice : fogDevices){
|
||||
if(fogDevice.getName().equalsIgnoreCase(name))
|
||||
return fogDevice;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isActuator(String name){
|
||||
for(Actuator actuator : actuators){
|
||||
if(actuator.getName().equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Actuator getActuator(String name){
|
||||
for(Actuator actuator : actuators){
|
||||
if(actuator.getName().equalsIgnoreCase(name))
|
||||
return actuator;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isSensor(String name){
|
||||
for(Sensor sensor : sensors){
|
||||
if(sensor.getName().equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Sensor getSensor(String name){
|
||||
for(Sensor sensor : sensors){
|
||||
if(sensor.getName().equalsIgnoreCase(name))
|
||||
return sensor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PhysicalTopology getPhysicalTopology(int userId, String appId, String physicalTopologyFile) throws Exception{
|
||||
|
||||
fogDevices = new ArrayList<FogDevice>();
|
||||
sensors = new ArrayList<Sensor>();
|
||||
actuators = new ArrayList<Actuator>();
|
||||
|
||||
|
||||
try {
|
||||
JSONObject doc = (JSONObject) JSONValue.parse(new FileReader(physicalTopologyFile));
|
||||
JSONArray nodes = (JSONArray) doc.get("nodes");
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<JSONObject> iter =nodes.iterator();
|
||||
while(iter.hasNext()){
|
||||
JSONObject node = iter.next();
|
||||
String nodeType = (String) node.get("type");
|
||||
String nodeName = (String) node.get("name");
|
||||
|
||||
if(nodeType.equalsIgnoreCase("FOG_DEVICE")){
|
||||
long mips = (Long) node.get("mips");
|
||||
int ram = new BigDecimal((Long)node.get("ram")).intValueExact();
|
||||
long upBw = new BigDecimal((Long)node.get("upBw")).intValueExact();
|
||||
long downBw = new BigDecimal((Long)node.get("downBw")).intValueExact();
|
||||
int level = new BigDecimal((Long)node.get("level")).intValue();
|
||||
double ratePerMips = new BigDecimal((Double)node.get("ratePerMips")).doubleValue();
|
||||
|
||||
FogDevice fogDevice = createFogDevice(nodeName, mips, ram, upBw, downBw, level, ratePerMips);
|
||||
fogDevice.setParentId(-1);
|
||||
|
||||
fogDevices.add(fogDevice);
|
||||
|
||||
} else if(nodeType.equals("SENSOR")){
|
||||
String sensorType = node.get("sensorType").toString();
|
||||
int distType = new BigDecimal((Long)node.get("distribution")).intValue();
|
||||
Distribution distribution = null;
|
||||
if(distType == Distribution.DETERMINISTIC)
|
||||
distribution = new DeterministicDistribution(new BigDecimal((Double)node.get("value")).doubleValue());
|
||||
else if(distType == Distribution.NORMAL){
|
||||
distribution = new NormalDistribution(new BigDecimal((Double)node.get("mean")).doubleValue(),
|
||||
new BigDecimal((Double)node.get("stdDev")).doubleValue());
|
||||
} else if(distType == Distribution.UNIFORM){
|
||||
distribution = new UniformDistribution(new BigDecimal((Double)node.get("min")).doubleValue(),
|
||||
new BigDecimal((Double)node.get("max")).doubleValue());
|
||||
}
|
||||
System.out.println("Sensor type : "+sensorType);
|
||||
sensors.add(new Sensor(nodeName, sensorType, userId, appId, distribution));
|
||||
} else if(nodeType.equals("ACTUATOR")){
|
||||
String actuatorType = node.get("actuatorType").toString();
|
||||
actuators.add(new Actuator(nodeName, userId, appId, actuatorType));
|
||||
}
|
||||
}
|
||||
|
||||
JSONArray links = (JSONArray) doc.get("links");
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<JSONObject> linksIter =links.iterator();
|
||||
while(linksIter.hasNext()){
|
||||
JSONObject link = linksIter.next();
|
||||
String src = (String) link.get("source");
|
||||
String dst = (String) link.get("destination");
|
||||
double lat = (Double) link.get("latency");
|
||||
|
||||
connectEntities(src, dst, lat);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PhysicalTopology physicalTopology = new PhysicalTopology();
|
||||
physicalTopology.setFogDevices(fogDevices);
|
||||
physicalTopology.setActuators(actuators);
|
||||
physicalTopology.setSensors(sensors);
|
||||
return physicalTopology;
|
||||
}
|
||||
private static FogDevice createFogDevice(String nodeName, long mips,
|
||||
int ram, long upBw, long downBw, int level, double ratePerMips) {
|
||||
|
||||
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 PowerModelLinear(107.339, 83.4333)
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static void connectEntities(String src, String dst, double lat) {
|
||||
if(isFogDevice(src) && isFogDevice(dst)){
|
||||
FogDevice srcDev = getFogDevice(src);
|
||||
FogDevice destDev = getFogDevice(dst);
|
||||
FogDevice southernDev = (srcDev.getLevel() > destDev.getLevel())?srcDev:destDev;
|
||||
FogDevice northernDev = (srcDev.getLevel() > destDev.getLevel())?destDev:srcDev;
|
||||
southernDev.setUplinkLatency(lat);
|
||||
southernDev.setParentId(northernDev.getId());
|
||||
} else if(isFogDevice(src) && isSensor(dst)){
|
||||
FogDevice srcDev = getFogDevice(src);
|
||||
Sensor sensor = getSensor(dst);
|
||||
sensor.setLatency(lat);
|
||||
sensor.setGatewayDeviceId(srcDev.getId());
|
||||
} else if(isSensor(src) && isFogDevice(dst)){
|
||||
FogDevice fogDevice = getFogDevice(dst);
|
||||
Sensor sensor = getSensor(src);
|
||||
sensor.setLatency(lat);
|
||||
sensor.setGatewayDeviceId(fogDevice.getId());
|
||||
} else if(isFogDevice(src) && isActuator(dst)){
|
||||
FogDevice fogDevice = getFogDevice(src);
|
||||
Actuator actuator = getActuator(dst);
|
||||
actuator.setLatency(lat);
|
||||
actuator.setGatewayDeviceId(fogDevice.getId());
|
||||
} else if(isActuator(src) && isFogDevice(dst)){
|
||||
FogDevice fogDevice = getFogDevice(dst);
|
||||
Actuator actuator = getActuator(src);
|
||||
actuator.setLatency(lat);
|
||||
actuator.setGatewayDeviceId(fogDevice.getId());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
34
src/org/fog/utils/Logger.java
Normal file
34
src/org/fog/utils/Logger.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import org.cloudbus.cloudsim.core.CloudSim;
|
||||
|
||||
public class Logger {
|
||||
|
||||
public static final int ERROR = 1;
|
||||
public static final int DEBUG = 0;
|
||||
|
||||
public static int LOG_LEVEL = Logger.DEBUG;
|
||||
private static DecimalFormat df = new DecimalFormat("#.00");
|
||||
|
||||
public static boolean ENABLED = false;;
|
||||
|
||||
public static void setLogLevel(int level){
|
||||
Logger.LOG_LEVEL = level;
|
||||
}
|
||||
|
||||
public static void debug(String name, String message){
|
||||
if(!ENABLED)
|
||||
return;
|
||||
if(Logger.LOG_LEVEL <= Logger.DEBUG)
|
||||
System.out.println(df.format(CloudSim.clock())+" : "+name+" : "+message);
|
||||
}
|
||||
public static void error(String name, String message){
|
||||
if(!ENABLED)
|
||||
return;
|
||||
if(Logger.LOG_LEVEL <= Logger.ERROR)
|
||||
System.out.println(df.format(CloudSim.clock())+" : "+name+" : "+message);
|
||||
}
|
||||
|
||||
}
|
||||
28
src/org/fog/utils/ModuleLaunchConfig.java
Normal file
28
src/org/fog/utils/ModuleLaunchConfig.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import org.fog.application.AppModule;
|
||||
|
||||
public class ModuleLaunchConfig {
|
||||
|
||||
private AppModule module;
|
||||
private int instanceCount;
|
||||
|
||||
public ModuleLaunchConfig(AppModule module, int instanceCount){
|
||||
setModule(module);
|
||||
setInstanceCount(instanceCount);
|
||||
}
|
||||
|
||||
public AppModule getModule() {
|
||||
return module;
|
||||
}
|
||||
public void setModule(AppModule module) {
|
||||
this.module = module;
|
||||
}
|
||||
public int getInstanceCount() {
|
||||
return instanceCount;
|
||||
}
|
||||
public void setInstanceCount(int instanceCount) {
|
||||
this.instanceCount = instanceCount;
|
||||
}
|
||||
|
||||
}
|
||||
14
src/org/fog/utils/NetworkUsageMonitor.java
Normal file
14
src/org/fog/utils/NetworkUsageMonitor.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class NetworkUsageMonitor {
|
||||
|
||||
private static double networkUsage = 0.0;
|
||||
|
||||
public static void sendingTuple(double latency, double tupleNwSize){
|
||||
networkUsage += latency*tupleNwSize;
|
||||
}
|
||||
|
||||
public static double getNetworkUsage(){
|
||||
return networkUsage;
|
||||
}
|
||||
}
|
||||
34
src/org/fog/utils/OperatorEdge.java
Normal file
34
src/org/fog/utils/OperatorEdge.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class OperatorEdge {
|
||||
|
||||
private String src;
|
||||
private String dst;
|
||||
private double selectivity;
|
||||
|
||||
public OperatorEdge(String src, String dst, double selectivity){
|
||||
this.src = src;
|
||||
this.dst = dst;
|
||||
this.selectivity = selectivity;
|
||||
}
|
||||
|
||||
public String getSrc() {
|
||||
return src;
|
||||
}
|
||||
public void setSrc(String src) {
|
||||
this.src = src;
|
||||
}
|
||||
public String getDst() {
|
||||
return dst;
|
||||
}
|
||||
public void setDst(String dst) {
|
||||
this.dst = dst;
|
||||
}
|
||||
public double getSelectivity() {
|
||||
return selectivity;
|
||||
}
|
||||
public void setSelectivity(double selectivity) {
|
||||
this.selectivity = selectivity;
|
||||
}
|
||||
|
||||
}
|
||||
13
src/org/fog/utils/OperatorSetComparator.java
Normal file
13
src/org/fog/utils/OperatorSetComparator.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class OperatorSetComparator implements Comparator<List<String>>{
|
||||
|
||||
@Override
|
||||
public int compare(List<String> arg0, List<String> arg1) {
|
||||
return (arg1.size() - arg0.size());
|
||||
}
|
||||
|
||||
}
|
||||
43
src/org/fog/utils/ResourceUsageDetails.java
Normal file
43
src/org/fog/utils/ResourceUsageDetails.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class ResourceUsageDetails {
|
||||
|
||||
private double mips;
|
||||
private double uplinkBandwidth;
|
||||
private double cpuTrafficIntensity;
|
||||
private double nwTrafficIntensity;
|
||||
|
||||
public ResourceUsageDetails(double mips, double uplinkBandwidth,
|
||||
double cpuTrafficIntensity, double nwTrafficIntensity) {
|
||||
super();
|
||||
this.mips = mips;
|
||||
this.uplinkBandwidth = uplinkBandwidth;
|
||||
this.cpuTrafficIntensity = cpuTrafficIntensity;
|
||||
this.nwTrafficIntensity = nwTrafficIntensity;
|
||||
}
|
||||
public double getMips() {
|
||||
return mips;
|
||||
}
|
||||
public void setMips(double mips) {
|
||||
this.mips = mips;
|
||||
}
|
||||
public double getUplinkBandwidth() {
|
||||
return uplinkBandwidth;
|
||||
}
|
||||
public void setUplinkBandwidth(double uplinkBandwidth) {
|
||||
this.uplinkBandwidth = uplinkBandwidth;
|
||||
}
|
||||
public double getCpuTrafficIntensity() {
|
||||
return cpuTrafficIntensity;
|
||||
}
|
||||
public void setCpuTrafficIntensity(double cpuTrafficIntensity) {
|
||||
this.cpuTrafficIntensity = cpuTrafficIntensity;
|
||||
}
|
||||
public double getNwTrafficIntensity() {
|
||||
return nwTrafficIntensity;
|
||||
}
|
||||
public void setNwTrafficIntensity(double nwTrafficIntensity) {
|
||||
this.nwTrafficIntensity = nwTrafficIntensity;
|
||||
}
|
||||
|
||||
}
|
||||
153
src/org/fog/utils/TimeKeeper.java
Normal file
153
src/org/fog/utils/TimeKeeper.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package org.fog.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.cloudbus.cloudsim.core.CloudSim;
|
||||
import org.fog.entities.Tuple;
|
||||
|
||||
public class TimeKeeper {
|
||||
|
||||
private static TimeKeeper instance;
|
||||
|
||||
private long simulationStartTime;
|
||||
private int count;
|
||||
private Map<Integer, Double> emitTimes;
|
||||
private Map<Integer, Double> endTimes;
|
||||
private Map<Integer, List<Integer>> loopIdToTupleIds;
|
||||
private Map<Integer, Double> tupleIdToCpuStartTime;
|
||||
private Map<String, Double> tupleTypeToAverageCpuTime;
|
||||
private Map<String, Integer> tupleTypeToExecutedTupleCount;
|
||||
|
||||
private Map<Integer, Double> loopIdToCurrentAverage;
|
||||
private Map<Integer, Integer> loopIdToCurrentNum;
|
||||
|
||||
public static TimeKeeper getInstance(){
|
||||
if(instance == null)
|
||||
instance = new TimeKeeper();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public int getUniqueId(){
|
||||
return count++;
|
||||
}
|
||||
|
||||
public void tupleStartedExecution(Tuple tuple){
|
||||
tupleIdToCpuStartTime.put(tuple.getCloudletId(), CloudSim.clock());
|
||||
}
|
||||
|
||||
public void tupleEndedExecution(Tuple tuple){
|
||||
if(!tupleIdToCpuStartTime.containsKey(tuple.getCloudletId()))
|
||||
return;
|
||||
double executionTime = CloudSim.clock() - tupleIdToCpuStartTime.get(tuple.getCloudletId());
|
||||
if(!tupleTypeToAverageCpuTime.containsKey(tuple.getTupleType())){
|
||||
tupleTypeToAverageCpuTime.put(tuple.getTupleType(), executionTime);
|
||||
tupleTypeToExecutedTupleCount.put(tuple.getTupleType(), 1);
|
||||
} else{
|
||||
double currentAverage = tupleTypeToAverageCpuTime.get(tuple.getTupleType());
|
||||
int currentCount = tupleTypeToExecutedTupleCount.get(tuple.getTupleType());
|
||||
tupleTypeToAverageCpuTime.put(tuple.getTupleType(), (currentAverage*currentCount+executionTime)/(currentCount+1));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> loopIdToTupleIds(){
|
||||
return getInstance().getLoopIdToTupleIds();
|
||||
}
|
||||
|
||||
private TimeKeeper(){
|
||||
count = 1;
|
||||
setEmitTimes(new HashMap<Integer, Double>());
|
||||
setEndTimes(new HashMap<Integer, Double>());
|
||||
setLoopIdToTupleIds(new HashMap<Integer, List<Integer>>());
|
||||
setTupleTypeToAverageCpuTime(new HashMap<String, Double>());
|
||||
setTupleTypeToExecutedTupleCount(new HashMap<String, Integer>());
|
||||
setTupleIdToCpuStartTime(new HashMap<Integer, Double>());
|
||||
setLoopIdToCurrentAverage(new HashMap<Integer, Double>());
|
||||
setLoopIdToCurrentNum(new HashMap<Integer, Integer>());
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Map<Integer, Double> getEmitTimes() {
|
||||
return emitTimes;
|
||||
}
|
||||
|
||||
public void setEmitTimes(Map<Integer, Double> emitTimes) {
|
||||
this.emitTimes = emitTimes;
|
||||
}
|
||||
|
||||
public Map<Integer, Double> getEndTimes() {
|
||||
return endTimes;
|
||||
}
|
||||
|
||||
public void setEndTimes(Map<Integer, Double> endTimes) {
|
||||
this.endTimes = endTimes;
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> getLoopIdToTupleIds() {
|
||||
return loopIdToTupleIds;
|
||||
}
|
||||
|
||||
public void setLoopIdToTupleIds(Map<Integer, List<Integer>> loopIdToTupleIds) {
|
||||
this.loopIdToTupleIds = loopIdToTupleIds;
|
||||
}
|
||||
|
||||
public Map<String, Double> getTupleTypeToAverageCpuTime() {
|
||||
return tupleTypeToAverageCpuTime;
|
||||
}
|
||||
|
||||
public void setTupleTypeToAverageCpuTime(
|
||||
Map<String, Double> tupleTypeToAverageCpuTime) {
|
||||
this.tupleTypeToAverageCpuTime = tupleTypeToAverageCpuTime;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getTupleTypeToExecutedTupleCount() {
|
||||
return tupleTypeToExecutedTupleCount;
|
||||
}
|
||||
|
||||
public void setTupleTypeToExecutedTupleCount(
|
||||
Map<String, Integer> tupleTypeToExecutedTupleCount) {
|
||||
this.tupleTypeToExecutedTupleCount = tupleTypeToExecutedTupleCount;
|
||||
}
|
||||
|
||||
public Map<Integer, Double> getTupleIdToCpuStartTime() {
|
||||
return tupleIdToCpuStartTime;
|
||||
}
|
||||
|
||||
public void setTupleIdToCpuStartTime(Map<Integer, Double> tupleIdToCpuStartTime) {
|
||||
this.tupleIdToCpuStartTime = tupleIdToCpuStartTime;
|
||||
}
|
||||
|
||||
public long getSimulationStartTime() {
|
||||
return simulationStartTime;
|
||||
}
|
||||
|
||||
public void setSimulationStartTime(long simulationStartTime) {
|
||||
this.simulationStartTime = simulationStartTime;
|
||||
}
|
||||
|
||||
public Map<Integer, Double> getLoopIdToCurrentAverage() {
|
||||
return loopIdToCurrentAverage;
|
||||
}
|
||||
|
||||
public void setLoopIdToCurrentAverage(Map<Integer, Double> loopIdToCurrentAverage) {
|
||||
this.loopIdToCurrentAverage = loopIdToCurrentAverage;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getLoopIdToCurrentNum() {
|
||||
return loopIdToCurrentNum;
|
||||
}
|
||||
|
||||
public void setLoopIdToCurrentNum(Map<Integer, Integer> loopIdToCurrentNum) {
|
||||
this.loopIdToCurrentNum = loopIdToCurrentNum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
src/org/fog/utils/TupleFinishDetails.java
Normal file
51
src/org/fog/utils/TupleFinishDetails.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package org.fog.utils;
|
||||
|
||||
public class TupleFinishDetails {
|
||||
|
||||
private String queryId;
|
||||
private int actualTupleId;
|
||||
private double emitTime;
|
||||
private double finishTime;
|
||||
private String sensorType;
|
||||
public TupleFinishDetails(String queryId, int actualTupleId, double emitTime, double finishTime, String sensorType){
|
||||
this.queryId = queryId;
|
||||
this.actualTupleId = actualTupleId;
|
||||
this.emitTime = emitTime;
|
||||
this.finishTime = finishTime;
|
||||
this.sensorType = sensorType;
|
||||
}
|
||||
|
||||
public String getQueryId() {
|
||||
return queryId;
|
||||
}
|
||||
public void setQueryId(String queryId) {
|
||||
this.queryId = queryId;
|
||||
}
|
||||
public int getActualTupleId() {
|
||||
return actualTupleId;
|
||||
}
|
||||
public void setActualTupleId(int actualTupleId) {
|
||||
this.actualTupleId = actualTupleId;
|
||||
}
|
||||
public double getEmitTime() {
|
||||
return emitTime;
|
||||
}
|
||||
public void setEmitTime(double emitTime) {
|
||||
this.emitTime = emitTime;
|
||||
}
|
||||
public double getFinishTime() {
|
||||
return finishTime;
|
||||
}
|
||||
public void setFinishTime(double finishTime) {
|
||||
this.finishTime = finishTime;
|
||||
}
|
||||
|
||||
public String getSensorType() {
|
||||
return sensorType;
|
||||
}
|
||||
|
||||
public void setSensorType(String sensorType) {
|
||||
this.sensorType = sensorType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
public class DeterministicDistribution extends Distribution{
|
||||
|
||||
private double value;
|
||||
|
||||
public DeterministicDistribution(double value) {
|
||||
super();
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNextValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistributionType() {
|
||||
return Distribution.DETERMINISTIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanInterTransmitTime() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/org/fog/utils/distribution/Distribution.java
Normal file
24
src/org/fog/utils/distribution/Distribution.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Distribution {
|
||||
|
||||
public static int NORMAL = 1;
|
||||
public static int DETERMINISTIC = 2;
|
||||
public static int UNIFORM = 3;
|
||||
|
||||
protected Random random;
|
||||
public abstract double getNextValue();
|
||||
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
public void setRandom(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public abstract int getDistributionType();
|
||||
public abstract double getMeanInterTransmitTime();
|
||||
}
|
||||
47
src/org/fog/utils/distribution/NormalDistribution.java
Normal file
47
src/org/fog/utils/distribution/NormalDistribution.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class NormalDistribution extends Distribution{
|
||||
|
||||
private double mean;
|
||||
private double stdDev;
|
||||
|
||||
public NormalDistribution(double mean, double stdDev) {
|
||||
setMean(mean);
|
||||
setStdDev(stdDev);
|
||||
setRandom(new Random());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNextValue() {
|
||||
return random.nextGaussian()*stdDev + mean;
|
||||
}
|
||||
|
||||
public double getMean() {
|
||||
return mean;
|
||||
}
|
||||
|
||||
public void setMean(double mean) {
|
||||
this.mean = mean;
|
||||
}
|
||||
|
||||
public double getStdDev() {
|
||||
return stdDev;
|
||||
}
|
||||
|
||||
public void setStdDev(double stdDev) {
|
||||
this.stdDev = stdDev;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistributionType() {
|
||||
return Distribution.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanInterTransmitTime() {
|
||||
return mean;
|
||||
}
|
||||
|
||||
}
|
||||
45
src/org/fog/utils/distribution/UniformDistribution.java
Normal file
45
src/org/fog/utils/distribution/UniformDistribution.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.fog.utils.distribution;
|
||||
|
||||
public class UniformDistribution extends Distribution{
|
||||
|
||||
private double min;
|
||||
private double max;
|
||||
|
||||
public UniformDistribution(double min, double max){
|
||||
super();
|
||||
setMin(min);
|
||||
setMax(max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNextValue() {
|
||||
return getRandom().nextDouble()*(getMax()-getMin())+getMin();
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public void setMin(double min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public void setMax(double max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistributionType() {
|
||||
return Distribution.UNIFORM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanInterTransmitTime() {
|
||||
return (min+max)/2;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user