In fog computing, the computation offloading decision decides where to offload the task cloud, fog or execute it locally. “The FogDevice.java” abstract file should be extended and “processTupleArrival()” abstract methods have to implement for offloading the task from where you want.
protected void processTupleArrival(SimEvent ev) {
Tuple tuple = (Tuple) ev.getData();
if (getName().equals("cloud")) {
updateCloudTraffic();
}
if (tuple.getTupleType() == "HEALTH_SENSED_DATA") {
int check = Integer.MAX_VALUE;
FogCell selectedCell = null;
List
for (Cells cell : cells) {
FogCell fogcell = cell.FogCells;
listofNodes.addAll(fogcell.listOfMobileNodes);
listofNodes.addAll(fogcell.listOfStaticNodes);
if (!fogCellTupleMap.containsKey(fogcell)) {
fogCellTupleMap.put(fogcell, new ArrayList());
}
if (fogCellTupleMap.get(fogcell).size() < check) {
selectedCell = fogcell;
check = fogCellTupleMap.get(fogcell).size();
}
}
//IABO algorithm to be called for offloading
NodeVm nodeVmResult = IABO(listofNodes, tuple);
System.out.println("Fogcell id #" + selectedCell.getId() + " tuple id #" + tuple.getCloudletId() + " tuple type :" + tuple.getTupleType());
fogCellTupleMap.get(selectedCell).add(tuple);
tuple.setVmId(nodeVmResult.VirtualMachine.getId());
tuple.setFogNodeName(nodeVmResult.FogNode.getName());
System.out.println("sending down tuple type :" + tuple.getTupleType() + "FogNode :" + nodeVmResult.FogNode.getName() + "Fogcell id #" + nodeVmResult.FogNode.getParentId());
sendDown(tuple, nodeVmResult.FogNode.getParentId());
}
public NodeVm IABO(List
double waittime = Double.MAX_VALUE;
FogDevice selectedNode = null;
Vm selectedVm = null;
System.out.println();
for (Nodes node : listofnode) {
FogDevice fognode = (FogDevice) node.fogNodes;
Map
NodeVm nodeVm = null;
TupleTime tupletime = null;
for (Map.Entry nodevmtupletime : fitnessValue.entrySet()) {
nodeVm = (NodeVm) nodevmtupletime.getKey();
tupletime = (TupleTime) nodevmtupletime.getValue();
}
double time = tupletime.time;
if (waittime > time) {
waittime = time;
selectedNode = (FogDevice) nodeVm.FogNode;
selectedVm = nodeVm.VirtualMachine;
}
System.out.println("IABO-> Vm id " + nodeVm.VirtualMachine.getId() + " Node name : " + node.nodeName + " Fogcell name :" + node.fogNodes.getParentId() + " fitness value " + tupletime.time);
}
System.out.println("IABO-> selected FogNode :" + selectedNode.getName() + " Vm id #" + selectedVm.getId());
NodeVm nodeVm = new NodeVm(selectedNode, selectedVm);
List
TupleTime tupletime = new TupleTime(tuple, waittime);
tupltime.add(tupletime);
System.out.println();
boolean isNodeVmNot = true;
if (!getWaitingTime().isEmpty()) {
for (Map.Entry waitingTimeMap : getWaitingTime().entrySet()) {
NodeVm nodevmmap = (NodeVm) waitingTimeMap.getKey();
List
if (selectedNode == nodevmmap.FogNode && selectedVm == nodevmmap.VirtualMachine) {
System.out.println("Node name :" + selectedNode.getName() + " Vm id #" + selectedVm.getId() + " tuple type " + tuple.getTupleType() + " waiting time " + waittime);
tupleTimelist.add(tupletime);
getWaitingTime().replace(nodeVm, tupleTimelist); .
isNodeVmNot = false;
System.out.println("waiting time again added");
break;
}
}
}
if (isNodeVmNot == true) {
System.out.println("added node vm and tuple time with getWaitingTime()");
System.out.println("Node name :" + selectedNode.getName() + " Vm id #" + selectedVm.getId() + " tuple type " + tuple.getTupleType() + " waiting time " + waittime);
tupletime = new TupleTime(tuple, 0.0);
tupltime.add(tupletime);
getWaitingTime().put(nodeVm, tupltime);
}
return nodeVm;
}