Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gpucloudsim
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LPDS
gpucloudsim
Commits
059beb41
Commit
059beb41
authored
Dec 15, 2011
by
rodrigo.calheiros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NetworkCloudSim merged with CloudSim
parent
09118073
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
4651 additions
and
0 deletions
+4651
-0
AggregateSwitch.java
...cloudbus/cloudsim/network/datacenter/AggregateSwitch.java
+107
-0
AppCloudlet.java
...org/cloudbus/cloudsim/network/datacenter/AppCloudlet.java
+65
-0
CloudletHPCSpaceShared.java
...s/cloudsim/network/datacenter/CloudletHPCSpaceShared.java
+808
-0
CloudletHPCSpaceSharedO.java
.../cloudsim/network/datacenter/CloudletHPCSpaceSharedO.java
+900
-0
Constants.java
...a/org/cloudbus/cloudsim/network/datacenter/Constants.java
+71
-0
EdgeSwitch.java
.../org/cloudbus/cloudsim/network/datacenter/EdgeSwitch.java
+137
-0
HostPacket.java
.../org/cloudbus/cloudsim/network/datacenter/HostPacket.java
+22
-0
MonteCarloApp.java
...g/cloudbus/cloudsim/network/datacenter/MonteCarloApp.java
+70
-0
NetDatacenterBroker.java
...dbus/cloudsim/network/datacenter/NetDatacenterBroker.java
+732
-0
NetPacket.java
...a/org/cloudbus/cloudsim/network/datacenter/NetPacket.java
+22
-0
NetworkCloudlet.java
...cloudbus/cloudsim/network/datacenter/NetworkCloudlet.java
+61
-0
NetworkDatacenter.java
...oudbus/cloudsim/network/datacenter/NetworkDatacenter.java
+196
-0
NetworkHost.java
...org/cloudbus/cloudsim/network/datacenter/NetworkHost.java
+195
-0
NetworkVm.java
...a/org/cloudbus/cloudsim/network/datacenter/NetworkVm.java
+34
-0
RootSwitch.java
.../org/cloudbus/cloudsim/network/datacenter/RootSwitch.java
+68
-0
Switch.java
...java/org/cloudbus/cloudsim/network/datacenter/Switch.java
+504
-0
TaskStage.java
...a/org/cloudbus/cloudsim/network/datacenter/TaskStage.java
+23
-0
VmHPCAllocationPolicySimple.java
...udsim/network/datacenter/VmHPCAllocationPolicySimple.java
+257
-0
WorkflowApp.java
...org/cloudbus/cloudsim/network/datacenter/WorkflowApp.java
+72
-0
testMainclass.java
...g/cloudbus/cloudsim/network/datacenter/testMainclass.java
+307
-0
No files found.
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/AggregateSwitch.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.core.SimEvent
;
import
org.cloudbus.cloudsim.core.predicates.PredicateType
;
public
class
AggregateSwitch
extends
Switch
{
public
AggregateSwitch
(
String
name
,
int
level
,
NetworkDatacenter
dc
)
{
super
(
name
,
level
,
dc
);
// 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
>();
}
private
void
processpacket_down
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//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
//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
;
}
}
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
);
}
}
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/AppCloudlet.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.cloudbus.cloudsim.UtilizationModel
;
import
org.cloudbus.cloudsim.UtilizationModelFull
;
import
org.cloudbus.cloudsim.core.CloudSim
;
public
class
AppCloudlet
{
public
static
final
int
APP_MC
=
1
;
public
static
final
int
APP_Workflow
=
3
;
public
AppCloudlet
(
int
type
,
int
appID
,
double
deadline
,
int
numbervm
,
int
userId
)
{
super
();
this
.
type
=
type
;
this
.
appID
=
appID
;
this
.
deadline
=
deadline
;
this
.
numbervm
=
numbervm
;
this
.
userId
=
userId
;
clist
=
new
ArrayList
<
NetworkCloudlet
>();
}
public
int
type
;
//fft,fem
public
int
appID
;
public
ArrayList
<
NetworkCloudlet
>
clist
;
public
double
deadline
;
public
double
accuracy
;
public
int
numbervm
;
public
int
userId
;
public
double
exeTime
;
public
int
requestclass
;
public
void
createCloudletList
(
List
<
Integer
>
vmIdList
)
{
for
(
int
i
=
0
;
i
<
numbervm
;
i
++){
long
length
=
4
;
long
fileSize
=
300
;
long
outputSize
=
300
;
long
memory
=
256
;
int
pesNumber
=
4
;
UtilizationModel
utilizationModel
=
new
UtilizationModelFull
();
//HPCCloudlet cl=new HPCCloudlet();
NetworkCloudlet
cl
=
new
NetworkCloudlet
(
Constants
.
currentCloudletId
,
length
,
pesNumber
,
fileSize
,
outputSize
,
memory
,
utilizationModel
,
utilizationModel
,
utilizationModel
);
// setting the owner of these Cloudlets
Constants
.
currentCloudletId
++;
cl
.
setUserId
(
userId
);
cl
.
submittime
=
CloudSim
.
clock
();
// TaskStage ts=new TaskStage(Constants.EXECUTION, 0, length, 0,memory, (i+1)%numbervm);
// TaskStage ts1=new TaskStage(Constants.WAIT_SEND, 100, 0, 0, memory, (i+1)%numbervm);
// 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);
// 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
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/CloudletHPCSpaceShared.java
0 → 100755
View file @
059beb41
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
;
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/CloudletHPCSpaceSharedO.java
0 → 100755
View file @
059beb41
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
CloudletHPCSpaceSharedO
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
private
ResCloudlet
buffered
;
//to overlap with communication
private
double
lastbufferUpdateTime
;
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
CloudletHPCSpaceSharedO
()
{
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
>>();
//this.buffered=new ArrayList<ResCloudlet>();
}
/**
* 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
*/
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
if
(
getCloudletExecList
().
size
()>
1
)
System
.
out
.
println
(
"Something is wrong "
+
getCloudletExecList
().
size
());
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
)
{
//if(Constants.logflag)
//System.out.println(cl.getCloudletId()+ "Cloudlet is in Execution: "+ CloudSim.clock());
//rcl.updateCloudletFinishedSoFar((long) (capacity * Math.round(timeSpam) * rcl.getPesNumber()));
//update the time
cl
.
timespentInStage
+=
Math
.
round
(
CloudSim
.
clock
()-
cl
.
timetostartStage
);
if
(
cl
.
getCloudletId
()==
198
)
System
.
out
.
println
(
"I am in 198 "
+
CloudSim
.
clock
());
if
(
cl
.
timespentInStage
>=
st
.
time
)
{
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
)
{
List
<
NetPacket
>
pktlist
=
this
.
pktrecv
.
get
(
st
.
vpeer
);
if
(
Constants
.
logflag
)
System
.
out
.
println
(
cl
.
getCloudletId
()+
"Cloudlet is in Recieve: "
+
CloudSim
.
clock
());
List
<
NetPacket
>
pkttoremove
=
new
ArrayList
<
NetPacket
>();
if
(
pktlist
!=
null
){
if
(
pktlist
.
size
()!=
0
)
{
Iterator
it
=
pktlist
.
iterator
();
NetPacket
pkt
=
null
;
while
(
it
.
hasNext
())
{
pkt
=(
NetPacket
)
it
.
next
();
if
(
pkt
.
virtualrecvid
==
cl
.
getCloudletId
())
//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
}
}
if
(
buffered
!=
null
)
updatebuffered
(
CloudSim
.
clock
());
else
{
//System.out.println("Update Buffer");
}
}
}
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
System
.
out
.
println
(
rcl
.
getCloudletId
()+
"Cloudlet is in finished: "
+
CloudSim
.
clock
());
((
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
())
{
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
++)
{
toRemove
.
clear
();
for
(
ResCloudlet
rcl
:
getCloudletWaitingList
())
{
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
);
for
(
int
k
=
0
;
k
<
rcl
.
getPesNumber
();
k
++)
{
rcl
.
setMachineAndPeId
(
0
,
i
);
}
getCloudletExecList
().
add
(
rcl
);
usedPes
+=
rcl
.
getPesNumber
();
toRemove
.
add
(
rcl
);
// if(buffered!=null){
// HPCCloudlet cl=(HPCCloudlet)(buffered.getCloudlet());
// cl.timetostartStage=CloudSim.clock();
// }
buffered
=
null
;
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
();
NetworkCloudlet
cl
=(
NetworkCloudlet
)
rcl
.
getCloudlet
();
if
(
cl
.
currStagenum
==-
1
)
{
cl
.
currStagenum
=
0
;
}
double
estimatedFinishTime
=
currentTime
+
cl
.
stages
.
get
(
cl
.
currStagenum
).
time
;
//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
updatebuffered
(
double
time
)
{
// TODO Auto-generated method stub
NetworkCloudlet
cl
=(
NetworkCloudlet
)(
buffered
.
getCloudlet
());
if
(
cl
.
currStagenum
==
Constants
.
FINISH
){
System
.
out
.
println
(
cl
.
getCloudletId
()+
"Cloudlet is in finished: "
+
CloudSim
.
clock
());
cl
.
finishtime
=
CloudSim
.
clock
();
buffered
.
setCloudletStatus
(
Cloudlet
.
SUCCESS
);
buffered
.
finalizeCloudlet
();
getCloudletFinishedList
().
add
(
buffered
);
this
.
getCloudletWaitingList
().
remove
(
buffered
);
buffered
=
null
;
return
;
}
time
=
CloudSim
.
clock
()-
this
.
lastbufferUpdateTime
;
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
+=
time
;
//cl.timetostartStage=CloudSim.clock();
if
(
cl
.
timespentInStage
>=
st
.
time
)
{
changetonextstage
(
cl
,
st
);
//change the stage
}
}
}
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.
*
* @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
;
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/Constants.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
Constants
{
public
static
final
int
FFT
=
0
;
public
static
int
roundrobinRack
=
0
;
public
static
int
maxhostVM
=
2
;
public
static
int
HOST_PEs
=
8
;
public
static
double
maxMemperVM
=
1024
*
1024
;
//kb
public
static
final
int
BIN_NODE_TIME
=
10
;
public
static
int
currentCloudletId
=
0
;
public
static
int
currentAppId
=
0
;
public
static
final
int
EXECUTION
=
0
;
public
static
final
int
WAIT_SEND
=
1
;
public
static
final
int
WAIT_RECV
=
2
;
public
static
final
int
FINISH
=-
2
;
public
static
final
int
ROOT_LEVEL
=
0
;
public
static
final
int
Agg_LEVEL
=
1
;
public
static
final
int
EDGE_LEVEL
=
2
;
public
static
final
int
PES_NUMBER
=
4
;
public
static
final
int
FILE_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
boolean
BASE
=
true
;
public
static
long
BandWidthEdgeAgg
=
100
*
1024
*
1024
;
//100 Megabits
public
static
long
BandWidthEdgeHost
=
100
*
1024
*
1024
;
//
public
static
long
BandWidthAggRoot
=
20
*
1024
*
1024
*
2
;
//40gb
public
static
double
SwitchingDelayRoot
=.
002
85
;
public
static
double
SwitchingDelayAgg
=.
00245
;
//.00245
public
static
double
SwitchingDelayEdge
=.
00157
;
//ms
public
static
double
EdgeSwitchPort
=
4
;
//number of host
public
static
double
AggSwitchPort
=
1
;
//number of Edge
public
static
double
RootSwitchPort
=
1
;
//number of Agg
public
static
double
seed
=
199
;
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
nexttime
=
1000
;
public
static
int
totaldatatransfer
=
0
;
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/EdgeSwitch.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.core.SimEvent
;
import
org.cloudbus.cloudsim.core.predicates.PredicateType
;
public
class
EdgeSwitch
extends
Switch
{
public
EdgeSwitch
(
String
name
,
int
dcid
,
NetworkDatacenter
dc
)
{
super
(
name
,
dcid
,
dc
);
hostlist
=
new
HashMap
<
Integer
,
NetworkHost
>();
uplinkswitchpktlist
=
new
HashMap
<
Integer
,
List
<
HostPacket
>>();
packetTohost
=
new
HashMap
<
Integer
,
List
<
HostPacket
>>();
uplinkbandwidth
=
Constants
.
BandWidthEdgeAgg
;
downlinkbandwidth
=
Constants
.
BandWidthEdgeHost
;
this
.
switching_delay
=
Constants
.
SwitchingDelayEdge
;
numport
=
Constants
.
EdgeSwitchPort
;
uplinkswitches
=
new
ArrayList
<
Switch
>();
// TODO Auto-generated constructor stub
}
private
void
registerHost
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
NetworkHost
hs
=(
NetworkHost
)
ev
.
getData
();
hostlist
.
put
(
hs
.
getId
(),(
NetworkHost
)
ev
.
getData
());
}
private
void
processpacket_up
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//packet coming from down level router/host.
//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
);
// packet is recieved from host
//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
);
hspkt
.
recieverhostid
=
hostid
;
//packet needs to go to a host which is connected directly to switch
if
(
hs
!=
null
)
{
//packet to be sent to host connected to the switch
List
<
HostPacket
>
pktlist
=
this
.
packetTohost
.
get
(
hostid
);
if
(
pktlist
==
null
){
pktlist
=
new
ArrayList
<
HostPacket
>();
this
.
packetTohost
.
put
(
hostid
,
pktlist
);
}
pktlist
.
add
(
hspkt
);
return
;
}
//otherwise
//packet is to be sent to upper switch
//ASSUMPTION EACH EDGE is Connected to one aggregate level switch
//if there are more than one Aggregate level switch one need to modify following code
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
;
}
private
void
processpacketforward
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//search for the host and packets..send to them
if
(
this
.
uplinkswitchpktlist
!=
null
)
{
for
(
Entry
<
Integer
,
List
<
HostPacket
>>
es:
uplinkswitchpktlist
.
entrySet
())
{
int
tosend
=
es
.
getKey
();
List
<
HostPacket
>
hspktlist
=
es
.
getValue
();
if
(!
hspktlist
.
isEmpty
()){
//sharing bandwidth between packets
double
avband
=
this
.
uplinkbandwidth
/
hspktlist
.
size
();
Iterator
<
HostPacket
>
it
=
hspktlist
.
iterator
();
while
(
it
.
hasNext
())
{
HostPacket
hspkt
=
it
.
next
();
double
delay
=
1000
*
hspkt
.
pkt
.
data
/
avband
;
this
.
send
(
tosend
,
delay
,
CloudSimTags
.
Network_Event_UP
,
hspkt
);
}
hspktlist
.
clear
();
}
}
}
if
(
this
.
packetTohost
!=
null
)
{
for
(
Entry
<
Integer
,
List
<
HostPacket
>>
es:
packetTohost
.
entrySet
())
{
int
tosend
=
es
.
getKey
();
NetworkHost
hs
=
this
.
hostlist
.
get
(
tosend
);
List
<
HostPacket
>
hspktlist
=
es
.
getValue
();
if
(!
hspktlist
.
isEmpty
()){
double
avband
=
this
.
downlinkbandwidth
/
hspktlist
.
size
();
Iterator
<
HostPacket
>
it
=
hspktlist
.
iterator
();
while
(
it
.
hasNext
()){
HostPacket
hspkt
=
it
.
next
();
//hspkt.recieverhostid=tosend;
//hs.packetrecieved.add(hspkt);
this
.
send
(
this
.
getId
(),
hspkt
.
pkt
.
data
/
avband
,
CloudSimTags
.
Network_Event_Host
,
hspkt
);
}
hspktlist
.
clear
();
}
}
}
//or to switch at next level.
//clear the list
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/HostPacket.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
public
class
HostPacket
{
public
HostPacket
(
int
id
,
NetPacket
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
;
}
NetPacket
pkt
;
int
senderhostid
;
int
recieverhostid
;
int
sendervmid
;
int
recievervmid
;
int
cloudletid
;
double
stime
;
//time when sent
double
rtime
;
//time when received
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/MonteCarloApp.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.List
;
import
org.cloudbus.cloudsim.UtilizationModel
;
import
org.cloudbus.cloudsim.UtilizationModelFull
;
import
org.cloudbus.cloudsim.core.CloudSim
;
public
class
MonteCarloApp
extends
AppCloudlet
{
public
MonteCarloApp
(
int
type
,
int
appID
,
double
deadline
,
int
numbervm
,
int
userId
)
{
super
(
type
,
appID
,
deadline
,
numbervm
,
userId
);
this
.
numbervm
=
this
.
getnumvm
();
this
.
exeTime
=
getExecTime
()/
this
.
numbervm
;
}
@Override
public
void
createCloudletList
(
List
<
Integer
>
vmIdList
){
//basically, each task runs the simulation and then data is consolidated in one task
int
executionTime
=
getExecTime
();
long
memory
=
accuracyToMemory
();
long
fileSize
=
Constants
.
FILE_SIZE
;
long
outputSize
=
Constants
.
OUTPUT_SIZE
;
int
pesNumber
=
Constants
.
PES_NUMBER
;
int
stgId
=
0
;
int
t
=
Constants
.
currentCloudletId
;
for
(
int
i
=
0
;
i
<
numbervm
;
i
++){
UtilizationModel
utilizationModel
=
new
UtilizationModelFull
();
NetworkCloudlet
cl
=
new
NetworkCloudlet
(
Constants
.
currentCloudletId
,
executionTime
/
numbervm
,
pesNumber
,
fileSize
,
outputSize
,
memory
,
utilizationModel
,
utilizationModel
,
utilizationModel
);
Constants
.
currentCloudletId
++;
cl
.
setUserId
(
userId
);
cl
.
submittime
=
CloudSim
.
clock
();
cl
.
currStagenum
=-
1
;
cl
.
setVmId
(
vmIdList
.
get
(
i
));
//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
()));
//0 has an extra stage of waiting for results; others send
if
(
i
==
0
){
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
));
}
else
{
cl
.
stages
.
add
(
new
TaskStage
(
Constants
.
WAIT_SEND
,
Constants
.
COMMUNICATION_LENGTH
,
0
,
stgId
++,
memory
,
vmIdList
.
get
(
0
),
t
));
}
clist
.
add
(
cl
);
}
}
public
int
getnumvm
(){
double
exetime
=
getExecTime
()/
2
;
//for two vms
if
(
this
.
deadline
>
exetime
)
return
2
;
else
if
(
this
.
deadline
>(
exetime
/
4
))
return
4
;
return
4
;
}
private
int
getExecTime
()
{
//use exec constraints as Binomial
return
100
;
}
private
long
accuracyToMemory
()
{
//use same memory constraints as Binomial
return
240076
;
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/NetDatacenterBroker.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
/*
* 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
*/
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Random
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
java.util.UUID
;
import
org.cloudbus.cloudsim.Cloudlet
;
import
org.cloudbus.cloudsim.CloudletSchedulerSpaceShared
;
import
org.cloudbus.cloudsim.DatacenterCharacteristics
;
import
org.cloudbus.cloudsim.Log
;
import
org.cloudbus.cloudsim.Vm
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.core.SimEntity
;
import
org.cloudbus.cloudsim.core.SimEvent
;
import
org.cloudbus.cloudsim.distributions.UniformDistr
;
import
org.cloudbus.cloudsim.lists.CloudletList
;
import
org.cloudbus.cloudsim.lists.VmList
;
/**
* DatacentreBroker represents a broker
* acting on behalf of a user. It hides VM management,
* as vm creation, sumbission of cloudlets to this VMs
* and destruction of VMs.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public
class
NetDatacenterBroker
extends
SimEntity
{
// TODO: remove unnecessary variables
/** The vm list. */
private
List
<?
extends
Vm
>
vmList
;
/** The vms created list. */
private
List
<?
extends
Vm
>
vmsCreatedList
;
/** The cloudlet list. */
private
List
<?
extends
NetworkCloudlet
>
cloudletList
;
private
List
<?
extends
AppCloudlet
>
appCloudletList
;
/** The cloudlet submitted list. */
private
Map
<
Integer
,
Integer
>
appCloudletRecieved
;
private
List
<?
extends
Cloudlet
>
cloudletSubmittedList
;
/** The cloudlet received list. */
private
List
<?
extends
Cloudlet
>
cloudletReceivedList
;
/** The cloudlets submitted. */
private
int
cloudletsSubmitted
;
/** The vms requested. */
private
int
vmsRequested
;
/** The vms acks. */
private
int
vmsAcks
;
/** The vms destroyed. */
private
int
vmsDestroyed
;
/** The datacenter ids list. */
private
List
<
Integer
>
datacenterIdsList
;
/** The datacenter requested ids list. */
private
List
<
Integer
>
datacenterRequestedIdsList
;
/** The vms to datacenters map. */
private
Map
<
Integer
,
Integer
>
vmsToDatacentersMap
;
/** The datacenter characteristics list. */
private
Map
<
Integer
,
DatacenterCharacteristics
>
datacenterCharacteristicsList
;
public
static
NetworkDatacenter
linkDC
;
public
boolean
createvmflag
=
true
;
public
static
int
cachedcloudlet
=
0
;
/**
* Created a new DatacenterBroker object.
*
* @param name name to be associated with this entity (as
* required by Sim_entity class from simjava package)
*
* @throws Exception the exception
*
* @pre name != null
* @post $none
*/
public
NetDatacenterBroker
(
String
name
)
throws
Exception
{
super
(
name
);
setVmList
(
new
ArrayList
<
NetworkVm
>());
setVmsCreatedList
(
new
ArrayList
<
NetworkVm
>());
setCloudletList
(
new
ArrayList
<
NetworkCloudlet
>());
setAppCloudletList
(
new
ArrayList
<
AppCloudlet
>());
setCloudletSubmittedList
(
new
ArrayList
<
Cloudlet
>());
setCloudletReceivedList
(
new
ArrayList
<
Cloudlet
>());
this
.
appCloudletRecieved
=
new
HashMap
<
Integer
,
Integer
>();
cloudletsSubmitted
=
0
;
setVmsRequested
(
0
);
setVmsAcks
(
0
);
setVmsDestroyed
(
0
);
setDatacenterIdsList
(
new
LinkedList
<
Integer
>());
setDatacenterRequestedIdsList
(
new
ArrayList
<
Integer
>());
setVmsToDatacentersMap
(
new
HashMap
<
Integer
,
Integer
>());
setDatacenterCharacteristicsList
(
new
HashMap
<
Integer
,
DatacenterCharacteristics
>());
}
/**
* This method is used to send to the broker the list with
* virtual machines that must be created.
*
* @param list the list
*
* @pre list !=null
* @post $none
*/
public
void
submitVmList
(
List
<?
extends
Vm
>
list
)
{
getVmList
().
addAll
(
list
);
}
/**
* This method is used to send to the broker the list of
* cloudlets.
*
* @param list the list
*
* @pre list !=null
* @post $none
*/
public
void
submitCloudletList
(
List
<?
extends
NetworkCloudlet
>
list
){
getCloudletList
().
addAll
(
list
);
}
/**
* Specifies that a given cloudlet must run in a specific virtual machine.
*
* @param cloudletId ID of the cloudlet being bount to a vm
* @param vmId the vm id
*
* @pre cloudletId > 0
* @pre id > 0
* @post $none
*/
// public void bindCloudletToVm(int cloudletId, int vmId){
// CloudletList.getById(getCloudletList(), cloudletId).setVmId(vmId);
// }
public
void
setLinkDC
(
NetworkDatacenter
linkDC
)
{
this
.
linkDC
=
linkDC
;
}
/**
* Processes events available for this Broker.
*
* @param ev a SimEvent object
*
* @pre ev != null
* @post $none
*/
@Override
public
void
processEvent
(
SimEvent
ev
)
{
//Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag());
switch
(
ev
.
getTag
()){
// Resource characteristics request
case
CloudSimTags
.
RESOURCE_CHARACTERISTICS_REQUEST
:
processResourceCharacteristicsRequest
(
ev
);
break
;
// Resource characteristics answer
case
CloudSimTags
.
RESOURCE_CHARACTERISTICS
:
processResourceCharacteristics
(
ev
);
break
;
// VM Creation answer
//A finished cloudlet returned
case
CloudSimTags
.
CLOUDLET_RETURN
:
processCloudletReturn
(
ev
);
break
;
// if the simulation finishes
case
CloudSimTags
.
END_OF_SIMULATION
:
shutdownEntity
();
break
;
case
CloudSimTags
.
NextCycle
:
if
(
Constants
.
BASE
)
this
.
createVmsInDatacenterBase
(
this
.
linkDC
.
getId
());
break
;
// other unknown tags are processed by this method
default
:
processOtherEvent
(
ev
);
break
;
}
}
/**
* Process the return of a request for the characteristics of a PowerDatacenter.
*
* @param ev a SimEvent object
*
* @pre ev != $null
* @post $none
*/
protected
void
processResourceCharacteristics
(
SimEvent
ev
)
{
DatacenterCharacteristics
characteristics
=
(
DatacenterCharacteristics
)
ev
.
getData
();
getDatacenterCharacteristicsList
().
put
(
characteristics
.
getId
(),
characteristics
);
if
(
getDatacenterCharacteristicsList
().
size
()
==
getDatacenterIdsList
().
size
())
{
setDatacenterRequestedIdsList
(
new
ArrayList
<
Integer
>());
createVmsInDatacenterBase
(
getDatacenterIdsList
().
get
(
0
));
}
}
/**
* Process a request for the characteristics of a PowerDatacenter.
*
* @param ev a SimEvent object
*
* @pre ev != $null
* @post $none
*/
protected
void
processResourceCharacteristicsRequest
(
SimEvent
ev
)
{
setDatacenterIdsList
(
CloudSim
.
getCloudResourceList
());
setDatacenterCharacteristicsList
(
new
HashMap
<
Integer
,
DatacenterCharacteristics
>());
Log
.
printLine
(
CloudSim
.
clock
()+
": "
+
getName
()+
": Cloud Resource List received with "
+
getDatacenterIdsList
().
size
()+
" resource(s)"
);
for
(
Integer
datacenterId
:
getDatacenterIdsList
())
{
sendNow
(
datacenterId
,
CloudSimTags
.
RESOURCE_CHARACTERISTICS
,
getId
());
}
}
/**
* Process the ack received due to a request for VM creation.
*
* @param ev a SimEvent object
*
* @pre ev != null
* @post $none
*/
/**
* Process a cloudlet return event.
*
* @param ev a SimEvent object
*
* @pre ev != $null
* @post $none
*/
protected
void
processCloudletReturn
(
SimEvent
ev
)
{
Cloudlet
cloudlet
=
(
Cloudlet
)
ev
.
getData
();
getCloudletReceivedList
().
add
(
cloudlet
);
//Log.printLine(CloudSim.clock()+": "+getName()+ ": Cloudlet "+cloudlet.getCloudletId()+" received");
cloudletsSubmitted
--;
if
(
getCloudletList
().
size
()==
0
&&
cloudletsSubmitted
==
0
&&
Constants
.
iteration
>
10
)
{
//all cloudlets executed
Log
.
printLine
(
CloudSim
.
clock
()+
": "
+
getName
()+
": All Cloudlets executed. Finishing..."
);
clearDatacenters
();
finishExecution
();
}
else
{
//some cloudlets haven't finished yet
if
(
getAppCloudletList
().
size
()>
0
&&
cloudletsSubmitted
==
0
)
{
//all the cloudlets sent finished. It means that some bount
//cloudlet is waiting its VM be created
clearDatacenters
();
createVmsInDatacenterBase
(
0
);
}
}
}
/**
* Overrides this method when making a new and different type of Broker.
* This method is called by {@link #body()} for incoming unknown tags.
*
* @param ev a SimEvent object
*
* @pre ev != null
* @post $none
*/
protected
void
processOtherEvent
(
SimEvent
ev
){
if
(
ev
==
null
){
Log
.
printLine
(
getName
()
+
".processOtherEvent(): "
+
"Error - an event is null."
);
return
;
}
Log
.
printLine
(
getName
()
+
".processOtherEvent(): "
+
"Error - event unknown by this DatacenterBroker."
);
}
/**
* Create the virtual machines in a datacenter.
*
* @param datacenterId Id of the chosen PowerDatacenter
*
* @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
;
String
datacenterName
=
CloudSim
.
getEntityName
(
datacenterId
);
int
j
=
0
;
//All host will have two VMs (assumption) VM is the minimum unit
if
(
createvmflag
)
{
CreateVMs
(
datacenterId
);
createvmflag
=
false
;
}
//generate Request
//RequestGenerator reqgen=new RequestGenerator();
//OptionPricingRequest[] reqs=reqgen.getNextRequests(1);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
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
k
=
0
;
int
totalvm
=
this
.
vmsCreatedList
.
size
();
int
currentvmid
=
0
;
for
(
AppCloudlet
app:
this
.
getAppCloudletList
())
{
List
<
Integer
>
vmids
=
new
ArrayList
<
Integer
>();
int
numVms
=
this
.
linkDC
.
getVmList
().
size
();
UniformDistr
ufrnd
=
new
UniformDistr
(
0
,
numVms
,
5
);
for
(
int
i
=
0
;
i
<
app
.
numbervm
;
i
++)
{
// int vmid=currentvmid%numVms;//
int
vmid
=(
int
)
ufrnd
.
sample
();
currentvmid
++;
vmids
.
add
(
vmid
);
}
if
(
vmids
!=
null
){
if
(!
vmids
.
isEmpty
()){
app
.
createCloudletList
(
vmids
);
for
(
int
i
=
0
;
i
<
app
.
numbervm
;
i
++)
{
app
.
clist
.
get
(
i
).
setUserId
(
this
.
getId
());
//this.getCloudletList().add(app.clist.get(i));
this
.
appCloudletRecieved
.
put
(
app
.
appID
,
app
.
numbervm
);
this
.
getCloudletSubmittedList
().
add
(
app
.
clist
.
get
(
i
));
this
.
cloudletsSubmitted
++;
//Log.printLine(CloudSim.clock()+": "+getName()+ ": Sending cloudlet "+app.clist.get(i).getCloudletId()+" to VM #"+app.clist.get(i).getVmId());
sendNow
(
getVmsToDatacentersMap
().
get
(
this
.
getVmList
().
get
(
0
).
getId
()),
CloudSimTags
.
CLOUDLET_SUBMIT
,
app
.
clist
.
get
(
i
));
}
System
.
out
.
println
(
"app"
+(
k
++));
}
}
}
setAppCloudletList
(
new
ArrayList
<
AppCloudlet
>());
if
(
Constants
.
iteration
<
10
){
Constants
.
iteration
++;
this
.
schedule
(
this
.
getId
(),
Constants
.
nexttime
,
CloudSimTags
.
NextCycle
);
}
getDatacenterRequestedIdsList
().
add
(
datacenterId
);
setVmsRequested
(
requestedVms
);
setVmsAcks
(
0
);
}
private
void
CreateVMs
(
int
datacenterId
)
{
// TODO Auto-generated method stub
int
numVM
=
this
.
linkDC
.
getHostList
().
size
()*
Constants
.
maxhostVM
;
// two VMs per host
for
(
int
i
=
0
;
i
<
numVM
;
i
++)
{
int
requestedVms
=
0
;
int
vmid
=
i
;
int
mips
=
1
;
long
size
=
10000
;
// image size (MB)
int
ram
=
512
;
// vm memory (MB)
long
bw
=
1000
;
int
pesNumber
=
Constants
.
HOST_PEs
/
Constants
.
maxhostVM
;
// number of cpus
String
vmm
=
"Xen"
;
// VMM name
// create VM
NetworkVm
vm
=
new
NetworkVm
(
vmid
,
this
.
getId
(),
mips
,
pesNumber
,
ram
,
bw
,
size
,
vmm
,
new
CloudletHPCSpaceShared
());
this
.
linkDC
.
processVmCreateHPC
(
vm
);
// add the VM to the vmList
getVmList
().
add
(
vm
);
requestedVms
++;
getVmsToDatacentersMap
().
put
(
vmid
,
datacenterId
);
getVmsCreatedList
().
add
(
VmList
.
getById
(
getVmList
(),
vmid
));
}
}
/**
* Submit cloudlets to the created VMs.
*
* @pre $none
* @post $none
/**
* Destroy the virtual machines running in datacenters.
*
* @pre $none
* @post $none
*/
protected
void
clearDatacenters
()
{
for
(
Vm
vm
:
getVmsCreatedList
())
{
Log
.
printLine
(
CloudSim
.
clock
()
+
": "
+
getName
()
+
": Destroying VM #"
+
vm
.
getId
());
sendNow
(
getVmsToDatacentersMap
().
get
(
vm
.
getId
()),
CloudSimTags
.
VM_DESTROY
,
vm
);
}
getVmsCreatedList
().
clear
();
}
/**
* Send an internal event communicating the end of the simulation.
*
* @pre $none
* @post $none
*/
private
void
finishExecution
()
{
sendNow
(
getId
(),
CloudSimTags
.
END_OF_SIMULATION
);
}
/* (non-Javadoc)
* @see cloudsim.core.SimEntity#shutdownEntity()
*/
@Override
public
void
shutdownEntity
()
{
Log
.
printLine
(
getName
()
+
" is shutting down..."
);
}
/* (non-Javadoc)
* @see cloudsim.core.SimEntity#startEntity()
*/
@Override
public
void
startEntity
()
{
Log
.
printLine
(
getName
()
+
" is starting..."
);
schedule
(
getId
(),
0
,
CloudSimTags
.
RESOURCE_CHARACTERISTICS_REQUEST
);
}
/**
* Gets the vm list.
*
* @param <T> the generic type
* @return the vm list
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
Vm
>
List
<
T
>
getVmList
()
{
return
(
List
<
T
>)
vmList
;
}
/**
* Sets the vm list.
*
* @param <T> the generic type
* @param vmList the new vm list
*/
protected
<
T
extends
Vm
>
void
setVmList
(
List
<
T
>
vmList
)
{
this
.
vmList
=
vmList
;
}
/**
* Gets the cloudlet list.
*
* @param <T> the generic type
* @return the cloudlet list
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
NetworkCloudlet
>
List
<
T
>
getCloudletList
()
{
return
(
List
<
T
>)
cloudletList
;
}
/**
* Sets the cloudlet list.
*
* @param <T> the generic type
* @param cloudletList the new cloudlet list
*/
protected
<
T
extends
NetworkCloudlet
>
void
setCloudletList
(
List
<
T
>
cloudletList
)
{
this
.
cloudletList
=
cloudletList
;
}
public
<
T
extends
AppCloudlet
>
List
<
T
>
getAppCloudletList
()
{
return
(
List
<
T
>)
appCloudletList
;
}
public
<
T
extends
AppCloudlet
>
void
setAppCloudletList
(
List
<
T
>
appCloudletList
)
{
this
.
appCloudletList
=
appCloudletList
;
}
/**
* Gets the cloudlet submitted list.
*
* @param <T> the generic type
* @return the cloudlet submitted list
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
Cloudlet
>
List
<
T
>
getCloudletSubmittedList
()
{
return
(
List
<
T
>)
cloudletSubmittedList
;
}
/**
* Sets the cloudlet submitted list.
*
* @param <T> the generic type
* @param cloudletSubmittedList the new cloudlet submitted list
*/
protected
<
T
extends
Cloudlet
>
void
setCloudletSubmittedList
(
List
<
T
>
cloudletSubmittedList
)
{
this
.
cloudletSubmittedList
=
cloudletSubmittedList
;
}
/**
* Gets the cloudlet received list.
*
* @param <T> the generic type
* @return the cloudlet received list
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
Cloudlet
>
List
<
T
>
getCloudletReceivedList
()
{
return
(
List
<
T
>)
cloudletReceivedList
;
}
/**
* Sets the cloudlet received list.
*
* @param <T> the generic type
* @param cloudletReceivedList the new cloudlet received list
*/
protected
<
T
extends
Cloudlet
>
void
setCloudletReceivedList
(
List
<
T
>
cloudletReceivedList
)
{
this
.
cloudletReceivedList
=
cloudletReceivedList
;
}
/**
* Gets the vm list.
*
* @param <T> the generic type
* @return the vm list
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
Vm
>
List
<
T
>
getVmsCreatedList
()
{
return
(
List
<
T
>)
vmsCreatedList
;
}
/**
* Sets the vm list.
*
* @param <T> the generic type
* @param vmsCreatedList the vms created list
*/
protected
<
T
extends
Vm
>
void
setVmsCreatedList
(
List
<
T
>
vmsCreatedList
)
{
this
.
vmsCreatedList
=
vmsCreatedList
;
}
/**
* Gets the vms requested.
*
* @return the vms requested
*/
protected
int
getVmsRequested
()
{
return
vmsRequested
;
}
/**
* Sets the vms requested.
*
* @param vmsRequested the new vms requested
*/
protected
void
setVmsRequested
(
int
vmsRequested
)
{
this
.
vmsRequested
=
vmsRequested
;
}
/**
* Gets the vms acks.
*
* @return the vms acks
*/
protected
int
getVmsAcks
()
{
return
vmsAcks
;
}
/**
* Sets the vms acks.
*
* @param vmsAcks the new vms acks
*/
protected
void
setVmsAcks
(
int
vmsAcks
)
{
this
.
vmsAcks
=
vmsAcks
;
}
/**
* Increment vms acks.
*/
protected
void
incrementVmsAcks
()
{
this
.
vmsAcks
++;
}
/**
* Gets the vms destroyed.
*
* @return the vms destroyed
*/
protected
int
getVmsDestroyed
()
{
return
vmsDestroyed
;
}
/**
* Sets the vms destroyed.
*
* @param vmsDestroyed the new vms destroyed
*/
protected
void
setVmsDestroyed
(
int
vmsDestroyed
)
{
this
.
vmsDestroyed
=
vmsDestroyed
;
}
/**
* Gets the datacenter ids list.
*
* @return the datacenter ids list
*/
protected
List
<
Integer
>
getDatacenterIdsList
()
{
return
datacenterIdsList
;
}
/**
* Sets the datacenter ids list.
*
* @param datacenterIdsList the new datacenter ids list
*/
protected
void
setDatacenterIdsList
(
List
<
Integer
>
datacenterIdsList
)
{
this
.
datacenterIdsList
=
datacenterIdsList
;
}
/**
* Gets the vms to datacenters map.
*
* @return the vms to datacenters map
*/
protected
Map
<
Integer
,
Integer
>
getVmsToDatacentersMap
()
{
return
vmsToDatacentersMap
;
}
/**
* Sets the vms to datacenters map.
*
* @param vmsToDatacentersMap the vms to datacenters map
*/
protected
void
setVmsToDatacentersMap
(
Map
<
Integer
,
Integer
>
vmsToDatacentersMap
)
{
this
.
vmsToDatacentersMap
=
vmsToDatacentersMap
;
}
/**
* Gets the datacenter characteristics list.
*
* @return the datacenter characteristics list
*/
protected
Map
<
Integer
,
DatacenterCharacteristics
>
getDatacenterCharacteristicsList
()
{
return
datacenterCharacteristicsList
;
}
/**
* Sets the datacenter characteristics list.
*
* @param datacenterCharacteristicsList the datacenter characteristics list
*/
protected
void
setDatacenterCharacteristicsList
(
Map
<
Integer
,
DatacenterCharacteristics
>
datacenterCharacteristicsList
)
{
this
.
datacenterCharacteristicsList
=
datacenterCharacteristicsList
;
}
/**
* Gets the datacenter requested ids list.
*
* @return the datacenter requested ids list
*/
protected
List
<
Integer
>
getDatacenterRequestedIdsList
()
{
return
datacenterRequestedIdsList
;
}
/**
* Sets the datacenter requested ids list.
*
* @param datacenterRequestedIdsList the new datacenter requested ids list
*/
protected
void
setDatacenterRequestedIdsList
(
List
<
Integer
>
datacenterRequestedIdsList
)
{
this
.
datacenterRequestedIdsList
=
datacenterRequestedIdsList
;
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/NetPacket.java
0 → 100755
View file @
059beb41
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
;
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/NetworkCloudlet.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.Map
;
import
org.cloudbus.cloudsim.Cloudlet
;
import
org.cloudbus.cloudsim.UtilizationModel
;
public
class
NetworkCloudlet
extends
Cloudlet
implements
Comparable
{
long
memory
;
public
NetworkCloudlet
(
int
cloudletId
,
long
cloudletLength
,
int
pesNumber
,
long
cloudletFileSize
,
long
cloudletOutputSize
,
long
memory
,
UtilizationModel
utilizationModelCpu
,
UtilizationModel
utilizationModelRam
,
UtilizationModel
utilizationModelBw
)
{
super
(
cloudletId
,
cloudletLength
,
pesNumber
,
cloudletFileSize
,
cloudletOutputSize
,
utilizationModelCpu
,
utilizationModelRam
,
utilizationModelBw
);
// TODO Auto-generated constructor stub
currStagenum
=-
1
;
this
.
memory
=
memory
;
stages
=
new
ArrayList
<
TaskStage
>();
}
public
double
submittime
;
public
double
finishtime
;
public
double
exetime
;
public
double
numStage
;
public
int
currStagenum
;
public
double
timetostartStage
;
public
double
timespentInStage
;
public
Map
<
Double
,
NetPacket
>
timeCommunicate
;
public
ArrayList
<
TaskStage
>
stages
;
public
double
starttime
;
@Override
public
int
compareTo
(
Object
arg0
)
{
// TODO Auto-generated method stub
NetworkCloudlet
s1
=(
NetworkCloudlet
)
arg0
;
int
alpha
=
0
;
return
0
;
}
public
double
getSubmittime
()
{
// TODO Auto-generated method stub
return
submittime
;
};
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/NetworkDatacenter.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
/*
* 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
*/
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
org.cloudbus.cloudsim.Cloudlet
;
import
org.cloudbus.cloudsim.CloudletScheduler
;
import
org.cloudbus.cloudsim.DataCloudTags
;
import
org.cloudbus.cloudsim.Datacenter
;
import
org.cloudbus.cloudsim.DatacenterCharacteristics
;
import
org.cloudbus.cloudsim.File
;
import
org.cloudbus.cloudsim.Host
;
import
org.cloudbus.cloudsim.InfoPacket
;
import
org.cloudbus.cloudsim.Log
;
import
org.cloudbus.cloudsim.Storage
;
import
org.cloudbus.cloudsim.Vm
;
import
org.cloudbus.cloudsim.VmAllocationPolicy
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.core.SimEntity
;
import
org.cloudbus.cloudsim.core.SimEvent
;
/**
* Datacenter class is a CloudResource whose hostList
* are virtualized. It deals with processing of VM queries (i.e., handling
* of VMs) instead of processing Cloudlet-related queries. So, even though an
* AllocPolicy will be instantiated (in the init() method of the superclass,
* it will not be used, as processing of cloudlets are handled by the CloudletScheduler
* and processing of VirtualMachines are handled by the VmAllocationPolicy.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public
class
NetworkDatacenter
extends
Datacenter
{
public
NetworkDatacenter
(
String
name
,
DatacenterCharacteristics
characteristics
,
VmAllocationPolicy
vmAllocationPolicy
,
List
<
Storage
>
storageList
,
double
schedulingInterval
)
throws
Exception
{
super
(
name
,
characteristics
,
vmAllocationPolicy
,
storageList
,
schedulingInterval
);
// TODO Auto-generated constructor stub
VmToSwitchid
=
new
HashMap
<
Integer
,
Integer
>();
HostToSwitchid
=
new
HashMap
<
Integer
,
Integer
>();
VmtoHostlist
=
new
HashMap
<
Integer
,
Integer
>();
Switchlist
=
new
HashMap
<
Integer
,
Switch
>();
}
public
Map
<
Integer
,
Integer
>
VmToSwitchid
;
public
Map
<
Integer
,
Integer
>
HostToSwitchid
;
public
Map
<
Integer
,
Switch
>
Switchlist
;
public
Map
<
Integer
,
Integer
>
VmtoHostlist
;
public
Map
<
Integer
,
Switch
>
getEdgeSwitch
(){
Map
<
Integer
,
Switch
>
edgeswitch
=
new
HashMap
<
Integer
,
Switch
>();
for
(
Entry
<
Integer
,
Switch
>
es:
Switchlist
.
entrySet
()){
if
(
es
.
getValue
().
level
==
Constants
.
EDGE_LEVEL
)
{
edgeswitch
.
put
(
es
.
getKey
(),
es
.
getValue
());
}
}
return
edgeswitch
;
}
public
boolean
processVmCreateHPC
(
Vm
vm
)
{
boolean
result
=
getVmAllocationPolicy
().
allocateHostForVm
(
vm
);
if
(
result
)
{
this
.
VmToSwitchid
.
put
(
vm
.
getId
(),
((
NetworkHost
)
vm
.
getHost
()).
sw
.
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
;
if
(
getDebts
().
containsKey
(
vm
.
getUserId
()))
{
amount
=
getDebts
().
get
(
vm
.
getUserId
());
}
amount
+=
getCharacteristics
().
getCostPerMem
()
*
vm
.
getRam
();
amount
+=
getCharacteristics
().
getCostPerStorage
()
*
vm
.
getSize
();
getDebts
().
put
(
vm
.
getUserId
(),
amount
);
getVmList
().
add
(
vm
);
vm
.
updateVmProcessing
(
CloudSim
.
clock
(),
getVmAllocationPolicy
().
getHost
(
vm
).
getVmScheduler
().
getAllocatedMipsForVm
(
vm
));
}
return
result
;
}
protected
void
processCloudletSubmit
(
SimEvent
ev
,
boolean
ack
)
{
updateCloudletProcessing
();
try
{
// gets the Cloudlet object
Cloudlet
cl
=
(
Cloudlet
)
ev
.
getData
();
// checks whether this Cloudlet has finished or not
if
(
cl
.
isFinished
()){
String
name
=
CloudSim
.
getEntityName
(
cl
.
getUserId
());
Log
.
printLine
(
getName
()+
": Warning - Cloudlet #"
+
cl
.
getCloudletId
()+
" owned by "
+
name
+
" is already completed/finished."
);
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.
// If ack is not required, this method don't send back a result.
// Hence, this might cause CloudSim to be hanged since waiting
// for this Cloudlet back.
if
(
ack
)
{
int
[]
data
=
new
int
[
3
];
data
[
0
]
=
getId
();
data
[
1
]
=
cl
.
getCloudletId
();
data
[
2
]
=
CloudSimTags
.
FALSE
;
// unique tag = operation tag
int
tag
=
CloudSimTags
.
CLOUDLET_SUBMIT_ACK
;
sendNow
(
cl
.
getUserId
(),
tag
,
data
);
}
sendNow
(
cl
.
getUserId
(),
CloudSimTags
.
CLOUDLET_RETURN
,
cl
);
return
;
}
// process this Cloudlet to this CloudResource
cl
.
setResourceParameter
(
getId
(),
getCharacteristics
().
getCostPerSecond
(),
getCharacteristics
().
getCostPerBw
());
int
userId
=
cl
.
getUserId
();
int
vmId
=
cl
.
getVmId
();
double
fileTransferTime
=
predictFileTransferTime
(
cl
.
getRequiredFiles
());
//time to transfer the files
Host
host
=
getVmAllocationPolicy
().
getHost
(
vmId
,
userId
);
Vm
vm
=
host
.
getVm
(
vmId
,
userId
);
CloudletScheduler
scheduler
=
vm
.
getCloudletScheduler
();
//System.out.println("cloudlet recieved by VM"+vmId);
double
estimatedFinishTime
=
scheduler
.
cloudletSubmit
(
cl
,
fileTransferTime
);
//if (estimatedFinishTime > 0.0 && estimatedFinishTime < getSchedulingInterval()) { //if this cloudlet is in the exec queue
if
(
estimatedFinishTime
>
0.0
)
{
//if this cloudlet is in the exec queue
//double estimatedFinishTime = (cl.getCloudletTotalLength()/(capacity*cl.getPesNumber())); //time to process the cloudlet
//Log.printLine(estimatedFinishTime+"="+gl.getCloudletLength()+"/("+capacity+"*"+gl.getNumPE()+")");
estimatedFinishTime
+=
fileTransferTime
;
//estimatedFinishTime += CloudSim.clock();
//Log.printLine(CloudSim.clock()+": Next event scheduled to +"+estimatedFinishTime);
send
(
getId
(),
estimatedFinishTime
,
CloudSimTags
.
VM_DATACENTER_EVENT
);
//event to update the stages
send
(
getId
(),
0.0001
,
CloudSimTags
.
VM_DATACENTER_EVENT
);
}
if
(
ack
)
{
int
[]
data
=
new
int
[
3
];
data
[
0
]
=
getId
();
data
[
1
]
=
cl
.
getCloudletId
();
data
[
2
]
=
CloudSimTags
.
TRUE
;
// unique tag = operation tag
int
tag
=
CloudSimTags
.
CLOUDLET_SUBMIT_ACK
;
sendNow
(
cl
.
getUserId
(),
tag
,
data
);
}
}
catch
(
ClassCastException
c
)
{
Log
.
printLine
(
getName
()
+
".processCloudletSubmit(): "
+
"ClassCastException error."
);
c
.
printStackTrace
();
}
catch
(
Exception
e
)
{
Log
.
printLine
(
getName
()
+
".processCloudletSubmit(): "
+
"Exception error."
);
e
.
printStackTrace
();
}
checkCloudletCompletion
();
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/NetworkHost.java
0 → 100755
View file @
059beb41
/*
* 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
*/
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
org.cloudbus.cloudsim.Datacenter
;
import
org.cloudbus.cloudsim.Host
;
import
org.cloudbus.cloudsim.Log
;
import
org.cloudbus.cloudsim.Pe
;
import
org.cloudbus.cloudsim.Vm
;
import
org.cloudbus.cloudsim.VmScheduler
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.lists.PeList
;
import
org.cloudbus.cloudsim.lists.VmList
;
import
org.cloudbus.cloudsim.provisioners.BwProvisioner
;
import
org.cloudbus.cloudsim.provisioners.RamProvisioner
;
/**
* Host class extends a Machine to include other hostList beside PEs
* to support simulation of virtualized grids. It executes actions related
* to management of virtual machines (e.g., creation and destruction). A host has
* a defined policy for provisioning memory and bw, as well as an allocation policy
* for Pe's to virtual machines.
*
* A host is associated to a datacenter. It can host virtual machines.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public
class
NetworkHost
extends
Host
{
public
List
<
HostPacket
>
packetTosendLocal
;
public
List
<
HostPacket
>
packetTosendGlobal
;
public
List
<
HostPacket
>
packetrecieved
;
public
double
memory
;
public
Switch
sw
;
public
double
bandwidth
;
//latency
public
List
<
Double
>
CPUfinTimeCPU
=
new
ArrayList
<
Double
>();
//time when last job will finish on CPU1
public
double
fintime
=
0
;
public
NetworkHost
(
int
id
,
RamProvisioner
ramProvisioner
,
BwProvisioner
bwProvisioner
,
long
storage
,
List
<?
extends
Pe
>
peList
,
VmScheduler
vmScheduler
)
{
super
(
id
,
ramProvisioner
,
bwProvisioner
,
storage
,
peList
,
vmScheduler
);
// TODO Auto-generated constructor stub
this
.
packetrecieved
=
new
ArrayList
<
HostPacket
>();
this
.
packetTosendGlobal
=
new
ArrayList
<
HostPacket
>();
this
.
packetTosendLocal
=
new
ArrayList
<
HostPacket
>();
}
/**
* Requests updating of processing of cloudlets in the VMs running in this host.
*
* @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
*
* @pre currentTime >= 0.0
* @post $none
*/
public
double
updateVmsProcessing
(
double
currentTime
)
{
double
smallerTime
=
Double
.
MAX_VALUE
;
//insert in each vm packet recieved
recvpackets
();
for
(
Vm
vm
:
super
.
getVmList
())
{
// if (vm.isInMigration()) {
// continue;
// }
double
time
=
((
NetworkVm
)
vm
).
updateVmProcessing
(
currentTime
,
getVmScheduler
().
getAllocatedMipsForVm
(
vm
));
if
(
time
>
0.0
&&
time
<
smallerTime
)
{
smallerTime
=
time
;
}
}
sendpackets
();
return
smallerTime
;
}
private
void
recvpackets
()
{
// TODO Auto-generated method stub
for
(
HostPacket
hs:
packetrecieved
)
{
//hs.stime=hs.rtime;
hs
.
pkt
.
recievetime
=
CloudSim
.
clock
();
//insertthe packet in recievedlist
Vm
vm
=
VmList
.
getById
(
getVmList
(),
hs
.
pkt
.
reciever
);
List
<
NetPacket
>
pktlist
=((
CloudletHPCSpaceShared
)
vm
.
getCloudletScheduler
()).
pktrecv
.
get
(
hs
.
pkt
.
sender
);
//List<NetPacket> pktlist=((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pktrecv.get(hs.pkt.virtualsendid);
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
);
}
packetrecieved
.
clear
();
}
private
void
sendpackets
()
{
// TODO Auto-generated method stub
for
(
Vm
vm:
super
.
getVmList
())
{
for
(
Entry
<
Integer
,
List
<
NetPacket
>>
es:
((
CloudletHPCSpaceShared
)
vm
.
getCloudletScheduler
()).
pkttosend
.
entrySet
())
//for(Entry<Integer, List<NetPacket>> es:((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pkttosend.entrySet())
{
List
<
NetPacket
>
pktlist
=
es
.
getValue
();
for
(
NetPacket
pkt:
pktlist
)
{
HostPacket
hpkt
=
new
HostPacket
(
this
.
getId
(),
pkt
,
vm
.
getId
(),
pkt
.
sender
);
Vm
vm2
=
VmList
.
getById
(
this
.
getVmList
(),
hpkt
.
recievervmid
);
if
(
vm2
!=
null
)
this
.
packetTosendLocal
.
add
(
hpkt
);
else
this
.
packetTosendGlobal
.
add
(
hpkt
);
}
pktlist
.
clear
();
}
}
boolean
flag
=
false
;
for
(
HostPacket
hs:
packetTosendLocal
)
{
flag
=
true
;
hs
.
stime
=
hs
.
rtime
;
hs
.
pkt
.
recievetime
=
CloudSim
.
clock
();
//insertthe packet in recievedlist
Vm
vm
=
VmList
.
getById
(
getVmList
(),
hs
.
pkt
.
reciever
);
//Vm vm=getVmList().get(hs.pkt.reciever);
List
<
NetPacket
>
pktlist
=((
CloudletHPCSpaceShared
)
vm
.
getCloudletScheduler
()).
pktrecv
.
get
(
hs
.
pkt
.
sender
);
//List<NetPacket> pktlist=((CloudletHPCSpaceSharedO)vm.getCloudletScheduler()).pktrecv.get(hs.pkt.virtualsendid);
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
);
}
if
(
flag
){
for
(
Vm
vm
:
super
.
getVmList
())
{
// if (vm.isInMigration()) {
// continue;
// }
double
time
=
((
NetworkVm
)
vm
).
updateVmProcessing
(
CloudSim
.
clock
(),
getVmScheduler
().
getAllocatedMipsForVm
(
vm
));
}
}
this
.
packetTosendLocal
.
clear
();
double
avband
=
this
.
bandwidth
/
packetTosendGlobal
.
size
();
for
(
HostPacket
hs:
packetTosendGlobal
)
{
double
delay
=(
1000
*
hs
.
pkt
.
data
)/
avband
;
Constants
.
totaldatatransfer
+=
hs
.
pkt
.
data
;
//System.out.println(hs.pkt.virtualsendid+" "+hs.pkt.virtualrecvid+" "+hs.pkt.data);
CloudSim
.
send
(
this
.
getDatacenter
().
getId
(),
this
.
sw
.
getId
(),
delay
,
CloudSimTags
.
Network_Event_UP
,
hs
);
//send to switch with delay
}
this
.
packetTosendGlobal
.
clear
();
}
@SuppressWarnings
(
"unchecked"
)
public
double
getMaxUtilizationAmongVmsPes
(
Vm
vm
)
{
return
PeList
.
getMaxUtilizationAmongVmsPes
((
List
<
Pe
>)
getPeList
(),
vm
);
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/NetworkVm.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.cloudbus.cloudsim.CloudletScheduler
;
import
org.cloudbus.cloudsim.Vm
;
public
class
NetworkVm
extends
Vm
implements
Comparable
{
public
NetworkVm
(
int
id
,
int
userId
,
double
mips
,
int
pesNumber
,
int
ram
,
long
bw
,
long
size
,
String
vmm
,
CloudletScheduler
cloudletScheduler
)
{
super
(
id
,
userId
,
mips
,
pesNumber
,
ram
,
bw
,
size
,
vmm
,
cloudletScheduler
);
// TODO Auto-generated constructor stub
cloudletlist
=
new
ArrayList
<
NetworkCloudlet
>();
}
public
ArrayList
<
NetworkCloudlet
>
cloudletlist
;
int
type
;
public
ArrayList
<
NetPacket
>
recvPktlist
;
public
double
memory
;
public
boolean
flagfree
;
//if true it is free
public
double
finishtime
;
public
boolean
isFree
()
{
return
flagfree
;
}
public
int
compareTo
(
Object
arg0
)
{
NetworkVm
hs
=(
NetworkVm
)
arg0
;
if
(
hs
.
finishtime
>
this
.
finishtime
)
return
-
1
;
if
(
hs
.
finishtime
<
this
.
finishtime
)
return
1
;
return
0
;
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/RootSwitch.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.core.SimEvent
;
import
org.cloudbus.cloudsim.core.predicates.PredicateType
;
public
class
RootSwitch
extends
Switch
{
public
RootSwitch
(
String
name
,
int
level
,
NetworkDatacenter
dc
)
{
super
(
name
,
level
,
dc
);
downlinkswitchpktlist
=
new
HashMap
<
Integer
,
List
<
HostPacket
>>();
downlinkswitches
=
new
ArrayList
<
Switch
>();
downlinkbandwidth
=
Constants
.
BandWidthAggRoot
;
latency
=
Constants
.
SwitchingDelayRoot
;
numport
=
Constants
.
RootSwitchPort
;
// TODO Auto-generated constructor stub
}
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
.
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
);
}
}
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/Switch.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.SortedMap
;
import
java.util.SortedSet
;
import
java.util.TreeMap
;
import
java.util.Map.Entry
;
import
java.util.TreeSet
;
import
org.cloudbus.cloudsim.Log
;
import
org.cloudbus.cloudsim.Vm
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.core.CloudSimTags
;
import
org.cloudbus.cloudsim.core.SimEntity
;
import
org.cloudbus.cloudsim.core.SimEvent
;
import
org.cloudbus.cloudsim.core.predicates.PredicateType
;
import
org.cloudbus.cloudsim.lists.VmList
;
public
class
Switch
extends
SimEntity
{
//switch level
public
int
id
;
public
int
level
;
//three levels
public
int
datacenterid
;
public
Map
<
Integer
,
List
<
HostPacket
>>
uplinkswitchpktlist
;
public
Map
<
Integer
,
List
<
HostPacket
>>
downlinkswitchpktlist
;
public
Map
<
Integer
,
NetworkHost
>
hostlist
;
public
List
<
Switch
>
uplinkswitches
;
public
List
<
Switch
>
downlinkswitches
;
public
Map
<
Integer
,
List
<
HostPacket
>>
packetTohost
;
int
type
;
//edge switch or aggregation switch
public
double
uplinkbandwidth
;
public
double
downlinkbandwidth
;
public
double
latency
;
public
double
numport
;
public
NetworkDatacenter
dc
;
public
SortedMap
<
Double
,
List
<
NetworkHost
>>
fintimelistHost
=
new
TreeMap
<
Double
,
List
<
NetworkHost
>>();
//something is running on these hosts
public
SortedMap
<
Double
,
List
<
NetworkVm
>>
fintimelistVM
=
new
TreeMap
<
Double
,
List
<
NetworkVm
>>();
//something is running on these hosts
public
ArrayList
<
HostPacket
>
pktlist
;
public
List
<
Vm
>
BagofTaskVm
=
new
ArrayList
<
Vm
>();
public
double
switching_delay
;
public
Map
<
Integer
,
NetworkVm
>
Vmlist
;
public
Switch
(
String
name
,
int
level
,
NetworkDatacenter
dc
)
{
super
(
name
);
this
.
level
=
level
;
/* if(level==Constants.EDGE_LEVEL)
{
hostlist=new HashMap<Integer,HPCHost>();
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
packetTohost=new HashMap<Integer,List<HostPacket>>();
uplinkbandwidth=Constants.BandWidthEdgeAgg;
downlinkbandwidth=Constants.BandWidthEdgeHost;
latency=Constants.SwitchingDelayEdge;
numport=Constants.EdgeSwitchPort;
uplinkswitches=new ArrayList<Switch>();
}
if(level==Constants.Agg_LEVEL)
{
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>();
}
if(level==Constants.ROOT_LEVEL)
{
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
downlinkswitches=new ArrayList<Switch>();
downlinkbandwidth=Constants.BandWidthAggRoot;
latency=Constants.SwitchingDelayRoot;
numport=Constants.RootSwitchPort;
}*/
this
.
dc
=
dc
;
// TODO Auto-generated constructor stub
}
@Override
public
void
startEntity
()
{
Log
.
printLine
(
getName
()
+
" is starting..."
);
schedule
(
getId
(),
0
,
CloudSimTags
.
RESOURCE_CHARACTERISTICS_REQUEST
);
}
@Override
public
void
processEvent
(
SimEvent
ev
)
{
//Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag());
switch
(
ev
.
getTag
()){
// Resource characteristics request
case
CloudSimTags
.
Network_Event_UP
:
//process the packet from down switch or host
processpacket_up
(
ev
);
break
;
case
CloudSimTags
.
Network_Event_DOWN
:
//process the packet from uplink
processpacket_down
(
ev
);
break
;
case
CloudSimTags
.
Network_Event_send
:
processpacketforward
(
ev
);
break
;
case
CloudSimTags
.
Network_Event_Host
:
processhostpacket
(
ev
);
break
;
// Resource characteristics answer
case
CloudSimTags
.
RESOURCE_Register
:
registerHost
(
ev
);
break
;
// other unknown tags are processed by this method
default
:
processOtherEvent
(
ev
);
break
;
}
}
private
void
processhostpacket
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//Send packet to host
HostPacket
hspkt
=(
HostPacket
)
ev
.
getData
();
NetworkHost
hs
=
this
.
hostlist
.
get
(
hspkt
.
recieverhostid
);
hs
.
packetrecieved
.
add
(
hspkt
);
}
private
void
processpacket_down
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//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
//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
.
EDGE_LEVEL
)
{
// packet is to be recieved by host
int
hostid
=
dc
.
VmtoHostlist
.
get
(
recvVMid
);
hspkt
.
recieverhostid
=
hostid
;
List
<
HostPacket
>
pktlist
=
this
.
packetTohost
.
get
(
hostid
);
if
(
pktlist
==
null
){
pktlist
=
new
ArrayList
<
HostPacket
>();
this
.
packetTohost
.
put
(
hostid
,
pktlist
);
}
pktlist
.
add
(
hspkt
);
return
;
}
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
;
}
}
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
.
EDGE_LEVEL
)
{
// packet is recieved from host
//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
);
hspkt
.
recieverhostid
=
hostid
;
if
(
hs
!=
null
)
{
//packet to be sent to host connected to the switch
List
<
HostPacket
>
pktlist
=
this
.
packetTohost
.
get
(
hostid
);
if
(
pktlist
==
null
){
pktlist
=
new
ArrayList
<
HostPacket
>();
this
.
packetTohost
.
put
(
hostid
,
pktlist
);
}
pktlist
.
add
(
hspkt
);
return
;
}
//packet is to be sent to upper 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
);
}
}
}
private
void
registerHost
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
NetworkHost
hs
=(
NetworkHost
)
ev
.
getData
();
hostlist
.
put
(
hs
.
getId
(),(
NetworkHost
)
ev
.
getData
());
}
private
void
processpacket
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//send packet to itself with switching delay (discarding other)
CloudSim
.
cancelAll
(
getId
(),
new
PredicateType
(
CloudSimTags
.
Network_Event_UP
));
schedule
(
getId
(),
this
.
switching_delay
,
CloudSimTags
.
Network_Event_UP
);
pktlist
.
add
((
HostPacket
)
ev
.
getData
());
//add the packet in the list
}
private
void
processOtherEvent
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
}
private
void
processpacketforward
(
SimEvent
ev
)
{
// TODO Auto-generated method stub
//search for the host and packets..send to them
if
(
this
.
downlinkswitchpktlist
!=
null
)
{
for
(
Entry
<
Integer
,
List
<
HostPacket
>>
es:
downlinkswitchpktlist
.
entrySet
())
{
int
tosend
=
es
.
getKey
();
List
<
HostPacket
>
hspktlist
=
es
.
getValue
();
if
(!
hspktlist
.
isEmpty
()){
double
avband
=
this
.
downlinkbandwidth
/
hspktlist
.
size
();
Iterator
<
HostPacket
>
it
=
hspktlist
.
iterator
();
while
(
it
.
hasNext
()){
HostPacket
hspkt
=
it
.
next
();
double
delay
=
1000
*
hspkt
.
pkt
.
data
/
avband
;
this
.
send
(
tosend
,
delay
,
CloudSimTags
.
Network_Event_DOWN
,
hspkt
);
}
hspktlist
.
clear
();
}
}
}
if
(
this
.
uplinkswitchpktlist
!=
null
)
{
for
(
Entry
<
Integer
,
List
<
HostPacket
>>
es:
uplinkswitchpktlist
.
entrySet
())
{
int
tosend
=
es
.
getKey
();
List
<
HostPacket
>
hspktlist
=
es
.
getValue
();
if
(!
hspktlist
.
isEmpty
()){
double
avband
=
this
.
uplinkbandwidth
/
hspktlist
.
size
();
Iterator
<
HostPacket
>
it
=
hspktlist
.
iterator
();
while
(
it
.
hasNext
())
{
HostPacket
hspkt
=
it
.
next
();
double
delay
=
1000
*
hspkt
.
pkt
.
data
/
avband
;
this
.
send
(
tosend
,
delay
,
CloudSimTags
.
Network_Event_UP
,
hspkt
);
}
hspktlist
.
clear
();
}
}
}
if
(
this
.
packetTohost
!=
null
)
{
for
(
Entry
<
Integer
,
List
<
HostPacket
>>
es:
packetTohost
.
entrySet
())
{
int
tosend
=
es
.
getKey
();
NetworkHost
hs
=
this
.
hostlist
.
get
(
tosend
);
List
<
HostPacket
>
hspktlist
=
es
.
getValue
();
if
(!
hspktlist
.
isEmpty
()){
double
avband
=
this
.
downlinkbandwidth
/
hspktlist
.
size
();
Iterator
<
HostPacket
>
it
=
hspktlist
.
iterator
();
while
(
it
.
hasNext
()){
HostPacket
hspkt
=
it
.
next
();
//hspkt.recieverhostid=tosend;
//hs.packetrecieved.add(hspkt);
this
.
send
(
this
.
getId
(),
hspkt
.
pkt
.
data
/
avband
,
CloudSimTags
.
Network_Event_Host
,
hspkt
);
}
hspktlist
.
clear
();
}
}
}
//or to switch at next level.
//clear the list
}
private
NetworkHost
getHostwithVM
(
int
vmid
)
{
// TODO Auto-generated method stub
for
(
Entry
<
Integer
,
NetworkHost
>
es:
this
.
hostlist
.
entrySet
())
{
Vm
vm
=
VmList
.
getById
(
es
.
getValue
().
getVmList
(),
vmid
);
if
(
vm
!=
null
)
return
es
.
getValue
();
}
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
)
{
// TODO Auto-generated method stub
List
<
NetworkVm
>
freehostls
=
new
ArrayList
<
NetworkVm
>();
for
(
Entry
<
Integer
,
NetworkVm
>
et:
this
.
Vmlist
.
entrySet
())
{
if
(
et
.
getValue
().
isFree
())
{
freehostls
.
add
(
et
.
getValue
());
}
if
(
freehostls
.
size
()==
numVMReq
)
break
;
}
return
freehostls
;
}
private
List
<
NetworkHost
>
getfreehostlist
(
int
numhost
)
{
// TODO Auto-generated method stub
List
<
NetworkHost
>
freehostls
=
new
ArrayList
<
NetworkHost
>();
for
(
Entry
<
Integer
,
NetworkHost
>
et:
this
.
hostlist
.
entrySet
())
{
if
(
et
.
getValue
().
getFreePesNumber
()==
et
.
getValue
().
getPesNumber
())
{
freehostls
.
add
(
et
.
getValue
());
}
if
(
freehostls
.
size
()==
numhost
)
break
;
}
return
freehostls
;
}
@Override
public
void
shutdownEntity
()
{
Log
.
printLine
(
getName
()
+
" is shutting down..."
);
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/TaskStage.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
public
class
TaskStage
{
public
TaskStage
(
int
type
,
double
data
,
double
time
,
double
stageid
,
long
memory
,
int
peer
,
int
vpeer
)
{
super
();
this
.
type
=
type
;
this
.
data
=
data
;
this
.
time
=
time
;
this
.
stageid
=
stageid
;
this
.
memory
=
memory
;
this
.
peer
=
peer
;
this
.
vpeer
=
vpeer
;
}
int
vpeer
;
int
type
;
//execution, recv, send,
double
data
;
//data generated or send or recv
double
time
;
//execution time for this stage
double
stageid
;
long
memory
;
int
peer
;
//from whom data needed to be recieved or send
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/VmHPCAllocationPolicySimple.java
0 → 100755
View file @
059beb41
/*
* 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
*/
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.cloudbus.cloudsim.Host
;
import
org.cloudbus.cloudsim.Log
;
import
org.cloudbus.cloudsim.Vm
;
import
org.cloudbus.cloudsim.VmAllocationPolicy
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.power.PowerHost
;
/**
* VmAllocationPolicySimple is an VmAllocationPolicy that
* chooses, as the host for a VM, the host with
* less PEs in use.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public
class
VmHPCAllocationPolicySimple
extends
VmAllocationPolicy
{
/** The vm table. */
private
Map
<
String
,
Host
>
vmTable
;
/** The used pes. */
private
Map
<
String
,
Integer
>
usedPes
;
/** The free pes. */
private
List
<
Integer
>
freePes
;
/**
* Creates the new VmAllocationPolicySimple object.
*
* @param list the list
*
* @pre $none
* @post $none
*/
public
VmHPCAllocationPolicySimple
(
List
<?
extends
Host
>
list
)
{
super
(
list
);
setFreePes
(
new
ArrayList
<
Integer
>());
for
(
Host
host
:
getHostList
())
{
getFreePes
().
add
(
host
.
getPesNumber
());
}
setVmTable
(
new
HashMap
<
String
,
Host
>());
setUsedPes
(
new
HashMap
<
String
,
Integer
>());
}
/**
* Allocates a host for a given VM.
*
* @param vm VM specification
*
* @return $true if the host could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public
boolean
allocateHostForVm
(
Vm
vm
)
{
NetworkHost
allocatedHost
=
findHostForVm
(
vm
);
if
(
allocatedHost
!=
null
&&
allocatedHost
.
vmCreate
(
vm
))
{
//if vm has been succesfully created in the host
getVmTable
().
put
(
vm
.
getUid
(),
allocatedHost
);
if
(!
Log
.
isDisabled
())
{
Log
.
print
(
String
.
format
(
"%.2f: VM #"
+
vm
.
getId
()
+
" has been allocated to the host #"
+
allocatedHost
.
getId
()
+
"\n"
,
CloudSim
.
clock
()));
}
return
true
;
}
return
false
;
}
public
NetworkHost
findHostForVm
(
Vm
vm
)
{
double
minPower
=
Double
.
MAX_VALUE
;
NetworkHost
allocatedHost
=
null
;
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
allocatedHost
;
}
protected
double
getMaxUtilizationAfterAllocation
(
NetworkHost
host
,
Vm
vm
)
{
List
<
Double
>
allocatedMipsForVm
=
null
;
NetworkHost
allocatedHost
=
(
NetworkHost
)
vm
.
getHost
();
if
(
allocatedHost
!=
null
)
{
allocatedMipsForVm
=
vm
.
getHost
().
getAllocatedMipsForVm
(
vm
);
}
if
(!
host
.
allocatePesForVm
(
vm
,
vm
.
getCurrentRequestedMips
()))
{
return
-
1
;
}
double
maxUtilization
=
host
.
getMaxUtilizationAmongVmsPes
(
vm
);
host
.
deallocatePesForVm
(
vm
);
if
(
allocatedHost
!=
null
&&
allocatedMipsForVm
!=
null
)
{
vm
.
getHost
().
allocatePesForVm
(
vm
,
allocatedMipsForVm
);
}
return
maxUtilization
;
}
/**
* Releases the host used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
@Override
public
void
deallocateHostForVm
(
Vm
vm
)
{
Host
host
=
getVmTable
().
remove
(
vm
.
getUid
());
int
idx
=
getHostList
().
indexOf
(
host
);
int
pes
=
getUsedPes
().
remove
(
vm
.
getUid
());
if
(
host
!=
null
)
{
host
.
vmDestroy
(
vm
);
getFreePes
().
set
(
idx
,
getFreePes
().
get
(
idx
)
+
pes
);
}
}
/**
* Gets the host that is executing the given VM belonging to the
* given user.
*
* @param vm the vm
*
* @return the Host with the given vmID and userID; $null if not found
*
* @pre $none
* @post $none
*/
@Override
public
Host
getHost
(
Vm
vm
)
{
return
getVmTable
().
get
(
vm
.
getUid
());
}
/**
* Gets the host that is executing the given VM belonging to the
* given user.
*
* @param vmId the vm id
* @param userId the user id
*
* @return the Host with the given vmID and userID; $null if not found
*
* @pre $none
* @post $none
*/
@Override
public
Host
getHost
(
int
vmId
,
int
userId
)
{
return
getVmTable
().
get
(
Vm
.
getUid
(
userId
,
vmId
));
}
/**
* Gets the vm table.
*
* @return the vm table
*/
public
Map
<
String
,
Host
>
getVmTable
()
{
return
vmTable
;
}
/**
* Sets the vm table.
*
* @param vmTable the vm table
*/
protected
void
setVmTable
(
Map
<
String
,
Host
>
vmTable
)
{
this
.
vmTable
=
vmTable
;
}
/**
* Gets the used pes.
*
* @return the used pes
*/
protected
Map
<
String
,
Integer
>
getUsedPes
()
{
return
usedPes
;
}
/**
* Sets the used pes.
*
* @param usedPes the used pes
*/
protected
void
setUsedPes
(
Map
<
String
,
Integer
>
usedPes
)
{
this
.
usedPes
=
usedPes
;
}
/**
* Gets the free pes.
*
* @return the free pes
*/
protected
List
<
Integer
>
getFreePes
()
{
return
freePes
;
}
/**
* Sets the free pes.
*
* @param freePes the new free pes
*/
protected
void
setFreePes
(
List
<
Integer
>
freePes
)
{
this
.
freePes
=
freePes
;
}
/* (non-Javadoc)
* @see cloudsim.VmAllocationPolicy#optimizeAllocation(double, cloudsim.VmList, double)
*/
@Override
public
List
<
Map
<
String
,
Object
>>
optimizeAllocation
(
List
<?
extends
Vm
>
vmList
)
{
// TODO Auto-generated method stub
return
null
;
}
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm, org.cloudbus.cloudsim.Host)
*/
@Override
public
boolean
allocateHostForVm
(
Vm
vm
,
Host
host
)
{
if
(
host
.
vmCreate
(
vm
))
{
//if vm has been succesfully created in the host
getVmTable
().
put
(
vm
.
getUid
(),
host
);
Log
.
formatLine
(
"%.2f: VM #"
+
vm
.
getId
()
+
" has been allocated to the host #"
+
host
.
getId
(),
CloudSim
.
clock
());
return
true
;
}
return
false
;
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/WorkflowApp.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.util.List
;
import
org.cloudbus.cloudsim.UtilizationModel
;
import
org.cloudbus.cloudsim.UtilizationModelFull
;
import
org.cloudbus.cloudsim.core.CloudSim
;
public
class
WorkflowApp
extends
AppCloudlet
{
public
WorkflowApp
(
int
type
,
int
appID
,
double
deadline
,
int
numbervm
,
int
userId
)
{
super
(
type
,
appID
,
deadline
,
numbervm
,
userId
);
// TODO Auto-generated constructor stub
this
.
exeTime
=
100
;
this
.
numbervm
=
3
;
}
public
void
createCloudletList
(
List
<
Integer
>
vmIdList
){
long
fileSize
=
Constants
.
FILE_SIZE
;
long
outputSize
=
Constants
.
OUTPUT_SIZE
;
int
pesNumber
=
Constants
.
PES_NUMBER
;
int
memory
=
100
;
UtilizationModel
utilizationModel
=
new
UtilizationModelFull
();
int
i
=
0
;
//Task A
NetworkCloudlet
cl
=
new
NetworkCloudlet
(
Constants
.
currentCloudletId
,
0
,
1
,
fileSize
,
outputSize
,
memory
,
utilizationModel
,
utilizationModel
,
utilizationModel
);
cl
.
numStage
=
2
;
Constants
.
currentCloudletId
++;
cl
.
setUserId
(
userId
);
cl
.
submittime
=
CloudSim
.
clock
();
cl
.
currStagenum
=-
1
;
cl
.
setVmId
(
vmIdList
.
get
(
i
));
//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
(
Constants
.
WAIT_SEND
,
1000
,
0
,
1
,
memory
,
vmIdList
.
get
(
2
),
cl
.
getCloudletId
()+
2
));
clist
.
add
(
cl
);
i
++;
//Task B
NetworkCloudlet
clb
=
new
NetworkCloudlet
(
Constants
.
currentCloudletId
,
0
,
1
,
fileSize
,
outputSize
,
memory
,
utilizationModel
,
utilizationModel
,
utilizationModel
);
clb
.
numStage
=
2
;
Constants
.
currentCloudletId
++;
clb
.
setUserId
(
userId
);
clb
.
submittime
=
CloudSim
.
clock
();
clb
.
currStagenum
=-
1
;
clb
.
setVmId
(
vmIdList
.
get
(
i
));
//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
(
Constants
.
WAIT_SEND
,
1000
,
0
,
1
,
memory
,
vmIdList
.
get
(
2
),
clb
.
getCloudletId
()+
1
));
clist
.
add
(
clb
);
i
++;
//Task C
NetworkCloudlet
clc
=
new
NetworkCloudlet
(
Constants
.
currentCloudletId
,
0
,
1
,
fileSize
,
outputSize
,
memory
,
utilizationModel
,
utilizationModel
,
utilizationModel
);
clc
.
numStage
=
2
;
Constants
.
currentCloudletId
++;
clc
.
setUserId
(
userId
);
clc
.
submittime
=
CloudSim
.
clock
();
clc
.
currStagenum
=-
1
;
clc
.
setVmId
(
vmIdList
.
get
(
i
));
//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
(
Constants
.
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
()));
clist
.
add
(
clc
);
}
}
modules/cloudsim/src/main/java/org/cloudbus/cloudsim/network/datacenter/testMainclass.java
0 → 100755
View file @
059beb41
package
org
.
cloudbus
.
cloudsim
.
network
.
datacenter
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.cloudbus.cloudsim.Cloudlet
;
import
org.cloudbus.cloudsim.CloudletSchedulerSpaceShared
;
import
org.cloudbus.cloudsim.DatacenterCharacteristics
;
import
org.cloudbus.cloudsim.Host
;
import
org.cloudbus.cloudsim.Log
;
import
org.cloudbus.cloudsim.Pe
;
import
org.cloudbus.cloudsim.Storage
;
import
org.cloudbus.cloudsim.UtilizationModel
;
import
org.cloudbus.cloudsim.UtilizationModelFull
;
import
org.cloudbus.cloudsim.Vm
;
import
org.cloudbus.cloudsim.VmAllocationPolicySimple
;
import
org.cloudbus.cloudsim.VmSchedulerTimeShared
;
import
org.cloudbus.cloudsim.core.CloudSim
;
import
org.cloudbus.cloudsim.distributions.UniformDistr
;
import
org.cloudbus.cloudsim.provisioners.BwProvisionerSimple
;
import
org.cloudbus.cloudsim.provisioners.PeProvisionerSimple
;
import
org.cloudbus.cloudsim.provisioners.RamProvisionerSimple
;
public
class
testMainclass
{
/**
* @param args
*/
/** The cloudlet list. */
private
static
List
<
AppCloudlet
>
cloudletList
;
/** The vmlist. */
private
static
List
<
NetworkVm
>
vmlist
;
/**
* Creates main() to run this example.
*
* @param args the args
*/
public
static
void
main
(
String
[]
args
)
{
Log
.
printLine
(
"Starting CloudSimExample1..."
);
try
{
int
num_user
=
1
;
// number of cloud users
Calendar
calendar
=
Calendar
.
getInstance
();
boolean
trace_flag
=
false
;
// mean trace events
// 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
// list one of them to run a CloudSim simulation
NetworkDatacenter
datacenter0
=
createDatacenter
(
"Datacenter_0"
);
// Third step: Create Broker
NetDatacenterBroker
broker
=
createBroker
();
int
brokerId
=
broker
.
getId
();
broker
.
setLinkDC
(
datacenter0
);
//broker.setLinkDC(datacenter0);
// Fifth step: Create one Cloudlet
cloudletList
=
new
ArrayList
<
AppCloudlet
>();
vmlist
=
new
ArrayList
<
NetworkVm
>();
// submit vm list to the broker
broker
.
submitVmList
(
vmlist
);
// Sixth step: Starts the simulation
CloudSim
.
startSimulation
();
CloudSim
.
stopSimulation
();
//Final step: Print results when simulation is over
List
<
Cloudlet
>
newList
=
broker
.
getCloudletReceivedList
();
printCloudletList
(
newList
);
System
.
out
.
println
(
"numberofcloudlet "
+
newList
.
size
()+
" Cached "
+
NetDatacenterBroker
.
cachedcloudlet
+
" Data transfered "
+
Constants
.
totaldatatransfer
);
// Print the debt of each user to each datacenter
datacenter0
.
printDebts
();
Log
.
printLine
(
"CloudSimExample1 finished!"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
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:
// 1. We need to create a list to store
// our machine
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
<
Constants
.
EdgeSwitchPort
*
Constants
.
AggSwitchPort
*
Constants
.
RootSwitchPort
;
i
++)
{
// 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core.
// 3. Create PEs and add these into an object of PowerPeList.
List
<
Pe
>
peList
=
new
ArrayList
<
Pe
>();
peList
.
add
(
new
Pe
(
0
,
new
PeProvisionerSimple
(
mips
)));
// need to store PowerPe id and MIPS Rating
peList
.
add
(
new
Pe
(
1
,
new
PeProvisionerSimple
(
mips
)));
// need to store PowerPe id and MIPS 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 store PowerPe id and MIPS Rating
peList
.
add
(
new
Pe
(
4
,
new
PeProvisionerSimple
(
mips
)));
// need to store PowerPe id and MIPS Rating
peList
.
add
(
new
Pe
(
5
,
new
PeProvisionerSimple
(
mips
)));
// need to store PowerPe id and MIPS Rating
peList
.
add
(
new
Pe
(
6
,
new
PeProvisionerSimple
(
mips
)));
// need to store PowerPe id and MIPS Rating
peList
.
add
(
new
Pe
(
7
,
new
PeProvisionerSimple
(
mips
)));
// need to store PowerPe id and MIPS Rating
// 4. Create PowerHost with its id and list of PEs and add them to the list of machines
hostList
.
add
(
new
NetworkHost
(
i
,
new
RamProvisionerSimple
(
ram
),
new
BwProvisionerSimple
(
bw
),
storage
,
peList
,
new
VmSchedulerTimeShared
(
peList
)
)
);
// This is our machine
}
// 5. Create a DatacenterCharacteristics object that stores the
// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time zone
// and its price (G$/Pe time unit).
String
arch
=
"x86"
;
// system architecture
String
os
=
"Linux"
;
// operating system
String
vmm
=
"Xen"
;
double
time_zone
=
10.0
;
// time zone this resource located
double
cost
=
3.0
;
// the cost of using processing in this resource
double
costPerMem
=
0.05
;
// the cost of using memory in this resource
double
costPerStorage
=
0.001
;
// the cost of using storage in this
// resource
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
// submit vms and cloudlets according
// to the specific rules of the simulated scenario
/**
* Creates the broker.
*
* @return the datacenter broker
*/
private
static
NetDatacenterBroker
createBroker
()
{
NetDatacenterBroker
broker
=
null
;
try
{
broker
=
new
NetDatacenterBroker
(
"Broker"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
broker
;
}
/**
* Prints the Cloudlet objects.
*
* @param list list of Cloudlets
* @throws IOException
*/
private
static
void
printCloudletList
(
List
<
Cloudlet
>
list
)
throws
IOException
{
int
size
=
list
.
size
();
Cloudlet
cloudlet
;
double
fintime
=
0
;
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
)
{
// //Root Switch
// Switch swroot=new Switch("Root", Constants.ROOT_LEVEL, dc);
// dc.Switchlist.put(swroot.getId(), swroot);
// //Agg Switch
// 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].uplinkswitches.add(swroot);
// dc.Switchlist.put(aggswitch[j].getId(), aggswitch[j]);
// }
//Edge Switch
EdgeSwitch
edgeswitch
[]=
new
EdgeSwitch
[
1
];
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
edgeswitch
[
i
]=
new
EdgeSwitch
(
"Edge"
+
i
,
Constants
.
EDGE_LEVEL
,
dc
);
//edgeswitch[i].uplinkswitches.add(null);
dc
.
Switchlist
.
put
(
edgeswitch
[
i
].
getId
(),
edgeswitch
[
i
]);
//aggswitch[(int) (i/Constants.AggSwitchPort)].downlinkswitches.add(edgeswitch[i]);
}
for
(
Host
hs:
dc
.
getHostList
())
{
NetworkHost
hs1
=(
NetworkHost
)
hs
;
hs1
.
bandwidth
=
Constants
.
BandWidthEdgeHost
;
int
switchnum
=(
int
)
(
hs
.
getId
()/
Constants
.
EdgeSwitchPort
);
edgeswitch
[
switchnum
].
hostlist
.
put
(
hs
.
getId
(),
hs1
);
dc
.
HostToSwitchid
.
put
(
hs
.
getId
(),
edgeswitch
[
switchnum
].
getId
());
hs1
.
sw
=
edgeswitch
[
switchnum
];
List
<
NetworkHost
>
hslist
=
hs1
.
sw
.
fintimelistHost
.
get
(
0
D
);
if
(
hslist
==
null
)
{
hslist
=
new
ArrayList
<
NetworkHost
>();
hs1
.
sw
.
fintimelistHost
.
put
(
0
D
,
hslist
);
}
hslist
.
add
(
hs1
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment