How to create an application in iFogSim

Description

In iFogSim, an application is modeled as Directed Acyclic Graph and its vertices are represented by modules and edges denoted by data dependencies. In the below figure, modules of clients, concentration_calculator and coordinator represents as vertices and arrow marks between modules, sensor and actuator denotes edges.

public class GameFog {
.
.
.
public static void main(String[] args) {

Log.printLine(“Starting GameFog…”);

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 = “game”;

FogBroker broker = new FogBroker(“broker”);

Application application = createApplication(appId, broker.getId());
application.setUserId(broker.getId());

.
.
.
.
CloudSim.startSimulation();

CloudSim.stopSimulation();

Log.printLine(“Game finished!”);
} catch (Exception e) {
e.printStackTrace();
Log.printLine(“Unwanted errors happen ” + e.getMessage());
}
}

/ * to create the game application in the DDF */

@SuppressWarnings({“serial”})
private static Application createApplication(String appId, int userId) {

Application application = Application.createApplication(appId, userId);

application.addAppModule(“client”, 10);
application.addAppModule(“concentration_calculator”, 10); application.addAppModule(“connector”, 10);

/*connecting the application modules (vertices) in the application model with edges*/

if (EEG_TRANSMISSION_TIME == 10)
{
application.addAppEdge(“EEG”, “client”, 2000, 500, “EEG”, Tuple.UP, AppEdge.SENSOR);
}
else
{
application.addAppEdge(“EEG”, “client”, 3000, 500, “EEG”, Tuple.UP, AppEdge.SENSOR);
}

application.addAppEdge(“client”, “concentration_calculator”, 3500, 500, “_SENSOR”, Tuple.UP, AppEdge.MODULE);
application.addAppEdge(“concentration_calculator”, “connector”, 100, 1000, 1000, “PLAYER_GAME_STATE”, Tuple.UP, AppEdge.MODULE);
application.addAppEdge(“concentration_calculator”, “client”, 14, 500, “CONCENTRATION”, Tuple.DOWN, AppEdge.MODULE);
application.addAppEdge(“connector”, “client”, 100, 28, 1000, “GLOBAL_GAME_STATE”, Tuple.DOWN, AppEdge.MODULE);
application.addAppEdge(“client”, “DISPLAY”, 1000, 500, “SELF_STATE_UPDATE”, Tuple.DOWN, AppEdge.ACTUATOR);
application.addAppEdge(“client”, “DISPLAY”, 1000, 500, “GLOBAL_STATE_UPDATE”, Tuple.DOWN, AppEdge.ACTUATOR);

/* Defining the input-output relationships (represented by selectivity) of the application modules. */

application.addTupleMapping(“client”, “EEG”, “_SENSOR”, new FractionalSelectivity(0.9));
application.addTupleMapping(“client”, “CONCENTRATION”, “SELF_STATE_UPDATE”, new FractionalSelectivity(1.0));
application.addTupleMapping(“concentration_calculator”, “_SENSOR”, “CONCENTRATION”, new FractionalSelectivity(1.0));
application.addTupleMapping(“client”, “GLOBAL_GAME_STATE”, “GLOBAL_STATE_UPDATE”, new FractionalSelectivity(1.0));

final AppLoop loop1 = new AppLoop(new ArrayList() {
{
add(“EEG”);
add(“client”);
add(“concentration_calculator”);
add(“client”);
add(“DISPLAY”);
}
});
List loops = new ArrayList() {
{
add(loop1);
}
};
application.setLoops(loops);

return application;
}
}

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit