├── .gitattributes ├── .gitignore ├── FCFS.txt ├── GP.txt ├── OLB.txt ├── README.txt └── SJF.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # ========================= 15 | # Operating System Files 16 | # ========================= 17 | 18 | # OSX 19 | # ========================= 20 | 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Thumbnails 26 | ._* 27 | 28 | # Files that might appear in the root of a volume 29 | .DocumentRevisions-V100 30 | .fseventsd 31 | .Spotlight-V100 32 | .TemporaryItems 33 | .Trashes 34 | .VolumeIcon.icns 35 | 36 | # Directories potentially created on remote AFP share 37 | .AppleDB 38 | .AppleDesktop 39 | Network Trash Folder 40 | Temporary Items 41 | .apdisk 42 | 43 | # Windows 44 | # ========================= 45 | 46 | # Windows image file caches 47 | Thumbs.db 48 | ehthumbs.db 49 | 50 | # Folder config file 51 | Desktop.ini 52 | 53 | # Recycle Bin used on file shares 54 | $RECYCLE.BIN/ 55 | 56 | # Windows Installer files 57 | *.cab 58 | *.msi 59 | *.msm 60 | *.msp 61 | 62 | # Windows shortcuts 63 | *.lnk 64 | -------------------------------------------------------------------------------- /FCFS.txt: -------------------------------------------------------------------------------- 1 | //FCFS 2 | 3 | /* 4 | * Title: CloudSim Toolkit 5 | * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation 6 | * of Clouds 7 | * Licence: GPL - http://www.gnu.org/copyleft/gpl.html 8 | * 9 | * Copyright (c) 2009, The University of Melbourne, Australia 10 | */ 11 | 12 | package trial; 13 | 14 | 15 | import java.text.DecimalFormat; 16 | import java.util.ArrayList; 17 | import java.util.Calendar; 18 | import java.util.LinkedList; 19 | import java.util.List; 20 | import java.lang.Object; 21 | 22 | import org.cloudbus.cloudsim.core.SimEntity; 23 | import org.cloudbus.cloudsim.Cloudlet; 24 | import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared; 25 | import org.cloudbus.cloudsim.CloudletSchedulerTimeShared; 26 | import org.cloudbus.cloudsim.Datacenter; 27 | import org.cloudbus.cloudsim.DatacenterBroker; 28 | import org.cloudbus.cloudsim.DatacenterCharacteristics; 29 | import org.cloudbus.cloudsim.Host; 30 | import org.cloudbus.cloudsim.Log; 31 | import org.cloudbus.cloudsim.Pe; 32 | import org.cloudbus.cloudsim.Storage; 33 | import org.cloudbus.cloudsim.UtilizationModel; 34 | import org.cloudbus.cloudsim.UtilizationModelFull; 35 | import org.cloudbus.cloudsim.Vm; 36 | import org.cloudbus.cloudsim.VmAllocationPolicySimple; 37 | import org.cloudbus.cloudsim.VmSchedulerTimeShared; 38 | import org.cloudbus.cloudsim.core.CloudSim; 39 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 40 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 41 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 42 | 43 | 44 | /** 45 | * A simple example showing how to create 46 | * a datacenter with one host and run two 47 | * cloudlets on it. The cloudlets run in 48 | * VMs with the same MIPS requirements. 49 | * The cloudlets will take the same time to 50 | * complete the execution. 51 | */ 52 | public class Trial { 53 | 54 | /** The cloudlet list. */ 55 | private static List cloudletList; 56 | 57 | /** The vmlist. */ 58 | private static List vmlist; 59 | 60 | /** 61 | * Creates main() to run this example 62 | */ 63 | public static void main(String[] args) { 64 | 65 | Log.printLine("Starting CloudSimExample2..."); 66 | 67 | try { 68 | // First step: Initialize the CloudSim package. It should be called 69 | // before creating any entities. 70 | int num_user = 1; // number of cloud users 71 | Calendar calendar = Calendar.getInstance(); 72 | boolean trace_flag = false; // mean trace events 73 | 74 | // Initialize the CloudSim library 75 | CloudSim.init(num_user, calendar, trace_flag); 76 | 77 | // Second step: Create Datacenters 78 | //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation 79 | @SuppressWarnings("unused") 80 | Datacenter datacenter0 = createDatacenter("Datacenter_0"); 81 | 82 | //Third step: Create Broker 83 | DatacenterBroker broker = createBroker(); 84 | int brokerId = broker.getId(); 85 | 86 | int vms = 50; 87 | int cloudlets=1000; 88 | 89 | //Fourth step: Create one virtual machine 90 | vmlist = new ArrayList(); 91 | 92 | long size = 1000; //image size (MB) 93 | int ram = 512; //vm memory (MB) 94 | int mips = 250; 95 | long bw = 1000; 96 | int pesNumber = 1; //number of cpus 97 | String vmm = "Xen"; //VMM name 98 | int jk=1; 99 | //create VMs 100 | Vm[] vm = new Vm[vms]; 101 | //Log.printLine("*************************************"+ vms); 102 | for(int i=0;i(); 119 | 120 | //Cloudlet properties 121 | long length = 4000; 122 | long fileSize = 300; 123 | long outputSize = 300; 124 | int pesNumber1 = 1; 125 | UtilizationModel utilizationModel = new UtilizationModelFull(); 126 | 127 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 128 | 129 | for(int i=0;i hostList = new ArrayList(); 177 | 178 | // 2. A Machine contains one or more PEs or CPUs/Cores. 179 | // In this example, it will have only one core. 180 | List peList = new ArrayList(); 181 | 182 | int mips = 102400; 183 | 184 | // 3. Create PEs and add these into a list. 185 | peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating 186 | 187 | //4. Create Host with its id and list of PEs and add them to the list of machines 188 | int hostId=0; 189 | int ram = 102400; //host memory (MB) 190 | long storage = 1000000; //host storage 191 | int bw = 200000; 192 | 193 | hostList.add( 194 | new Host( 195 | hostId, 196 | new RamProvisionerSimple(ram), 197 | new BwProvisionerSimple(bw), 198 | storage, 199 | peList, 200 | new VmSchedulerTimeShared(peList) 201 | ) 202 | ); // This is our machine 203 | 204 | 205 | // 5. Create a DatacenterCharacteristics object that stores the 206 | // properties of a data center: architecture, OS, list of 207 | // Machines, allocation policy: time- or space-shared, time zone 208 | // and its price (G$/Pe time unit). 209 | String arch = "x86"; // system architecture 210 | String os = "Linux"; // operating system 211 | String vmm = "Xen"; 212 | double time_zone = 10.0; // time zone this resource located 213 | double cost = 3.0; // the cost of using processing in this resource 214 | double costPerMem = 0.05; // the cost of using memory in this resource 215 | double costPerStorage = 0.001; // the cost of using storage in this resource 216 | double costPerBw = 0.0; // the cost of using bw in this resource 217 | LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now 218 | 219 | DatacenterCharacteristics characteristics = new DatacenterCharacteristics( 220 | arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw); 221 | 222 | 223 | // 6. Finally, we need to create a PowerDatacenter object. 224 | Datacenter datacenter = null; 225 | try { 226 | datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0); 227 | } catch (Exception e) { 228 | e.printStackTrace(); 229 | } 230 | 231 | return datacenter; 232 | } 233 | 234 | //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according 235 | //to the specific rules of the simulated scenario 236 | private static DatacenterBroker createBroker(){ 237 | 238 | DatacenterBroker broker = null; 239 | try { 240 | broker = new DatacenterBroker("Broker"); 241 | } catch (Exception e) { 242 | e.printStackTrace(); 243 | return null; 244 | } 245 | return broker; 246 | } 247 | 248 | /** 249 | * Prints the Cloudlet objects 250 | * @param list list of Cloudlets 251 | */ 252 | private static void printCloudletList(List list) { 253 | int size = list.size(); 254 | Cloudlet cloudlet; 255 | 256 | String indent = " "; 257 | Log.printLine(); 258 | Log.printLine("========== OUTPUT =========="); 259 | Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + 260 | "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time"); 261 | 262 | DecimalFormat dft = new DecimalFormat("###.##"); 263 | for (int i = 0; i < size; i++) { 264 | cloudlet = list.get(i); 265 | Log.print(indent + cloudlet.getCloudletId() + indent + indent); 266 | 267 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){ 268 | Log.print("SUCCESS"); 269 | 270 | Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() + 271 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+ 272 | indent + indent + dft.format(cloudlet.getFinishTime())); 273 | 274 | } 275 | } 276 | 277 | 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /GP.txt: -------------------------------------------------------------------------------- 1 | //GENERALIZED Priority Algorithm 2 | 3 | 4 | 5 | /* 6 | * Title: CloudSim Toolkit 7 | * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation 8 | * of Clouds 9 | * Licence: GPL - http://www.gnu.org/copyleft/gpl.html 10 | * 11 | * Copyright (c) 2009, The University of Melbourne, Australia 12 | */ 13 | 14 | package third; 15 | 16 | 17 | import java.text.DecimalFormat; 18 | import java.util.ArrayList; 19 | import java.util.Calendar; 20 | import java.util.LinkedList; 21 | import java.util.List; 22 | 23 | import org.cloudbus.cloudsim.Cloudlet; 24 | import org.cloudbus.cloudsim.CloudletSchedulerTimeShared; 25 | import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared; 26 | import org.cloudbus.cloudsim.Datacenter; 27 | import org.cloudbus.cloudsim.DatacenterBroker; 28 | import org.cloudbus.cloudsim.DatacenterCharacteristics; 29 | import org.cloudbus.cloudsim.Host; 30 | import org.cloudbus.cloudsim.Log; 31 | import org.cloudbus.cloudsim.Pe; 32 | import org.cloudbus.cloudsim.Storage; 33 | import org.cloudbus.cloudsim.UtilizationModel; 34 | import org.cloudbus.cloudsim.UtilizationModelFull; 35 | import org.cloudbus.cloudsim.Vm; 36 | import org.cloudbus.cloudsim.VmAllocationPolicySimple; 37 | import org.cloudbus.cloudsim.VmSchedulerTimeShared; 38 | import org.cloudbus.cloudsim.core.CloudSim; 39 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 40 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 41 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 42 | 43 | 44 | /** 45 | * A simple example showing how to create 46 | * a datacenter with one host and run two 47 | * cloudlets on it. The cloudlets run in 48 | * VMs with the same MIPS requirements. 49 | * The cloudlets will take the same time to 50 | * complete the execution. 51 | */ 52 | public class Third { 53 | 54 | /** The cloudlet list. */ 55 | private static List cloudletList; 56 | 57 | /** The vmlist. */ 58 | private static List vmlist; 59 | 60 | /** 61 | * Creates main() to run this example 62 | */ 63 | public static void main(String[] args) { 64 | 65 | Log.printLine("Starting CloudSimExample2..."); 66 | 67 | try { 68 | // First step: Initialize the CloudSim package. It should be called 69 | // before creating any entities. 70 | int num_user = 1; // number of cloud users 71 | Calendar calendar = Calendar.getInstance(); 72 | boolean trace_flag = false; // mean trace events 73 | 74 | // Initialize the CloudSim library 75 | CloudSim.init(num_user, calendar, trace_flag); 76 | 77 | // Second step: Create Datacenters 78 | //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation 79 | @SuppressWarnings("unused") 80 | Datacenter datacenter0 = createDatacenter("Datacenter_0"); 81 | 82 | //Third step: Create Broker 83 | DatacenterBroker broker = createBroker(); 84 | int brokerId = broker.getId(); 85 | 86 | //Fourth step: Create one virtual machine 87 | vmlist = new ArrayList(); 88 | 89 | int vms = 10; 90 | int cloudlets = 700; 91 | 92 | //VM description 93 | int vmid = 0; 94 | long size = 1000; //image size (MB) 95 | int ram = 512; //vm memory (MB) 96 | int mips = 250; 97 | long bw = 1000; 98 | int pesNumber = 1; //number of cpus 99 | String vmm = "Xen"; //VMM name 100 | 101 | 102 | //create two VMs 103 | int jk=1; 104 | 105 | Vm vm[]=new Vm[vms]; 106 | 107 | for(int i=0; i lstvms = vmlist; 122 | for (int a = 0; a < lstvms.size(); a++) { 123 | for (int b = a + 1; b < lstvms.size(); b++) { 124 | if (lstvms.get(b).getMips() > lstvms.get(a).getMips()) { 125 | Vm temp = lstvms.get(a); 126 | lstvms.set(a, lstvms.get(b)); 127 | lstvms.set(b, temp); 128 | } 129 | } 130 | } 131 | for (Vm mm : lstvms) { 132 | System.out.println("Vm id = " + mm.getId() + " - MIPS = " + mm.getMips()); 133 | } 134 | 135 | 136 | //add the VMs to the vmList 137 | //vmlist.add(vm[1]); 138 | 139 | 140 | //submit vm list to the broker 141 | broker.submitVmList(lstvms); 142 | 143 | 144 | //Fifth step: Create two Cloudlets 145 | cloudletList = new ArrayList(); 146 | 147 | 148 | 149 | //Cloudlet properties 150 | int id = 0; 151 | long length = 4000; 152 | long fileSize = 300; 153 | long outputSize = 300; 154 | 155 | UtilizationModel utilizationModel = new UtilizationModelFull(); 156 | 157 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 158 | 159 | for(int i=0;i lstCloudlets = cloudletList; 174 | for (int a = 0; a < lstCloudlets.size(); a++) { 175 | for (int b = a + 1; b < lstCloudlets.size(); b++) { 176 | if (lstCloudlets.get(b).getCloudletLength() > lstCloudlets.get(a).getCloudletLength()) { 177 | Cloudlet temp = lstCloudlets.get(a); 178 | lstCloudlets.set(a, lstCloudlets.get(b)); 179 | lstCloudlets.set(b, temp); 180 | } 181 | } 182 | } 183 | //for (Cloudlet cl : lstCloudlets) { 184 | /* System.out.println("Cloudlet id = " + cl.getCloudletId() + " - Length = " + cl.getCloudletLength());*/ 185 | //} 186 | //submit cloudlet list to the broker 187 | broker.submitCloudletList(lstCloudlets); 188 | 189 | //broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId()); 190 | //broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId()); 191 | 192 | // Sixth step: Starts the simulation 193 | CloudSim.startSimulation(); 194 | 195 | 196 | // Final step: Print results when simulation is over 197 | List newList = broker.getCloudletReceivedList(); 198 | 199 | CloudSim.stopSimulation(); 200 | 201 | printCloudletList(newList); 202 | 203 | Log.printLine("CloudSimExample2 finished!"); 204 | } 205 | catch (Exception e) { 206 | e.printStackTrace(); 207 | Log.printLine("The simulation has been terminated due to an unexpected error"); 208 | } 209 | } 210 | 211 | private static Datacenter createDatacenter(String name){ 212 | 213 | // Here are the steps needed to create a PowerDatacenter: 214 | // 1. We need to create a list to store 215 | // our machine 216 | List hostList = new ArrayList(); 217 | 218 | // 2. A Machine contains one or more PEs or CPUs/Cores. 219 | // In this example, it will have only one core. 220 | List peList = new ArrayList(); 221 | 222 | int mips = 302400; 223 | 224 | // 3. Create PEs and add these into a list. 225 | peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating 226 | 227 | //4. Create Host with its id and list of PEs and add them to the list of machines 228 | int hostId=0; 229 | int ram = 102400; //host memory (MB) 230 | long storage = 1000000; //host storage 231 | int bw = 200000; 232 | 233 | hostList.add( 234 | new Host( 235 | hostId, 236 | new RamProvisionerSimple(ram), 237 | new BwProvisionerSimple(bw), 238 | storage, 239 | peList, 240 | new VmSchedulerTimeShared(peList) 241 | ) 242 | ); // This is our machine 243 | 244 | 245 | // 5. Create a DatacenterCharacteristics object that stores the 246 | // properties of a data center: architecture, OS, list of 247 | // Machines, allocation policy: time- or space-shared, time zone 248 | // and its price (G$/Pe time unit). 249 | String arch = "x86"; // system architecture 250 | String os = "Linux"; // operating system 251 | String vmm = "Xen"; 252 | double time_zone = 10.0; // time zone this resource located 253 | double cost = 3.0; // the cost of using processing in this resource 254 | double costPerMem = 0.05; // the cost of using memory in this resource 255 | double costPerStorage = 0.001; // the cost of using storage in this resource 256 | double costPerBw = 0.0; // the cost of using bw in this resource 257 | LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now 258 | 259 | DatacenterCharacteristics characteristics = new DatacenterCharacteristics( 260 | arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw); 261 | 262 | 263 | // 6. Finally, we need to create a PowerDatacenter object. 264 | Datacenter datacenter = null; 265 | try { 266 | datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0); 267 | } catch (Exception e) { 268 | e.printStackTrace(); 269 | } 270 | 271 | return datacenter; 272 | } 273 | 274 | //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according 275 | //to the specific rules of the simulated scenario 276 | private static DatacenterBroker createBroker(){ 277 | 278 | DatacenterBroker broker = null; 279 | try { 280 | broker = new DatacenterBroker("Broker"); 281 | } catch (Exception e) { 282 | e.printStackTrace(); 283 | return null; 284 | } 285 | return broker; 286 | } 287 | 288 | /** 289 | * Prints the Cloudlet objects 290 | * @param list list of Cloudlets 291 | */ 292 | private static void printCloudletList(List list) { 293 | int size = list.size(); 294 | Cloudlet cloudlet; 295 | 296 | String indent = " "; 297 | Log.printLine(); 298 | Log.printLine("========== OUTPUT =========="); 299 | Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + 300 | "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time"); 301 | 302 | DecimalFormat dft = new DecimalFormat("###.##"); 303 | for (int i = 0; i < size; i++) { 304 | cloudlet = list.get(i); 305 | Log.print(indent + cloudlet.getCloudletId() + indent + indent); 306 | 307 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){ 308 | Log.print("SUCCESS"); 309 | 310 | Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() + 311 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+ 312 | indent + indent + dft.format(cloudlet.getFinishTime())); 313 | } 314 | else 315 | { 316 | Log.print("Failure"); 317 | } 318 | } 319 | 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /OLB.txt: -------------------------------------------------------------------------------- 1 | //OPPORTUNISTIC load Balancing 2 | 3 | 4 | /* 5 | * Title: CloudSim Toolkit 6 | * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation 7 | * of Clouds 8 | * Licence: GPL - http://www.gnu.org/copyleft/gpl.html 9 | * 10 | * Copyright (c) 2009, The University of Melbourne, Australia 11 | */ 12 | 13 | package round; 14 | 15 | 16 | import java.text.DecimalFormat; 17 | import java.util.ArrayList; 18 | import java.util.Calendar; 19 | import java.util.LinkedList; 20 | import java.util.List; 21 | 22 | import org.cloudbus.cloudsim.Cloudlet; 23 | import org.cloudbus.cloudsim.CloudletSchedulerTimeShared; 24 | import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared; 25 | import org.cloudbus.cloudsim.Datacenter; 26 | import org.cloudbus.cloudsim.DatacenterBroker; 27 | import org.cloudbus.cloudsim.DatacenterCharacteristics; 28 | import org.cloudbus.cloudsim.Host; 29 | import org.cloudbus.cloudsim.Log; 30 | import org.cloudbus.cloudsim.Pe; 31 | import org.cloudbus.cloudsim.Storage; 32 | import org.cloudbus.cloudsim.UtilizationModel; 33 | import org.cloudbus.cloudsim.UtilizationModelFull; 34 | import org.cloudbus.cloudsim.Vm; 35 | import org.cloudbus.cloudsim.VmAllocationPolicySimple; 36 | import org.cloudbus.cloudsim.VmSchedulerTimeShared; 37 | import org.cloudbus.cloudsim.core.CloudSim; 38 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 39 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 40 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 41 | 42 | 43 | /** 44 | * A simple example showing how to create 45 | * a datacenter with one host and run two 46 | * cloudlets on it. The cloudlets run in 47 | * VMs with the same MIPS requirements. 48 | * The cloudlets will take the same time to 49 | * complete the execution. 50 | */ 51 | public class Round { 52 | 53 | /** The cloudlet list. */ 54 | private static List cloudletList; 55 | 56 | /** The vmlist. */ 57 | private static List vmlist; 58 | 59 | /** 60 | * Creates main() to run this example 61 | */ 62 | public static void main(String[] args) { 63 | 64 | Log.printLine("Starting CloudSimExample2..."); 65 | 66 | try { 67 | // First step: Initialize the CloudSim package. It should be called 68 | // before creating any entities. 69 | int num_user = 1; // number of cloud users 70 | Calendar calendar = Calendar.getInstance(); 71 | boolean trace_flag = false; // mean trace events 72 | 73 | // Initialize the CloudSim library 74 | CloudSim.init(num_user, calendar, trace_flag); 75 | 76 | // Second step: Create Datacenters 77 | //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation 78 | @SuppressWarnings("unused") 79 | Datacenter datacenter0 = createDatacenter("Datacenter_0"); 80 | 81 | //Third step: Create Broker 82 | RDatacenterBroker broker = createBroker(); 83 | int brokerId = broker.getId(); 84 | 85 | //Fourth step: Create one virtual machine 86 | vmlist = new ArrayList(); 87 | 88 | int vms = 100; 89 | int cloudlets = 700; 90 | 91 | //VM description 92 | int vmid = 0; 93 | long size = 1000; //image size (MB) 94 | int ram = 512; //vm memory (MB) 95 | int mips = 250; 96 | long bw = 1000; 97 | int pesNumber = 1; //number of cpus 98 | String vmm = "Xen"; //VMM name 99 | 100 | int jk=1; 101 | //create two VMs 102 | 103 | Vm vm[]=new Vm[vms]; 104 | 105 | for(int i=0; i(); 128 | 129 | 130 | 131 | //Cloudlet properties 132 | int id = 0; 133 | long length = 4000; 134 | long fileSize = 300; 135 | long outputSize = 300; 136 | 137 | UtilizationModel utilizationModel = new UtilizationModelFull(); 138 | 139 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 140 | 141 | for(int i=0;i=cloudletsize[j]) 178 | { min=j; least=cloudletsize[j];} 179 | } 180 | //Log.printLine("jkhgjghjhgjgjhgj" +cloudlet[i].getCloudletTotalLength() ); 181 | broker.bindCloudletToVm(cloudlet[i].getCloudletId(),vm[min].getId()); 182 | cloudletsize[min]+=cloudlet[i].getCloudletTotalLength(); 183 | } 184 | //broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId()); 185 | //broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId()); 186 | 187 | // Sixth step: Starts the simulation 188 | CloudSim.startSimulation(); 189 | 190 | 191 | // Final step: Print results when simulation is over 192 | List newList = broker.getCloudletReceivedList(); 193 | 194 | CloudSim.stopSimulation(); 195 | 196 | printCloudletList(newList); 197 | 198 | Log.printLine("CloudSimExample2 finished!"); 199 | } 200 | catch (Exception e) { 201 | e.printStackTrace(); 202 | Log.printLine("The simulation has been terminated due to an unexpected error"); 203 | } 204 | } 205 | 206 | private static Datacenter createDatacenter(String name){ 207 | 208 | // Here are the steps needed to create a PowerDatacenter: 209 | // 1. We need to create a list to store 210 | // our machine 211 | List hostList = new ArrayList(); 212 | 213 | // 2. A Machine contains one or more PEs or CPUs/Cores. 214 | // In this example, it will have only one core. 215 | List peList = new ArrayList(); 216 | 217 | int mips = 102400; 218 | 219 | // 3. Create PEs and add these into a list. 220 | peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating 221 | 222 | //4. Create Host with its id and list of PEs and add them to the list of machines 223 | int hostId=0; 224 | int ram = 102400; //host memory (MB) 225 | long storage = 1000000; //host storage 226 | int bw = 200000; 227 | 228 | hostList.add( 229 | new Host( 230 | hostId, 231 | new RamProvisionerSimple(ram), 232 | new BwProvisionerSimple(bw), 233 | storage, 234 | peList, 235 | new VmSchedulerTimeShared(peList) 236 | ) 237 | ); // This is our machine 238 | 239 | 240 | // 5. Create a DatacenterCharacteristics object that stores the 241 | // properties of a data center: architecture, OS, list of 242 | // Machines, allocation policy: time- or space-shared, time zone 243 | // and its price (G$/Pe time unit). 244 | String arch = "x86"; // system architecture 245 | String os = "Linux"; // operating system 246 | String vmm = "Xen"; 247 | double time_zone = 10.0; // time zone this resource located 248 | double cost = 3.0; // the cost of using processing in this resource 249 | double costPerMem = 0.05; // the cost of using memory in this resource 250 | double costPerStorage = 0.001; // the cost of using storage in this resource 251 | double costPerBw = 0.0; // the cost of using bw in this resource 252 | LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now 253 | 254 | DatacenterCharacteristics characteristics = new DatacenterCharacteristics( 255 | arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw); 256 | 257 | 258 | // 6. Finally, we need to create a PowerDatacenter object. 259 | Datacenter datacenter = null; 260 | try { 261 | datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0); 262 | } catch (Exception e) { 263 | e.printStackTrace(); 264 | } 265 | 266 | return datacenter; 267 | } 268 | 269 | //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according 270 | //to the specific rules of the simulated scenario 271 | private static RDatacenterBroker createBroker(){ 272 | 273 | RDatacenterBroker broker = null; 274 | try { 275 | broker = new RDatacenterBroker("Broker"); 276 | } catch (Exception e) { 277 | e.printStackTrace(); 278 | return null; 279 | } 280 | return broker; 281 | } 282 | 283 | /** 284 | * Prints the Cloudlet objects 285 | * @param list list of Cloudlets 286 | */ 287 | private static void printCloudletList(List list) { 288 | int size = list.size(); 289 | Cloudlet cloudlet; 290 | 291 | String indent = " "; 292 | Log.printLine(); 293 | Log.printLine("========== OUTPUT =========="); 294 | Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + 295 | "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time"); 296 | 297 | DecimalFormat dft = new DecimalFormat("###.##"); 298 | for (int i = 0; i < size; i++) { 299 | cloudlet = list.get(i); 300 | Log.print(indent + cloudlet.getCloudletId() + indent + indent); 301 | 302 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){ 303 | Log.print("SUCCESS"); 304 | 305 | Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() + 306 | indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+ 307 | indent + indent + dft.format(cloudlet.getFinishTime())); 308 | } 309 | } 310 | 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | # Evaluating-cloud-computing-scheduling-algorithms-against-a-variety-of-environments-and-scenarios 2 | Codes for implementing SJF,FCFS, Generalized Priority, Opportunistic Load Balancing algorithm in CloudSim in Netbeans. 3 | 4 | There are four txt file for the code of each scheduling algorithm i used. To run them, implement them in a JAVA IDE along with 5 | CLOUDSIM library included. Assign the number of Vms in the program itself as it requires user input now and also the cloudlet 6 | lengths should be stored in a file input.txt on the desktop. 7 | -------------------------------------------------------------------------------- /SJF.txt: -------------------------------------------------------------------------------- 1 | //SJF 2 | 3 | package myappp; 4 | 5 | import java.text.DecimalFormat; 6 | import java.util.ArrayList; 7 | import java.util.Calendar; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | 11 | import org.cloudbus.cloudsim.Cloudlet; 12 | import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared; 13 | import org.cloudbus.cloudsim.CloudletSchedulerTimeShared; 14 | import org.cloudbus.cloudsim.Datacenter; 15 | import org.cloudbus.cloudsim.DatacenterBroker; 16 | import org.cloudbus.cloudsim.DatacenterCharacteristics; 17 | import org.cloudbus.cloudsim.Host; 18 | import org.cloudbus.cloudsim.Log; 19 | import org.cloudbus.cloudsim.Pe; 20 | import org.cloudbus.cloudsim.Storage; 21 | import org.cloudbus.cloudsim.UtilizationModel; 22 | import org.cloudbus.cloudsim.UtilizationModelFull; 23 | import org.cloudbus.cloudsim.Vm; 24 | import org.cloudbus.cloudsim.VmAllocationPolicySimple; 25 | import org.cloudbus.cloudsim.VmSchedulerTimeShared; 26 | import org.cloudbus.cloudsim.core.CloudSim; 27 | import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; 28 | import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; 29 | import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; 30 | 31 | /** 32 | * An Self test simulation will show how to 20 cloudlets will be distributed among 33 | * 05 Vms with different MIPS requirements. 34 | */ 35 | public class Myappp { 36 | 37 | /** The cloudlet list. */ 38 | private static List cloudletList,cloudletListSJF; 39 | 40 | /** The vmlist. */ 41 | private static List vmlist; 42 | 43 | private static List createVM(int userId, int vms, int idShift) { 44 | //Creates a container to store VMs. This list is passed to the broker later 45 | LinkedList list = new LinkedList(); 46 | 47 | //VM Parameters 48 | long size = 1000; //image size (MB) 49 | int ram = 512; //vm memory (MB) 50 | int mips = 250; 51 | long bw = 1000; 52 | int pesNumber = 1; //number of cpus 53 | String vmm = "Xen"; //VMM name 54 | int jk=1; 55 | //create VMs 56 | Vm[] vm = new Vm[vms]; 57 | //Log.printLine("*************************************"+ vms); 58 | for(int i=0;i createCloudlet(int userId, int cloudlets, int idShift){ 75 | // Creates a container to store Cloudlets 76 | LinkedList list = new LinkedList(); 77 | 78 | //cloudlet parameters 79 | long length = 4000; 80 | long fileSize = 300; 81 | long outputSize = 300; 82 | int pesNumber = 1; 83 | UtilizationModel utilizationModel = new UtilizationModelFull(); 84 | 85 | Cloudlet[] cloudlet = new Cloudlet[cloudlets]; 86 | 87 | for(int i=0;i clist) 117 | { 118 | Cloudlet c; 119 | for (int i=0; i list, int VmId) 131 | { 132 | int c = 0; 133 | double art = 0; 134 | for(int i=0;i list, int VmId) 144 | { 145 | double mkspane = 0; 146 | for(int i=0;i mkspane) 149 | mkspane = list.get(i).getFinishTime(); 150 | return mkspane; 151 | } 152 | 153 | ////////////////////////// STATIC METHODS /////////////////////// 154 | /** 155 | * Creates main() to run this example 156 | */ 157 | public static void main(String[] args) { 158 | Log.printLine("Starting CloudSimTestSJF..."); 159 | 160 | try { 161 | // First step: Initialize the CloudSim package. It should be called 162 | // before creating any entities. 163 | int num_user = 1; // number of cloud users 164 | Calendar calendar = Calendar.getInstance(); 165 | boolean trace_flag = false; // mean trace events 166 | 167 | // Initialize the CloudSim library 168 | CloudSim.init(num_user, calendar, trace_flag); 169 | 170 | // Second step: Create Datacenters 171 | //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation 172 | Datacenter datacenter0 = createDatacenter("Datacenter_0"); 173 | 174 | //Third step: Create Broker 175 | //RoundRobinDatacenterBroker broker = new RoundRobinDatacenterBroker("Broker"); 176 | 177 | int vms = 10; 178 | int cloudlets=50; 179 | 180 | 181 | DatacenterBroker broker = createBroker("Broker_0"); 182 | 183 | int brokerId = broker.getId(); 184 | 185 | //Fourth step: Create five virtual machine 186 | vmlist = createVM(brokerId, vms, 0); //creating 1 vms 187 | 188 | //submit vm list to the broker 189 | broker.submitVmList(vmlist); 190 | 191 | //Fifth step: Create ten Cloudlets 192 | cloudletList = createCloudlet(brokerId, cloudlets, 0); // creating 10 cloudlets 193 | 194 | Log.printLine("cloudletlist size = " + cloudletList.size()); 195 | cloudletListSJF = new LinkedList(); 196 | getCloudletListSJF(cloudletList); 197 | //sortCloudletList(cloudletList); 198 | 199 | //submit cloudlet list to the broker 200 | broker.submitCloudletList(cloudletListSJF); 201 | 202 | 203 | // Sixth step: Starts the simulation 204 | CloudSim.startSimulation(); 205 | 206 | 207 | // Final step: Print results when simulation is over 208 | List newList = broker.getCloudletReceivedList(); 209 | 210 | CloudSim.stopSimulation(); 211 | 212 | printCloudletList(newList); 213 | 214 | //for (int a=0; a hostList = new ArrayList(); 237 | 238 | // 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should 239 | // create a list to store these PEs before creating 240 | // a Machine. 241 | List peList1 = new ArrayList(); 242 | 243 | int mips = 102400; 244 | 245 | // 3. Create PEs and add these into the list. 246 | //for a quad-core machine, a list of 4 PEs is required: 247 | peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating 248 | peList1.add(new Pe(1, new PeProvisionerSimple(mips))); 249 | peList1.add(new Pe(2, new PeProvisionerSimple(mips))); 250 | peList1.add(new Pe(3, new PeProvisionerSimple(mips))); 251 | 252 | //Another list, for a dual-core machine 253 | List peList2 = new ArrayList(); 254 | 255 | peList2.add(new Pe(0, new PeProvisionerSimple(mips))); 256 | peList2.add(new Pe(1, new PeProvisionerSimple(mips))); 257 | 258 | //4. Create Hosts with its id and list of PEs and add them to the list of machines 259 | int hostId=0; 260 | int ram = 102400; //host memory (MB) 261 | long storage = 1000000; //host storage 262 | int bw = 200000; 263 | 264 | hostList.add( 265 | new Host( 266 | hostId, 267 | new RamProvisionerSimple(ram), 268 | new BwProvisionerSimple(bw), 269 | storage, 270 | peList1, 271 | new VmSchedulerTimeShared(peList1) 272 | ) 273 | ); // This is our first machine 274 | 275 | hostId++; 276 | 277 | /*hostList.add( 278 | new Host( 279 | hostId, 280 | new RamProvisionerSimple(ram), 281 | new BwProvisionerSimple(bw), 282 | storage, 283 | peList2, 284 | new VmSchedulerTimeShared(peList2) 285 | ) 286 | ); // Second machine */ 287 | 288 | // 5. Create a DatacenterCharacteristics object that stores the 289 | // properties of a data center: architecture, OS, list of 290 | // Machines, allocation policy: time- or space-shared, time zone 291 | // and its price (G$/Pe time unit). 292 | String arch = "x86"; // system architecture 293 | String os = "Linux"; // operating system 294 | String vmm = "Xen"; 295 | double time_zone = 10.0; // time zone this resource located 296 | double cost = 3.0; // the cost of using processing in this resource 297 | double costPerMem = 0.05; // the cost of using memory in this resource 298 | double costPerStorage = 0.1; // the cost of using storage in this resource 299 | double costPerBw = 0.1; // the cost of using bw in this resource 300 | LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now 301 | 302 | DatacenterCharacteristics characteristics = new DatacenterCharacteristics( 303 | arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw); 304 | 305 | 306 | // 6. Finally, we need to create a PowerDatacenter object. 307 | Datacenter datacenter = null; 308 | try { 309 | datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0); 310 | } catch (Exception e) { 311 | e.printStackTrace(); 312 | } 313 | 314 | return datacenter; 315 | } 316 | //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according 317 | //to the specific rules of the simulated scenario 318 | private static DatacenterBroker createBroker(String name){ 319 | 320 | DatacenterBroker broker = null; 321 | try { 322 | broker = new DatacenterBroker(name); 323 | } catch (Exception e) { 324 | e.printStackTrace(); 325 | return null; 326 | } 327 | return broker; 328 | } 329 | /** 330 | * Prints the Cloudlet objects 331 | * @param list list of Cloudlets 332 | */ 333 | private static void printCloudletList(List list) { 334 | int size = list.size(); 335 | Cloudlet cloudlet; 336 | 337 | double avrt=0; 338 | 339 | String indent = " "; 340 | Log.printLine(); 341 | Log.printLine("========== OUTPUT =========="); 342 | Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + 343 | "Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time"); 344 | 345 | DecimalFormat dft = new DecimalFormat("###.##"); 346 | for (int i = 0; i < size; i++) { 347 | cloudlet = list.get(i); 348 | Log.print(indent + cloudlet.getCloudletId() + indent + indent); 349 | 350 | if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){ 351 | Log.print("SUCCESS"); 352 | avrt += cloudlet.getActualCPUTime(); 353 | Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() + 354 | indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) + 355 | indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime())); 356 | 357 | } 358 | else 359 | { 360 | Log.print("Failure"); 361 | } 362 | 363 | 364 | } 365 | //Log.printLine("Average execution Time = " + avrt/size); 366 | 367 | } 368 | } 369 | 370 | --------------------------------------------------------------------------------