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

Office Address

Social List

How to Create an Application in IFogSim?

Create an Application in IFogSim

Condition for Create an Application in IFogSim

  • Description:
    Creating an application in iFogSim involves defining its components, interactions, and execution flows. Start with initializing an Application object with a unique identifier and user ID, followed by adding application modules representing tasks or processes using addAppModule, where each module specifies its name and resource requirements. Define data flow and dependencies between these modules by establishing edges using addAppEdge, which links modules with data tuples and specifies the direction, type, and communication parameters. Map data tuples to modules for processing using addTupleMapping, assigning selectivity rates to ensure proper data handling. Construct application loops with AppLoop objects to define sequences of module executions, which represent the application's operational logic. Combine modules, edges, tuple mappings, and loops into the application object to complete its structure.
Sample Code
  • package fogsamples;
    import org.cloudbus.cloudsim.*;
    import org.cloudbus.cloudsim.core.CloudSim;
    import org.fog.application.AppEdge;
    import org.fog.application.AppLoop;
    import org.fog.application.Application;
    import org.fog.entities.FogBroker;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.List;
    import org.fog.application.selectivity.FractionalSelectivity;
    import org.fog.entities.Tuple;
    public class ApplicationExample {
     private static final int EEG_TRANSMISSION_TIME = 10;
     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
       // Initialize the CloudSim library
       CloudSim.init(num_user, calendar, trace_flag);
       String appId = "game"; // Application ID
       FogBroker broker = new FogBroker("broker");
       // Create the application
       Application application = createApplication(appId, broker.getId());
       application.setUserId(broker.getId());
       // Print application details
       printApplicationDetails(application);
       // Start and stop the simulation
       CloudSim.startSimulation();
       CloudSim.stopSimulation();
       Log.printLine("Game finished!");
      } catch (Exception e) {
       e.printStackTrace();
       Log.printLine("Unwanted errors happened: " + e.getMessage());
      }
     }
     @SuppressWarnings("serial")
     private static Application createApplication(String appId, int userId) {
      // Create a new application
      Application application = Application.createApplication(appId, userId);
      // Add application modules
      application.addAppModule("client", 10);
      application.addAppModule("concentration_calculator", 10);
      application.addAppModule("connector", 10);
      // Add edges between application modules
      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);
      // Add tuple mappings
      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));
      // Define the application loops
      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;
     }
     private static void printApplicationDetails(Application application) {
      System.out.println("Application ID: " + application.getAppId());
      System.out.println("Modules: ");
      application.getModules().forEach(module -> System.out.println(" - " + module.getName()));
      System.out.println("Edges: ");
      application.getEdges().forEach(edge -> System.out.println(" - From: " + edge.getSource()
        + " To: " + edge.getDestination()
        + " Tuple Type: " + edge.getTupleType()));
      System.out.println("Loops: ");
      application.getLoops().forEach(loop -> System.out.println(" - " + loop.getModules()));
     }
    }
ScreenShots
  • Create an Application in IFogSim1