Commit 09118073 authored by rodrigo.calheiros's avatar rodrigo.calheiros

Issues solved: 2, 5, 9, 10, 19

Issue solution not tested: 8
parent 656e4f68
...@@ -88,9 +88,15 @@ public class CloudSimExample1 { ...@@ -88,9 +88,15 @@ public class CloudSimExample1 {
// create VM // create VM
Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
Vm vm1 = new Vm(1, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
Vm vm2 = new Vm(2, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
// add the VM to the vmList // add the VM to the vmList
vmlist.add(vm); vmlist.add(vm);
vmlist.add(vm1);
vmlist.add(vm2);
// submit vm list to the broker // submit vm list to the broker
broker.submitVmList(vmlist); broker.submitVmList(vmlist);
...@@ -108,9 +114,21 @@ public class CloudSimExample1 { ...@@ -108,9 +114,21 @@ public class CloudSimExample1 {
Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet.setUserId(brokerId); cloudlet.setUserId(brokerId);
cloudlet.setVmId(vmid); cloudlet.setVmId(vmid);
Cloudlet cloudlet1 = new Cloudlet(1, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet1.setUserId(brokerId);
cloudlet1.setVmId(1);
Cloudlet cloudlet2 = new Cloudlet(2, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet2.setUserId(brokerId);
cloudlet2.setVmId(2);
// add the cloudlet to the list // add the cloudlet to the list
cloudletList.add(cloudlet); cloudletList.add(cloudlet);
cloudletList.add(cloudlet1);
cloudletList.add(cloudlet2);
// submit cloudlet list to the broker // submit cloudlet list to the broker
broker.submitCloudletList(cloudletList); broker.submitCloudletList(cloudletList);
......
...@@ -18,6 +18,7 @@ import java.util.Map.Entry; ...@@ -18,6 +18,7 @@ import java.util.Map.Entry;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerDynamicWorkload; import org.cloudbus.cloudsim.CloudletSchedulerDynamicWorkload;
import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared;
import org.cloudbus.cloudsim.DatacenterBroker; import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics; import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log; import org.cloudbus.cloudsim.Log;
...@@ -48,9 +49,9 @@ public class DVFS { ...@@ -48,9 +49,9 @@ public class DVFS {
/** The vm list. */ /** The vm list. */
private static List<Vm> vmList; private static List<Vm> vmList;
private static double hostsNumber = 10; private static double hostsNumber = 2;
private static double vmsNumber = 20; private static double vmsNumber = 10;
private static double cloudletsNumber = 20; private static double cloudletsNumber = 10;
/** /**
* Creates main() to run this example. * Creates main() to run this example.
...@@ -109,7 +110,7 @@ public class DVFS { ...@@ -109,7 +110,7 @@ public class DVFS {
int totalTotalRequested = 0; int totalTotalRequested = 0;
int totalTotalAllocated = 0; int totalTotalAllocated = 0;
ArrayList<Double> sla = new ArrayList<Double>(); ArrayList<Double> sla = new ArrayList<Double>();
int numberOfAllocations = 0; /*int numberOfAllocations = 0;
for (Entry<String, List<List<Double>>> entry : datacenter.getUnderAllocatedMips().entrySet()) { for (Entry<String, List<List<Double>>> entry : datacenter.getUnderAllocatedMips().entrySet()) {
List<List<Double>> underAllocatedMips = entry.getValue(); List<List<Double>> underAllocatedMips = entry.getValue();
double totalRequested = 0; double totalRequested = 0;
...@@ -127,7 +128,7 @@ public class DVFS { ...@@ -127,7 +128,7 @@ public class DVFS {
} }
totalTotalRequested += totalRequested; totalTotalRequested += totalRequested;
totalTotalAllocated += totalAllocated; totalTotalAllocated += totalAllocated;
} }*/
double averageSla = 0; double averageSla = 0;
if (sla.size() > 0) { if (sla.size() > 0) {
...@@ -167,7 +168,7 @@ public class DVFS { ...@@ -167,7 +168,7 @@ public class DVFS {
List<Cloudlet> list = new ArrayList<Cloudlet>(); List<Cloudlet> list = new ArrayList<Cloudlet>();
long length = 150000; // 10 min on 250 MIPS long length = 150000; // 10 min on 250 MIPS
int pesNumber = 1; int pesNumber = 2;
long fileSize = 300; long fileSize = 300;
long outputSize = 300; long outputSize = 300;
...@@ -201,8 +202,7 @@ public class DVFS { ...@@ -201,8 +202,7 @@ public class DVFS {
for (int i = 0; i < vmsNumber; i++) { for (int i = 0; i < vmsNumber; i++) {
vms.add( vms.add(
new Vm(i, brokerId, mips[i % mips.length], pesNumber, ram, bw, size, vmm, new CloudletSchedulerDynamicWorkload(mips[i % mips.length], pesNumber)) new Vm(i, brokerId, mips[i % mips.length], pesNumber, ram, bw, size, vmm, new CloudletSchedulerSpaceShared()));
);
} }
return vms; return vms;
......
...@@ -376,7 +376,6 @@ public class CloudletSchedulerSpaceShared extends CloudletScheduler { ...@@ -376,7 +376,6 @@ public class CloudletSchedulerSpaceShared extends CloudletScheduler {
for (int i = 0; i < cloudlet.getPesNumber(); i++) { for (int i = 0; i < cloudlet.getPesNumber(); i++) {
rcl.setMachineAndPeId(0, i); rcl.setMachineAndPeId(0, i);
} }
getCloudletExecList().add(rcl); getCloudletExecList().add(rcl);
usedPes += cloudlet.getPesNumber(); usedPes += cloudlet.getPesNumber();
} else {// no enough free PEs: go to the waiting queue } else {// no enough free PEs: go to the waiting queue
......
...@@ -471,7 +471,7 @@ public class Datacenter extends SimEntity { ...@@ -471,7 +471,7 @@ public class Datacenter extends SimEntity {
} else { } else {
data[2] = CloudSimTags.FALSE; data[2] = CloudSimTags.FALSE;
} }
sendNow(vm.getUserId(), CloudSimTags.VM_CREATE_ACK, data); send(vm.getUserId(), 0.1, CloudSimTags.VM_CREATE_ACK, data);
} }
if (result) { if (result) {
...@@ -909,7 +909,7 @@ public class Datacenter extends SimEntity { ...@@ -909,7 +909,7 @@ public class Datacenter extends SimEntity {
* @post $none * @post $none
*/ */
protected void updateCloudletProcessing() { protected void updateCloudletProcessing() {
//Log.printLine(CloudSim.clock()+": PowerDatacenter #"+this.get_id()+": updating cloudlet processing......................................."); //Log.printLine(CloudSim.clock()+": PowerDatacenter #: updating cloudlet processing.......................................");
//if some time passed since last processing //if some time passed since last processing
if (CloudSim.clock() > this.getLastProcessTime()+0.1) { if (CloudSim.clock() > this.getLastProcessTime()+0.1) {
List<? extends Host> list = getVmAllocationPolicy().getHostList(); List<? extends Host> list = getVmAllocationPolicy().getHostList();
......
...@@ -33,46 +33,44 @@ import org.cloudbus.cloudsim.lists.VmList; ...@@ -33,46 +33,44 @@ import org.cloudbus.cloudsim.lists.VmList;
*/ */
public class DatacenterBroker extends SimEntity { public class DatacenterBroker extends SimEntity {
// TODO: remove unnecessary variables
/** The vm list. */ /** The vm list. */
private List<? extends Vm> vmList; protected List<? extends Vm> vmList;
/** The vms created list. */ /** The vms created list. */
private List<? extends Vm> vmsCreatedList; protected List<? extends Vm> vmsCreatedList;
/** The cloudlet list. */ /** The cloudlet list. */
private List<? extends Cloudlet> cloudletList; protected List<? extends Cloudlet> cloudletList;
/** The cloudlet submitted list. */ /** The cloudlet submitted list. */
private List<? extends Cloudlet> cloudletSubmittedList; protected List<? extends Cloudlet> cloudletSubmittedList;
/** The cloudlet received list. */ /** The cloudlet received list. */
private List<? extends Cloudlet> cloudletReceivedList; protected List<? extends Cloudlet> cloudletReceivedList;
/** The cloudlets submitted. */ /** The cloudlets submitted. */
private int cloudletsSubmitted; protected int cloudletsSubmitted;
/** The vms requested. */ /** The vms requested. */
private int vmsRequested; protected int vmsRequested;
/** The vms acks. */ /** The vms acks. */
private int vmsAcks; protected int vmsAcks;
/** The vms destroyed. */ /** The vms destroyed. */
private int vmsDestroyed; protected int vmsDestroyed;
/** The datacenter ids list. */ /** The datacenter ids list. */
private List<Integer> datacenterIdsList; protected List<Integer> datacenterIdsList;
/** The datacenter requested ids list. */ /** The datacenter requested ids list. */
private List<Integer> datacenterRequestedIdsList; protected List<Integer> datacenterRequestedIdsList;
/** The vms to datacenters map. */ /** The vms to datacenters map. */
private Map<Integer, Integer> vmsToDatacentersMap; protected Map<Integer, Integer> vmsToDatacentersMap;
/** The datacenter characteristics list. */ /** The datacenter characteristics list. */
private Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList; protected Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList;
/** /**
...@@ -396,7 +394,7 @@ public class DatacenterBroker extends SimEntity { ...@@ -396,7 +394,7 @@ public class DatacenterBroker extends SimEntity {
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
private void finishExecution() { protected void finishExecution() {
sendNow(getId(), CloudSimTags.END_OF_SIMULATION); sendNow(getId(), CloudSimTags.END_OF_SIMULATION);
} }
......
...@@ -452,7 +452,7 @@ public class DatacenterCharacteristics { ...@@ -452,7 +452,7 @@ public class DatacenterCharacteristics {
* *
* @return the id * @return the id
*/ */
protected int getId() { public int getId() {
return id; return id;
} }
...@@ -545,7 +545,7 @@ public class DatacenterCharacteristics { ...@@ -545,7 +545,7 @@ public class DatacenterCharacteristics {
* *
* @return the cost per second * @return the cost per second
*/ */
protected double getCostPerSecond() { public double getCostPerSecond() {
return costPerSecond; return costPerSecond;
} }
......
...@@ -151,11 +151,11 @@ public class Vm { ...@@ -151,11 +151,11 @@ public class Vm {
List<Double> currentRequestedMips = getCloudletScheduler().getCurrentRequestedMips(); List<Double> currentRequestedMips = getCloudletScheduler().getCurrentRequestedMips();
if (isRecentlyCreated()) { if (isRecentlyCreated()) {
boolean mipsIsNull = true; //boolean mipsIsNull = true;
if (CloudSim.clock() > 0) { //if (CloudSim.clock() > 0) {
mipsIsNull = false; //mipsIsNull = false;
setRecentlyCreated(false); setRecentlyCreated(false);
} //}
// for (double mips : currentRequestedMips) { // for (double mips : currentRequestedMips) {
// if (mips > 0.0) { // if (mips > 0.0) {
// mipsIsNull = false; // mipsIsNull = false;
...@@ -165,14 +165,13 @@ public class Vm { ...@@ -165,14 +165,13 @@ public class Vm {
// } // }
//if (mipsIsNull && isRecentlyCreated()) { //if (mipsIsNull && isRecentlyCreated()) {
if (mipsIsNull) { //if (mipsIsNull) {
currentRequestedMips = new ArrayList<Double>(); currentRequestedMips = new ArrayList<Double>();
for (int i = 0; i < getPesNumber(); i++) { for (int i = 0; i < getPesNumber(); i++) {
currentRequestedMips.add(getMips()); currentRequestedMips.add(getMips());
} }
} //}
} }
return currentRequestedMips; return currentRequestedMips;
} }
......
...@@ -232,6 +232,12 @@ public class VmAllocationPolicySimple extends VmAllocationPolicy { ...@@ -232,6 +232,12 @@ public class VmAllocationPolicySimple extends VmAllocationPolicy {
public boolean allocateHostForVm(Vm vm, Host host) { public boolean allocateHostForVm(Vm vm, Host host) {
if (host.vmCreate(vm)) { //if vm has been succesfully created in the host if (host.vmCreate(vm)) { //if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), host); getVmTable().put(vm.getUid(), host);
int requiredPes = vm.getPesNumber();
int idx = getHostList().indexOf(host);
getUsedPes().put(vm.getUid(), requiredPes);
getFreePes().set(idx, getFreePes().get(idx) - requiredPes);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock()); Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock());
return true; return true;
} }
......
...@@ -77,7 +77,6 @@ public class VmSchedulerSpaceShared extends VmScheduler { ...@@ -77,7 +77,6 @@ public class VmSchedulerSpaceShared extends VmScheduler {
getPeAllocationMap().put(vm.getUid(), selectedPes); getPeAllocationMap().put(vm.getUid(), selectedPes);
getMipsMap().put(vm.getUid(), mipsShare); getMipsMap().put(vm.getUid(), mipsShare);
setAvailableMips(getAvailableMips() - totalMips); setAvailableMips(getAvailableMips() - totalMips);
return true; return true;
} }
......
...@@ -89,7 +89,7 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -89,7 +89,7 @@ public class VmSchedulerTimeShared extends VmScheduler {
} }
totalRequestedMips += mips; totalRequestedMips += mips;
} }
if (getVmsMigratingIn().contains(vmUid)) { if (getVmsMigratingIn().contains(vmUid)) {
totalRequestedMips *= 0.1; // performance cost incurred by the destination host = 10% MIPS totalRequestedMips *= 0.1; // performance cost incurred by the destination host = 10% MIPS
} }
...@@ -166,10 +166,12 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -166,10 +166,12 @@ public class VmSchedulerTimeShared extends VmScheduler {
Pe pe = peIterator.next(); Pe pe = peIterator.next();
PeProvisioner peProvisioner = pe.getPeProvisioner(); PeProvisioner peProvisioner = pe.getPeProvisioner();
double availableMips = peProvisioner.getAvailableMips(); double availableMips = peProvisioner.getAvailableMips();
for (Map.Entry<String, List<Double>> entry : getMipsMap().entrySet()) { for (Map.Entry<String, List<Double>> entry : getMipsMap().entrySet()) {
String vmUid = entry.getKey(); String vmUid = entry.getKey();
getPeMap().put(vmUid, new LinkedList<Pe>()); getPeMap().put(vmUid, new LinkedList<Pe>());
for (double mips : entry.getValue()) { for (double mips : entry.getValue()) {
System.out.println("=> mips:"+mips);
while (mips >= 0.1) { while (mips >= 0.1) {
if (availableMips >= mips) { if (availableMips >= mips) {
peProvisioner.allocateMipsForVm(vmUid, mips); peProvisioner.allocateMipsForVm(vmUid, mips);
......
...@@ -58,7 +58,10 @@ public class CloudSim { ...@@ -58,7 +58,10 @@ public class CloudSim {
private static boolean traceFlag = false; private static boolean traceFlag = false;
/** The calendar. */ /** The calendar. */
private static Calendar calendar = null; private static Calendar calendar = null;
/** The termination time. */
private static long terminateAt = -1;
/** /**
* Initialises all the common attributes. * Initialises all the common attributes.
...@@ -189,6 +192,34 @@ public class CloudSim { ...@@ -189,6 +192,34 @@ public class CloudSim {
+ "Error - can't stop Cloud Simulation."); + "Error - can't stop Cloud Simulation.");
} }
} }
/**
* This method is called if one wants to terminate the simulation.
*
* @return true, if successful; false otherwise.
*/
public static boolean terminateSimulation() {
running = false;
printMessage("Simulation: Reached termination time.");
return true;
}
/**
* This method is called if one wants to terminate the simulation at a
* given time.
*
* @param time the time at which the simulation has to be terminated
* @return true, if successful
* otherwise.
*/
public static boolean terminateSimulation(long time) {
if (time <= clock) {
return false;
} else {
terminateAt = time;
}
return true;
}
/** /**
* Gets a new copy of initial simulation Calendar. * Gets a new copy of initial simulation Calendar.
...@@ -830,6 +861,13 @@ public class CloudSim { ...@@ -830,6 +861,13 @@ public class CloudSim {
if (runClockTick() || abruptTerminate) { if (runClockTick() || abruptTerminate) {
break; break;
} }
//this block allows termination of simulation at a specific time
if (terminateAt != -1 && clock >= terminateAt) {
terminateSimulation();
clock = terminateAt;
break;
}
if (pauseAt != -1 && ((future.size() > 0 && clock <= pauseAt && pauseAt <= future.iterator().next().eventTime()) || future.size() == 0 && pauseAt <= clock)) { if (pauseAt != -1 && ((future.size() > 0 && clock <= pauseAt && pauseAt <= future.iterator().next().eventTime()) || future.size() == 0 && pauseAt <= clock)) {
pauseSimulation(); pauseSimulation();
......
...@@ -20,7 +20,7 @@ package org.cloudbus.cloudsim.core; ...@@ -20,7 +20,7 @@ package org.cloudbus.cloudsim.core;
* @author Anthony Sulistio * @author Anthony Sulistio
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 1.0
*/ */
public final class CloudSimTags { public class CloudSimTags {
// starting constant value for cloud-related tags // starting constant value for cloud-related tags
private static final int BASE = 0; private static final int BASE = 0;
...@@ -388,6 +388,17 @@ public final class CloudSimTags { ...@@ -388,6 +388,17 @@ public final class CloudSimTags {
* Denotes an internal event generated in a Broker * Denotes an internal event generated in a Broker
*/ */
public static final int VM_BROKER_EVENT = BASE + 42; public static final int VM_BROKER_EVENT = BASE + 42;
public static final int Network_Event_UP=BASE+43;
public static final int Network_Event_send=BASE+44;
public static final int RESOURCE_Register = BASE+45;
public static final int Network_Event_DOWN = BASE+46;
public static final int Network_Event_Host = BASE+47;
public static final int NextCycle = BASE+48;
// ///////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////
......
...@@ -68,6 +68,8 @@ public class PeProvisionerSimple extends PeProvisioner { ...@@ -68,6 +68,8 @@ public class PeProvisionerSimple extends PeProvisioner {
setAvailableMips(getAvailableMips() - mips); setAvailableMips(getAvailableMips() - mips);
getPeTable().put(vmUid, allocatedMips); getPeTable().put(vmUid, allocatedMips);
System.out.print("MIPS allocated for vm "+vmUid+" :");
for (double m:allocatedMips) System.out.print(" "+m+" "); System.out.println();
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment