Documentation Added with Some updates on Code.

parent ecd0ad0b
...@@ -9,99 +9,131 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -9,99 +9,131 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
public class AggregateSwitch extends Switch{ /**
* This class allows to simulate aggregate switch for Datacenter network.
* It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM International
* Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA),
* Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*
*/
public class AggregateSwitch extends Switch {
/**
* Constructor for Aggregate Switch
* We have to specify switches that are connected to its downlink and uplink ports,
* and corresponding bandwidths
*
* @param name Name of the switch
* @param level At which level switch is with respect to hosts.
* @param dc Pointer to Datacenter
*/
public AggregateSwitch(String name, int level, NetworkDatacenter dc) { public AggregateSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc); super(name, level, dc);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
uplinkbandwidth=Constants.BandWidthAggRoot;
downlinkbandwidth=Constants.BandWidthEdgeAgg;
latency=Constants.SwitchingDelayAgg;
numport=Constants.AggSwitchPort;
uplinkswitches=new ArrayList<Switch>();
downlinkswitches=new ArrayList<Switch>();
}
downlinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
private void processpacket_down(SimEvent ev) { uplinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
// TODO Auto-generated method stub uplinkbandwidth = NetworkConstants.BandWidthAggRoot;
//packet coming from up level router. downlinkbandwidth = NetworkConstants.BandWidthEdgeAgg;
//has to send downward latency = NetworkConstants.SwitchingDelayAgg;
//check which switch to forward to numport = NetworkConstants.AggSwitchPort;
//add packet in the switch list uplinkswitches = new ArrayList<Switch>();
//add packet in the host list downlinkswitches = new ArrayList<Switch>();
//int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.latency, CloudSimTags.Network_Event_send);
if(this.level==Constants.Agg_LEVEL)
{
//packet is coming from root so need to be sent to edgelevel swich
//find the id for edgelevel switch
int switchid=dc.VmToSwitchid.get(recvVMid);
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(switchid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
return;
}
} }
/**
* Send Packet to switch connected through a downlink port
*
* @param ev Event/packet to process
*/
@Override
protected void processpacket_down(SimEvent ev) {
// packet coming from up level router.
// has to send downward
// check which switch to forward to
// add packet in the switch list
// add packet in the host list
NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(
CloudSimTags.Network_Event_send));
schedule(getId(), this.latency, CloudSimTags.Network_Event_send);
if (this.level == NetworkConstants.Agg_LEVEL) {
// packet is coming from root so need to be sent to edgelevel swich
// find the id for edgelevel switch
int switchid = dc.VmToSwitchid.get(recvVMid);
List<NetworkPacket> pktlist = this.downlinkswitchpktlist.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
return;
}
private void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub
//packet coming from down level router.
//has to send up
//check which switch to forward to
//add packet in the switch list
//
//int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send);
if(this.level==Constants.Agg_LEVEL)
{
//packet is coming from edge level router so need to be sent to either root or another edge level swich
//find the id for edgelevel switch
int switchid=dc.VmToSwitchid.get(recvVMid);
boolean flagtoswtich=false;
for(Switch sw:this.downlinkswitches)
{
if(switchid==sw.getId()) flagtoswtich=true;
}
if(flagtoswtich)
{
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(switchid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
}
else//send to up
{
Switch sw=this.uplinkswitches.get(0);
List<HostPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
} }
/**
* Send Packet to switch connected through a uplink port
*
* @param ev Event/packet to process
*/
@Override
protected void processpacket_up(SimEvent ev) {
// packet coming from down level router.
// has to send up
// check which switch to forward to
// add packet in the switch list
//
// int src=ev.getSource();
NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(
CloudSimTags.Network_Event_send));
schedule(getId(), this.switching_delay, CloudSimTags.Network_Event_send);
if (this.level == NetworkConstants.Agg_LEVEL) {
// packet is coming from edge level router so need to be sent to
// either root or another edge level swich
// find the id for edgelevel switch
int switchid = dc.VmToSwitchid.get(recvVMid);
boolean flagtoswtich = false;
for (Switch sw : this.downlinkswitches) {
if (switchid == sw.getId())
flagtoswtich = true;
}
if (flagtoswtich) {
List<NetworkPacket> pktlist = this.downlinkswitchpktlist
.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
} else// send to up
{
Switch sw = this.uplinkswitches.get(0);
List<NetworkPacket> pktlist = this.uplinkswitchpktlist.get(sw
.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
}
} }
...@@ -7,59 +7,72 @@ import org.cloudbus.cloudsim.UtilizationModel; ...@@ -7,59 +7,72 @@ import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull; import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
/**
* AppCloudlet class represents an application which user submit for execution within datacenter.
* It consist of several networkClouds.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class AppCloudlet { public class AppCloudlet {
public static final int APP_MC = 1; public static final int APP_MC = 1;
public static final int APP_Workflow = 3; public static final int APP_Workflow = 3;
public AppCloudlet(int type, int appID,
double deadline, int numbervm, int userId) { public AppCloudlet(int type, int appID, double deadline, int numbervm,
int userId) {
super(); super();
this.type = type; this.type = type;
this.appID = appID; this.appID = appID;
this.deadline = deadline; this.deadline = deadline;
this.numbervm = numbervm; this.numbervm = numbervm;
this.userId = userId; this.userId = userId;
clist=new ArrayList<NetworkCloudlet>(); clist = new ArrayList<NetworkCloudlet>();
} }
public int type; //fft,fem
public int appID; public int type;
public ArrayList<NetworkCloudlet> clist; public int appID;
public double deadline; public ArrayList<NetworkCloudlet> clist;
public double accuracy; public double deadline;
public int numbervm; public double accuracy;
public int userId; public int numbervm;
public int userId;
public double exeTime; public double exeTime;
public int requestclass; public int requestclass;
/**
public void createCloudletList(List<Integer> vmIdList) * An example of creating APPcloudlet
{ * @param vmIdList VMs where Cloudlet will be executed
for(int i=0;i<numbervm;i++){ */
long length = 4; public void createCloudletList(List<Integer> vmIdList) {
long fileSize = 300; for (int i = 0; i < numbervm; i++) {
long outputSize = 300; long length = 4;
long memory = 256; long fileSize = 300;
int pesNumber = 4; long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull(); long memory = 256;
//HPCCloudlet cl=new HPCCloudlet(); int pesNumber = 4;
NetworkCloudlet cl = new NetworkCloudlet(Constants.currentCloudletId, length, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); UtilizationModel utilizationModel = new UtilizationModelFull();
// HPCCloudlet cl=new HPCCloudlet();
NetworkCloudlet cl = new NetworkCloudlet(
NetworkConstants.currentCloudletId, length, pesNumber, fileSize,
outputSize, memory, utilizationModel, utilizationModel,
utilizationModel);
// setting the owner of these Cloudlets // setting the owner of these Cloudlets
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
cl.setUserId(userId); cl.setUserId(userId);
cl.submittime=CloudSim.clock(); cl.submittime = CloudSim.clock();
// TaskStage ts=new TaskStage(Constants.EXECUTION, 0, length, 0,memory, (i+1)%numbervm); cl.currStagenum = -1;
// TaskStage ts1=new TaskStage(Constants.WAIT_SEND, 100, 0, 0, memory, (i+1)%numbervm); clist.add(cl);
// TaskStage ts2=new TaskStage(Constants.WAIT_RECV, 100, 0, 0, memory, (i+1)%numbervm);
// TaskStage ts3=new TaskStage(Constants.EXECUTION, 0, length, 0, memory, (i+1)%numbervm); }
// cl.stages.add(ts); // based on type
// cl.stages.add(ts1);
// cl.stages.add(ts2); }
// cl.stages.add(ts3);
// cl.submittime=CloudSim.clock();
cl.currStagenum=-1;
clist.add(cl);
}
//based on type
}
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* BagofTaskApp is an example of AppCloudlet having three noncommunicating tasks.
*
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull; import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
public class MonteCarloApp extends AppCloudlet { public class BagofTaskApp extends AppCloudlet {
public MonteCarloApp(int type, int appID, double deadline, int numbervm, int userId) { public BagofTaskApp(int type, int appID, double deadline, int numbervm, int userId) {
super(type, appID, deadline, numbervm,userId); super(type, appID, deadline, numbervm,userId);
this.numbervm=this.getnumvm(); this.numbervm=this.getnumvm();
...@@ -19,34 +35,39 @@ public class MonteCarloApp extends AppCloudlet { ...@@ -19,34 +35,39 @@ public class MonteCarloApp extends AppCloudlet {
public void createCloudletList(List<Integer> vmIdList){ public void createCloudletList(List<Integer> vmIdList){
//basically, each task runs the simulation and then data is consolidated in one task //basically, each task runs the simulation and then data is consolidated in one task
int executionTime = getExecTime(); int executionTime = getExecTime();
long memory = accuracyToMemory(); long memory = 1000;
long fileSize = Constants.FILE_SIZE; long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = Constants.OUTPUT_SIZE; long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = Constants.PES_NUMBER; int pesNumber = NetworkConstants.PES_NUMBER;
int stgId=0; int stgId=0;
int t=Constants.currentCloudletId; int t=NetworkConstants.currentCloudletId;
for(int i=0;i<numbervm;i++){ for(int i=0;i<numbervm;i++){
UtilizationModel utilizationModel = new UtilizationModelFull(); UtilizationModel utilizationModel = new UtilizationModelFull();
NetworkCloudlet cl = new NetworkCloudlet(Constants.currentCloudletId, executionTime/numbervm, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, executionTime/numbervm, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
cl.setUserId(userId); cl.setUserId(userId);
cl.submittime=CloudSim.clock(); cl.submittime=CloudSim.clock();
cl.currStagenum=-1; cl.currStagenum=-1;
cl.setVmId(vmIdList.get(i)); cl.setVmId(vmIdList.get(i));
//compute and send data to node 0 //compute and send data to node 0
cl.stages.add(new TaskStage(Constants.EXECUTION, Constants.COMMUNICATION_LENGTH, executionTime/numbervm, stgId++, memory, vmIdList.get(0),cl.getCloudletId())); cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, NetworkConstants.COMMUNICATION_LENGTH, executionTime/numbervm, stgId++, memory, vmIdList.get(0),cl.getCloudletId()));
//0 has an extra stage of waiting for results; others send //0 has an extra stage of waiting for results; others send
if (i==0){ if (i==0){
for(int j=1;j<numbervm;j++) for(int j=1;j<numbervm;j++)
cl.stages.add(new TaskStage(Constants.WAIT_RECV, Constants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(j),cl.getCloudletId()+j)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, NetworkConstants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(j),cl.getCloudletId()+j));
} else { } else {
cl.stages.add(new TaskStage(Constants.WAIT_SEND, Constants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(0),t)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, NetworkConstants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(0),t));
} }
clist.add(cl); clist.add(cl);
} }
} }
/**
* One can generate number of VMs for each application based on deadline
* @return
*/
public int getnumvm(){ public int getnumvm(){
double exetime=getExecTime()/2;//for two vms double exetime=getExecTime()/2;//for two vms
if(this.deadline>exetime) if(this.deadline>exetime)
...@@ -57,14 +78,10 @@ public class MonteCarloApp extends AppCloudlet { ...@@ -57,14 +78,10 @@ public class MonteCarloApp extends AppCloudlet {
} }
private int getExecTime() { private int getExecTime() {
//use exec constraints as Binomial //use exec constraints
return 100; return 100;
} }
private long accuracyToMemory() {
//use same memory constraints as Binomial
return 240076;
}
} }
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.ResCloudlet;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
public class CloudletHPCSpaceShared extends CloudletScheduler{
/*
* 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-2010, The University of Melbourne, Australia
*/
/**
* CloudletSchedulerSpaceShared implements a policy of
* scheduling performed by a virtual machine. It consider
* that there will be only one cloudlet per VM. Other cloudlets will be in a
* waiting list. We consider that file transfer from cloudlets waiting happens
* before cloudlet execution. I.e., even though cloudlets must wait for CPU,
* data transfer happens as soon as cloudlets are submitted.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
/** The cloudlet waiting list. */
private List<? extends ResCloudlet> cloudletWaitingList;
/** The cloudlet exec list. */
private List<? extends ResCloudlet> cloudletExecList;
/** The cloudlet paused list. */
private List<? extends ResCloudlet> cloudletPausedList;
/** The cloudlet finished list. */
private List<? extends ResCloudlet> cloudletFinishedList;
/** The current CPUs. */
protected int currentCpus;
/** The used PEs. */
protected int usedPes;
//for network
public Map<Integer,List<NetPacket>> pkttosend;
public Map<Integer,List<NetPacket>> pktrecv;
/**
* Creates a new CloudletSchedulerSpaceShared object. This method must be invoked
* before starting the actual simulation.
*
* @pre $none
* @post $none
*/
public CloudletHPCSpaceShared() {
super();
this.cloudletWaitingList = new ArrayList<ResCloudlet>();
this.cloudletExecList = new ArrayList<ResCloudlet>();
this.cloudletPausedList = new ArrayList<ResCloudlet>();
this.cloudletFinishedList = new ArrayList<ResCloudlet>();
this.usedPes = 0;
this.currentCpus = 0;
this.pkttosend= new HashMap<Integer,List<NetPacket>>();
this.pktrecv= new HashMap<Integer,List<NetPacket>>();
}
/**
* Updates the processing of cloudlets running under management of this scheduler.
*
* @param currentTime current simulation time
* @param mipsShare array with MIPS share of each processor available to the scheduler
*
* @return time predicted completion time of the earliest finishing cloudlet, or 0
* if there is no next events
*
* @pre currentTime >= 0
* @post $none
*/
@Override
public double updateVmProcessing(double currentTime, List<Double> mipsShare) {
setCurrentMipsShare(mipsShare);
double timeSpam = currentTime - getPreviousTime(); // time since last update
double capacity = 0.0;
int cpus = 0;
for (Double mips : mipsShare) { // count the CPUs available to the VMM
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus; // average capacity of each cpu
for (ResCloudlet rcl : getCloudletExecList()) { // each machine in the exec list has the same amount of cpu
NetworkCloudlet cl=(NetworkCloudlet) rcl.getCloudlet();
if((cl.currStagenum!=-1))
{
if(cl.currStagenum==Constants.FINISH){
//long len=rcl.getRemainingCloudletLength();
//rcl.updateCloudletFinishedSoFar(len);
break;
}
TaskStage st= cl.stages.get(cl.currStagenum);
if(st.type==Constants.EXECUTION)
{
//rcl.updateCloudletFinishedSoFar((long) (capacity * Math.round(timeSpam) * rcl.getPesNumber()));
//update the time
cl.timespentInStage=Math.round(CloudSim.clock()-cl.timetostartStage);
if(cl.timespentInStage>=st.time)
{
changetonextstage(cl,st);
//change the stage
}
}
if(st.type==Constants.WAIT_RECV)
{
List<NetPacket> pktlist=this.pktrecv.get(st.peer);
List<NetPacket> pkttoremove=new ArrayList<NetPacket>();
if(pktlist!=null)
{
Iterator it=pktlist.iterator();
NetPacket pkt=null;
if(it.hasNext())
{
pkt=(NetPacket)it.next();
if(pkt.reciever==cl.getVmId())//Asumption packet will not arrive in the same cycle
{
pkt.recievetime=CloudSim.clock();
st.time=CloudSim.clock()-pkt.sendtime;
changetonextstage(cl,st);
pkttoremove.add(pkt);
}
}
pktlist.removeAll(pkttoremove);
//if(pkt!=null)
//else wait for recieving the packet
}
}
}
else
{
cl.currStagenum=0;
cl.timetostartStage=CloudSim.clock();
if(cl.stages.get(0).type==Constants.EXECUTION)
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),cl.stages.get(0).time, CloudSimTags.VM_DATACENTER_EVENT);
else
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),0.0001, CloudSimTags.VM_DATACENTER_EVENT);
///sendstage///
}
//check status
//if execution stage
//update the cloudlet finishtime
//CHECK WHETHER IT IS WAITING FOR THE PACKET
// if packet received change the status of job and update the time.
//
//rcl.updateCloudletFinishedSoFar((long) (capacity * timeSpam * rcl.getPesNumber()));
}
if (getCloudletExecList().size() == 0 && getCloudletWaitingList().size() == 0) { // no more cloudlets in this scheduler
setPreviousTime(currentTime);
return 0.0;
}
//update each cloudlet
int finished = 0;
int cont = 0;
List<ResCloudlet> toRemove = new ArrayList<ResCloudlet>();
for (ResCloudlet rcl : getCloudletExecList()) {
//if (rcl.getRemainingCloudletLength() == 0.0) {// finished anyway, rounding issue...
if(((NetworkCloudlet)(rcl.getCloudlet())).currStagenum==Constants.FINISH){
//stage is changed and packet to send
((NetworkCloudlet)(rcl.getCloudlet())).finishtime=CloudSim.clock();
toRemove.add(rcl);
cloudletFinish(rcl);
finished++;
}
cont++;
}
getCloudletExecList().removeAll(toRemove);
//add all the CloudletExecList in waitingList.
//sort the waitinglist
//
//for each finished cloudlet, add a new one from the waiting list
if (!getCloudletWaitingList().isEmpty()) {
for (int i = 0; i < finished; i++) {
toRemove.clear();
for (ResCloudlet rcl : getCloudletWaitingList()) {
if ((currentCpus - usedPes) >= rcl.getPesNumber()) {
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int k = 0; k < rcl.getPesNumber(); k++) {
rcl.setMachineAndPeId(0, i);
}
getCloudletExecList().add(rcl);
usedPes += rcl.getPesNumber();
toRemove.add(rcl);
break;
}
}
getCloudletWaitingList().removeAll(toRemove);
}// for(cont)
}
//estimate finish time of cloudlets in the execution queue
double nextEvent = Double.MAX_VALUE;
for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getPesNumber()));
if (estimatedFinishTime - currentTime < 0.1) {
estimatedFinishTime = currentTime + 0.1;
}
if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime;
}
}
setPreviousTime(currentTime);
return nextEvent;
}
private void changetonextstage(NetworkCloudlet cl, TaskStage st) {
// TODO Auto-generated method stub
cl.timespentInStage=0;
cl.timetostartStage=CloudSim.clock();
int currstage=cl.currStagenum;
if(currstage>=(cl.stages.size()-1))
cl.currStagenum=Constants.FINISH;
else{
cl.currStagenum=currstage+1;
TaskStage st1=cl.stages.get(cl.currStagenum);
int i=0;
for(i=cl.currStagenum;i<cl.stages.size();i++)
{
if(cl.stages.get(i).type==Constants.WAIT_SEND)
{
NetPacket pkt=new NetPacket(cl.getVmId(), cl.stages.get(i).peer, cl.stages.get(i).data, CloudSim.clock(),-1,cl.getCloudletId(),cl.stages.get(i).vpeer);
List<NetPacket> pktlist=this.pkttosend.get(cl.getVmId());
if(pktlist==null)
pktlist=new ArrayList<NetPacket>();
pktlist.add(pkt);
this.pkttosend.put(cl.getVmId(), pktlist);
}
else break;
}
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),0.0001, CloudSimTags.VM_DATACENTER_EVENT);
if(i==cl.stages.size()) cl.currStagenum=Constants.FINISH;
else {
cl.currStagenum=i;
if(cl.stages.get(i).type==Constants.EXECUTION)
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),cl.stages.get(i).time, CloudSimTags.VM_DATACENTER_EVENT);
}
}
}
/**
* Cancels execution of a cloudlet.
*
* @param cloudletId ID of the cloudlet being cancealed
*
* @return the canceled cloudlet, $null if not found
*
* @pre $none
* @post $none
*/
@Override
public Cloudlet cloudletCancel(int cloudletId) {
//First, looks in the finished queue
for (ResCloudlet rcl : getCloudletFinishedList()) {
if (rcl.getCloudletId() == cloudletId) {
getCloudletFinishedList().remove(rcl);
return rcl.getCloudlet();
}
}
//Then searches in the exec list
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) {
getCloudletExecList().remove(rcl);
if (rcl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rcl);
} else {
rcl.setCloudletStatus(Cloudlet.CANCELED);
}
return rcl.getCloudlet();
}
}
//Now, looks in the paused queue
for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) {
getCloudletPausedList().remove(rcl);
return rcl.getCloudlet();
}
}
//Finally, looks in the waiting list
for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) {
rcl.setCloudletStatus(Cloudlet.CANCELED);
getCloudletWaitingList().remove(rcl);
return rcl.getCloudlet();
}
}
return null;
}
/**
* Pauses execution of a cloudlet.
*
* @param cloudletId ID of the cloudlet being paused
*
* @return $true if cloudlet paused, $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public boolean cloudletPause(int cloudletId) {
boolean found = false;
int position = 0;
//first, looks for the cloudlet in the exec list
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) {
found = true;
break;
}
position++;
}
if (found){
//moves to the paused list
ResCloudlet rgl = getCloudletExecList().remove(position);
if (rgl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rgl);
} else {
rgl.setCloudletStatus(Cloudlet.PAUSED);
getCloudletPausedList().add(rgl);
}
return true;
}
//now, look for the cloudlet in the waiting list
position = 0;
found = false;
for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) {
found = true;
break;
}
position++;
}
if (found) {
// moves to the paused list
ResCloudlet rgl = getCloudletWaitingList().remove(position);
if (rgl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rgl);
} else {
rgl.setCloudletStatus(Cloudlet.PAUSED);
getCloudletPausedList().add(rgl);
}
return true;
}
return false;
}
/**
* Processes a finished cloudlet.
*
* @param rcl finished cloudlet
*
* @pre rgl != $null
* @post $none
*/
@Override
public void cloudletFinish(ResCloudlet rcl) {
rcl.setCloudletStatus(Cloudlet.SUCCESS);
rcl.finalizeCloudlet();
getCloudletFinishedList().add(rcl);
usedPes -= rcl.getPesNumber();
}
/**
* Resumes execution of a paused cloudlet.
*
* @param cloudletId ID of the cloudlet being resumed
*
* @return $true if the cloudlet was resumed, $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public double cloudletResume(int cloudletId) {
boolean found=false;
int position=0;
//look for the cloudlet in the paused list
for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) {
found = true;
break;
}
position++;
}
if (found){
ResCloudlet rcl = getCloudletPausedList().remove(position);
if ((currentCpus - usedPes) >= rcl.getPesNumber()) {// it can go to the exec list
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < rcl.getPesNumber(); i++) {
rcl.setMachineAndPeId(0, i);
}
long size = rcl.getRemainingCloudletLength();
size *= rcl.getPesNumber();
rcl.getCloudlet().setCloudletLength(size);
getCloudletExecList().add(rcl);
usedPes += rcl.getPesNumber();
// calculate the expected time for cloudlet completion
double capacity = 0.0;
int cpus = 0;
for (Double mips : getCurrentMipsShare()) {
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus;
long remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = CloudSim.clock() + (remainingLength / (capacity * rcl.getPesNumber()));
return estimatedFinishTime;
} else {// no enough free PEs: go to the waiting queue
rcl.setCloudletStatus(Cloudlet.QUEUED);
long size = rcl.getRemainingCloudletLength();
size *= rcl.getPesNumber();
rcl.getCloudlet().setCloudletLength(size);
getCloudletWaitingList().add(rcl);
return 0.0;
}
}
//not found in the paused list: either it is in in the queue, executing or not exist
return 0.0;
}
/**
* Receives an cloudlet to be executed in the VM managed by this scheduler.
*
* @param cloudlet the submited cloudlet
* @param fileTransferTime time required to move the required files from the SAN to the VM
*
* @return expected finish time of this cloudlet, or 0 if it is in the waiting queue
*
* @pre gl != null
* @post $none
*/
@Override
public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) {
if ((currentCpus - usedPes) >= cloudlet.getPesNumber()) {// it can go to the exec list
ResCloudlet rcl = new ResCloudlet(cloudlet);
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < cloudlet.getPesNumber(); i++) {
rcl.setMachineAndPeId(0, i);
}
getCloudletExecList().add(rcl);
usedPes += cloudlet.getPesNumber();
} else {// no enough free PEs: go to the waiting queue
ResCloudlet rcl = new ResCloudlet(cloudlet);
rcl.setCloudletStatus(Cloudlet.QUEUED);
getCloudletWaitingList().add(rcl);
return 0.0;
}
// calculate the expected time for cloudlet completion
double capacity = 0.0;
int cpus = 0;
for (Double mips : getCurrentMipsShare()) {
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus;
// use the current capacity to estimate the extra amount of
// time to file transferring. It must be added to the cloudlet length
double extraSize = capacity * fileTransferTime;
long length = cloudlet.getCloudletLength();
length += extraSize;
cloudlet.setCloudletLength(length);
return cloudlet.getCloudletLength() / capacity;
}
/* (non-Javadoc)
* @see cloudsim.CloudletScheduler#cloudletSubmit(cloudsim.Cloudlet)
*/
@Override
public double cloudletSubmit(Cloudlet cloudlet) {
cloudletSubmit(cloudlet, 0);
return 0;
}
/**
* Gets the status of a cloudlet.
*
* @param cloudletId ID of the cloudlet
*
* @return status of the cloudlet, -1 if cloudlet not found
*
* @pre $none
* @post $none
*/
@Override
public int getCloudletStatus(int cloudletId) {
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) {
return rcl.getCloudletStatus();
}
}
for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) {
return rcl.getCloudletStatus();
}
}
for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) {
return rcl.getCloudletStatus();
}
}
return -1;
}
/**
* Get utilization created by all cloudlets.
*
* @param time the time
*
* @return total utilization
*/
@Override
public double getTotalUtilizationOfCpu(double time) {
double totalUtilization = 0;
for (ResCloudlet gl : getCloudletExecList()) {
totalUtilization += gl.getCloudlet().getUtilizationOfCpu(time);
}
return totalUtilization;
}
/**
* Informs about completion of some cloudlet in the VM managed
* by this scheduler.
*
* @return $true if there is at least one finished cloudlet; $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public boolean isFinishedCloudlets() {
return getCloudletFinishedList().size() > 0;
}
/**
* Returns the next cloudlet in the finished list, $null if this list is empty.
*
* @return a finished cloudlet
*
* @pre $none
* @post $none
*/
@Override
public Cloudlet getNextFinishedCloudlet() {
if (getCloudletFinishedList().size() > 0) {
return getCloudletFinishedList().remove(0).getCloudlet();
}
return null;
}
/**
* Returns the number of cloudlets runnning in the virtual machine.
*
* @return number of cloudlets runnning
*
* @pre $none
* @post $none
*/
@Override
public int runningCloudlets() {
return getCloudletExecList().size();
}
/**
* Returns one cloudlet to migrate to another vm.
*
* @return one running cloudlet
*
* @pre $none
* @post $none
*/
@Override
public Cloudlet migrateCloudlet() {
ResCloudlet rcl = getCloudletExecList().remove(0);
rcl.finalizeCloudlet();
Cloudlet cl = rcl.getCloudlet();
usedPes -= cl.getPesNumber();
return cl;
}
/**
* Gets the cloudlet waiting list.
*
* @param <T> the generic type
* @return the cloudlet waiting list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletWaitingList() {
return (List<T>) cloudletWaitingList;
}
/**
* Cloudlet waiting list.
*
* @param <T> the generic type
* @param cloudletWaitingList the cloudlet waiting list
*/
protected <T extends ResCloudlet> void cloudletWaitingList(List<T> cloudletWaitingList) {
this.cloudletWaitingList = cloudletWaitingList;
}
/**
* Gets the cloudlet exec list.
*
* @param <T> the generic type
* @return the cloudlet exec list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletExecList() {
return (List<T>) cloudletExecList;
}
/**
* Sets the cloudlet exec list.
*
* @param <T> the generic type
* @param cloudletExecList the new cloudlet exec list
*/
protected <T extends ResCloudlet> void setCloudletExecList(List<T> cloudletExecList) {
this.cloudletExecList = cloudletExecList;
}
/**
* Gets the cloudlet paused list.
*
* @param <T> the generic type
* @return the cloudlet paused list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletPausedList() {
return (List<T>) cloudletPausedList;
}
/**
* Sets the cloudlet paused list.
*
* @param <T> the generic type
* @param cloudletPausedList the new cloudlet paused list
*/
protected <T extends ResCloudlet> void setCloudletPausedList(List<T> cloudletPausedList) {
this.cloudletPausedList = cloudletPausedList;
}
/**
* Gets the cloudlet finished list.
*
* @param <T> the generic type
* @return the cloudlet finished list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletFinishedList() {
return (List<T>) cloudletFinishedList;
}
/**
* Sets the cloudlet finished list.
*
* @param <T> the generic type
* @param cloudletFinishedList the new cloudlet finished list
*/
protected <T extends ResCloudlet> void setCloudletFinishedList(List<T> cloudletFinishedList) {
this.cloudletFinishedList = cloudletFinishedList;
}
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler#getCurrentRequestedMips()
*/
@Override
public List<Double> getCurrentRequestedMips() {
List<Double> mipsShare = new ArrayList<Double>();
if (getCurrentMipsShare() != null) {
for (Double mips : getCurrentMipsShare()) {
mipsShare.add(mips);
}
}
return mipsShare;
}
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler#getTotalCurrentAvailableMipsForCloudlet(org.cloudbus.cloudsim.ResCloudlet, java.util.List)
*/
@Override
public double getTotalCurrentAvailableMipsForCloudlet(ResCloudlet rcl, List<Double> mipsShare) {
double capacity = 0.0;
int cpus = 0;
for (Double mips : mipsShare) { // count the cpus available to the vmm
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus; // average capacity of each cpu
return capacity;
}
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler#getTotalCurrentAllocatedMipsForCloudlet(org.cloudbus.cloudsim.ResCloudlet, double)
*/
@Override
public double getTotalCurrentAllocatedMipsForCloudlet(ResCloudlet rcl, double time) {
// TODO Auto-generated method stub
return 0.0;
}
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler#getTotalCurrentRequestedMipsForCloudlet(org.cloudbus.cloudsim.ResCloudlet, double)
*/
@Override
public double getTotalCurrentRequestedMipsForCloudlet(ResCloudlet rcl, double time) {
// TODO Auto-generated method stub
return 0.0;
}
@Override
public double getCurrentRequestedUtilizationOfBw() {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getCurrentRequestedUtilizationOfRam() {
// TODO Auto-generated method stub
return 0;
}
}
...@@ -11,26 +11,53 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -11,26 +11,53 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* This class allows to simulate Edge switch for Datacenter network.
* It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM International
* Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA),
* Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*
*/
public class EdgeSwitch extends Switch{ public class EdgeSwitch extends Switch{
public EdgeSwitch(String name, int dcid, NetworkDatacenter dc) { /**
super(name, dcid, dc); * Constructor for Edge Switch
* We have to specify switches that are connected to its downlink and uplink ports,
* and corresponding bandwidths. In this switch downlink ports are
* connected to hosts not to a switch.
*
* @param name Name of the switch
* @param level At which level switch is with respect to hosts.
* @param dc Pointer to Datacenter
*/
public EdgeSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc);
hostlist=new HashMap<Integer,NetworkHost>(); hostlist=new HashMap<Integer,NetworkHost>();
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); uplinkswitchpktlist=new HashMap<Integer,List<NetworkPacket>>();
packetTohost=new HashMap<Integer,List<HostPacket>>(); packetTohost=new HashMap<Integer,List<NetworkPacket>>();
uplinkbandwidth=Constants.BandWidthEdgeAgg; uplinkbandwidth=NetworkConstants.BandWidthEdgeAgg;
downlinkbandwidth=Constants.BandWidthEdgeHost; downlinkbandwidth=NetworkConstants.BandWidthEdgeHost;
this.switching_delay=Constants.SwitchingDelayEdge; this.switching_delay=NetworkConstants.SwitchingDelayEdge;
numport=Constants.EdgeSwitchPort; numport=NetworkConstants.EdgeSwitchPort;
uplinkswitches=new ArrayList<Switch>(); uplinkswitches=new ArrayList<Switch>();
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
private void registerHost(SimEvent ev) { /**
// TODO Auto-generated method stub * Send Packet to switch connected through a uplink port
NetworkHost hs=(NetworkHost)ev.getData(); *
hostlist.put(hs.getId(),(NetworkHost)ev.getData()); * @param ev Event/packet to process
} */
private void processpacket_up(SimEvent ev) { @Override
protected void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//packet coming from down level router/host. //packet coming from down level router/host.
//has to send up //has to send up
...@@ -38,7 +65,7 @@ public class EdgeSwitch extends Switch{ ...@@ -38,7 +65,7 @@ public class EdgeSwitch extends Switch{
//add packet in the switch list //add packet in the switch list
// //
//int src=ev.getSource(); //int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt=(NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send); schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send);
...@@ -54,9 +81,9 @@ public class EdgeSwitch extends Switch{ ...@@ -54,9 +81,9 @@ public class EdgeSwitch extends Switch{
if(hs!=null) if(hs!=null)
{ {
//packet to be sent to host connected to the switch //packet to be sent to host connected to the switch
List<HostPacket> pktlist=this.packetTohost.get(hostid); List<NetworkPacket> pktlist=this.packetTohost.get(hostid);
if(pktlist==null){ if(pktlist==null){
pktlist=new ArrayList<HostPacket>(); pktlist=new ArrayList<NetworkPacket>();
this.packetTohost.put(hostid, pktlist); this.packetTohost.put(hostid, pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
...@@ -69,9 +96,9 @@ public class EdgeSwitch extends Switch{ ...@@ -69,9 +96,9 @@ public class EdgeSwitch extends Switch{
//if there are more than one Aggregate level switch one need to modify following code //if there are more than one Aggregate level switch one need to modify following code
Switch sw=this.uplinkswitches.get(0); Switch sw=this.uplinkswitches.get(0);
List<HostPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId()); List<NetworkPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){ if(pktlist==null){
pktlist=new ArrayList<HostPacket>(); pktlist=new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist); this.uplinkswitchpktlist.put(sw.getId(), pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
...@@ -79,24 +106,31 @@ public class EdgeSwitch extends Switch{ ...@@ -79,24 +106,31 @@ public class EdgeSwitch extends Switch{
} }
private void processpacketforward(SimEvent ev) { /**
* Send Packet to hosts connected to the switch
*
* @param ev Event/packet to process
*/
@Override
protected void processpacketforward(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//search for the host and packets..send to them //search for the host and packets..send to them
if(this.uplinkswitchpktlist!=null) if(this.uplinkswitchpktlist!=null)
{ {
for(Entry<Integer, List<HostPacket>> es:uplinkswitchpktlist.entrySet()) for(Entry<Integer, List<NetworkPacket>> es:uplinkswitchpktlist.entrySet())
{ {
int tosend=es.getKey(); int tosend=es.getKey();
List<HostPacket> hspktlist=es.getValue(); List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){ if(!hspktlist.isEmpty()){
//sharing bandwidth between packets //sharing bandwidth between packets
double avband=this.uplinkbandwidth/hspktlist.size(); double avband=this.uplinkbandwidth/hspktlist.size();
Iterator<HostPacket> it=hspktlist.iterator(); Iterator<NetworkPacket> it=hspktlist.iterator();
while(it.hasNext()) while(it.hasNext())
{ {
HostPacket hspkt=it.next(); NetworkPacket hspkt=it.next();
double delay=1000*hspkt.pkt.data/avband; double delay=1000*hspkt.pkt.data/avband;
this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt); this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt);
...@@ -107,16 +141,16 @@ public class EdgeSwitch extends Switch{ ...@@ -107,16 +141,16 @@ public class EdgeSwitch extends Switch{
} }
if(this.packetTohost!=null) if(this.packetTohost!=null)
{ {
for(Entry<Integer, List<HostPacket>> es:packetTohost.entrySet()) for(Entry<Integer, List<NetworkPacket>> es:packetTohost.entrySet())
{ {
int tosend=es.getKey(); int tosend=es.getKey();
NetworkHost hs=this.hostlist.get(tosend); NetworkHost hs=this.hostlist.get(tosend);
List<HostPacket> hspktlist=es.getValue(); List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){ if(!hspktlist.isEmpty()){
double avband=this.downlinkbandwidth/hspktlist.size(); double avband=this.downlinkbandwidth/hspktlist.size();
Iterator<HostPacket> it=hspktlist.iterator(); Iterator<NetworkPacket> it=hspktlist.iterator();
while(it.hasNext()){ while(it.hasNext()){
HostPacket hspkt=it.next(); NetworkPacket hspkt=it.next();
//hspkt.recieverhostid=tosend; //hspkt.recieverhostid=tosend;
//hs.packetrecieved.add(hspkt); //hs.packetrecieved.add(hspkt);
this.send(this.getId(),hspkt.pkt.data/avband,CloudSimTags.Network_Event_Host, hspkt); this.send(this.getId(),hspkt.pkt.data/avband,CloudSimTags.Network_Event_Host, hspkt);
......
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* HostPacket represents the packet that travels through the virtual network with a Host.
* It contains information about cloudlets which are communicating
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class HostPacket { public class HostPacket {
public HostPacket(int id, NetPacket pkt2, int vmid, int cloudletid) { public HostPacket(int sender, int reciever, double data, double sendtime,
// TODO Auto-generated constructor stub double recievetime, int vsnd, int vrvd) {
this.pkt=pkt2; super();
this.sendervmid=vmid; this.sender = sender;
this.cloudletid=cloudletid; this.reciever = reciever;
this.senderhostid=id; this.data = data;
this.stime=pkt.sendtime; this.sendtime = sendtime;
this.recievervmid=pkt2.reciever; this.recievetime = recievetime;
this.virtualrecvid = vrvd;
this.virtualsendid = vsnd;
} }
NetPacket pkt;
int senderhostid; int sender;
int recieverhostid; int virtualrecvid;
int sendervmid; int virtualsendid;
int recievervmid; int reciever;
int cloudletid; double data;
double stime;//time when sent double sendtime;
double rtime;//time when received double recievetime;
} }
...@@ -8,9 +8,6 @@ package org.cloudbus.cloudsim.network.datacenter; ...@@ -8,9 +8,6 @@ package org.cloudbus.cloudsim.network.datacenter;
* Copyright (c) 2009-2010, The University of Melbourne, Australia * Copyright (c) 2009-2010, The University of Melbourne, Australia
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -36,14 +33,13 @@ import org.cloudbus.cloudsim.lists.CloudletList; ...@@ -36,14 +33,13 @@ import org.cloudbus.cloudsim.lists.CloudletList;
import org.cloudbus.cloudsim.lists.VmList; import org.cloudbus.cloudsim.lists.VmList;
/** /**
* DatacentreBroker represents a broker * NetDatacentreBroker represents a broker acting on behalf of Datacenter
* acting on behalf of a user. It hides VM management, * provider. It hides VM management, as vm creation, submission of cloudlets to
* as vm creation, sumbission of cloudlets to this VMs * this VMs and destruction of VMs. NOTE- It is an example only. It work on behalf of a provider not for
* and destruction of VMs. * users. One has to implement interaction with user broker to this broker.
* *
* @author Rodrigo N. Calheiros * @author Saurabh Kumar Garg
* @author Anton Beloglazov * @since CloudSim Toolkit 3.0
* @since CloudSim Toolkit 1.0
*/ */
public class NetDatacenterBroker extends SimEntity { public class NetDatacenterBroker extends SimEntity {
...@@ -54,20 +50,19 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -54,20 +50,19 @@ public class NetDatacenterBroker extends SimEntity {
/** The vms created list. */ /** The vms created list. */
private List<? extends Vm> vmsCreatedList; private List<? extends Vm> vmsCreatedList;
/** The cloudlet list. */ /** The cloudlet list. */
private List<? extends NetworkCloudlet> cloudletList; private List<? extends NetworkCloudlet> cloudletList;
private List<? extends AppCloudlet> appCloudletList; private List<? extends AppCloudlet> appCloudletList;
/** The cloudlet submitted list. */ /** The Appcloudlet submitted list. */
private Map<Integer, Integer> appCloudletRecieved; private Map<Integer, Integer> appCloudletRecieved;
private List<? extends Cloudlet> cloudletSubmittedList; private List<? extends Cloudlet> cloudletSubmittedList;
/** The cloudlet received list. */ /** The cloudlet received list. */
private List<? extends Cloudlet> cloudletReceivedList; private List<? extends Cloudlet> cloudletReceivedList;
/** The cloudlets submitted. */ /** The cloudlets submitted. */
private int cloudletsSubmitted; private int cloudletsSubmitted;
...@@ -93,18 +88,20 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -93,18 +88,20 @@ public class NetDatacenterBroker extends SimEntity {
private Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList; private Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList;
public static NetworkDatacenter linkDC; public static NetworkDatacenter linkDC;
public boolean createvmflag=true; public boolean createvmflag = true;
public static int cachedcloudlet=0; public static int cachedcloudlet = 0;
/** /**
* Created a new DatacenterBroker object. * Created a new DatacenterBroker object.
* *
* @param name name to be associated with this entity (as * @param name
* required by Sim_entity class from simjava package) * name to be associated with this entity (as required by
* * Sim_entity class from simjava package)
* @throws Exception the exception *
* * @throws Exception
* the exception
*
* @pre name != null * @pre name != null
* @post $none * @post $none
*/ */
...@@ -117,9 +114,9 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -117,9 +114,9 @@ public class NetDatacenterBroker extends SimEntity {
setAppCloudletList(new ArrayList<AppCloudlet>()); setAppCloudletList(new ArrayList<AppCloudlet>());
setCloudletSubmittedList(new ArrayList<Cloudlet>()); setCloudletSubmittedList(new ArrayList<Cloudlet>());
setCloudletReceivedList(new ArrayList<Cloudlet>()); setCloudletReceivedList(new ArrayList<Cloudlet>());
this.appCloudletRecieved=new HashMap<Integer,Integer>(); this.appCloudletRecieved = new HashMap<Integer, Integer>();
cloudletsSubmitted=0; cloudletsSubmitted = 0;
setVmsRequested(0); setVmsRequested(0);
setVmsAcks(0); setVmsAcks(0);
setVmsDestroyed(0); setVmsDestroyed(0);
...@@ -128,15 +125,16 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -128,15 +125,16 @@ public class NetDatacenterBroker extends SimEntity {
setDatacenterRequestedIdsList(new ArrayList<Integer>()); setDatacenterRequestedIdsList(new ArrayList<Integer>());
setVmsToDatacentersMap(new HashMap<Integer, Integer>()); setVmsToDatacentersMap(new HashMap<Integer, Integer>());
setDatacenterCharacteristicsList(new HashMap<Integer, DatacenterCharacteristics>()); setDatacenterCharacteristicsList(new HashMap<Integer, DatacenterCharacteristics>());
} }
/** /**
* This method is used to send to the broker the list with * This method is used to send to the broker the list with virtual machines
* virtual machines that must be created. * that must be created.
* *
* @param list the list * @param list
* * the list
*
* @pre list !=null * @pre list !=null
* @post $none * @post $none
*/ */
...@@ -145,90 +143,98 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -145,90 +143,98 @@ public class NetDatacenterBroker extends SimEntity {
} }
/** /**
* This method is used to send to the broker the list of * This method is used to send to the broker the list of cloudlets.
* cloudlets. *
* * @param list
* @param list the list * the list
* *
* @pre list !=null * @pre list !=null
* @post $none * @post $none
*/ */
public void submitCloudletList(List<? extends NetworkCloudlet> list){ public void submitCloudletList(List<? extends NetworkCloudlet> list) {
getCloudletList().addAll(list); getCloudletList().addAll(list);
} }
/** /**
* Specifies that a given cloudlet must run in a specific virtual machine. * Specifies that a given cloudlet must run in a specific virtual machine.
* *
* @param cloudletId ID of the cloudlet being bount to a vm * @param cloudletId
* @param vmId the vm id * ID of the cloudlet being bount to a vm
* * @param vmId
* the vm id
*
* @pre cloudletId > 0 * @pre cloudletId > 0
* @pre id > 0 * @pre id > 0
* @post $none * @post $none
*/ */
// public void bindCloudletToVm(int cloudletId, int vmId){ // public void bindCloudletToVm(int cloudletId, int vmId){
// CloudletList.getById(getCloudletList(), cloudletId).setVmId(vmId); // CloudletList.getById(getCloudletList(), cloudletId).setVmId(vmId);
// } // }
public void setLinkDC(NetworkDatacenter linkDC) { public void setLinkDC(NetworkDatacenter linkDC) {
this.linkDC = linkDC; this.linkDC = linkDC;
} }
/** /**
* Processes events available for this Broker. * Processes events available for this Broker.
* *
* @param ev a SimEvent object * @param ev
* * a SimEvent object
* @pre ev != null *
* @post $none * @pre ev != null
*/ * @post $none
*/
@Override @Override
public void processEvent(SimEvent ev) { public void processEvent(SimEvent ev) {
//Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag()); // Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag());
switch (ev.getTag()){ switch (ev.getTag()) {
// Resource characteristics request // Resource characteristics request
case CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST: case CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST:
processResourceCharacteristicsRequest(ev); processResourceCharacteristicsRequest(ev);
break; break;
// Resource characteristics answer // Resource characteristics answer
case CloudSimTags.RESOURCE_CHARACTERISTICS: case CloudSimTags.RESOURCE_CHARACTERISTICS:
processResourceCharacteristics(ev); processResourceCharacteristics(ev);
break; break;
// VM Creation answer // VM Creation answer
//A finished cloudlet returned // A finished cloudlet returned
case CloudSimTags.CLOUDLET_RETURN: case CloudSimTags.CLOUDLET_RETURN:
processCloudletReturn(ev); processCloudletReturn(ev);
break; break;
// if the simulation finishes // if the simulation finishes
case CloudSimTags.END_OF_SIMULATION: case CloudSimTags.END_OF_SIMULATION:
shutdownEntity(); shutdownEntity();
break; break;
case CloudSimTags.NextCycle: case CloudSimTags.NextCycle:
if(Constants.BASE) if (NetworkConstants.BASE)
this.createVmsInDatacenterBase(this.linkDC.getId()); this.createVmsInDatacenterBase(this.linkDC.getId());
break; break;
// other unknown tags are processed by this method // other unknown tags are processed by this method
default: default:
processOtherEvent(ev); processOtherEvent(ev);
break; break;
} }
} }
/** /**
* Process the return of a request for the characteristics of a PowerDatacenter. * Process the return of a request for the characteristics of a
* * PowerDatacenter.
* @param ev a SimEvent object *
* * @param ev
* a SimEvent object
*
* @pre ev != $null * @pre ev != $null
* @post $none * @post $none
*/ */
protected void processResourceCharacteristics(SimEvent ev) { protected void processResourceCharacteristics(SimEvent ev) {
DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev
getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics); .getData();
getDatacenterCharacteristicsList().put(characteristics.getId(),
characteristics);
if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) { if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList()
.size()) {
setDatacenterRequestedIdsList(new ArrayList<Integer>()); setDatacenterRequestedIdsList(new ArrayList<Integer>());
createVmsInDatacenterBase(getDatacenterIdsList().get(0)); createVmsInDatacenterBase(getDatacenterIdsList().get(0));
} }
...@@ -236,60 +242,63 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -236,60 +242,63 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Process a request for the characteristics of a PowerDatacenter. * Process a request for the characteristics of a PowerDatacenter.
* *
* @param ev a SimEvent object * @param ev
* * a SimEvent object
*
* @pre ev != $null * @pre ev != $null
* @post $none * @post $none
*/ */
protected void processResourceCharacteristicsRequest(SimEvent ev) { protected void processResourceCharacteristicsRequest(SimEvent ev) {
setDatacenterIdsList(CloudSim.getCloudResourceList()); setDatacenterIdsList(CloudSim.getCloudResourceList());
setDatacenterCharacteristicsList(new HashMap<Integer, DatacenterCharacteristics>()); setDatacenterCharacteristicsList(new HashMap<Integer, DatacenterCharacteristics>());
Log.printLine(CloudSim.clock()+": "+getName()+ ": Cloud Resource List received with "+getDatacenterIdsList().size()+" resource(s)"); Log.printLine(CloudSim.clock() + ": " + getName()
+ ": Cloud Resource List received with "
+ getDatacenterIdsList().size() + " resource(s)");
for (Integer datacenterId : getDatacenterIdsList()) { for (Integer datacenterId : getDatacenterIdsList()) {
sendNow(datacenterId, CloudSimTags.RESOURCE_CHARACTERISTICS, getId()); sendNow(datacenterId, CloudSimTags.RESOURCE_CHARACTERISTICS,
getId());
} }
} }
/** /**
* Process the ack received due to a request for VM creation. * Process the ack received due to a request for VM creation.
* *
* @param ev a SimEvent object * @param ev
* * a SimEvent object
*
* @pre ev != null * @pre ev != null
* @post $none * @post $none
*/ */
/** /**
* Process a cloudlet return event. * Process a cloudlet return event.
* *
* @param ev a SimEvent object * @param ev
* * a SimEvent object
*
* @pre ev != $null * @pre ev != $null
* @post $none * @post $none
*/ */
protected void processCloudletReturn(SimEvent ev) { protected void processCloudletReturn(SimEvent ev) {
Cloudlet cloudlet = (Cloudlet) ev.getData(); Cloudlet cloudlet = (Cloudlet) ev.getData();
getCloudletReceivedList().add(cloudlet); getCloudletReceivedList().add(cloudlet);
//Log.printLine(CloudSim.clock()+": "+getName()+ ": Cloudlet "+cloudlet.getCloudletId()+" received"); // Log.printLine(CloudSim.clock()+": "+getName()+
// ": Cloudlet "+cloudlet.getCloudletId()+" received");
cloudletsSubmitted--; cloudletsSubmitted--;
if (getCloudletList().size()==0&&cloudletsSubmitted==0&& Constants.iteration>10) { //all cloudlets executed if (getCloudletList().size() == 0 && cloudletsSubmitted == 0
Log.printLine(CloudSim.clock()+": "+getName()+ ": All Cloudlets executed. Finishing..."); && NetworkConstants.iteration > 10) { // all cloudlets executed
Log.printLine(CloudSim.clock() + ": " + getName()
+ ": All Cloudlets executed. Finishing...");
clearDatacenters(); clearDatacenters();
finishExecution(); finishExecution();
} else { //some cloudlets haven't finished yet } else { // some cloudlets haven't finished yet
if (getAppCloudletList().size()>0 && cloudletsSubmitted==0) { if (getAppCloudletList().size() > 0 && cloudletsSubmitted == 0) {
//all the cloudlets sent finished. It means that some bount // all the cloudlets sent finished. It means that some bount
//cloudlet is waiting its VM be created // cloudlet is waiting its VM be created
clearDatacenters(); clearDatacenters();
createVmsInDatacenterBase(0); createVmsInDatacenterBase(0);
} }
...@@ -300,154 +309,157 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -300,154 +309,157 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Overrides this method when making a new and different type of Broker. * Overrides this method when making a new and different type of Broker.
* This method is called by {@link #body()} for incoming unknown tags. * This method is called by {@link #body()} for incoming unknown tags.
* *
* @param ev a SimEvent object * @param ev
* * a SimEvent object
*
* @pre ev != null * @pre ev != null
* @post $none * @post $none
*/ */
protected void processOtherEvent(SimEvent ev){ protected void processOtherEvent(SimEvent ev) {
if (ev == null){ if (ev == null) {
Log.printLine(getName() + ".processOtherEvent(): " + "Error - an event is null."); Log.printLine(getName() + ".processOtherEvent(): "
return; + "Error - an event is null.");
} return;
}
Log.printLine(getName() + ".processOtherEvent(): " + "Error - event unknown by this DatacenterBroker.");
} Log.printLine(getName() + ".processOtherEvent(): "
+ "Error - event unknown by this DatacenterBroker.");
/** }
* Create the virtual machines in a datacenter.
* /**
* @param datacenterId Id of the chosen PowerDatacenter * Create the virtual machines in a datacenter and submit/schedule cloudlets
* * to them.
* @pre $none *
* @post $none * @param datacenterId
*/ * Id of the chosen PowerDatacenter
protected void createVmsInDatacenterBase(int datacenterId) { *
// send as much vms as possible for this datacenter before trying the next one * @pre $none
* @post $none
*/
protected void createVmsInDatacenterBase(int datacenterId) {
// send as much vms as possible for this datacenter before trying the
// next one
int requestedVms = 0; int requestedVms = 0;
String datacenterName = CloudSim.getEntityName(datacenterId); String datacenterName = CloudSim.getEntityName(datacenterId);
int j=0; int j = 0;
//All host will have two VMs (assumption) VM is the minimum unit // All host will have two VMs (assumption) VM is the minimum unit
if(createvmflag) if (createvmflag) {
{ CreateVMs(datacenterId);
CreateVMs(datacenterId); createvmflag = false;
createvmflag=false; }
}
// generate Application execution Requests
//generate Request
//RequestGenerator reqgen=new RequestGenerator(); for (int i = 0; i < 100; i++) {
this.getAppCloudletList().add(
//OptionPricingRequest[] reqs=reqgen.getNextRequests(1); new WorkflowApp(AppCloudlet.APP_Workflow,
NetworkConstants.currentAppId, 0, 0, this.getId()));
for(int i=0;i<100;i++) NetworkConstants.currentAppId++;
{
this.getAppCloudletList().add(new WorkflowApp(AppCloudlet.APP_Workflow, Constants.currentAppId, 0, 0, this.getId()));
//this.getAppCloudletList().add(reqs[i].getAppCloudlet(0,));
Constants.currentAppId++;
} }
int seed=5; int seed = 5;
int k=0; int k = 0;
int totalvm=this.vmsCreatedList.size(); int totalvm = this.vmsCreatedList.size();
int currentvmid=0; int currentvmid = 0;
for(AppCloudlet app:this.getAppCloudletList())
{ //schedule the application on VMs
for (AppCloudlet app : this.getAppCloudletList()) {
List<Integer> vmids=new ArrayList<Integer>();
int numVms=this.linkDC.getVmList().size(); List<Integer> vmids = new ArrayList<Integer>();
UniformDistr ufrnd=new UniformDistr(0,numVms,5); int numVms = this.linkDC.getVmList().size();
for(int i=0;i<app.numbervm;i++) UniformDistr ufrnd = new UniformDistr(0, numVms, 5);
{ for (int i = 0; i < app.numbervm; i++) {
// int vmid=currentvmid%numVms;// int vmid = (int) ufrnd.sample();
int vmid=(int)ufrnd.sample(); currentvmid++;
currentvmid++; vmids.add(vmid);
vmids.add(vmid);
}
}
if (vmids != null) {
if(vmids!=null){ if (!vmids.isEmpty()) {
if(!vmids.isEmpty()){
app.createCloudletList(vmids); app.createCloudletList(vmids);
for(int i=0;i<app.numbervm;i++) for (int i = 0; i < app.numbervm; i++) {
{
app.clist.get(i).setUserId(this.getId()); app.clist.get(i).setUserId(this.getId());
//this.getCloudletList().add(app.clist.get(i)); // this.getCloudletList().add(app.clist.get(i));
this.appCloudletRecieved.put(app.appID, app.numbervm); this.appCloudletRecieved.put(app.appID, app.numbervm);
this.getCloudletSubmittedList().add(app.clist.get(i)); this.getCloudletSubmittedList().add(app.clist.get(i));
this.cloudletsSubmitted++; this.cloudletsSubmitted++;
//Log.printLine(CloudSim.clock()+": "+getName()+ ": Sending cloudlet "+app.clist.get(i).getCloudletId()+" to VM #"+app.clist.get(i).getVmId()); // Log.printLine(CloudSim.clock()+": "+getName()+
sendNow(getVmsToDatacentersMap().get(this.getVmList().get(0).getId()), CloudSimTags.CLOUDLET_SUBMIT, app.clist.get(i)); // Sending cloudlet
sendNow(getVmsToDatacentersMap().get(
this.getVmList().get(0).getId()),
CloudSimTags.CLOUDLET_SUBMIT, app.clist.get(i));
} }
System.out.println("app"+(k++)); System.out.println("app" + (k++));
} }
} }
} }
setAppCloudletList(new ArrayList<AppCloudlet>()); setAppCloudletList(new ArrayList<AppCloudlet>());
if(Constants.iteration<10){ if (NetworkConstants.iteration < 10) {
Constants.iteration++; NetworkConstants.iteration++;
this.schedule(this.getId(), Constants.nexttime, CloudSimTags.NextCycle); this.schedule(this.getId(), NetworkConstants.nexttime,
CloudSimTags.NextCycle);
} }
getDatacenterRequestedIdsList().add(datacenterId);
setVmsRequested(requestedVms); setVmsRequested(requestedVms);
setVmsAcks(0); setVmsAcks(0);
} }
private void CreateVMs(int datacenterId) {
private void CreateVMs(int datacenterId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
int numVM=this.linkDC.getHostList().size()*Constants.maxhostVM; // two VMs per host int numVM = this.linkDC.getHostList().size() * NetworkConstants.maxhostVM; // two
for(int i=0;i<numVM;i++) // VMs
{ // per
int requestedVms = 0; // host
int vmid = i; for (int i = 0; i < numVM; i++) {
int requestedVms = 0;
int vmid = i;
int mips = 1; int mips = 1;
long size = 10000; // image size (MB) long size = 10000; // image size (MB)
int ram = 512; // vm memory (MB) int ram = 512; // vm memory (MB)
long bw = 1000; long bw = 1000;
int pesNumber = Constants.HOST_PEs/Constants.maxhostVM; // number of cpus int pesNumber = NetworkConstants.HOST_PEs / NetworkConstants.maxhostVM; // number
// of
// cpus
String vmm = "Xen"; // VMM name String vmm = "Xen"; // VMM name
// create VM // create VM
NetworkVm vm = new NetworkVm(vmid, this.getId(), mips, pesNumber, ram, bw, size, vmm, new CloudletHPCSpaceShared()); NetworkVm vm = new NetworkVm(vmid, this.getId(), mips, pesNumber,
this.linkDC.processVmCreateHPC(vm); ram, bw, size, vmm, new NetworkCloudletSpaceSharedScheduler());
this.linkDC.processVmCreateNetwork(vm);
// add the VM to the vmList // add the VM to the vmList
getVmList().add(vm); getVmList().add(vm);
requestedVms++; requestedVms++;
getVmsToDatacentersMap().put(vmid, datacenterId); getVmsToDatacentersMap().put(vmid, datacenterId);
getVmsCreatedList().add(VmList.getById(getVmList(), vmid)); getVmsCreatedList().add(VmList.getById(getVmList(), vmid));
} }
} }
/**
* Submit cloudlets to the created VMs.
*
* @pre $none
* @post $none
/** /**
* Destroy the virtual machines running in datacenters. * Submit cloudlets to the created VMs.
* *
* @pre $none
* @post $none /** Destroy the virtual machines running in datacenters.
*
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
protected void clearDatacenters() { protected void clearDatacenters() {
for (Vm vm : getVmsCreatedList()) { for (Vm vm : getVmsCreatedList()) {
Log.printLine(CloudSim.clock() + ": " + getName() + ": Destroying VM #" + vm.getId()); Log.printLine(CloudSim.clock() + ": " + getName()
sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.VM_DESTROY, vm); + ": Destroying VM #" + vm.getId());
sendNow(getVmsToDatacentersMap().get(vm.getId()),
CloudSimTags.VM_DESTROY, vm);
} }
getVmsCreatedList().clear(); getVmsCreatedList().clear();
...@@ -455,7 +467,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -455,7 +467,7 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Send an internal event communicating the end of the simulation. * Send an internal event communicating the end of the simulation.
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -463,15 +475,19 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -463,15 +475,19 @@ public class NetDatacenterBroker extends SimEntity {
sendNow(getId(), CloudSimTags.END_OF_SIMULATION); sendNow(getId(), CloudSimTags.END_OF_SIMULATION);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see cloudsim.core.SimEntity#shutdownEntity() * @see cloudsim.core.SimEntity#shutdownEntity()
*/ */
@Override @Override
public void shutdownEntity() { public void shutdownEntity() {
Log.printLine(getName() + " is shutting down..."); Log.printLine(getName() + " is shutting down...");
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see cloudsim.core.SimEntity#startEntity() * @see cloudsim.core.SimEntity#startEntity()
*/ */
@Override @Override
...@@ -482,8 +498,9 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -482,8 +498,9 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Gets the vm list. * Gets the vm list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the vm list * @return the vm list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -493,19 +510,21 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -493,19 +510,21 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the vm list. * Sets the vm list.
* *
* @param <T> the generic type * @param <T>
* @param vmList the new vm list * the generic type
* @param vmList
* the new vm list
*/ */
protected <T extends Vm> void setVmList(List<T> vmList) { protected <T extends Vm> void setVmList(List<T> vmList) {
this.vmList = vmList; this.vmList = vmList;
} }
/** /**
* Gets the cloudlet list. * Gets the cloudlet list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet list * @return the cloudlet list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -513,29 +532,33 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -513,29 +532,33 @@ public class NetDatacenterBroker extends SimEntity {
return (List<T>) cloudletList; return (List<T>) cloudletList;
} }
/** /**
* Sets the cloudlet list. * Sets the cloudlet list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletList the new cloudlet list * the generic type
*/ * @param cloudletList
protected <T extends NetworkCloudlet> void setCloudletList(List<T> cloudletList) { * the new cloudlet list
*/
protected <T extends NetworkCloudlet> void setCloudletList(
List<T> cloudletList) {
this.cloudletList = cloudletList; this.cloudletList = cloudletList;
} }
public<T extends AppCloudlet> List<T>getAppCloudletList() { public <T extends AppCloudlet> List<T> getAppCloudletList() {
return (List<T>)appCloudletList; return (List<T>) appCloudletList;
} }
public <T extends AppCloudlet> void setAppCloudletList(List<T> appCloudletList) { public <T extends AppCloudlet> void setAppCloudletList(
List<T> appCloudletList) {
this.appCloudletList = appCloudletList; this.appCloudletList = appCloudletList;
} }
/** /**
* Gets the cloudlet submitted list. * Gets the cloudlet submitted list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet submitted list * @return the cloudlet submitted list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -543,21 +566,24 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -543,21 +566,24 @@ public class NetDatacenterBroker extends SimEntity {
return (List<T>) cloudletSubmittedList; return (List<T>) cloudletSubmittedList;
} }
/** /**
* Sets the cloudlet submitted list. * Sets the cloudlet submitted list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletSubmittedList the new cloudlet submitted list * the generic type
*/ * @param cloudletSubmittedList
protected <T extends Cloudlet> void setCloudletSubmittedList(List<T> cloudletSubmittedList) { * the new cloudlet submitted list
*/
protected <T extends Cloudlet> void setCloudletSubmittedList(
List<T> cloudletSubmittedList) {
this.cloudletSubmittedList = cloudletSubmittedList; this.cloudletSubmittedList = cloudletSubmittedList;
} }
/** /**
* Gets the cloudlet received list. * Gets the cloudlet received list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet received list * @return the cloudlet received list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -567,18 +593,22 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -567,18 +593,22 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the cloudlet received list. * Sets the cloudlet received list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletReceivedList the new cloudlet received list * the generic type
*/ * @param cloudletReceivedList
protected <T extends Cloudlet> void setCloudletReceivedList(List<T> cloudletReceivedList) { * the new cloudlet received list
*/
protected <T extends Cloudlet> void setCloudletReceivedList(
List<T> cloudletReceivedList) {
this.cloudletReceivedList = cloudletReceivedList; this.cloudletReceivedList = cloudletReceivedList;
} }
/** /**
* Gets the vm list. * Gets the vm list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the vm list * @return the vm list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -588,9 +618,11 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -588,9 +618,11 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the vm list. * Sets the vm list.
* *
* @param <T> the generic type * @param <T>
* @param vmsCreatedList the vms created list * the generic type
* @param vmsCreatedList
* the vms created list
*/ */
protected <T extends Vm> void setVmsCreatedList(List<T> vmsCreatedList) { protected <T extends Vm> void setVmsCreatedList(List<T> vmsCreatedList) {
this.vmsCreatedList = vmsCreatedList; this.vmsCreatedList = vmsCreatedList;
...@@ -598,7 +630,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -598,7 +630,7 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Gets the vms requested. * Gets the vms requested.
* *
* @return the vms requested * @return the vms requested
*/ */
protected int getVmsRequested() { protected int getVmsRequested() {
...@@ -607,8 +639,9 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -607,8 +639,9 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the vms requested. * Sets the vms requested.
* *
* @param vmsRequested the new vms requested * @param vmsRequested
* the new vms requested
*/ */
protected void setVmsRequested(int vmsRequested) { protected void setVmsRequested(int vmsRequested) {
this.vmsRequested = vmsRequested; this.vmsRequested = vmsRequested;
...@@ -616,7 +649,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -616,7 +649,7 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Gets the vms acks. * Gets the vms acks.
* *
* @return the vms acks * @return the vms acks
*/ */
protected int getVmsAcks() { protected int getVmsAcks() {
...@@ -625,8 +658,9 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -625,8 +658,9 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the vms acks. * Sets the vms acks.
* *
* @param vmsAcks the new vms acks * @param vmsAcks
* the new vms acks
*/ */
protected void setVmsAcks(int vmsAcks) { protected void setVmsAcks(int vmsAcks) {
this.vmsAcks = vmsAcks; this.vmsAcks = vmsAcks;
...@@ -641,7 +675,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -641,7 +675,7 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Gets the vms destroyed. * Gets the vms destroyed.
* *
* @return the vms destroyed * @return the vms destroyed
*/ */
protected int getVmsDestroyed() { protected int getVmsDestroyed() {
...@@ -650,8 +684,9 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -650,8 +684,9 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the vms destroyed. * Sets the vms destroyed.
* *
* @param vmsDestroyed the new vms destroyed * @param vmsDestroyed
* the new vms destroyed
*/ */
protected void setVmsDestroyed(int vmsDestroyed) { protected void setVmsDestroyed(int vmsDestroyed) {
this.vmsDestroyed = vmsDestroyed; this.vmsDestroyed = vmsDestroyed;
...@@ -659,7 +694,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -659,7 +694,7 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Gets the datacenter ids list. * Gets the datacenter ids list.
* *
* @return the datacenter ids list * @return the datacenter ids list
*/ */
protected List<Integer> getDatacenterIdsList() { protected List<Integer> getDatacenterIdsList() {
...@@ -668,8 +703,9 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -668,8 +703,9 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the datacenter ids list. * Sets the datacenter ids list.
* *
* @param datacenterIdsList the new datacenter ids list * @param datacenterIdsList
* the new datacenter ids list
*/ */
protected void setDatacenterIdsList(List<Integer> datacenterIdsList) { protected void setDatacenterIdsList(List<Integer> datacenterIdsList) {
this.datacenterIdsList = datacenterIdsList; this.datacenterIdsList = datacenterIdsList;
...@@ -677,7 +713,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -677,7 +713,7 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Gets the vms to datacenters map. * Gets the vms to datacenters map.
* *
* @return the vms to datacenters map * @return the vms to datacenters map
*/ */
protected Map<Integer, Integer> getVmsToDatacentersMap() { protected Map<Integer, Integer> getVmsToDatacentersMap() {
...@@ -686,16 +722,18 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -686,16 +722,18 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the vms to datacenters map. * Sets the vms to datacenters map.
* *
* @param vmsToDatacentersMap the vms to datacenters map * @param vmsToDatacentersMap
* the vms to datacenters map
*/ */
protected void setVmsToDatacentersMap(Map<Integer, Integer> vmsToDatacentersMap) { protected void setVmsToDatacentersMap(
Map<Integer, Integer> vmsToDatacentersMap) {
this.vmsToDatacentersMap = vmsToDatacentersMap; this.vmsToDatacentersMap = vmsToDatacentersMap;
} }
/** /**
* Gets the datacenter characteristics list. * Gets the datacenter characteristics list.
* *
* @return the datacenter characteristics list * @return the datacenter characteristics list
*/ */
protected Map<Integer, DatacenterCharacteristics> getDatacenterCharacteristicsList() { protected Map<Integer, DatacenterCharacteristics> getDatacenterCharacteristicsList() {
...@@ -704,16 +742,18 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -704,16 +742,18 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the datacenter characteristics list. * Sets the datacenter characteristics list.
* *
* @param datacenterCharacteristicsList the datacenter characteristics list * @param datacenterCharacteristicsList
* the datacenter characteristics list
*/ */
protected void setDatacenterCharacteristicsList(Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList) { protected void setDatacenterCharacteristicsList(
Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList) {
this.datacenterCharacteristicsList = datacenterCharacteristicsList; this.datacenterCharacteristicsList = datacenterCharacteristicsList;
} }
/** /**
* Gets the datacenter requested ids list. * Gets the datacenter requested ids list.
* *
* @return the datacenter requested ids list * @return the datacenter requested ids list
*/ */
protected List<Integer> getDatacenterRequestedIdsList() { protected List<Integer> getDatacenterRequestedIdsList() {
...@@ -722,10 +762,12 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -722,10 +762,12 @@ public class NetDatacenterBroker extends SimEntity {
/** /**
* Sets the datacenter requested ids list. * Sets the datacenter requested ids list.
* *
* @param datacenterRequestedIdsList the new datacenter requested ids list * @param datacenterRequestedIdsList
* the new datacenter requested ids list
*/ */
protected void setDatacenterRequestedIdsList(List<Integer> datacenterRequestedIdsList) { protected void setDatacenterRequestedIdsList(
List<Integer> datacenterRequestedIdsList) {
this.datacenterRequestedIdsList = datacenterRequestedIdsList; this.datacenterRequestedIdsList = datacenterRequestedIdsList;
} }
......
package org.cloudbus.cloudsim.network.datacenter;
public class NetPacket {
public NetPacket(int sender, int reciever, double data, double sendtime,
double recievetime,int vsnd,int vrvd) {
super();
this.sender = sender;
this.reciever = reciever;
this.data = data;
this.sendtime = sendtime;
this.recievetime = recievetime;
this.virtualrecvid=vrvd;
this.virtualsendid=vsnd;
}
int sender;
int virtualrecvid;
int virtualsendid;
int reciever;
double data;
double sendtime;
double recievetime;
}
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
/**
* NetworkCloudlet class extends Cloudlet to support simulation of complex applications.
* Each such network Cloudlet represents a task of the application. Each task consists of several
* stages.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class NetworkCloudlet extends Cloudlet implements Comparable {
public class NetworkCloudlet extends Cloudlet implements Comparable{
long memory; long memory;
public NetworkCloudlet(int cloudletId, long cloudletLength, public NetworkCloudlet(int cloudletId, long cloudletLength, int pesNumber,
int pesNumber, long cloudletFileSize, long cloudletOutputSize, long memory, long cloudletFileSize, long cloudletOutputSize, long memory,
UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelCpu,
UtilizationModel utilizationModelRam, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw) { UtilizationModel utilizationModelBw) {
...@@ -21,41 +34,36 @@ public class NetworkCloudlet extends Cloudlet implements Comparable{ ...@@ -21,41 +34,36 @@ public class NetworkCloudlet extends Cloudlet implements Comparable{
cloudletOutputSize, utilizationModelCpu, utilizationModelRam, cloudletOutputSize, utilizationModelCpu, utilizationModelRam,
utilizationModelBw); utilizationModelBw);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
currStagenum=-1; currStagenum = -1;
this.memory=memory; this.memory = memory;
stages=new ArrayList<TaskStage>(); stages = new ArrayList<TaskStage>();
} }
public double submittime;
public double finishtime; public double submittime; //time when cloudlet will be submitted
public double exetime; public double finishtime; //time when cloudlet finish execution
public double numStage; public double exetime; //execution time for cloudlet
public int currStagenum; public double numStage;//number of stages in cloudlet
public int currStagenum; //current stage of cloudlet execution
public double timetostartStage; public double timetostartStage;
public double timespentInStage; public double timespentInStage; //how much time spent in particular stage
public Map<Double, NetPacket> timeCommunicate; public Map<Double, HostPacket> timeCommunicate;
public ArrayList<TaskStage> stages; public ArrayList<TaskStage> stages; //all stages which cloudlet execution consists of.
public double starttime;
public double starttime;
@Override @Override
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
NetworkCloudlet s1=(NetworkCloudlet)arg0; NetworkCloudlet s1 = (NetworkCloudlet) arg0;
int alpha=0; int alpha = 0;
return 0; return 0;
} }
public double getSubmittime() { public double getSubmittime() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return submittime; return submittime;
}; };
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -16,30 +15,28 @@ import org.cloudbus.cloudsim.ResCloudlet; ...@@ -16,30 +15,28 @@ import org.cloudbus.cloudsim.ResCloudlet;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags; import org.cloudbus.cloudsim.core.CloudSimTags;
public class CloudletHPCSpaceSharedO extends CloudletScheduler{ public class NetworkCloudletSpaceSharedScheduler extends CloudletScheduler {
/*
* 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-2010, The University of Melbourne, Australia
*/
/*
* 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-2010, The University of Melbourne, Australia
*/
/** /**
* CloudletSchedulerSpaceShared implements a policy of * CloudletSchedulerSpaceShared implements a policy of scheduling performed
* scheduling performed by a virtual machine. It consider * by a virtual machine. It consider that there will be only one cloudlet
* that there will be only one cloudlet per VM. Other cloudlets will be in a * per VM. Other cloudlets will be in a waiting list. We consider that file
* waiting list. We consider that file transfer from cloudlets waiting happens * transfer from cloudlets waiting happens before cloudlet execution. I.e.,
* before cloudlet execution. I.e., even though cloudlets must wait for CPU, * even though cloudlets must wait for CPU, data transfer happens as soon as
* data transfer happens as soon as cloudlets are submitted. * cloudlets are submitted.
* *
* @author Rodrigo N. Calheiros * @author Saurabh Kumar Garg
* @author Anton Beloglazov * @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 3.0
*/ */
/** The cloudlet waiting list. */ /** The cloudlet waiting list. */
private List<? extends ResCloudlet> cloudletWaitingList; private List<? extends ResCloudlet> cloudletWaitingList;
...@@ -58,23 +55,20 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -58,23 +55,20 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** The used PEs. */ /** The used PEs. */
protected int usedPes; protected int usedPes;
// for network
//for network
private ResCloudlet buffered;//to overlap with communication public Map<Integer, List<HostPacket>> pkttosend;
private double lastbufferUpdateTime; public Map<Integer, List<HostPacket>> pktrecv;
public Map<Integer,List<NetPacket>> pkttosend;
public Map<Integer,List<NetPacket>> pktrecv;
/** /**
* Creates a new CloudletSchedulerSpaceShared object. This method must be invoked * Creates a new CloudletSchedulerSpaceShared object. This method must be
* before starting the actual simulation. * invoked before starting the actual simulation.
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
public CloudletHPCSpaceSharedO() { public NetworkCloudletSpaceSharedScheduler() {
super(); super();
this.cloudletWaitingList = new ArrayList<ResCloudlet>(); this.cloudletWaitingList = new ArrayList<ResCloudlet>();
this.cloudletExecList = new ArrayList<ResCloudlet>(); this.cloudletExecList = new ArrayList<ResCloudlet>();
...@@ -82,29 +76,34 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -82,29 +76,34 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
this.cloudletFinishedList = new ArrayList<ResCloudlet>(); this.cloudletFinishedList = new ArrayList<ResCloudlet>();
this.usedPes = 0; this.usedPes = 0;
this.currentCpus = 0; this.currentCpus = 0;
this.pkttosend= new HashMap<Integer,List<NetPacket>>(); this.pkttosend = new HashMap<Integer, List<HostPacket>>();
this.pktrecv= new HashMap<Integer,List<NetPacket>>(); this.pktrecv = new HashMap<Integer, List<HostPacket>>();
//this.buffered=new ArrayList<ResCloudlet>();
} }
/** /**
* Updates the processing of cloudlets running under management of this scheduler. * Updates the processing of cloudlets running under management of this
* * scheduler.
* @param currentTime current simulation time *
* @param mipsShare array with MIPS share of each processor available to the scheduler * @param currentTime
* * current simulation time
* @return time predicted completion time of the earliest finishing cloudlet, or 0 * @param mipsShare
* if there is no next events * array with MIPS share of each processor available to the
* * scheduler
*
* @return time predicted completion time of the earliest finishing
* cloudlet, or 0 if there is no next events
*
* @pre currentTime >= 0 * @pre currentTime >= 0
* @post $none * @post $none
*/ */
@Override
public double updateVmProcessing(double currentTime, List<Double> mipsShare) { public double updateVmProcessing(double currentTime, List<Double> mipsShare) {
setCurrentMipsShare(mipsShare); setCurrentMipsShare(mipsShare);
double timeSpam = currentTime - getPreviousTime(); // time since last update double timeSpam = currentTime - getPreviousTime(); // time since last
// update
double capacity = 0.0; double capacity = 0.0;
int cpus = 0; int cpus = 0;
for (Double mips : mipsShare) { // count the CPUs available to the VMM for (Double mips : mipsShare) { // count the CPUs available to the VMM
capacity += mips; capacity += mips;
if (mips > 0) { if (mips > 0) {
...@@ -113,111 +112,102 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -113,111 +112,102 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
currentCpus = cpus; currentCpus = cpus;
capacity /= cpus; // average capacity of each cpu capacity /= cpus; // average capacity of each cpu
if(getCloudletExecList().size()>1)
System.out.println("Something is wrong "+getCloudletExecList().size()); for (ResCloudlet rcl : getCloudletExecList()) { // each machine in the
for (ResCloudlet rcl : getCloudletExecList()) { // each machine in the exec list has the same amount of cpu // exec list has the
// same amount of cpu
NetworkCloudlet cl=(NetworkCloudlet) rcl.getCloudlet();
if((cl.currStagenum!=-1)) NetworkCloudlet cl = (NetworkCloudlet) rcl.getCloudlet();
{
if(cl.currStagenum==Constants.FINISH){ // check status
//long len=rcl.getRemainingCloudletLength(); // if execution stage
//rcl.updateCloudletFinishedSoFar(len); // update the cloudlet finishtime
// CHECK WHETHER IT IS WAITING FOR THE PACKET
// if packet received change the status of job and update the time.
//
if ((cl.currStagenum != -1)) {
if (cl.currStagenum == NetworkConstants.FINISH) {
// long len=rcl.getRemainingCloudletLength();
// rcl.updateCloudletFinishedSoFar(len);
break; break;
} }
TaskStage st= cl.stages.get(cl.currStagenum); TaskStage st = cl.stages.get(cl.currStagenum);
if(st.type==Constants.EXECUTION) if (st.type == NetworkConstants.EXECUTION) {
{
//if(Constants.logflag) // rcl.updateCloudletFinishedSoFar((long) (capacity *
//System.out.println(cl.getCloudletId()+ "Cloudlet is in Execution: "+ CloudSim.clock()); // Math.round(timeSpam) * rcl.getPesNumber()));
//rcl.updateCloudletFinishedSoFar((long) (capacity * Math.round(timeSpam) * rcl.getPesNumber())); // update the time
//update the time cl.timespentInStage = Math.round(CloudSim.clock()
cl.timespentInStage+=Math.round(CloudSim.clock()-cl.timetostartStage); - cl.timetostartStage);
if(cl.getCloudletId()==198) if (cl.timespentInStage >= st.time) {
System.out.println("I am in 198 "+CloudSim.clock()); changetonextstage(cl, st);
if(cl.timespentInStage>=st.time) // change the stage
{ }
if(cl.getCloudletId()==198)
System.out.println("I am in 198 "+CloudSim.clock());
changetonextstage(cl,st);
//change the stage
}
} }
if(st.type==Constants.WAIT_RECV) if (st.type == NetworkConstants.WAIT_RECV) {
{ List<HostPacket> pktlist = this.pktrecv.get(st.peer);
List<NetPacket> pktlist=this.pktrecv.get(st.vpeer); List<HostPacket> pkttoremove = new ArrayList<HostPacket>();
if(Constants.logflag) if (pktlist != null) {
System.out.println(cl.getCloudletId()+ "Cloudlet is in Recieve: "+ CloudSim.clock()); Iterator it = pktlist.iterator();
List<NetPacket> pkttoremove=new ArrayList<NetPacket>(); HostPacket pkt = null;
if(pktlist!=null){ if (it.hasNext()) {
if(pktlist.size()!=0) pkt = (HostPacket) it.next();
{ if (pkt.reciever == cl.getVmId())// Asumption packet
Iterator it=pktlist.iterator(); // will not
NetPacket pkt=null; // arrive in the
while(it.hasNext()) // same cycle
{ {
pkt=(NetPacket)it.next(); pkt.recievetime = CloudSim.clock();
if(pkt.virtualrecvid==cl.getCloudletId())//Asumption packet will not arrive in the same cycle st.time = CloudSim.clock() - pkt.sendtime;
{ changetonextstage(cl, st);
pkt.recievetime=CloudSim.clock(); pkttoremove.add(pkt);
st.time=CloudSim.clock()-pkt.sendtime; }
}
changetonextstage(cl,st); pktlist.removeAll(pkttoremove);
pkttoremove.add(pkt); // if(pkt!=null)
} // else wait for recieving the packet
} }
pktlist.removeAll(pkttoremove);
//if(pkt!=null)
//else wait for recieving the packet
}
}
if(buffered!=null)
updatebuffered(CloudSim.clock());
else {
//System.out.println("Update Buffer");
}
} }
} else {
} cl.currStagenum = 0;
else cl.timetostartStage = CloudSim.clock();
{
cl.currStagenum=0; if (cl.stages.get(0).type == NetworkConstants.EXECUTION)
cl.timetostartStage=CloudSim.clock(); NetDatacenterBroker.linkDC.schedule(
NetDatacenterBroker.linkDC.getId(),
if(cl.stages.get(0).type==Constants.EXECUTION) cl.stages.get(0).time,
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),cl.stages.get(0).time, CloudSimTags.VM_DATACENTER_EVENT); CloudSimTags.VM_DATACENTER_EVENT);
else else
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),0.0001, CloudSimTags.VM_DATACENTER_EVENT); NetDatacenterBroker.linkDC.schedule(
///sendstage/// NetDatacenterBroker.linkDC.getId(), 0.0001,
CloudSimTags.VM_DATACENTER_EVENT);
// /sendstage///
} }
//check status
//if execution stage
//update the cloudlet finishtime
//CHECK WHETHER IT IS WAITING FOR THE PACKET
// if packet received change the status of job and update the time.
//
//rcl.updateCloudletFinishedSoFar((long) (capacity * timeSpam * rcl.getPesNumber()));
} }
if (getCloudletExecList().size() == 0 && getCloudletWaitingList().size() == 0) { // no more cloudlets in this scheduler if (getCloudletExecList().size() == 0
&& getCloudletWaitingList().size() == 0) { // no more cloudlets
// in this scheduler
setPreviousTime(currentTime); setPreviousTime(currentTime);
return 0.0; return 0.0;
} }
//update each cloudlet // update each cloudlet
int finished = 0; int finished = 0;
int cont = 0; int cont = 0;
List<ResCloudlet> toRemove = new ArrayList<ResCloudlet>(); List<ResCloudlet> toRemove = new ArrayList<ResCloudlet>();
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
//if (rcl.getRemainingCloudletLength() == 0.0) {// finished anyway, rounding issue... // if (rcl.getRemainingCloudletLength() == 0.0) {// finished anyway,
if(((NetworkCloudlet)(rcl.getCloudlet())).currStagenum==Constants.FINISH){ // rounding issue...
//stage is changed and packet to send if (((NetworkCloudlet) (rcl.getCloudlet())).currStagenum == NetworkConstants.FINISH) {
System.out.println(rcl.getCloudletId()+ "Cloudlet is in finished: "+ CloudSim.clock()); // stage is changed and packet to send
((NetworkCloudlet)(rcl.getCloudlet())).finishtime=CloudSim.clock(); ((NetworkCloudlet) (rcl.getCloudlet())).finishtime = CloudSim
.clock();
toRemove.add(rcl); toRemove.add(rcl);
cloudletFinish(rcl); cloudletFinish(rcl);
finished++; finished++;
...@@ -225,66 +215,36 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -225,66 +215,36 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
cont++; cont++;
} }
getCloudletExecList().removeAll(toRemove); getCloudletExecList().removeAll(toRemove);
//add all the CloudletExecList in waitingList. // add all the CloudletExecList in waitingList.
//sort the waitinglist // sort the waitinglist
// //
// for each finished cloudlet, add a new one from the waiting list
//for each finished cloudlet, add a new one from the waiting list
if (!getCloudletWaitingList().isEmpty()) { if (!getCloudletWaitingList().isEmpty()) {
if(this.buffered==null){
buffered=getCloudletWaitingList().get(0);
NetworkCloudlet cl=(NetworkCloudlet)(buffered.getCloudlet());
cl.currStagenum=0;
cl.timetostartStage=CloudSim.clock();
}
for (int i = 0; i < finished; i++) { for (int i = 0; i < finished; i++) {
toRemove.clear(); toRemove.clear();
for (ResCloudlet rcl : getCloudletWaitingList()) { for (ResCloudlet rcl : getCloudletWaitingList()) {
if ((currentCpus - usedPes) >= rcl.getPesNumber()) { if ((currentCpus - usedPes) >= rcl.getPesNumber()) {
NetworkCloudlet cl1=(NetworkCloudlet)(rcl.getCloudlet());
if(cl1.currStagenum==Constants.FINISH)
{
System.out.println(rcl.getCloudletId()+ "Cloudlet is in finished: "+ CloudSim.clock());
((NetworkCloudlet)(rcl.getCloudlet())).finishtime=CloudSim.clock();
rcl.setCloudletStatus(Cloudlet.SUCCESS);
rcl.finalizeCloudlet();
getCloudletFinishedList().add(rcl);
toRemove.add(rcl);
continue;
}
rcl.setCloudletStatus(Cloudlet.INEXEC); rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int k = 0; k < rcl.getPesNumber(); k++) { for (int k = 0; k < rcl.getPesNumber(); k++) {
rcl.setMachineAndPeId(0, i); rcl.setMachineAndPeId(0, i);
} }
getCloudletExecList().add(rcl); getCloudletExecList().add(rcl);
usedPes += rcl.getPesNumber(); usedPes += rcl.getPesNumber();
toRemove.add(rcl); toRemove.add(rcl);
// if(buffered!=null){
// HPCCloudlet cl=(HPCCloudlet)(buffered.getCloudlet());
// cl.timetostartStage=CloudSim.clock();
// }
buffered=null;
break; break;
} }
} }
getCloudletWaitingList().removeAll(toRemove); getCloudletWaitingList().removeAll(toRemove);
}// for(cont) }// for(cont)
} }
//estimate finish time of cloudlets in the execution queue // estimate finish time of cloudlets in the execution queue
double nextEvent = Double.MAX_VALUE; double nextEvent = Double.MAX_VALUE;
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength(); double remainingLength = rcl.getRemainingCloudletLength();
NetworkCloudlet cl=(NetworkCloudlet) rcl.getCloudlet(); double estimatedFinishTime = currentTime
if(cl.currStagenum==-1) + (remainingLength / (capacity * rcl.getPesNumber()));
{
cl.currStagenum=0;
}
double estimatedFinishTime = currentTime+cl.stages.get(cl.currStagenum).time;//currentTime + (remainingLength / (capacity * rcl.getPesNumber()));
if (estimatedFinishTime - currentTime < 0.1) { if (estimatedFinishTime - currentTime < 0.1) {
estimatedFinishTime = currentTime + 0.1; estimatedFinishTime = currentTime + 0.1;
} }
...@@ -296,96 +256,65 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -296,96 +256,65 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
return nextEvent; return nextEvent;
} }
private void updatebuffered(double time) { private void changetonextstage(NetworkCloudlet cl, TaskStage st) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
NetworkCloudlet cl=(NetworkCloudlet)(buffered.getCloudlet()); cl.timespentInStage = 0;
cl.timetostartStage = CloudSim.clock();
if(cl.currStagenum==Constants.FINISH){ int currstage = cl.currStagenum;
if (currstage >= (cl.stages.size() - 1))
System.out.println(cl.getCloudletId()+ "Cloudlet is in finished: "+ CloudSim.clock()); cl.currStagenum = NetworkConstants.FINISH;
cl.finishtime=CloudSim.clock(); else {
buffered.setCloudletStatus(Cloudlet.SUCCESS); cl.currStagenum = currstage + 1;
buffered.finalizeCloudlet(); TaskStage st1 = cl.stages.get(cl.currStagenum);
getCloudletFinishedList().add(buffered); int i = 0;
this.getCloudletWaitingList().remove(buffered); for (i = cl.currStagenum; i < cl.stages.size(); i++) {
buffered=null; if (cl.stages.get(i).type == NetworkConstants.WAIT_SEND) {
return; HostPacket pkt = new HostPacket(cl.getVmId(),
} cl.stages.get(i).peer, cl.stages.get(i).data,
time=CloudSim.clock()-this.lastbufferUpdateTime; CloudSim.clock(), -1, cl.getCloudletId(),
TaskStage st= cl.stages.get(cl.currStagenum); cl.stages.get(i).vpeer);
List<HostPacket> pktlist = this.pkttosend.get(cl.getVmId());
if(st.type==Constants.EXECUTION) if (pktlist == null)
{ pktlist = new ArrayList<HostPacket>();
pktlist.add(pkt);
//rcl.updateCloudletFinishedSoFar((long) (capacity * Math.round(timeSpam) * rcl.getPesNumber())); this.pkttosend.put(cl.getVmId(), pktlist);
//update the time
cl.timespentInStage+=time; } else
//cl.timetostartStage=CloudSim.clock(); break;
if(cl.timespentInStage>=st.time)
{ }
changetonextstage(cl,st); NetDatacenterBroker.linkDC.schedule(
//change the stage NetDatacenterBroker.linkDC.getId(), 0.0001,
} CloudSimTags.VM_DATACENTER_EVENT);
if (i == cl.stages.size())
cl.currStagenum = NetworkConstants.FINISH;
else {
cl.currStagenum = i;
if (cl.stages.get(i).type == NetworkConstants.EXECUTION)
NetDatacenterBroker.linkDC.schedule(
NetDatacenterBroker.linkDC.getId(),
cl.stages.get(i).time,
CloudSimTags.VM_DATACENTER_EVENT);
}
} }
}
private void changetonextstage(NetworkCloudlet cl, TaskStage st) {
// TODO Auto-generated method stub
cl.timespentInStage=0;
cl.timetostartStage=CloudSim.clock();
int currstage=cl.currStagenum;
if(currstage>=(cl.stages.size()-1))
cl.currStagenum=Constants.FINISH;
else{
if(cl.currStagenum==Constants.FINISH) return;
cl.currStagenum=currstage+1;
TaskStage st1=cl.stages.get(cl.currStagenum);
int i=0;
for(i=cl.currStagenum;i<cl.stages.size();i++)
{
if(cl.stages.get(i).type==Constants.WAIT_SEND)
{
if(Constants.logflag)
System.out.println(cl.getCloudletId()+ "Cloudlet is in Sending: "+ CloudSim.clock());
NetPacket pkt=new NetPacket(cl.getVmId(), cl.stages.get(i).peer, cl.stages.get(i).data, CloudSim.clock(),-1,cl.getCloudletId(),cl.stages.get(i).vpeer);
List<NetPacket> pktlist=this.pkttosend.get(cl.getVmId());
if(pktlist==null)
pktlist=new ArrayList<NetPacket>();
pktlist.add(pkt);
this.pkttosend.put(cl.getVmId(), pktlist);
}
else break;
}
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),0.0001, CloudSimTags.VM_DATACENTER_EVENT);
if(i==cl.stages.size()) cl.currStagenum=Constants.FINISH;
else {
cl.currStagenum=i;
if(cl.stages.get(i).type==Constants.EXECUTION)
NetDatacenterBroker.linkDC.schedule(NetDatacenterBroker.linkDC.getId(),cl.stages.get(i).time, CloudSimTags.VM_DATACENTER_EVENT);
if(cl.stages.get(i).type==Constants.WAIT_RECV)
{ if(buffered!=null)
this.lastbufferUpdateTime=CloudSim.clock();
}
}
}
} }
/** /**
* Cancels execution of a cloudlet. * Cancels execution of a cloudlet.
* *
* @param cloudletId ID of the cloudlet being cancealed * @param cloudletId
* * ID of the cloudlet being cancealed
*
* @return the canceled cloudlet, $null if not found * @return the canceled cloudlet, $null if not found
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
@Override @Override
public Cloudlet cloudletCancel(int cloudletId) { public Cloudlet cloudletCancel(int cloudletId) {
//First, looks in the finished queue // First, looks in the finished queue
for (ResCloudlet rcl : getCloudletFinishedList()) { for (ResCloudlet rcl : getCloudletFinishedList()) {
if (rcl.getCloudletId() == cloudletId) { if (rcl.getCloudletId() == cloudletId) {
getCloudletFinishedList().remove(rcl); getCloudletFinishedList().remove(rcl);
...@@ -393,7 +322,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -393,7 +322,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
} }
//Then searches in the exec list // Then searches in the exec list
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) { if (rcl.getCloudletId() == cloudletId) {
getCloudletExecList().remove(rcl); getCloudletExecList().remove(rcl);
...@@ -406,7 +335,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -406,7 +335,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
} }
//Now, looks in the paused queue // Now, looks in the paused queue
for (ResCloudlet rcl : getCloudletPausedList()) { for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) { if (rcl.getCloudletId() == cloudletId) {
getCloudletPausedList().remove(rcl); getCloudletPausedList().remove(rcl);
...@@ -414,7 +343,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -414,7 +343,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
} }
//Finally, looks in the waiting list // Finally, looks in the waiting list
for (ResCloudlet rcl : getCloudletWaitingList()) { for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) { if (rcl.getCloudletId() == cloudletId) {
rcl.setCloudletStatus(Cloudlet.CANCELED); rcl.setCloudletStatus(Cloudlet.CANCELED);
...@@ -429,11 +358,12 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -429,11 +358,12 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Pauses execution of a cloudlet. * Pauses execution of a cloudlet.
* *
* @param cloudletId ID of the cloudlet being paused * @param cloudletId
* * ID of the cloudlet being paused
*
* @return $true if cloudlet paused, $false otherwise * @return $true if cloudlet paused, $false otherwise
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -442,7 +372,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -442,7 +372,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
boolean found = false; boolean found = false;
int position = 0; int position = 0;
//first, looks for the cloudlet in the exec list // first, looks for the cloudlet in the exec list
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) { if (rcl.getCloudletId() == cloudletId) {
found = true; found = true;
...@@ -451,8 +381,8 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -451,8 +381,8 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
position++; position++;
} }
if (found){ if (found) {
//moves to the paused list // moves to the paused list
ResCloudlet rgl = getCloudletExecList().remove(position); ResCloudlet rgl = getCloudletExecList().remove(position);
if (rgl.getRemainingCloudletLength() == 0.0) { if (rgl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rgl); cloudletFinish(rgl);
...@@ -464,7 +394,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -464,7 +394,7 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
//now, look for the cloudlet in the waiting list // now, look for the cloudlet in the waiting list
position = 0; position = 0;
found = false; found = false;
for (ResCloudlet rcl : getCloudletWaitingList()) { for (ResCloudlet rcl : getCloudletWaitingList()) {
...@@ -493,9 +423,10 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -493,9 +423,10 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Processes a finished cloudlet. * Processes a finished cloudlet.
* *
* @param rcl finished cloudlet * @param rcl
* * finished cloudlet
*
* @pre rgl != $null * @pre rgl != $null
* @post $none * @post $none
*/ */
...@@ -509,20 +440,21 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -509,20 +440,21 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Resumes execution of a paused cloudlet. * Resumes execution of a paused cloudlet.
* *
* @param cloudletId ID of the cloudlet being resumed * @param cloudletId
* * ID of the cloudlet being resumed
*
* @return $true if the cloudlet was resumed, $false otherwise * @return $true if the cloudlet was resumed, $false otherwise
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
@Override @Override
public double cloudletResume(int cloudletId) { public double cloudletResume(int cloudletId) {
boolean found=false; boolean found = false;
int position=0; int position = 0;
//look for the cloudlet in the paused list // look for the cloudlet in the paused list
for (ResCloudlet rcl : getCloudletPausedList()) { for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) { if (rcl.getCloudletId() == cloudletId) {
found = true; found = true;
...@@ -531,10 +463,11 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -531,10 +463,11 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
position++; position++;
} }
if (found){ if (found) {
ResCloudlet rcl = getCloudletPausedList().remove(position); ResCloudlet rcl = getCloudletPausedList().remove(position);
if ((currentCpus - usedPes) >= rcl.getPesNumber()) {// it can go to the exec list if ((currentCpus - usedPes) >= rcl.getPesNumber()) {// it can go to
// the exec list
rcl.setCloudletStatus(Cloudlet.INEXEC); rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < rcl.getPesNumber(); i++) { for (int i = 0; i < rcl.getPesNumber(); i++) {
rcl.setMachineAndPeId(0, i); rcl.setMachineAndPeId(0, i);
...@@ -560,7 +493,8 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -560,7 +493,8 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
capacity /= cpus; capacity /= cpus;
long remainingLength = rcl.getRemainingCloudletLength(); long remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = CloudSim.clock() + (remainingLength / (capacity * rcl.getPesNumber())); double estimatedFinishTime = CloudSim.clock()
+ (remainingLength / (capacity * rcl.getPesNumber()));
return estimatedFinishTime; return estimatedFinishTime;
} else {// no enough free PEs: go to the waiting queue } else {// no enough free PEs: go to the waiting queue
...@@ -576,25 +510,32 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -576,25 +510,32 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
//not found in the paused list: either it is in in the queue, executing or not exist // not found in the paused list: either it is in in the queue, executing
// or not exist
return 0.0; return 0.0;
} }
/** /**
* Receives an cloudlet to be executed in the VM managed by this scheduler. * Receives an cloudlet to be executed in the VM managed by this scheduler.
* *
* @param cloudlet the submited cloudlet * @param cloudlet
* @param fileTransferTime time required to move the required files from the SAN to the VM * the submited cloudlet
* * @param fileTransferTime
* @return expected finish time of this cloudlet, or 0 if it is in the waiting queue * time required to move the required files from the SAN to the
* * VM
*
* @return expected finish time of this cloudlet, or 0 if it is in the
* waiting queue
*
* @pre gl != null * @pre gl != null
* @post $none * @post $none
*/ */
@Override @Override
public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) { public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) {
if ((currentCpus - usedPes) >= cloudlet.getPesNumber()) {// it can go to the exec list if ((currentCpus - usedPes) >= cloudlet.getPesNumber()) {// it can go to
// the exec
// list
ResCloudlet rcl = new ResCloudlet(cloudlet); ResCloudlet rcl = new ResCloudlet(cloudlet);
rcl.setCloudletStatus(Cloudlet.INEXEC); rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < cloudlet.getPesNumber(); i++) { for (int i = 0; i < cloudlet.getPesNumber(); i++) {
...@@ -632,7 +573,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -632,7 +573,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
return cloudlet.getCloudletLength() / capacity; return cloudlet.getCloudletLength() / capacity;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see cloudsim.CloudletScheduler#cloudletSubmit(cloudsim.Cloudlet) * @see cloudsim.CloudletScheduler#cloudletSubmit(cloudsim.Cloudlet)
*/ */
@Override @Override
...@@ -643,11 +586,12 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -643,11 +586,12 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Gets the status of a cloudlet. * Gets the status of a cloudlet.
* *
* @param cloudletId ID of the cloudlet * @param cloudletId
* * ID of the cloudlet
*
* @return status of the cloudlet, -1 if cloudlet not found * @return status of the cloudlet, -1 if cloudlet not found
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -676,9 +620,10 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -676,9 +620,10 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Get utilization created by all cloudlets. * Get utilization created by all cloudlets.
* *
* @param time the time * @param time
* * the time
*
* @return total utilization * @return total utilization
*/ */
@Override @Override
...@@ -691,11 +636,12 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -691,11 +636,12 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
/** /**
* Informs about completion of some cloudlet in the VM managed * Informs about completion of some cloudlet in the VM managed by this
* by this scheduler. * scheduler.
* *
* @return $true if there is at least one finished cloudlet; $false otherwise * @return $true if there is at least one finished cloudlet; $false
* * otherwise
*
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -705,10 +651,11 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -705,10 +651,11 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
/** /**
* Returns the next cloudlet in the finished list, $null if this list is empty. * Returns the next cloudlet in the finished list, $null if this list is
* * empty.
*
* @return a finished cloudlet * @return a finished cloudlet
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -722,9 +669,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -722,9 +669,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Returns the number of cloudlets runnning in the virtual machine. * Returns the number of cloudlets runnning in the virtual machine.
* *
* @return number of cloudlets runnning * @return number of cloudlets runnning
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -735,9 +682,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -735,9 +682,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Returns one cloudlet to migrate to another vm. * Returns one cloudlet to migrate to another vm.
* *
* @return one running cloudlet * @return one running cloudlet
* *
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -752,8 +699,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -752,8 +699,9 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Gets the cloudlet waiting list. * Gets the cloudlet waiting list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet waiting list * @return the cloudlet waiting list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -763,18 +711,22 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -763,18 +711,22 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Cloudlet waiting list. * Cloudlet waiting list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletWaitingList the cloudlet waiting list * the generic type
* @param cloudletWaitingList
* the cloudlet waiting list
*/ */
protected <T extends ResCloudlet> void cloudletWaitingList(List<T> cloudletWaitingList) { protected <T extends ResCloudlet> void cloudletWaitingList(
List<T> cloudletWaitingList) {
this.cloudletWaitingList = cloudletWaitingList; this.cloudletWaitingList = cloudletWaitingList;
} }
/** /**
* Gets the cloudlet exec list. * Gets the cloudlet exec list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet exec list * @return the cloudlet exec list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -784,18 +736,22 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -784,18 +736,22 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Sets the cloudlet exec list. * Sets the cloudlet exec list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletExecList the new cloudlet exec list * the generic type
* @param cloudletExecList
* the new cloudlet exec list
*/ */
protected <T extends ResCloudlet> void setCloudletExecList(List<T> cloudletExecList) { protected <T extends ResCloudlet> void setCloudletExecList(
List<T> cloudletExecList) {
this.cloudletExecList = cloudletExecList; this.cloudletExecList = cloudletExecList;
} }
/** /**
* Gets the cloudlet paused list. * Gets the cloudlet paused list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet paused list * @return the cloudlet paused list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -805,18 +761,22 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -805,18 +761,22 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Sets the cloudlet paused list. * Sets the cloudlet paused list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletPausedList the new cloudlet paused list * the generic type
* @param cloudletPausedList
* the new cloudlet paused list
*/ */
protected <T extends ResCloudlet> void setCloudletPausedList(List<T> cloudletPausedList) { protected <T extends ResCloudlet> void setCloudletPausedList(
List<T> cloudletPausedList) {
this.cloudletPausedList = cloudletPausedList; this.cloudletPausedList = cloudletPausedList;
} }
/** /**
* Gets the cloudlet finished list. * Gets the cloudlet finished list.
* *
* @param <T> the generic type * @param <T>
* the generic type
* @return the cloudlet finished list * @return the cloudlet finished list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -826,15 +786,20 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -826,15 +786,20 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
/** /**
* Sets the cloudlet finished list. * Sets the cloudlet finished list.
* *
* @param <T> the generic type * @param <T>
* @param cloudletFinishedList the new cloudlet finished list * the generic type
* @param cloudletFinishedList
* the new cloudlet finished list
*/ */
protected <T extends ResCloudlet> void setCloudletFinishedList(List<T> cloudletFinishedList) { protected <T extends ResCloudlet> void setCloudletFinishedList(
List<T> cloudletFinishedList) {
this.cloudletFinishedList = cloudletFinishedList; this.cloudletFinishedList = cloudletFinishedList;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.cloudbus.cloudsim.CloudletScheduler#getCurrentRequestedMips() * @see org.cloudbus.cloudsim.CloudletScheduler#getCurrentRequestedMips()
*/ */
@Override @Override
...@@ -848,11 +813,16 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -848,11 +813,16 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
return mipsShare; return mipsShare;
} }
/* (non-Javadoc) /*
* @see org.cloudbus.cloudsim.CloudletScheduler#getTotalCurrentAvailableMipsForCloudlet(org.cloudbus.cloudsim.ResCloudlet, java.util.List) * (non-Javadoc)
*
* @see org.cloudbus.cloudsim.CloudletScheduler#
* getTotalCurrentAvailableMipsForCloudlet
* (org.cloudbus.cloudsim.ResCloudlet, java.util.List)
*/ */
@Override @Override
public double getTotalCurrentAvailableMipsForCloudlet(ResCloudlet rcl, List<Double> mipsShare) { public double getTotalCurrentAvailableMipsForCloudlet(ResCloudlet rcl,
List<Double> mipsShare) {
double capacity = 0.0; double capacity = 0.0;
int cpus = 0; int cpus = 0;
for (Double mips : mipsShare) { // count the cpus available to the vmm for (Double mips : mipsShare) { // count the cpus available to the vmm
...@@ -866,20 +836,30 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -866,20 +836,30 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
return capacity; return capacity;
} }
/* (non-Javadoc) /*
* @see org.cloudbus.cloudsim.CloudletScheduler#getTotalCurrentAllocatedMipsForCloudlet(org.cloudbus.cloudsim.ResCloudlet, double) * (non-Javadoc)
*
* @see org.cloudbus.cloudsim.CloudletScheduler#
* getTotalCurrentAllocatedMipsForCloudlet
* (org.cloudbus.cloudsim.ResCloudlet, double)
*/ */
@Override @Override
public double getTotalCurrentAllocatedMipsForCloudlet(ResCloudlet rcl, double time) { public double getTotalCurrentAllocatedMipsForCloudlet(ResCloudlet rcl,
double time) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0.0; return 0.0;
} }
/* (non-Javadoc) /*
* @see org.cloudbus.cloudsim.CloudletScheduler#getTotalCurrentRequestedMipsForCloudlet(org.cloudbus.cloudsim.ResCloudlet, double) * (non-Javadoc)
*
* @see org.cloudbus.cloudsim.CloudletScheduler#
* getTotalCurrentRequestedMipsForCloudlet
* (org.cloudbus.cloudsim.ResCloudlet, double)
*/ */
@Override @Override
public double getTotalCurrentRequestedMipsForCloudlet(ResCloudlet rcl, double time) { public double getTotalCurrentRequestedMipsForCloudlet(ResCloudlet rcl,
double time) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0.0; return 0.0;
} }
...@@ -897,4 +877,3 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{ ...@@ -897,4 +877,3 @@ public class CloudletHPCSpaceSharedO extends CloudletScheduler{
} }
} }
...@@ -4,25 +4,29 @@ import java.util.HashMap; ...@@ -4,25 +4,29 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Constants { public class NetworkConstants {
public static final int FFT = 0;
public static int roundrobinRack=0;
public static int maxhostVM=2; public static int maxhostVM=2;
public static int HOST_PEs=8; public static int HOST_PEs=8;
public static double maxMemperVM=1024*1024;//kb public static double maxMemperVM=1024*1024;//kb
public static final int BIN_NODE_TIME=10;
public static int currentCloudletId=0; public static int currentCloudletId=0;
public static int currentAppId=0; public static int currentAppId=0;
//stage type
public static final int EXECUTION=0; public static final int EXECUTION=0;
public static final int WAIT_SEND=1; public static final int WAIT_SEND=1;
public static final int WAIT_RECV=2; public static final int WAIT_RECV=2;
public static final int FINISH=-2; public static final int FINISH=-2;
//number of switches at each level
public static final int ROOT_LEVEL=0; public static final int ROOT_LEVEL=0;
public static final int Agg_LEVEL=1; public static final int Agg_LEVEL=1;
public static final int EDGE_LEVEL=2; public static final int EDGE_LEVEL=2;
...@@ -30,17 +34,8 @@ public static final int EDGE_LEVEL=2; ...@@ -30,17 +34,8 @@ public static final int EDGE_LEVEL=2;
public static final int PES_NUMBER=4; public static final int PES_NUMBER=4;
public static final int FILE_SIZE=300; public static final int FILE_SIZE=300;
public static final int OUTPUT_SIZE=300; public static final int OUTPUT_SIZE=300;
public static int REQUESTS_PER_SECOND=200;
public static final int COMMUNICATION_LENGTH=1;
public static int Requestspersecond = 2;
public static int REQUEST_CLASSES=10;
public static double LOW_ACCURACY_RATE=0.2;
public static double MEDIUM_ACCURACY_RATE=.3;
public static double HIGH_ACCURACY_RATE=0.9;
public static boolean schedulerOverlap=true;
public static final int COMMUNICATION_LENGTH=1;
public static boolean BASE = true; public static boolean BASE = true;
...@@ -62,7 +57,7 @@ public static double RootSwitchPort=1;//number of Agg ...@@ -62,7 +57,7 @@ public static double RootSwitchPort=1;//number of Agg
public static double seed=199; public static double seed=199;
public static boolean logflag=false; public static boolean logflag=false;
public static Map<Integer,Map<Integer,Boolean>> Cache=new HashMap<Integer,Map<Integer,Boolean>>();
public static int iteration=10; public static int iteration=10;
public static int nexttime=1000; public static int nexttime=1000;
......
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/* /*
* Title: CloudSim Toolkit * Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
...@@ -7,8 +8,6 @@ package org.cloudbus.cloudsim.network.datacenter; ...@@ -7,8 +8,6 @@ package org.cloudbus.cloudsim.network.datacenter;
* Copyright (c) 2009-2010, The University of Melbourne, Australia * Copyright (c) 2009-2010, The University of Melbourne, Australia
*/ */
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -36,19 +35,53 @@ import org.cloudbus.cloudsim.core.SimEntity; ...@@ -36,19 +35,53 @@ import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
/** /**
* Datacenter class is a CloudResource whose hostList * NetworkDatacenter class is a Datacenter whose hostList are virtualized and
* are virtualized. It deals with processing of VM queries (i.e., handling * networked. It contains all the information about internal network. For example,
* of VMs) instead of processing Cloudlet-related queries. So, even though an * which VM is connected to Switch etc.
* AllocPolicy will be instantiated (in the init() method of the superclass, * It deals with processing of VM queries (i.e., handling of VMs)
* it will not be used, as processing of cloudlets are handled by the CloudletScheduler * instead of processing Cloudlet-related queries. So, even though an
* and processing of VirtualMachines are handled by the VmAllocationPolicy. * AllocPolicy will be instantiated (in the init() method of the superclass, it
* * will not be used, as processing of cloudlets are handled by the
* @author Rodrigo N. Calheiros * CloudletScheduler and processing of VirtualMachines are handled by the
* @author Anton Beloglazov * VmAllocationPolicy.
* @since CloudSim Toolkit 1.0 *
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*/ */
public class NetworkDatacenter extends Datacenter { public class NetworkDatacenter extends Datacenter {
/**
* Allocates a new NetworkDatacenter object.
*
* @param name the name to be associated with this entity (as
* required by Sim_entity class from simjava package)
* @param characteristics an object of DatacenterCharacteristics
* @param storageList a LinkedList of storage elements, for data simulation
* @param vmAllocationPolicy the vmAllocationPolicy
*
* @throws Exception This happens when one of the following scenarios occur:
* <ul>
* <li> creating this entity before initializing CloudSim package
* <li> this entity name is <tt>null</tt> or empty
* <li> this entity has <tt>zero</tt> number of PEs (Processing
* Elements). <br>
* No PEs mean the Cloudlets can't be processed.
* A CloudResource must contain one or more Machines.
* A Machine must contain one or more PEs.
* </ul>
*
* @pre name != null
* @pre resource != null
* @post $none
*/
public NetworkDatacenter(String name, public NetworkDatacenter(String name,
DatacenterCharacteristics characteristics, DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy, List<Storage> storageList, VmAllocationPolicy vmAllocationPolicy, List<Storage> storageList,
...@@ -56,41 +89,50 @@ public class NetworkDatacenter extends Datacenter { ...@@ -56,41 +89,50 @@ public class NetworkDatacenter extends Datacenter {
super(name, characteristics, vmAllocationPolicy, storageList, super(name, characteristics, vmAllocationPolicy, storageList,
schedulingInterval); schedulingInterval);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
VmToSwitchid=new HashMap<Integer,Integer>(); VmToSwitchid = new HashMap<Integer, Integer>();
HostToSwitchid=new HashMap<Integer,Integer>(); HostToSwitchid = new HashMap<Integer, Integer>();
VmtoHostlist=new HashMap<Integer,Integer>(); VmtoHostlist = new HashMap<Integer, Integer>();
Switchlist=new HashMap<Integer,Switch>(); Switchlist = new HashMap<Integer, Switch>();
} }
public Map<Integer,Integer> VmToSwitchid;
public Map<Integer,Integer> HostToSwitchid; public Map<Integer, Integer> VmToSwitchid;
public Map<Integer,Switch> Switchlist; public Map<Integer, Integer> HostToSwitchid;
public Map<Integer, Switch> Switchlist;
public Map<Integer,Integer> VmtoHostlist; public Map<Integer, Integer> VmtoHostlist;
public Map<Integer, Switch> getEdgeSwitch(){ /**
Map<Integer,Switch> edgeswitch=new HashMap<Integer,Switch>(); * Get list of all EdgeSwitches in the Datacenter network
for(Entry<Integer, Switch> es:Switchlist.entrySet()){ * One can design similar functions for other type of switches.
if(es.getValue().level==Constants.EDGE_LEVEL) *
{ */
edgeswitch.put(es.getKey(), es.getValue()); public Map<Integer, Switch> getEdgeSwitch() {
} Map<Integer, Switch> edgeswitch = new HashMap<Integer, Switch>();
} for (Entry<Integer, Switch> es : Switchlist.entrySet()) {
if (es.getValue().level == NetworkConstants.EDGE_LEVEL) {
edgeswitch.put(es.getKey(), es.getValue());
}
}
return edgeswitch; return edgeswitch;
} }
/**
* Create the VM within the NetworkDatacenter.
public boolean processVmCreateHPC(Vm vm) { * It can be directly accessed by Datacenter Broker
* which manage allocation of Cloudlets.
*
*
*/
public boolean processVmCreateNetwork(Vm vm) {
boolean result = getVmAllocationPolicy().allocateHostForVm(vm); boolean result = getVmAllocationPolicy().allocateHostForVm(vm);
if (result) { if (result) {
this.VmToSwitchid.put(vm.getId(), ((NetworkHost)vm.getHost()).sw.getId()); this.VmToSwitchid.put(vm.getId(),
this.VmtoHostlist.put(vm.getId(),vm.getHost().getId()); ((NetworkHost) vm.getHost()).sw.getId());
System.out.println(vm.getId()+" VM is created on "+vm.getHost().getId()); this.VmtoHostlist.put(vm.getId(), vm.getHost().getId());
System.out.println(vm.getId() + " VM is created on "
+ vm.getHost().getId());
double amount = 0.0; double amount = 0.0;
if (getDebts().containsKey(vm.getUserId())) { if (getDebts().containsKey(vm.getUserId())) {
amount = getDebts().get(vm.getUserId()); amount = getDebts().get(vm.getUserId());
...@@ -102,95 +144,116 @@ public class NetworkDatacenter extends Datacenter { ...@@ -102,95 +144,116 @@ public class NetworkDatacenter extends Datacenter {
getVmList().add(vm); getVmList().add(vm);
vm.updateVmProcessing(CloudSim.clock(), getVmAllocationPolicy().getHost(vm).getVmScheduler().getAllocatedMipsForVm(vm)); vm.updateVmProcessing(CloudSim.clock(), getVmAllocationPolicy()
} .getHost(vm).getVmScheduler().getAllocatedMipsForVm(vm));
return result; }
} return result;
}
/**
* Processes a Cloudlet submission.
*
* @param ev a SimEvent object
* @param ack an acknowledgement
*
* @pre ev != null
* @post $none
*/
protected void processCloudletSubmit(SimEvent ev, boolean ack) { protected void processCloudletSubmit(SimEvent ev, boolean ack) {
updateCloudletProcessing(); updateCloudletProcessing();
try { try {
// gets the Cloudlet object // gets the Cloudlet object
Cloudlet cl = (Cloudlet) ev.getData(); Cloudlet cl = (Cloudlet) ev.getData();
// checks whether this Cloudlet has finished or not
// checks whether this Cloudlet has finished or not if (cl.isFinished()) {
if (cl.isFinished()){ String name = CloudSim.getEntityName(cl.getUserId());
String name = CloudSim.getEntityName(cl.getUserId()); Log.printLine(getName() + ": Warning - Cloudlet #"
Log.printLine(getName()+": Warning - Cloudlet #"+cl.getCloudletId()+" owned by "+name+" is already completed/finished."); + cl.getCloudletId() + " owned by " + name
Log.printLine("Therefore, it is not being executed again"); + " is already completed/finished.");
Log.printLine(); Log.printLine("Therefore, it is not being executed again");
Log.printLine();
// NOTE: If a Cloudlet has finished, then it won't be processed.
// So, if ack is required, this method sends back a result. // NOTE: If a Cloudlet has finished, then it won't be processed.
// If ack is not required, this method don't send back a result. // So, if ack is required, this method sends back a result.
// Hence, this might cause CloudSim to be hanged since waiting // If ack is not required, this method don't send back a result.
// for this Cloudlet back. // Hence, this might cause CloudSim to be hanged since waiting
if (ack) { // for this Cloudlet back.
int[] data = new int[3]; if (ack) {
data[0] = getId(); int[] data = new int[3];
data[1] = cl.getCloudletId(); data[0] = getId();
data[2] = CloudSimTags.FALSE; data[1] = cl.getCloudletId();
data[2] = CloudSimTags.FALSE;
// unique tag = operation tag
int tag = CloudSimTags.CLOUDLET_SUBMIT_ACK; // unique tag = operation tag
sendNow(cl.getUserId(), tag, data); int tag = CloudSimTags.CLOUDLET_SUBMIT_ACK;
} sendNow(cl.getUserId(), tag, data);
}
sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_RETURN, cl);
sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_RETURN, cl);
return;
} return;
}
// process this Cloudlet to this CloudResource
cl.setResourceParameter(getId(), getCharacteristics().getCostPerSecond(), getCharacteristics().getCostPerBw()); // process this Cloudlet to this CloudResource
cl.setResourceParameter(getId(), getCharacteristics()
int userId = cl.getUserId(); .getCostPerSecond(), getCharacteristics().getCostPerBw());
int vmId = cl.getVmId();
int userId = cl.getUserId();
double fileTransferTime = predictFileTransferTime(cl.getRequiredFiles()); //time to transfer the files int vmId = cl.getVmId();
Host host = getVmAllocationPolicy().getHost(vmId, userId); double fileTransferTime = predictFileTransferTime(cl
Vm vm = host.getVm(vmId, userId); .getRequiredFiles()); // time to transfer the files
CloudletScheduler scheduler = vm.getCloudletScheduler();
//System.out.println("cloudlet recieved by VM"+vmId); Host host = getVmAllocationPolicy().getHost(vmId, userId);
double estimatedFinishTime = scheduler.cloudletSubmit(cl,fileTransferTime); Vm vm = host.getVm(vmId, userId);
CloudletScheduler scheduler = vm.getCloudletScheduler();
//if (estimatedFinishTime > 0.0 && estimatedFinishTime < getSchedulingInterval()) { //if this cloudlet is in the exec queue // System.out.println("cloudlet recieved by VM"+vmId);
if (estimatedFinishTime > 0.0) { //if this cloudlet is in the exec queue double estimatedFinishTime = scheduler.cloudletSubmit(cl,
//double estimatedFinishTime = (cl.getCloudletTotalLength()/(capacity*cl.getPesNumber())); //time to process the cloudlet fileTransferTime);
//Log.printLine(estimatedFinishTime+"="+gl.getCloudletLength()+"/("+capacity+"*"+gl.getNumPE()+")");
estimatedFinishTime += fileTransferTime; // if (estimatedFinishTime > 0.0 && estimatedFinishTime <
//estimatedFinishTime += CloudSim.clock(); // getSchedulingInterval()) { //if this cloudlet is in the exec
//Log.printLine(CloudSim.clock()+": Next event scheduled to +"+estimatedFinishTime); // queue
send(getId(), estimatedFinishTime, CloudSimTags.VM_DATACENTER_EVENT); if (estimatedFinishTime > 0.0) { // if this cloudlet is in the exec
// queue
//event to update the stages // double estimatedFinishTime =
send(getId(), 0.0001, CloudSimTags.VM_DATACENTER_EVENT); // (cl.getCloudletTotalLength()/(capacity*cl.getPesNumber()));
} // //time to process the cloudlet
// Log.printLine(estimatedFinishTime+"="+gl.getCloudletLength()+"/("+capacity+"*"+gl.getNumPE()+")");
if (ack) { estimatedFinishTime += fileTransferTime;
int[] data = new int[3]; // estimatedFinishTime += CloudSim.clock();
data[0] = getId(); // Log.printLine(CloudSim.clock()+": Next event scheduled to +"+estimatedFinishTime);
data[1] = cl.getCloudletId(); send(getId(), estimatedFinishTime,
data[2] = CloudSimTags.TRUE; CloudSimTags.VM_DATACENTER_EVENT);
// unique tag = operation tag // event to update the stages
int tag = CloudSimTags.CLOUDLET_SUBMIT_ACK; send(getId(), 0.0001, CloudSimTags.VM_DATACENTER_EVENT);
sendNow(cl.getUserId(), tag, data); }
}
} if (ack) {
catch (ClassCastException c) { int[] data = new int[3];
Log.printLine(getName() + ".processCloudletSubmit(): " + "ClassCastException error."); data[0] = getId();
c.printStackTrace(); data[1] = cl.getCloudletId();
} data[2] = CloudSimTags.TRUE;
catch (Exception e) {
Log.printLine(getName() + ".processCloudletSubmit(): " + "Exception error."); // unique tag = operation tag
e.printStackTrace(); int tag = CloudSimTags.CLOUDLET_SUBMIT_ACK;
} sendNow(cl.getUserId(), tag, data);
}
checkCloudletCompletion(); } catch (ClassCastException c) {
} Log.printLine(getName() + ".processCloudletSubmit(): "
+ "ClassCastException error.");
c.printStackTrace();
} catch (Exception e) {
Log.printLine(getName() + ".processCloudletSubmit(): "
+ "Exception error.");
e.printStackTrace();
}
checkCloudletCompletion();
}
} }
...@@ -27,169 +27,192 @@ import org.cloudbus.cloudsim.provisioners.BwProvisioner; ...@@ -27,169 +27,192 @@ import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner; import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/** /**
* Host class extends a Machine to include other hostList beside PEs * NetworkHost class extends Host to support simulation of networked datacenters.
* to support simulation of virtualized grids. It executes actions related * It executes actions related to management of packets (send and receive)other than that of
* to management of virtual machines (e.g., creation and destruction). A host has * virtual machines (e.g., creation and destruction). A host has a defined
* a defined policy for provisioning memory and bw, as well as an allocation policy * policy for provisioning memory and bw, as well as an allocation policy for
* for Pe's to virtual machines. * Pe's to virtual machines.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
* *
* A host is associated to a datacenter. It can host virtual machines. *
* * @author Saurabh Kumar Garg
* @author Rodrigo N. Calheiros * @since CloudSim Toolkit 1.0
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/ */
public class NetworkHost extends Host { public class NetworkHost extends Host {
public List <HostPacket> packetTosendLocal; public List<NetworkPacket> packetTosendLocal;
public List <HostPacket> packetTosendGlobal; public List<NetworkPacket> packetTosendGlobal;
public List <HostPacket> packetrecieved; public List<NetworkPacket> packetrecieved;
public double memory; public double memory;
public Switch sw; public Switch sw; //Edge switch in general
public double bandwidth;//latency public double bandwidth;// latency
public List<Double> CPUfinTimeCPU=new ArrayList<Double>();//time when last job will finish on CPU1 public List<Double> CPUfinTimeCPU = new ArrayList<Double>();// time when
// last job will
public double fintime=0; // finish on
// CPU1
public double fintime = 0;
public NetworkHost(int id, RamProvisioner ramProvisioner, public NetworkHost(int id, RamProvisioner ramProvisioner,
BwProvisioner bwProvisioner, long storage, BwProvisioner bwProvisioner, long storage,
List<? extends Pe> peList, VmScheduler vmScheduler) { List<? extends Pe> peList, VmScheduler vmScheduler) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler); super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
// TODO Auto-generated constructor stub
this.packetrecieved=new ArrayList<HostPacket>(); this.packetrecieved = new ArrayList<NetworkPacket>();
this.packetTosendGlobal=new ArrayList<HostPacket>(); this.packetTosendGlobal = new ArrayList<NetworkPacket>();
this.packetTosendLocal=new ArrayList<HostPacket>(); this.packetTosendLocal = new ArrayList<NetworkPacket>();
} }
/**
/** * Requests updating of processing of cloudlets in the VMs running in this
* Requests updating of processing of cloudlets in the VMs running in this host. * host.
* *
* @param currentTime the current time * @param currentTime
* * the current time
* @return expected time of completion of the next cloudlet in all VMs in this host. Double.MAX_VALUE *
* if there is no future events expected in this host * @return expected time of completion of the next cloudlet in all VMs in
* * this host. Double.MAX_VALUE if there is no future events expected
* @pre currentTime >= 0.0 * in th is host
* @post $none *
* @pre currentTime >= 0.0
* @post $none
*/ */
public double updateVmsProcessing(double currentTime) { public double updateVmsProcessing(double currentTime) {
double smallerTime = Double.MAX_VALUE; double smallerTime = Double.MAX_VALUE;
//insert in each vm packet recieved // insert in each vm packet recieved
recvpackets(); recvpackets();
for (Vm vm : super.getVmList()) { for (Vm vm : super.getVmList()) {
// if (vm.isInMigration()) { // if (vm.isInMigration()) {
// continue; // continue;
// } // }
double time = ((NetworkVm)vm).updateVmProcessing(currentTime, getVmScheduler().getAllocatedMipsForVm(vm)); double time = ((NetworkVm) vm).updateVmProcessing(currentTime,
getVmScheduler().getAllocatedMipsForVm(vm));
if (time > 0.0 && time < smallerTime) { if (time > 0.0 && time < smallerTime) {
smallerTime = time; smallerTime = time;
} }
} }
sendpackets(); //send the packets to other hosts/VMs
sendpackets();
return smallerTime;
}
return smallerTime;
}
/**
* Receives packet and forward it to the corresponding VM for processing
* host.
*
*
*/
private void recvpackets() { private void recvpackets() {
// TODO Auto-generated method stub
for(HostPacket hs:packetrecieved) for (NetworkPacket hs : packetrecieved) {
{ // hs.stime=hs.rtime;
//hs.stime=hs.rtime; hs.pkt.recievetime = CloudSim.clock();
hs.pkt.recievetime=CloudSim.clock();
// insertthe packet in recievedlist of VM
Vm vm = VmList.getById(getVmList(), hs.pkt.reciever);
List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm
.getCloudletScheduler()).pktrecv.get(hs.pkt.sender);
//insertthe packet in recievedlist if (pktlist == null) {
Vm vm=VmList.getById(getVmList(), hs.pkt.reciever); pktlist = new ArrayList<HostPacket>();
List<NetPacket> pktlist=((CloudletHPCSpaceShared)vm.getCloudletScheduler()).pktrecv.get(hs.pkt.sender); ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv
//List<NetPacket> pktlist=((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pktrecv.get(hs.pkt.virtualsendid); .put(hs.pkt.sender, pktlist);
if(pktlist==null){
pktlist=new ArrayList<NetPacket>();
((CloudletHPCSpaceShared)vm.getCloudletScheduler()).pktrecv.put(hs.pkt.sender, pktlist);
// ((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pktrecv.put(hs.pkt.virtualsendid, pktlist);
} }
pktlist.add(hs.pkt); pktlist.add(hs.pkt);
} }
packetrecieved.clear(); packetrecieved.clear();
} }
/**
* Send packet check whether a packet belongs to a local VM or to a VM hosted on other machine.
*
*
*/
private void sendpackets() { private void sendpackets() {
// TODO Auto-generated method stub
for(Vm vm:super.getVmList())
{ for (Vm vm : super.getVmList()) {
for(Entry<Integer, List<NetPacket>> es:((CloudletHPCSpaceShared)vm.getCloudletScheduler()).pkttosend.entrySet()) for (Entry<Integer, List<HostPacket>> es : ((NetworkCloudletSpaceSharedScheduler) vm
//for(Entry<Integer, List<NetPacket>> es:((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pkttosend.entrySet()) .getCloudletScheduler()).pkttosend.entrySet())
{ {
List<NetPacket> pktlist=es.getValue(); List<HostPacket> pktlist = es.getValue();
for(NetPacket pkt:pktlist) for (HostPacket pkt : pktlist) {
{ NetworkPacket hpkt = new NetworkPacket(this.getId(), pkt,
HostPacket hpkt=new HostPacket(this.getId(),pkt,vm.getId(),pkt.sender); vm.getId(), pkt.sender);
Vm vm2=VmList.getById(this.getVmList(), hpkt.recievervmid); Vm vm2 = VmList
if(vm2!=null) this.packetTosendLocal.add(hpkt); .getById(this.getVmList(), hpkt.recievervmid);
else this.packetTosendGlobal.add(hpkt); if (vm2 != null)
} this.packetTosendLocal.add(hpkt);
pktlist.clear(); else
this.packetTosendGlobal.add(hpkt);
}
pktlist.clear();
} }
} }
boolean flag=false; boolean flag = false;
for(HostPacket hs:packetTosendLocal) for (NetworkPacket hs : packetTosendLocal) {
{ flag = true;
flag=true; hs.stime = hs.rtime;
hs.stime=hs.rtime; hs.pkt.recievetime = CloudSim.clock();
hs.pkt.recievetime=CloudSim.clock(); // insertthe packet in recievedlist
//insertthe packet in recievedlist Vm vm = VmList.getById(getVmList(), hs.pkt.reciever);
Vm vm=VmList.getById(getVmList(), hs.pkt.reciever); // Vm vm=getVmList().get(hs.pkt.reciever);
//Vm vm=getVmList().get(hs.pkt.reciever);
List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm
List<NetPacket> pktlist=((CloudletHPCSpaceShared)vm.getCloudletScheduler()).pktrecv.get(hs.pkt.sender); .getCloudletScheduler()).pktrecv.get(hs.pkt.sender);
//List<NetPacket> pktlist=((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pktrecv.get(hs.pkt.virtualsendid); if (pktlist == null) {
if(pktlist==null){ pktlist = new ArrayList<HostPacket>();
pktlist=new ArrayList<NetPacket>(); ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv
((CloudletHPCSpaceShared)vm.getCloudletScheduler()).pktrecv.put(hs.pkt.sender, pktlist); .put(hs.pkt.sender, pktlist);
// ((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pktrecv.put(hs.pkt.virtualsendid, pktlist);
} }
pktlist.add(hs.pkt); pktlist.add(hs.pkt);
}
if(flag){
for (Vm vm : super.getVmList()) {
// if (vm.isInMigration()) {
// continue;
// }
double time = ((NetworkVm)vm).updateVmProcessing(CloudSim.clock(), getVmScheduler().getAllocatedMipsForVm(vm));
} }
if (flag) {
for (Vm vm : super.getVmList()) {
// if (vm.isInMigration()) {
// continue;
// }
double time = ((NetworkVm) vm).updateVmProcessing(CloudSim
.clock(), getVmScheduler().getAllocatedMipsForVm(vm));
}
} }
//Sending packet to other VMs therefore packet is forwarded to a Edge switch
this.packetTosendLocal.clear(); this.packetTosendLocal.clear();
double avband=this.bandwidth/packetTosendGlobal.size(); double avband = this.bandwidth / packetTosendGlobal.size();
for(HostPacket hs:packetTosendGlobal) for (NetworkPacket hs : packetTosendGlobal) {
{ double delay = (1000 * hs.pkt.data) / avband;
double delay=(1000*hs.pkt.data)/avband; NetworkConstants.totaldatatransfer += hs.pkt.data;
Constants.totaldatatransfer+=hs.pkt.data; // System.out.println(hs.pkt.virtualsendid+" "+hs.pkt.virtualrecvid+" "+hs.pkt.data);
//System.out.println(hs.pkt.virtualsendid+" "+hs.pkt.virtualrecvid+" "+hs.pkt.data);
CloudSim.send(this.getDatacenter().getId(), this.sw.getId(), delay,
CloudSim.send(this.getDatacenter().getId(), this.sw.getId(), delay, CloudSimTags.Network_Event_UP, hs); CloudSimTags.Network_Event_UP, hs);
//send to switch with delay // send to switch with delay
} }
this.packetTosendGlobal.clear(); this.packetTosendGlobal.clear();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public double getMaxUtilizationAmongVmsPes(Vm vm) { public double getMaxUtilizationAmongVmsPes(Vm vm) {
return PeList.getMaxUtilizationAmongVmsPes((List<Pe>) getPeList(), vm); return PeList.getMaxUtilizationAmongVmsPes((List<Pe>) getPeList(), vm);
} }
} }
package org.cloudbus.cloudsim.network.datacenter;
/**
* NewtorkPacket represents the packet which travel from one server to another.
* Each packet contains ids of the sender VM and receiver VM,
* time at which it is send and received, type and virtual ids of tasks, which are communicating.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class NetworkPacket {
public NetworkPacket(int id, HostPacket pkt2, int vmid, int cloudletid) {
// TODO Auto-generated constructor stub
this.pkt = pkt2;
this.sendervmid = vmid;
this.cloudletid = cloudletid;
this.senderhostid = id;
this.stime = pkt.sendtime;
this.recievervmid = pkt2.reciever;
}
HostPacket pkt;
int senderhostid;
int recieverhostid;
int sendervmid;
int recievervmid;
int cloudletid;
double stime;// time when sent
double rtime;// time when received
}
...@@ -6,29 +6,49 @@ import java.util.List; ...@@ -6,29 +6,49 @@ import java.util.List;
import org.cloudbus.cloudsim.CloudletScheduler; import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
/**
* NetworkVm class extends Vm to support simulation of networked datacenters.
* It executes actions related to management of packets (send and receive).
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class NetworkVm extends Vm implements Comparable{ public class NetworkVm extends Vm implements Comparable {
public NetworkVm(int id, int userId, double mips, int pesNumber, int ram, public NetworkVm(int id, int userId, double mips, int pesNumber, int ram,
long bw, long size, String vmm, CloudletScheduler cloudletScheduler) { long bw, long size, String vmm, CloudletScheduler cloudletScheduler) {
super(id, userId, mips, pesNumber, ram, bw, size, vmm, cloudletScheduler); super(id, userId, mips, pesNumber, ram, bw, size, vmm,
cloudletScheduler);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
cloudletlist=new ArrayList<NetworkCloudlet>(); cloudletlist = new ArrayList<NetworkCloudlet>();
} }
public ArrayList<NetworkCloudlet> cloudletlist; public ArrayList<NetworkCloudlet> cloudletlist;
int type; int type;
public ArrayList<NetPacket> recvPktlist; public ArrayList<HostPacket> recvPktlist;
public double memory; public double memory;
public boolean flagfree;//if true it is free public boolean flagfree;// if true it is free
public double finishtime; public double finishtime;
public boolean isFree()
{ public boolean isFree() {
return flagfree; return flagfree;
} }
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
NetworkVm hs=(NetworkVm)arg0; NetworkVm hs = (NetworkVm) arg0;
if(hs.finishtime>this.finishtime) return -1; if (hs.finishtime > this.finishtime)
if(hs.finishtime<this.finishtime) return 1; return -1;
if (hs.finishtime < this.finishtime)
return 1;
return 0; return 0;
} }
} }
...@@ -21,15 +21,16 @@ import org.cloudbus.cloudsim.core.CloudSim; ...@@ -21,15 +21,16 @@ import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.power.PowerHost; import org.cloudbus.cloudsim.power.PowerHost;
/** /**
* VmAllocationPolicySimple is an VmAllocationPolicy that * NetworkVmAllocationPolicy is an VmAllocationPolicy that
* chooses, as the host for a VM, the host with * chooses, as the host for a VM, the host with
* less PEs in use. * less PEs in use.
* *
* @author Rodrigo N. Calheiros * @author Rodrigo N. Calheiros
* @author Anton Beloglazov * @author Anton Beloglazov
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 1.0
*/ */
public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { public class NetworkVmAllocationPolicy extends VmAllocationPolicy {
/** The vm table. */ /** The vm table. */
private Map<String, Host> vmTable; private Map<String, Host> vmTable;
...@@ -48,7 +49,7 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { ...@@ -48,7 +49,7 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
public VmHPCAllocationPolicySimple(List<? extends Host> list) { public NetworkVmAllocationPolicy(List<? extends Host> list) {
super(list); super(list);
setFreePes(new ArrayList<Integer>()); setFreePes(new ArrayList<Integer>());
...@@ -74,34 +75,51 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { ...@@ -74,34 +75,51 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
@Override @Override
public boolean allocateHostForVm(Vm vm) { public boolean allocateHostForVm(Vm vm) {
NetworkHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { //if vm has been succesfully created in the host int requiredPes = vm.getPesNumber();
getVmTable().put(vm.getUid(), allocatedHost); boolean result = false;
if (!Log.isDisabled()) { int tries = 0;
Log.print(String.format("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock())); List<Integer> freePesTmp = new ArrayList<Integer>();
} for (Integer freePes : getFreePes()) {
return true; freePesTmp.add(freePes);
} }
return false;
}
public NetworkHost findHostForVm(Vm vm) { if (!getVmTable().containsKey(vm.getUid())) { //if this vm was not created
double minPower = Double.MAX_VALUE; do {//we still trying until we find a host or until we try all of them
NetworkHost allocatedHost = null; int moreFree = Integer.MIN_VALUE;
int idx = -1;
//we want the host with less pes in use
for (int i=0; i < freePesTmp.size(); i++) {
if (freePesTmp.get(i) > moreFree) {
moreFree = freePesTmp.get(i);
idx = i;
}
}
NetworkHost host =this.<NetworkHost>getHostList().get(idx);
result = host.vmCreate(vm);
if (result) { //if vm were succesfully created in the host
//Log.printLine("VmAllocationPolicy: VM #"+vm.getVmId()+ "Chosen host: #"+host.getMachineID()+" idx:"+idx);
getVmTable().put(vm.getUid(), host);
getUsedPes().put(vm.getUid(), requiredPes);
getFreePes().set(idx, getFreePes().get(idx) - requiredPes);
result = true;
break;
} else {
freePesTmp.set(idx, Integer.MIN_VALUE);
}
tries++;
} while (!result && tries < getFreePes().size());
for (NetworkHost host : this.<NetworkHost>getHostList()) {
if (host.isSuitableForVm(vm)) {
double maxUtilization = getMaxUtilizationAfterAllocation(host, vm);
if ((!vm.isRecentlyCreated() && maxUtilization > 1) || (vm.isRecentlyCreated() && maxUtilization > 1.0)) {
continue;
}
allocatedHost = host;
} }
return result;
} }
return allocatedHost;
}
protected double getMaxUtilizationAfterAllocation(NetworkHost host, Vm vm) { protected double getMaxUtilizationAfterAllocation(NetworkHost host, Vm vm) {
List<Double> allocatedMipsForVm = null; List<Double> allocatedMipsForVm = null;
NetworkHost allocatedHost = (NetworkHost) vm.getHost(); NetworkHost allocatedHost = (NetworkHost) vm.getHost();
...@@ -248,6 +266,12 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { ...@@ -248,6 +266,12 @@ public class VmHPCAllocationPolicySimple 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;
} }
......
...@@ -9,60 +9,92 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -9,60 +9,92 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
public class RootSwitch extends Switch{ /**
* This class allows to simulate Root switch which connects Datacenter to
* external network. It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*
*/
public class RootSwitch extends Switch {
/**
* Constructor for Root Switch We have to specify switches that are
* connected to its downlink ports, and corresponding bandwidths
*
* @param name
* Name of the switch
* @param level
* At which level switch is with respect to hosts.
* @param dc
* Pointer to Datacenter
*/
public RootSwitch(String name, int level, NetworkDatacenter dc) { public RootSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc); super(name, level, dc);
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); downlinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
downlinkswitches=new ArrayList<Switch>(); downlinkswitches = new ArrayList<Switch>();
downlinkbandwidth=Constants.BandWidthAggRoot; downlinkbandwidth = NetworkConstants.BandWidthAggRoot;
latency=Constants.SwitchingDelayRoot; latency = NetworkConstants.SwitchingDelayRoot;
numport=Constants.RootSwitchPort; numport = NetworkConstants.RootSwitchPort;
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
/**
private void processpacket_up(SimEvent ev) { * Send Packet to switch connected through a downlink port
// TODO Auto-generated method stub *
//packet coming from down level router. * @param ev
//has to send up * Event/packet to process
//check which switch to forward to */
//add packet in the switch list @Override
protected void processpacket_up(SimEvent ev) {
// packet coming from down level router.
// has to send up
// check which switch to forward to
// add packet in the switch list
// //
//int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send); CloudSimTags.Network_Event_send));
schedule(getId(), this.switching_delay, CloudSimTags.Network_Event_send);
if(this.level==Constants.ROOT_LEVEL)
{
//get id of edge router
int edgeswitchid=dc.VmToSwitchid.get(recvVMid);
//search which aggregate switch has it
int aggSwtichid=-1;;
for(Switch sw:this.downlinkswitches)
{
for(Switch edge:sw.downlinkswitches)
{
if(edge.getId()==edgeswitchid){
aggSwtichid=sw.getId();
break;
}
}
}
if(aggSwtichid<0) System.out.println(" No destination for this packet");
else{
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(aggSwtichid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
if (this.level == NetworkConstants.ROOT_LEVEL) {
// get id of edge router
int edgeswitchid = dc.VmToSwitchid.get(recvVMid);
// search which aggregate switch has it
int aggSwtichid = -1;
;
for (Switch sw : this.downlinkswitches) {
for (Switch edge : sw.downlinkswitches) {
if (edge.getId() == edgeswitchid) {
aggSwtichid = sw.getId();
break;
}
}
}
if (aggSwtichid < 0)
System.out.println(" No destination for this packet");
else {
List<NetworkPacket> pktlist = this.downlinkswitchpktlist
.get(aggSwtichid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
} }
...@@ -21,484 +21,402 @@ import org.cloudbus.cloudsim.core.SimEvent; ...@@ -21,484 +21,402 @@ import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
import org.cloudbus.cloudsim.lists.VmList; import org.cloudbus.cloudsim.lists.VmList;
public class Switch extends SimEntity{ public class Switch extends SimEntity {
// switch level
//switch level
public int id; public int id;
public int level;//three levels public int level;// three levels
public int datacenterid; public int datacenterid;
public Map<Integer,List<HostPacket>> uplinkswitchpktlist; public Map<Integer, List<NetworkPacket>> uplinkswitchpktlist;
public Map<Integer,List<HostPacket>> downlinkswitchpktlist; public Map<Integer, List<NetworkPacket>> downlinkswitchpktlist;
public Map<Integer,NetworkHost> hostlist; public Map<Integer, NetworkHost> hostlist;
public List<Switch>uplinkswitches; public List<Switch> uplinkswitches;
public List <Switch>downlinkswitches; public List<Switch> downlinkswitches;
public Map<Integer,List<HostPacket>> packetTohost; public Map<Integer, List<NetworkPacket>> packetTohost;
int type;//edge switch or aggregation switch int type;// edge switch or aggregation switch
public double uplinkbandwidth; public double uplinkbandwidth;
public double downlinkbandwidth; public double downlinkbandwidth;
public double latency; public double latency;
public double numport; public double numport;
public NetworkDatacenter dc; public NetworkDatacenter dc;
public SortedMap<Double,List<NetworkHost>> fintimelistHost=new TreeMap<Double,List<NetworkHost>>();//something is running on these hosts public SortedMap<Double, List<NetworkHost>> fintimelistHost = new TreeMap<Double, List<NetworkHost>>();// something
public SortedMap<Double,List<NetworkVm>> fintimelistVM=new TreeMap<Double,List<NetworkVm>>();//something is running on these hosts // is
public ArrayList<HostPacket> pktlist; // running
public List<Vm> BagofTaskVm=new ArrayList<Vm>(); // on
// these
// hosts
public SortedMap<Double, List<NetworkVm>> fintimelistVM = new TreeMap<Double, List<NetworkVm>>();// something
// is
// running
// on
// these
// hosts
public ArrayList<NetworkPacket> pktlist;
public List<Vm> BagofTaskVm = new ArrayList<Vm>();
public double switching_delay; public double switching_delay;
public Map<Integer,NetworkVm> Vmlist; public Map<Integer, NetworkVm> Vmlist;
public Switch(String name,int level,NetworkDatacenter dc) {
public Switch(String name, int level, NetworkDatacenter dc) {
super(name); super(name);
this.level=level; this.level = level;
/* if(level==Constants.EDGE_LEVEL) /*
{ * if(level==Constants.EDGE_LEVEL) { hostlist=new
hostlist=new HashMap<Integer,HPCHost>(); * HashMap<Integer,HPCHost>(); uplinkswitchpktlist=new
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); * HashMap<Integer,List<HostPacket>>(); packetTohost=new
packetTohost=new HashMap<Integer,List<HostPacket>>(); * HashMap<Integer,List<HostPacket>>();
uplinkbandwidth=Constants.BandWidthEdgeAgg; * uplinkbandwidth=Constants.BandWidthEdgeAgg;
downlinkbandwidth=Constants.BandWidthEdgeHost; * downlinkbandwidth=Constants.BandWidthEdgeHost;
latency=Constants.SwitchingDelayEdge; * latency=Constants.SwitchingDelayEdge;
numport=Constants.EdgeSwitchPort; * numport=Constants.EdgeSwitchPort; uplinkswitches=new
uplinkswitches=new ArrayList<Switch>(); * ArrayList<Switch>();
*
} * } if(level==Constants.Agg_LEVEL) { downlinkswitchpktlist=new
if(level==Constants.Agg_LEVEL) * HashMap<Integer,List<HostPacket>>(); uplinkswitchpktlist=new
{ * HashMap<Integer,List<HostPacket>>();
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); * uplinkbandwidth=Constants.BandWidthAggRoot;
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); * downlinkbandwidth=Constants.BandWidthEdgeAgg;
uplinkbandwidth=Constants.BandWidthAggRoot; * latency=Constants.SwitchingDelayAgg; numport=Constants.AggSwitchPort;
downlinkbandwidth=Constants.BandWidthEdgeAgg; * uplinkswitches=new ArrayList<Switch>(); downlinkswitches=new
latency=Constants.SwitchingDelayAgg; * ArrayList<Switch>(); } if(level==Constants.ROOT_LEVEL) {
numport=Constants.AggSwitchPort; * downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
uplinkswitches=new ArrayList<Switch>(); * downlinkswitches=new ArrayList<Switch>();
downlinkswitches=new ArrayList<Switch>(); *
} * downlinkbandwidth=Constants.BandWidthAggRoot;
if(level==Constants.ROOT_LEVEL) * latency=Constants.SwitchingDelayRoot;
{ * numport=Constants.RootSwitchPort;
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); *
downlinkswitches=new ArrayList<Switch>(); * }
*/
downlinkbandwidth=Constants.BandWidthAggRoot; this.dc = dc;
latency=Constants.SwitchingDelayRoot;
numport=Constants.RootSwitchPort;
}*/
this.dc=dc;
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@Override @Override
public void startEntity() { public void startEntity() {
Log.printLine(getName() + " is starting..."); Log.printLine(getName() + " is starting...");
schedule(getId(), 0, CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST); schedule(getId(), 0, CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST);
} }
@Override @Override
public void processEvent(SimEvent ev) { public void processEvent(SimEvent ev) {
//Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag()); // Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag());
switch (ev.getTag()){ switch (ev.getTag()) {
// Resource characteristics request // Resource characteristics request
case CloudSimTags.Network_Event_UP: case CloudSimTags.Network_Event_UP:
//process the packet from down switch or host // process the packet from down switch or host
processpacket_up(ev); processpacket_up(ev);
break; break;
case CloudSimTags.Network_Event_DOWN: case CloudSimTags.Network_Event_DOWN:
//process the packet from uplink // process the packet from uplink
processpacket_down(ev); processpacket_down(ev);
break; break;
case CloudSimTags.Network_Event_send: case CloudSimTags.Network_Event_send:
processpacketforward(ev); processpacketforward(ev);
break; break;
case CloudSimTags.Network_Event_Host: case CloudSimTags.Network_Event_Host:
processhostpacket(ev); processhostpacket(ev);
break; break;
// Resource characteristics answer // Resource characteristics answer
case CloudSimTags.RESOURCE_Register: case CloudSimTags.RESOURCE_Register:
registerHost(ev); registerHost(ev);
break; break;
// other unknown tags are processed by this method // other unknown tags are processed by this method
default: default:
processOtherEvent(ev); processOtherEvent(ev);
break; break;
} }
} }
private void processhostpacket(SimEvent ev) { protected void processhostpacket(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//Send packet to host // Send packet to host
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt = (NetworkPacket) ev.getData();
NetworkHost hs=this.hostlist.get(hspkt.recieverhostid); NetworkHost hs = this.hostlist.get(hspkt.recieverhostid);
hs.packetrecieved.add(hspkt); hs.packetrecieved.add(hspkt);
} }
protected void processpacket_down(SimEvent ev) {
private void processpacket_down(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//packet coming from up level router. // packet coming from up level router.
//has to send downward // has to send downward
//check which switch to forward to // check which switch to forward to
//add packet in the switch list // add packet in the switch list
//add packet in the host list // add packet in the host list
//int src=ev.getSource(); // int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(
schedule(getId(),this.latency, CloudSimTags.Network_Event_send); CloudSimTags.Network_Event_send));
if(this.level==Constants.EDGE_LEVEL) schedule(getId(), this.latency, CloudSimTags.Network_Event_send);
{ if (this.level == NetworkConstants.EDGE_LEVEL) {
// packet is to be recieved by host // packet is to be recieved by host
int hostid=dc.VmtoHostlist.get(recvVMid); int hostid = dc.VmtoHostlist.get(recvVMid);
hspkt.recieverhostid=hostid; hspkt.recieverhostid = hostid;
List<HostPacket> pktlist=this.packetTohost.get(hostid); List<NetworkPacket> pktlist = this.packetTohost.get(hostid);
if(pktlist==null){ if (pktlist == null) {
pktlist=new ArrayList<HostPacket>(); pktlist = new ArrayList<NetworkPacket>();
this.packetTohost.put(hostid, pktlist); this.packetTohost.put(hostid, pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
return; return;
} }
if(this.level==Constants.Agg_LEVEL) if (this.level == NetworkConstants.Agg_LEVEL) {
{ // packet is coming from root so need to be sent to edgelevel swich
//packet is coming from root so need to be sent to edgelevel swich // find the id for edgelevel switch
//find the id for edgelevel switch int switchid = dc.VmToSwitchid.get(recvVMid);
int switchid=dc.VmToSwitchid.get(recvVMid); List<NetworkPacket> pktlist = this.downlinkswitchpktlist.get(switchid);
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(switchid); if (pktlist == null) {
if(pktlist==null){ pktlist = new ArrayList<NetworkPacket>();
pktlist=new ArrayList<HostPacket>(); this.downlinkswitchpktlist.put(switchid, pktlist);
this.downlinkswitchpktlist.put(switchid, pktlist); }
} pktlist.add(hspkt);
pktlist.add(hspkt); return;
return; }
}
}
}
private void processpacket_up(SimEvent ev) { protected void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//packet coming from down level router. // packet coming from down level router.
//has to send up // has to send up
//check which switch to forward to // check which switch to forward to
//add packet in the switch list // add packet in the switch list
// //
//int src=ev.getSource(); // int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send); CloudSimTags.Network_Event_send));
if(this.level==Constants.EDGE_LEVEL) schedule(getId(), this.switching_delay, CloudSimTags.Network_Event_send);
{ if (this.level == NetworkConstants.EDGE_LEVEL) {
// packet is recieved from host // packet is recieved from host
//packet is to be sent to aggregate level or to another host in the same level // packet is to be sent to aggregate level or to another host in the
// same level
int hostid=dc.VmtoHostlist.get(recvVMid);
NetworkHost hs=this.hostlist.get(hostid); int hostid = dc.VmtoHostlist.get(recvVMid);
hspkt.recieverhostid=hostid; NetworkHost hs = this.hostlist.get(hostid);
if(hs!=null) hspkt.recieverhostid = hostid;
{ if (hs != null) {
//packet to be sent to host connected to the switch // packet to be sent to host connected to the switch
List<HostPacket> pktlist=this.packetTohost.get(hostid); List<NetworkPacket> pktlist = this.packetTohost.get(hostid);
if(pktlist==null){ if (pktlist == null) {
pktlist=new ArrayList<HostPacket>(); pktlist = new ArrayList<NetworkPacket>();
this.packetTohost.put(hostid, pktlist); this.packetTohost.put(hostid, pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
return; return;
} }
//packet is to be sent to upper switch // packet is to be sent to upper switch
//ASSUMPTION EACH EDGE is Connected to one aggregate level switch // ASSUMPTION EACH EDGE is Connected to one aggregate level switch
Switch sw=this.uplinkswitches.get(0);
List<HostPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
return;
}
if(this.level==Constants.Agg_LEVEL)
{
//packet is coming from edge level router so need to be sent to either root or another edge level swich
//find the id for edgelevel switch
int switchid=dc.VmToSwitchid.get(recvVMid);
boolean flagtoswtich=false;
for(Switch sw:this.downlinkswitches)
{
if(switchid==sw.getId()) flagtoswtich=true;
}
if(flagtoswtich)
{
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(switchid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
}
else//send to up
{
Switch sw=this.uplinkswitches.get(0);
List<HostPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
if(this.level==Constants.ROOT_LEVEL)
{
//get id of edge router
int edgeswitchid=dc.VmToSwitchid.get(recvVMid);
//search which aggregate switch has it
int aggSwtichid=-1;;
for(Switch sw:this.downlinkswitches)
{
for(Switch edge:sw.downlinkswitches)
{
if(edge.getId()==edgeswitchid){
aggSwtichid=sw.getId();
break;
}
}
}
if(aggSwtichid<0) System.out.println(" No destination for this packet");
else{
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(aggSwtichid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
Switch sw = this.uplinkswitches.get(0);
List<NetworkPacket> pktlist = this.uplinkswitchpktlist.get(sw.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
return;
}
if (this.level == NetworkConstants.Agg_LEVEL) {
// packet is coming from edge level router so need to be sent to
// either root or another edge level swich
// find the id for edgelevel switch
int switchid = dc.VmToSwitchid.get(recvVMid);
boolean flagtoswtich = false;
for (Switch sw : this.downlinkswitches) {
if (switchid == sw.getId())
flagtoswtich = true;
}
if (flagtoswtich) {
List<NetworkPacket> pktlist = this.downlinkswitchpktlist
.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
} else// send to up
{
Switch sw = this.uplinkswitches.get(0);
List<NetworkPacket> pktlist = this.uplinkswitchpktlist.get(sw
.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
if (this.level == NetworkConstants.ROOT_LEVEL) {
// get id of edge router
int edgeswitchid = dc.VmToSwitchid.get(recvVMid);
// search which aggregate switch has it
int aggSwtichid = -1;
;
for (Switch sw : this.downlinkswitches) {
for (Switch edge : sw.downlinkswitches) {
if (edge.getId() == edgeswitchid) {
aggSwtichid = sw.getId();
break;
}
}
}
if (aggSwtichid < 0)
System.out.println(" No destination for this packet");
else {
List<NetworkPacket> pktlist = this.downlinkswitchpktlist
.get(aggSwtichid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
private void registerHost(SimEvent ev) { private void registerHost(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
NetworkHost hs=(NetworkHost)ev.getData(); NetworkHost hs = (NetworkHost) ev.getData();
hostlist.put(hs.getId(),(NetworkHost)ev.getData()); hostlist.put(hs.getId(), (NetworkHost) ev.getData());
} }
protected void processpacket(SimEvent ev) {
private void processpacket(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//send packet to itself with switching delay (discarding other) // send packet to itself with switching delay (discarding other)
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_UP)); CloudSim.cancelAll(getId(), new PredicateType(
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_UP); CloudSimTags.Network_Event_UP));
pktlist.add((HostPacket)ev.getData()); schedule(getId(), this.switching_delay, CloudSimTags.Network_Event_UP);
pktlist.add((NetworkPacket) ev.getData());
//add the packet in the list
// add the packet in the list
}
}
private void processOtherEvent(SimEvent ev) { private void processOtherEvent(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
private void processpacketforward(SimEvent ev) { protected void processpacketforward(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//search for the host and packets..send to them // search for the host and packets..send to them
if(this.downlinkswitchpktlist!=null) if (this.downlinkswitchpktlist != null) {
{ for (Entry<Integer, List<NetworkPacket>> es : downlinkswitchpktlist
for(Entry<Integer, List<HostPacket>> es:downlinkswitchpktlist.entrySet()) .entrySet()) {
{ int tosend = es.getKey();
int tosend=es.getKey(); List<NetworkPacket> hspktlist = es.getValue();
List<HostPacket> hspktlist=es.getValue(); if (!hspktlist.isEmpty()) {
if(!hspktlist.isEmpty()){ double avband = this.downlinkbandwidth / hspktlist.size();
double avband=this.downlinkbandwidth/hspktlist.size(); Iterator<NetworkPacket> it = hspktlist.iterator();
Iterator<HostPacket> it=hspktlist.iterator(); while (it.hasNext()) {
while(it.hasNext()){ NetworkPacket hspkt = it.next();
HostPacket hspkt=it.next(); double delay = 1000 * hspkt.pkt.data / avband;
double delay=1000*hspkt.pkt.data/avband;
this.send(tosend, delay,
this.send(tosend,delay,CloudSimTags.Network_Event_DOWN, hspkt); CloudSimTags.Network_Event_DOWN, hspkt);
} }
hspktlist.clear(); hspktlist.clear();
} }
} }
} }
if(this.uplinkswitchpktlist!=null) if (this.uplinkswitchpktlist != null) {
{ for (Entry<Integer, List<NetworkPacket>> es : uplinkswitchpktlist
for(Entry<Integer, List<HostPacket>> es:uplinkswitchpktlist.entrySet()) .entrySet()) {
{ int tosend = es.getKey();
int tosend=es.getKey(); List<NetworkPacket> hspktlist = es.getValue();
List<HostPacket> hspktlist=es.getValue(); if (!hspktlist.isEmpty()) {
if(!hspktlist.isEmpty()){ double avband = this.uplinkbandwidth / hspktlist.size();
double avband=this.uplinkbandwidth/hspktlist.size(); Iterator<NetworkPacket> it = hspktlist.iterator();
Iterator<HostPacket> it=hspktlist.iterator(); while (it.hasNext()) {
while(it.hasNext()) NetworkPacket hspkt = it.next();
{ double delay = 1000 * hspkt.pkt.data / avband;
HostPacket hspkt=it.next();
double delay=1000*hspkt.pkt.data/avband; this.send(tosend, delay, CloudSimTags.Network_Event_UP,
hspkt);
this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt);
} }
hspktlist.clear(); hspktlist.clear();
} }
} }
} }
if(this.packetTohost!=null) if (this.packetTohost != null) {
{ for (Entry<Integer, List<NetworkPacket>> es : packetTohost.entrySet()) {
for(Entry<Integer, List<HostPacket>> es:packetTohost.entrySet()) int tosend = es.getKey();
{ NetworkHost hs = this.hostlist.get(tosend);
int tosend=es.getKey(); List<NetworkPacket> hspktlist = es.getValue();
NetworkHost hs=this.hostlist.get(tosend); if (!hspktlist.isEmpty()) {
List<HostPacket> hspktlist=es.getValue(); double avband = this.downlinkbandwidth / hspktlist.size();
if(!hspktlist.isEmpty()){ Iterator<NetworkPacket> it = hspktlist.iterator();
double avband=this.downlinkbandwidth/hspktlist.size(); while (it.hasNext()) {
Iterator<HostPacket> it=hspktlist.iterator(); NetworkPacket hspkt = it.next();
while(it.hasNext()){ // hspkt.recieverhostid=tosend;
HostPacket hspkt=it.next(); // hs.packetrecieved.add(hspkt);
//hspkt.recieverhostid=tosend; this.send(this.getId(), hspkt.pkt.data / avband,
//hs.packetrecieved.add(hspkt); CloudSimTags.Network_Event_Host, hspkt);
this.send(this.getId(),hspkt.pkt.data/avband,CloudSimTags.Network_Event_Host, hspkt);
} }
hspktlist.clear(); hspktlist.clear();
} }
} }
} }
//or to switch at next level.
//clear the list
}
// or to switch at next level.
// clear the list
}
private NetworkHost getHostwithVM(int vmid) { private NetworkHost getHostwithVM(int vmid) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
for(Entry<Integer, NetworkHost> es:this.hostlist.entrySet()) for (Entry<Integer, NetworkHost> es : this.hostlist.entrySet()) {
{ Vm vm = VmList.getById(es.getValue().getVmList(), vmid);
Vm vm=VmList.getById(es.getValue().getVmList(),vmid); if (vm != null)
if(vm!=null) return es.getValue(); return es.getValue();
} }
return null; return null;
} }
public List<NetworkHost> gethostsWithAvailability(int numHostReq,
double deadline, double exeTime) {
// TODO Auto-generated method stub
List<NetworkHost> ls=null;
for(Entry<Double,List<NetworkHost>> es:this.fintimelistHost.entrySet()){
if((es.getKey()+exeTime)>=deadline){
ls= null;
break;}
else{
if(es.getValue().size()>=numHostReq)
{
ls= es.getValue();
break;
}
}
}
// if(ls==null)
// {
// List<HPCHost> freehostlist=getfreehostlist(numHostReq);
// if(freehostlist.size()>=numHostReq) ls=freehostlist;
// }
return ls;
}
public List<NetworkVm> getVmsWithAvailability(int numVMReq,
double deadline, double exeTime) {
// TODO Auto-generated method stub
List<NetworkVm> ls=new ArrayList<NetworkVm>();
// SortedMap<Double,HPCVm> vmlst=getfintimelistVM();
int i =0;
for(Entry<Integer,NetworkHost> es:this.hostlist.entrySet()){
for(Vm vm:es.getValue().getVmList())
{
NetworkVm v=(NetworkVm)vm;
if((v.finishtime+exeTime)<deadline)
{
ls.add(v);
i++;
}
if(i>=numVMReq) break;
}
if(i>=numVMReq) break;
}
// if((es.getKey()+exeTime)>=deadline){
// ls= null;
// break;}
// else{
// if(es.getValue().size()>=numVMReq)
// {
// ls= es.getValue();
// break;
// }
// }
// }
// if(ls==null)
// {
// List<HPCVm> freeVMlist=getfreeVmlist(numVMReq);
// if(freeVMlist.size()>=numVMReq) ls=freeVMlist;
// }
return ls;
}
// private SortedMap<Double, HPCVm> getfintimelistVM() {
// // TODO Auto-generated method stub
// SortedMap<Double,HPCVm> getfintimelis
// return null;
// }
private List<NetworkVm> getfreeVmlist(int numVMReq) { private List<NetworkVm> getfreeVmlist(int numVMReq) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
List<NetworkVm> freehostls=new ArrayList<NetworkVm>(); List<NetworkVm> freehostls = new ArrayList<NetworkVm>();
for(Entry<Integer,NetworkVm> et:this.Vmlist.entrySet()) for (Entry<Integer, NetworkVm> et : this.Vmlist.entrySet()) {
{ if (et.getValue().isFree()) {
if(et.getValue().isFree())
{
freehostls.add(et.getValue()); freehostls.add(et.getValue());
} }
if(freehostls.size()==numVMReq) if (freehostls.size() == numVMReq)
break; break;
} }
return freehostls; return freehostls;
} }
private List<NetworkHost> getfreehostlist(int numhost) { private List<NetworkHost> getfreehostlist(int numhost) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
List<NetworkHost> freehostls=new ArrayList<NetworkHost>(); List<NetworkHost> freehostls = new ArrayList<NetworkHost>();
for(Entry<Integer,NetworkHost> et:this.hostlist.entrySet()) for (Entry<Integer, NetworkHost> et : this.hostlist.entrySet()) {
{ if (et.getValue().getFreePesNumber() == et.getValue()
if(et.getValue().getFreePesNumber()==et.getValue().getPesNumber()) .getPesNumber()) {
{
freehostls.add(et.getValue()); freehostls.add(et.getValue());
} }
if(freehostls.size()==numhost) if (freehostls.size() == numhost)
break; break;
} }
return freehostls; return freehostls;
} }
@Override @Override
public void shutdownEntity() { public void shutdownEntity() {
Log.printLine(getName() + " is shutting down..."); Log.printLine(getName() + " is shutting down...");
} }
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* Taskstage represents various stages a networkCloudlet can have during execution.
* Four stage types which are possible-> EXECUTION=0; WAIT_SEND=1; WAIT_RECV=2; FINISH=-2;
* Check NeworkConstants.java file for that.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class TaskStage { public class TaskStage {
public TaskStage(int type, double data, double time, double stageid,long memory, public TaskStage(int type, double data, double time, double stageid,
int peer,int vpeer) { long memory, int peer, int vpeer) {
super(); super();
this.type = type; this.type = type;
this.data = data; this.data = data;
...@@ -10,14 +27,15 @@ public class TaskStage { ...@@ -10,14 +27,15 @@ public class TaskStage {
this.stageid = stageid; this.stageid = stageid;
this.memory = memory; this.memory = memory;
this.peer = peer; this.peer = peer;
this.vpeer=vpeer; this.vpeer = vpeer;
} }
int vpeer; int vpeer;
int type;//execution, recv, send, int type;// execution, recv, send,
double data;//data generated or send or recv double data;// data generated or send or recv
double time;//execution time for this stage double time;// execution time for this stage
double stageid; double stageid;
long memory; long memory;
int peer;//from whom data needed to be recieved or send int peer;// from whom data needed to be recieved or send
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* WorkflowApp is an example of AppCloudlet having three communicating tasks.
* Task A and B sends the data (packet) while Task C receives them
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
...@@ -16,30 +32,30 @@ public class WorkflowApp extends AppCloudlet{ ...@@ -16,30 +32,30 @@ public class WorkflowApp extends AppCloudlet{
this.numbervm=3; this.numbervm=3;
} }
public void createCloudletList(List<Integer> vmIdList){ public void createCloudletList(List<Integer> vmIdList){
long fileSize = Constants.FILE_SIZE; long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = Constants.OUTPUT_SIZE; long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = Constants.PES_NUMBER; int pesNumber = NetworkConstants.PES_NUMBER;
int memory=100; int memory=100;
UtilizationModel utilizationModel = new UtilizationModelFull(); UtilizationModel utilizationModel = new UtilizationModelFull();
int i=0; int i=0;
//Task A //Task A
NetworkCloudlet cl = new NetworkCloudlet(Constants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
cl.numStage=2; cl.numStage=2;
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
cl.setUserId(userId); cl.setUserId(userId);
cl.submittime=CloudSim.clock(); cl.submittime=CloudSim.clock();
cl.currStagenum=-1; cl.currStagenum=-1;
cl.setVmId(vmIdList.get(i)); cl.setVmId(vmIdList.get(i));
//first stage: big computation //first stage: big computation
cl.stages.add(new TaskStage(Constants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(0),cl.getCloudletId())); cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(0),cl.getCloudletId()));
cl.stages.add(new TaskStage(Constants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),cl.getCloudletId()+2)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),cl.getCloudletId()+2));
clist.add(cl); clist.add(cl);
i++; i++;
//Task B //Task B
NetworkCloudlet clb = new NetworkCloudlet(Constants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet clb = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
clb.numStage=2; clb.numStage=2;
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
clb.setUserId(userId); clb.setUserId(userId);
clb.submittime=CloudSim.clock(); clb.submittime=CloudSim.clock();
clb.currStagenum=-1; clb.currStagenum=-1;
...@@ -47,24 +63,24 @@ public class WorkflowApp extends AppCloudlet{ ...@@ -47,24 +63,24 @@ public class WorkflowApp extends AppCloudlet{
//first stage: big computation //first stage: big computation
clb.stages.add(new TaskStage(Constants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(1),clb.getCloudletId())); clb.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(1),clb.getCloudletId()));
clb.stages.add(new TaskStage(Constants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),clb.getCloudletId()+1)); clb.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),clb.getCloudletId()+1));
clist.add(clb); clist.add(clb);
i++; i++;
//Task C //Task C
NetworkCloudlet clc = new NetworkCloudlet(Constants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet clc = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
clc.numStage=2; clc.numStage=2;
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
clc.setUserId(userId); clc.setUserId(userId);
clc.submittime=CloudSim.clock(); clc.submittime=CloudSim.clock();
clc.currStagenum=-1; clc.currStagenum=-1;
clc.setVmId(vmIdList.get(i)); clc.setVmId(vmIdList.get(i));
//first stage: big computation //first stage: big computation
clc.stages.add(new TaskStage(Constants.WAIT_RECV, 1000, 0, 0, memory, vmIdList.get(0),cl.getCloudletId())); clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 0, memory, vmIdList.get(0),cl.getCloudletId()));
clc.stages.add(new TaskStage(Constants.WAIT_RECV, 1000, 0, 1, memory, vmIdList.get(1),cl.getCloudletId()+1)); clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 1, memory, vmIdList.get(1),cl.getCloudletId()+1));
clc.stages.add(new TaskStage(Constants.EXECUTION, 0, 1000*0.8, 1, memory, vmIdList.get(0),clc.getCloudletId())); clc.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 1, memory, vmIdList.get(0),clc.getCloudletId()));
clist.add(clc); clist.add(clc);
......
...@@ -33,275 +33,301 @@ public class testMainclass { ...@@ -33,275 +33,301 @@ public class testMainclass {
* @param args * @param args
*/ */
/** The cloudlet list. */
private static List<AppCloudlet> cloudletList;
/** The cloudlet list. */ /** The vmlist. */
private static List<AppCloudlet> cloudletList; private static List<NetworkVm> vmlist;
/** The vmlist. */ /**
private static List<NetworkVm> vmlist; * Creates main() to run this example.
*
/** * @param args
* Creates main() to run this example. * the args
* */
* @param args the args public static void main(String[] args) {
*/
public static void main(String[] args) { Log.printLine("Starting CloudSimExample1...");
Log.printLine("Starting CloudSimExample1..."); try {
int num_user = 1; // number of cloud users
try { Calendar calendar = Calendar.getInstance();
int num_user = 1; // number of cloud users boolean trace_flag = false; // mean trace events
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; // mean trace events // Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag);
// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag); // Second step: Create Datacenters
// Datacenters are the resource providers in CloudSim. We need at
// Second step: Create Datacenters // list one of them to run a CloudSim simulation
// Datacenters are the resource providers in CloudSim. We need at NetworkDatacenter datacenter0 = createDatacenter("Datacenter_0");
// list one of them to run a CloudSim simulation
NetworkDatacenter datacenter0 = createDatacenter("Datacenter_0"); // Third step: Create Broker
NetDatacenterBroker broker = createBroker();
// Third step: Create Broker int brokerId = broker.getId();
NetDatacenterBroker broker = createBroker(); broker.setLinkDC(datacenter0);
int brokerId = broker.getId(); // broker.setLinkDC(datacenter0);
broker.setLinkDC(datacenter0); // Fifth step: Create one Cloudlet
//broker.setLinkDC(datacenter0); cloudletList = new ArrayList<AppCloudlet>();
// Fifth step: Create one Cloudlet
cloudletList = new ArrayList<AppCloudlet>(); vmlist = new ArrayList<NetworkVm>();
vmlist = new ArrayList<NetworkVm>(); // submit vm list to the broker
// submit vm list to the broker broker.submitVmList(vmlist);
// Sixth step: Starts the simulation
broker.submitVmList(vmlist); CloudSim.startSimulation();
// Sixth step: Starts the simulation CloudSim.stopSimulation();
CloudSim.startSimulation();
// Final step: Print results when simulation is over
CloudSim.stopSimulation(); List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);
//Final step: Print results when simulation is over System.out.println("numberofcloudlet " + newList.size()
List<Cloudlet> newList = broker.getCloudletReceivedList(); + " Cached " + NetDatacenterBroker.cachedcloudlet
printCloudletList(newList); + " Data transfered " + NetworkConstants.totaldatatransfer);
System.out.println("numberofcloudlet "+newList.size()+" Cached "+NetDatacenterBroker.cachedcloudlet+" Data transfered "+Constants.totaldatatransfer); // Print the debt of each user to each datacenter
// Print the debt of each user to each datacenter datacenter0.printDebts();
datacenter0.printDebts();
Log.printLine("CloudSimExample1 finished!");
Log.printLine("CloudSimExample1 finished!"); } catch (Exception e) {
} catch (Exception e) { e.printStackTrace();
e.printStackTrace(); Log.printLine("Unwanted errors happen");
Log.printLine("Unwanted errors happen");
}
} }
}
/**
* Creates the datacenter.
*
* @param name
* the name
*
* @return the datacenter
*/
private static NetworkDatacenter createDatacenter(String name) {
/** // Here are the steps needed to create a PowerDatacenter:
* Creates the datacenter. // 1. We need to create a list to store
* // our machine
* @param name the name
*
* @return the datacenter
*/
private static NetworkDatacenter createDatacenter(String name) {
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store
// our machine
List<NetworkHost> hostList = new ArrayList<NetworkHost>();
List<NetworkHost> hostList = new ArrayList<NetworkHost>();
// 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core.
// List<Pe> peList = new ArrayList<Pe>();
int mips = 1;
// 3. Create PEs and add these into a list.
// peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to
// store Pe id and MIPS Rating
// 4. Create Host with its id and list of PEs and add them to the list
// of machines
int hostId = 0;
int ram = 2048; // host memory (MB)
long storage = 1000000; // host storage
int bw = 10000;
for (int i = 0; i < NetworkConstants.EdgeSwitchPort
* NetworkConstants.AggSwitchPort
* NetworkConstants.RootSwitchPort; i++) {
// 2. A Machine contains one or more PEs or CPUs/Cores. // 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core. // In this example, it will have only one core.
//List<Pe> peList = new ArrayList<Pe>(); // 3. Create PEs and add these into an object of PowerPeList.
List<Pe> peList = new ArrayList<Pe>();
int mips = 1; peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to
// store
// 3. Create PEs and add these into a list. // PowerPe
//peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating // id and
// MIPS
// 4. Create Host with its id and list of PEs and add them to the list // Rating
// of machines peList.add(new Pe(1, new PeProvisionerSimple(mips))); // need to
int hostId = 0; // store
int ram = 2048; // host memory (MB) // PowerPe
long storage = 1000000; // host storage // id and
int bw = 10000; // MIPS
for (int i = 0; i < Constants.EdgeSwitchPort*Constants.AggSwitchPort*Constants.RootSwitchPort; i++) { // Rating
// 2. A Machine contains one or more PEs or CPUs/Cores. peList.add(new Pe(2, new PeProvisionerSimple(mips))); // need to
// In this example, it will have only one core. // store
// 3. Create PEs and add these into an object of PowerPeList. // PowerPe
List<Pe> peList = new ArrayList<Pe>(); // id and
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // MIPS
peList.add(new Pe(1, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // Rating
peList.add(new Pe(2, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating peList.add(new Pe(3, new PeProvisionerSimple(mips))); // need to
peList.add(new Pe(3, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // store
peList.add(new Pe(4, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // PowerPe
peList.add(new Pe(5, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // id and
peList.add(new Pe(6, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // MIPS
peList.add(new Pe(7, new PeProvisionerSimple(mips))); // need to store PowerPe id and MIPS Rating // Rating
peList.add(new Pe(4, new PeProvisionerSimple(mips))); // need to
// store
// PowerPe
// id and
// 4. Create PowerHost with its id and list of PEs and add them to the list of machines // MIPS
hostList.add( // Rating
new NetworkHost( peList.add(new Pe(5, new PeProvisionerSimple(mips))); // need to
i, // store
new RamProvisionerSimple(ram), // PowerPe
new BwProvisionerSimple(bw), // id and
storage, // MIPS
peList, // Rating
new VmSchedulerTimeShared(peList) peList.add(new Pe(6, new PeProvisionerSimple(mips))); // need to
) // store
); // This is our machine // PowerPe
} // id and
// MIPS
// Rating
// 5. Create a DatacenterCharacteristics object that stores the peList.add(new Pe(7, new PeProvisionerSimple(mips))); // need to
// properties of a data center: architecture, OS, list of // store
// Machines, allocation policy: time- or space-shared, time zone // PowerPe
// and its price (G$/Pe time unit). // id and
String arch = "x86"; // system architecture // MIPS
String os = "Linux"; // operating system // Rating
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource located // 4. Create PowerHost with its id and list of PEs and add them to
double cost = 3.0; // the cost of using processing in this resource // the list of machines
double costPerMem = 0.05; // the cost of using memory in this resource hostList.add(new NetworkHost(i, new RamProvisionerSimple(ram),
double costPerStorage = 0.001; // the cost of using storage in this new BwProvisionerSimple(bw), storage, peList,
// resource new VmSchedulerTimeShared(peList))); // This is our machine
double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
// devices by now
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);
// 6. Finally, we need to create a PowerDatacenter object.
NetworkDatacenter datacenter = null;
try {
datacenter = new NetworkDatacenter(name, characteristics, new VmHPCAllocationPolicySimple(hostList), storageList, 0);
//datacenter = new HPCDatacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0.0001);
} catch (Exception e) {
e.printStackTrace();
}
CreateNetwork(2,datacenter);
return datacenter;
} }
// We strongly encourage users to develop their own broker policies, to // 5. Create a DatacenterCharacteristics object that stores the
// submit vms and cloudlets according // properties of a data center: architecture, OS, list of
// to the specific rules of the simulated scenario // Machines, allocation policy: time- or space-shared, time zone
/** // and its price (G$/Pe time unit).
* Creates the broker. String arch = "x86"; // system architecture
* String os = "Linux"; // operating system
* @return the datacenter broker String vmm = "Xen";
*/ double time_zone = 10.0; // time zone this resource located
private static NetDatacenterBroker createBroker() { double cost = 3.0; // the cost of using processing in this resource
NetDatacenterBroker broker = null; double costPerMem = 0.05; // the cost of using memory in this resource
try { double costPerStorage = 0.001; // the cost of using storage in this
broker = new NetDatacenterBroker("Broker"); // resource
} catch (Exception e) { double costPerBw = 0.0; // the cost of using bw in this resource
e.printStackTrace(); LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are
return null; // not
} // adding
return broker; // SAN
// devices by now
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);
// 6. Finally, we need to create a NetworkDatacenter object.
NetworkDatacenter datacenter = null;
try {
datacenter = new NetworkDatacenter(name, characteristics,
new NetworkVmAllocationPolicy(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
} }
// Create Internal Datacenter network
CreateNetwork(2, datacenter);
return datacenter;
}
/** // We strongly encourage users to develop their own broker policies, to
* Prints the Cloudlet objects. // submit vms and cloudlets according
* // to the specific rules of the simulated scenario
* @param list list of Cloudlets /**
* @throws IOException * Creates the broker.
*/ *
private static void printCloudletList(List<Cloudlet> list) throws IOException { * @return the datacenter broker
int size = list.size(); */
Cloudlet cloudlet; private static NetDatacenterBroker createBroker() {
double fintime=0; NetDatacenterBroker broker = null;
String indent = " "; try {
Log.printLine(); broker = new NetDatacenterBroker("Broker");
Log.printLine("========== OUTPUT =========="); } catch (Exception e) {
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent e.printStackTrace();
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent return null;
+ "Start Time" + indent + "Finish Time"); }
return broker;
DecimalFormat dft = new DecimalFormat("###.##"); }
for (int i = 0; i < size; i++) {
cloudlet = list.get(i); /**
Log.print(indent + cloudlet.getCloudletId() + indent + indent); * Prints the Cloudlet objects.
*
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { * @param list
Log.print("SUCCESS"); * list of Cloudlets
fintime=cloudlet.getFinishTime(); * @throws IOException
Log.printLine(indent + indent + cloudlet.getResourceId() */
+ indent + indent + indent + cloudlet.getVmId() private static void printCloudletList(List<Cloudlet> list)
+ indent + indent throws IOException {
+ dft.format(cloudlet.getActualCPUTime()) + indent int size = list.size();
+ indent + dft.format(cloudlet.getExecStartTime()) Cloudlet cloudlet;
+ indent + indent double fintime = 0;
+ dft.format(cloudlet.getFinishTime())); String indent = " ";
} Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
+ "Data center ID" + indent + "VM ID" + indent + "Time"
+ indent + "Start Time" + indent + "Finish Time");
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
Log.print("SUCCESS");
fintime = cloudlet.getFinishTime();
Log.printLine(indent + indent + cloudlet.getResourceId()
+ indent + indent + indent + cloudlet.getVmId()
+ indent + indent
+ dft.format(cloudlet.getActualCPUTime()) + indent
+ indent + dft.format(cloudlet.getExecStartTime())
+ indent + indent
+ dft.format(cloudlet.getFinishTime()));
} }
File f=new File("outputmine.csv");
if(!f.exists())
{
f.createNewFile();
}
FileOutputStream fop1=new FileOutputStream(f,true);
fop1.write(("RequestClass ,"+Constants.REQUEST_CLASSES+",numberofcloudlet, "+list.size()+" ,Cached, "+NetDatacenterBroker.cachedcloudlet+" ,Data transfered, "+Constants.totaldatatransfer+ " ,Process Time, "+fintime+"\n").getBytes());
fop1.close();
} }
}
static void CreateNetwork(int numhost, NetworkDatacenter dc) {
static void CreateNetwork(int numhost, NetworkDatacenter dc)
{ // //Root Switch
// Switch swroot=new Switch("Root", Constants.ROOT_LEVEL, dc);
// //Root Switch // dc.Switchlist.put(swroot.getId(), swroot);
// Switch swroot=new Switch("Root", Constants.ROOT_LEVEL, dc); // //Agg Switch
// dc.Switchlist.put(swroot.getId(), swroot); // Switch aggswitch[]=new Switch[(int) Constants.RootSwitchPort];
// //Agg Switch // for(int j=0;j<Constants.RootSwitchPort;j++)
// Switch aggswitch[]=new Switch[(int) Constants.RootSwitchPort]; // {
// for(int j=0;j<Constants.RootSwitchPort;j++) // aggswitch[j]=new Switch("Agg"+j, Constants.Agg_LEVEL, dc);
// { // swroot.downlinkswitches.add(aggswitch[j]);
// aggswitch[j]=new Switch("Agg"+j, Constants.Agg_LEVEL, dc); // aggswitch[j].uplinkswitches.add(swroot);
// swroot.downlinkswitches.add(aggswitch[j]); // dc.Switchlist.put(aggswitch[j].getId(), aggswitch[j]);
// aggswitch[j].uplinkswitches.add(swroot); // }
// dc.Switchlist.put(aggswitch[j].getId(), aggswitch[j]); // Edge Switch
// } EdgeSwitch edgeswitch[] = new EdgeSwitch[1];
//Edge Switch
EdgeSwitch edgeswitch[]=new EdgeSwitch[1]; for (int i = 0; i < 1; i++) {
edgeswitch[i] = new EdgeSwitch("Edge" + i,
for(int i=0;i<1;i++) NetworkConstants.EDGE_LEVEL, dc);
{ // edgeswitch[i].uplinkswitches.add(null);
edgeswitch[i]=new EdgeSwitch("Edge"+i, Constants.EDGE_LEVEL, dc);
//edgeswitch[i].uplinkswitches.add(null);
dc.Switchlist.put(edgeswitch[i].getId(), edgeswitch[i]); dc.Switchlist.put(edgeswitch[i].getId(), edgeswitch[i]);
//aggswitch[(int) (i/Constants.AggSwitchPort)].downlinkswitches.add(edgeswitch[i]); // aggswitch[(int)
// (i/Constants.AggSwitchPort)].downlinkswitches.add(edgeswitch[i]);
} }
for(Host hs:dc.getHostList()) for (Host hs : dc.getHostList()) {
{ NetworkHost hs1 = (NetworkHost) hs;
NetworkHost hs1=(NetworkHost)hs; hs1.bandwidth = NetworkConstants.BandWidthEdgeHost;
hs1.bandwidth=Constants.BandWidthEdgeHost; int switchnum = (int) (hs.getId() / NetworkConstants.EdgeSwitchPort);
int switchnum=(int) (hs.getId()/Constants.EdgeSwitchPort);
edgeswitch[switchnum].hostlist.put(hs.getId(), hs1); edgeswitch[switchnum].hostlist.put(hs.getId(), hs1);
dc.HostToSwitchid.put(hs.getId(),edgeswitch[switchnum].getId()); dc.HostToSwitchid.put(hs.getId(), edgeswitch[switchnum].getId());
hs1.sw=edgeswitch[switchnum]; hs1.sw = edgeswitch[switchnum];
List<NetworkHost> hslist=hs1.sw.fintimelistHost.get(0D); List<NetworkHost> hslist = hs1.sw.fintimelistHost.get(0D);
if(hslist==null) if (hslist == null) {
{ hslist = new ArrayList<NetworkHost>();
hslist=new ArrayList<NetworkHost>(); hs1.sw.fintimelistHost.put(0D, hslist);
hs1.sw.fintimelistHost.put(0D,hslist);
} }
hslist.add(hs1); hslist.add(hs1);
} }
} }
} }
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