Commit 4f25a01a authored by rodrigo.calheiros's avatar rodrigo.calheiros

Removed warnings from Network package

parent b463216f
package org.cloudbus.cloudsim.examples.network.datacenter; package org.cloudbus.cloudsim.examples.network.datacenter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -10,20 +8,13 @@ import java.util.LinkedList; ...@@ -10,20 +8,13 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared;
import org.cloudbus.cloudsim.DatacenterCharacteristics; import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host; import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log; import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe; import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage; import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared; import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.distributions.UniformDistr;
import org.cloudbus.cloudsim.network.datacenter.AppCloudlet;
import org.cloudbus.cloudsim.network.datacenter.EdgeSwitch; import org.cloudbus.cloudsim.network.datacenter.EdgeSwitch;
import org.cloudbus.cloudsim.network.datacenter.NetDatacenterBroker; import org.cloudbus.cloudsim.network.datacenter.NetDatacenterBroker;
import org.cloudbus.cloudsim.network.datacenter.NetworkConstants; import org.cloudbus.cloudsim.network.datacenter.NetworkConstants;
...@@ -37,13 +28,6 @@ import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; ...@@ -37,13 +28,6 @@ import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
public class TestExample { public class TestExample {
/**
* @param args
*/
/** The cloudlet list. */
private static List<AppCloudlet> cloudletList;
/** The vmlist. */ /** The vmlist. */
private static List<NetworkVm> vmlist; private static List<NetworkVm> vmlist;
...@@ -72,11 +56,9 @@ public class TestExample { ...@@ -72,11 +56,9 @@ public class TestExample {
// Third step: Create Broker // Third step: Create Broker
NetDatacenterBroker broker = createBroker(); NetDatacenterBroker broker = createBroker();
int brokerId = broker.getId();
broker.setLinkDC(datacenter0); broker.setLinkDC(datacenter0);
// broker.setLinkDC(datacenter0); // broker.setLinkDC(datacenter0);
// Fifth step: Create one Cloudlet // Fifth step: Create one Cloudlet
cloudletList = new ArrayList<AppCloudlet>();
vmlist = new ArrayList<NetworkVm>(); vmlist = new ArrayList<NetworkVm>();
...@@ -92,9 +74,9 @@ public class TestExample { ...@@ -92,9 +74,9 @@ public class TestExample {
// Final step: Print results when simulation is over // Final step: Print results when simulation is over
List<Cloudlet> newList = broker.getCloudletReceivedList(); List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList); printCloudletList(newList);
System.out.println("numberofcloudlet " + newList.size() System.out.println("numberofcloudlet " + newList.size() + " Cached "
+ " Cached " + NetDatacenterBroker.cachedcloudlet + NetDatacenterBroker.cachedcloudlet + " Data transfered "
+ " Data transfered " + NetworkConstants.totaldatatransfer); + NetworkConstants.totaldatatransfer);
// Print the debt of each user to each datacenter // Print the debt of each user to each datacenter
datacenter0.printDebts(); datacenter0.printDebts();
...@@ -133,70 +115,72 @@ public class TestExample { ...@@ -133,70 +115,72 @@ public class TestExample {
// 4. Create Host with its id and list of PEs and add them to the list // 4. Create Host with its id and list of PEs and add them to the list
// of machines // of machines
int hostId = 0;
int ram = 2048; // host memory (MB) int ram = 2048; // host memory (MB)
long storage = 1000000; // host storage long storage = 1000000; // host storage
int bw = 10000; int bw = 10000;
for (int i = 0; i < NetworkConstants.EdgeSwitchPort for (int i = 0; i < NetworkConstants.EdgeSwitchPort * NetworkConstants.AggSwitchPort
* NetworkConstants.AggSwitchPort
* NetworkConstants.RootSwitchPort; i++) { * NetworkConstants.RootSwitchPort; i++) {
// 2. A Machine contains one or more PEs or CPUs/Cores. // 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core. // In this example, it will have only one core.
// 3. Create PEs and add these into an object of PowerPeList. // 3. Create PEs and add these into an object of PowerPeList.
List<Pe> peList = new ArrayList<Pe>(); List<Pe> peList = new ArrayList<Pe>();
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(1, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(1, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(2, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(2, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(3, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(3, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(4, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(4, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(5, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(5, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(6, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(6, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
peList.add(new Pe(7, new PeProvisionerSimple(mips))); // need to peList.add(new Pe(7, new PeProvisionerSimple(mips))); // need to
// store // store
// PowerPe // PowerPe
// id and // id and
// MIPS // MIPS
// Rating // Rating
// 4. Create PowerHost with its id and list of PEs and add them to // 4. Create PowerHost with its id and list of PEs and add them to
// the list of machines // the list of machines
hostList.add(new NetworkHost(i, new RamProvisionerSimple(ram), hostList.add(new NetworkHost(
new BwProvisionerSimple(bw), storage, peList, i,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerTimeShared(peList))); // This is our machine new VmSchedulerTimeShared(peList))); // This is our machine
} }
...@@ -211,23 +195,34 @@ public class TestExample { ...@@ -211,23 +195,34 @@ public class TestExample {
double cost = 3.0; // the cost of using processing in this resource double cost = 3.0; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.001; // the cost of using storage in this double costPerStorage = 0.001; // the cost of using storage in this
// resource // resource
double costPerBw = 0.0; // the cost of using bw in this resource double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are
// not // not
// adding // adding
// SAN // SAN
// devices by now // devices by now
DatacenterCharacteristics characteristics = new DatacenterCharacteristics( DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem, arch,
costPerStorage, costPerBw); os,
vmm,
hostList,
time_zone,
cost,
costPerMem,
costPerStorage,
costPerBw);
// 6. Finally, we need to create a NetworkDatacenter object. // 6. Finally, we need to create a NetworkDatacenter object.
NetworkDatacenter datacenter = null; NetworkDatacenter datacenter = null;
try { try {
datacenter = new NetworkDatacenter(name, characteristics, datacenter = new NetworkDatacenter(
new NetworkVmAllocationPolicy(hostList), storageList, 0); name,
characteristics,
new NetworkVmAllocationPolicy(hostList),
storageList,
0);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -263,17 +258,14 @@ public class TestExample { ...@@ -263,17 +258,14 @@ public class TestExample {
* list of Cloudlets * list of Cloudlets
* @throws IOException * @throws IOException
*/ */
private static void printCloudletList(List<Cloudlet> list) private static void printCloudletList(List<Cloudlet> list) throws IOException {
throws IOException {
int size = list.size(); int size = list.size();
Cloudlet cloudlet; Cloudlet cloudlet;
double fintime = 0;
String indent = " "; String indent = " ";
Log.printLine(); Log.printLine();
Log.printLine("========== OUTPUT =========="); Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + "Data center ID" + indent + "VM ID"
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+ indent + "Start Time" + indent + "Finish Time");
DecimalFormat dft = new DecimalFormat("###.##"); DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
...@@ -282,13 +274,9 @@ public class TestExample { ...@@ -282,13 +274,9 @@ public class TestExample {
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
Log.print("SUCCESS"); Log.print("SUCCESS");
fintime = cloudlet.getFinishTime(); Log.printLine(indent + indent + cloudlet.getResourceId() + indent + indent + indent
Log.printLine(indent + indent + cloudlet.getResourceId() + cloudlet.getVmId() + indent + indent + dft.format(cloudlet.getActualCPUTime())
+ indent + indent + indent + cloudlet.getVmId() + indent + indent + dft.format(cloudlet.getExecStartTime()) + indent + indent
+ indent + indent
+ dft.format(cloudlet.getActualCPUTime()) + indent
+ indent + dft.format(cloudlet.getExecStartTime())
+ indent + indent
+ dft.format(cloudlet.getFinishTime())); + dft.format(cloudlet.getFinishTime()));
} }
} }
...@@ -297,24 +285,11 @@ public class TestExample { ...@@ -297,24 +285,11 @@ public class TestExample {
static void CreateNetwork(int numhost, NetworkDatacenter dc) { static void CreateNetwork(int numhost, NetworkDatacenter dc) {
// //Root Switch
// Switch swroot=new Switch("Root", Constants.ROOT_LEVEL, dc);
// dc.Switchlist.put(swroot.getId(), swroot);
// //Agg Switch
// Switch aggswitch[]=new Switch[(int) Constants.RootSwitchPort];
// for(int j=0;j<Constants.RootSwitchPort;j++)
// {
// aggswitch[j]=new Switch("Agg"+j, Constants.Agg_LEVEL, dc);
// swroot.downlinkswitches.add(aggswitch[j]);
// aggswitch[j].uplinkswitches.add(swroot);
// dc.Switchlist.put(aggswitch[j].getId(), aggswitch[j]);
// }
// Edge Switch // Edge Switch
EdgeSwitch edgeswitch[] = new EdgeSwitch[1]; EdgeSwitch edgeswitch[] = new EdgeSwitch[1];
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
edgeswitch[i] = new EdgeSwitch("Edge" + i, edgeswitch[i] = new EdgeSwitch("Edge" + i, NetworkConstants.EDGE_LEVEL, dc);
NetworkConstants.EDGE_LEVEL, dc);
// edgeswitch[i].uplinkswitches.add(null); // edgeswitch[i].uplinkswitches.add(null);
dc.Switchlist.put(edgeswitch[i].getId(), edgeswitch[i]); dc.Switchlist.put(edgeswitch[i].getId(), edgeswitch[i]);
// aggswitch[(int) // aggswitch[(int)
......
...@@ -16,10 +16,10 @@ import org.cloudbus.cloudsim.core.predicates.PredicateType; ...@@ -16,10 +16,10 @@ import org.cloudbus.cloudsim.core.predicates.PredicateType;
* It interacts with other switches in order to exchange * It interacts with other switches in order to exchange
* packets. Please refer to following publication for more details: * packets. Please refer to following publication for more details:
* *
* Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel * Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM International * Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM International
* Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA), * Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA),
* Melbourne, Australia, December 5-7, 2011. * Melbourne, Australia, December 5-7, 2011.
* *
* @author Saurabh Kumar Garg * @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0 * @since CloudSim Toolkit 3.0
...@@ -31,25 +31,24 @@ public class EdgeSwitch extends Switch{ ...@@ -31,25 +31,24 @@ public class EdgeSwitch extends Switch{
/** /**
* Constructor for Edge Switch * Constructor for Edge Switch
* We have to specify switches that are connected to its downlink and uplink ports, * We have to specify switches that are connected to its downlink and uplink ports,
* and corresponding bandwidths. In this switch downlink ports are * and corresponding bandwidths. In this switch downlink ports are
* connected to hosts not to a switch. * connected to hosts not to a switch.
* *
* @param name Name of the switch * @param name Name of the switch
* @param level At which level switch is with respect to hosts. * @param level At which level switch is with respect to hosts.
* @param dc Pointer to Datacenter * @param dc Pointer to Datacenter
*/ */
public EdgeSwitch(String name, int level, NetworkDatacenter dc) { public EdgeSwitch(String name, int level, NetworkDatacenter dc) {
super(name, level, dc); super(name, level, dc);
hostlist=new HashMap<Integer,NetworkHost>(); hostlist=new HashMap<Integer,NetworkHost>();
uplinkswitchpktlist=new HashMap<Integer,List<NetworkPacket>>(); uplinkswitchpktlist=new HashMap<Integer,List<NetworkPacket>>();
packetTohost=new HashMap<Integer,List<NetworkPacket>>(); packetTohost=new HashMap<Integer,List<NetworkPacket>>();
uplinkbandwidth=NetworkConstants.BandWidthEdgeAgg; uplinkbandwidth=NetworkConstants.BandWidthEdgeAgg;
downlinkbandwidth=NetworkConstants.BandWidthEdgeHost; downlinkbandwidth=NetworkConstants.BandWidthEdgeHost;
this.switching_delay=NetworkConstants.SwitchingDelayEdge; this.switching_delay=NetworkConstants.SwitchingDelayEdge;
numport=NetworkConstants.EdgeSwitchPort; numport=NetworkConstants.EdgeSwitchPort;
uplinkswitches=new ArrayList<Switch>(); uplinkswitches=new ArrayList<Switch>();
// TODO Auto-generated constructor stub
} }
/** /**
* Send Packet to switch connected through a uplink port * Send Packet to switch connected through a uplink port
...@@ -58,66 +57,64 @@ public class EdgeSwitch extends Switch{ ...@@ -58,66 +57,64 @@ public class EdgeSwitch extends Switch{
*/ */
@Override @Override
protected void processpacket_up(SimEvent ev) { protected void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub
//packet coming from down level router/host. //packet coming from down level router/host.
//has to send up //has to send up
//check which switch to forward to //check which switch to forward to
//add packet in the switch list //add packet in the switch list
// //
//int src=ev.getSource(); //int src=ev.getSource();
NetworkPacket hspkt=(NetworkPacket) ev.getData(); NetworkPacket hspkt=(NetworkPacket) ev.getData();
int recvVMid=hspkt.pkt.reciever; int recvVMid=hspkt.pkt.reciever;
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send)); CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_send));
schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send); schedule(getId(),this.switching_delay, CloudSimTags.Network_Event_send);
// packet is recieved from host // packet is recieved from host
//packet is to be sent to aggregate level or to another host in the same level //packet is to be sent to aggregate level or to another host in the same level
int hostid=dc.VmtoHostlist.get(recvVMid); int hostid=dc.VmtoHostlist.get(recvVMid);
NetworkHost hs=this.hostlist.get(hostid); NetworkHost hs=this.hostlist.get(hostid);
hspkt.recieverhostid=hostid; hspkt.recieverhostid=hostid;
//packet needs to go to a host which is connected directly to switch //packet needs to go to a host which is connected directly to switch
if(hs!=null) if(hs!=null)
{ {
//packet to be sent to host connected to the switch //packet to be sent to host connected to the switch
List<NetworkPacket> pktlist=this.packetTohost.get(hostid); List<NetworkPacket> pktlist=this.packetTohost.get(hostid);
if(pktlist==null){ if(pktlist==null){
pktlist=new ArrayList<NetworkPacket>(); pktlist=new ArrayList<NetworkPacket>();
this.packetTohost.put(hostid, pktlist); this.packetTohost.put(hostid, pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
return; return;
} }
//otherwise //otherwise
//packet is to be sent to upper switch //packet is to be sent to upper switch
//ASSUMPTION EACH EDGE is Connected to one aggregate level 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 //if there are more than one Aggregate level switch one need to modify following code
Switch sw=this.uplinkswitches.get(0); Switch sw=this.uplinkswitches.get(0);
List<NetworkPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId()); List<NetworkPacket> pktlist=this.uplinkswitchpktlist.get(sw.getId());
if(pktlist==null){ if(pktlist==null){
pktlist=new ArrayList<NetworkPacket>(); pktlist=new ArrayList<NetworkPacket>();
this.uplinkswitchpktlist.put(sw.getId(), pktlist); this.uplinkswitchpktlist.put(sw.getId(), pktlist);
} }
pktlist.add(hspkt); pktlist.add(hspkt);
return; return;
} }
/** /**
* Send Packet to hosts connected to the switch * Send Packet to hosts connected to the switch
* *
* @param ev Event/packet to process * @param ev Event/packet to process
*/ */
@Override @Override
protected void processpacketforward(SimEvent ev) { protected void processpacketforward(SimEvent ev) {
// TODO Auto-generated method stub
//search for the host and packets..send to them //search for the host and packets..send to them
if(this.uplinkswitchpktlist!=null) if(this.uplinkswitchpktlist!=null)
{ {
for(Entry<Integer, List<NetworkPacket>> es:uplinkswitchpktlist.entrySet()) for(Entry<Integer, List<NetworkPacket>> es:uplinkswitchpktlist.entrySet())
...@@ -132,7 +129,7 @@ public class EdgeSwitch extends Switch{ ...@@ -132,7 +129,7 @@ public class EdgeSwitch extends Switch{
{ {
NetworkPacket hspkt=it.next(); NetworkPacket hspkt=it.next();
double delay=1000*hspkt.pkt.data/avband; double delay=1000*hspkt.pkt.data/avband;
this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt); this.send(tosend,delay,CloudSimTags.Network_Event_UP, hspkt);
} }
hspktlist.clear(); hspktlist.clear();
...@@ -143,8 +140,6 @@ public class EdgeSwitch extends Switch{ ...@@ -143,8 +140,6 @@ public class EdgeSwitch extends Switch{
{ {
for(Entry<Integer, List<NetworkPacket>> es:packetTohost.entrySet()) for(Entry<Integer, List<NetworkPacket>> es:packetTohost.entrySet())
{ {
int tosend=es.getKey();
NetworkHost hs=this.hostlist.get(tosend);
List<NetworkPacket> hspktlist=es.getValue(); List<NetworkPacket> hspktlist=es.getValue();
if(!hspktlist.isEmpty()){ if(!hspktlist.isEmpty()){
double avband=this.downlinkbandwidth/hspktlist.size(); double avband=this.downlinkbandwidth/hspktlist.size();
...@@ -157,13 +152,13 @@ public class EdgeSwitch extends Switch{ ...@@ -157,13 +152,13 @@ public class EdgeSwitch extends Switch{
} }
hspktlist.clear(); hspktlist.clear();
} }
} }
} }
//or to switch at next level. //or to switch at next level.
//clear the list //clear the list
} }
......
...@@ -13,14 +13,8 @@ import java.util.HashMap; ...@@ -13,14 +13,8 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared;
import org.cloudbus.cloudsim.DatacenterCharacteristics; import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log; import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
...@@ -29,14 +23,13 @@ import org.cloudbus.cloudsim.core.CloudSimTags; ...@@ -29,14 +23,13 @@ import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEntity; import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.SimEvent; import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.distributions.UniformDistr; import org.cloudbus.cloudsim.distributions.UniformDistr;
import org.cloudbus.cloudsim.lists.CloudletList;
import org.cloudbus.cloudsim.lists.VmList; import org.cloudbus.cloudsim.lists.VmList;
/** /**
* NetDatacentreBroker represents a broker acting on behalf of Datacenter * NetDatacentreBroker represents a broker acting on behalf of Datacenter
* provider. It hides VM management, as vm creation, submission of cloudlets to * 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 * 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. * users. One has to implement interaction with user broker to this broker.
* *
* @author Saurabh Kumar Garg * @author Saurabh Kumar Garg
* @since CloudSim Toolkit 3.0 * @since CloudSim Toolkit 3.0
...@@ -56,7 +49,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -56,7 +49,7 @@ public class NetDatacenterBroker extends SimEntity {
private List<? extends AppCloudlet> appCloudletList; private List<? extends AppCloudlet> appCloudletList;
/** The Appcloudlet submitted list. */ /** The Appcloudlet submitted list. */
private Map<Integer, Integer> appCloudletRecieved; private final Map<Integer, Integer> appCloudletRecieved;
private List<? extends Cloudlet> cloudletSubmittedList; private List<? extends Cloudlet> cloudletSubmittedList;
...@@ -170,8 +163,8 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -170,8 +163,8 @@ public class NetDatacenterBroker extends SimEntity {
// public void bindCloudletToVm(int cloudletId, int vmId){ // public void bindCloudletToVm(int cloudletId, int vmId){
// CloudletList.getById(getCloudletList(), cloudletId).setVmId(vmId); // CloudletList.getById(getCloudletList(), cloudletId).setVmId(vmId);
// } // }
public void setLinkDC(NetworkDatacenter linkDC) { public void setLinkDC(NetworkDatacenter alinkDC) {
this.linkDC = linkDC; linkDC = alinkDC;
} }
/** /**
...@@ -191,26 +184,27 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -191,26 +184,27 @@ public class NetDatacenterBroker extends SimEntity {
case CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST: case CloudSimTags.RESOURCE_CHARACTERISTICS_REQUEST:
processResourceCharacteristicsRequest(ev); processResourceCharacteristicsRequest(ev);
break; break;
// Resource characteristics answer // Resource characteristics answer
case CloudSimTags.RESOURCE_CHARACTERISTICS: case CloudSimTags.RESOURCE_CHARACTERISTICS:
processResourceCharacteristics(ev); processResourceCharacteristics(ev);
break; break;
// VM Creation answer // VM Creation answer
// A finished cloudlet returned // A finished cloudlet returned
case CloudSimTags.CLOUDLET_RETURN: case CloudSimTags.CLOUDLET_RETURN:
processCloudletReturn(ev); processCloudletReturn(ev);
break; break;
// if the simulation finishes // if the simulation finishes
case CloudSimTags.END_OF_SIMULATION: case CloudSimTags.END_OF_SIMULATION:
shutdownEntity(); shutdownEntity();
break; break;
case CloudSimTags.NextCycle: case CloudSimTags.NextCycle:
if (NetworkConstants.BASE) if (NetworkConstants.BASE) {
this.createVmsInDatacenterBase(this.linkDC.getId()); this.createVmsInDatacenterBase(linkDC.getId());
}
break; break;
// other unknown tags are processed by this method // other unknown tags are processed by this method
default: default:
processOtherEvent(ev); processOtherEvent(ev);
break; break;
...@@ -229,7 +223,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -229,7 +223,7 @@ public class NetDatacenterBroker extends SimEntity {
*/ */
protected void processResourceCharacteristics(SimEvent ev) { protected void processResourceCharacteristics(SimEvent ev) {
DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev
.getData(); .getData();
getDatacenterCharacteristicsList().put(characteristics.getId(), getDatacenterCharacteristicsList().put(characteristics.getId(),
characteristics); characteristics);
...@@ -341,8 +335,6 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -341,8 +335,6 @@ public class NetDatacenterBroker extends SimEntity {
// send as much vms as possible for this datacenter before trying the // send as much vms as possible for this datacenter before trying the
// next one // next one
int requestedVms = 0; int requestedVms = 0;
String datacenterName = CloudSim.getEntityName(datacenterId);
int j = 0;
// All host will have two VMs (assumption) VM is the minimum unit // All host will have two VMs (assumption) VM is the minimum unit
...@@ -360,16 +352,14 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -360,16 +352,14 @@ public class NetDatacenterBroker extends SimEntity {
NetworkConstants.currentAppId++; NetworkConstants.currentAppId++;
} }
int seed = 5;
int k = 0; int k = 0;
int totalvm = this.vmsCreatedList.size();
int currentvmid = 0; int currentvmid = 0;
//schedule the application on VMs //schedule the application on VMs
for (AppCloudlet app : this.getAppCloudletList()) { for (AppCloudlet app : this.getAppCloudletList()) {
List<Integer> vmids = new ArrayList<Integer>(); List<Integer> vmids = new ArrayList<Integer>();
int numVms = this.linkDC.getVmList().size(); int numVms = linkDC.getVmList().size();
UniformDistr ufrnd = new UniformDistr(0, numVms, 5); UniformDistr ufrnd = new UniformDistr(0, numVms, 5);
for (int i = 0; i < app.numbervm; i++) { for (int i = 0; i < app.numbervm; i++) {
...@@ -409,18 +399,17 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -409,18 +399,17 @@ public class NetDatacenterBroker extends SimEntity {
CloudSimTags.NextCycle); CloudSimTags.NextCycle);
} }
setVmsRequested(requestedVms); setVmsRequested(requestedVms);
setVmsAcks(0); setVmsAcks(0);
} }
private void CreateVMs(int datacenterId) { private void CreateVMs(int datacenterId) {
// TODO Auto-generated method stub int numVM = linkDC.getHostList().size() * NetworkConstants.maxhostVM; // two
int numVM = this.linkDC.getHostList().size() * NetworkConstants.maxhostVM; // two // VMs
// VMs // per
// per // host
// host
for (int i = 0; i < numVM; i++) { for (int i = 0; i < numVM; i++) {
int requestedVms = 0; int requestedVms = 0;
int vmid = i; int vmid = i;
...@@ -429,14 +418,14 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -429,14 +418,14 @@ public class NetDatacenterBroker extends SimEntity {
int ram = 512; // vm memory (MB) int ram = 512; // vm memory (MB)
long bw = 1000; long bw = 1000;
int pesNumber = NetworkConstants.HOST_PEs / NetworkConstants.maxhostVM; // number int pesNumber = NetworkConstants.HOST_PEs / NetworkConstants.maxhostVM; // number
// of // of
// cpus // cpus
String vmm = "Xen"; // VMM name String vmm = "Xen"; // VMM name
// create VM // create VM
NetworkVm vm = new NetworkVm(vmid, this.getId(), mips, pesNumber, NetworkVm vm = new NetworkVm(vmid, this.getId(), mips, pesNumber,
ram, bw, size, vmm, new NetworkCloudletSpaceSharedScheduler()); ram, bw, size, vmm, new NetworkCloudletSpaceSharedScheduler());
this.linkDC.processVmCreateNetwork(vm); linkDC.processVmCreateNetwork(vm);
// add the VM to the vmList // add the VM to the vmList
getVmList().add(vm); getVmList().add(vm);
requestedVms++; requestedVms++;
...@@ -545,6 +534,7 @@ public class NetDatacenterBroker extends SimEntity { ...@@ -545,6 +534,7 @@ public class NetDatacenterBroker extends SimEntity {
this.cloudletList = cloudletList; this.cloudletList = cloudletList;
} }
@SuppressWarnings("unchecked")
public <T extends AppCloudlet> List<T> getAppCloudletList() { public <T extends AppCloudlet> List<T> getAppCloudletList() {
return (List<T>) appCloudletList; return (List<T>) appCloudletList;
} }
......
...@@ -5,10 +5,11 @@ import java.util.Map; ...@@ -5,10 +5,11 @@ import java.util.Map;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.UtilizationModel; import org.cloudbus.cloudsim.UtilizationModel;
/** /**
* NetworkCloudlet class extends Cloudlet to support simulation of complex applications. * NetworkCloudlet class extends Cloudlet to support simulation of complex
* Each such network Cloudlet represents a task of the application. Each task consists of several * applications. Each such network Cloudlet represents a task of the
* stages. * application. Each task consists of several stages.
* *
* Please refer to following publication for more details: * Please refer to following publication for more details:
* *
...@@ -16,54 +17,61 @@ import org.cloudbus.cloudsim.UtilizationModel; ...@@ -16,54 +17,61 @@ import org.cloudbus.cloudsim.UtilizationModel;
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM * Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS * International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011. * Press, USA), Melbourne, Australia, December 5-7, 2011.
* *
* *
* @author Saurabh Kumar Garg * @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 1.0
*/ */
public class NetworkCloudlet extends Cloudlet implements Comparable { public class NetworkCloudlet extends Cloudlet implements Comparable<Object> {
long memory; long memory;
public NetworkCloudlet(int cloudletId, long cloudletLength, int pesNumber, public NetworkCloudlet(
long cloudletFileSize, long cloudletOutputSize, long memory, int cloudletId,
long cloudletLength,
int pesNumber,
long cloudletFileSize,
long cloudletOutputSize,
long memory,
UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelCpu,
UtilizationModel utilizationModelRam, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw) { UtilizationModel utilizationModelBw) {
super(cloudletId, cloudletLength, pesNumber, cloudletFileSize, super(
cloudletOutputSize, utilizationModelCpu, utilizationModelRam, cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw); utilizationModelBw);
// TODO Auto-generated constructor stub
currStagenum = -1; currStagenum = -1;
this.memory = memory; this.memory = memory;
stages = new ArrayList<TaskStage>(); stages = new ArrayList<TaskStage>();
} }
public double submittime; //time when cloudlet will be submitted public double submittime; // time when cloudlet will be submitted
public double finishtime; //time when cloudlet finish execution public double finishtime; // time when cloudlet finish execution
public double exetime; //execution time for cloudlet public double exetime; // execution time for cloudlet
public double numStage;//number of stages in cloudlet public double numStage;// number of stages in cloudlet
public int currStagenum; //current stage of cloudlet execution public int currStagenum; // current stage of cloudlet execution
public double timetostartStage; public double timetostartStage;
public double timespentInStage; //how much time spent in particular stage public double timespentInStage; // how much time spent in particular stage
public Map<Double, HostPacket> timeCommunicate; public Map<Double, HostPacket> timeCommunicate;
public ArrayList<TaskStage> stages; //all stages which cloudlet execution consists of. public ArrayList<TaskStage> stages; // all stages which cloudlet execution
// consists of.
public double starttime; public double starttime;
@Override @Override
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
// TODO Auto-generated method stub
NetworkCloudlet s1 = (NetworkCloudlet) arg0;
int alpha = 0;
return 0; return 0;
} }
public double getSubmittime() { public double getSubmittime() {
// TODO Auto-generated method stub
return submittime; return submittime;
}; }
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NetworkConstants { public class NetworkConstants {
public static int maxhostVM = 2;
public static int HOST_PEs = 8;
public static int maxhostVM=2; public static double maxMemperVM = 1024 * 1024;// kb
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 int currentCloudletId=0; public static final int PES_NUMBER = 4;
public static int currentAppId=0; public static final int FILE_SIZE = 300;
public static final int OUTPUT_SIZE = 300;
public static final int COMMUNICATION_LENGTH = 1;
//stage type public static boolean BASE = true;
public static final int EXECUTION=0;
public static final int WAIT_SEND=1;
public static final int WAIT_RECV=2;
public static final int FINISH=-2;
public static 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
//number of switches at each level public static double EdgeSwitchPort = 4;// number of host
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 double AggSwitchPort = 1;// number of Edge
public static final int FILE_SIZE=300;
public static final int OUTPUT_SIZE=300;
public static final int COMMUNICATION_LENGTH=1; public static double RootSwitchPort = 1;// number of Agg
public static boolean BASE = true; public static double seed = 199;
public static boolean logflag = false;
public static long BandWidthEdgeAgg=100*1024*1024;//100 Megabits public static int iteration = 10;
public static long BandWidthEdgeHost=100*1024*1024;// public static int nexttime = 1000;
public static long BandWidthAggRoot=20*1024*1024*2;//40gb
public static double SwitchingDelayRoot=.00285; public static int totaldatatransfer = 0;
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;
} }
...@@ -9,13 +9,10 @@ ...@@ -9,13 +9,10 @@
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.Host; import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe; import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmScheduler; import org.cloudbus.cloudsim.VmScheduler;
...@@ -27,11 +24,11 @@ import org.cloudbus.cloudsim.provisioners.BwProvisioner; ...@@ -27,11 +24,11 @@ import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner; import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/** /**
* NetworkHost class extends Host to support simulation of networked datacenters. * NetworkHost class extends Host to support simulation of networked
* It executes actions related to management of packets (send and receive)other than that of * datacenters. It executes actions related to management of packets (send and
* virtual machines (e.g., creation and destruction). A host has a defined * receive)other than that of virtual machines (e.g., creation and destruction).
* policy for provisioning memory and bw, as well as an allocation policy for * A host has a defined policy for provisioning memory and bw, as well as an
* Pe's to virtual machines. * allocation policy for Pe's to virtual machines.
* *
* Please refer to following publication for more details: * Please refer to following publication for more details:
* *
...@@ -39,10 +36,10 @@ import org.cloudbus.cloudsim.provisioners.RamProvisioner; ...@@ -39,10 +36,10 @@ import org.cloudbus.cloudsim.provisioners.RamProvisioner;
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM * Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS * International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011. * Press, USA), Melbourne, Australia, December 5-7, 2011.
* *
* *
* @author Saurabh Kumar Garg * @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 3.0
*/ */
public class NetworkHost extends Host { public class NetworkHost extends Host {
...@@ -50,20 +47,24 @@ public class NetworkHost extends Host { ...@@ -50,20 +47,24 @@ public class NetworkHost extends Host {
public List<NetworkPacket> packetTosendGlobal; public List<NetworkPacket> packetTosendGlobal;
public List<NetworkPacket> packetrecieved; public List<NetworkPacket> packetrecieved;
public double memory; public double memory;
public Switch sw; //Edge switch in general public Switch sw; // Edge switch in general
public double bandwidth;// latency public double bandwidth;// latency
public List<Double> CPUfinTimeCPU = new ArrayList<Double>();// time when public List<Double> CPUfinTimeCPU = new ArrayList<Double>();// time when
// last job will // last job will
// finish on // finish on
// CPU1 // CPU1
public double fintime = 0; public double fintime = 0;
public NetworkHost(int id, RamProvisioner ramProvisioner, public NetworkHost(
BwProvisioner bwProvisioner, long storage, int id,
List<? extends Pe> peList, VmScheduler vmScheduler) { RamProvisioner ramProvisioner,
BwProvisioner bwProvisioner,
long storage,
List<? extends Pe> peList,
VmScheduler vmScheduler) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler); super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
this.packetrecieved = new ArrayList<NetworkPacket>(); this.packetrecieved = new ArrayList<NetworkPacket>();
this.packetTosendGlobal = new ArrayList<NetworkPacket>(); this.packetTosendGlobal = new ArrayList<NetworkPacket>();
this.packetTosendLocal = new ArrayList<NetworkPacket>(); this.packetTosendLocal = new ArrayList<NetworkPacket>();
...@@ -79,11 +80,12 @@ public class NetworkHost extends Host { ...@@ -79,11 +80,12 @@ public class NetworkHost extends Host {
* *
* @return expected time of completion of the next cloudlet in all VMs in * @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 * this host. Double.MAX_VALUE if there is no future events expected
* in th is host * in th is host
* *
* @pre currentTime >= 0.0 * @pre currentTime >= 0.0
* @post $none * @post $none
*/ */
@Override
public double updateVmsProcessing(double currentTime) { public double updateVmsProcessing(double currentTime) {
double smallerTime = Double.MAX_VALUE; double smallerTime = Double.MAX_VALUE;
// insert in each vm packet recieved // insert in each vm packet recieved
...@@ -93,18 +95,19 @@ public class NetworkHost extends Host { ...@@ -93,18 +95,19 @@ public class NetworkHost extends Host {
// continue; // continue;
// } // }
double time = ((NetworkVm) vm).updateVmProcessing(currentTime, double time = ((NetworkVm) vm).updateVmProcessing(currentTime, getVmScheduler()
getVmScheduler().getAllocatedMipsForVm(vm)); .getAllocatedMipsForVm(vm));
if (time > 0.0 && time < smallerTime) { if (time > 0.0 && time < smallerTime) {
smallerTime = time; smallerTime = time;
} }
} }
//send the packets to other hosts/VMs // send the packets to other hosts/VMs
sendpackets(); sendpackets();
return smallerTime; return smallerTime;
} }
/** /**
* Receives packet and forward it to the corresponding VM for processing * Receives packet and forward it to the corresponding VM for processing
* host. * host.
...@@ -112,49 +115,49 @@ public class NetworkHost extends Host { ...@@ -112,49 +115,49 @@ public class NetworkHost extends Host {
* *
*/ */
private void recvpackets() { private void recvpackets() {
for (NetworkPacket hs : packetrecieved) { for (NetworkPacket hs : packetrecieved) {
// hs.stime=hs.rtime; // hs.stime=hs.rtime;
hs.pkt.recievetime = CloudSim.clock(); hs.pkt.recievetime = CloudSim.clock();
// insertthe packet in recievedlist of VM // insertthe packet in recievedlist of VM
Vm vm = VmList.getById(getVmList(), hs.pkt.reciever); Vm vm = VmList.getById(getVmList(), hs.pkt.reciever);
List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv
.getCloudletScheduler()).pktrecv.get(hs.pkt.sender); .get(hs.pkt.sender);
if (pktlist == null) { if (pktlist == null) {
pktlist = new ArrayList<HostPacket>(); pktlist = new ArrayList<HostPacket>();
((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv.put(
.put(hs.pkt.sender, pktlist); hs.pkt.sender,
pktlist);
} }
pktlist.add(hs.pkt); pktlist.add(hs.pkt);
} }
packetrecieved.clear(); packetrecieved.clear();
} }
/** /**
* Send packet check whether a packet belongs to a local VM or to a VM hosted on other machine. * Send packet check whether a packet belongs to a local VM or to a VM
* hosted on other machine.
* *
* *
*/ */
private void sendpackets() { private void sendpackets() {
for (Vm vm : super.getVmList()) { for (Vm vm : super.getVmList()) {
for (Entry<Integer, List<HostPacket>> es : ((NetworkCloudletSpaceSharedScheduler) vm for (Entry<Integer, List<HostPacket>> es : ((NetworkCloudletSpaceSharedScheduler) vm
.getCloudletScheduler()).pkttosend.entrySet()) .getCloudletScheduler()).pkttosend.entrySet()) {
{
List<HostPacket> pktlist = es.getValue(); List<HostPacket> pktlist = es.getValue();
for (HostPacket pkt : pktlist) { for (HostPacket pkt : pktlist) {
NetworkPacket hpkt = new NetworkPacket(this.getId(), pkt, NetworkPacket hpkt = new NetworkPacket(this.getId(), pkt, vm.getId(), pkt.sender);
vm.getId(), pkt.sender); Vm vm2 = VmList.getById(this.getVmList(), hpkt.recievervmid);
Vm vm2 = VmList if (vm2 != null) {
.getById(this.getVmList(), hpkt.recievervmid);
if (vm2 != null)
this.packetTosendLocal.add(hpkt); this.packetTosendLocal.add(hpkt);
else } else {
this.packetTosendGlobal.add(hpkt); this.packetTosendGlobal.add(hpkt);
}
} }
pktlist.clear(); pktlist.clear();
...@@ -172,12 +175,13 @@ public class NetworkHost extends Host { ...@@ -172,12 +175,13 @@ public class NetworkHost extends Host {
Vm vm = VmList.getById(getVmList(), hs.pkt.reciever); Vm vm = VmList.getById(getVmList(), hs.pkt.reciever);
// Vm vm=getVmList().get(hs.pkt.reciever); // Vm vm=getVmList().get(hs.pkt.reciever);
List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm List<HostPacket> pktlist = ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv
.getCloudletScheduler()).pktrecv.get(hs.pkt.sender); .get(hs.pkt.sender);
if (pktlist == null) { if (pktlist == null) {
pktlist = new ArrayList<HostPacket>(); pktlist = new ArrayList<HostPacket>();
((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv ((NetworkCloudletSpaceSharedScheduler) vm.getCloudletScheduler()).pktrecv.put(
.put(hs.pkt.sender, pktlist); hs.pkt.sender,
pktlist);
} }
pktlist.add(hs.pkt); pktlist.add(hs.pkt);
...@@ -188,14 +192,14 @@ public class NetworkHost extends Host { ...@@ -188,14 +192,14 @@ public class NetworkHost extends Host {
// continue; // continue;
// } // }
double time = ((NetworkVm) vm).updateVmProcessing(CloudSim vm.updateVmProcessing(CloudSim.clock(), getVmScheduler().getAllocatedMipsForVm(vm));
.clock(), getVmScheduler().getAllocatedMipsForVm(vm));
} }
} }
//Sending packet to other VMs therefore packet is forwarded to a Edge switch // Sending packet to other VMs therefore packet is forwarded to a Edge
// switch
this.packetTosendLocal.clear(); this.packetTosendLocal.clear();
double avband = this.bandwidth / packetTosendGlobal.size(); double avband = this.bandwidth / packetTosendGlobal.size();
for (NetworkPacket hs : packetTosendGlobal) { for (NetworkPacket hs : packetTosendGlobal) {
...@@ -203,16 +207,19 @@ public class NetworkHost extends Host { ...@@ -203,16 +207,19 @@ public class NetworkHost extends Host {
NetworkConstants.totaldatatransfer += hs.pkt.data; NetworkConstants.totaldatatransfer += hs.pkt.data;
// System.out.println(hs.pkt.virtualsendid+" "+hs.pkt.virtualrecvid+" "+hs.pkt.data); // System.out.println(hs.pkt.virtualsendid+" "+hs.pkt.virtualrecvid+" "+hs.pkt.data);
CloudSim.send(this.getDatacenter().getId(), this.sw.getId(), delay, CloudSim.send(
CloudSimTags.Network_Event_UP, hs); this.getDatacenter().getId(),
this.sw.getId(),
delay,
CloudSimTags.Network_Event_UP,
hs);
// send to switch with delay // send to switch with delay
} }
this.packetTosendGlobal.clear(); this.packetTosendGlobal.clear();
} }
@SuppressWarnings("unchecked")
public double getMaxUtilizationAmongVmsPes(Vm vm) { public double getMaxUtilizationAmongVmsPes(Vm vm) {
return PeList.getMaxUtilizationAmongVmsPes((List<Pe>) getPeList(), vm); return PeList.getMaxUtilizationAmongVmsPes(getPeList(), vm);
} }
} }
package org.cloudbus.cloudsim.network.datacenter; package org.cloudbus.cloudsim.network.datacenter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.CloudletScheduler; import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
/** /**
* NetworkVm class extends Vm to support simulation of networked datacenters. * NetworkVm class extends Vm to support simulation of networked datacenters. It
* It executes actions related to management of packets (send and receive). * executes actions related to management of packets (send and receive).
* *
* Please refer to following publication for more details: * Please refer to following publication for more details:
* *
...@@ -16,19 +15,26 @@ import org.cloudbus.cloudsim.Vm; ...@@ -16,19 +15,26 @@ import org.cloudbus.cloudsim.Vm;
* Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM * Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
* International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS * International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
* Press, USA), Melbourne, Australia, December 5-7, 2011. * Press, USA), Melbourne, Australia, December 5-7, 2011.
* *
* *
* @author Saurabh Kumar Garg * @author Saurabh Kumar Garg
* @since CloudSim Toolkit 1.0 * @since CloudSim Toolkit 3.0
*/ */
public class NetworkVm extends Vm implements Comparable { 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);
public NetworkVm(int id, int userId, double mips, int pesNumber, int ram,
long bw, long size, String vmm, CloudletScheduler cloudletScheduler) {
super(id, userId, mips, pesNumber, ram, bw, size, vmm,
cloudletScheduler);
// TODO Auto-generated constructor stub
cloudletlist = new ArrayList<NetworkCloudlet>(); cloudletlist = new ArrayList<NetworkCloudlet>();
} }
...@@ -45,10 +51,12 @@ public class NetworkVm extends Vm implements Comparable { ...@@ -45,10 +51,12 @@ public class NetworkVm extends Vm implements Comparable {
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
NetworkVm hs = (NetworkVm) arg0; NetworkVm hs = (NetworkVm) arg0;
if (hs.finishtime > this.finishtime) if (hs.finishtime > this.finishtime) {
return -1; return -1;
if (hs.finishtime < this.finishtime) }
if (hs.finishtime < this.finishtime) {
return 1; return 1;
}
return 0; return 0;
} }
} }
...@@ -4,9 +4,9 @@ import java.util.ArrayList; ...@@ -4,9 +4,9 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.Log; import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
...@@ -67,30 +67,7 @@ public class Switch extends SimEntity { ...@@ -67,30 +67,7 @@ public class Switch extends SimEntity {
public Switch(String name, int level, NetworkDatacenter dc) { public Switch(String name, int level, NetworkDatacenter dc) {
super(name); super(name);
this.level = level; this.level = level;
/*
* if(level==Constants.EDGE_LEVEL) { hostlist=new HashMap<Integer,HPCHost>();
* uplinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); packetTohost=new
* HashMap<Integer,List<HostPacket>>(); uplinkbandwidth=Constants.BandWidthEdgeAgg;
* downlinkbandwidth=Constants.BandWidthEdgeHost; latency=Constants.SwitchingDelayEdge;
* numport=Constants.EdgeSwitchPort; uplinkswitches=new ArrayList<Switch>();
*
* } if(level==Constants.Agg_LEVEL) { downlinkswitchpktlist=new
* HashMap<Integer,List<HostPacket>>(); uplinkswitchpktlist=new
* HashMap<Integer,List<HostPacket>>(); uplinkbandwidth=Constants.BandWidthAggRoot;
* downlinkbandwidth=Constants.BandWidthEdgeAgg; latency=Constants.SwitchingDelayAgg;
* numport=Constants.AggSwitchPort; uplinkswitches=new ArrayList<Switch>();
* downlinkswitches=new ArrayList<Switch>(); } if(level==Constants.ROOT_LEVEL) {
* downlinkswitchpktlist=new HashMap<Integer,List<HostPacket>>(); downlinkswitches=new
* ArrayList<Switch>();
*
* downlinkbandwidth=Constants.BandWidthAggRoot; latency=Constants.SwitchingDelayRoot;
* numport=Constants.RootSwitchPort;
*
* }
*/
this.dc = dc; this.dc = dc;
// TODO Auto-generated constructor stub
} }
@Override @Override
...@@ -104,34 +81,33 @@ public class Switch extends SimEntity { ...@@ -104,34 +81,33 @@ public class Switch extends SimEntity {
// Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag()); // Log.printLine(CloudSim.clock()+"[Broker]: event received:"+ev.getTag());
switch (ev.getTag()) { switch (ev.getTag()) {
// Resource characteristics request // Resource characteristics request
case CloudSimTags.Network_Event_UP: case CloudSimTags.Network_Event_UP:
// process the packet from down switch or host // process the packet from down switch or host
processpacket_up(ev); processpacket_up(ev);
break; break;
case CloudSimTags.Network_Event_DOWN: case CloudSimTags.Network_Event_DOWN:
// process the packet from uplink // process the packet from uplink
processpacket_down(ev); processpacket_down(ev);
break; break;
case CloudSimTags.Network_Event_send: case CloudSimTags.Network_Event_send:
processpacketforward(ev); processpacketforward(ev);
break; break;
case CloudSimTags.Network_Event_Host: case CloudSimTags.Network_Event_Host:
processhostpacket(ev); processhostpacket(ev);
break; break;
// Resource characteristics answer // Resource characteristics answer
case CloudSimTags.RESOURCE_Register: case CloudSimTags.RESOURCE_Register:
registerHost(ev); registerHost(ev);
break; break;
// other unknown tags are processed by this method // other unknown tags are processed by this method
default: default:
processOtherEvent(ev); processOtherEvent(ev);
break; break;
} }
} }
protected void processhostpacket(SimEvent ev) { protected void processhostpacket(SimEvent ev) {
// TODO Auto-generated method stub
// Send packet to host // Send packet to host
NetworkPacket hspkt = (NetworkPacket) ev.getData(); NetworkPacket hspkt = (NetworkPacket) ev.getData();
NetworkHost hs = hostlist.get(hspkt.recieverhostid); NetworkHost hs = hostlist.get(hspkt.recieverhostid);
...@@ -139,7 +115,6 @@ public class Switch extends SimEntity { ...@@ -139,7 +115,6 @@ public class Switch extends SimEntity {
} }
protected void processpacket_down(SimEvent ev) { protected void processpacket_down(SimEvent ev) {
// TODO Auto-generated method stub
// packet coming from up level router. // packet coming from up level router.
// has to send downward // has to send downward
// check which switch to forward to // check which switch to forward to
...@@ -178,7 +153,6 @@ public class Switch extends SimEntity { ...@@ -178,7 +153,6 @@ public class Switch extends SimEntity {
} }
protected void processpacket_up(SimEvent ev) { protected void processpacket_up(SimEvent ev) {
// TODO Auto-generated method stub
// packet coming from down level router. // packet coming from down level router.
// has to send up // has to send up
// check which switch to forward to // check which switch to forward to
...@@ -277,13 +251,11 @@ public class Switch extends SimEntity { ...@@ -277,13 +251,11 @@ public class Switch extends SimEntity {
} }
private void registerHost(SimEvent ev) { private void registerHost(SimEvent ev) {
// TODO Auto-generated method stub
NetworkHost hs = (NetworkHost) ev.getData(); NetworkHost hs = (NetworkHost) ev.getData();
hostlist.put(hs.getId(), (NetworkHost) ev.getData()); hostlist.put(hs.getId(), (NetworkHost) ev.getData());
} }
protected void processpacket(SimEvent ev) { protected void processpacket(SimEvent ev) {
// TODO Auto-generated method stub
// send packet to itself with switching delay (discarding other) // send packet to itself with switching delay (discarding other)
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_UP)); CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.Network_Event_UP));
schedule(getId(), switching_delay, CloudSimTags.Network_Event_UP); schedule(getId(), switching_delay, CloudSimTags.Network_Event_UP);
...@@ -294,12 +266,10 @@ public class Switch extends SimEntity { ...@@ -294,12 +266,10 @@ public class Switch extends SimEntity {
} }
private void processOtherEvent(SimEvent ev) { private void processOtherEvent(SimEvent ev) {
// TODO Auto-generated method stub
} }
protected void processpacketforward(SimEvent ev) { protected void processpacketforward(SimEvent ev) {
// TODO Auto-generated method stub
// search for the host and packets..send to them // search for the host and packets..send to them
if (downlinkswitchpktlist != null) { if (downlinkswitchpktlist != null) {
...@@ -338,8 +308,6 @@ public class Switch extends SimEntity { ...@@ -338,8 +308,6 @@ public class Switch extends SimEntity {
} }
if (packetTohost != null) { if (packetTohost != null) {
for (Entry<Integer, List<NetworkPacket>> es : packetTohost.entrySet()) { for (Entry<Integer, List<NetworkPacket>> es : packetTohost.entrySet()) {
int tosend = es.getKey();
NetworkHost hs = hostlist.get(tosend);
List<NetworkPacket> hspktlist = es.getValue(); List<NetworkPacket> hspktlist = es.getValue();
if (!hspktlist.isEmpty()) { if (!hspktlist.isEmpty()) {
double avband = downlinkbandwidth / hspktlist.size(); double avband = downlinkbandwidth / hspktlist.size();
...@@ -360,8 +328,11 @@ public class Switch extends SimEntity { ...@@ -360,8 +328,11 @@ public class Switch extends SimEntity {
} }
private NetworkHost getHostwithVM(int vmid) { //
// TODO Auto-generated method stub // R: We changed visibility of the below methods from private to protected.
//
protected NetworkHost getHostwithVM(int vmid) {
for (Entry<Integer, NetworkHost> es : hostlist.entrySet()) { for (Entry<Integer, NetworkHost> es : hostlist.entrySet()) {
Vm vm = VmList.getById(es.getValue().getVmList(), vmid); Vm vm = VmList.getById(es.getValue().getVmList(), vmid);
if (vm != null) { if (vm != null) {
...@@ -371,8 +342,7 @@ public class Switch extends SimEntity { ...@@ -371,8 +342,7 @@ public class Switch extends SimEntity {
return null; return null;
} }
private List<NetworkVm> getfreeVmlist(int numVMReq) { protected List<NetworkVm> getfreeVmlist(int numVMReq) {
// TODO Auto-generated method stub
List<NetworkVm> freehostls = new ArrayList<NetworkVm>(); List<NetworkVm> freehostls = new ArrayList<NetworkVm>();
for (Entry<Integer, NetworkVm> et : Vmlist.entrySet()) { for (Entry<Integer, NetworkVm> et : Vmlist.entrySet()) {
if (et.getValue().isFree()) { if (et.getValue().isFree()) {
...@@ -386,8 +356,7 @@ public class Switch extends SimEntity { ...@@ -386,8 +356,7 @@ public class Switch extends SimEntity {
return freehostls; return freehostls;
} }
private List<NetworkHost> getfreehostlist(int numhost) { protected List<NetworkHost> getfreehostlist(int numhost) {
// TODO Auto-generated method stub
List<NetworkHost> freehostls = new ArrayList<NetworkHost>(); List<NetworkHost> freehostls = new ArrayList<NetworkHost>();
for (Entry<Integer, NetworkHost> et : hostlist.entrySet()) { for (Entry<Integer, NetworkHost> et : hostlist.entrySet()) {
if (et.getValue().getNumberOfFreePes() == et.getValue().getNumberOfPes()) { if (et.getValue().getNumberOfFreePes() == et.getValue().getNumberOfPes()) {
......
...@@ -22,67 +22,112 @@ import org.cloudbus.cloudsim.UtilizationModel; ...@@ -22,67 +22,112 @@ import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull; import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
public class WorkflowApp extends AppCloudlet{ public class WorkflowApp extends AppCloudlet {
public WorkflowApp(int type, int appID, double deadline, public WorkflowApp(int type, int appID, double deadline, int numbervm, int userId) {
int numbervm, int userId) { super(type, appID, deadline, numbervm, userId);
super(type, appID, deadline, numbervm, userId); this.exeTime = 100;
// TODO Auto-generated constructor stub this.numbervm = 3;
this.exeTime=100;
this.numbervm=3;
} }
public void createCloudletList(List<Integer> vmIdList){
@Override
public void createCloudletList(List<Integer> vmIdList) {
long fileSize = NetworkConstants.FILE_SIZE; long fileSize = NetworkConstants.FILE_SIZE;
long outputSize = NetworkConstants.OUTPUT_SIZE; long outputSize = NetworkConstants.OUTPUT_SIZE;
int pesNumber = NetworkConstants.PES_NUMBER; int memory = 100;
int memory=100;
UtilizationModel utilizationModel = new UtilizationModelFull(); UtilizationModel utilizationModel = new UtilizationModelFull();
int i=0; int i = 0;
//Task A // Task A
NetworkCloudlet cl = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); NetworkCloudlet cl = new NetworkCloudlet(
cl.numStage=2; NetworkConstants.currentCloudletId,
NetworkConstants.currentCloudletId++; 0,
cl.setUserId(userId); 1,
cl.submittime=CloudSim.clock(); fileSize,
cl.currStagenum=-1; outputSize,
cl.setVmId(vmIdList.get(i)); memory,
utilizationModel,
//first stage: big computation utilizationModel,
cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(0),cl.getCloudletId())); utilizationModel);
cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),cl.getCloudletId()+2)); cl.numStage = 2;
clist.add(cl); NetworkConstants.currentCloudletId++;
i++; cl.setUserId(userId);
//Task B cl.submittime = CloudSim.clock();
NetworkCloudlet clb = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); cl.currStagenum = -1;
clb.numStage=2; cl.setVmId(vmIdList.get(i));
NetworkConstants.currentCloudletId++;
clb.setUserId(userId); // first stage: big computation
clb.submittime=CloudSim.clock(); cl.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000 * 0.8, 0, memory, vmIdList.get(0), cl
clb.currStagenum=-1; .getCloudletId()));
clb.setVmId(vmIdList.get(i)); cl.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2), cl
.getCloudletId() + 2));
//first stage: big computation clist.add(cl);
i++;
clb.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 0, memory, vmIdList.get(1),clb.getCloudletId())); // Task B
clb.stages.add(new TaskStage(NetworkConstants.WAIT_SEND, 1000, 0, 1, memory, vmIdList.get(2),clb.getCloudletId()+1)); NetworkCloudlet clb = new NetworkCloudlet(
clist.add(clb); NetworkConstants.currentCloudletId,
i++; 0,
1,
//Task C fileSize,
NetworkCloudlet clc = new NetworkCloudlet(NetworkConstants.currentCloudletId, 0, 1, fileSize, outputSize, memory, utilizationModel, utilizationModel, utilizationModel); outputSize,
clc.numStage=2; memory,
NetworkConstants.currentCloudletId++; utilizationModel,
clc.setUserId(userId); utilizationModel,
clc.submittime=CloudSim.clock(); utilizationModel);
clc.currStagenum=-1; clb.numStage = 2;
clc.setVmId(vmIdList.get(i)); NetworkConstants.currentCloudletId++;
clb.setUserId(userId);
//first stage: big computation clb.submittime = CloudSim.clock();
clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 0, memory, vmIdList.get(0),cl.getCloudletId())); clb.currStagenum = -1;
clc.stages.add(new TaskStage(NetworkConstants.WAIT_RECV, 1000, 0, 1, memory, vmIdList.get(1),cl.getCloudletId()+1)); clb.setVmId(vmIdList.get(i));
clc.stages.add(new TaskStage(NetworkConstants.EXECUTION, 0, 1000*0.8, 1, memory, vmIdList.get(0),clc.getCloudletId()));
// first stage: big computation
clist.add(clc);
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);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment