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,91 @@
/*
* 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.lists;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.cloudbus.cloudsim.Cloudlet;
/**
* CloudletList is a collection of operations on lists of Cloudlets.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class CloudletList {
/**
* Gets the by id.
*
* @param cloudletList the cloudlet list
* @param id the id
* @return the by id
*/
public static <T extends Cloudlet> T getById(List<T> cloudletList, int id) {
for (T cloudlet : cloudletList) {
if (cloudlet.getCloudletId() == id) {
return cloudlet;
}
}
return null;
}
/**
* Returns the position of the cloudlet with that id, if it exists. Otherwise -1.
* @param cloudletList - the list of cloudlets.
* @param id - the id we search for.
* @return - the position of the cloudlet with that id, or -1 otherwise.
*/
public static <T extends Cloudlet> int getPositionById(List<T> cloudletList, int id) {
int i = 0 ;
for (T cloudlet : cloudletList) {
if (cloudlet.getCloudletId() == id) {
return i;
}
i++;
}
return -1;
}
/**
* Sorts the Cloudlets in a list based on their lengths.
*
* @param cloudletList the cloudlet list
* @pre $none
* @post $none
*/
public static <T extends Cloudlet> void sort(List<T> cloudletList) {
Collections.sort(cloudletList, new Comparator<T>() {
/**
* Compares two objects.
*
* @param a the first Object to be compared
* @param b the second Object to be compared
* @return the value 0 if both Objects are numerically equal; a value less than 0 if the
* first Object is numerically less than the second Object; and a value greater
* than 0 if the first Object is numerically greater than the second Object.
* @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected to be of type
* <tt>Cloudlet</tt>
* @pre a != null
* @pre b != null
* @post $none
*/
@Override
public int compare(T a, T b) throws ClassCastException {
Double cla = Double.valueOf(a.getCloudletTotalLength());
Double clb = Double.valueOf(b.getCloudletTotalLength());
return cla.compareTo(clb);
}
});
}
}

View File

@@ -0,0 +1,148 @@
/*
* 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.lists;
import java.util.List;
import org.cloudbus.cloudsim.Host;
/**
* HostList is a collection of operations on lists of hosts.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class HostList {
/**
* Gets the Machine object for a particular ID.
*
* @param <T> the generic type
* @param hostList the host list
* @param id the host ID
* @return the Machine object or <tt>null</tt> if no machine exists
* @see gridsim.Machine
* @pre id >= 0
* @post $none
*/
public static <T extends Host> T getById(List<T> hostList, int id) {
for (T host : hostList) {
if (host.getId() == id) {
return host;
}
}
return null;
}
/**
* Gets the total number of PEs for all Machines.
*
* @param <T> the generic type
* @param hostList the host list
* @return number of PEs
* @pre $none
* @post $result >= 0
*/
public static <T extends Host> int getNumberOfPes(List<T> hostList) {
int numberOfPes = 0;
for (T host : hostList) {
numberOfPes += host.getPeList().size();
}
return numberOfPes;
}
/**
* Gets the total number of <tt>FREE</tt> or non-busy PEs for all Machines.
*
* @param <T> the generic type
* @param hostList the host list
* @return number of PEs
* @pre $none
* @post $result >= 0
*/
public static <T extends Host> int getNumberOfFreePes(List<T> hostList) {
int numberOfFreePes = 0;
for (T host : hostList) {
numberOfFreePes += PeList.getNumberOfFreePes(host.getPeList());
}
return numberOfFreePes;
}
/**
* Gets the total number of <tt>BUSY</tt> PEs for all Machines.
*
* @param <T> the generic type
* @param hostList the host list
* @return number of PEs
* @pre $none
* @post $result >= 0
*/
public static <T extends Host> int getNumberOfBusyPes(List<T> hostList) {
int numberOfBusyPes = 0;
for (T host : hostList) {
numberOfBusyPes += PeList.getNumberOfBusyPes(host.getPeList());
}
return numberOfBusyPes;
}
/**
* Gets a Machine with free Pe.
*
* @param <T> the generic type
* @param hostList the host list
* @return a machine object or <tt>null</tt> if not found
* @pre $none
* @post $none
*/
public static <T extends Host> T getHostWithFreePe(List<T> hostList) {
return getHostWithFreePe(hostList, 1);
}
/**
* Gets a Machine with a specified number of free Pe.
*
* @param <T> the generic type
* @param hostList the host list
* @param pesNumber the pes number
* @return a machine object or <tt>null</tt> if not found
* @pre $none
* @post $none
*/
public static <T extends Host> T getHostWithFreePe(List<T> hostList, int pesNumber) {
for (T host : hostList) {
if (PeList.getNumberOfFreePes(host.getPeList()) >= pesNumber) {
return host;
}
}
return null;
}
/**
* Sets the particular Pe status on a Machine.
*
* @param <T> the generic type
* @param hostList the host list
* @param status Pe status, either <tt>Pe.FREE</tt> or <tt>Pe.BUSY</tt>
* @param hostId the host id
* @param peId the pe id
* @return <tt>true</tt> if the Pe status has changed, <tt>false</tt> otherwise (Machine id or
* Pe id might not be exist)
* @pre machineID >= 0
* @pre peID >= 0
* @post $none
*/
public static <T extends Host> boolean setPeStatus(List<T> hostList, int status, int hostId, int peId) {
T host = getById(hostList, hostId);
if (host == null) {
return false;
}
return host.setPeStatus(peId, status);
}
}

View File

@@ -0,0 +1,230 @@
/*
* 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.lists;
import java.util.List;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Vm;
/**
* PeList is a collection of operations on lists of PEs.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PeList {
/**
* Gets MIPS Rating for a specified Pe ID.
*
* @param id the Pe ID
* @param peList the pe list
* @return the MIPS rating if exists, otherwise returns -1
* @pre id >= 0
* @post $none
*/
public static <T extends Pe> Pe getById(List<T> peList, int id) {
for (Pe pe : peList) {
if (pe.getId() == id) {
return pe;
}
}
return null;
}
/**
* Gets MIPS Rating for a specified Pe ID.
*
* @param id the Pe ID
* @param peList the pe list
* @return the MIPS rating if exists, otherwise returns -1
* @pre id >= 0
* @post $none
*/
public static <T extends Pe> int getMips(List<T> peList, int id) {
Pe pe = getById(peList, id);
if (pe != null) {
return pe.getMips();
}
return -1;
}
/**
* Gets total MIPS Rating for all PEs.
*
* @param peList the pe list
* @return the total MIPS Rating
* @pre $none
* @post $none
*/
public static <T extends Pe> int getTotalMips(List<T> peList) {
int totalMips = 0;
for (Pe pe : peList) {
totalMips += pe.getMips();
}
return totalMips;
}
/**
* Gets the max utilization among by all PEs.
*
* @param peList the pe list
* @return the utilization
*/
public static <T extends Pe> double getMaxUtilization(List<T> peList) {
double maxUtilization = 0;
for (Pe pe : peList) {
double utilization = pe.getPeProvisioner().getUtilization();
if (utilization > maxUtilization) {
maxUtilization = utilization;
}
}
return maxUtilization;
}
/**
* Gets the max utilization among by all PEs allocated to the VM.
*
* @param vm the vm
* @param peList the pe list
* @return the utilization
*/
public static <T extends Pe> double getMaxUtilizationAmongVmsPes(List<T> peList, Vm vm) {
double maxUtilization = 0;
for (Pe pe : peList) {
if (pe.getPeProvisioner().getAllocatedMipsForVm(vm) == null) {
continue;
}
double utilization = pe.getPeProvisioner().getUtilization();
if (utilization > maxUtilization) {
maxUtilization = utilization;
}
}
return maxUtilization;
}
/**
* Gets a Pe ID which is FREE.
*
* @param peList the pe list
* @return a Pe ID if it is FREE, otherwise returns -1
* @pre $none
* @post $none
*/
public static <T extends Pe> Pe getFreePe(List<T> peList) {
for (Pe pe : peList) {
if (pe.getStatus() == Pe.FREE) {
return pe;
}
}
return null;
}
/**
* Gets the number of <tt>FREE</tt> or non-busy Pe.
*
* @param peList the pe list
* @return number of Pe
* @pre $none
* @post $result >= 0
*/
public static <T extends Pe> int getNumberOfFreePes(List<T> peList) {
int cnt = 0;
for (Pe pe : peList) {
if (pe.getStatus() == Pe.FREE) {
cnt++;
}
}
return cnt;
}
/**
* Sets the Pe status.
*
* @param status Pe status, either <tt>Pe.FREE</tt> or <tt>Pe.BUSY</tt>
* @param id the id
* @param peList the pe list
* @return <tt>true</tt> if the Pe status has been changed, <tt>false</tt> otherwise (Pe id might
* not be exist)
* @pre peID >= 0
* @post $none
*/
public static <T extends Pe> boolean setPeStatus(List<T> peList, int id, int status) {
Pe pe = getById(peList, id);
if (pe != null) {
pe.setStatus(status);
return true;
}
return false;
}
/**
* Gets the number of <tt>BUSY</tt> Pe.
*
* @param peList the pe list
* @return number of Pe
* @pre $none
* @post $result >= 0
*/
public static <T extends Pe> int getNumberOfBusyPes(List<T> peList) {
int cnt = 0;
for (Pe pe : peList) {
if (pe.getStatus() == Pe.BUSY) {
cnt++;
}
}
return cnt;
}
/**
* Sets the status of PEs of this machine to FAILED. NOTE: <tt>resName</tt> and
* <tt>machineID</tt> are used for debugging purposes, which is <b>ON</b> by default. Use
* {@link #setStatusFailed(boolean)} if you do not want this information.
*
* @param resName the name of the resource
* @param hostId the id of this machine
* @param failed the new value for the "failed" parameter
*/
public static <T extends Pe> void setStatusFailed(
List<T> peList,
String resName,
int hostId,
boolean failed) {
String status = null;
if (failed) {
status = "FAILED";
} else {
status = "WORKING";
}
Log.printLine(resName + " - Machine: " + hostId + " is " + status);
setStatusFailed(peList, failed);
}
/**
* Sets the status of PEs of this machine to FAILED.
*
* @param failed the new value for the "failed" parameter
* @param peList the pe list
*/
public static <T extends Pe> void setStatusFailed(List<T> peList, boolean failed) {
// a loop to set the status of all the PEs in this machine
for (Pe pe : peList) {
if (failed) {
pe.setStatus(Pe.FAILED);
} else {
pe.setStatus(Pe.FREE);
}
}
}
}

View File

@@ -0,0 +1,108 @@
/*
* 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.lists;
import java.util.List;
import org.cloudbus.cloudsim.ResCloudlet;
/**
* ResCloudletList is a collection of operations on lists of ResCloudlets.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class ResCloudletList {
/**
* Returns a given Cloudlet. This method needs a combination of Cloudlet Id and User Id because
* each Cloud Users might have exactly same Cloudlet Ids.
*
* @param cloudletId a Cloudlet Id
* @param userId an User Id
* @param list the list
* @return the Cloudlet.
* @throws IndexOutOfBoundsException - if a Cloudlet with specified Id and user id is not in the
* list.
* @pre cloudletId >= 0
* @pre userId >= 0
* @post $none
*/
public static <T extends ResCloudlet> ResCloudlet getByIdAndUserId(
List<T> list,
int cloudletId,
int userId) {
for (T rcl : list) {
if (rcl.getCloudletId() == cloudletId && rcl.getUserId() == userId) {
return rcl;
}
}
return null;
}
/**
* Finds the index of a Cloudlet inside the list. This method needs a combination of Cloudlet Id
* and User Id because each Cloud User might have exactly the same Cloudlet Id.
*
* @param cloudletId a Cloudlet Id
* @param userId an User Id
* @param list the list
* @return the index in this list of the first occurrence of the specified Cloudlet, or
* <code>-1</code> if the list does not contain this Cloudlet.
* @pre cloudletId >= 0
* @pre userId >= 0
* @post $none
*/
public static <T extends ResCloudlet> int indexOf(List<T> list, int cloudletId, int userId) {
int i = 0;
for (T rcl : list) {
if (rcl.getCloudletId() == cloudletId && rcl.getUserId() == userId) {
return i;
}
i++;
}
return -1;
}
/**
* Move a ResCloudlet object from this linked-list into a specified one.
*
* @param listFrom the list from
* @param listTo the list to
* @param cloudlet the cloudlet
* @return <b>true</b> if the moving operation successful, otherwise return <b>false</b>
* @pre obj != null
* @pre list != null
* @post $result == true || $result == false
*/
public static <T extends ResCloudlet> boolean move(List<T> listFrom, List<T> listTo, T cloudlet) {
if (listFrom.remove(cloudlet)) {
listTo.add(cloudlet);
return true;
}
return false;
}
/**
* Returns the position of the cloudlet with that id, if it exists. Otherwise -1.
* @param cloudletList - the list of cloudlets.
* @param id - the id we search for.
* @return - the position of the cloudlet with that id, or -1 otherwise.
*/
public static <T extends ResCloudlet> int getPositionById(List<T> cloudletList, int id) {
int i = 0 ;
for (T cloudlet : cloudletList) {
if (cloudlet.getCloudletId() == id) {
return i;
}
i++;
}
return -1;
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.lists;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
/**
* VmList is a collection of operations on lists of VMs.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class VmList {
/**
* Return a reference to a Vm object from its ID.
*
* @param id ID of required VM
* @param vmList the vm list
* @return Vm with the given ID, $null if not found
* @pre $none
* @post $none
*/
public static <T extends Vm> T getById(List<T> vmList, int id) {
for (T vm : vmList) {
if (vm.getId() == id) {
return vm;
}
}
return null;
}
/**
* Return a reference to a Vm object from its ID and user ID.
*
* @param id ID of required VM
* @param userId the user ID
* @param vmList the vm list
* @return Vm with the given ID, $null if not found
* @pre $none
* @post $none
*/
public static <T extends Vm> T getByIdAndUserId(List<T> vmList, int id, int userId) {
for (T vm : vmList) {
if (vm.getId() == id && vm.getUserId() == userId) {
return vm;
}
}
return null;
}
}