Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to connect lower level Fog devices with nearby gateways in iFogSim?

Description

A simple way to connect low level Fog devices to nearby gateway Fog devices. Here the gateway Fog devices are created with corresponding x and y coordinate values.

Source Code

To be placed in Main class:

private static FogDevice addLowLevelFogDevice(String id, int brokerId, String appId){

FogDevice lowLevelFogDevice = createAFogDevice("LowLevelFog-

Device-"+id, 1000, 1000, 10000, 270, 2, 0, 87.53, 82.44);

lowLevelFogDevice.setParentId(-1);

lowLevelFogDevice.setxCoordinate(getValue(10.00));

lowLevelFogDevice.setyCoordinate(getValue(15.00));

getIdByName.put(lowLevelFogDevice.getName(), lowLevelFogDe-

vice.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;

}

To be placed in Controller class:

private void gatewaySelection() {

for(int i=0;i

FogDevice fogDevice = getFogDevices().get(i);

int parentID=-1;

if(fogDevice.getParentId()==-1) {

double minDistance = Config.MAX_NUMBER;

for(int j=0;j

FogDevice anUpperDevice = getFogDevices().get(j);

if(fogDevice.getLevel()+1==anUpperDe-

vice.getLevel()){

double distance = calculateDistance(fogDe-

vice,anUpperDevice);

if(distance

minDistance = distance;

parentID = anUpperDevice.getId();}

}

}

}

fogDevice.setParentId(parentID);

}

}

private double calculateDistance(FogDevice fogDevice, FogDeviceanUpperDevice) {

return Math.sqrt(Math.pow(fogDevice.getxCoordinate()-anUpperDevice.getxCoordinate(), 2.00)+

Math.pow(fogDevice.getyCoordinate()-anUpperDevice.getyCoordinate(), 2.00));

}

To be placed in FogDevice class:

protected double xCoordinate;

protected double yCoordinate;

public double getxCoordinate() {

return xCoordinate;

}

public void setxCoordinate(double xCoordinate) {

this.xCoordinate = xCoordinate;

}

public double getyCoordinate() {

return yCoordinate;

}

public void setyCoordinate(double yCoordinate) {

this.yCoordinate = yCoordinate;

}

Inclusion in Controller constructor method:

gatewaySelection();

Inclusion in Config class:

public static final double MAX_NUMBER = 9999999.00;

Output

Connect lower level Fog devices with nearby gateways