initial commit of EdgeCloudSim

EdgeCloudSim with default network model, mobility model,  load generator
model, edge orchestrator, and VM CPU utilization model
This commit is contained in:
Cagatay Sonmez
2017-02-18 13:22:32 +03:00
commit 19c4b9de40
35 changed files with 4098 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/*
* Title: EdgeCloudSim - EdgeHost
*
* Description:
* EdgeHost adds location information over CloudSim's Host class
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.edge_server;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
import edu.boun.edgecloudsim.utils.Location;
public class EdgeHost extends Host {
private Location location;
public EdgeHost(int id, RamProvisioner ramProvisioner,
BwProvisioner bwProvisioner, long storage,
List<? extends Pe> peList, VmScheduler vmScheduler) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
}
public void setPlace(Location _location){
location=_location;
}
public Location getLocation(){
return location;
}
}

View File

@@ -0,0 +1,224 @@
/*
* Title: EdgeCloudSim - Edge Server Manager
*
* Description:
* EdgeServerManager is responsible for creating datacenters, hosts and VMs.
* It also provides the list of VMs running on the hosts.
* This information is critical for the edge orchestrator.
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.edge_server;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.VmSchedulerSpaceShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.utils.Location;
import edu.boun.edgecloudsim.utils.SimUtils;
public class EdgeServerManager {
private List<Datacenter> localDatacenters;
private List<List<EdgeVM>> vmList;
private int hostIdCounter;
public EdgeServerManager() {
localDatacenters=new ArrayList<Datacenter>();
vmList = new ArrayList<List<EdgeVM>>();
hostIdCounter = 0;
}
public List<EdgeVM> getVmList(int hostId){
return vmList.get(hostId);
}
public List<Datacenter> getDatacenterList(){
return localDatacenters;
}
public void startDatacenters() throws Exception{
//create random number generator for each place
Document doc = SimSettings.getInstance().getEdgeDevicesDocument();
NodeList datacenterList = doc.getElementsByTagName("datacenter");
for (int i = 0; i < datacenterList.getLength(); i++) {
Node datacenterNode = datacenterList.item(i);
Element datacenterElement = (Element) datacenterNode;
localDatacenters.add(createDatacenter(i, datacenterElement));
}
}
public void createVmList(int brockerId){
int hostCounter=0;
int vmCounter=0;
//Create VMs for each hosts
Document doc = SimSettings.getInstance().getEdgeDevicesDocument();
NodeList datacenterList = doc.getElementsByTagName("datacenter");
for (int i = 0; i < datacenterList.getLength(); i++) {
Node datacenterNode = datacenterList.item(i);
Element datacenterElement = (Element) datacenterNode;
NodeList hostNodeList = datacenterElement.getElementsByTagName("host");
for (int j = 0; j < hostNodeList.getLength(); j++) {
vmList.add(hostCounter, new ArrayList<EdgeVM>());
Node hostNode = hostNodeList.item(j);
Element hostElement = (Element) hostNode;
NodeList vmNodeList = hostElement.getElementsByTagName("VM");
for (int k = 0; k < vmNodeList.getLength(); k++) {
Node vmNode = vmNodeList.item(k);
Element vmElement = (Element) vmNode;
String vmm = vmElement.getAttribute("vmm");
int numOfCores = Integer.parseInt(vmElement.getElementsByTagName("core").item(0).getTextContent());
double mips = Double.parseDouble(vmElement.getElementsByTagName("mips").item(0).getTextContent());
int ram = Integer.parseInt(vmElement.getElementsByTagName("ram").item(0).getTextContent());
long storage = Long.parseLong(vmElement.getElementsByTagName("storage").item(0).getTextContent());
long bandwidth = SimSettings.getInstance().getWlanBandwidth() / (hostNodeList.getLength()+vmNodeList.getLength());
//VM Parameters
EdgeVM vm = new EdgeVM(vmCounter, brockerId, mips, numOfCores, ram, bandwidth, storage, vmm, new CloudletSchedulerTimeShared());
vm.setVmType(SimSettings.VM_TYPES.EDGE_VM);
vmList.get(hostCounter).add(vm);
vmCounter++;
}
hostCounter++;
}
}
}
public void terminateDatacenters(){
for (Datacenter datacenter : localDatacenters) {
datacenter.shutdownEntity();
}
}
//average utilization of all VMs
public double getAvgUtilization(){
double totalUtilization = 0;
double vmCounter = 0;
// for each datacenter...
for(int i= 0; i<localDatacenters.size(); i++) {
List<? extends Host> list = localDatacenters.get(i).getHostList();
// for each host...
for (int j=0; j < list.size(); j++) {
Host host = list.get(j);
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().getVmList(host.getId());
//for each vm...
for(int vmIndex=0; vmIndex<vmArray.size(); vmIndex++){
totalUtilization += vmArray.get(vmIndex).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
vmCounter++;
}
}
}
return totalUtilization / vmCounter;
}
private Datacenter createDatacenter(int index, Element datacenterElement) throws Exception{
String arch = datacenterElement.getAttribute("arch");
String os = datacenterElement.getAttribute("os");
String vmm = datacenterElement.getAttribute("vmm");
double costPerBw = Double.parseDouble(datacenterElement.getElementsByTagName("costPerBw").item(0).getTextContent());
double costPerSec = Double.parseDouble(datacenterElement.getElementsByTagName("costPerSec").item(0).getTextContent());
double costPerMem = Double.parseDouble(datacenterElement.getElementsByTagName("costPerMem").item(0).getTextContent());
double costPerStorage = Double.parseDouble(datacenterElement.getElementsByTagName("costPerStorage").item(0).getTextContent());
List<EdgeHost> hostList=createHosts(datacenterElement);
String name = "Datacenter_" + Integer.toString(index);
double time_zone = 3.0; // time zone this resource located
LinkedList<Storage> storageList = new LinkedList<Storage>(); //we are not adding SAN devices by now
// 5. Create a DatacenterCharacteristics object that stores the
// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time zone
// and its price (G$/Pe time unit).
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, costPerSec, costPerMem, costPerStorage, costPerBw);
// 6. Finally, we need to create a PowerDatacenter object.
Datacenter datacenter = null;
VmAllocationPolicy vm_policy = SimManager.getInstance().getScenarioFactory().getVmAllocationPolicy(hostList,index);
datacenter = new Datacenter(name, characteristics, vm_policy, storageList, 0);
return datacenter;
}
private List<EdgeHost> createHosts(Element datacenterElement){
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store one or more Machines
List<EdgeHost> hostList = new ArrayList<EdgeHost>();
Element location = (Element)datacenterElement.getElementsByTagName("location").item(0);
String attractiveness = location.getElementsByTagName("attractiveness").item(0).getTextContent();
int wlan_id = Integer.parseInt(location.getElementsByTagName("wlan_id").item(0).getTextContent());
int x_pos = Integer.parseInt(location.getElementsByTagName("x_pos").item(0).getTextContent());
int y_pos = Integer.parseInt(location.getElementsByTagName("y_pos").item(0).getTextContent());
SimSettings.PLACE_TYPES placeType = SimUtils.stringToPlace(attractiveness);
NodeList hostNodeList = datacenterElement.getElementsByTagName("host");
for (int j = 0; j < hostNodeList.getLength(); j++) {
Node hostNode = hostNodeList.item(j);
Element hostElement = (Element) hostNode;
int numOfCores = Integer.parseInt(hostElement.getElementsByTagName("core").item(0).getTextContent());
double mips = Double.parseDouble(hostElement.getElementsByTagName("mips").item(0).getTextContent());
int ram = Integer.parseInt(hostElement.getElementsByTagName("ram").item(0).getTextContent());
long storage = Long.parseLong(hostElement.getElementsByTagName("storage").item(0).getTextContent());
long bandwidth = SimSettings.getInstance().getWlanBandwidth() / hostNodeList.getLength();
// 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
// create a list to store these PEs before creating
// a Machine.
List<Pe> peList = new ArrayList<Pe>();
// 3. Create PEs and add these into the list.
//for a quad-core machine, a list of 4 PEs is required:
for(int i=0; i<numOfCores; i++){
peList.add(new Pe(i, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
}
//4. Create Hosts with its id and list of PEs and add them to the list of machines
EdgeHost host = new EdgeHost(
hostIdCounter,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bandwidth), //kbps
storage,
peList,
new VmSchedulerSpaceShared(peList)
);
host.setPlace(new Location(placeType, wlan_id, x_pos, y_pos));
hostList.add(host);
hostIdCounter++;
}
return hostList;
}
}

View File

@@ -0,0 +1,34 @@
/*
* Title: EdgeCloudSim - EdgeVM
*
* Description:
* EdgeVM adds vm type information over CloudSim's VM class
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.edge_server;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Vm;
import edu.boun.edgecloudsim.core.SimSettings;
public class EdgeVM extends Vm {
private SimSettings.VM_TYPES type;
public EdgeVM(int id, int userId, double mips, int numberOfPes, int ram,
long bw, long size, String vmm, CloudletScheduler cloudletScheduler) {
super(id, userId, mips, numberOfPes, ram, bw, size, vmm, cloudletScheduler);
}
public void setVmType(SimSettings.VM_TYPES _type){
type=_type;
}
public SimSettings.VM_TYPES getVmType(){
return type;
}
}

View File

@@ -0,0 +1,158 @@
/*
* Title: EdgeCloudSim - Custom Vm Allocation Policy
*
* Description:
* VmAllocationPolicy_Custom implements VmAllocationPolicy to decide which.
* VM is created on which host locatied on the datacenters. For those
* who wants to add another Vm Allocation Policy to EdgeCloudSim should
* provide another concreate instance of VmAllocationPolicy via ScenarioFactory
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.edge_server;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import edu.boun.edgecloudsim.core.SimSettings;
/*
* Same as VmAllocationPolicySimple.
*/
public class VmAllocationPolicy_Custom extends VmAllocationPolicy {
/** The vm table. */
private Map<String, Host> vmTable;
private static int createdVmNum;
private int DataCenterIndex;
public VmAllocationPolicy_Custom(List<? extends Host> list, int _DataCenterIndex) {
super(list);
setVmTable(new HashMap<String, Host>());
DataCenterIndex=_DataCenterIndex;
createdVmNum = 0;
}
@Override
public boolean allocateHostForVm(Vm vm) {
boolean result = false;
if (!getVmTable().containsKey(vm.getUid())) { // if this vm was not created
boolean vmFound = false;
int vmCounter = 0;
int hostIndex = 0;
int dataCenterIndex = 0;
//find proper datacenter id and host id for this VM
Document doc = SimSettings.getInstance().getEdgeDevicesDocument();
NodeList datacenterList = doc.getElementsByTagName("datacenter");
for (int i = 0; (!vmFound && i < datacenterList.getLength()); i++) {
Node datacenterNode = datacenterList.item(i);
Element datacenterElement = (Element) datacenterNode;
NodeList hostNodeList = datacenterElement.getElementsByTagName("host");
for (int j = 0; (!vmFound && j < hostNodeList.getLength()); j++) {
Node hostNode = hostNodeList.item(j);
Element hostElement = (Element) hostNode;
NodeList vmNodeList = hostElement.getElementsByTagName("VM");
for (int k = 0; (!vmFound && k < vmNodeList.getLength()); k++) {
if(vmCounter == vm.getId()){
dataCenterIndex = i;
hostIndex = j;
vmFound = true;
}
vmCounter++;
}
}
}
if(vmFound && dataCenterIndex == DataCenterIndex && hostIndex < getHostList().size()){
Host host = getHostList().get(hostIndex);
result = host.vmCreate(vm);
if (result) { // if vm were succesfully created in the host
getVmTable().put(vm.getUid(), host);
createdVmNum++;
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),CloudSim.clock());
result = true;
}
}
}
return result;
}
@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);
createdVmNum++;
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),CloudSim.clock());
return true;
}
return false;
}
@Override
public List<Map<String, Object>> optimizeAllocation(
List<? extends Vm> vmList) {
// TODO Auto-generated method stub
return null;
}
@Override
public void deallocateHostForVm(Vm vm) {
Host host = getVmTable().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
}
}
@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}
@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}
public static int getCreatedVmNum(){
return createdVmNum;
}
/**
* 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;
}
}