If any application module run on the cloud device then the cost of the cloud is estimated. The “FogDevice.java” abstract class should be extended and “updateEnergyConsumption()” abstract methods have to implement for calculate the cost execution in cloud.
private void updateEnergyConsumption() {
double totalMipsAllocated = 0;
for(final Vm vm : getHost().getVmList()){
AppModule operator = (AppModule)vm;
operator.updateVmProcessing(CloudSim.clock(), getVmAllocationPolicy().getHost(operator).getVmScheduler()
.getAllocatedMipsForVm(operator));
totalMipsAllocated += getHost().getTotalAllocatedMipsForVm(vm);
}
double timeNow = CloudSim.clock();
double currentCost = getTotalCost();
double newcost = currentCost + (timeNow-lastUtilizationUpdateTime)*getRatePerMips()*lastUtilization*getHost().getTotalMips();
setTotalCost(newcost);
lastUtilization = Math.min(1, totalMipsAllocated/getHost().getTotalMips());
lastUtilizationUpdateTime = timeNow;
}
private void printPowerDetails() {
for(FogDevice fogDevice : getFogDevices()){
System.out.println(fogDevice.getName() + " : Energy Consumed = " + fogDevice.getEnergyConsumption());
}
}