Documentation Added with Some updates on Code.

parent ecd0ad0b
......@@ -9,99 +9,131 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
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) {
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;
}
downlinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
uplinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
uplinkbandwidth = NetworkConstants.BandWidthAggRoot;
downlinkbandwidth = NetworkConstants.BandWidthEdgeAgg;
latency = NetworkConstants.SwitchingDelayAgg;
numport = NetworkConstants.AggSwitchPort;
uplinkswitches = new ArrayList<Switch>();
downlinkswitches = new ArrayList<Switch>();
}
/**
* 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;
import org.cloudbus.cloudsim.UtilizationModelFull;
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 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) {
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>();
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 int type;
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);
public int requestclass;
/**
* An example of creating APPcloudlet
* @param vmIdList VMs where Cloudlet will be executed
*/
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(
NetworkConstants.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
}
NetworkConstants.currentCloudletId++;
cl.setUserId(userId);
cl.submittime = CloudSim.clock();
cl.currStagenum = -1;
clist.add(cl);
}
// based on type
}
}
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 org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
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);
this.numbervm=this.getnumvm();
......@@ -19,34 +35,39 @@ public class MonteCarloApp extends AppCloudlet {
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;
long memory = 1000;
long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = NetworkConstants.PES_NUMBER;
int stgId=0;
int t=Constants.currentCloudletId;
int t=NetworkConstants.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++;
NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, executionTime/numbervm, pesNumber, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
NetworkConstants.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()));
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
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));
cl.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, NetworkConstants.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));
cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, NetworkConstants.COMMUNICATION_LENGTH, 0, stgId++, memory, vmIdList.get(0),t));
}
clist.add(cl);
}
}
/**
* One can generate number of VMs for each application based on deadline
* @return
*/
public int getnumvm(){
double exetime=getExecTime()/2;//for two vms
if(this.deadline>exetime)
......@@ -57,14 +78,10 @@ public class MonteCarloApp extends AppCloudlet {
}
private int getExecTime() {
//use exec constraints as Binomial
//use exec constraints
return 100;
}
private long accuracyToMemory() {
//use same memory constraints as Binomial
return 240076;
}
}
......@@ -11,26 +11,53 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
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 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>();
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;
uplinkswitchpktlist=new HashMap<Integer,List<NetworkPacket>>();
packetTohost=new HashMap<Integer,List<NetworkPacket>>();
uplinkbandwidth=NetworkConstants.BandWidthEdgeAgg;
downlinkbandwidth=NetworkConstants.BandWidthEdgeHost;
this.switching_delay=NetworkConstants.SwitchingDelayEdge;
numport=NetworkConstants.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) {
/**
* Send Packet to switch connected through a uplink port
*
* @param ev Event/packet to process
*/
@Override
protected void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub
//packet coming from down level router/host.
//has to send up
......@@ -38,7 +65,7 @@ public class EdgeSwitch extends Switch{
//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;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send);
......@@ -54,9 +81,9 @@ public class EdgeSwitch extends Switch{
if(hs!=null)
{
//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){
pktlist=new ArrayList<HostPacket>();
pktlist=new ArrayList<NetworkPacket>();
this.packetTohost.put(hostid, pktlist);
}
pktlist.add(hspkt);
......@@ -69,9 +96,9 @@ public class EdgeSwitch extends 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());
List<NetworkPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){
pktlist=new ArrayList<HostPacket>();
pktlist=new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
......@@ -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
//search for the host and packets..send to them
if(this.uplinkswitchpktlist!=null)
{
for(Entry<Integer, List<HostPacket>> es:uplinkswitchpktlist.entrySet())
for(Entry<Integer, List<NetworkPacket>> es:uplinkswitchpktlist.entrySet())
{
int tosend=es.getKey();
List<HostPacket> hspktlist=es.getValue();
List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){
//sharing bandwidth between packets
double avband=this.uplinkbandwidth/hspktlist.size();
Iterator<HostPacket> it=hspktlist.iterator();
Iterator<NetworkPacket> it=hspktlist.iterator();
while(it.hasNext())
{
HostPacket hspkt=it.next();
NetworkPacket hspkt=it.next();
double delay=1000*hspkt.pkt.data/avband;
this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt);
......@@ -107,16 +141,16 @@ public class EdgeSwitch extends Switch{
}
if(this.packetTohost!=null)
{
for(Entry<Integer, List<HostPacket>> es:packetTohost.entrySet())
for(Entry<Integer, List<NetworkPacket>> es:packetTohost.entrySet())
{
int tosend=es.getKey();
NetworkHost hs=this.hostlist.get(tosend);
List<HostPacket> hspktlist=es.getValue();
List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){
double avband=this.downlinkbandwidth/hspktlist.size();
Iterator<HostPacket> it=hspktlist.iterator();
Iterator<NetworkPacket> it=hspktlist.iterator();
while(it.hasNext()){
HostPacket hspkt=it.next();
NetworkPacket hspkt=it.next();
//hspkt.recieverhostid=tosend;
//hs.packetrecieved.add(hspkt);
this.send(this.getId(),hspkt.pkt.data/avband,CloudSimTags.Network_Event_Host, hspkt);
......
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 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;
public HostPacket(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;
}
NetPacket pkt;
int senderhostid;
int recieverhostid;
int sendervmid;
int recievervmid;
int cloudletid;
double stime;//time when sent
double rtime;//time when received
int sender;
int virtualrecvid;
int virtualsendid;
int reciever;
double data;
double sendtime;
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;
import java.util.ArrayList;
import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet;
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;
public NetworkCloudlet(int cloudletId, long cloudletLength,
int pesNumber, long cloudletFileSize, long cloudletOutputSize, long memory,
public NetworkCloudlet(int cloudletId, long cloudletLength, int pesNumber,
long cloudletFileSize, long cloudletOutputSize, long memory,
UtilizationModel utilizationModelCpu,
UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw) {
......@@ -21,41 +34,36 @@ public class NetworkCloudlet extends Cloudlet implements Comparable{
cloudletOutputSize, utilizationModelCpu, utilizationModelRam,
utilizationModelBw);
// TODO Auto-generated constructor stub
currStagenum=-1;
this.memory=memory;
stages=new ArrayList<TaskStage>();
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 submittime; //time when cloudlet will be submitted
public double finishtime; //time when cloudlet finish execution
public double exetime; //execution time for cloudlet
public double numStage;//number of stages in cloudlet
public int currStagenum; //current stage of cloudlet execution
public double timetostartStage;
public double timespentInStage;
public Map<Double, NetPacket> timeCommunicate;
public ArrayList<TaskStage> stages;
public double starttime;
public double timespentInStage; //how much time spent in particular stage
public Map<Double, HostPacket> timeCommunicate;
public ArrayList<TaskStage> stages; //all stages which cloudlet execution consists of.
public double starttime;
@Override
public int compareTo(Object arg0) {
// TODO Auto-generated method stub
NetworkCloudlet s1=(NetworkCloudlet)arg0;
int alpha=0;
NetworkCloudlet s1 = (NetworkCloudlet) arg0;
int alpha = 0;
return 0;
}
public double getSubmittime() {
// TODO Auto-generated method stub
return submittime;
};
}
......@@ -4,25 +4,29 @@ import java.util.HashMap;
import java.util.List;
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 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;
//stage type
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;
//number of switches at each level
public static final int ROOT_LEVEL=0;
public static final int Agg_LEVEL=1;
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 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 final int COMMUNICATION_LENGTH=1;
public static boolean BASE = true;
......@@ -62,7 +57,7 @@ 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;
......
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;
import org.cloudbus.cloudsim.CloudletScheduler;
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,
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
cloudletlist=new ArrayList<NetworkCloudlet>();
cloudletlist = new ArrayList<NetworkCloudlet>();
}
public ArrayList<NetworkCloudlet> cloudletlist;
int type;
public ArrayList<NetPacket> recvPktlist;
int type;
public ArrayList<HostPacket> recvPktlist;
public double memory;
public boolean flagfree;//if true it is free
public boolean flagfree;// if true it is free
public double finishtime;
public boolean isFree()
{
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;
NetworkVm hs = (NetworkVm) arg0;
if (hs.finishtime > this.finishtime)
return -1;
if (hs.finishtime < this.finishtime)
return 1;
return 0;
}
}
......@@ -21,15 +21,16 @@ import org.cloudbus.cloudsim.core.CloudSim;
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
* less PEs in use.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0
*/
public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
public class NetworkVmAllocationPolicy extends VmAllocationPolicy {
/** The vm table. */
private Map<String, Host> vmTable;
......@@ -48,7 +49,7 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
* @pre $none
* @post $none
*/
public VmHPCAllocationPolicySimple(List<? extends Host> list) {
public NetworkVmAllocationPolicy(List<? extends Host> list) {
super(list);
setFreePes(new ArrayList<Integer>());
......@@ -74,34 +75,51 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
@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;
int requiredPes = vm.getPesNumber();
boolean result = false;
int tries = 0;
List<Integer> freePesTmp = new ArrayList<Integer>();
for (Integer freePes : getFreePes()) {
freePesTmp.add(freePes);
}
return false;
}
public NetworkHost findHostForVm(Vm vm) {
double minPower = Double.MAX_VALUE;
NetworkHost allocatedHost = null;
if (!getVmTable().containsKey(vm.getUid())) { //if this vm was not created
do {//we still trying until we find a host or until we try all of them
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) {
List<Double> allocatedMipsForVm = null;
NetworkHost allocatedHost = (NetworkHost) vm.getHost();
......@@ -248,6 +266,12 @@ public class VmHPCAllocationPolicySimple extends VmAllocationPolicy {
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);
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());
return true;
}
......
......@@ -9,60 +9,92 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
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) {
super(name, level, dc);
downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>();
downlinkswitches=new ArrayList<Switch>();
downlinkbandwidth=Constants.BandWidthAggRoot;
latency=Constants.SwitchingDelayRoot;
numport=Constants.RootSwitchPort;
downlinkswitchpktlist = new HashMap<Integer, List<NetworkPacket>>();
downlinkswitches = new ArrayList<Switch>();
downlinkbandwidth = NetworkConstants.BandWidthAggRoot;
latency = NetworkConstants.SwitchingDelayRoot;
numport = NetworkConstants.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
/**
* Send Packet to switch connected through a downlink 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();
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);
}
}
}
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.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;
/**
* 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 TaskStage(int type, double data, double time, double stageid,long memory,
int peer,int vpeer) {
public TaskStage(int type, double data, double time, double stageid,
long memory, int peer, int vpeer) {
super();
this.type = type;
this.data = data;
......@@ -10,14 +27,15 @@ public class TaskStage {
this.stageid = stageid;
this.memory = memory;
this.peer = peer;
this.vpeer=vpeer;
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
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
int peer;// from whom data needed to be recieved or send
}
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 org.cloudbus.cloudsim.UtilizationModel;
......@@ -16,30 +32,30 @@ public class WorkflowApp extends AppCloudlet{
this.numbervm=3;
}
public void createCloudletList(List<Integer> vmIdList){
long fileSize = Constants.FILE_SIZE;
long outputSize = Constants.OUTPUT_SIZE;
int pesNumber = Constants.PES_NUMBER;
long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = NetworkConstants.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);
NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
cl.numStage=2;
Constants.currentCloudletId++;
NetworkConstants.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));
cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(0),cl.getCloudletId()));
cl.stages.add(new TaskStage(NetworkConstants.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);
NetworkCloudlet clb = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
clb.numStage=2;
Constants.currentCloudletId++;
NetworkConstants.currentCloudletId++;
clb.setUserId(userId);
clb.submittime=CloudSim.clock();
clb.currStagenum=-1;
......@@ -47,24 +63,24 @@ public class WorkflowApp extends AppCloudlet{
//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));
clb.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(1),clb.getCloudletId()));
clb.stages.add(new TaskStage(NetworkConstants.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);
NetworkCloudlet clc = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel);
clc.numStage=2;
Constants.currentCloudletId++;
NetworkConstants.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()));
clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 0, memory, vmIdList.get(0),cl.getCloudletId()));
clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 1, memory, vmIdList.get(1),cl.getCloudletId()+1));
clc.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 1, memory, vmIdList.get(0),clc.getCloudletId()));
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