This commit is contained in:
2021-04-06 00:45:28 +02:00
commit 17fabc368e
836 changed files with 3042963 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network;
import java.util.Iterator;
/**
* This class represents an delay-topology storing every distance between connected nodes
*
* @author Thomas Hohnstein
* @since CloudSim Toolkit 1.0
*/
public class DelayMatrix_Float {
/**
* matrix holding delay information between any two nodes
*/
protected float[][] mDelayMatrix = null;
/**
* number of nodes in the distance-aware-topology
*/
protected int mTotalNodeNum = 0;
/**
* private constructor to ensure that only an correct initialized delay-matrix could be created
*/
@SuppressWarnings("unused")
private DelayMatrix_Float() {
};
/**
* this constructor creates an correct initialized Float-Delay-Matrix
*
* @param graph the topological graph as source-information
* @param directed true if an directed matrix should be computed, false otherwise
*/
public DelayMatrix_Float(TopologicalGraph graph, boolean directed) {
// lets preinitialize the Delay-Matrix
createDelayMatrix(graph, directed);
// now its time to calculate all possible connection-delays
calculateShortestPath();
}
/**
* @param srcID the id of the source-node
* @param destID the id of the destination-node
* @return the delay-count between the given two nodes
*/
public float getDelay(int srcID, int destID) {
// check the nodeIDs against internal array-boundarys
if (srcID > mTotalNodeNum || destID > mTotalNodeNum) {
throw new ArrayIndexOutOfBoundsException("srcID or destID is higher than highest stored node-ID!");
}
return mDelayMatrix[srcID][destID];
}
/**
* creates all internal necessary network-distance structures from the given graph for
* similarity we assume all kommunikation-distances are symmetrical thus leads to an undirected
* network
*
* @param graph this graph contains all node and link information
* @param directed defines to preinitialize an directed or undirected Delay-Matrix!
*/
private void createDelayMatrix(TopologicalGraph graph, boolean directed) {
// number of nodes inside the network
mTotalNodeNum = graph.getNumberOfNodes();
mDelayMatrix = new float[mTotalNodeNum][mTotalNodeNum];
// cleanup the complete distance-matrix with "0"s
for (int row = 0; row < mTotalNodeNum; ++row) {
for (int col = 0; col < mTotalNodeNum; ++col) {
mDelayMatrix[row][col] = Float.MAX_VALUE;
}
}
Iterator<TopologicalLink> itr = graph.getLinkIterator();
TopologicalLink edge;
while (itr.hasNext()) {
edge = itr.next();
mDelayMatrix[edge.getSrcNodeID()][edge.getDestNodeID()] = edge.getLinkDelay();
if (!directed) {
// according to aproximity of symmetry to all kommunication-paths
mDelayMatrix[edge.getDestNodeID()][edge.getSrcNodeID()] = edge.getLinkDelay();
}
}
}
/**
* just calculates all pairs shortest paths
*/
private void calculateShortestPath() {
FloydWarshall_Float floyd = new FloydWarshall_Float();
floyd.initialize(mTotalNodeNum);
mDelayMatrix = floyd.allPairsShortestPaths(mDelayMatrix);
}
/**
* this method just creates an string-output from the internal structures... eg. printsout the
* delay-matrix...
*/
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("just a simple printout of the distance-aware-topology-class\n");
buffer.append("delay-matrix is:\n");
for (int column = 0; column < mTotalNodeNum; ++column) {
buffer.append("\t" + column);
}
for (int row = 0; row < mTotalNodeNum; ++row) {
buffer.append("\n" + row);
for (int col = 0; col < mTotalNodeNum; ++col) {
if (mDelayMatrix[row][col] == Float.MAX_VALUE) {
buffer.append("\t" + "-");
} else {
buffer.append("\t" + mDelayMatrix[row][col]);
}
}
}
return buffer.toString();
}
}

View File

@@ -0,0 +1,193 @@
/*
* @(#)FloydWarshall.java ver 1.2 6/20/2005
*
* Modified by Weishuai Yang (wyang@cs.binghamton.edu).
* Originally written by Rahul Simha
*
*/
package org.cloudbus.cloudsim.network;
/**
* FloydWarshall algorithm to calculate all pairs delay and predecessor matrix.
*
* @author Rahul Simha
* @author Weishuai Yang
* @version 1.2, 6/20/2005
* @since CloudSim Toolkit 1.0
*/
public class FloydWarshall_Float {
/**
* Number of vertices (when initialized)
*/
private int numVertices;
// /**
// * The adjacency matrix (given as input),
// * here I use float rather than double to save memory,
// * since there won't be a lot of spilting for delay,
// * and float is accurate enough.
// */
// private float[][] adjMatrix;
/**
* Matrices used in dynamic programming
*/
private float[][] Dk, Dk_minus_one;
/**
* Matrices used in dynamic programming
*/
private int[][] Pk, Pk_minus_one;
/**
* initialization matrix
*
* @param numVertices number of nodes
*/
public void initialize(int numVertices) {
this.numVertices = numVertices;
// Initialize Dk matrices.
Dk = new float[numVertices][];
Dk_minus_one = new float[numVertices][];
for (int i = 0; i < numVertices; i++) {
Dk[i] = new float[numVertices];
Dk_minus_one[i] = new float[numVertices];
}
// Initialize Pk matrices.
Pk = new int[numVertices][];
Pk_minus_one = new int[numVertices][];
for (int i = 0; i < numVertices; i++) {
Pk[i] = new int[numVertices];
Pk_minus_one[i] = new int[numVertices];
}
}
/**
* calculates all pairs delay
*
* @param adjMatrix original delay matrix
* @return all pairs delay matrix
*/
public float[][] allPairsShortestPaths(float[][] adjMatrix) {
// Dk_minus_one = weights when k = -1
for (int i = 0; i < numVertices; i++) {
for (int j = 0; j < numVertices; j++) {
if (adjMatrix[i][j] != 0) {
Dk_minus_one[i][j] = adjMatrix[i][j];
Pk_minus_one[i][j] = i;
} else {
Dk_minus_one[i][j] = Float.MAX_VALUE;
Pk_minus_one[i][j] = -1;
}
// NOTE: we have set the value to infinity and will exploit
// this to avoid a comparison.
}
}
// Now iterate over k.
for (int k = 0; k < numVertices; k++) {
// Compute Dk[i][j], for each i,j
for (int i = 0; i < numVertices; i++) {
for (int j = 0; j < numVertices; j++) {
if (i != j) {
// D_k[i][j] = min ( D_k-1[i][j], D_k-1[i][k] + D_k-1[k][j].
if (Dk_minus_one[i][j] <= Dk_minus_one[i][k] + Dk_minus_one[k][j]) {
Dk[i][j] = Dk_minus_one[i][j];
Pk[i][j] = Pk_minus_one[i][j];
} else {
Dk[i][j] = Dk_minus_one[i][k] + Dk_minus_one[k][j];
Pk[i][j] = Pk_minus_one[k][j];
}
} else {
Pk[i][j] = -1;
}
}
}
// Now store current Dk into D_k-1
for (int i = 0; i < numVertices; i++) {
for (int j = 0; j < numVertices; j++) {
Dk_minus_one[i][j] = Dk[i][j];
Pk_minus_one[i][j] = Pk[i][j];
}
}
} // end-outermost-for
return Dk;
}
/**
* gets predecessor matrix
*
* @return predecessor matrix
*/
public int[][] getPK() {
return Pk;
}
/*
public static void main (String[] argv)
{
// A test case.
*
double[][] adjMatrix = {
{0, 1, 0, 0, 1},
{1, 0, 1, 3, 0},
{0, 1, 0, 2, 0},
{0, 3, 2, 0, 1},
{1, 0, 0, 1, 0},
};
int n = adjMatrix.length;
FloydWarshall fwAlg = new FloydWarshall ();
fwAlg.initialize (n);
adjMatrix=fwAlg.allPairsShortestPaths (adjMatrix);
//debug begin
StringBuffer s0=new StringBuffer("Delay Information before floydwarshall:\n");
for(int i=0;i<n;i++){
s0.append("Node "+i+" to others:");
for(int j=0;j<n;j++){
s0.append(LogFormatter.sprintf(" % 6.1f ", adjMatrix[i][j]));
}
s0.append("\n");
}
Log.printLine(""+s0);
int[][] Pk=fwAlg.getPK();
Log.printLine("Path information");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
Log.print("From "+i+" to "+j+": ");
int pre=Pk[i][j];
while((pre!=-1)&&(pre!=i)){
Log.print(" <- "+ pre);
pre=Pk[i][pre];
if((pre==-1)||(pre==i))
Log.print(" <- "+ pre);
}
Log.printLine("\n");
}
}
}
*/
}

View File

@@ -0,0 +1,204 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
/**
* This class is just an file-reader for the special brite-format! the brite-file is structured as
* followed: Node-section: NodeID, xpos, ypos, indegree, outdegree, ASid, type(router/AS)
* Edge-section: EdgeID, fromNode, toNode, euclideanLength, linkDelay, linkBandwith, AS_from, AS_to,
* type
*
* @author Thomas Hohnstein
* @since CloudSim Toolkit 1.0
*/
public class GraphReaderBrite implements GraphReaderIF {
private static final int PARSE_NOTHING = 0;
private static final int PARSE_NODES = 1;
private static final int PARSE_EDGES = 2;
private int state = PARSE_NOTHING;
private TopologicalGraph graph = null;
/**
* this method just reads the file and creates an TopologicalGraph object
*
* @param filename name of the file to read
* @return created TopologicalGraph
* @throws IOException
*/
@Override
public TopologicalGraph readGraphFile(String filename) throws IOException {
graph = new TopologicalGraph();
// lets read the file
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
String lineSep = System.getProperty("line.separator");
String nextLine = null;
StringBuffer sb = new StringBuffer();
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);
//
// note:
// BufferedReader strips the EOL character.
//
sb.append(lineSep);
// functionality to diferentiate between all the parsing-states
// state that should just find the start of node-declaration
if (state == PARSE_NOTHING) {
if (nextLine.contains("Nodes:")) {
// Log.printLine("found start of Nodes... switch to parse nodes!");
state = PARSE_NODES;
}
}
// the state to retrieve all node-information
else if (state == PARSE_NODES) {
// perform the parsing of this node-line
parseNodeString(nextLine);
}
// the state to retrieve all edges-information
else if (state == PARSE_EDGES) {
parseEdgesString(nextLine);
}
}
br.close();
// Log.printLine("read file successfully...");
// Log.printLine(sb.toString());
return graph;
}
private void parseNodeString(String nodeLine) {
StringTokenizer tokenizer = new StringTokenizer(nodeLine);
// number of node parameters to parse (counts at linestart)
int parameters = 3;
// first test to step to the next parsing-state (edges)
if (nodeLine.contains("Edges:")) {
// Log.printLine("found start of Edges... switch to parse edges!");
state = PARSE_EDGES;
return;
}
// test against an empty line
if (!tokenizer.hasMoreElements()) {
// Log.printLine("this line contains no tokens...");
return;
}
// parse this string-line to read all node-parameters
// NodeID, xpos, ypos, indegree, outdegree, ASid, type(router/AS)
int nodeID = 0;
String nodeLabel = "";
int xPos = 0;
int yPos = 0;
for (int actualParam = 0; tokenizer.hasMoreElements() && actualParam < parameters; actualParam++) {
String token = tokenizer.nextToken();
switch (actualParam) {
case 0: // Log.printLine("nodeID: "+token);
// Log.printLine("nodeLabel: "+token);
nodeID = Integer.valueOf(token);
nodeLabel = Integer.toString(nodeID);
break;
case 1: // Log.printLine("x-Pos: "+token);
xPos = Integer.valueOf(token);
break;
case 2: // Log.printLine("y-Pos: "+token);
yPos = Integer.valueOf(token);
break;
}
}
// instanciate an new node-object with previous parsed parameters
TopologicalNode topoNode = new TopologicalNode(nodeID, nodeLabel, xPos, yPos);
graph.addNode(topoNode);
}// parseNodeString-END
private void parseEdgesString(String nodeLine) {
StringTokenizer tokenizer = new StringTokenizer(nodeLine);
// number of node parameters to parse (counts at linestart)
int parameters = 6;
// test against an empty line
if (!tokenizer.hasMoreElements()) {
// Log.printLine("this line contains no tokens...");
return;
}
// parse this string-line to read all node-parameters
// EdgeID, fromNode, toNode, euclideanLength, linkDelay, linkBandwith, AS_from, AS_to, type
// int edgeID = 0;
int fromNode = 0;
int toNode = 0;
// float euclideanLength = 0;
float linkDelay = 0;
int linkBandwith = 0;
for (int actualParam = 0; tokenizer.hasMoreElements() && actualParam < parameters; actualParam++) {
String token = tokenizer.nextToken();
switch (actualParam) {
case 0: // Log.printLine("edgeID: "+token);
// edgeID = Integer.valueOf(token);
break;
case 1: // Log.printLine("fromNode: "+token);
fromNode = Integer.valueOf(token);
break;
case 2: // Log.printLine("toNode: "+token);
toNode = Integer.valueOf(token);
break;
case 3: // Log.printLine("euclideanLength: "+token);
// euclideanLength = Float.valueOf(token);
break;
case 4: // Log.printLine("linkDelay: "+token);
linkDelay = Float.valueOf(token);
break;
case 5: // Log.printLine("linkBandwith: "+token);
linkBandwith = Float.valueOf(token).intValue();
break;
}// switch-END
}// for-END
graph.addLink(new TopologicalLink(fromNode, toNode, linkDelay, linkBandwith));
}
}

View File

@@ -0,0 +1,30 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network;
import java.io.IOException;
/**
* This interface abstracts an reader for different graph-file-formats
*
* @author Thomas Hohnstein
* @since CloudSim Toolkit 1.0
*/
public interface GraphReaderIF {
/**
* this method just reads the file and creates an TopologicalGraph object
*
* @param filename name of the file to read
* @return created TopologicalGraph
* @throws IOException
*/
TopologicalGraph readGraphFile(String filename) throws IOException;
}

View File

@@ -0,0 +1,113 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* This class represents an graph containing nodes and edges, used for input with an network-layer
* Graphical-Output Restricions! EdgeColors: GraphicalProperties.getColorEdge NodeColors:
* GraphicalProperties.getColorNode
*
* @author Thomas Hohnstein
* @since CloudSim Toolkit 1.0
*/
public class TopologicalGraph {
private List<TopologicalLink> linkList = null;
private List<TopologicalNode> nodeList = null;
/**
* just the constructor to create an empty graph-object
*/
public TopologicalGraph() {
linkList = new LinkedList<TopologicalLink>();
nodeList = new LinkedList<TopologicalNode>();
}
/**
* adds an link between two topological nodes
*
* @param edge the topological link
*/
public void addLink(TopologicalLink edge) {
linkList.add(edge);
}
/**
* adds an Topological Node to this graph
*
* @param node the topological node to add
*/
public void addNode(TopologicalNode node) {
nodeList.add(node);
}
/**
* returns the number of nodes contained inside the topological-graph
*
* @return number of nodes
*/
public int getNumberOfNodes() {
return nodeList.size();
}
/**
* returns the number of links contained inside the topological-graph
*
* @return number of links
*/
public int getNumberOfLinks() {
return linkList.size();
}
/**
* return an iterator through all network-graph links
*
* @return the iterator throug all links
*/
public Iterator<TopologicalLink> getLinkIterator() {
return linkList.iterator();
}
/**
* returns an iterator through all network-graph nodes
*
* @return the iterator through all nodes
*/
public Iterator<TopologicalNode> getNodeIterator() {
return nodeList.iterator();
}
/**
* prints out all internal node and link information
*/
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("topological-node-information: \n");
for (TopologicalNode node : nodeList) {
buffer.append(node.getNodeID() + " | x is: " + node.getCoordinateX() + " y is: "
+ node.getCoordinateY() + "\n");
}
buffer.append("\n\n node-link-information:\n");
for (TopologicalLink link : linkList) {
buffer.append("from: " + link.getSrcNodeID() + " to: " + link.getDestNodeID() + " delay: "
+ link.getLinkDelay() + "\n");
}
return buffer.toString();
}
}

View File

@@ -0,0 +1,83 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network;
/**
* This class represents an link (edge) from an graph
*
* @author Thomas Hohnstein
* @since CloudSim Toolkit 1.0
*/
public class TopologicalLink {
/**
* id of the link src node-id
*/
private int srcNodeID = 0;
/**
* id of the link dest node-id
*/
private int destNodeID = 0;
/**
* representing the link-delay of the connection
*/
private float linkDelay = 0;
private float linkBw = 0;
/**
* creates an new link-object
*/
public TopologicalLink(int srcNode, int destNode, float delay, float bw) {
// lets initialize all internal attributes
linkDelay = delay;
srcNodeID = srcNode;
destNodeID = destNode;
linkBw = bw;
}
/**
* returns the node-ID from the SrcNode
*
* @return nodeID
*/
public int getSrcNodeID() {
return srcNodeID;
}
/**
* return the node-ID from the DestNode
*
* @return nodeID
*/
public int getDestNodeID() {
return destNodeID;
}
/**
* return the link-delay of the defined linke
*
* @return the delay-amount
*/
public float getLinkDelay() {
return linkDelay;
}
/**
* return the link-bw of the defined linke
*
* @return the bw
*/
public float getLinkBw() {
return linkBw;
}
}

View File

@@ -0,0 +1,104 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network;
/**
* Just represents an topological network node retrieves its information from an
* topological-generated file (eg. topology-generator)
*
* @author Thomas Hohnstein
* @since CloudSim Toolkit 1.0
*/
public class TopologicalNode {
/**
* its the nodes-ID inside this network
*/
private int nodeID = 0;
/**
* describes the nodes-name inside the network
*/
private String nodeName = null;
/**
* representing the x an y world-coordinates
*/
private int worldX = 0;
private int worldY = 0;
/**
* constructs an new node
*/
public TopologicalNode(int nodeID) {
// lets initialize all private class attributes
this.nodeID = nodeID;
nodeName = String.valueOf(nodeID);
}
/**
* constructs an new node including world-coordinates
*/
public TopologicalNode(int nodeID, int x, int y) {
// lets initialize all private class attributes
this.nodeID = nodeID;
nodeName = String.valueOf(nodeID);
worldX = x;
worldY = y;
}
/**
* constructs an new node including world-coordinates and the nodeName
*/
public TopologicalNode(int nodeID, String nodeName, int x, int y) {
// lets initialize all private class attributes
this.nodeID = nodeID;
this.nodeName = nodeName;
worldX = x;
worldY = y;
}
/**
* delivers the nodes id
*
* @return just the nodeID
*/
public int getNodeID() {
return nodeID;
}
/**
* delivers the name of the node
*
* @return name of the node
*/
public String getNodeLabel() {
return nodeName;
}
/**
* returns the x coordinate of this network-node
*
* @return the x coordinate
*/
public int getCoordinateX() {
return worldX;
}
/**
* returns the y coordinate of this network-node
*
* @return the y coordinate
*/
public int getCoordinateY() {
return worldY;
}
}

View File

@@ -0,0 +1,137 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* 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 1.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);
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(), latency, CloudSimTags.Network_Event_send);
if (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 = downlinkswitchpktlist.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
return;
}
}
/**
* 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(), switching_delay, CloudSimTags.Network_Event_send);
if (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 : downlinkswitches) {
if (switchid == sw.getId()) {
flagtoswtich = true;
}
}
if (flagtoswtich) {
List<NetworkPacket> pktlist = downlinkswitchpktlist.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
} else// send to up
{
Switch sw = uplinkswitches.get(0);
List<NetworkPacket> pktlist = uplinkswitchpktlist.get(sw.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
}
}

View File

@@ -0,0 +1,100 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* 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) {
super();
this.type = type;
this.appID = appID;
this.deadline = deadline;
this.numbervm = numbervm;
this.userId = userId;
clist = new ArrayList<NetworkCloudlet>();
}
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;
/**
* 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
NetworkConstants.currentCloudletId++;
cl.setUserId(userId);
cl.submittime = CloudSim.clock();
cl.currStagenum = -1;
clist.add(cl);
}
// based on type
}
}

View File

@@ -0,0 +1,160 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* 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 {
/**
* 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<NetworkPacket>>();
packetTohost = new HashMap<Integer, List<NetworkPacket>>();
uplinkbandwidth = NetworkConstants.BandWidthEdgeAgg;
downlinkbandwidth = NetworkConstants.BandWidthEdgeHost;
switching_delay = NetworkConstants.SwitchingDelayEdge;
numport = NetworkConstants.EdgeSwitchPort;
uplinkswitches = new ArrayList<Switch>();
}
/**
* 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/host.
// 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(), switching_delay, CloudSimTags.Network_Event_send);
// packet is recieved from host
// packet is to be sent to aggregate level or to another host in the same level
int hostid = dc.VmtoHostlist.get(recvVMid);
NetworkHost hs = hostlist.get(hostid);
hspkt.recieverhostid = hostid;
// packet needs to go to a host which is connected directly to switch
if (hs != null) {
// packet to be sent to host connected to the switch
List<NetworkPacket> pktlist = packetTohost.get(hostid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
packetTohost.put(hostid, pktlist);
}
pktlist.add(hspkt);
return;
}
// otherwise
// packet is to be sent to upper switch
// ASSUMPTION EACH EDGE is Connected to one aggregate level switch
// if there are more than one Aggregate level switch one need to modify following code
Switch sw = uplinkswitches.get(0);
List<NetworkPacket> pktlist = uplinkswitchpktlist.get(sw.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
return;
}
/**
* Send Packet to hosts connected to the switch
*
* @param ev Event/packet to process
*/
@Override
protected void processpacketforward(SimEvent ev) {
// search for the host and packets..send to them
if (uplinkswitchpktlist != null) {
for (Entry<Integer, List<NetworkPacket>> es : uplinkswitchpktlist.entrySet()) {
int tosend = es.getKey();
List<NetworkPacket> hspktlist = es.getValue();
if (!hspktlist.isEmpty()) {
// sharing bandwidth between packets
double avband = uplinkbandwidth / hspktlist.size();
Iterator<NetworkPacket> it = hspktlist.iterator();
while (it.hasNext()) {
NetworkPacket hspkt = it.next();
double delay = 1000 * hspkt.pkt.data / avband;
this.send(tosend, delay, CloudSimTags.Network_Event_UP, hspkt);
}
hspktlist.clear();
}
}
}
if (packetTohost != null) {
for (Entry<Integer, List<NetworkPacket>> es : packetTohost.entrySet()) {
List<NetworkPacket> hspktlist = es.getValue();
if (!hspktlist.isEmpty()) {
double avband = downlinkbandwidth / hspktlist.size();
Iterator<NetworkPacket> it = hspktlist.iterator();
while (it.hasNext()) {
NetworkPacket hspkt = it.next();
// hspkt.recieverhostid=tosend;
// hs.packetrecieved.add(hspkt);
this.send(getId(), hspkt.pkt.data / avband, CloudSimTags.Network_Event_Host, hspkt);
}
hspktlist.clear();
}
}
}
// or to switch at next level.
// clear the list
}
}

View File

@@ -0,0 +1,57 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
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 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;
virtualrecvid = vrvd;
virtualsendid = vsnd;
}
int sender;
int virtualrecvid;
int virtualsendid;
int reciever;
double data;
double sendtime;
double recievetime;
}

View File

@@ -0,0 +1,689 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.distributions.UniformDistr;
import org.cloudbus.cloudsim.lists.VmList;
/**
* NetDatacentreBroker represents a broker acting on behalf of Datacenter provider. It hides VM
* management, as vm creation, submission of cloudlets to this VMs and destruction of VMs. NOTE- It
* is an example only. It work on behalf of a provider not for users. One has to implement
* interaction with user broker to this broker.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*/
public class NetDatacenterBroker extends SimEntity {
// TODO: remove unnecessary variables
/** The vm list. */
private List<? extends Vm> vmList;
/** The vms created list. */
private List<? extends Vm> vmsCreatedList;
/** The cloudlet list. */
private List<? extends NetworkCloudlet> cloudletList;
private List<? extends AppCloudlet> appCloudletList;
/** The Appcloudlet submitted list. */
private final Map<Integer, Integer> appCloudletRecieved;
private List<? extends Cloudlet> cloudletSubmittedList;
/** The cloudlet received list. */
private List<? extends Cloudlet> cloudletReceivedList;
/** The cloudlets submitted. */
private int cloudletsSubmitted;
/** The vms requested. */
private int vmsRequested;
/** The vms acks. */
private int vmsAcks;
/** The vms destroyed. */
private int vmsDestroyed;
/** The datacenter ids list. */
private List<Integer> datacenterIdsList;
/** The datacenter requested ids list. */
private List<Integer> datacenterRequestedIdsList;
/** The vms to datacenters map. */
private Map<Integer, Integer> vmsToDatacentersMap;
/** The datacenter characteristics list. */
private Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList;
public static NetworkDatacenter linkDC;
public boolean createvmflag = true;
public static int cachedcloudlet = 0;
/**
* Created a new DatacenterBroker object.
*
* @param name name to be associated with this entity (as required by Sim_entity class from
* simjava package)
*
* @throws Exception the exception
*
* @pre name != null
* @post $none
*/
public NetDatacenterBroker(String name) throws Exception {
super(name);
setVmList(new ArrayList<NetworkVm>());
setVmsCreatedList(new ArrayList<NetworkVm>());
setCloudletList(new ArrayList<NetworkCloudlet>());
setAppCloudletList(new ArrayList<AppCloudlet>());
setCloudletSubmittedList(new ArrayList<Cloudlet>());
setCloudletReceivedList(new ArrayList<Cloudlet>());
appCloudletRecieved = new HashMap<Integer, Integer>();
cloudletsSubmitted = 0;
setVmsRequested(0);
setVmsAcks(0);
setVmsDestroyed(0);
setDatacenterIdsList(new LinkedList<Integer>());
setDatacenterRequestedIdsList(new ArrayList<Integer>());
setVmsToDatacentersMap(new HashMap<Integer, Integer>());
setDatacenterCharacteristicsList(new HashMap<Integer, DatacenterCharacteristics>());
}
/**
* This method is used to send to the broker the list with virtual machines that must be
* created.
*
* @param list the list
*
* @pre list !=null
* @post $none
*/
public void submitVmList(List<? extends Vm> list) {
getVmList().addAll(list);
}
/**
* This method is used to send to the broker the list of cloudlets.
*
* @param list the list
*
* @pre list !=null
* @post $none
*/
public void submitCloudletList(List<? extends NetworkCloudlet> list) {
getCloudletList().addAll(list);
}
public void setLinkDC(NetworkDatacenter alinkDC) {
linkDC = alinkDC;
}
/**
* Processes events available for this Broker.
*
* @param ev a SimEvent object
*
* @pre ev != null
* @post $none
*/
@Override
public void processEvent(SimEvent ev) {
switch (ev.getTag()) {
// Resource characteristics request
case CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST:
processResourceCharacteristicsRequest(ev);
break;
// Resource characteristics answer
case CloudSimTags.RESOURCE_CHARACTERISTICS:
processResourceCharacteristics(ev);
break;
// VM Creation answer
// A finished cloudlet returned
case CloudSimTags.CLOUDLET_RETURN:
processCloudletReturn(ev);
break;
// if the simulation finishes
case CloudSimTags.END_OF_SIMULATION:
shutdownEntity();
break;
case CloudSimTags.NextCycle:
if (NetworkConstants.BASE) {
createVmsInDatacenterBase(linkDC.getId());
}
break;
// other unknown tags are processed by this method
default:
processOtherEvent(ev);
break;
}
}
/**
* Process the return of a request for the characteristics of a PowerDatacenter.
*
* @param ev a SimEvent object
*
* @pre ev != $null
* @post $none
*/
protected void processResourceCharacteristics(SimEvent ev) {
DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData();
getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics);
if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) {
setDatacenterRequestedIdsList(new ArrayList<Integer>());
createVmsInDatacenterBase(getDatacenterIdsList().get(0));
}
}
/**
* Process a request for the characteristics of a PowerDatacenter.
*
* @param ev a SimEvent object
*
* @pre ev != $null
* @post $none
*/
protected void processResourceCharacteristicsRequest(SimEvent ev) {
setDatacenterIdsList(CloudSim.getCloudResourceList());
setDatacenterCharacteristicsList(new HashMap<Integer, DatacenterCharacteristics>());
Log.printLine(CloudSim.clock() + ": " + getName() + ": Cloud Resource List received with "
+ getDatacenterIdsList().size() + " resource(s)");
for (Integer datacenterId : getDatacenterIdsList()) {
sendNow(datacenterId, CloudSimTags.RESOURCE_CHARACTERISTICS, getId());
}
}
/**
* Process the ack received due to a request for VM creation.
*
* @param ev a SimEvent object
*
* @pre ev != null
* @post $none
*/
/**
* Process a cloudlet return event.
*
* @param ev a SimEvent object
*
* @pre ev != $null
* @post $none
*/
protected void processCloudletReturn(SimEvent ev) {
Cloudlet cloudlet = (Cloudlet) ev.getData();
getCloudletReceivedList().add(cloudlet);
cloudletsSubmitted--;
// all cloudlets executed
if (getCloudletList().size() == 0 && cloudletsSubmitted == 0 && NetworkConstants.iteration > 10) {
Log.printLine(CloudSim.clock() + ": " + getName() + ": All Cloudlets executed. Finishing...");
clearDatacenters();
finishExecution();
} else { // some cloudlets haven't finished yet
if (getAppCloudletList().size() > 0 && cloudletsSubmitted == 0) {
// all the cloudlets sent finished. It means that some bount
// cloudlet is waiting its VM be created
clearDatacenters();
createVmsInDatacenterBase(0);
}
}
}
/**
* Overrides this method when making a new and different type of Broker. This method is called
* by {@link #body()} for incoming unknown tags.
*
* @param ev a SimEvent object
*
* @pre ev != null
* @post $none
*/
protected void processOtherEvent(SimEvent ev) {
if (ev == null) {
Log.printLine(getName() + ".processOtherEvent(): " + "Error - an event is null.");
return;
}
Log.printLine(getName() + ".processOtherEvent(): "
+ "Error - event unknown by this DatacenterBroker.");
}
/**
* Create the virtual machines in a datacenter and submit/schedule cloudlets to them.
*
* @param datacenterId Id of the chosen PowerDatacenter
*
* @pre $none
* @post $none
*/
protected void createVmsInDatacenterBase(int datacenterId) {
// send as much vms as possible for this datacenter before trying the
// next one
int requestedVms = 0;
// All host will have two VMs (assumption) VM is the minimum unit
if (createvmflag) {
CreateVMs(datacenterId);
createvmflag = false;
}
// generate Application execution Requests
for (int i = 0; i < 100; i++) {
this.getAppCloudletList().add(
new WorkflowApp(AppCloudlet.APP_Workflow, NetworkConstants.currentAppId, 0, 0, getId()));
NetworkConstants.currentAppId++;
}
int k = 0;
// schedule the application on VMs
for (AppCloudlet app : this.getAppCloudletList()) {
List<Integer> vmids = new ArrayList<Integer>();
int numVms = linkDC.getVmList().size();
UniformDistr ufrnd = new UniformDistr(0, numVms, 5);
for (int i = 0; i < app.numbervm; i++) {
int vmid = (int) ufrnd.sample();
vmids.add(vmid);
}
if (vmids != null) {
if (!vmids.isEmpty()) {
app.createCloudletList(vmids);
for (int i = 0; i < app.numbervm; i++) {
app.clist.get(i).setUserId(getId());
appCloudletRecieved.put(app.appID, app.numbervm);
this.getCloudletSubmittedList().add(app.clist.get(i));
cloudletsSubmitted++;
// Sending cloudlet
sendNow(
getVmsToDatacentersMap().get(this.getVmList().get(0).getId()),
CloudSimTags.CLOUDLET_SUBMIT,
app.clist.get(i));
}
System.out.println("app" + (k++));
}
}
}
setAppCloudletList(new ArrayList<AppCloudlet>());
if (NetworkConstants.iteration < 10) {
NetworkConstants.iteration++;
this.schedule(getId(), NetworkConstants.nexttime, CloudSimTags.NextCycle);
}
setVmsRequested(requestedVms);
setVmsAcks(0);
}
private void CreateVMs(int datacenterId) {
// two VMs per host
int numVM = linkDC.getHostList().size() * NetworkConstants.maxhostVM;
for (int i = 0; i < numVM; i++) {
int vmid = i;
int mips = 1;
long size = 10000; // image size (MB)
int ram = 512; // vm memory (MB)
long bw = 1000;
int pesNumber = NetworkConstants.HOST_PEs / NetworkConstants.maxhostVM;
String vmm = "Xen"; // VMM name
// create VM
NetworkVm vm = new NetworkVm(
vmid,
getId(),
mips,
pesNumber,
ram,
bw,
size,
vmm,
new NetworkCloudletSpaceSharedScheduler());
linkDC.processVmCreateNetwork(vm);
// add the VM to the vmList
getVmList().add(vm);
getVmsToDatacentersMap().put(vmid, datacenterId);
getVmsCreatedList().add(VmList.getById(getVmList(), vmid));
}
}
/**
* Submit cloudlets to the created VMs.
*
* @pre $none
* @post $none /** Destroy the virtual machines running in datacenters.
*
* @pre $none
* @post $none
*/
protected void clearDatacenters() {
for (Vm vm : getVmsCreatedList()) {
Log.printLine(CloudSim.clock() + ": " + getName() + ": Destroying VM #" + vm.getId());
sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.VM_DESTROY, vm);
}
getVmsCreatedList().clear();
}
/**
* Send an internal event communicating the end of the simulation.
*
* @pre $none
* @post $none
*/
private void finishExecution() {
sendNow(getId(), CloudSimTags.END_OF_SIMULATION);
}
/*
* (non-Javadoc)
* @see cloudsim.core.SimEntity#shutdownEntity()
*/
@Override
public void shutdownEntity() {
Log.printLine(getName() + " is shutting down...");
}
/*
* (non-Javadoc)
* @see cloudsim.core.SimEntity#startEntity()
*/
@Override
public void startEntity() {
Log.printLine(getName() + " is starting...");
schedule(getId(), 0, CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST);
}
/**
* Gets the vm list.
*
* @param <T> the generic type
* @return the vm list
*/
@SuppressWarnings("unchecked")
public <T extends Vm> List<T> getVmList() {
return (List<T>) vmList;
}
/**
* Sets the vm list.
*
* @param <T> the generic type
* @param vmList the new vm list
*/
protected <T extends Vm> void setVmList(List<T> vmList) {
this.vmList = vmList;
}
/**
* Gets the cloudlet list.
*
* @param <T> the generic type
* @return the cloudlet list
*/
@SuppressWarnings("unchecked")
public <T extends NetworkCloudlet> List<T> getCloudletList() {
return (List<T>) cloudletList;
}
/**
* Sets the cloudlet list.
*
* @param <T> the generic type
* @param cloudletList the new cloudlet list
*/
protected <T extends NetworkCloudlet> void setCloudletList(List<T> cloudletList) {
this.cloudletList = cloudletList;
}
@SuppressWarnings("unchecked")
public <T extends AppCloudlet> List<T> getAppCloudletList() {
return (List<T>) appCloudletList;
}
public <T extends AppCloudlet> void setAppCloudletList(List<T> appCloudletList) {
this.appCloudletList = appCloudletList;
}
/**
* Gets the cloudlet submitted list.
*
* @param <T> the generic type
* @return the cloudlet submitted list
*/
@SuppressWarnings("unchecked")
public <T extends Cloudlet> List<T> getCloudletSubmittedList() {
return (List<T>) cloudletSubmittedList;
}
/**
* Sets the cloudlet submitted list.
*
* @param <T> the generic type
* @param cloudletSubmittedList the new cloudlet submitted list
*/
protected <T extends Cloudlet> void setCloudletSubmittedList(List<T> cloudletSubmittedList) {
this.cloudletSubmittedList = cloudletSubmittedList;
}
/**
* Gets the cloudlet received list.
*
* @param <T> the generic type
* @return the cloudlet received list
*/
@SuppressWarnings("unchecked")
public <T extends Cloudlet> List<T> getCloudletReceivedList() {
return (List<T>) cloudletReceivedList;
}
/**
* Sets the cloudlet received list.
*
* @param <T> the generic type
* @param cloudletReceivedList the new cloudlet received list
*/
protected <T extends Cloudlet> void setCloudletReceivedList(List<T> cloudletReceivedList) {
this.cloudletReceivedList = cloudletReceivedList;
}
/**
* Gets the vm list.
*
* @param <T> the generic type
* @return the vm list
*/
@SuppressWarnings("unchecked")
public <T extends Vm> List<T> getVmsCreatedList() {
return (List<T>) vmsCreatedList;
}
/**
* Sets the vm list.
*
* @param <T> the generic type
* @param vmsCreatedList the vms created list
*/
protected <T extends Vm> void setVmsCreatedList(List<T> vmsCreatedList) {
this.vmsCreatedList = vmsCreatedList;
}
/**
* Gets the vms requested.
*
* @return the vms requested
*/
protected int getVmsRequested() {
return vmsRequested;
}
/**
* Sets the vms requested.
*
* @param vmsRequested the new vms requested
*/
protected void setVmsRequested(int vmsRequested) {
this.vmsRequested = vmsRequested;
}
/**
* Gets the vms acks.
*
* @return the vms acks
*/
protected int getVmsAcks() {
return vmsAcks;
}
/**
* Sets the vms acks.
*
* @param vmsAcks the new vms acks
*/
protected void setVmsAcks(int vmsAcks) {
this.vmsAcks = vmsAcks;
}
/**
* Increment vms acks.
*/
protected void incrementVmsAcks() {
vmsAcks++;
}
/**
* Gets the vms destroyed.
*
* @return the vms destroyed
*/
protected int getVmsDestroyed() {
return vmsDestroyed;
}
/**
* Sets the vms destroyed.
*
* @param vmsDestroyed the new vms destroyed
*/
protected void setVmsDestroyed(int vmsDestroyed) {
this.vmsDestroyed = vmsDestroyed;
}
/**
* Gets the datacenter ids list.
*
* @return the datacenter ids list
*/
protected List<Integer> getDatacenterIdsList() {
return datacenterIdsList;
}
/**
* Sets the datacenter ids list.
*
* @param datacenterIdsList the new datacenter ids list
*/
protected void setDatacenterIdsList(List<Integer> datacenterIdsList) {
this.datacenterIdsList = datacenterIdsList;
}
/**
* Gets the vms to datacenters map.
*
* @return the vms to datacenters map
*/
protected Map<Integer, Integer> getVmsToDatacentersMap() {
return vmsToDatacentersMap;
}
/**
* Sets the vms to datacenters map.
*
* @param vmsToDatacentersMap the vms to datacenters map
*/
protected void setVmsToDatacentersMap(Map<Integer, Integer> vmsToDatacentersMap) {
this.vmsToDatacentersMap = vmsToDatacentersMap;
}
/**
* Gets the datacenter characteristics list.
*
* @return the datacenter characteristics list
*/
protected Map<Integer, DatacenterCharacteristics> getDatacenterCharacteristicsList() {
return datacenterCharacteristicsList;
}
/**
* Sets the datacenter characteristics list.
*
* @param datacenterCharacteristicsList the datacenter characteristics list
*/
protected void setDatacenterCharacteristicsList(
Map<Integer, DatacenterCharacteristics> datacenterCharacteristicsList) {
this.datacenterCharacteristicsList = datacenterCharacteristicsList;
}
/**
* Gets the datacenter requested ids list.
*
* @return the datacenter requested ids list
*/
protected List<Integer> getDatacenterRequestedIdsList() {
return datacenterRequestedIdsList;
}
/**
* Sets the datacenter requested ids list.
*
* @param datacenterRequestedIdsList the new datacenter requested ids list
*/
protected void setDatacenterRequestedIdsList(List<Integer> datacenterRequestedIdsList) {
this.datacenterRequestedIdsList = datacenterRequestedIdsList;
}
}

View File

@@ -0,0 +1,90 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
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<Object> {
long memory;
public NetworkCloudlet(
int cloudletId,
long cloudletLength,
int pesNumber,
long cloudletFileSize,
long cloudletOutputSize,
long memory,
UtilizationModel utilizationModelCpu,
UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw) {
super(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw);
currStagenum = -1;
this.memory = memory;
stages = new ArrayList<TaskStage>();
}
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; // 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) {
return 0;
}
public double getSubmittime() {
return submittime;
}
}

View File

@@ -0,0 +1,797 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.ResCloudlet;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
/**
* CloudletSchedulerSpaceShared implements a policy of scheduling performed by a virtual machine. It
* consider that there will be only one cloudlet per VM. Other cloudlets will be in a waiting list.
* We consider that file transfer from cloudlets waiting happens before cloudlet execution. I.e.,
* even though cloudlets must wait for CPU, data transfer happens as soon as cloudlets are
* submitted.
*
* @author Saurabh Kumar Garg
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*/
public class NetworkCloudletSpaceSharedScheduler extends CloudletScheduler {
/** The cloudlet waiting list. */
private List<? extends ResCloudlet> cloudletWaitingList;
/** The cloudlet exec list. */
private List<? extends ResCloudlet> cloudletExecList;
/** The cloudlet paused list. */
private List<? extends ResCloudlet> cloudletPausedList;
/** The cloudlet finished list. */
private List<? extends ResCloudlet> cloudletFinishedList;
/** The current CPUs. */
protected int currentCpus;
/** The used PEs. */
protected int usedPes;
// for network
public Map<Integer, List<HostPacket>> pkttosend;
public Map<Integer, List<HostPacket>> pktrecv;
/**
* Creates a new CloudletSchedulerSpaceShared object. This method must be invoked before
* starting the actual simulation.
*
* @pre $none
* @post $none
*/
public NetworkCloudletSpaceSharedScheduler() {
super();
cloudletWaitingList = new ArrayList<ResCloudlet>();
cloudletExecList = new ArrayList<ResCloudlet>();
cloudletPausedList = new ArrayList<ResCloudlet>();
cloudletFinishedList = new ArrayList<ResCloudlet>();
usedPes = 0;
currentCpus = 0;
pkttosend = new HashMap<Integer, List<HostPacket>>();
pktrecv = new HashMap<Integer, List<HostPacket>>();
}
/**
* Updates the processing of cloudlets running under management of this scheduler.
*
* @param currentTime current simulation time
* @param mipsShare array with MIPS share of each processor available to the scheduler
* @return time predicted completion time of the earliest finishing cloudlet, or 0 if there is
* no next events
* @pre currentTime >= 0
* @post $none
*/
@Override
public double updateVmProcessing(double currentTime, List<Double> mipsShare) {
setCurrentMipsShare(mipsShare);
// update
double capacity = 0.0;
int cpus = 0;
for (Double mips : mipsShare) { // count the CPUs available to the VMM
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus; // average capacity of each cpu
for (ResCloudlet rcl : getCloudletExecList()) { // each machine in the
// exec list has the
// same amount of cpu
NetworkCloudlet cl = (NetworkCloudlet) rcl.getCloudlet();
// check status
// if execution stage
// update the cloudlet finishtime
// CHECK WHETHER IT IS WAITING FOR THE PACKET
// if packet received change the status of job and update the time.
//
if ((cl.currStagenum != -1)) {
if (cl.currStagenum == NetworkConstants.FINISH) {
break;
}
TaskStage st = cl.stages.get(cl.currStagenum);
if (st.type == NetworkConstants.EXECUTION) {
// update the time
cl.timespentInStage = Math.round(CloudSim.clock() - cl.timetostartStage);
if (cl.timespentInStage >= st.time) {
changetonextstage(cl, st);
// change the stage
}
}
if (st.type == NetworkConstants.WAIT_RECV) {
List<HostPacket> pktlist = pktrecv.get(st.peer);
List<HostPacket> pkttoremove = new ArrayList<HostPacket>();
if (pktlist != null) {
Iterator<HostPacket> it = pktlist.iterator();
HostPacket pkt = null;
if (it.hasNext()) {
pkt = it.next();
// Asumption packet will not arrive in the same cycle
if (pkt.reciever == cl.getVmId()) {
pkt.recievetime = CloudSim.clock();
st.time = CloudSim.clock() - pkt.sendtime;
changetonextstage(cl, st);
pkttoremove.add(pkt);
}
}
pktlist.removeAll(pkttoremove);
// if(pkt!=null)
// else wait for recieving the packet
}
}
} else {
cl.currStagenum = 0;
cl.timetostartStage = CloudSim.clock();
if (cl.stages.get(0).type == NetworkConstants.EXECUTION) {
NetDatacenterBroker.linkDC.schedule(
NetDatacenterBroker.linkDC.getId(),
cl.stages.get(0).time,
CloudSimTags.VM_DATACENTER_EVENT);
} else {
NetDatacenterBroker.linkDC.schedule(
NetDatacenterBroker.linkDC.getId(),
0.0001,
CloudSimTags.VM_DATACENTER_EVENT);
// /sendstage///
}
}
}
if (getCloudletExecList().size() == 0 && getCloudletWaitingList().size() == 0) { // no
// more cloudlets in this scheduler
setPreviousTime(currentTime);
return 0.0;
}
// update each cloudlet
int finished = 0;
List<ResCloudlet> toRemove = new ArrayList<ResCloudlet>();
for (ResCloudlet rcl : getCloudletExecList()) {
// rounding issue...
if (((NetworkCloudlet) (rcl.getCloudlet())).currStagenum == NetworkConstants.FINISH) {
// stage is changed and packet to send
((NetworkCloudlet) (rcl.getCloudlet())).finishtime = CloudSim.clock();
toRemove.add(rcl);
cloudletFinish(rcl);
finished++;
}
}
getCloudletExecList().removeAll(toRemove);
// add all the CloudletExecList in waitingList.
// sort the waitinglist
// for each finished cloudlet, add a new one from the waiting list
if (!getCloudletWaitingList().isEmpty()) {
for (int i = 0; i < finished; i++) {
toRemove.clear();
for (ResCloudlet rcl : getCloudletWaitingList()) {
if ((currentCpus - usedPes) >= rcl.getNumberOfPes()) {
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int k = 0; k < rcl.getNumberOfPes(); k++) {
rcl.setMachineAndPeId(0, i);
}
getCloudletExecList().add(rcl);
usedPes += rcl.getNumberOfPes();
toRemove.add(rcl);
break;
}
}
getCloudletWaitingList().removeAll(toRemove);
}// for(cont)
}
// estimate finish time of cloudlets in the execution queue
double nextEvent = Double.MAX_VALUE;
for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
}
if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime;
}
}
setPreviousTime(currentTime);
return nextEvent;
}
private void changetonextstage(NetworkCloudlet cl, TaskStage st) {
cl.timespentInStage = 0;
cl.timetostartStage = CloudSim.clock();
int currstage = cl.currStagenum;
if (currstage >= (cl.stages.size() - 1)) {
cl.currStagenum = NetworkConstants.FINISH;
} else {
cl.currStagenum = currstage + 1;
int i = 0;
for (i = cl.currStagenum; i < cl.stages.size(); i++) {
if (cl.stages.get(i).type == NetworkConstants.WAIT_SEND) {
HostPacket pkt = new HostPacket(
cl.getVmId(),
cl.stages.get(i).peer,
cl.stages.get(i).data,
CloudSim.clock(),
-1,
cl.getCloudletId(),
cl.stages.get(i).vpeer);
List<HostPacket> pktlist = pkttosend.get(cl.getVmId());
if (pktlist == null) {
pktlist = new ArrayList<HostPacket>();
}
pktlist.add(pkt);
pkttosend.put(cl.getVmId(), pktlist);
} else {
break;
}
}
NetDatacenterBroker.linkDC.schedule(
NetDatacenterBroker.linkDC.getId(),
0.0001,
CloudSimTags.VM_DATACENTER_EVENT);
if (i == cl.stages.size()) {
cl.currStagenum = NetworkConstants.FINISH;
} else {
cl.currStagenum = i;
if (cl.stages.get(i).type == NetworkConstants.EXECUTION) {
NetDatacenterBroker.linkDC.schedule(
NetDatacenterBroker.linkDC.getId(),
cl.stages.get(i).time,
CloudSimTags.VM_DATACENTER_EVENT);
}
}
}
}
/**
* Cancels execution of a cloudlet.
*
* @param cloudletId ID of the cloudlet being cancealed
* @return the canceled cloudlet, $null if not found
* @pre $none
* @post $none
*/
@Override
public Cloudlet cloudletCancel(int cloudletId) {
// First, looks in the finished queue
for (ResCloudlet rcl : getCloudletFinishedList()) {
if (rcl.getCloudletId() == cloudletId) {
getCloudletFinishedList().remove(rcl);
return rcl.getCloudlet();
}
}
// Then searches in the exec list
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) {
getCloudletExecList().remove(rcl);
if (rcl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rcl);
} else {
rcl.setCloudletStatus(Cloudlet.CANCELED);
}
return rcl.getCloudlet();
}
}
// Now, looks in the paused queue
for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) {
getCloudletPausedList().remove(rcl);
return rcl.getCloudlet();
}
}
// Finally, looks in the waiting list
for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) {
rcl.setCloudletStatus(Cloudlet.CANCELED);
getCloudletWaitingList().remove(rcl);
return rcl.getCloudlet();
}
}
return null;
}
/**
* Pauses execution of a cloudlet.
*
* @param cloudletId ID of the cloudlet being paused
* @return $true if cloudlet paused, $false otherwise
* @pre $none
* @post $none
*/
@Override
public boolean cloudletPause(int cloudletId) {
boolean found = false;
int position = 0;
// first, looks for the cloudlet in the exec list
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) {
found = true;
break;
}
position++;
}
if (found) {
// moves to the paused list
ResCloudlet rgl = getCloudletExecList().remove(position);
if (rgl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rgl);
} else {
rgl.setCloudletStatus(Cloudlet.PAUSED);
getCloudletPausedList().add(rgl);
}
return true;
}
// now, look for the cloudlet in the waiting list
position = 0;
found = false;
for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) {
found = true;
break;
}
position++;
}
if (found) {
// moves to the paused list
ResCloudlet rgl = getCloudletWaitingList().remove(position);
if (rgl.getRemainingCloudletLength() == 0.0) {
cloudletFinish(rgl);
} else {
rgl.setCloudletStatus(Cloudlet.PAUSED);
getCloudletPausedList().add(rgl);
}
return true;
}
return false;
}
/**
* Processes a finished cloudlet.
*
* @param rcl finished cloudlet
* @pre rgl != $null
* @post $none
*/
@Override
public void cloudletFinish(ResCloudlet rcl) {
rcl.setCloudletStatus(Cloudlet.SUCCESS);
rcl.finalizeCloudlet();
getCloudletFinishedList().add(rcl);
usedPes -= rcl.getNumberOfPes();
}
/**
* Resumes execution of a paused cloudlet.
*
* @param cloudletId ID of the cloudlet being resumed
* @return $true if the cloudlet was resumed, $false otherwise
* @pre $none
* @post $none
*/
@Override
public double cloudletResume(int cloudletId) {
boolean found = false;
int position = 0;
// look for the cloudlet in the paused list
for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) {
found = true;
break;
}
position++;
}
if (found) {
ResCloudlet rcl = getCloudletPausedList().remove(position);
// it can go to the exec list
if ((currentCpus - usedPes) >= rcl.getNumberOfPes()) {
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < rcl.getNumberOfPes(); i++) {
rcl.setMachineAndPeId(0, i);
}
long size = rcl.getRemainingCloudletLength();
size *= rcl.getNumberOfPes();
rcl.getCloudlet().setCloudletLength(size);
getCloudletExecList().add(rcl);
usedPes += rcl.getNumberOfPes();
// calculate the expected time for cloudlet completion
double capacity = 0.0;
int cpus = 0;
for (Double mips : getCurrentMipsShare()) {
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus;
long remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = CloudSim.clock()
+ (remainingLength / (capacity * rcl.getNumberOfPes()));
return estimatedFinishTime;
} else {// no enough free PEs: go to the waiting queue
rcl.setCloudletStatus(Cloudlet.QUEUED);
long size = rcl.getRemainingCloudletLength();
size *= rcl.getNumberOfPes();
rcl.getCloudlet().setCloudletLength(size);
getCloudletWaitingList().add(rcl);
return 0.0;
}
}
// not found in the paused list: either it is in in the queue, executing
// or not exist
return 0.0;
}
/**
* Receives an cloudlet to be executed in the VM managed by this scheduler.
*
* @param cloudlet the submited cloudlet
* @param fileTransferTime time required to move the required files from the SAN to the VM
* @return expected finish time of this cloudlet, or 0 if it is in the waiting queue
* @pre gl != null
* @post $none
*/
@Override
public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) {
// it can go to the exec list
if ((currentCpus - usedPes) >= cloudlet.getNumberOfPes()) {
ResCloudlet rcl = new ResCloudlet(cloudlet);
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < cloudlet.getNumberOfPes(); i++) {
rcl.setMachineAndPeId(0, i);
}
getCloudletExecList().add(rcl);
usedPes += cloudlet.getNumberOfPes();
} else {// no enough free PEs: go to the waiting queue
ResCloudlet rcl = new ResCloudlet(cloudlet);
rcl.setCloudletStatus(Cloudlet.QUEUED);
getCloudletWaitingList().add(rcl);
return 0.0;
}
// calculate the expected time for cloudlet completion
double capacity = 0.0;
int cpus = 0;
for (Double mips : getCurrentMipsShare()) {
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus;
// use the current capacity to estimate the extra amount of
// time to file transferring. It must be added to the cloudlet length
double extraSize = capacity * fileTransferTime;
long length = cloudlet.getCloudletLength();
length += extraSize;
cloudlet.setCloudletLength(length);
return cloudlet.getCloudletLength() / capacity;
}
/*
* (non-Javadoc)
* @see cloudsim.CloudletScheduler#cloudletSubmit(cloudsim.Cloudlet)
*/
@Override
public double cloudletSubmit(Cloudlet cloudlet) {
cloudletSubmit(cloudlet, 0);
return 0;
}
/**
* Gets the status of a cloudlet.
*
* @param cloudletId ID of the cloudlet
* @return status of the cloudlet, -1 if cloudlet not found
* @pre $none
* @post $none
*/
@Override
public int getCloudletStatus(int cloudletId) {
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getCloudletId() == cloudletId) {
return rcl.getCloudletStatus();
}
}
for (ResCloudlet rcl : getCloudletPausedList()) {
if (rcl.getCloudletId() == cloudletId) {
return rcl.getCloudletStatus();
}
}
for (ResCloudlet rcl : getCloudletWaitingList()) {
if (rcl.getCloudletId() == cloudletId) {
return rcl.getCloudletStatus();
}
}
return -1;
}
/**
* Get utilization created by all cloudlets.
*
* @param time the time
* @return total utilization
*/
@Override
public double getTotalUtilizationOfCpu(double time) {
double totalUtilization = 0;
for (ResCloudlet gl : getCloudletExecList()) {
totalUtilization += gl.getCloudlet().getUtilizationOfCpu(time);
}
return totalUtilization;
}
/**
* Informs about completion of some cloudlet in the VM managed by this scheduler.
*
* @return $true if there is at least one finished cloudlet; $false otherwise
* @pre $none
* @post $none
*/
@Override
public boolean isFinishedCloudlets() {
return getCloudletFinishedList().size() > 0;
}
/**
* Returns the next cloudlet in the finished list, $null if this list is empty.
*
* @return a finished cloudlet
* @pre $none
* @post $none
*/
@Override
public Cloudlet getNextFinishedCloudlet() {
if (getCloudletFinishedList().size() > 0) {
return getCloudletFinishedList().remove(0).getCloudlet();
}
return null;
}
/**
* Returns the number of cloudlets runnning in the virtual machine.
*
* @return number of cloudlets runnning
* @pre $none
* @post $none
*/
@Override
public int runningCloudlets() {
return getCloudletExecList().size();
}
/**
* Returns one cloudlet to migrate to another vm.
*
* @return one running cloudlet
* @pre $none
* @post $none
*/
@Override
public Cloudlet migrateCloudlet() {
ResCloudlet rcl = getCloudletExecList().remove(0);
rcl.finalizeCloudlet();
Cloudlet cl = rcl.getCloudlet();
usedPes -= cl.getNumberOfPes();
return cl;
}
/**
* Gets the cloudlet waiting list.
*
* @param <T> the generic type
* @return the cloudlet waiting list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletWaitingList() {
return (List<T>) cloudletWaitingList;
}
/**
* Cloudlet waiting list.
*
* @param <T> the generic type
* @param cloudletWaitingList the cloudlet waiting list
*/
protected <T extends ResCloudlet> void cloudletWaitingList(List<T> cloudletWaitingList) {
this.cloudletWaitingList = cloudletWaitingList;
}
/**
* Gets the cloudlet exec list.
*
* @param <T> the generic type
* @return the cloudlet exec list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletExecList() {
return (List<T>) cloudletExecList;
}
/**
* Sets the cloudlet exec list.
*
* @param <T> the generic type
* @param cloudletExecList the new cloudlet exec list
*/
protected <T extends ResCloudlet> void setCloudletExecList(List<T> cloudletExecList) {
this.cloudletExecList = cloudletExecList;
}
/**
* Gets the cloudlet paused list.
*
* @param <T> the generic type
* @return the cloudlet paused list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletPausedList() {
return (List<T>) cloudletPausedList;
}
/**
* Sets the cloudlet paused list.
*
* @param <T> the generic type
* @param cloudletPausedList the new cloudlet paused list
*/
protected <T extends ResCloudlet> void setCloudletPausedList(List<T> cloudletPausedList) {
this.cloudletPausedList = cloudletPausedList;
}
/**
* Gets the cloudlet finished list.
*
* @param <T> the generic type
* @return the cloudlet finished list
*/
@SuppressWarnings("unchecked")
protected <T extends ResCloudlet> List<T> getCloudletFinishedList() {
return (List<T>) cloudletFinishedList;
}
/**
* Sets the cloudlet finished list.
*
* @param <T> the generic type
* @param cloudletFinishedList the new cloudlet finished list
*/
protected <T extends ResCloudlet> void setCloudletFinishedList(List<T> cloudletFinishedList) {
this.cloudletFinishedList = cloudletFinishedList;
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler#getCurrentRequestedMips()
*/
@Override
public List<Double> getCurrentRequestedMips() {
List<Double> mipsShare = new ArrayList<Double>();
if (getCurrentMipsShare() != null) {
for (Double mips : getCurrentMipsShare()) {
mipsShare.add(mips);
}
}
return mipsShare;
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler# getTotalCurrentAvailableMipsForCloudlet
* (org.cloudbus.cloudsim.ResCloudlet, java.util.List)
*/
@Override
public double getTotalCurrentAvailableMipsForCloudlet(ResCloudlet rcl, List<Double> mipsShare) {
double capacity = 0.0;
int cpus = 0;
for (Double mips : mipsShare) { // count the cpus available to the vmm
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus; // average capacity of each cpu
return capacity;
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler# getTotalCurrentAllocatedMipsForCloudlet
* (org.cloudbus.cloudsim.ResCloudlet, double)
*/
@Override
public double getTotalCurrentAllocatedMipsForCloudlet(ResCloudlet rcl, double time) {
return 0.0;
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.CloudletScheduler# getTotalCurrentRequestedMipsForCloudlet
* (org.cloudbus.cloudsim.ResCloudlet, double)
*/
@Override
public double getTotalCurrentRequestedMipsForCloudlet(ResCloudlet rcl, double time) {
return 0.0;
}
@Override
public double getCurrentRequestedUtilizationOfBw() {
return 0;
}
@Override
public double getCurrentRequestedUtilizationOfRam() {
return 0;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
public class NetworkConstants {
public static int maxhostVM = 2;
public static int HOST_PEs = 8;
public static double maxMemperVM = 1024 * 1024;// kb
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;
public static final int PES_NUMBER = 4;
public static final int FILE_SIZE = 300;
public static final int OUTPUT_SIZE = 300;
public static final int COMMUNICATION_LENGTH = 1;
public static boolean BASE = true;
public static long BandWidthEdgeAgg = 100 * 1024 * 1024;// 100 Megabits
public static long BandWidthEdgeHost = 100 * 1024 * 1024;//
public static long BandWidthAggRoot = 20 * 1024 * 1024 * 2;// 40gb
public static double SwitchingDelayRoot = .00285;
public static double SwitchingDelayAgg = .00245;// .00245
public static double SwitchingDelayEdge = .00157;// ms
public static double EdgeSwitchPort = 4;// number of host
public static double AggSwitchPort = 1;// number of Edge
public static double RootSwitchPort = 1;// number of Agg
public static double seed = 199;
public static boolean logflag = false;
public static int iteration = 10;
public static int nexttime = 1000;
public static int totaldatatransfer = 0;
}

View File

@@ -0,0 +1,221 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
/**
* NetworkDatacenter class is a Datacenter whose hostList are virtualized and networked. It contains
* all the information about internal network. For example, which VM is connected to Switch etc. It
* deals with processing of VM queries (i.e., handling of VMs) instead of processing
* Cloudlet-related queries. So, even though an AllocPolicy will be instantiated (in the init()
* method of the superclass, it will not be used, as processing of cloudlets are handled by the
* CloudletScheduler and processing of VirtualMachines are handled by the VmAllocationPolicy.
*
* Please refer to following publication for more details:
*
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel Applications in Cloud
* Simulations, Proceedings of the 4th IEEE/ACM International Conference on Utility and Cloud
* Computing (UCC 2011, IEEE CS Press, USA), Melbourne, Australia, December 5-7, 2011.
*
* @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0
*/
public class NetworkDatacenter extends Datacenter {
/**
* Allocates a new NetworkDatacenter object.
*
* @param name the name to be associated with this entity (as required by Sim_entity class from
* simjava package)
* @param characteristics an object of DatacenterCharacteristics
* @param storageList a LinkedList of storage elements, for data simulation
* @param vmAllocationPolicy the vmAllocationPolicy
*
* @throws Exception This happens when one of the following scenarios occur:
* <ul>
* <li>creating this entity before initializing CloudSim package
* <li>this entity name is <tt>null</tt> or empty
* <li>this entity has <tt>zero</tt> number of PEs (Processing Elements). <br>
* No PEs mean the Cloudlets can't be processed. A CloudResource must contain one or
* more Machines. A Machine must contain one or more PEs.
* </ul>
*
* @pre name != null
* @pre resource != null
* @post $none
*/
public NetworkDatacenter(
String name,
DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy,
List<Storage> storageList,
double schedulingInterval) throws Exception {
super(name, characteristics, vmAllocationPolicy, storageList, schedulingInterval);
VmToSwitchid = new HashMap<Integer, Integer>();
HostToSwitchid = new HashMap<Integer, Integer>();
VmtoHostlist = new HashMap<Integer, Integer>();
Switchlist = new HashMap<Integer, Switch>();
}
public Map<Integer, Integer> VmToSwitchid;
public Map<Integer, Integer> HostToSwitchid;
public Map<Integer, Switch> Switchlist;
public Map<Integer, Integer> VmtoHostlist;
/**
* Get list of all EdgeSwitches in the Datacenter network One can design similar functions for
* other type of switches.
*
*/
public Map<Integer, Switch> getEdgeSwitch() {
Map<Integer, Switch> edgeswitch = new HashMap<Integer, Switch>();
for (Entry<Integer, Switch> es : Switchlist.entrySet()) {
if (es.getValue().level == NetworkConstants.EDGE_LEVEL) {
edgeswitch.put(es.getKey(), es.getValue());
}
}
return edgeswitch;
}
/**
* Create the VM within the NetworkDatacenter. It can be directly accessed by Datacenter Broker
* which manage allocation of Cloudlets.
*
*
*/
public boolean processVmCreateNetwork(Vm vm) {
boolean result = getVmAllocationPolicy().allocateHostForVm(vm);
if (result) {
VmToSwitchid.put(vm.getId(), ((NetworkHost) vm.getHost()).sw.getId());
VmtoHostlist.put(vm.getId(), vm.getHost().getId());
System.out.println(vm.getId() + " VM is created on " + vm.getHost().getId());
getVmList().add(vm);
vm.updateVmProcessing(CloudSim.clock(), getVmAllocationPolicy().getHost(vm).getVmScheduler()
.getAllocatedMipsForVm(vm));
}
return result;
}
/**
* Processes a Cloudlet submission.
*
* @param ev a SimEvent object
* @param ack an acknowledgement
*
* @pre ev != null
* @post $none
*/
@Override
protected void processCloudletSubmit(SimEvent ev, boolean ack) {
updateCloudletProcessing();
try {
// gets the Cloudlet object
Cloudlet cl = (Cloudlet) ev.getData();
// checks whether this Cloudlet has finished or not
if (cl.isFinished()) {
String name = CloudSim.getEntityName(cl.getUserId());
Log.printLine(getName() + ": Warning - Cloudlet #" + cl.getCloudletId() + " owned by " + name
+ " is already completed/finished.");
Log.printLine("Therefore, it is not being executed again");
Log.printLine();
// NOTE: If a Cloudlet has finished, then it won't be processed.
// So, if ack is required, this method sends back a result.
// If ack is not required, this method don't send back a result.
// Hence, this might cause CloudSim to be hanged since waiting
// for this Cloudlet back.
if (ack) {
int[] data = new int[3];
data[0] = getId();
data[1] = cl.getCloudletId();
data[2] = CloudSimTags.FALSE;
// unique tag = operation tag
int tag = CloudSimTags.CLOUDLET_SUBMIT_ACK;
sendNow(cl.getUserId(), tag, data);
}
sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_RETURN, cl);
return;
}
// process this Cloudlet to this CloudResource
cl.setResourceParameter(getId(), getCharacteristics().getCostPerSecond(), getCharacteristics()
.getCostPerBw());
int userId = cl.getUserId();
int vmId = cl.getVmId();
// time to transfer the files
double fileTransferTime = predictFileTransferTime(cl.getRequiredFiles());
Host host = getVmAllocationPolicy().getHost(vmId, userId);
Vm vm = host.getVm(vmId, userId);
CloudletScheduler scheduler = vm.getCloudletScheduler();
double estimatedFinishTime = scheduler.cloudletSubmit(cl, fileTransferTime);
if (estimatedFinishTime > 0.0) { // if this cloudlet is in the exec
// time to process the cloudlet
estimatedFinishTime += fileTransferTime;
send(getId(), estimatedFinishTime, CloudSimTags.VM_DATACENTER_EVENT);
// event to update the stages
send(getId(), 0.0001, CloudSimTags.VM_DATACENTER_EVENT);
}
if (ack) {
int[] data = new int[3];
data[0] = getId();
data[1] = cl.getCloudletId();
data[2] = CloudSimTags.TRUE;
// unique tag = operation tag
int tag = CloudSimTags.CLOUDLET_SUBMIT_ACK;
sendNow(cl.getUserId(), tag, data);
}
} catch (ClassCastException c) {
Log.printLine(getName() + ".processCloudletSubmit(): " + "ClassCastException error.");
c.printStackTrace();
} catch (Exception e) {
Log.printLine(getName() + ".processCloudletSubmit(): " + "Exception error.");
e.printStackTrace();
}
checkCloudletCompletion();
}
}

View File

@@ -0,0 +1,202 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.lists.VmList;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/**
* NetworkHost class extends Host to support simulation of networked datacenters. It executes
* actions related to management of packets (send and receive)other than that of virtual machines
* (e.g., creation and destruction). A host has a defined policy for provisioning memory and bw, as
* well as an allocation policy for Pe's to virtual machines.
*
* 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 NetworkHost extends Host {
public List<NetworkPacket> packetTosendLocal;
public List<NetworkPacket> packetTosendGlobal;
public List<NetworkPacket> packetrecieved;
public double memory;
public Switch sw; // Edge switch in general
public double bandwidth;// latency
/** time when last job will finish on CPU1 **/
public List<Double> CPUfinTimeCPU = new ArrayList<Double>();
public double fintime = 0;
public NetworkHost(
int id,
RamProvisioner ramProvisioner,
BwProvisioner bwProvisioner,
long storage,
List<? extends Pe> peList,
VmScheduler vmScheduler) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
packetrecieved = new ArrayList<NetworkPacket>();
packetTosendGlobal = new ArrayList<NetworkPacket>();
packetTosendLocal = new ArrayList<NetworkPacket>();
}
/**
* Requests updating of processing of cloudlets in the VMs running in this host.
*
* @param currentTime the current time
*
* @return expected time of completion of the next cloudlet in all VMs in this host.
* Double.MAX_VALUE if there is no future events expected in th is host
*
* @pre currentTime >= 0.0
* @post $none
*/
@Override
public double updateVmsProcessing(double currentTime) {
double smallerTime = Double.MAX_VALUE;
// insert in each vm packet recieved
recvpackets();
for (Vm vm : super.getVmList()) {
double time = ((NetworkVm) vm).updateVmProcessing(currentTime, getVmScheduler()
.getAllocatedMipsForVm(vm));
if (time > 0.0 && time < smallerTime) {
smallerTime = time;
}
}
// send the packets to other hosts/VMs
sendpackets();
return smallerTime;
}
/**
* Receives packet and forward it to the corresponding VM for processing host.
*
*
*/
private void recvpackets() {
for (NetworkPacket hs : packetrecieved) {
hs.pkt.recievetime = CloudSim.clock();
// insertthe packet in recievedlist of VM
Vm vm = VmList.getById(getVmList(), hs.pkt.reciever);
List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv
.get(hs.pkt.sender);
if (pktlist == null) {
pktlist = new ArrayList<HostPacket>();
((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv.put(
hs.pkt.sender,
pktlist);
}
pktlist.add(hs.pkt);
}
packetrecieved.clear();
}
/**
* Send packet check whether a packet belongs to a local VM or to a VM hosted on other machine.
*
*
*/
private void sendpackets() {
for (Vm vm : super.getVmList()) {
for (Entry<Integer, List<HostPacket>> es : ((NetworkCloudletSpaceSharedScheduler) vm
.getCloudletScheduler()).pkttosend.entrySet()) {
List<HostPacket> pktlist = es.getValue();
for (HostPacket pkt : pktlist) {
NetworkPacket hpkt = new NetworkPacket(getId(), pkt, vm.getId(), pkt.sender);
Vm vm2 = VmList.getById(this.getVmList(), hpkt.recievervmid);
if (vm2 != null) {
packetTosendLocal.add(hpkt);
} else {
packetTosendGlobal.add(hpkt);
}
}
pktlist.clear();
}
}
boolean flag = false;
for (NetworkPacket hs : packetTosendLocal) {
flag = true;
hs.stime = hs.rtime;
hs.pkt.recievetime = CloudSim.clock();
// insertthe packet in recievedlist
Vm vm = VmList.getById(getVmList(), hs.pkt.reciever);
List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv
.get(hs.pkt.sender);
if (pktlist == null) {
pktlist = new ArrayList<HostPacket>();
((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv.put(
hs.pkt.sender,
pktlist);
}
pktlist.add(hs.pkt);
}
if (flag) {
for (Vm vm : super.getVmList()) {
vm.updateVmProcessing(CloudSim.clock(), getVmScheduler().getAllocatedMipsForVm(vm));
}
}
// Sending packet to other VMs therefore packet is forwarded to a Edge switch
packetTosendLocal.clear();
double avband = bandwidth / packetTosendGlobal.size();
for (NetworkPacket hs : packetTosendGlobal) {
double delay = (1000 * hs.pkt.data) / avband;
NetworkConstants.totaldatatransfer += hs.pkt.data;
CloudSim.send(getDatacenter().getId(), sw.getId(), delay, CloudSimTags.Network_Event_UP, hs);
// send to switch with delay
}
packetTosendGlobal.clear();
}
public double getMaxUtilizationAmongVmsPes(Vm vm) {
return PeList.getMaxUtilizationAmongVmsPes(getPeList(), vm);
}
}

View File

@@ -0,0 +1,52 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
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) {
pkt = pkt2;
sendervmid = vmid;
this.cloudletid = cloudletid;
senderhostid = id;
stime = pkt.sendtime;
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
}

View File

@@ -0,0 +1,73 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
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 3.0
*/
public class NetworkVm extends Vm implements Comparable<Object> {
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);
cloudletlist = new ArrayList<NetworkCloudlet>();
}
public ArrayList<NetworkCloudlet> cloudletlist;
int type;
public ArrayList<HostPacket> recvPktlist;
public double memory;
public boolean flagfree;// if true it is free
public double finishtime;
public boolean isFree() {
return flagfree;
}
@Override
public int compareTo(Object arg0) {
NetworkVm hs = (NetworkVm) arg0;
if (hs.finishtime > finishtime) {
return -1;
}
if (hs.finishtime < finishtime) {
return 1;
}
return 0;
}
}

View File

@@ -0,0 +1,277 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* 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 NetworkVmAllocationPolicy extends VmAllocationPolicy {
/** The vm table. */
private Map<String, Host> vmTable;
/** The used pes. */
private Map<String, Integer> usedPes;
/** The free pes. */
private List<Integer> freePes;
/**
* Creates the new VmAllocationPolicySimple object.
*
* @param list the list
*
* @pre $none
* @post $none
*/
public NetworkVmAllocationPolicy(List<? extends Host> list) {
super(list);
setFreePes(new ArrayList<Integer>());
for (Host host : getHostList()) {
getFreePes().add(host.getNumberOfPes());
}
setVmTable(new HashMap<String, Host>());
setUsedPes(new HashMap<String, Integer>());
}
/**
* Allocates a host for a given VM.
*
* @param vm VM specification
*
* @return $true if the host could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public boolean allocateHostForVm(Vm vm) {
int requiredPes = vm.getNumberOfPes();
boolean result = false;
int tries = 0;
List<Integer> freePesTmp = new ArrayList<Integer>();
for (Integer freePes : getFreePes()) {
freePesTmp.add(freePes);
}
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
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());
}
return result;
}
protected double getMaxUtilizationAfterAllocation(NetworkHost host, Vm vm) {
List<Double> allocatedMipsForVm = null;
NetworkHost allocatedHost = (NetworkHost) vm.getHost();
if (allocatedHost != null) {
allocatedMipsForVm = vm.getHost().getAllocatedMipsForVm(vm);
}
if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
return -1;
}
double maxUtilization = host.getMaxUtilizationAmongVmsPes(vm);
host.deallocatePesForVm(vm);
if (allocatedHost != null && allocatedMipsForVm != null) {
vm.getHost().allocatePesForVm(vm, allocatedMipsForVm);
}
return maxUtilization;
}
/**
* Releases the host used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
@Override
public void deallocateHostForVm(Vm vm) {
Host host = getVmTable().remove(vm.getUid());
int idx = getHostList().indexOf(host);
int pes = getUsedPes().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
getFreePes().set(idx, getFreePes().get(idx) + pes);
}
}
/**
* Gets the host that is executing the given VM belonging to the given user.
*
* @param vm the vm
*
* @return the Host with the given vmID and userID; $null if not found
*
* @pre $none
* @post $none
*/
@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}
/**
* Gets the host that is executing the given VM belonging to the given user.
*
* @param vmId the vm id
* @param userId the user id
*
* @return the Host with the given vmID and userID; $null if not found
*
* @pre $none
* @post $none
*/
@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}
/**
* Gets the vm table.
*
* @return the vm table
*/
public Map<String, Host> getVmTable() {
return vmTable;
}
/**
* Sets the vm table.
*
* @param vmTable the vm table
*/
protected void setVmTable(Map<String, Host> vmTable) {
this.vmTable = vmTable;
}
/**
* Gets the used pes.
*
* @return the used pes
*/
protected Map<String, Integer> getUsedPes() {
return usedPes;
}
/**
* Sets the used pes.
*
* @param usedPes the used pes
*/
protected void setUsedPes(Map<String, Integer> usedPes) {
this.usedPes = usedPes;
}
/**
* Gets the free pes.
*
* @return the free pes
*/
protected List<Integer> getFreePes() {
return freePes;
}
/**
* Sets the free pes.
*
* @param freePes the new free pes
*/
protected void setFreePes(List<Integer> freePes) {
this.freePes = freePes;
}
/*
* (non-Javadoc)
* @see cloudsim.VmAllocationPolicy#optimizeAllocation(double, cloudsim.VmList, double)
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm,
* org.cloudbus.cloudsim.Host)
*/
@Override
public boolean allocateHostForVm(Vm vm, Host host) {
if (host.vmCreate(vm)) { // if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), host);
int requiredPes = vm.getNumberOfPes();
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;
}
return false;
}
}

View File

@@ -0,0 +1,97 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* 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<NetworkPacket>>();
downlinkswitches = new ArrayList<Switch>();
downlinkbandwidth = NetworkConstants.BandWidthAggRoot;
latency = NetworkConstants.SwitchingDelayRoot;
numport = NetworkConstants.RootSwitchPort;
}
/**
* 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
NetworkPacket hspkt = (NetworkPacket) ev.getData();
int recvVMid = hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(), switching_delay, CloudSimTags.Network_Event_send);
if (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 : 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 = downlinkswitchpktlist.get(aggSwtichid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
}

View File

@@ -0,0 +1,386 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
import org.cloudbus.cloudsim.lists.VmList;
public class Switch extends SimEntity {
// switch level
public int id;
public int level;// three levels
public int datacenterid;
public Map<Integer, List<NetworkPacket>> uplinkswitchpktlist;
public Map<Integer, List<NetworkPacket>> downlinkswitchpktlist;
public Map<Integer, NetworkHost> hostlist;
public List<Switch> uplinkswitches;
public List<Switch> downlinkswitches;
public Map<Integer, List<NetworkPacket>> packetTohost;
int type;// edge switch or aggregation switch
public double uplinkbandwidth;
public double downlinkbandwidth;
public double latency;
public double numport;
public NetworkDatacenter dc;
// something is running on these hosts
public SortedMap<Double, List<NetworkHost>> fintimelistHost = new TreeMap<Double, List<NetworkHost>>();
// something is running on these hosts
public SortedMap<Double, List<NetworkVm>> fintimelistVM = new TreeMap<Double, List<NetworkVm>>();
public ArrayList<NetworkPacket> pktlist;
public List<Vm> BagofTaskVm = new ArrayList<Vm>();
public double switching_delay;
public Map<Integer, NetworkVm> Vmlist;
public Switch(String name, int level, NetworkDatacenter dc) {
super(name);
this.level = level;
this.dc = dc;
}
@Override
public void startEntity() {
Log.printLine(getName() + " is starting...");
schedule(getId(), 0, CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST);
}
@Override
public void processEvent(SimEvent ev) {
// Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag());
switch (ev.getTag()) {
// Resource characteristics request
case CloudSimTags.Network_Event_UP:
// process the packet from down switch or host
processpacket_up(ev);
break;
case CloudSimTags.Network_Event_DOWN:
// process the packet from uplink
processpacket_down(ev);
break;
case CloudSimTags.Network_Event_send:
processpacketforward(ev);
break;
case CloudSimTags.Network_Event_Host:
processhostpacket(ev);
break;
// Resource characteristics answer
case CloudSimTags.RESOURCE_Register:
registerHost(ev);
break;
// other unknown tags are processed by this method
default:
processOtherEvent(ev);
break;
}
}
protected void processhostpacket(SimEvent ev) {
// Send packet to host
NetworkPacket hspkt = (NetworkPacket) ev.getData();
NetworkHost hs = hostlist.get(hspkt.recieverhostid);
hs.packetrecieved.add(hspkt);
}
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
// 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(), latency, CloudSimTags.Network_Event_send);
if (level == NetworkConstants.EDGE_LEVEL) {
// packet is to be recieved by host
int hostid = dc.VmtoHostlist.get(recvVMid);
hspkt.recieverhostid = hostid;
List<NetworkPacket> pktlist = packetTohost.get(hostid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
packetTohost.put(hostid, pktlist);
}
pktlist.add(hspkt);
return;
}
if (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 = downlinkswitchpktlist.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
return;
}
}
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(), switching_delay, CloudSimTags.Network_Event_send);
if (level == NetworkConstants.EDGE_LEVEL) {
// packet is recieved from host
// packet is to be sent to aggregate level or to another host in the
// same level
int hostid = dc.VmtoHostlist.get(recvVMid);
NetworkHost hs = hostlist.get(hostid);
hspkt.recieverhostid = hostid;
if (hs != null) {
// packet to be sent to host connected to the switch
List<NetworkPacket> pktlist = packetTohost.get(hostid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
packetTohost.put(hostid, pktlist);
}
pktlist.add(hspkt);
return;
}
// packet is to be sent to upper switch
// ASSUMPTION EACH EDGE is Connected to one aggregate level switch
Switch sw = uplinkswitches.get(0);
List<NetworkPacket> pktlist = uplinkswitchpktlist.get(sw.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
return;
}
if (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 : downlinkswitches) {
if (switchid == sw.getId()) {
flagtoswtich = true;
}
}
if (flagtoswtich) {
List<NetworkPacket> pktlist = downlinkswitchpktlist.get(switchid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
downlinkswitchpktlist.put(switchid, pktlist);
}
pktlist.add(hspkt);
} else// send to up
{
Switch sw = uplinkswitches.get(0);
List<NetworkPacket> pktlist = uplinkswitchpktlist.get(sw.getId());
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
uplinkswitchpktlist.put(sw.getId(), pktlist);
}
pktlist.add(hspkt);
}
}
if (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 : 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 = downlinkswitchpktlist.get(aggSwtichid);
if (pktlist == null) {
pktlist = new ArrayList<NetworkPacket>();
downlinkswitchpktlist.put(aggSwtichid, pktlist);
}
pktlist.add(hspkt);
}
}
}
private void registerHost(SimEvent ev) {
NetworkHost hs = (NetworkHost) ev.getData();
hostlist.put(hs.getId(), (NetworkHost) ev.getData());
}
protected void processpacket(SimEvent ev) {
// send packet to itself with switching delay (discarding other)
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_UP));
schedule(getId(), switching_delay, CloudSimTags.Network_Event_UP);
pktlist.add((NetworkPacket) ev.getData());
// add the packet in the list
}
private void processOtherEvent(SimEvent ev) {
}
protected void processpacketforward(SimEvent ev) {
// search for the host and packets..send to them
if (downlinkswitchpktlist != null) {
for (Entry<Integer, List<NetworkPacket>> es : downlinkswitchpktlist.entrySet()) {
int tosend = es.getKey();
List<NetworkPacket> hspktlist = es.getValue();
if (!hspktlist.isEmpty()) {
double avband = downlinkbandwidth / hspktlist.size();
Iterator<NetworkPacket> it = hspktlist.iterator();
while (it.hasNext()) {
NetworkPacket hspkt = it.next();
double delay = 1000 * hspkt.pkt.data / avband;
this.send(tosend, delay, CloudSimTags.Network_Event_DOWN, hspkt);
}
hspktlist.clear();
}
}
}
if (uplinkswitchpktlist != null) {
for (Entry<Integer, List<NetworkPacket>> es : uplinkswitchpktlist.entrySet()) {
int tosend = es.getKey();
List<NetworkPacket> hspktlist = es.getValue();
if (!hspktlist.isEmpty()) {
double avband = uplinkbandwidth / hspktlist.size();
Iterator<NetworkPacket> it = hspktlist.iterator();
while (it.hasNext()) {
NetworkPacket hspkt = it.next();
double delay = 1000 * hspkt.pkt.data / avband;
this.send(tosend, delay, CloudSimTags.Network_Event_UP, hspkt);
}
hspktlist.clear();
}
}
}
if (packetTohost != null) {
for (Entry<Integer, List<NetworkPacket>> es : packetTohost.entrySet()) {
List<NetworkPacket> hspktlist = es.getValue();
if (!hspktlist.isEmpty()) {
double avband = downlinkbandwidth / hspktlist.size();
Iterator<NetworkPacket> it = hspktlist.iterator();
while (it.hasNext()) {
NetworkPacket hspkt = it.next();
// hspkt.recieverhostid=tosend;
// hs.packetrecieved.add(hspkt);
this.send(getId(), hspkt.pkt.data / avband, CloudSimTags.Network_Event_Host, hspkt);
}
hspktlist.clear();
}
}
}
// or to switch at next level.
// clear the list
}
//
// R: We changed visibility of the below methods from private to protected.
//
protected NetworkHost getHostwithVM(int vmid) {
for (Entry<Integer, NetworkHost> es : hostlist.entrySet()) {
Vm vm = VmList.getById(es.getValue().getVmList(), vmid);
if (vm != null) {
return es.getValue();
}
}
return null;
}
protected List<NetworkVm> getfreeVmlist(int numVMReq) {
List<NetworkVm> freehostls = new ArrayList<NetworkVm>();
for (Entry<Integer, NetworkVm> et : Vmlist.entrySet()) {
if (et.getValue().isFree()) {
freehostls.add(et.getValue());
}
if (freehostls.size() == numVMReq) {
break;
}
}
return freehostls;
}
protected List<NetworkHost> getfreehostlist(int numhost) {
List<NetworkHost> freehostls = new ArrayList<NetworkHost>();
for (Entry<Integer, NetworkHost> et : hostlist.entrySet()) {
if (et.getValue().getNumberOfFreePes() == et.getValue().getNumberOfPes()) {
freehostls.add(et.getValue());
}
if (freehostls.size() == numhost) {
break;
}
}
return freehostls;
}
@Override
public void shutdownEntity() {
Log.printLine(getName() + " is shutting down...");
}
}

View File

@@ -0,0 +1,52 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
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) {
super();
this.type = type;
this.data = data;
this.time = time;
this.stageid = stageid;
this.memory = memory;
this.peer = peer;
this.vpeer = vpeer;
}
int vpeer;
int type;// execution, recv, send,
double data;// data generated or send or recv
double time;// execution time for this stage
double stageid;
long memory;
int peer;// from whom data needed to be recieved or send
}

View File

@@ -0,0 +1,138 @@
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.network.datacenter;
import java.util.List;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* 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
*/
public class WorkflowApp extends AppCloudlet {
public WorkflowApp(int type, int appID, double deadline, int numbervm, int userId) {
super(type, appID, deadline, numbervm, userId);
exeTime = 100;
this.numbervm = 3;
}
@Override
public void createCloudletList(List<Integer> vmIdList) {
long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = NetworkConstants.OUTPUT_SIZE;
int memory = 100;
UtilizationModel utilizationModel = new UtilizationModelFull();
int i = 0;
// Task A
NetworkCloudlet cl = new NetworkCloudlet(
NetworkConstants.currentCloudletId,
0,
1,
fileSize,
outputSize,
memory,
utilizationModel,
utilizationModel,
utilizationModel);
cl.numStage = 2;
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(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(
NetworkConstants.currentCloudletId,
0,
1,
fileSize,
outputSize,
memory,
utilizationModel,
utilizationModel,
utilizationModel);
clb.numStage = 2;
NetworkConstants.currentCloudletId++;
clb.setUserId(userId);
clb.submittime = CloudSim.clock();
clb.currStagenum = -1;
clb.setVmId(vmIdList.get(i));
// first stage: big computation
clb.stages.add(new TaskStage(
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(
NetworkConstants.currentCloudletId,
0,
1,
fileSize,
outputSize,
memory,
utilizationModel,
utilizationModel,
utilizationModel);
clc.numStage = 2;
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(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);
}
}