This commit is contained in:
2021-04-06 00:45:28 +02:00
commit 17fabc368e
836 changed files with 3042963 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.provisioners;
import org.cloudbus.cloudsim.Vm;
/**
* BwProvisioner is an abstract class that represents the provisioning policy of bandwidth to
* virtual machines inside a Host. When extending this class, care must be taken to guarantee that
* the field availableBw will always contain the amount of free bandwidth available for future
* allocations.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public abstract class BwProvisioner {
/** The bw. */
private long bw;
/** The available bw. */
private long availableBw;
/**
* Creates the new BwProvisioner.
*
* @param bw overall amount of bandwidth available in the host.
*
* @pre bw >= 0
* @post $none
*/
public BwProvisioner(long bw) {
setBw(bw);
setAvailableBw(bw);
}
/**
* Allocates BW for a given VM.
*
* @param vm virtual machine for which the bw are being allocated
* @param bw the bw
*
* @return $true if the bw could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
public abstract boolean allocateBwForVm(Vm vm, long bw);
/**
* Gets the allocated BW for VM.
*
* @param vm the VM
*
* @return the allocated BW for vm
*/
public abstract long getAllocatedBwForVm(Vm vm);
/**
* Releases BW used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
public abstract void deallocateBwForVm(Vm vm);
/**
* Releases BW used by a all VMs.
*
* @pre $none
* @post none
*/
public void deallocateBwForAllVms() {
setAvailableBw(getBw());
}
/**
* Checks if BW is suitable for vm.
*
* @param vm the vm
* @param bw the bw
*
* @return true, if BW is suitable for vm
*/
public abstract boolean isSuitableForVm(Vm vm, long bw);
/**
* Gets the bw.
*
* @return the bw
*/
public long getBw() {
return bw;
}
/**
* Sets the bw.
*
* @param bw the new bw
*/
protected void setBw(long bw) {
this.bw = bw;
}
/**
* Gets the available BW in the host.
*
* @return available bw
*
* @pre $none
* @post $none
*/
public long getAvailableBw() {
return availableBw;
}
/**
* Gets the amount of used BW in the host.
*
* @return used bw
*
* @pre $none
* @post $none
*/
public long getUsedBw() {
return bw - availableBw;
}
/**
* Sets the available bw.
*
* @param availableBw the new available bw
*/
protected void setAvailableBw(long availableBw) {
this.availableBw = availableBw;
}
}

View File

@@ -0,0 +1,128 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.provisioners;
import java.util.HashMap;
import java.util.Map;
import org.cloudbus.cloudsim.Vm;
/**
* BwProvisionerSimple is a class that implements a simple best effort allocation policy: if there
* is bw available to request, it allocates; otherwise, it fails.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public class BwProvisionerSimple extends BwProvisioner {
/** The bw table. */
private Map<String, Long> bwTable;
/**
* Instantiates a new bw provisioner simple.
*
* @param bw the bw
*/
public BwProvisionerSimple(long bw) {
super(bw);
setBwTable(new HashMap<String, Long>());
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.BwProvisioner#allocateBwForVm(cloudsim.Vm, long)
*/
@Override
public boolean allocateBwForVm(Vm vm, long bw) {
deallocateBwForVm(vm);
if (getAvailableBw() >= bw) {
setAvailableBw(getAvailableBw() - bw);
getBwTable().put(vm.getUid(), bw);
vm.setCurrentAllocatedBw(getAllocatedBwForVm(vm));
return true;
}
vm.setCurrentAllocatedBw(getAllocatedBwForVm(vm));
return false;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.BwProvisioner#getAllocatedBwForVm(cloudsim.Vm)
*/
@Override
public long getAllocatedBwForVm(Vm vm) {
if (getBwTable().containsKey(vm.getUid())) {
return getBwTable().get(vm.getUid());
}
return 0;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.BwProvisioner#deallocateBwForVm(cloudsim.Vm)
*/
@Override
public void deallocateBwForVm(Vm vm) {
if (getBwTable().containsKey(vm.getUid())) {
long amountFreed = getBwTable().remove(vm.getUid());
setAvailableBw(getAvailableBw() + amountFreed);
vm.setCurrentAllocatedBw(0);
}
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.BwProvisioner#deallocateBwForVm(cloudsim.Vm)
*/
@Override
public void deallocateBwForAllVms() {
super.deallocateBwForAllVms();
getBwTable().clear();
}
/*
* (non-Javadoc)
* @see
* gridsim.virtualization.power.provisioners.BWProvisioner#isSuitableForVm(gridsim.virtualization
* .power.VM, long)
*/
@Override
public boolean isSuitableForVm(Vm vm, long bw) {
long allocatedBw = getAllocatedBwForVm(vm);
boolean result = allocateBwForVm(vm, bw);
deallocateBwForVm(vm);
if (allocatedBw > 0) {
allocateBwForVm(vm, allocatedBw);
}
return result;
}
/**
* Gets the bw table.
*
* @return the bw table
*/
protected Map<String, Long> getBwTable() {
return bwTable;
}
/**
* Sets the bw table.
*
* @param bwTable the bw table
*/
protected void setBwTable(Map<String, Long> bwTable) {
this.bwTable = bwTable;
}
}

View File

@@ -0,0 +1,199 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.provisioners;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
/**
* The Class PeProvisioner.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public abstract class PeProvisioner {
/** The mips. */
private double mips;
/** The available mips. */
private double availableMips;
/**
* Creates the new PeProvisioner.
*
* @param mips overall amount of MIPS available in the Pe
*
* @pre mips>=0
* @post $none
*/
public PeProvisioner(double mips) {
setMips(mips);
setAvailableMips(mips);
}
/**
* Allocates MIPS for a given VM.
*
* @param vm virtual machine for which the MIPS are being allocated
* @param mips the mips
*
* @return $true if the MIPS could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
public abstract boolean allocateMipsForVm(Vm vm, double mips);
/**
* Allocates MIPS for a given VM.
*
* @param vmUid the vm uid
* @param mips the mips
*
* @return $true if the MIPS could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
public abstract boolean allocateMipsForVm(String vmUid, double mips);
/**
* Allocates MIPS for a given VM.
*
* @param vm virtual machine for which the MIPS are being allocated
* @param mips the mips for each virtual Pe
*
* @return $true if the MIPS could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
public abstract boolean allocateMipsForVm(Vm vm, List<Double> mips);
/**
* Gets allocated MIPS for a given VM.
*
* @param vm virtual machine for which the MIPS are being allocated
*
* @return array of allocated MIPS
*
* @pre $none
* @post $none
*/
public abstract List<Double> getAllocatedMipsForVm(Vm vm);
/**
* Gets total allocated MIPS for a given VM for all PEs.
*
* @param vm virtual machine for which the MIPS are being allocated
*
* @return total allocated MIPS
*
* @pre $none
* @post $none
*/
public abstract double getTotalAllocatedMipsForVm(Vm vm);
/**
* Gets allocated MIPS for a given VM for a given virtual Pe.
*
* @param vm virtual machine for which the MIPS are being allocated
* @param peId the pe id
*
* @return allocated MIPS
*
* @pre $none
* @post $none
*/
public abstract double getAllocatedMipsForVmByVirtualPeId(Vm vm, int peId);
/**
* Releases MIPS used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
public abstract void deallocateMipsForVm(Vm vm);
/**
* Releases MIPS used by all VMs.
*
* @pre $none
* @post none
*/
public void deallocateMipsForAllVms() {
setAvailableMips(getMips());
}
/**
* Gets the MIPS.
*
* @return the MIPS
*/
public double getMips() {
return mips;
}
/**
* Sets the MIPS.
*
* @param mips the MIPS to set
*/
public void setMips(double mips) {
this.mips = mips;
}
/**
* Gets the available MIPS in the PE.
*
* @return available MIPS
*
* @pre $none
* @post $none
*/
public double getAvailableMips() {
return availableMips;
}
/**
* Sets the available MIPS.
*
* @param availableMips the availableMips to set
*/
protected void setAvailableMips(double availableMips) {
this.availableMips = availableMips;
}
/**
* Gets the total allocated MIPS.
*
* @return the total allocated MIPS
*/
public double getTotalAllocatedMips() {
double totalAllocatedMips = getMips() - getAvailableMips();
if (totalAllocatedMips > 0) {
return totalAllocatedMips;
}
return 0;
}
/**
* Gets the utilization of the Pe in percents.
*
* @return the utilization
*/
public double getUtilization() {
return getTotalAllocatedMips() / getMips();
}
}

View File

@@ -0,0 +1,188 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.provisioners;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Vm;
/**
* The Class PeProvisionerSimple.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PeProvisionerSimple extends PeProvisioner {
/** The pe table. */
private Map<String, List<Double>> peTable;
/**
* Creates the PeProvisionerSimple object.
*
* @param availableMips the available mips
*
* @pre $none
* @post $none
*/
public PeProvisionerSimple(double availableMips) {
super(availableMips);
setPeTable(new HashMap<String, ArrayList<Double>>());
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#allocateMipsForVM(cloudsim.power.VM, int)
*/
@Override
public boolean allocateMipsForVm(Vm vm, double mips) {
return allocateMipsForVm(vm.getUid(), mips);
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#allocateMipsForVm(java.lang.String, double)
*/
@Override
public boolean allocateMipsForVm(String vmUid, double mips) {
if (getAvailableMips() < mips) {
return false;
}
List<Double> allocatedMips;
if (getPeTable().containsKey(vmUid)) {
allocatedMips = getPeTable().get(vmUid);
} else {
allocatedMips = new ArrayList<Double>();
}
allocatedMips.add(mips);
setAvailableMips(getAvailableMips() - mips);
getPeTable().put(vmUid, allocatedMips);
return true;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#allocateMipsForVM(cloudsim.power.VM,
* java.util.ArrayList)
*/
@Override
public boolean allocateMipsForVm(Vm vm, List<Double> mips) {
int totalMipsToAllocate = 0;
for (double _mips : mips) {
totalMipsToAllocate += _mips;
}
if (getAvailableMips() + getTotalAllocatedMipsForVm(vm) < totalMipsToAllocate) {
return false;
}
setAvailableMips(getAvailableMips() + getTotalAllocatedMipsForVm(vm) - totalMipsToAllocate);
getPeTable().put(vm.getUid(), mips);
return true;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#deallocateMipsForAllVms()
*/
@Override
public void deallocateMipsForAllVms() {
super.deallocateMipsForAllVms();
getPeTable().clear();
}
/*
* (non-Javadoc)
* @see
* cloudsim.provisioners.PeProvisioner#getAllocatedMipsForVMByVirtualPeId(cloudsim.power.VM,
* int)
*/
@Override
public double getAllocatedMipsForVmByVirtualPeId(Vm vm, int peId) {
if (getPeTable().containsKey(vm.getUid())) {
try {
return getPeTable().get(vm.getUid()).get(peId);
} catch (Exception e) {
}
}
return 0;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#getAllocatedMipsForVM(cloudsim.power.VM)
*/
@Override
public List<Double> getAllocatedMipsForVm(Vm vm) {
if (getPeTable().containsKey(vm.getUid())) {
return getPeTable().get(vm.getUid());
}
return null;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#getTotalAllocatedMipsForVM(cloudsim.power.VM)
*/
@Override
public double getTotalAllocatedMipsForVm(Vm vm) {
if (getPeTable().containsKey(vm.getUid())) {
double totalAllocatedMips = 0.0;
for (double mips : getPeTable().get(vm.getUid())) {
totalAllocatedMips += mips;
}
return totalAllocatedMips;
}
return 0;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.PeProvisioner#deallocateMipsForVM(cloudsim.power.VM)
*/
@Override
public void deallocateMipsForVm(Vm vm) {
if (getPeTable().containsKey(vm.getUid())) {
for (double mips : getPeTable().get(vm.getUid())) {
setAvailableMips(getAvailableMips() + mips);
}
getPeTable().remove(vm.getUid());
}
}
/**
* Gets the pe table.
*
* @return the peTable
*/
protected Map<String, List<Double>> getPeTable() {
return peTable;
}
/**
* Sets the pe table.
*
* @param peTable the peTable to set
*/
@SuppressWarnings("unchecked")
protected void setPeTable(Map<String, ? extends List<Double>> peTable) {
this.peTable = (Map<String, List<Double>>) peTable;
}
}

View File

@@ -0,0 +1,146 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.provisioners;
import org.cloudbus.cloudsim.Vm;
/**
* RamProvisioner is an abstract class that represents the provisioning policy of memory to virtual
* machines inside a Host. When extending this class, care must be taken to guarantee that the field
* availableMemory will always contain the amount of free memory available for future allocations.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public abstract class RamProvisioner {
/** The ram. */
private int ram;
/** The available ram. */
private int availableRam;
/**
* Creates the new RamProvisioner.
*
* @param ram the ram
*
* @pre ram>=0
* @post $none
*/
public RamProvisioner(int ram) {
setRam(ram);
setAvailableRam(ram);
}
/**
* Allocates RAM for a given VM.
*
* @param vm virtual machine for which the RAM are being allocated
* @param ram the RAM
*
* @return $true if the RAM could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
public abstract boolean allocateRamForVm(Vm vm, int ram);
/**
* Gets the allocated RAM for VM.
*
* @param vm the VM
*
* @return the allocated RAM for vm
*/
public abstract int getAllocatedRamForVm(Vm vm);
/**
* Releases BW used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
public abstract void deallocateRamForVm(Vm vm);
/**
* Releases BW used by a all VMs.
*
* @pre $none
* @post none
*/
public void deallocateRamForAllVms() {
setAvailableRam(getRam());
}
/**
* Checks if is suitable for vm.
*
* @param vm the vm
* @param ram the ram
*
* @return true, if is suitable for vm
*/
public abstract boolean isSuitableForVm(Vm vm, int ram);
/**
* Gets the ram.
*
* @return the ram
*/
public int getRam() {
return ram;
}
/**
* Sets the ram.
*
* @param ram the ram to set
*/
protected void setRam(int ram) {
this.ram = ram;
}
/**
* Gets the amount of used RAM in the host.
*
* @return used ram
*
* @pre $none
* @post $none
*/
public int getUsedRam() {
return ram - availableRam;
}
/**
* Gets the available RAM in the host.
*
* @return available ram
*
* @pre $none
* @post $none
*/
public int getAvailableRam() {
return availableRam;
}
/**
* Sets the available ram.
*
* @param availableRam the availableRam to set
*/
protected void setAvailableRam(int availableRam) {
this.availableRam = availableRam;
}
}

View File

@@ -0,0 +1,133 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.provisioners;
import java.util.HashMap;
import java.util.Map;
import org.cloudbus.cloudsim.Vm;
/**
* RamProvisionerSimple is an extension of RamProvisioner which uses a best-effort policy to
* allocate memory to a VM.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public class RamProvisionerSimple extends RamProvisioner {
/** The RAM table. */
private Map<String, Integer> ramTable;
/**
* Instantiates a new ram provisioner simple.
*
* @param availableRam the available ram
*/
public RamProvisionerSimple(int availableRam) {
super(availableRam);
setRamTable(new HashMap<String, Integer>());
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.RamProvisioner#allocateRamForVm(cloudsim.Vm, int)
*/
@Override
public boolean allocateRamForVm(Vm vm, int ram) {
int maxRam = vm.getRam();
if (ram >= maxRam) {
ram = maxRam;
}
deallocateRamForVm(vm);
if (getAvailableRam() >= ram) {
setAvailableRam(getAvailableRam() - ram);
getRamTable().put(vm.getUid(), ram);
vm.setCurrentAllocatedRam(getAllocatedRamForVm(vm));
return true;
}
vm.setCurrentAllocatedRam(getAllocatedRamForVm(vm));
return false;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.RamProvisioner#getAllocatedRamForVm(cloudsim.Vm)
*/
@Override
public int getAllocatedRamForVm(Vm vm) {
if (getRamTable().containsKey(vm.getUid())) {
return getRamTable().get(vm.getUid());
}
return 0;
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.RamProvisioner#deallocateRamForVm(cloudsim.Vm)
*/
@Override
public void deallocateRamForVm(Vm vm) {
if (getRamTable().containsKey(vm.getUid())) {
int amountFreed = getRamTable().remove(vm.getUid());
setAvailableRam(getAvailableRam() + amountFreed);
vm.setCurrentAllocatedRam(0);
}
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.RamProvisioner#deallocateRamForVm(cloudsim.Vm)
*/
@Override
public void deallocateRamForAllVms() {
super.deallocateRamForAllVms();
getRamTable().clear();
}
/*
* (non-Javadoc)
* @see cloudsim.provisioners.RamProvisioner#isSuitableForVm(cloudsim.Vm, int)
*/
@Override
public boolean isSuitableForVm(Vm vm, int ram) {
int allocatedRam = getAllocatedRamForVm(vm);
boolean result = allocateRamForVm(vm, ram);
deallocateRamForVm(vm);
if (allocatedRam > 0) {
allocateRamForVm(vm, allocatedRam);
}
return result;
}
/**
* Gets the ram table.
*
* @return the ram table
*/
protected Map<String, Integer> getRamTable() {
return ramTable;
}
/**
* Sets the ram table.
*
* @param ramTable the ram table
*/
protected void setRamTable(Map<String, Integer> ramTable) {
this.ramTable = ramTable;
}
}