Documentation Added with Some updates on Code.

parent ecd0ad0b
...@@ -9,99 +9,131 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -9,99 +9,131 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
public class AggregateSwitch extends Switch{ /**
* This class allows to simulate aggregate switch for Datacenter network.
* It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM International
* Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA),
* Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*
*/
public class AggregateSwitch extends Switch {
/**
* Constructor for Aggregate Switch
* We have to specify switches that are connected to its downlink and uplink ports,
* and corresponding bandwidths
*
* @param name Name of the switch
* @param level At which level switch is with respect to hosts.
* @param dc Pointer to Datacenter
*/
public AggregateSwitch(String name, int level, NetworkDatacenter dc) { public AggregateSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc); super(name, level, dc);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
uplinkbandwidth=Constants.BandWidthAggRoot;
downlinkbandwidth=Constants.BandWidthEdgeAgg;
latency=Constants.SwitchingDelayAgg;
numport=Constants.AggSwitchPort;
uplinkswitches=new ArrayList<Switch>();
downlinkswitches=new ArrayList<Switch>();
}
downlinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
private void processpacket_down(SimEvent ev) { uplinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
// TODO Auto-generated method stub uplinkbandwidth = NetworkConstants.BandWidthAggRoot;
//packet coming from up level router. downlinkbandwidth = NetworkConstants.BandWidthEdgeAgg;
//has to send downward latency = NetworkConstants.SwitchingDelayAgg;
//check which switch to forward to numport = NetworkConstants.AggSwitchPort;
//add packet in the switch list uplinkswitches = new ArrayList<Switch>();
//add packet in the host list downlinkswitches = new ArrayList<Switch>();
//int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.latency, CloudSimTags.Network_Event_send);
if(this.level==Constants.Agg_LEVEL)
{
//packet is coming from root so need to be sent to edgelevel swich
//find the id for edgelevel switch
int switchid=dc.VmToSwitchid.get(recvVMid);
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(switchid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
return;
}
} }
/**
* Send Packet to switch connected through a downlink port
*
* @param ev Event/packet to process
*/
@Override
protected void processpacket_down(SimEvent ev) {
// packet coming from up level router.
// has to send downward
// check which switch to forward to
// add packet in the switch list
// add packet in the host list
NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(
CloudSimTags.Network_Event_send));
schedule(getId(), this.latency, CloudSimTags.Network_Event_send);
if (this.level == NetworkConstants.Agg_LEVEL) {
// packet is coming from root so need to be sent to edgelevel swich
// find the id for edgelevel switch
int switchid = dc.VmToSwitchid.get(recvVMid);
List<NetworkPacket> pktlist = this.downlinkswitchpktlist.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
return;
}
private void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub
//packet coming from down level router.
//has to send up
//check which switch to forward to
//add packet in the switch list
//
//int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send);
if(this.level==Constants.Agg_LEVEL)
{
//packet is coming from edge level router so need to be sent to either root or another edge level swich
//find the id for edgelevel switch
int switchid=dc.VmToSwitchid.get(recvVMid);
boolean flagtoswtich=false;
for(Switch sw:this.downlinkswitches)
{
if(switchid==sw.getId()) flagtoswtich=true;
}
if(flagtoswtich)
{
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(switchid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
}
else//send to up
{
Switch sw=this.uplinkswitches.get(0);
List<HostPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
} }
/**
* Send Packet to switch connected through a uplink port
*
* @param ev Event/packet to process
*/
@Override
protected void processpacket_up(SimEvent ev) {
// packet coming from down level router.
// has to send up
// check which switch to forward to
// add packet in the switch list
//
// int src=ev.getSource();
NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(
CloudSimTags.Network_Event_send));
schedule(getId(), this.switching_delay, CloudSimTags.Network_Event_send);
if (this.level == NetworkConstants.Agg_LEVEL) {
// packet is coming from edge level router so need to be sent to
// either root or another edge level swich
// find the id for edgelevel switch
int switchid = dc.VmToSwitchid.get(recvVMid);
boolean flagtoswtich = false;
for (Switch sw : this.downlinkswitches) {
if (switchid == sw.getId())
flagtoswtich = true;
}
if (flagtoswtich) {
List<NetworkPacket> pktlist = this.downlinkswitchpktlist
.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
} else// send to up
{
Switch sw = this.uplinkswitches.get(0);
List<NetworkPacket> pktlist = this.uplinkswitchpktlist.get(sw
.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
}
} }
...@@ -7,59 +7,72 @@ import org.cloudbus.cloudsim.UtilizationModel; ...@@ -7,59 +7,72 @@ import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull; import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
/**
* AppCloudlet class represents an application which user submit for execution within datacenter.
* It consist of several networkClouds.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class AppCloudlet { public class AppCloudlet {
public static final int APP_MC = 1; public static final int APP_MC = 1;
public static final int APP_Workflow = 3; public static final int APP_Workflow = 3;
public AppCloudlet(int type, int appID,
double deadline, int numbervm, int userId) { public AppCloudlet(int type, int appID, double deadline, int numbervm,
int userId) {
super(); super();
this.type = type; this.type = type;
this.appID = appID; this.appID = appID;
this.deadline = deadline; this.deadline = deadline;
this.numbervm = numbervm; this.numbervm = numbervm;
this.userId = userId; this.userId = userId;
clist=new ArrayList<NetworkCloudlet>(); clist = new ArrayList<NetworkCloudlet>();
} }
public int type; //fft,fem
public int appID; public int type;
public ArrayList<NetworkCloudlet> clist; public int appID;
public double deadline; public ArrayList<NetworkCloudlet> clist;
public double accuracy; public double deadline;
public int numbervm; public double accuracy;
public int userId; public int numbervm;
public int userId;
public double exeTime; public double exeTime;
public int requestclass; public int requestclass;
/**
public void createCloudletList(List<Integer> vmIdList) * An example of creating APPcloudlet
{ * @param vmIdList VMs where Cloudlet will be executed
for(int i=0;i<numbervm;i++){ */
long length = 4; public void createCloudletList(List<Integer> vmIdList) {
long fileSize = 300; for (int i = 0; i < numbervm; i++) {
long outputSize = 300; long length = 4;
long memory = 256; long fileSize = 300;
int pesNumber = 4; long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull(); long memory = 256;
//HPCCloudlet cl=new HPCCloudlet(); int pesNumber = 4;
NetworkCloudlet cl = new NetworkCloudlet(Constants.currentCloudletId, length, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); UtilizationModel utilizationModel = new UtilizationModelFull();
// HPCCloudlet cl=new HPCCloudlet();
NetworkCloudlet cl = new NetworkCloudlet(
NetworkConstants.currentCloudletId, length, pesNumber, fileSize,
outputSize, memory, utilizationModel, utilizationModel,
utilizationModel);
// setting the owner of these Cloudlets // setting the owner of these Cloudlets
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
cl.setUserId(userId); cl.setUserId(userId);
cl.submittime=CloudSim.clock(); cl.submittime = CloudSim.clock();
// TaskStage ts=new TaskStage(Constants.EXECUTION, 0, length, 0,memory, (i+1)%numbervm); cl.currStagenum = -1;
// TaskStage ts1=new TaskStage(Constants.WAIT_SEND, 100, 0, 0, memory, (i+1)%numbervm); clist.add(cl);
// TaskStage ts2=new TaskStage(Constants.WAIT_RECV, 100, 0, 0, memory, (i+1)%numbervm);
// TaskStage ts3=new TaskStage(Constants.EXECUTION, 0, length, 0, memory, (i+1)%numbervm); }
// cl.stages.add(ts); // based on type
// cl.stages.add(ts1);
// cl.stages.add(ts2); }
// cl.stages.add(ts3);
// cl.submittime=CloudSim.clock();
cl.currStagenum=-1;
clist.add(cl);
}
//based on type
}
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* BagofTaskApp is an example of AppCloudlet having three noncommunicating tasks.
*
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull; import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
public class MonteCarloApp extends AppCloudlet { public class BagofTaskApp extends AppCloudlet {
public MonteCarloApp(int type, int appID, double deadline, int numbervm, int userId) { public BagofTaskApp(int type, int appID, double deadline, int numbervm, int userId) {
super(type, appID, deadline, numbervm,userId); super(type, appID, deadline, numbervm,userId);
this.numbervm=this.getnumvm(); this.numbervm=this.getnumvm();
...@@ -19,34 +35,39 @@ public class MonteCarloApp extends AppCloudlet { ...@@ -19,34 +35,39 @@ public class MonteCarloApp extends AppCloudlet {
public void createCloudletList(List<Integer> vmIdList){ public void createCloudletList(List<Integer> vmIdList){
//basically, each task runs the simulation and then data is consolidated in one task //basically, each task runs the simulation and then data is consolidated in one task
int executionTime = getExecTime(); int executionTime = getExecTime();
long memory = accuracyToMemory(); long memory = 1000;
long fileSize = Constants.FILE_SIZE; long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = Constants.OUTPUT_SIZE; long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = Constants.PES_NUMBER; int pesNumber = NetworkConstants.PES_NUMBER;
int stgId=0; int stgId=0;
int t=Constants.currentCloudletId; int t=NetworkConstants.currentCloudletId;
for(int i=0;i<numbervm;i++){ for(int i=0;i<numbervm;i++){
UtilizationModel utilizationModel = new UtilizationModelFull(); UtilizationModel utilizationModel = new UtilizationModelFull();
NetworkCloudlet cl = new NetworkCloudlet(Constants.currentCloudletId, executionTime/numbervm, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, executionTime/numbervm, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
cl.setUserId(userId); cl.setUserId(userId);
cl.submittime=CloudSim.clock(); cl.submittime=CloudSim.clock();
cl.currStagenum=-1; cl.currStagenum=-1;
cl.setVmId(vmIdList.get(i)); cl.setVmId(vmIdList.get(i));
//compute and send data to node 0 //compute and send data to node 0
cl.stages.add(new TaskStage(Constants.EXECUTION, Constants.COMMUNICATION_LENGTH, executionTime/numbervm, stgId++, memory, vmIdList.get(0),cl.getCloudletId())); cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, NetworkConstants.COMMUNICATION_LENGTH, executionTime/numbervm, stgId++, memory, vmIdList.get(0),cl.getCloudletId()));
//0 has an extra stage of waiting for results; others send //0 has an extra stage of waiting for results; others send
if (i==0){ if (i==0){
for(int j=1;j<numbervm;j++) for(int j=1;j<numbervm;j++)
cl.stages.add(new TaskStage(Constants.WAIT_RECV, Constants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(j),cl.getCloudletId()+j)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, NetworkConstants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(j),cl.getCloudletId()+j));
} else { } else {
cl.stages.add(new TaskStage(Constants.WAIT_SEND, Constants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(0),t)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, NetworkConstants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(0),t));
} }
clist.add(cl); clist.add(cl);
} }
} }
/**
* One can generate number of VMs for each application based on deadline
* @return
*/
public int getnumvm(){ public int getnumvm(){
double exetime=getExecTime()/2;//for two vms double exetime=getExecTime()/2;//for two vms
if(this.deadline>exetime) if(this.deadline>exetime)
...@@ -57,14 +78,10 @@ public class MonteCarloApp extends AppCloudlet { ...@@ -57,14 +78,10 @@ public class MonteCarloApp extends AppCloudlet {
} }
private int getExecTime() { private int getExecTime() {
//use exec constraints as Binomial //use exec constraints
return 100; return 100;
} }
private long accuracyToMemory() {
//use same memory constraints as Binomial
return 240076;
}
} }
...@@ -11,26 +11,53 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -11,26 +11,53 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* This class allows to simulate Edge switch for Datacenter network.
* It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM International
* Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA),
* Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*
*/
public class EdgeSwitch extends Switch{ public class EdgeSwitch extends Switch{
public EdgeSwitch(String name, int dcid, NetworkDatacenter dc) { /**
super(name, dcid, dc); * Constructor for Edge Switch
* We have to specify switches that are connected to its downlink and uplink ports,
* and corresponding bandwidths. In this switch downlink ports are
* connected to hosts not to a switch.
*
* @param name Name of the switch
* @param level At which level switch is with respect to hosts.
* @param dc Pointer to Datacenter
*/
public EdgeSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc);
hostlist=new HashMap<Integer,NetworkHost>(); hostlist=new HashMap<Integer,NetworkHost>();
uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); uplinkswitchpktlist=new HashMap<Integer,List<NetworkPacket>>();
packetTohost=new HashMap<Integer,List<HostPacket>>(); packetTohost=new HashMap<Integer,List<NetworkPacket>>();
uplinkbandwidth=Constants.BandWidthEdgeAgg; uplinkbandwidth=NetworkConstants.BandWidthEdgeAgg;
downlinkbandwidth=Constants.BandWidthEdgeHost; downlinkbandwidth=NetworkConstants.BandWidthEdgeHost;
this.switching_delay=Constants.SwitchingDelayEdge; this.switching_delay=NetworkConstants.SwitchingDelayEdge;
numport=Constants.EdgeSwitchPort; numport=NetworkConstants.EdgeSwitchPort;
uplinkswitches=new ArrayList<Switch>(); uplinkswitches=new ArrayList<Switch>();
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
private void registerHost(SimEvent ev) { /**
// TODO Auto-generated method stub * Send Packet to switch connected through a uplink port
NetworkHost hs=(NetworkHost)ev.getData(); *
hostlist.put(hs.getId(),(NetworkHost)ev.getData()); * @param ev Event/packet to process
} */
private void processpacket_up(SimEvent ev) { @Override
protected void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//packet coming from down level router/host. //packet coming from down level router/host.
//has to send up //has to send up
...@@ -38,7 +65,7 @@ public class EdgeSwitch extends Switch{ ...@@ -38,7 +65,7 @@ public class EdgeSwitch extends Switch{
//add packet in the switch list //add packet in the switch list
// //
//int src=ev.getSource(); //int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt=(NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send); schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send);
...@@ -54,9 +81,9 @@ public class EdgeSwitch extends Switch{ ...@@ -54,9 +81,9 @@ public class EdgeSwitch extends Switch{
if(hs!=null) if(hs!=null)
{ {
//packet to be sent to host connected to the switch //packet to be sent to host connected to the switch
List<HostPacket> pktlist=this.packetTohost.get(hostid); List<NetworkPacket> pktlist=this.packetTohost.get(hostid);
if(pktlist==null){ if(pktlist==null){
pktlist=new ArrayList<HostPacket>(); pktlist=new ArrayList<NetworkPacket>();
this.packetTohost.put(hostid, pktlist); this.packetTohost.put(hostid, pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
...@@ -69,9 +96,9 @@ public class EdgeSwitch extends Switch{ ...@@ -69,9 +96,9 @@ public class EdgeSwitch extends Switch{
//if there are more than one Aggregate level switch one need to modify following code //if there are more than one Aggregate level switch one need to modify following code
Switch sw=this.uplinkswitches.get(0); Switch sw=this.uplinkswitches.get(0);
List<HostPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId()); List<NetworkPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){ if(pktlist==null){
pktlist=new ArrayList<HostPacket>(); pktlist=new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist); this.uplinkswitchpktlist.put(sw.getId(), pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
...@@ -79,24 +106,31 @@ public class EdgeSwitch extends Switch{ ...@@ -79,24 +106,31 @@ public class EdgeSwitch extends Switch{
} }
private void processpacketforward(SimEvent ev) { /**
* Send Packet to hosts connected to the switch
*
* @param ev Event/packet to process
*/
@Override
protected void processpacketforward(SimEvent ev) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//search for the host and packets..send to them //search for the host and packets..send to them
if(this.uplinkswitchpktlist!=null) if(this.uplinkswitchpktlist!=null)
{ {
for(Entry<Integer, List<HostPacket>> es:uplinkswitchpktlist.entrySet()) for(Entry<Integer, List<NetworkPacket>> es:uplinkswitchpktlist.entrySet())
{ {
int tosend=es.getKey(); int tosend=es.getKey();
List<HostPacket> hspktlist=es.getValue(); List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){ if(!hspktlist.isEmpty()){
//sharing bandwidth between packets //sharing bandwidth between packets
double avband=this.uplinkbandwidth/hspktlist.size(); double avband=this.uplinkbandwidth/hspktlist.size();
Iterator<HostPacket> it=hspktlist.iterator(); Iterator<NetworkPacket> it=hspktlist.iterator();
while(it.hasNext()) while(it.hasNext())
{ {
HostPacket hspkt=it.next(); NetworkPacket hspkt=it.next();
double delay=1000*hspkt.pkt.data/avband; double delay=1000*hspkt.pkt.data/avband;
this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt); this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt);
...@@ -107,16 +141,16 @@ public class EdgeSwitch extends Switch{ ...@@ -107,16 +141,16 @@ public class EdgeSwitch extends Switch{
} }
if(this.packetTohost!=null) if(this.packetTohost!=null)
{ {
for(Entry<Integer, List<HostPacket>> es:packetTohost.entrySet()) for(Entry<Integer, List<NetworkPacket>> es:packetTohost.entrySet())
{ {
int tosend=es.getKey(); int tosend=es.getKey();
NetworkHost hs=this.hostlist.get(tosend); NetworkHost hs=this.hostlist.get(tosend);
List<HostPacket> hspktlist=es.getValue(); List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){ if(!hspktlist.isEmpty()){
double avband=this.downlinkbandwidth/hspktlist.size(); double avband=this.downlinkbandwidth/hspktlist.size();
Iterator<HostPacket> it=hspktlist.iterator(); Iterator<NetworkPacket> it=hspktlist.iterator();
while(it.hasNext()){ while(it.hasNext()){
HostPacket hspkt=it.next(); NetworkPacket hspkt=it.next();
//hspkt.recieverhostid=tosend; //hspkt.recieverhostid=tosend;
//hs.packetrecieved.add(hspkt); //hs.packetrecieved.add(hspkt);
this.send(this.getId(),hspkt.pkt.data/avband,CloudSimTags.Network_Event_Host, hspkt); this.send(this.getId(),hspkt.pkt.data/avband,CloudSimTags.Network_Event_Host, hspkt);
......
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* HostPacket represents the packet that travels through the virtual network with a Host.
* It contains information about cloudlets which are communicating
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class HostPacket { public class HostPacket {
public HostPacket(int id, NetPacket pkt2, int vmid, int cloudletid) { public HostPacket(int sender, int reciever, double data, double sendtime,
// TODO Auto-generated constructor stub double recievetime, int vsnd, int vrvd) {
this.pkt=pkt2; super();
this.sendervmid=vmid; this.sender = sender;
this.cloudletid=cloudletid; this.reciever = reciever;
this.senderhostid=id; this.data = data;
this.stime=pkt.sendtime; this.sendtime = sendtime;
this.recievervmid=pkt2.reciever; this.recievetime = recievetime;
this.virtualrecvid = vrvd;
this.virtualsendid = vsnd;
} }
NetPacket pkt;
int senderhostid; int sender;
int recieverhostid; int virtualrecvid;
int sendervmid; int virtualsendid;
int recievervmid; int reciever;
int cloudletid; double data;
double stime;//time when sent double sendtime;
double rtime;//time when received double recievetime;
} }
package org.cloudbus.cloudsim.network.datacenter;
public class NetPacket {
public NetPacket(int sender, int reciever, double data, double sendtime,
double recievetime,int vsnd,int vrvd) {
super();
this.sender = sender;
this.reciever = reciever;
this.data = data;
this.sendtime = sendtime;
this.recievetime = recievetime;
this.virtualrecvid=vrvd;
this.virtualsendid=vsnd;
}
int sender;
int virtualrecvid;
int virtualsendid;
int reciever;
double data;
double sendtime;
double recievetime;
}
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
/**
* NetworkCloudlet class extends Cloudlet to support simulation of complex applications.
* Each such network Cloudlet represents a task of the application. Each task consists of several
* stages.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class NetworkCloudlet extends Cloudlet implements Comparable {
public class NetworkCloudlet extends Cloudlet implements Comparable{
long memory; long memory;
public NetworkCloudlet(int cloudletId, long cloudletLength, public NetworkCloudlet(int cloudletId, long cloudletLength, int pesNumber,
int pesNumber, long cloudletFileSize, long cloudletOutputSize, long memory, long cloudletFileSize, long cloudletOutputSize, long memory,
UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelCpu,
UtilizationModel utilizationModelRam, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw) { UtilizationModel utilizationModelBw) {
...@@ -21,41 +34,36 @@ public class NetworkCloudlet extends Cloudlet implements Comparable{ ...@@ -21,41 +34,36 @@ public class NetworkCloudlet extends Cloudlet implements Comparable{
cloudletOutputSize, utilizationModelCpu, utilizationModelRam, cloudletOutputSize, utilizationModelCpu, utilizationModelRam,
utilizationModelBw); utilizationModelBw);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
currStagenum=-1; currStagenum = -1;
this.memory=memory; this.memory = memory;
stages=new ArrayList<TaskStage>(); stages = new ArrayList<TaskStage>();
} }
public double submittime;
public double finishtime; public double submittime; //time when cloudlet will be submitted
public double exetime; public double finishtime; //time when cloudlet finish execution
public double numStage; public double exetime; //execution time for cloudlet
public int currStagenum; public double numStage;//number of stages in cloudlet
public int currStagenum; //current stage of cloudlet execution
public double timetostartStage; public double timetostartStage;
public double timespentInStage; public double timespentInStage; //how much time spent in particular stage
public Map<Double, NetPacket> timeCommunicate; public Map<Double, HostPacket> timeCommunicate;
public ArrayList<TaskStage> stages; public ArrayList<TaskStage> stages; //all stages which cloudlet execution consists of.
public double starttime;
public double starttime;
@Override @Override
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
NetworkCloudlet s1=(NetworkCloudlet)arg0; NetworkCloudlet s1 = (NetworkCloudlet) arg0;
int alpha=0; int alpha = 0;
return 0; return 0;
} }
public double getSubmittime() { public double getSubmittime() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return submittime; return submittime;
}; };
} }
...@@ -4,25 +4,29 @@ import java.util.HashMap; ...@@ -4,25 +4,29 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Constants { public class NetworkConstants {
public static final int FFT = 0;
public static int roundrobinRack=0;
public static int maxhostVM=2; public static int maxhostVM=2;
public static int HOST_PEs=8; public static int HOST_PEs=8;
public static double maxMemperVM=1024*1024;//kb public static double maxMemperVM=1024*1024;//kb
public static final int BIN_NODE_TIME=10;
public static int currentCloudletId=0; public static int currentCloudletId=0;
public static int currentAppId=0; public static int currentAppId=0;
//stage type
public static final int EXECUTION=0; public static final int EXECUTION=0;
public static final int WAIT_SEND=1; public static final int WAIT_SEND=1;
public static final int WAIT_RECV=2; public static final int WAIT_RECV=2;
public static final int FINISH=-2; public static final int FINISH=-2;
//number of switches at each level
public static final int ROOT_LEVEL=0; public static final int ROOT_LEVEL=0;
public static final int Agg_LEVEL=1; public static final int Agg_LEVEL=1;
public static final int EDGE_LEVEL=2; public static final int EDGE_LEVEL=2;
...@@ -30,17 +34,8 @@ public static final int EDGE_LEVEL=2; ...@@ -30,17 +34,8 @@ public static final int EDGE_LEVEL=2;
public static final int PES_NUMBER=4; public static final int PES_NUMBER=4;
public static final int FILE_SIZE=300; public static final int FILE_SIZE=300;
public static final int OUTPUT_SIZE=300; public static final int OUTPUT_SIZE=300;
public static int REQUESTS_PER_SECOND=200;
public static final int COMMUNICATION_LENGTH=1;
public static int Requestspersecond = 2;
public static int REQUEST_CLASSES=10;
public static double LOW_ACCURACY_RATE=0.2;
public static double MEDIUM_ACCURACY_RATE=.3;
public static double HIGH_ACCURACY_RATE=0.9;
public static boolean schedulerOverlap=true;
public static final int COMMUNICATION_LENGTH=1;
public static boolean BASE = true; public static boolean BASE = true;
...@@ -62,7 +57,7 @@ public static double RootSwitchPort=1;//number of Agg ...@@ -62,7 +57,7 @@ public static double RootSwitchPort=1;//number of Agg
public static double seed=199; public static double seed=199;
public static boolean logflag=false; public static boolean logflag=false;
public static Map<Integer,Map<Integer,Boolean>> Cache=new HashMap<Integer,Map<Integer,Boolean>>();
public static int iteration=10; public static int iteration=10;
public static int nexttime=1000; public static int nexttime=1000;
......
package org.cloudbus.cloudsim.network.datacenter;
/**
* NewtorkPacket represents the packet which travel from one server to another.
* Each packet contains ids of the sender VM and receiver VM,
* time at which it is send and received, type and virtual ids of tasks, which are communicating.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class NetworkPacket {
public NetworkPacket(int id, HostPacket pkt2, int vmid, int cloudletid) {
// TODO Auto-generated constructor stub
this.pkt = pkt2;
this.sendervmid = vmid;
this.cloudletid = cloudletid;
this.senderhostid = id;
this.stime = pkt.sendtime;
this.recievervmid = pkt2.reciever;
}
HostPacket pkt;
int senderhostid;
int recieverhostid;
int sendervmid;
int recievervmid;
int cloudletid;
double stime;// time when sent
double rtime;// time when received
}
...@@ -6,29 +6,49 @@ import java.util.List; ...@@ -6,29 +6,49 @@ import java.util.List;
import org.cloudbus.cloudsim.CloudletScheduler; import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
/**
* NetworkVm class extends Vm to support simulation of networked datacenters.
* It executes actions related to management of packets (send and receive).
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class NetworkVm extends Vm implements Comparable{ public class NetworkVm extends Vm implements Comparable {
public NetworkVm(int id, int userId, double mips, int pesNumber, int ram, public NetworkVm(int id, int userId, double mips, int pesNumber, int ram,
long bw, long size, String vmm, CloudletScheduler cloudletScheduler) { long bw, long size, String vmm, CloudletScheduler cloudletScheduler) {
super(id, userId, mips, pesNumber, ram, bw, size, vmm, cloudletScheduler); super(id, userId, mips, pesNumber, ram, bw, size, vmm,
cloudletScheduler);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
cloudletlist=new ArrayList<NetworkCloudlet>(); cloudletlist = new ArrayList<NetworkCloudlet>();
} }
public ArrayList<NetworkCloudlet> cloudletlist; public ArrayList<NetworkCloudlet> cloudletlist;
int type; int type;
public ArrayList<NetPacket> recvPktlist; public ArrayList<HostPacket> recvPktlist;
public double memory; public double memory;
public boolean flagfree;//if true it is free public boolean flagfree;// if true it is free
public double finishtime; public double finishtime;
public boolean isFree()
{ public boolean isFree() {
return flagfree; return flagfree;
} }
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
NetworkVm hs=(NetworkVm)arg0; NetworkVm hs = (NetworkVm) arg0;
if(hs.finishtime>this.finishtime) return -1; if (hs.finishtime > this.finishtime)
if(hs.finishtime<this.finishtime) return 1; return -1;
if (hs.finishtime < this.finishtime)
return 1;
return 0; return 0;
} }
} }
...@@ -21,15 +21,16 @@ import org.cloudbus.cloudsim.core.CloudSim; ...@@ -21,15 +21,16 @@ import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.power.PowerHost; import org.cloudbus.cloudsim.power.PowerHost;
/** /**
* VmAllocationPolicySimple is an VmAllocationPolicy that * NetworkVmAllocationPolicy is an VmAllocationPolicy that
* chooses, as the host for a VM, the host with * chooses, as the host for a VM, the host with
* less PEs in use. * less PEs in use.
* *
* @author Rodrigo N. Calheiros * @author Rodrigo N. Calheiros
* @author Anton Beloglazov * @author Anton Beloglazov
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 1.0
*/ */
public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { public class NetworkVmAllocationPolicy extends VmAllocationPolicy {
/** The vm table. */ /** The vm table. */
private Map<String, Host> vmTable; private Map<String, Host> vmTable;
...@@ -48,7 +49,7 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { ...@@ -48,7 +49,7 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
public VmHPCAllocationPolicySimple(List<? extends Host> list) { public NetworkVmAllocationPolicy(List<? extends Host> list) {
super(list); super(list);
setFreePes(new ArrayList<Integer>()); setFreePes(new ArrayList<Integer>());
...@@ -74,34 +75,51 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { ...@@ -74,34 +75,51 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
@Override @Override
public boolean allocateHostForVm(Vm vm) { public boolean allocateHostForVm(Vm vm) {
NetworkHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { //if vm has been succesfully created in the host int requiredPes = vm.getPesNumber();
getVmTable().put(vm.getUid(), allocatedHost); boolean result = false;
if (!Log.isDisabled()) { int tries = 0;
Log.print(String.format("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock())); List<Integer> freePesTmp = new ArrayList<Integer>();
} for (Integer freePes : getFreePes()) {
return true; freePesTmp.add(freePes);
} }
return false;
}
public NetworkHost findHostForVm(Vm vm) { if (!getVmTable().containsKey(vm.getUid())) { //if this vm was not created
double minPower = Double.MAX_VALUE; do {//we still trying until we find a host or until we try all of them
NetworkHost allocatedHost = null; int moreFree = Integer.MIN_VALUE;
int idx = -1;
//we want the host with less pes in use
for (int i=0; i < freePesTmp.size(); i++) {
if (freePesTmp.get(i) > moreFree) {
moreFree = freePesTmp.get(i);
idx = i;
}
}
NetworkHost host =this.<NetworkHost>getHostList().get(idx);
result = host.vmCreate(vm);
if (result) { //if vm were succesfully created in the host
//Log.printLine("VmAllocationPolicy: VM #"+vm.getVmId()+ "Chosen host: #"+host.getMachineID()+" idx:"+idx);
getVmTable().put(vm.getUid(), host);
getUsedPes().put(vm.getUid(), requiredPes);
getFreePes().set(idx, getFreePes().get(idx) - requiredPes);
result = true;
break;
} else {
freePesTmp.set(idx, Integer.MIN_VALUE);
}
tries++;
} while (!result && tries < getFreePes().size());
for (NetworkHost host : this.<NetworkHost>getHostList()) {
if (host.isSuitableForVm(vm)) {
double maxUtilization = getMaxUtilizationAfterAllocation(host, vm);
if ((!vm.isRecentlyCreated() && maxUtilization > 1) || (vm.isRecentlyCreated() && maxUtilization > 1.0)) {
continue;
}
allocatedHost = host;
} }
return result;
} }
return allocatedHost;
}
protected double getMaxUtilizationAfterAllocation(NetworkHost host, Vm vm) { protected double getMaxUtilizationAfterAllocation(NetworkHost host, Vm vm) {
List<Double> allocatedMipsForVm = null; List<Double> allocatedMipsForVm = null;
NetworkHost allocatedHost = (NetworkHost) vm.getHost(); NetworkHost allocatedHost = (NetworkHost) vm.getHost();
...@@ -248,6 +266,12 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy { ...@@ -248,6 +266,12 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
public boolean allocateHostForVm(Vm vm, Host host) { public boolean allocateHostForVm(Vm vm, Host host) {
if (host.vmCreate(vm)) { //if vm has been succesfully created in the host if (host.vmCreate(vm)) { //if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), host); getVmTable().put(vm.getUid(), host);
int requiredPes = vm.getPesNumber();
int idx = getHostList().indexOf(host);
getUsedPes().put(vm.getUid(), requiredPes);
getFreePes().set(idx, getFreePes().get(idx) - requiredPes);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock()); Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock());
return true; return true;
} }
......
...@@ -9,60 +9,92 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -9,60 +9,92 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType; import org.cloudbus.cloudsim.core.predicates.PredicateType;
public class RootSwitch extends Switch{ /**
* This class allows to simulate Root switch which connects Datacenter to
* external network. It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*
*/
public class RootSwitch extends Switch {
/**
* Constructor for Root Switch We have to specify switches that are
* connected to its downlink ports, and corresponding bandwidths
*
* @param name
* Name of the switch
* @param level
* At which level switch is with respect to hosts.
* @param dc
* Pointer to Datacenter
*/
public RootSwitch(String name, int level, NetworkDatacenter dc) { public RootSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc); super(name, level, dc);
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); downlinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
downlinkswitches=new ArrayList<Switch>(); downlinkswitches = new ArrayList<Switch>();
downlinkbandwidth=Constants.BandWidthAggRoot; downlinkbandwidth = NetworkConstants.BandWidthAggRoot;
latency=Constants.SwitchingDelayRoot; latency = NetworkConstants.SwitchingDelayRoot;
numport=Constants.RootSwitchPort; numport = NetworkConstants.RootSwitchPort;
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
/**
private void processpacket_up(SimEvent ev) { * Send Packet to switch connected through a downlink port
// TODO Auto-generated method stub *
//packet coming from down level router. * @param ev
//has to send up * Event/packet to process
//check which switch to forward to */
//add packet in the switch list @Override
protected void processpacket_up(SimEvent ev) {
// packet coming from down level router.
// has to send up
// check which switch to forward to
// add packet in the switch list
// //
//int src=ev.getSource();
HostPacket hspkt=(HostPacket) ev.getData(); NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send); CloudSimTags.Network_Event_send));
schedule(getId(), this.switching_delay, CloudSimTags.Network_Event_send);
if(this.level==Constants.ROOT_LEVEL)
{
//get id of edge router
int edgeswitchid=dc.VmToSwitchid.get(recvVMid);
//search which aggregate switch has it
int aggSwtichid=-1;;
for(Switch sw:this.downlinkswitches)
{
for(Switch edge:sw.downlinkswitches)
{
if(edge.getId()==edgeswitchid){
aggSwtichid=sw.getId();
break;
}
}
}
if(aggSwtichid<0) System.out.println(" No destination for this packet");
else{
List<HostPacket> pktlist=this.downlinkswitchpktlist.get(aggSwtichid);
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
this.downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
if (this.level == NetworkConstants.ROOT_LEVEL) {
// get id of edge router
int edgeswitchid = dc.VmToSwitchid.get(recvVMid);
// search which aggregate switch has it
int aggSwtichid = -1;
;
for (Switch sw : this.downlinkswitches) {
for (Switch edge : sw.downlinkswitches) {
if (edge.getId() == edgeswitchid) {
aggSwtichid = sw.getId();
break;
}
}
}
if (aggSwtichid < 0)
System.out.println(" No destination for this packet");
else {
List<NetworkPacket> pktlist = this.downlinkswitchpktlist
.get(aggSwtichid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
this.downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* Taskstage represents various stages a networkCloudlet can have during execution.
* Four stage types which are possible-> EXECUTION=0; WAIT_SEND=1; WAIT_RECV=2; FINISH=-2;
* Check NeworkConstants.java file for that.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class TaskStage { public class TaskStage {
public TaskStage(int type, double data, double time, double stageid,long memory, public TaskStage(int type, double data, double time, double stageid,
int peer,int vpeer) { long memory, int peer, int vpeer) {
super(); super();
this.type = type; this.type = type;
this.data = data; this.data = data;
...@@ -10,14 +27,15 @@ public class TaskStage { ...@@ -10,14 +27,15 @@ public class TaskStage {
this.stageid = stageid; this.stageid = stageid;
this.memory = memory; this.memory = memory;
this.peer = peer; this.peer = peer;
this.vpeer=vpeer; this.vpeer = vpeer;
} }
int vpeer; int vpeer;
int type;//execution, recv, send, int type;// execution, recv, send,
double data;//data generated or send or recv double data;// data generated or send or recv
double time;//execution time for this stage double time;// execution time for this stage
double stageid; double stageid;
long memory; long memory;
int peer;//from whom data needed to be recieved or send int peer;// from whom data needed to be recieved or send
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
/**
* WorkflowApp is an example of AppCloudlet having three communicating tasks.
* Task A and B sends the data (packet) while Task C receives them
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011.
*
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
...@@ -16,30 +32,30 @@ public class WorkflowApp extends AppCloudlet{ ...@@ -16,30 +32,30 @@ public class WorkflowApp extends AppCloudlet{
this.numbervm=3; this.numbervm=3;
} }
public void createCloudletList(List<Integer> vmIdList){ public void createCloudletList(List<Integer> vmIdList){
long fileSize = Constants.FILE_SIZE; long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = Constants.OUTPUT_SIZE; long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = Constants.PES_NUMBER; int pesNumber = NetworkConstants.PES_NUMBER;
int memory=100; int memory=100;
UtilizationModel utilizationModel = new UtilizationModelFull(); UtilizationModel utilizationModel = new UtilizationModelFull();
int i=0; int i=0;
//Task A //Task A
NetworkCloudlet cl = new NetworkCloudlet(Constants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
cl.numStage=2; cl.numStage=2;
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
cl.setUserId(userId); cl.setUserId(userId);
cl.submittime=CloudSim.clock(); cl.submittime=CloudSim.clock();
cl.currStagenum=-1; cl.currStagenum=-1;
cl.setVmId(vmIdList.get(i)); cl.setVmId(vmIdList.get(i));
//first stage: big computation //first stage: big computation
cl.stages.add(new TaskStage(Constants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(0),cl.getCloudletId())); cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(0),cl.getCloudletId()));
cl.stages.add(new TaskStage(Constants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),cl.getCloudletId()+2)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),cl.getCloudletId()+2));
clist.add(cl); clist.add(cl);
i++; i++;
//Task B //Task B
NetworkCloudlet clb = new NetworkCloudlet(Constants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet clb = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
clb.numStage=2; clb.numStage=2;
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
clb.setUserId(userId); clb.setUserId(userId);
clb.submittime=CloudSim.clock(); clb.submittime=CloudSim.clock();
clb.currStagenum=-1; clb.currStagenum=-1;
...@@ -47,24 +63,24 @@ public class WorkflowApp extends AppCloudlet{ ...@@ -47,24 +63,24 @@ public class WorkflowApp extends AppCloudlet{
//first stage: big computation //first stage: big computation
clb.stages.add(new TaskStage(Constants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(1),clb.getCloudletId())); clb.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(1),clb.getCloudletId()));
clb.stages.add(new TaskStage(Constants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),clb.getCloudletId()+1)); clb.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),clb.getCloudletId()+1));
clist.add(clb); clist.add(clb);
i++; i++;
//Task C //Task C
NetworkCloudlet clc = new NetworkCloudlet(Constants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet clc = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
clc.numStage=2; clc.numStage=2;
Constants.currentCloudletId++; NetworkConstants.currentCloudletId++;
clc.setUserId(userId); clc.setUserId(userId);
clc.submittime=CloudSim.clock(); clc.submittime=CloudSim.clock();
clc.currStagenum=-1; clc.currStagenum=-1;
clc.setVmId(vmIdList.get(i)); clc.setVmId(vmIdList.get(i));
//first stage: big computation //first stage: big computation
clc.stages.add(new TaskStage(Constants.WAIT_RECV, 1000, 0, 0, memory, vmIdList.get(0),cl.getCloudletId())); clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 0, memory, vmIdList.get(0),cl.getCloudletId()));
clc.stages.add(new TaskStage(Constants.WAIT_RECV, 1000, 0, 1, memory, vmIdList.get(1),cl.getCloudletId()+1)); clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 1, memory, vmIdList.get(1),cl.getCloudletId()+1));
clc.stages.add(new TaskStage(Constants.EXECUTION, 0, 1000*0.8, 1, memory, vmIdList.get(0),clc.getCloudletId())); clc.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 1, memory, vmIdList.get(0),clc.getCloudletId()));
clist.add(clc); clist.add(clc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment