This commit is contained in:
2021-04-06 00:45:28 +02:00
commit 17fabc368e
836 changed files with 3042963 additions and 0 deletions

View File

@@ -0,0 +1,148 @@
package org.fog.application;
/**
* Class represents application edges which connect modules together and represent data dependency between them.
* @author Harshit Gupta
*
*/
public class AppEdge {
public static final int SENSOR = 1; // App Edge originates from a sensor
public static final int ACTUATOR = 2; // App Edge leads to an actuator
public static final int MODULE = 3; // App Edge is between application modules
/**
* Name of source application module
*/
private String source;
/**
* Name of destination application module
*/
private String destination;
/**
* CPU length (in MIPS) of tuples carried by the application edge
*/
private double tupleCpuLength;
/**
* Network length (in bytes) of tuples carried by the application edge
*/
private double tupleNwLength;
/**
* Type of tuples carried by the application edge
*/
private String tupleType;
/**
* Direction of tuples carried by the application edge.
*/
private int direction;
private int edgeType;
/**
* Periodicity of application edge (in case it is periodic).
*/
private double periodicity;
/**
* Denotes if the application edge is a periodic edge.
*/
private boolean isPeriodic;
public AppEdge(){
}
public AppEdge(String source, String destination, double tupleCpuLength,
double tupleNwLength, String tupleType, int direction, int edgeType){
setSource(source);
setDestination(destination);
setTupleCpuLength(tupleCpuLength);
setTupleNwLength(tupleNwLength);
setTupleType(tupleType);
setDirection(direction);
setEdgeType(edgeType);
setPeriodic(false);
}
public AppEdge(String source, String destination, double periodicity, double tupleCpuLength,
double tupleNwLength, String tupleType, int direction, int edgeType){
setSource(source);
setDestination(destination);
setTupleCpuLength(tupleCpuLength);
setTupleNwLength(tupleNwLength);
setTupleType(tupleType);
setDirection(direction);
setEdgeType(edgeType);
setPeriodic(true);
setPeriodicity(periodicity);
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public double getTupleCpuLength() {
return tupleCpuLength;
}
public void setTupleCpuLength(double tupleCpuLength) {
this.tupleCpuLength = tupleCpuLength;
}
public double getTupleNwLength() {
return tupleNwLength;
}
public void setTupleNwLength(double tupleNwLength) {
this.tupleNwLength = tupleNwLength;
}
public String getTupleType() {
return tupleType;
}
public void setTupleType(String tupleType) {
this.tupleType = tupleType;
}
public int getDirection() {
return direction;
}
public void setDirection(int direction) {
this.direction = direction;
}
public int getEdgeType() {
return edgeType;
}
public void setEdgeType(int edgeType) {
this.edgeType = edgeType;
}
public double getPeriodicity() {
return periodicity;
}
public void setPeriodicity(double periodicity) {
this.periodicity = periodicity;
}
public boolean isPeriodic() {
return isPeriodic;
}
public void setPeriodic(boolean isPeriodic) {
this.isPeriodic = isPeriodic;
}
@Override
public String toString() {
return "AppEdge [source=" + source + ", destination=" + destination
+ ", tupleType=" + tupleType + "]";
}
}

View File

@@ -0,0 +1,70 @@
package org.fog.application;
import java.util.List;
import org.fog.utils.TimeKeeper;
public class AppLoop {
private int loopId;
private List<String> modules;
public AppLoop(List<String> modules){
setLoopId(TimeKeeper.getInstance().getUniqueId());
setModules(modules);
}
public boolean hasEdge(String src, String dest){
for(int i=0;i<modules.size()-1;i++){
if(modules.get(i).equals(src) && modules.get(i+1).equals(dest))
return true;
}
return false;
}
public String getStartModule(){
return modules.get(0);
}
public String getEndModule(){
return modules.get(modules.size()-1);
}
public boolean isStartModule(String module){
if(getStartModule().equals(module))
return true;
return false;
}
public boolean isEndModule(String module){
if(getEndModule().equals(module))
return true;
return false;
}
public String getNextModuleInLoop(String module){
String result = null;int i=0;
for(String mod : modules){
if(mod.equals(module)){
result = modules.get(i+1);
break;
}
i++;
}
return result;
}
public List<String> getModules() {
return modules;
}
public void setModules(List<String> modules) {
this.modules = modules;
}
public int getLoopId() {
return loopId;
}
public void setLoopId(int loopId) {
this.loopId = loopId;
}
}

View File

@@ -0,0 +1,134 @@
package org.fog.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.math3.util.Pair;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.power.PowerVm;
import org.fog.application.selectivity.SelectivityModel;
import org.fog.scheduler.TupleScheduler;
import org.fog.utils.FogUtils;
/**
* Class representing an application module, the processing elements of the application model of iFogSim.
* @author Harshit Gupta
*
*/
public class AppModule extends PowerVm{
private String name;
private String appId;
private Map<Pair<String, String>, SelectivityModel> selectivityMap;
/**
* A map from the AppModules sending tuples UP to this module to their instance IDs.
* If a new instance ID is detected, the number of instances is incremented.
*/
private Map<String, List<Integer>> downInstanceIdsMaps;
/**
* Number of instances of this module
*/
private int numInstances;
/**
* Mapping from tupleType emitted by this AppModule to Actuators subscribing to that tupleType
*/
private Map<String, List<Integer>> actuatorSubscriptions;
public AppModule(
int id,
String name,
String appId,
int userId,
double mips,
int ram,
long bw,
long size,
String vmm,
CloudletScheduler cloudletScheduler,
Map<Pair<String, String>, SelectivityModel> selectivityMap) {
super(id, userId, mips, 1, ram, bw, size, 1, vmm, cloudletScheduler, 300);
setName(name);
setId(id);
setAppId(appId);
setUserId(userId);
setUid(getUid(userId, id));
setMips(mips);
setNumberOfPes(1);
setRam(ram);
setBw(bw);
setSize(size);
setVmm(vmm);
setCloudletScheduler(cloudletScheduler);
setInMigration(false);
setBeingInstantiated(true);
setCurrentAllocatedBw(0);
setCurrentAllocatedMips(null);
setCurrentAllocatedRam(0);
setCurrentAllocatedSize(0);
setSelectivityMap(selectivityMap);
setActuatorSubscriptions(new HashMap<String, List<Integer>>());
setNumInstances(0);
setDownInstanceIdsMaps(new HashMap<String, List<Integer>>());
}
public AppModule(AppModule operator) {
super(FogUtils.generateEntityId(), operator.getUserId(), operator.getMips(), 1, operator.getRam(), operator.getBw(), operator.getSize(), 1, operator.getVmm(), new TupleScheduler(operator.getMips(), 1), operator.getSchedulingInterval());
setName(operator.getName());
setAppId(operator.getAppId());
setInMigration(false);
setBeingInstantiated(true);
setCurrentAllocatedBw(0);
setCurrentAllocatedMips(null);
setCurrentAllocatedRam(0);
setCurrentAllocatedSize(0);
setSelectivityMap(operator.getSelectivityMap());
setDownInstanceIdsMaps(new HashMap<String, List<Integer>>());
}
public void subscribeActuator(int id, String tuplyType){
if(!getActuatorSubscriptions().containsKey(tuplyType))
getActuatorSubscriptions().put(tuplyType, new ArrayList<Integer>());
getActuatorSubscriptions().get(tuplyType).add(id);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<Pair<String, String>, SelectivityModel> getSelectivityMap() {
return selectivityMap;
}
public void setSelectivityMap(Map<Pair<String, String>, SelectivityModel> selectivityMap) {
this.selectivityMap = selectivityMap;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public Map<String, List<Integer>> getActuatorSubscriptions() {
return actuatorSubscriptions;
}
public void setActuatorSubscriptions(Map<String, List<Integer>> actuatorSubscriptions) {
this.actuatorSubscriptions = actuatorSubscriptions;
}
public Map<String, List<Integer>> getDownInstanceIdsMaps() {
return downInstanceIdsMaps;
}
public void setDownInstanceIdsMaps(Map<String, List<Integer>> downInstanceIdsMaps) {
this.downInstanceIdsMaps = downInstanceIdsMaps;
}
public int getNumInstances() {
return numInstances;
}
public void setNumInstances(int numInstances) {
this.numInstances = numInstances;
}
}

View File

@@ -0,0 +1,341 @@
package org.fog.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.math3.util.Pair;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.fog.application.selectivity.SelectivityModel;
import org.fog.entities.Tuple;
import org.fog.scheduler.TupleScheduler;
import org.fog.utils.FogUtils;
import org.fog.utils.GeoCoverage;
/**
* Class represents an application in the Distributed Dataflow Model.
* @author Harshit Gupta
*
*/
public class Application {
private String appId;
private int userId;
private GeoCoverage geoCoverage;
/**
* List of application modules in the application
*/
private List<AppModule> modules;
/**
* List of application edges in the application
*/
private List<AppEdge> edges;
/**
* List of application loops to monitor for delay
*/
private List<AppLoop> loops;
private Map<String, AppEdge> edgeMap;
/**
* Creates a plain vanilla application with no modules and edges.
* @param appId
* @param userId
* @return
*/
public static Application createApplication(String appId, int userId){
return new Application(appId, userId);
}
/**
* Adds an application module to the application.
* @param moduleName
* @param ram
*/
public void addAppModule(String moduleName, int ram){
int mips = 1000;
long size = 10000;
long bw = 1000;
String vmm = "Xen";
AppModule module = new AppModule(FogUtils.generateEntityId(), moduleName, appId, userId,
mips, ram, bw, size, vmm, new TupleScheduler(mips, 1), new HashMap<Pair<String, String>, SelectivityModel>());
getModules().add(module);
}
/**
* Adds a non-periodic edge to the application model.
* @param source
* @param destination
* @param tupleCpuLength
* @param tupleNwLength
* @param tupleType
* @param direction
* @param edgeType
*/
public void addAppEdge(String source, String destination, double tupleCpuLength,
double tupleNwLength, String tupleType, int direction, int edgeType){
AppEdge edge = new AppEdge(source, destination, tupleCpuLength, tupleNwLength, tupleType, direction, edgeType);
getEdges().add(edge);
getEdgeMap().put(edge.getTupleType(), edge);
}
/**
* Adds a periodic edge to the application model.
* @param source
* @param destination
* @param tupleCpuLength
* @param tupleNwLength
* @param tupleType
* @param direction
* @param edgeType
*/
public void addAppEdge(String source, String destination, double periodicity, double tupleCpuLength,
double tupleNwLength, String tupleType, int direction, int edgeType){
AppEdge edge = new AppEdge(source, destination, periodicity, tupleCpuLength, tupleNwLength, tupleType, direction, edgeType);
getEdges().add(edge);
getEdgeMap().put(edge.getTupleType(), edge);
}
/**
* Define the input-output relationship of an application module for a given input tuple type.
* @param moduleName Name of the module
* @param inputTupleType Type of tuples carried by the incoming edge
* @param outputTupleType Type of tuples carried by the output edge
* @param selectivityModel Selectivity model governing the relation between the incoming and outgoing edge
*/
public void addTupleMapping(String moduleName, String inputTupleType, String outputTupleType, SelectivityModel selectivityModel){
AppModule module = getModuleByName(moduleName);
module.getSelectivityMap().put(new Pair<String, String>(inputTupleType, outputTupleType), selectivityModel);
}
/**
* Get a list of all periodic edges in the application.
* @param srcModule
* @return
*/
public List<AppEdge> getPeriodicEdges(String srcModule){
List<AppEdge> result = new ArrayList<AppEdge>();
for(AppEdge edge : edges){
if(edge.isPeriodic() && edge.getSource().equals(srcModule))
result.add(edge);
}
return result;
}
public Application(String appId, int userId) {
setAppId(appId);
setUserId(userId);
setModules(new ArrayList<AppModule>());
setEdges(new ArrayList<AppEdge>());
setGeoCoverage(null);
setLoops(new ArrayList<AppLoop>());
setEdgeMap(new HashMap<String, AppEdge>());
}
public Application(String appId, List<AppModule> modules,
List<AppEdge> edges, List<AppLoop> loops, GeoCoverage geoCoverage) {
setAppId(appId);
setModules(modules);
setEdges(edges);
setGeoCoverage(geoCoverage);
setLoops(loops);
setEdgeMap(new HashMap<String, AppEdge>());
for(AppEdge edge : edges){
getEdgeMap().put(edge.getTupleType(), edge);
}
}
/**
* Search and return an application module by its module name
* @param name the module name to be returned
* @return
*/
public AppModule getModuleByName(String name){
for(AppModule module : modules){
if(module.getName().equals(name))
return module;
}
return null;
}
/**
* Get the tuples generated upon execution of incoming tuple <i>inputTuple</i> by module named <i>moduleName</i>
* @param moduleName name of the module performing execution of incoming tuple and emitting resultant tuples
* @param inputTuple incoming tuple, whose execution creates resultant tuples
* @param sourceDeviceId
* @return
*/
public List<Tuple> getResultantTuples(String moduleName, Tuple inputTuple, int sourceDeviceId, int sourceModuleId){
List<Tuple> tuples = new ArrayList<Tuple>();
AppModule module = getModuleByName(moduleName);
for(AppEdge edge : getEdges()){
if(edge.getSource().equals(moduleName)){
Pair<String, String> pair = new Pair<String, String>(inputTuple.getTupleType(), edge.getTupleType());
if(module.getSelectivityMap().get(pair)==null)
continue;
SelectivityModel selectivityModel = module.getSelectivityMap().get(pair);
if(selectivityModel.canSelect()){
//TODO check if the edge is ACTUATOR, then create multiple tuples
if(edge.getEdgeType() == AppEdge.ACTUATOR){
//for(Integer actuatorId : module.getActuatorSubscriptions().get(edge.getTupleType())){
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
inputTuple.getNumberOfPes(),
(long) (edge.getTupleNwLength()),
inputTuple.getCloudletOutputSize(),
inputTuple.getUtilizationModelCpu(),
inputTuple.getUtilizationModelRam(),
inputTuple.getUtilizationModelBw()
);
tuple.setActualTupleId(inputTuple.getActualTupleId());
tuple.setUserId(inputTuple.getUserId());
tuple.setAppId(inputTuple.getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(Tuple.ACTUATOR);
tuple.setTupleType(edge.getTupleType());
tuple.setSourceDeviceId(sourceDeviceId);
tuple.setSourceModuleId(sourceModuleId);
//tuple.setActuatorId(actuatorId);
tuples.add(tuple);
//}
}else{
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
inputTuple.getNumberOfPes(),
(long) (edge.getTupleNwLength()),
inputTuple.getCloudletOutputSize(),
inputTuple.getUtilizationModelCpu(),
inputTuple.getUtilizationModelRam(),
inputTuple.getUtilizationModelBw()
);
tuple.setActualTupleId(inputTuple.getActualTupleId());
tuple.setUserId(inputTuple.getUserId());
tuple.setAppId(inputTuple.getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(edge.getDirection());
tuple.setTupleType(edge.getTupleType());
tuple.setSourceModuleId(sourceModuleId);
tuples.add(tuple);
}
}
}
}
return tuples;
}
/**
* Create a tuple for a given application edge
* @param edge
* @param sourceDeviceId
* @return
*/
public Tuple createTuple(AppEdge edge, int sourceDeviceId, int sourceModuleId){
AppModule module = getModuleByName(edge.getSource());
if(edge.getEdgeType() == AppEdge.ACTUATOR){
for(Integer actuatorId : module.getActuatorSubscriptions().get(edge.getTupleType())){
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
1,
(long) (edge.getTupleNwLength()),
100,
new UtilizationModelFull(),
new UtilizationModelFull(),
new UtilizationModelFull()
);
tuple.setUserId(getUserId());
tuple.setAppId(getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(Tuple.ACTUATOR);
tuple.setTupleType(edge.getTupleType());
tuple.setSourceDeviceId(sourceDeviceId);
tuple.setActuatorId(actuatorId);
tuple.setSourceModuleId(sourceModuleId);
return tuple;
}
}else{
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
1,
(long) (edge.getTupleNwLength()),
100,
new UtilizationModelFull(),
new UtilizationModelFull(),
new UtilizationModelFull()
);
//tuple.setActualTupleId(inputTuple.getActualTupleId());
tuple.setUserId(getUserId());
tuple.setAppId(getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(edge.getDirection());
tuple.setTupleType(edge.getTupleType());
tuple.setSourceModuleId(sourceModuleId);
return tuple;
}
return null;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public List<AppModule> getModules() {
return modules;
}
public void setModules(List<AppModule> modules) {
this.modules = modules;
}
public List<AppEdge> getEdges() {
return edges;
}
public void setEdges(List<AppEdge> edges) {
this.edges = edges;
}
public GeoCoverage getGeoCoverage() {
return geoCoverage;
}
public void setGeoCoverage(GeoCoverage geoCoverage) {
this.geoCoverage = geoCoverage;
}
public List<AppLoop> getLoops() {
return loops;
}
public void setLoops(List<AppLoop> loops) {
this.loops = loops;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Map<String, AppEdge> getEdgeMap() {
return edgeMap;
}
public void setEdgeMap(Map<String, AppEdge> edgeMap) {
this.edgeMap = edgeMap;
}
}

View File

@@ -0,0 +1,360 @@
package org.fog.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.math3.util.Pair;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.fog.application.selectivity.SelectivityModel;
import org.fog.entities.Tuple;
import org.fog.scheduler.TupleScheduler;
import org.fog.utils.FogUtils;
import org.fog.utils.GeoCoverage;
/**
* Class represents an application in the Distributed Dataflow Model.
* @author Harshit Gupta
*
*/
public class MyApplication {
private String appId;
private int userId;
private GeoCoverage geoCoverage;
/**
* List of application modules in the application
*/
private List<AppModule> modules;
/**
* List of application edges in the application
*/
private List<AppEdge> edges;
/**
* List of application loops to monitor for delay
*/
private List<AppLoop> loops;
private Map<String, AppEdge> edgeMap;
/**
* Creates a plain vanilla application with no modules and edges.
* @param appId
* @param userId
* @return
*/
public static MyApplication createApplication(String appId, int userId){
return new MyApplication(appId, userId);
}
/**
* Adds an application module to the application.
* @param moduleName
* @param ram
*/
/**
* Adds a non-periodic edge to the application model.
* @param source
* @param destination
* @param tupleCpuLength
* @param tupleNwLength
* @param tupleType
* @param direction
* @param edgeType
*/
public void addAppEdge(String source, String destination, double tupleCpuLength,
double tupleNwLength, String tupleType, int direction, int edgeType){
AppEdge edge = new AppEdge(source, destination, tupleCpuLength, tupleNwLength, tupleType, direction, edgeType);
getEdges().add(edge);
getEdgeMap().put(edge.getTupleType(), edge);
}
/**
* Adds a periodic edge to the application model.
* @param source
* @param destination
* @param tupleCpuLength
* @param tupleNwLength
* @param tupleType
* @param direction
* @param edgeType
*/
public void addAppEdge(String source, String destination, double periodicity, double tupleCpuLength,
double tupleNwLength, String tupleType, int direction, int edgeType){
AppEdge edge = new AppEdge(source, destination, periodicity, tupleCpuLength, tupleNwLength, tupleType, direction, edgeType);
getEdges().add(edge);
getEdgeMap().put(edge.getTupleType(), edge);
}
/**
* Define the input-output relationship of an application module for a given input tuple type.
* @param moduleName Name of the module
* @param inputTupleType Type of tuples carried by the incoming edge
* @param outputTupleType Type of tuples carried by the output edge
* @param selectivityModel Selectivity model governing the relation between the incoming and outgoing edge
*/
public void addTupleMapping(String moduleName, String inputTupleType, String outputTupleType, SelectivityModel selectivityModel){
AppModule module = getModuleByName(moduleName);
module.getSelectivityMap().put(new Pair<String, String>(inputTupleType, outputTupleType), selectivityModel);
}
/**
* Get a list of all periodic edges in the application.
* @param srcModule
* @return
*/
public List<AppEdge> getPeriodicEdges(String srcModule){
List<AppEdge> result = new ArrayList<AppEdge>();
for(AppEdge edge : edges){
if(edge.isPeriodic() && edge.getSource().equals(srcModule))
result.add(edge);
}
return result;
}
public MyApplication(String appId, int userId) {
setAppId(appId);
setUserId(userId);
setModules(new ArrayList<AppModule>());
setEdges(new ArrayList<AppEdge>());
setGeoCoverage(null);
setLoops(new ArrayList<AppLoop>());
setEdgeMap(new HashMap<String, AppEdge>());
}
public MyApplication(String appId, List<AppModule> modules,
List<AppEdge> edges, List<AppLoop> loops, GeoCoverage geoCoverage) {
setAppId(appId);
setModules(modules);
setEdges(edges);
setGeoCoverage(geoCoverage);
setLoops(loops);
setEdgeMap(new HashMap<String, AppEdge>());
for(AppEdge edge : edges){
getEdgeMap().put(edge.getTupleType(), edge);
}
}
/**
* Search and return an application module by its module name
* @param name the module name to be returned
* @return
*/
public AppModule getModuleByName(String name){
for(AppModule module : modules){
if(module.getName().equals(name))
return module;
}
return null;
}
/**
* Get the tuples generated upon execution of incoming tuple <i>inputTuple</i> by module named <i>moduleName</i>
* @param moduleName name of the module performing execution of incoming tuple and emitting resultant tuples
* @param inputTuple incoming tuple, whose execution creates resultant tuples
* @param sourceDeviceId
* @return
*/
public List<Tuple> getResultantTuples(String moduleName, Tuple inputTuple, int sourceDeviceId, int sourceModuleId){
List<Tuple> tuples = new ArrayList<Tuple>();
AppModule module = getModuleByName(moduleName);
for(AppEdge edge : getEdges()){
if(edge.getSource().equals(moduleName)){
Pair<String, String> pair = new Pair<String, String>(inputTuple.getTupleType(), edge.getTupleType());
if(module.getSelectivityMap().get(pair)==null)
continue;
SelectivityModel selectivityModel = module.getSelectivityMap().get(pair);
if(selectivityModel.canSelect()){
//TODO check if the edge is ACTUATOR, then create multiple tuples
if(edge.getEdgeType() == AppEdge.ACTUATOR){
//for(Integer actuatorId : module.getActuatorSubscriptions().get(edge.getTupleType())){
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
inputTuple.getNumberOfPes(),
(long) (edge.getTupleNwLength()),
inputTuple.getCloudletOutputSize(),
inputTuple.getUtilizationModelCpu(),
inputTuple.getUtilizationModelRam(),
inputTuple.getUtilizationModelBw()
);
tuple.setActualTupleId(inputTuple.getActualTupleId());
tuple.setUserId(inputTuple.getUserId());
tuple.setAppId(inputTuple.getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(Tuple.ACTUATOR);
tuple.setTupleType(edge.getTupleType());
tuple.setSourceDeviceId(sourceDeviceId);
tuple.setSourceModuleId(sourceModuleId);
//tuple.setActuatorId(actuatorId);
tuples.add(tuple);
//}
}else{
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
inputTuple.getNumberOfPes(),
(long) (edge.getTupleNwLength()),
inputTuple.getCloudletOutputSize(),
inputTuple.getUtilizationModelCpu(),
inputTuple.getUtilizationModelRam(),
inputTuple.getUtilizationModelBw()
);
tuple.setActualTupleId(inputTuple.getActualTupleId());
tuple.setUserId(inputTuple.getUserId());
tuple.setAppId(inputTuple.getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(edge.getDirection());
tuple.setTupleType(edge.getTupleType());
tuple.setSourceModuleId(sourceModuleId);
tuples.add(tuple);
}
}
}
}
return tuples;
}
/**
* Create a tuple for a given application edge
* @param edge
* @param sourceDeviceId
* @return
*/
public Tuple createTuple(AppEdge edge, int sourceDeviceId, int sourceModuleId){
AppModule module = getModuleByName(edge.getSource());
if(edge.getEdgeType() == AppEdge.ACTUATOR){
for(Integer actuatorId : module.getActuatorSubscriptions().get(edge.getTupleType())){
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
1,
(long) (edge.getTupleNwLength()),
100,
new UtilizationModelFull(),
new UtilizationModelFull(),
new UtilizationModelFull()
);
tuple.setUserId(getUserId());
tuple.setAppId(getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(Tuple.ACTUATOR);
tuple.setTupleType(edge.getTupleType());
tuple.setSourceDeviceId(sourceDeviceId);
tuple.setActuatorId(actuatorId);
tuple.setSourceModuleId(sourceModuleId);
return tuple;
}
}else{
Tuple tuple = new Tuple(appId, FogUtils.generateTupleId(), edge.getDirection(),
(long) (edge.getTupleCpuLength()),
1,
(long) (edge.getTupleNwLength()),
100,
new UtilizationModelFull(),
new UtilizationModelFull(),
new UtilizationModelFull()
);
//tuple.setActualTupleId(inputTuple.getActualTupleId());
tuple.setUserId(getUserId());
tuple.setAppId(getAppId());
tuple.setDestModuleName(edge.getDestination());
tuple.setSrcModuleName(edge.getSource());
tuple.setDirection(edge.getDirection());
tuple.setTupleType(edge.getTupleType());
tuple.setSourceModuleId(sourceModuleId);
return tuple;
}
return null;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public List<AppModule> getModules() {
return modules;
}
public void setModules(List<AppModule> modules) {
this.modules = modules;
}
public List<AppEdge> getEdges() {
return edges;
}
public void setEdges(List<AppEdge> edges) {
this.edges = edges;
}
public GeoCoverage getGeoCoverage() {
return geoCoverage;
}
public void setGeoCoverage(GeoCoverage geoCoverage) {
this.geoCoverage = geoCoverage;
}
public List<AppLoop> getLoops() {
return loops;
}
public void setLoops(List<AppLoop> loops) {
this.loops = loops;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Map<String, AppEdge> getEdgeMap() {
return edgeMap;
}
public void setEdgeMap(Map<String, AppEdge> edgeMap) {
this.edgeMap = edgeMap;
}
////////////////////////////////////////////////////////////// inclusion
private Map<Integer, Map<String, Double>> deadlineInfo;
private Map<Integer, Map<String, Integer>> additionalMipsInfo;
public Map<Integer, Map<String, Integer>> getAdditionalMipsInfo() {
return additionalMipsInfo;
}
public void setAdditionalMipsInfo(
Map<Integer, Map<String, Integer>> additionalMipsInfo) {
this.additionalMipsInfo = additionalMipsInfo;
}
public void setDeadlineInfo(Map<Integer, Map<String, Double>> deadlineInfo) {
this.deadlineInfo = deadlineInfo;
}
public Map<Integer, Map<String, Double>> getDeadlineInfo() {
return deadlineInfo;
}
public void addAppModule(String moduleName,int ram, int mips, long size, long bw){
String vmm = "Xen";
AppModule module = new AppModule(FogUtils.generateEntityId(), moduleName, appId, userId,
mips, ram, bw, size, vmm, new TupleScheduler(mips, 1), new HashMap<Pair<String, String>, SelectivityModel>());
getModules().add(module);
}
}

View File

@@ -0,0 +1,89 @@
package org.fog.application.selectivity;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* Generates an output tuple for every input tuple according to a bursty model.
* During high burst period, all input tuples result in an output tuple.
* During low burst period, no input tuples result in an output tuple.
* @author Harshit Gupta
*
*/
public class BurstySelectivity implements SelectivityModel{
/**
* Duration of the low burst period
*/
double burstLowPeriod;
/**
* Duration of the high burst period
*/
double burstHighPeriod;
/**
* First instance of the start of high burst period, using which subsequent burst periods will be calculated.
*/
double firstHighTime;
public BurstySelectivity(double burstLowPeriod, double burstHighPeriod, double firstHighTime){
setBurstLowPeriod(burstLowPeriod);
setBurstHighPeriod(burstHighPeriod);
setFirstHighTime(firstHighTime);
}
/**
* If the current time falls in the high burst period of the specified burst model, an output tuple is generated for the incoming tuple.
*/
@Override
public boolean canSelect() {
double time = CloudSim.clock() + getFirstHighTime();
double burstPeriod = getBurstHighPeriod()+getBurstLowPeriod();
double burstStartTime = burstPeriod*((int)(time/burstPeriod));
if(time <= burstStartTime + getBurstHighPeriod())
return true;
else
return false;
}
/**
* The mean tuple generation rate is the fraction of high burst period in the total burst period.
*/
@Override
public double getMeanRate() {
return getBurstHighPeriod()/(getBurstHighPeriod()+getBurstLowPeriod());
}
/**
* Maximum tuple generation rate equals 1 (when the burst is high)
*/
@Override
public double getMaxRate() {
return 1;
}
public double getBurstLowPeriod() {
return burstLowPeriod;
}
public void setBurstLowPeriod(double burstLowPeriod) {
this.burstLowPeriod = burstLowPeriod;
}
public double getBurstHighPeriod() {
return burstHighPeriod;
}
public void setBurstHighPeriod(double burstHighPeriod) {
this.burstHighPeriod = burstHighPeriod;
}
public double getFirstHighTime() {
return firstHighTime;
}
public void setFirstHighTime(double firstHighTime) {
this.firstHighTime = firstHighTime;
}
}

View File

@@ -0,0 +1,42 @@
package org.fog.application.selectivity;
/**
* Generates an output tuple for an incoming input tuple with a fixed probability
* @author Harshit Gupta
*
*/
public class FractionalSelectivity implements SelectivityModel{
/**
* The fixed probability of output tuple creation per incoming input tuple
*/
double selectivity;
public FractionalSelectivity(double selectivity){
setSelectivity(selectivity);
}
public double getSelectivity() {
return selectivity;
}
public void setSelectivity(double selectivity) {
this.selectivity = selectivity;
}
@Override
public boolean canSelect() {
if(Math.random() < getSelectivity()) // if the probability condition is satisfied
return true;
return false;
}
@Override
public double getMeanRate() {
return getSelectivity(); // the average rate of tuple generation is the fixed probability value
}
@Override
public double getMaxRate() {
return getSelectivity(); // the maximum rate of tuple generation is the fixed probability value
}
}

View File

@@ -0,0 +1,28 @@
package org.fog.application.selectivity;
/**
* Class representing the input-output relationships of application modules.
* @author Harshit Gupta
*
*/
public interface SelectivityModel {
/**
* Function called to check whether incoming tuple can generate an output tuple.
* @return true if a tuple can be emitted (selection possible)
*/
public boolean canSelect();
/**
* Average number of tuples generated per incoming input tuple.
* @return avg tuple generation rate
*/
public double getMeanRate();
/**
* Maximum number of tuples generated per incoming input tuple.
* @return max tuple generation rate
*/
public double getMaxRate();
}