diff --git a/modules/cloudsim/src/main/java/org/cloudbus/cloudsim/power/PowerDatacenter.java b/modules/cloudsim/src/main/java/org/cloudbus/cloudsim/power/PowerDatacenter.java index 5462077de..94349ac86 100644 --- a/modules/cloudsim/src/main/java/org/cloudbus/cloudsim/power/PowerDatacenter.java +++ b/modules/cloudsim/src/main/java/org/cloudbus/cloudsim/power/PowerDatacenter.java @@ -51,6 +51,12 @@ public class PowerDatacenter extends Datacenter { /** The VM migration count. */ private int migrationCount; + + // Migration Time + public double Tmigr = 0; + + // Migration Energy + public double Emigr; /** * Instantiates a new PowerDatacenter. @@ -84,6 +90,8 @@ protected void updateCloudletProcessing() { return; } double currentTime = CloudSim.clock(); + double Pm = 4.5; // VMs communication energy unit + double sum = 0; // if some time passed since last processing if (currentTime > getLastProcessTime()) { @@ -100,6 +108,13 @@ protected void updateCloudletProcessing() { Vm vm = (Vm) migrate.get("vm"); PowerHost targetHost = (PowerHost) migrate.get("host"); PowerHost oldHost = (PowerHost) vm.getHost(); + + // Calculates migration time and energy + double Cj = vm.getRam(); + double BWj = vm.getBw(); + Tmigr = Tmigr + Cj/BWj; + sum = sum + Pm*(Cj/BWj); + Emigr = 4*sum; if (oldHost == null) { Log.formatLine( @@ -140,6 +155,8 @@ protected void updateCloudletProcessing() { setLastProcessTime(currentTime); } + setMigrationTime(Tmigr); // Update Total Migration Time + setMigrationEnergy(Emigr); // Update Total Migration Energy } /** @@ -355,5 +372,22 @@ protected void setMigrationCount(int migrationCount) { protected void incrementMigrationCount() { setMigrationCount(getMigrationCount() + 1); } + + // sets migration time + public void setMigrationTime(double Tm){ + Tmigr = Tm; + } + //gets migration time + public double getMigrationTime(){ + return Tmigr; + } + //sets migration Energy + public void setMigrationEnergy(double Em){ + Emigr = Em; + } + //gets total migration energy + public double getMigrationEnergy(){ + return Emigr; + } }