CloudSim源代码学习之DatacenterCharacteristics.docx
《CloudSim源代码学习之DatacenterCharacteristics.docx》由会员分享,可在线阅读,更多相关《CloudSim源代码学习之DatacenterCharacteristics.docx(21页珍藏版)》请在冰豆网上搜索。
CloudSim源代码学习之DatacenterCharacteristics
packageorg.cloudbus.cloudsim;
importjava.util.List;//Anorderedcollection排好序的事件
importorg.cloudbus.cloudsim.core.CloudSim;//使网络仿真能够实现
importorg.cloudbus.cloudsim.lists.HostList;//主机列表
importorg.cloudbus.cloudsim.lists.PeList;//pe列表
/**DatacenterCharacteristics资源的静态属性
*DatacenterCharacteristicsrepresentsstaticpropertiesofa
*resourcesuchasresourcearchitecture,OperatingSystem(OS),management
*policy(time-orspace-shared),costandtimezoneatwhichtheresource
*islocatedalongresourceconfiguration.
*
*@authorManzurMurshed
*@authorRajkumarBuyya
*@authorRodrigoN.Calheiros
*@authorAntonBeloglazov
*@sinceCloudSimToolkit1.0
*/
publicclassDatacenterCharacteristics{
/**Theresourceid--setupwhenResourceiscreated.资源ID*/
privateintid;
/**Thearchitecture.架构*/
privateStringarchitecture;
/**Theos.操作系统*/
privateStringos;
/**Thehostlist.主机列表*/
privateList
extendsHost>hostList;
/**Thetimezone--differencefromGMT.时区*/
privatedoubletimeZone;
/**Price/CPU-unitifunit=sec.,thenG$/CPU-sec.每秒费用*/
privatedoublecostPerSecond;
/**ResourceTypes--allocationpolicy.分配协议*/
privateintallocationPolicy;
/**Time-sharedsystemusingRound-Robinalgorithm.【使用循环算法的时间共享系统】*/
publicstaticfinalintTIME_SHARED=0;
/**Spaced-sharedsystemusingFirstComeFirstServe(FCFS)algorithm.【使用先来先服务算法的空间共享系统】*/
publicstaticfinalintSPACE_SHARED=1;
/**AssumingallPEsinallMachineshavethesamerating.*/
publicstaticfinalintOTHER_POLICY_SAME_RATING=2;
/**AssumingallPEsinaMachinehavethesamerating.However,eachMachinehasdifferentratingtoeachother.*/
publicstaticfinalintOTHER_POLICY_DIFFERENT_RATING=3;
/**AresourcethatsupportsAdvancedReservationmechanisms.【支持预留机制】*/
publicstaticfinalintADVANCE_RESERVATION=4;
/**Thevmm.虚拟机管理程序*/
privateStringvmm;
/**Thecostpermem.每内存费用*/
privatedoublecostPerMem;
/**Thecostperstorage.每存储费用*/
privatedoublecostPerStorage;
/**Thecostperbw.每带宽费用*/
privatedoublecostPerBw;
/**【分配一新的数据中心特征对象】
*AllocatesanewDatacenterCharacteristicsobject.
*Ifthetimezoneisinvalid,thenbydefault,itwillbeGMT+0.默认时区
*
*@paramarchitecturethearchitectureofaresource
*@paramostheoperatingsystemused
*@paramvmmthevirtualmachinemonitorused
*@paramhostListlistofmachinesinaresource
*@paramtimeZonelocaltimezoneofauserthatownsthisreservation(预约时区).
*Timezoneshouldbeofrange[GMT-12...GMT+13]
*@paramcostPerSecthecostpersectousethisresource
*@paramcostPerMemthecosttousememoryinthisresource
*@paramcostPerStoragethecosttousestorageinthisresource
*@paramcostPerBwthecostperbw
*
*@prearchitecture!
=null
*@preOS!
=null
*@preVMM!
=null
*@premachineList!
=null
*@pretimeZone>=-12&&timeZone<=13
*@precostPerSec>=0.0
*@precostPerMem>=0
*@precostPerStorage>=0
*@post$none
*/
publicDatacenterCharacteristics(
Stringarchitecture,
Stringos,
Stringvmm,
List
extendsHost>hostList,
doubletimeZone,
doublecostPerSec,
doublecostPerMem,
doublecostPerStorage,
doublecostPerBw){
setId(-1);
setArchitecture(architecture);
setOs(os);
setHostList(hostList);
setAllocationPolicy(allocationPolicy);
setCostPerSecond(costPerSec);
setTimeZone(0.0);
setVmm(vmm);
setCostPerMem(costPerMem);
setCostPerStorage(costPerStorage);
setCostPerBw(costPerBw);
}
/**【资源名】
*Getsthenameofaresource.
*
*@returntheresourcename
*
*@pre$none
*@post$result!
=null
*/
publicStringgetResourceName(){
returnCloudSim.getEntityName(getId());
}
/**【至少有一个空闲PE的机器】
*GetsaMachinewithatleastoneemptyPe.
*
*@returnaMachineobjectorifnotfound
*@pre$none
*@post$none
*/
publicHostgetHostWithFreePe(){
returnHostList.getHostWithFreePe(getHostList());
}
/**【给定空闲PE数的机器】
*GetsaMachinewithatleastagivennumberoffreePe.
*
*@parampeNumberthepenumber
*@returnaMachineobjectorifnotfound
*@pre$none
*@post$none
*/
publicHostgetHostWithFreePe(intpeNumber){
returnHostList.getHostWithFreePe(getHostList(),peNumber);
}
/**【PE的MIPS】
*GetsMillionsInstructionsPerSecond(MIPS)RatingofaProcessing
*Element(Pe).ItisassumedallPEs'ratingissameinagivenmachine.
*
*@returntheMIPSRatingorifnoPEsareexists.
*@pre$none
*@post$result>=-1
*/
@SuppressWarnings("unchecked")
publicintgetMipsOfOnePe(){
if(getHostList().size()==0){
return-1;
}
returnPeList.getMips((List)getHostList().get(0).getPeList(),0);
}
/**资源异构时的获取PE的MIPS之方法....
*GetsMillionsInstructionsPerSecond(MIPS)RatingofaProcessing
*Element(Pe).
*Itisessentialtousethismethodwhenaresourceismadeup
*ofheterogenousPEs/machines.
*
*@paramidthemachineID
*@parampeIdthePeID
*@returntheMIPSRatingorifnoPEsareexists.
*@preid>=0
*@prepeID>=0
*@post$result>=-1
*/
@SuppressWarnings("unchecked")
publicintgetMipsOfOnePe(intid,intpeId){
if(getHostList().size()==0){
return-1;
}
returnPeList.getMips((List)HostList.getById(getHostList(),id).getPeList(),peId);
}
/**【一个资源的MIPS之和】
*GetsthetotalMIPSrating,whichisthesumofMIPSratingofall
*machinesinaresource.
*
*TotalMIPSratingfor:
*
*
*@returnthesumofMIPSratings
*
*@pre$none
*@post$result>=0
*/
publicintgetMips(){
intmips=0;
switch(getAllocationPolicy()){
//AssumingallPEsinallMachinehavesamerating.假设所有机器里的PE有同样的速率
caseDatacenterCharacteristics.TIME_SHARED:
caseDatacenterCharacteristics.OTHER_POLICY_SAME_RATING:
mips=getMipsOfOnePe()*HostList.getPesNumber(getHostList());
break;
//不同的机器有不同速率AssumingallPEsinagivenMachinehavethesamerating.
//ButdifferentmachinesinaClustercanhavedifferentrating
caseDatacenterCharacteristics.SPACE_SHARED:
caseDatacenterCharacteristics.OTHER_POLICY_DIFFERENT_RATING:
for(Hosthost:
getHostList()){
mips+=host.getTotalMips();
}
break;
default:
break;
}
returnmips;
}
/**《时间共享》CPU时间
*GetstheCPUtimegiventhespecifiedparameters(onlyforTIME_SHARED).
*NOTE:
TheCPUtimeforSPACE_SHAREDandADVANCE_RESERVATION
*arenotyetimplemented.
*
*@paramcloudletLengththelengthofaCloudlet云任务长度
*@paramloadtheloadofaCloudlet云任务负载
*
*@returntheCPUtime
*
*@precloudletLength>=0.0
*@preload>=0.0
*@post$result>=0.0
*/
publicdoublegetCpuTime(doublecloudletLength,doubleload){
doublecpuTime=0.0;
switch(getAllocationPolicy()){
caseDatacenterCharacteristics.TIME_SHARED:
cpuTime=cloudletLength/(getMipsOfOnePe()*(1.0-load));//load怎么算?
break;
default:
break;
}
returncpuTime;
}
/**【PE总数】
*GetsthetotalnumberofPEsforallMachines.
*
*@returnnumberofPEs
*
*@pre$none
*@post$result>=0
*/
publicintgetPesNumber(){
returnHostList.getPesNumber(getHostList());
}
/**【空闲PE总数】
*GetsthetotalnumberofFREEornon-busyPEsforallMachines.
*
*@returnnumberofPEs
*
*@pre$none
*@post$result>=0
*/
publicintgetFreePesNumber(){
returnHostList.getFreePesNumber(getHostList());
}
/**【机器PE总数】
*GetsthetotalnumberofBUSYPEsforallMachines.
*
*@returnnumberofPEs
*
*@pre$none
*@post$result>=0
*/
publicintgetBusyPesNumber(){
returnHostList.getBusyPesNumber(getHostList());
}
/**【设置PE状态】
*SetstheparticularPestatusonaMachine.
*
*@paramstatusPestatus,eitherPe.FREEorPe.BUSY
*@paramhostIdMachineID
*@parampeIdPeid
*@return
*otherwise(MachineidorPeidmightnotbeexist)
*@premachineID>=0
*@prepeID>=0
*@post$none
*/
publicbooleansetPeStatus(intstatus,inthostId,intpeId){
returnHostList.setPeStatus(getHostList(),status,hostId,peId);
}
/**【每MillionsInstruction的花费】
*GetsthecostperMillionsInstruction(MI)associatedwitharesource.
*
*@returnthecostusingaresource
*
*@pre$none
*@post$result>=0.0
*/
publicdoublegetCostPerMi(){
returngetCostPerSecond()/getMipsOfOnePe();
}
/**【机器总数】
*Getsthetotalnumberofmachines.
*
*@returntotalnumberofmachinesthisresourcehas.
*/
publicintgetHostsNumber(){
returngetHostList().size();
}
/**【当前失效的机器】
*Getsthecurrentnumberoffailedmachines.
*
*@returncurrentnumberoffailedmachinesthisresourcehas.
*/
publicintgetFailedHostsNumber(){
intfailedHostsNumber=0;
for(Hosthost:
getHostList()){
if(host.isFailed()){
failedHostsNumber++;
}
}
returnfailedHostsNumber;
}
/**【检查机器是否工作正常】
*Checkswhetherallmachinesofthisresourceareworkingproperlyornot.
*
*@returnifallmachinesareworking,
*otherwise
*/
publicbooleanisWorking(){
booleanresult=false;
if(getFailedHostsNumber()==0){
result=true;
}
returnresult;
}
/**【使用资源的内存花费】
*Getthecosttousememoryinthisresource.
*
*@returnthecosttousememory
*/
publicdoublegetCostPerMem(){
returncostPerMem;
}
/**【设置