diff --git a/trunk/distribution/pom.xml b/trunk/distribution/pom.xml
new file mode 100644
index 000000000..a4e38f983
--- /dev/null
+++ b/trunk/distribution/pom.xml
@@ -0,0 +1,79 @@
+
+ 4.0.0
+
+ cloudsim-package
+ org.cloudbus.cloudsim
+ 3.0.1
+
+ distribution
+ pom
+ distribution
+
+
+
+ cloudsim-${project.version}
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ install
+
+ single
+
+
+
+
+
+ src/main/assembly/package.xml
+
+ false
+
+
+
+
+
+
+
+ ${project.groupId}
+ cloudsim
+ ${project.version}
+ jar
+
+
+ ${project.groupId}
+ cloudsim
+ ${project.version}
+ jar
+ sources
+
+
+ ${project.groupId}
+ cloudsim
+ ${project.version}
+ jar
+ javadoc
+
+
+ ${project.groupId}
+ cloudsim-examples
+ ${project.version}
+ jar
+
+
+ ${project.groupId}
+ cloudsim-examples
+ ${project.version}
+ jar
+ sources
+
+
+ ${project.groupId}
+ documentation
+ ${project.version}
+ jar
+
+
+
+
\ No newline at end of file
diff --git a/trunk/distribution/src/main/assembly/package.xml b/trunk/distribution/src/main/assembly/package.xml
new file mode 100644
index 000000000..486fef7c1
--- /dev/null
+++ b/trunk/distribution/src/main/assembly/package.xml
@@ -0,0 +1,66 @@
+
+ package
+
+ tar.gz
+ zip
+
+
+
+ jars
+
+ ${project.groupId}:cloudsim:jar
+ ${project.groupId}:cloudsim:jar:sources
+ ${project.groupId}:cloudsim-examples:jar
+ ${project.groupId}:cloudsim-examples:jar:sources
+
+
+
+ sources
+ true
+
+
+ META-INF/
+
+
+
+ ${project.groupId}:cloudsim:jar:sources
+
+
+
+ examples
+ true
+
+
+ META-INF/
+
+
+
+ ${project.groupId}:cloudsim-examples:jar:sources
+
+
+
+ true
+
+
+ META-INF/
+
+
+ /
+
+ ${project.groupId}:documentation
+
+
+
+ docs
+ true
+
+
+ META-INF/
+
+
+
+ ${project.groupId}:cloudsim:jar:javadoc
+
+
+
+
\ No newline at end of file
diff --git a/trunk/documentation/pom.xml b/trunk/documentation/pom.xml
new file mode 100644
index 000000000..5072338e4
--- /dev/null
+++ b/trunk/documentation/pom.xml
@@ -0,0 +1,10 @@
+
+ 4.0.0
+
+ cloudsim-package
+ org.cloudbus.cloudsim
+ 3.0.1
+
+ documentation
+ documentation
+
\ No newline at end of file
diff --git a/trunk/documentation/src/main/resources/build.xml b/trunk/documentation/src/main/resources/build.xml
new file mode 100644
index 000000000..dd11fcc13
--- /dev/null
+++ b/trunk/documentation/src/main/resources/build.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+ This is the build file for CloudSim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Compiling a new jar file, named: "cloudsim-new.jar".
+ This jar file contains CloudSim classes only.
+
+
+
+
+
+
+
+
diff --git a/trunk/documentation/src/main/resources/changelog.txt b/trunk/documentation/src/main/resources/changelog.txt
new file mode 100644
index 000000000..7dd2ebf3f
--- /dev/null
+++ b/trunk/documentation/src/main/resources/changelog.txt
@@ -0,0 +1,206 @@
+-----------------------------------------
+Changes from CloudSim 3.0 to CloudSim 3.0.1
+-----------------------------------------
+
+WHAT'S NEW
+----------
+
+This is mainly a bug fix release. The following updates have been made:
+
+- Made the CloudletSchedulerTimeShared.getCapacity method protected, to facilitate the development of new cloudlet schedulers.
+- Fixed in PeList: problem in the generics declaration.
+- Fixed Issue #40: Inconsistencies on the return of Cloudlet.isCloudletFinished() and the Cloudlet status.
+- Fixed Issue #35: Default behaviour of Cloudlet may lead to unnecessary usage of heap space.
+- Fixed bug when searching for Cloudlets to cancel in cloudletSchedulerTimeshared
+- Fixed Issue #34: Call getVm(vmId, userId) Function had swaped parameters in several parts of the Datacenter class.
+- Fixed misleading comment on Example 4 that said that capacity of created VMs were different.
+- Fixed comment on example 2, which said that MIPS requirements were different. Actually, they are the same.
+- Fixed the ant building problem: added Flanagan's library to the classpath; updated the readme.txt
+
+
+-----------------------------------------
+Changes from CloudSim 2.1 to CloudSim 3.0
+-----------------------------------------
+
+WHAT'S NEW
+----------
+
+- NEW VM SCHEDULER. VmSchedulerTimeSharedOverSubscription models a scheduler that allows unbounded number of
+VMS to be deployed in a single VM, regardless its requirements in terms of number of MIPS. Notice that this
+was the behaviour of VmSchedulerTimeShared in CloudSim 1.0 Beta, but this behaviour had changed in
+CloudSim 2.0 to accommodate requests with specific amount of MIPS.
+
+- NEW DATACENTER NETWORK MODEL. A internal network model has been added to CloudSim 3.0. It supports definition
+of switches connecting hosts in arbitrary network topologies. New Vm classes and Cloudlet classes were added to
+take advantage of this feature without breaking compatibility of older code. This new feature also enables
+modelling of message-passing applications. They are included in the package 'network.datacenter'.
+
+- NEW VM ALLOCATION AND SELECTION POLICIES. 6 new VM allocation and 4 VM selection policies were added to the
+power package. To find more details about the policies please refer to the following paper:
+
+ Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive Heuristics for
+ Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in Cloud Data Centers", Concurrency
+ and Computation: Practice and Experience, ISSN: 1532-0626, Wiley Press, New York, USA, 2011, DOI: 10.1002/cpe.1867
+
+- NEW POWER MODELS. 7 power models of real servers using the data from SPECpower were added to the power package.
+They are PowerModelSpecPowerHpProLiantMl110G3PentiumD930, PowerModelSpecPowerHpProLiantMl110G4Xeon3040,
+PowerModelSpecPowerHpProLiantMl110G5Xeon3075, PowerModelSpecPowerIbmX3250XeonX3470, PowerModelSpecPowerIbmX3250XeonX3480,
+PowerModelSpecPowerIbmX3550XeonX5670, and PowerModelSpecPowerIbmX3550XeonX5675.
+
+- NEW WORKLOAD TRACES. Workload traces from the PlanetLab project were added and used in the examples of the
+power package. The data have originally been provided as a part of the CoMon project, a monitoring infrastructure
+for PlanetLab (http://comon.cs.princeton.edu/).
+
+- SUPPORT FOR EXTERNAL WORKLOADS. External workloads written in the Standard Workload Format (SWF, from the
+Parallel Workload Archive) can be loaded and read by CloudSim. Relevant classes are WorkloadModel and
+WorkloadFileReader ('util' package).
+
+- SUPPORT FOR USER-DEFINED END OF SIMULATION. Users are now able to specify a given event that causes the simulation
+to finish. We thanks Gaston Keller for developing this new feature.
+
+
+REMOVED CLASSES
+---------------
+
+- CloudCoordinator
+- Sensor
+- CloudCoordinator
+- PowerPe
+- Power.PeList
+
+
+API CHANGES
+-----------
+
+- CloudSim.terminateSimulation(long time) was changed to CloudSim.terminateSimulation(double time), to comply
+with clock field of CloudSim class.
+- PowerModel was moved from PowerPe to PowerHost
+- VM allocation policies in the power package were replaced by a completely new implementation.
+
+
+BUGFIXES AND IMPROVEMENTS
+-------------------------
+
+- Fixed issue 20: HostDynamicWorkload.updateVmsProcessing() throws NullPointerException.
+- Fixed issue 19: CloudSimTags class should be abstract, not final.
+- Fixed issue 17: "Something is wrong, the VM can's be restored" should be an Exception.
+- Fixed issue 16: cloudletsSubmitted in DatacenterBroker should be protected, not private.
+- Fixed issue 15: Simulation failed by the RAM where it should not fail.
+- Fixed issue 14: Rounding problem in VMSchedulerTimeShared.
+- Fixed issue 13: Output error when setDisableMigrations is set to true.
+- Fixed issue 12: Dynamically created space-shared VMs fail to process cloudlets.
+- Fixed issue 11: Wrong sharing of MIs among VMs by VmSchedulerTimeShared.
+- Fixed issue 10: Access modifier of DatacenterBroker::finishExecution().
+- Fixed issue 9: Access modifier of DatacenterBroker::cloudletsSubmitted.
+- Fixed issue 7: Problem in manifests of Maven-generated jar files.
+- Fixed issue 5: Abrupt termination of the simulation caused by VmAllocationPolicySimple.
+- Fixed issue 4: Network examples do not load topology file.
+- Fixed issue 2: Turn the 'future' queue of CloudSim class protected.
+- Fixed issue 1: VM is created without check on host's storage capacity.
+- The power package and corresponding examples were heavily updated, as well as new PlanetLab workload data were added.
+- Fix in Datacenter: one initial update step was been skipped, what caused malfunctions in the schedulers.
+- Fixed issue affecting all CloudletSchedulers: if updated was less then 1, due to a small timespam, processing was
+ never updated, because it was always rounded to 0.
+- Datacenter: Fixed problem with very short intervals between events.
+
+
+-----------------------------------------
+Changes from CloudSim 2.0 to CloudSim 2.1
+-----------------------------------------
+
+- The project has been migrated to using Apache Maven (http://maven.apache.org/). Maven simplifies
+ java project management by providing various tools and plugins for project building, testing, and
+ packaging, dependency management, etc.
+- The directory structure has been changed to comply with the Maven specification
+- The VmSchedulerTimeSharedWithPriority has been removed as well as the priority field from the
+ Vm class. Users can have the same functionality by using the VmSchedulerTimeShared class and
+ setting the MIPS requirements for VMs. See examples 2 and 3.
+- Bug fixes, refactoring and removal of obsolete code.
+
+
+----------------------------------------------
+Changes from CloudSim 1.0 beta to CloudSim 2.0
+----------------------------------------------
+
+WHAT'S NEW
+----------
+
+- NEW SIMULATION CORE. CloudSim 2.0 does not rely on SimJava to process simulation. Therefore, creation of threads was
+controlled, race conditions found in CloudSim beta were removed, scalability and performance of CloudSim improved.
+Moreover, support for dynamic creation and destruction of simulation entities was added.
+
+- IMPROVEMENT IN SCHEDULERS, which enhances accuracy of simulation results.
+
+- NEW FEATURES, including power-aware simulation, federation simulation, and network simulation.
+
+- PACKAGE ORGANIZATION CHANGES, including changes in class names, removal of classes, and changes in interfaces. Next, the
+main changes that affect CloudSim beta users are summarized.
+
+
+CHANGES IN CLASS NAMES
+----------------------
+
+The following classes had their names changed to better reflect its functionalities and/or to adhere to naming standards:
+
+(previous name) VMScheduler -> (current name) CloudletScheduler
+(previous name) TimeSharedVMScheduler -> (current name) CloudletSchedulerTimeShared
+(previous name) SpaceSharedVMScheduler -> (current name) CloudletSchedulerSpaceShared
+
+(previous name) VMMAllocationPolicy -> (current name) VmScheduler
+(previous name) TimeSharedAllocationPolicy -> (current name) VmSchedulerTimeShared
+(previous name) TimeSpaceSharedAllocationPolicy -> (current name) VmSchedulerOportunisticSpaceShared
+(previous name) TimeSharedWithPriorityAllocationPolicy -> (current name) VmSchedulerTimeShared
+(previous name) SpaceSharedAllocationPolicy -> (current name) VmSchedulerTimeSharedWithPriority
+
+(previous name) VMProvisioner -> (current name) VmAllocationPolicy
+(previous name) SimpleVMProvisioner -> (current name) VmAllocationPolicySimple
+
+(previous name) DataCenter -> (current name) Datacenter
+(previous name) PE -> (current name) Pe
+(previous name) VirtualMachine -> (current name) Vm
+
+(previous name) SimpleMemoryProvisioner -> (current name) provisioners.RamProvisionerSimple
+(previous name) MemoryProvisioner -> (current name) provisioners.RamProvisioner
+
+(previous name) BWProvisioner -> (current name) provisioners.BwProvisioner
+(previous name) SimpleBWProvisioner -> (current name) provisioners.BwProvisionerSimple
+
+(previous name) DataCenterTags -> (current name) core.CloudSimTags
+
+(previous name) SANStorage -> (current name) HardDriveStorage
+
+
+REMOVED CLASSES
+---------------
+
+Previous classes that implemented list operations were removed from CloudSim. Instead of this classes, users should use standard lists from java.utils
+
+* CloudletList
+* VirtualMachineList
+
+The following classes were removed because they were redundant:
+
+* VMCharacteristics
+
+
+INTERFACE CHANGES
+-----------------
+
+Because dependencies from SimJava were removed, and due to other code optimizations, some classes suffered major changes in their interfaces. The main ones are listed below:
+
+* Vm (previous VirtualMachine) now receives directly all the relevant VM parameters (before, it was done through a VMCharacteristics object)
+
+* Simulation entities (Datacenter, FederatedDatacenter, DatacenterBroker) have now simpler constructors. Please, refer to examples or Javadoc for new constructors
+
+
+NEW FEATURES
+------------
+
+Below there is a list of CloudSim's new features. Please, refer to Javadoc and examples for instructions on how to use this new features.
+
+* Network effects added through determination of network link latency and bandwidth;
+
+* Support for simulation of Federation of Data centers (new classes FederatedDatacenter, CloudCoordinator, and Sensor);
+
+* Support for modeling of energy-aware cloud computing.
+
diff --git a/trunk/documentation/src/main/resources/examples.txt b/trunk/documentation/src/main/resources/examples.txt
new file mode 100644
index 000000000..4a78a5a4f
--- /dev/null
+++ b/trunk/documentation/src/main/resources/examples.txt
@@ -0,0 +1,96 @@
+Running the CloudSim examples
+-----------------------------
+
+To run the CloudSim examples you need to do the following steps.
+
+In Windows:
+
+1. cd \jars
+2. java -classpath cloudsim-.jar;cloudsim-examples-.jar org.cloudbus.cloudsim.examples.CloudSimExample
+
+In Unix/Linux:
+
+1. cd /jars
+2. java -classpath cloudsim-.jar:cloudsim-examples-.jar org.cloudbus.cloudsim.examples.CloudSimExample
+
+Where you need to replace:
+
+ - by the path to a directory where you have unpacked the CloudSim package
+ - by the version of the downloaded CloudSim package
+ - by the of number of the example you want to run
+
+
+CloudSim examples source code
+-----------------------------
+
+You can find the source code of the examples in /examples/org/cloudbus/cloudsim/examples/
+
+
+Compiling and running examples
+------------------------------
+
+To compile and run an example (let's say org.cloudbus.cloudsim.examples.CloudSimExample1) you need to do the following steps:
+
+In Windows:
+
+1. cd
+2. javac -classpath jars\cloudsim-.jar;examples examples\org\cloudbus\cloudsim\examples\CloudSimExample1.java
+3. java -classpath jars\cloudsim-.jar;examples org.cloudbus.cloudsim.examples.CloudSimExample1
+
+In Unix/Linux:
+
+1. cd
+2. javac -classpath jars/cloudsim-.jar:examples examples/org/cloudbus/cloudsim/examples/CloudSimExample1.java
+3. java -classpath jars/cloudsim-.jar:examples org.cloudbus.cloudsim.examples.CloudSimExample1
+
+
+Compiling and running examples from the power package
+-----------------------------------------------------
+
+To compile and run an example (let's say org.cloudbus.cloudsim.examples.power.planetlab.LrMc) you need to do the following steps:
+
+In Windows:
+
+1. Download Michael Thomas Flanagan's Java Scientific Library from http://www.ee.ucl.ac.uk/~mflanaga/java/
+2. Copy flanagan.jar to /jars/
+3. cd
+4. javac -classpath jars\cloudsim-.jar;jars\flanagan.jar;examples examples\org\cloudbus\cloudsim\examples\power\planetlab\LrMc.java
+5. java -classpath jars\cloudsim-.jar;jars\flanagan.jar;examples org.cloudbus.cloudsim.examples.power.planetlab.LrMc
+
+In Unix/Linux:
+
+1. cd
+2. chmod +x ./install-flanagan.sh
+3. ./install-flanagan.jar
+4. javac -classpath jars/cloudsim-.jar:jars/flanagan.jar:examples examples/org/cloudbus/cloudsim/examples/power/planetlab/LrMc.java
+5. java -classpath jars/cloudsim-.jar:jars/flanagan.jar:examples org.cloudbus.cloudsim.examples.power.planetlab.LrMc
+
+
+Description of the CloudSim examples
+------------------------------------
+
+Here is the description of what each example does:
+
+CloudSimExample1.java : shows how to create a datacenter with one host and run one cloudlet on it.
+
+CloudSimExample2.java : shows how to create a datacenter with one host and run two cloudlets on it.
+ The cloudlets run in VMs with the same MIPS requirements. The cloudlets will take the same
+ time to complete the execution.
+
+CloudSimExample3.java : shows how to create a datacenter with two hosts and run two cloudlets on it.
+ The cloudlets run in VMs with different MIPS requirements. The cloudlets will take different
+ time to complete the execution depending on the requested VM performance.
+
+CloudSimExample4.java : shows how to create two datacenters with one host each and run two cloudlets on them.
+
+CloudSimExample5.java : shows how to create two datacenters with one host each and run cloudlets of two users on them.
+
+CloudSimExample6.java : shows how to create scalable simulations.
+
+CloudSimExample7.java : shows how to pause simulations.
+
+CloudSimExample8.java : shows how to add entities in run time.
+
+network: this package contains examples on how to run simulation with network simulation.
+
+power: this package contains examples on how to use CloudSim's power-aware features.
\ No newline at end of file
diff --git a/trunk/documentation/src/main/resources/install-flanagan.sh b/trunk/documentation/src/main/resources/install-flanagan.sh
new file mode 100755
index 000000000..b87c28c9a
--- /dev/null
+++ b/trunk/documentation/src/main/resources/install-flanagan.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+wget -P jars http://www.ee.ucl.ac.uk/~mflanaga/java/flanagan.jar
diff --git a/trunk/documentation/src/main/resources/license.txt b/trunk/documentation/src/main/resources/license.txt
new file mode 100644
index 000000000..02bbb60bc
--- /dev/null
+++ b/trunk/documentation/src/main/resources/license.txt
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
\ No newline at end of file
diff --git a/trunk/documentation/src/main/resources/pom.xml b/trunk/documentation/src/main/resources/pom.xml
new file mode 100644
index 000000000..1eb9cf71a
--- /dev/null
+++ b/trunk/documentation/src/main/resources/pom.xml
@@ -0,0 +1,129 @@
+
+
+
+
+
+
+ 4.0.0
+ org.cloudbus.cloudsim
+ cloudsim-toolkit
+ 2.1
+ bundle
+ cloudsim-toolkit
+ CloudSim: A Framework For Modeling And Simulation Of Cloud Computing Infrastructures And Services
+ http://www.cloudbus.org/cloudsim/
+
+
+ 1.6
+ UTF-8
+ 2.0.1
+
+
+
+ classes
+ classes
+ cloudsim-new
+ classes/test-classes
+ sources
+
+
+
+ true
+ src/main/resources
+
+
+
+
+
+ maven-compiler-plugin
+ 2.3.2
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.5
+
+ 1024
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.6
+ true
+
+
+
+
+
+
+
+ activator
+
+ true
+
+
+ true
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ ${felix-version}
+ true
+
+
+ cloudsim-toolkit
+ cloudsim-toolkit
+ org.apache.log4j;resolution:=optional
+ org.cloudbus.cloudsim.*;version="${project.version}"
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trunk/documentation/src/main/resources/readme.txt b/trunk/documentation/src/main/resources/readme.txt
new file mode 100644
index 000000000..2a4ab3d1f
--- /dev/null
+++ b/trunk/documentation/src/main/resources/readme.txt
@@ -0,0 +1,99 @@
+Table of Contents
+-----------------
+
+1. Directory structure of the CloudSim Toolkit
+2. Software requirements: Java version 1.6 or newer
+3. Installation and running the CloudSim Toolkit
+4. Running the CloudSim examples
+5. Learning CloudSim
+6. Compiling CloudSim: using Ant
+
+
+
+1. Directory structure of the CloudSim Toolkit
+----------------------------------------------
+
+cloudsim/ -- top level CloudSim directory
+ docs/ -- CloudSim API Documentation
+ examples/ -- CloudSim examples
+ jars/ -- CloudSim jar archives
+ sources/ -- CloudSim source code
+ tests/ -- CloudSim unit tests
+
+
+2. Software requirements: Java version 1.6 or newer
+---------------------------------------------------
+
+CloudSim has been tested and ran on Sun's Java version 1.6.0 or newer.
+Older versions of Java are not compatible.
+If you have non-Sun Java version, such as gcj or J++, they may not be compatible.
+You also need to install Ant to compile CloudSim (explained in more details later).
+
+
+3. Installation and running the CloudSim Toolkit
+------------------------------------------------
+
+You just need to unpack the CloudSim file to install.
+If you want to remove CloudSim, then remove the whole cloudsim directory.
+You do not need to compile CloudSim source code. The JAR files are
+provided to compile and to run CloudSim applications:
+
+ * jars/cloudsim-.jar -- contains the CloudSim class files
+ * jars/cloudsim--sources.jar -- contains the CloudSim source code files
+ * jars/cloudsim-examples-.jar -- contains the CloudSim examples class files
+ * jars/cloudsim-examples--sources.jar -- contains the CloudSim examples source code files
+
+
+4. Running the CloudSim examples
+--------------------------------
+
+Please read how to run the CloudSim examples in examples.txt
+
+
+5. Learning CloudSim
+--------------------
+
+To understand how to use CloudSim, please go through the examples provided
+in the examples/ directory.
+
+
+6. Downloading and using external jars
+---------------------------------------
+
+Some of the algorithms in the power package require Michael Thomas Flanagan's
+Java Scientific Library. In order to compile CloudSim, it is necessary to
+download this library. The library can be downloaded from:
+
+http://www.ee.ucl.ac.uk/~mflanaga/java/
+
+Once the library is downloaded, copy it to the jars/ directory. If you are running
+Linux, you can just run the ./install-flanagan.sh script, that will download the
+library and place it in the jars/ directory.
+
+Please, make sure that, by using such library, you are respecting the terms of use
+defined by the software's author.
+
+
+7. Compiling CloudSim: using Ant
+--------------------------------
+
+This release contains a simple buildfile for compiling CloudSim classes.
+You need to have ant installed (http://ant.apache.org/).
+Ant can be used in both Windows and Unix/Linux environment.
+
+Usage:
+
+ * Being in the CloudSim root directory (cloudsim/), type 'ant' to compile all
+ cloudsim source files, put them into the classes/ directory and to create
+ a cloudsim-new.jar file in the jars/ directory
+
+ * Being in the CloudSim root directory (cloudsim/), type 'ant clean' to delete
+ all the compiled classes and the classes/ directory itself. The generated
+ cloudsim-new.jar is not deleted.
+
+Note:
+
+ * You need to set up PATH for ant in Windows and/or Unix.
+
+
+
diff --git a/trunk/documentation/src/main/resources/release_notes.txt b/trunk/documentation/src/main/resources/release_notes.txt
new file mode 100644
index 000000000..e4c520024
--- /dev/null
+++ b/trunk/documentation/src/main/resources/release_notes.txt
@@ -0,0 +1,42 @@
+
+ Cloudsim Project to Release CloudSim Toolkit 3.0
+
+The Cloudbus Project at The University of Melbourne, Australia is proud to announce the
+release of the new version of its Cloud simulation software, the CloudSim.
+
+One year has passed since last version of CloudSim was released. Cloud computing now is
+mainstream, and has been heavily adopted by different industries. It is also omnipresent in
+conferences and journals from diverse fields such as high performance computing, grid computing,
+distributed systems, operating systems, software engineering, databases and so on. CloudSim has
+been present in publications in all the above fields.
+
+To help in further developments in the field of Cloud computing regardless the main area of
+application, new features and improvements were added to CloudSim 3.0. Having the project
+hosted in Google code allowed us to have an enhanced feedback from users, via issue tracking
+and group discussion. Based on this feedback, we could identify bugs, concepts that where being
+misinterpreted by users and features of little significance and complexity. In response to this
+feedback, we fixed all the identified bugs, clarified confusing aspects of the tool, and removed
+features that were proven to be unpopular with users and just were making the APIs confusing.
+
+This version of CloudSim brings enhanced modelling of power-aware and energy efficient Cloud
+computing, and also a new package allowing modelling of internal data center topologies and
+message-passing applications.
+
+We encourage the community to keep collaborating with us by notifying us about any identified
+bugs, providing feedback on new features you would like to have in future versions of the toolkit,
+and also developing your own extension packages, which we will be happy to promote on the project's
+homepage. We will also be happy to list on our homepage scientific peer-reviewed papers, whose
+results were obtained with CloudSim.
+
+As in its previous version, all components developed as part of the CloudSim Toolkit are open
+source released under the LGPL license to encourage innovation and pass full freedom to our users.
+
+We would like to thanks all the support we have received from users all around the world. Your
+contribution in finding and reporting bugs, proposing (and developing) new features, and even in
+using CloudSim has been paramount in the success of the project.
+
+To download the CloudSim software, please visit the Cloudbus Project web site at
+http://www.cloudbus.org/cloudsim/
+
+The CloudSim Team
+Melbourne, January 2012
diff --git a/trunk/modules/cloudsim-examples/pom.xml b/trunk/modules/cloudsim-examples/pom.xml
new file mode 100644
index 000000000..32ab08bf7
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/pom.xml
@@ -0,0 +1,21 @@
+
+
+ 4.0.0
+
+ modules
+ org.cloudbus.cloudsim
+ 3.0.1
+
+
+ cloudsim-examples
+ cloudsim-examples
+
+
+
+ ${project.groupId}
+ cloudsim
+ ${project.version}
+
+
+
+
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample1.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample1.java
new file mode 100644
index 000000000..74bb0a34d
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample1.java
@@ -0,0 +1,263 @@
+package org.cloudbus.cloudsim.examples;
+
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * A simple example showing how to create a datacenter with one host and run one
+ * cloudlet on it.
+ */
+public class CloudSimExample1 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example.
+ *
+ * @param args the args
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting CloudSimExample1...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ // Datacenters are the resource providers in CloudSim. We need at
+ // list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+
+ // Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ // Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ // VM description
+ int vmid = 0;
+ int mips = 1000;
+ long size = 10000; // image size (MB)
+ int ram = 512; // vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; // number of cpus
+ String vmm = "Xen"; // VMM name
+
+ // create VM
+ Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ // add the VM to the vmList
+ vmlist.add(vm);
+
+ // submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+ // Fifth step: Create one Cloudlet
+ cloudletList = new ArrayList();
+
+ // Cloudlet properties
+ int id = 0;
+ long length = 400000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet.setUserId(brokerId);
+ cloudlet.setVmId(vmid);
+
+ // add the cloudlet to the list
+ cloudletList.add(cloudlet);
+
+ // submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+ CloudSim.stopSimulation();
+
+ //Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+ printCloudletList(newList);
+
+ // Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+
+ Log.printLine("CloudSimExample1 finished!");
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("Unwanted errors happen");
+ }
+ }
+
+ /**
+ * Creates the datacenter.
+ *
+ * @param name the name
+ *
+ * @return the datacenter
+ */
+ private static Datacenter createDatacenter(String name) {
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ // 4. Create Host with its id and list of PEs and add them to the list
+ // of machines
+ int hostId = 0;
+ int ram = 2048; // host memory (MB)
+ long storage = 1000000; // host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList)
+ )
+ ); // This is our machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this
+ // resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); // we are not adding SAN
+ // devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem,
+ costPerStorage, costPerBw);
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ // We strongly encourage users to develop their own broker policies, to
+ // submit vms and cloudlets according
+ // to the specific rules of the simulated scenario
+ /**
+ * Creates the broker.
+ *
+ * @return the datacenter broker
+ */
+ private static DatacenterBroker createBroker() {
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects.
+ *
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
+ + "Data center ID" + indent + "VM ID" + indent + "Time" + indent
+ + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
+ Log.print("SUCCESS");
+
+ Log.printLine(indent + indent + cloudlet.getResourceId()
+ + indent + indent + indent + cloudlet.getVmId()
+ + indent + indent
+ + dft.format(cloudlet.getActualCPUTime()) + indent
+ + indent + dft.format(cloudlet.getExecStartTime())
+ + indent + indent
+ + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample2.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample2.java
new file mode 100644
index 000000000..ddd51cca3
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample2.java
@@ -0,0 +1,265 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples;
+
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+
+/**
+ * A simple example showing how to create
+ * a datacenter with one host and run two
+ * cloudlets on it. The cloudlets run in
+ * VMs with the same MIPS requirements.
+ * The cloudlets will take the same time to
+ * complete the execution.
+ */
+public class CloudSimExample2 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting CloudSimExample2...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+
+ //Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ //Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create two VMs
+ Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ vmid++;
+ Vm vm2 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VMs to the vmList
+ vmlist.add(vm1);
+ vmlist.add(vm2);
+
+ //submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+
+ //Fifth step: Create two Cloudlets
+ cloudletList = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ pesNumber=1;
+ long length = 250000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId);
+
+ id++;
+ Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet2.setUserId(brokerId);
+
+ //add the cloudlets to the list
+ cloudletList.add(cloudlet1);
+ cloudletList.add(cloudlet2);
+
+ //submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+
+ //bind the cloudlets to the vms. This way, the broker
+ // will submit the bound cloudlets only to the specific VM
+ broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId());
+ broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+
+ Log.printLine("CloudSimExample2 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList)
+ )
+ ); // This is our machine
+
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample3.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample3.java
new file mode 100644
index 000000000..4981e3267
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample3.java
@@ -0,0 +1,283 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+
+/**
+ * A simple example showing how to create
+ * a datacenter with two hosts and run two
+ * cloudlets on it. The cloudlets run in
+ * VMs with different MIPS requirements.
+ * The cloudlets will take different time
+ * to complete the execution depending on
+ * the requested VM performance.
+ */
+public class CloudSimExample3 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting CloudSimExample3...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+
+ //Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ //Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 2048; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create two VMs
+ Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //the second VM will have twice the priority of VM1 and so will receive twice CPU time
+ vmid++;
+ Vm vm2 = new Vm(vmid, brokerId, mips * 2, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VMs to the vmList
+ vmlist.add(vm1);
+ vmlist.add(vm2);
+
+ //submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+
+ //Fifth step: Create two Cloudlets
+ cloudletList = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId);
+
+ id++;
+ Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet2.setUserId(brokerId);
+
+ //add the cloudlets to the list
+ cloudletList.add(cloudlet1);
+ cloudletList.add(cloudlet2);
+
+ //submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+
+ //bind the cloudlets to the vms. This way, the broker
+ // will submit the bound cloudlets only to the specific VM
+ broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId());
+ broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+
+ Log.printLine("CloudSimExample3 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, 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
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList)
+ )
+ ); // This is our first machine
+
+ //create another machine in the Data center
+ List peList2 = new ArrayList();
+
+ peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
+
+ hostId++;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList2,
+ new VmSchedulerTimeShared(peList2)
+ )
+ ); // This is our second machine
+
+
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample4.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample4.java
new file mode 100644
index 000000000..557621137
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample4.java
@@ -0,0 +1,264 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.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;
+
+
+/**
+ * A simple example showing how to create
+ * two datacenters with one host each and
+ * run two cloudlets on them.
+ */
+public class CloudSimExample4 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting CloudSimExample4...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the GridSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+ Datacenter datacenter1 = createDatacenter("Datacenter_1");
+
+ //Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ //Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create two VMs
+ Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ vmid++;
+ Vm vm2 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VMs to the vmList
+ vmlist.add(vm1);
+ vmlist.add(vm2);
+
+ //submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+
+ //Fifth step: Create two Cloudlets
+ cloudletList = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId);
+
+ id++;
+ Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet2.setUserId(brokerId);
+
+ //add the cloudlets to the list
+ cloudletList.add(cloudlet1);
+ cloudletList.add(cloudlet2);
+
+ //submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+
+ //bind the cloudlets to the vms. This way, the broker
+ // will submit the bound cloudlets only to the specific VM
+ broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId());
+ broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("CloudSimExample4 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+
+ //in this example, the VMAllocatonPolicy in use is SpaceShared. It means that only one VM
+ //is allowed to run on each Pe. As each Host has only one Pe, only one VM can run on each Host.
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerSpaceShared(peList)
+ )
+ ); // This is our first machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample5.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample5.java
new file mode 100644
index 000000000..42181540d
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample5.java
@@ -0,0 +1,269 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.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;
+
+
+/**
+ * A simple example showing how to create
+ * two datacenters with one host each and
+ * run cloudlets of two users on them.
+ */
+public class CloudSimExample5 {
+
+ /** The cloudlet lists. */
+ private static List cloudletList1;
+ private static List cloudletList2;
+
+ /** The vmlists. */
+ private static List vmlist1;
+ private static List vmlist2;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting CloudSimExample5...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 2; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+ Datacenter datacenter1 = createDatacenter("Datacenter_1");
+
+ //Third step: Create Brokers
+ DatacenterBroker broker1 = createBroker(1);
+ int brokerId1 = broker1.getId();
+
+ DatacenterBroker broker2 = createBroker(2);
+ int brokerId2 = broker2.getId();
+
+ //Fourth step: Create one virtual machine for each broker/user
+ vmlist1 = new ArrayList();
+ vmlist2 = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create two VMs: the first one belongs to user1
+ Vm vm1 = new Vm(vmid, brokerId1, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //the second VM: this one belongs to user2
+ Vm vm2 = new Vm(vmid, brokerId2, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VMs to the vmlists
+ vmlist1.add(vm1);
+ vmlist2.add(vm2);
+
+ //submit vm list to the broker
+ broker1.submitVmList(vmlist1);
+ broker2.submitVmList(vmlist2);
+
+ //Fifth step: Create two Cloudlets
+ cloudletList1 = new ArrayList();
+ cloudletList2 = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId1);
+
+ Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet2.setUserId(brokerId2);
+
+ //add the cloudlets to the lists: each cloudlet belongs to one user
+ cloudletList1.add(cloudlet1);
+ cloudletList2.add(cloudlet2);
+
+ //submit cloudlet list to the brokers
+ broker1.submitCloudletList(cloudletList1);
+ broker2.submitCloudletList(cloudletList2);
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+ // Final step: Print results when simulation is over
+ List newList1 = broker1.getCloudletReceivedList();
+ List newList2 = broker2.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ Log.print("=============> User "+brokerId1+" ");
+ printCloudletList(newList1);
+
+ Log.print("=============> User "+brokerId2+" ");
+ printCloudletList(newList2);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("CloudSimExample5 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips=1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+
+ //in this example, the VMAllocatonPolicy in use is SpaceShared. It means that only one VM
+ //is allowed to run on each Pe. As each Host has only one Pe, only one VM can run on each Host.
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerSpaceShared(peList)
+ )
+ ); // This is our first machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(int id){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker"+id);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample6.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample6.java
new file mode 100644
index 000000000..558e863bf
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample6.java
@@ -0,0 +1,314 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+
+package org.cloudbus.cloudsim.examples;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * An example showing how to create
+ * scalable simulations.
+ */
+public class CloudSimExample6 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ private static List createVM(int userId, int vms) {
+
+ //Creates a container to store VMs. This list is passed to the broker later
+ LinkedList list = new LinkedList();
+
+ //VM Parameters
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ int mips = 1000;
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create VMs
+ Vm[] vm = new Vm[vms];
+
+ for(int i=0;i createCloudlet(int userId, int cloudlets){
+ // Creates a container to store Cloudlets
+ LinkedList list = new LinkedList();
+
+ //cloudlet parameters
+ long length = 1000;
+ long fileSize = 300;
+ long outputSize = 300;
+ int pesNumber = 1;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet[] cloudlet = new Cloudlet[cloudlets];
+
+ for(int i=0;i newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("CloudSimExample6 finished!");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store one or more
+ // Machines
+ List hostList = new ArrayList();
+
+ // 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 peList1 = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into the list.
+ //for a quad-core machine, a list of 4 PEs is required:
+ peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+ peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
+ peList1.add(new Pe(2, new PeProvisionerSimple(mips)));
+ peList1.add(new Pe(3, new PeProvisionerSimple(mips)));
+
+ //Another list, for a dual-core machine
+ List peList2 = new ArrayList();
+
+ peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
+ peList2.add(new Pe(1, new PeProvisionerSimple(mips)));
+
+ //4. Create Hosts with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList1,
+ new VmSchedulerTimeShared(peList1)
+ )
+ ); // This is our first machine
+
+ hostId++;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList2,
+ new VmSchedulerTimeShared(peList2)
+ )
+ ); // Second machine
+
+
+ //To create a host with a space-shared allocation policy for PEs to VMs:
+ //hostList.add(
+ // new Host(
+ // hostId,
+ // new CpuProvisionerSimple(peList1),
+ // new RamProvisionerSimple(ram),
+ // new BwProvisionerSimple(bw),
+ // storage,
+ // new VmSchedulerSpaceShared(peList1)
+ // )
+ // );
+
+ //To create a host with a oportunistic space-shared allocation policy for PEs to VMs:
+ //hostList.add(
+ // new Host(
+ // hostId,
+ // new CpuProvisionerSimple(peList1),
+ // new RamProvisionerSimple(ram),
+ // new BwProvisionerSimple(bw),
+ // storage,
+ // new VmSchedulerOportunisticSpaceShared(peList1)
+ // )
+ // );
+
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.1; // the cost of using storage in this resource
+ double costPerBw = 0.1; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
+ indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample7.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample7.java
new file mode 100644
index 000000000..4e4d091cc
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample7.java
@@ -0,0 +1,326 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+
+package org.cloudbus.cloudsim.examples;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * An example showing how to pause and resume the simulation,
+ * and create simulation entities (a DatacenterBroker in this example)
+ * dynamically.
+ */
+public class CloudSimExample7 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ private static List createVM(int userId, int vms, int idShift) {
+ //Creates a container to store VMs. This list is passed to the broker later
+ LinkedList list = new LinkedList();
+
+ //VM Parameters
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ int mips = 250;
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create VMs
+ Vm[] vm = new Vm[vms];
+
+ for(int i=0;i createCloudlet(int userId, int cloudlets, int idShift){
+ // Creates a container to store Cloudlets
+ LinkedList list = new LinkedList();
+
+ //cloudlet parameters
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ int pesNumber = 1;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet[] cloudlet = new Cloudlet[cloudlets];
+
+ for(int i=0;i newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("CloudSimExample7 finished!");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store one or more
+ // Machines
+ List hostList = new ArrayList();
+
+ // 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 peList1 = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into the list.
+ //for a quad-core machine, a list of 4 PEs is required:
+ peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+ peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
+ peList1.add(new Pe(2, new PeProvisionerSimple(mips)));
+ peList1.add(new Pe(3, new PeProvisionerSimple(mips)));
+
+ //Another list, for a dual-core machine
+ List peList2 = new ArrayList();
+
+ peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
+ peList2.add(new Pe(1, new PeProvisionerSimple(mips)));
+
+ //4. Create Hosts with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 16384; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList1,
+ new VmSchedulerTimeShared(peList1)
+ )
+ ); // This is our first machine
+
+ hostId++;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList2,
+ new VmSchedulerTimeShared(peList2)
+ )
+ ); // Second machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.1; // the cost of using storage in this resource
+ double costPerBw = 0.1; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(String name){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker(name);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
+ indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample8.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample8.java
new file mode 100644
index 000000000..387eb44fb
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample8.java
@@ -0,0 +1,361 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+
+package org.cloudbus.cloudsim.examples;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.core.SimEntity;
+import org.cloudbus.cloudsim.core.SimEvent;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * An example showing how to create simulation entities
+ * (a DatacenterBroker in this example) in run-time using
+ * a globar manager entity (GlobalBroker).
+ */
+public class CloudSimExample8 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmList. */
+ private static List vmList;
+
+ private static List createVM(int userId, int vms, int idShift) {
+ //Creates a container to store VMs. This list is passed to the broker later
+ LinkedList list = new LinkedList();
+
+ //VM Parameters
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ int mips = 250;
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create VMs
+ Vm[] vm = new Vm[vms];
+
+ for(int i=0;i createCloudlet(int userId, int cloudlets, int idShift){
+ // Creates a container to store Cloudlets
+ LinkedList list = new LinkedList();
+
+ //cloudlet parameters
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ int pesNumber = 1;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet[] cloudlet = new Cloudlet[cloudlets];
+
+ for(int i=0;i newList = broker.getCloudletReceivedList();
+ newList.addAll(globalBroker.getBroker().getCloudletReceivedList());
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("CloudSimExample8 finished!");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store one or more
+ // Machines
+ List hostList = new ArrayList();
+
+ // 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 peList1 = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into the list.
+ //for a quad-core machine, a list of 4 PEs is required:
+ peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+ peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
+ peList1.add(new Pe(2, new PeProvisionerSimple(mips)));
+ peList1.add(new Pe(3, new PeProvisionerSimple(mips)));
+
+ //Another list, for a dual-core machine
+ List peList2 = new ArrayList();
+
+ peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
+ peList2.add(new Pe(1, new PeProvisionerSimple(mips)));
+
+ //4. Create Hosts with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 16384; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList1,
+ new VmSchedulerTimeShared(peList1)
+ )
+ ); // This is our first machine
+
+ hostId++;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList2,
+ new VmSchedulerTimeShared(peList2)
+ )
+ ); // Second machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.1; // the cost of using storage in this resource
+ double costPerBw = 0.1; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(String name){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker(name);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
+ indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+
+ public static class GlobalBroker extends SimEntity {
+
+ private static final int CREATE_BROKER = 0;
+ private List vmList;
+ private List cloudletList;
+ private DatacenterBroker broker;
+
+ public GlobalBroker(String name) {
+ super(name);
+ }
+
+ @Override
+ public void processEvent(SimEvent ev) {
+ switch (ev.getTag()) {
+ case CREATE_BROKER:
+ setBroker(createBroker(super.getName()+"_"));
+
+ //Create VMs and Cloudlets and send them to broker
+ setVmList(createVM(getBroker().getId(), 5, 100)); //creating 5 vms
+ setCloudletList(createCloudlet(getBroker().getId(), 10, 100)); // creating 10 cloudlets
+
+ broker.submitVmList(getVmList());
+ broker.submitCloudletList(getCloudletList());
+
+ CloudSim.resumeSimulation();
+
+ break;
+
+ default:
+ Log.printLine(getName() + ": unknown event type");
+ break;
+ }
+ }
+
+ @Override
+ public void startEntity() {
+ Log.printLine(super.getName()+" is starting...");
+ schedule(getId(), 200, CREATE_BROKER);
+ }
+
+ @Override
+ public void shutdownEntity() {
+ }
+
+ public List getVmList() {
+ return vmList;
+ }
+
+ protected void setVmList(List vmList) {
+ this.vmList = vmList;
+ }
+
+ public List getCloudletList() {
+ return cloudletList;
+ }
+
+ protected void setCloudletList(List cloudletList) {
+ this.cloudletList = cloudletList;
+ }
+
+ public DatacenterBroker getBroker() {
+ return broker;
+ }
+
+ protected void setBroker(DatacenterBroker broker) {
+ this.broker = broker;
+ }
+
+ }
+
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java
new file mode 100644
index 000000000..a87225744
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java
@@ -0,0 +1,259 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples.network;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.NetworkTopology;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * A simple example showing how to create
+ * a datacenter with one host and a network
+ * topology and and run one cloudlet on it.
+ */
+public class NetworkExample1 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting NetworkExample1...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+
+ //Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ //Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create VM
+ Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VM to the vmList
+ vmlist.add(vm1);
+
+ //submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+
+ //Fifth step: Create one Cloudlet
+ cloudletList = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId);
+
+ //add the cloudlet to the list
+ cloudletList.add(cloudlet1);
+
+ //submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+ //Sixth step: configure network
+ //load the network topology file
+ NetworkTopology.buildNetworkTopology("topology.brite");
+
+ //maps CloudSim entities to BRITE entities
+ //PowerDatacenter will correspond to BRITE node 0
+ int briteNode=0;
+ NetworkTopology.mapNode(datacenter0.getId(),briteNode);
+
+ //Broker will correspond to BRITE node 3
+ briteNode=3;
+ NetworkTopology.mapNode(broker.getId(),briteNode);
+
+
+ // Seventh step: Starts the simulation
+ CloudSim.startSimulation();
+
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+
+ Log.printLine("NetworkExample1 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList)
+ )
+ ); // This is our machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem,
+ costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java
new file mode 100644
index 000000000..5978033b8
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java
@@ -0,0 +1,287 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+
+package org.cloudbus.cloudsim.examples.network;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.NetworkTopology;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * A simple example showing how to create
+ * two datacenters with one host and a
+ * network topology each and run two cloudlets
+ * on them.
+ */
+public class NetworkExample2 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting NetworkExample2...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+ Datacenter datacenter1 = createDatacenter("Datacenter_1");
+
+ //Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ //Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create two VMs
+ Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //the second VM will have twice the priority of VM1 and so will receive twice CPU time
+ vmid++;
+ Vm vm2 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VMs to the vmList
+ vmlist.add(vm1);
+ vmlist.add(vm2);
+
+ //submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+
+ //Fifth step: Create two Cloudlets
+ cloudletList = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId);
+
+ id++;
+ Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet2.setUserId(brokerId);
+
+ //add the cloudlets to the list
+ cloudletList.add(cloudlet1);
+ cloudletList.add(cloudlet2);
+
+ //submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+
+ //bind the cloudlets to the vms. This way, the broker
+ // will submit the bound cloudlets only to the specific VM
+ broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId());
+ broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());
+
+
+ //Sixth step: configure network
+ //load the network topology file
+ NetworkTopology.buildNetworkTopology("topology.brite");
+
+ //maps CloudSim entities to BRITE entities
+ //Datacenter0 will correspond to BRITE node 0
+ int briteNode=0;
+ NetworkTopology.mapNode(datacenter0.getId(),briteNode);
+
+ //Datacenter1 will correspond to BRITE node 2
+ briteNode=2;
+ NetworkTopology.mapNode(datacenter1.getId(),briteNode);
+
+ //Broker will correspond to BRITE node 3
+ briteNode=3;
+ NetworkTopology.mapNode(broker.getId(),briteNode);
+
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("NetworkExample2 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+
+ //in this example, the VMAllocatonPolicy in use is Time Shared with priorities. It means that VMs
+ //receive time shares accroding to their priority.
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList)
+ )
+ ); // This is our machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem,
+ costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java
new file mode 100644
index 000000000..d5d085530
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java
@@ -0,0 +1,293 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples.network;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.NetworkTopology;
+import org.cloudbus.cloudsim.Pe;
+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.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;
+
+/**
+ * A simple example showing how to create
+ * two datacenters with one host each and
+ * run cloudlets of two users with network
+ * topology on them.
+ */
+public class NetworkExample3 {
+
+ /** The cloudlet list. */
+ private static List cloudletList1;
+ private static List cloudletList2;
+
+ /** The vmlist. */
+ private static List vmlist1;
+ private static List vmlist2;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting NetworkExample3...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 2; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+ Datacenter datacenter1 = createDatacenter("Datacenter_1");
+
+ //Third step: Create Brokers
+ DatacenterBroker broker1 = createBroker(1);
+ int brokerId1 = broker1.getId();
+
+ DatacenterBroker broker2 = createBroker(2);
+ int brokerId2 = broker2.getId();
+
+ //Fourth step: Create one virtual machine for each broker/user
+ vmlist1 = new ArrayList();
+ vmlist2 = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ long size = 10000; //image size (MB)
+ int mips = 250;
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create two VMs: the first one belongs to user1
+ Vm vm1 = new Vm(vmid, brokerId1, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //the second VM: this one belongs to user2
+ Vm vm2 = new Vm(vmid, brokerId2, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VMs to the vmlists
+ vmlist1.add(vm1);
+ vmlist2.add(vm2);
+
+ //submit vm list to the broker
+ broker1.submitVmList(vmlist1);
+ broker2.submitVmList(vmlist2);
+
+ //Fifth step: Create two Cloudlets
+ cloudletList1 = new ArrayList();
+ cloudletList2 = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId1);
+
+ Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet2.setUserId(brokerId2);
+
+ //add the cloudlets to the lists: each cloudlet belongs to one user
+ cloudletList1.add(cloudlet1);
+ cloudletList2.add(cloudlet2);
+
+ //submit cloudlet list to the brokers
+ broker1.submitCloudletList(cloudletList1);
+ broker2.submitCloudletList(cloudletList2);
+
+
+ //Sixth step: configure network
+ //load the network topology file
+ NetworkTopology.buildNetworkTopology("topology.brite");
+
+ //maps CloudSim entities to BRITE entities
+ //Datacenter0 will correspond to BRITE node 0
+ int briteNode=0;
+ NetworkTopology.mapNode(datacenter0.getId(),briteNode);
+
+ //Datacenter1 will correspond to BRITE node 2
+ briteNode=2;
+ NetworkTopology.mapNode(datacenter1.getId(),briteNode);
+
+ //Broker1 will correspond to BRITE node 3
+ briteNode=3;
+ NetworkTopology.mapNode(broker1.getId(),briteNode);
+
+ //Broker2 will correspond to BRITE node 4
+ briteNode=4;
+ NetworkTopology.mapNode(broker2.getId(),briteNode);
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+ // Final step: Print results when simulation is over
+ List newList1 = broker1.getCloudletReceivedList();
+ List newList2 = broker2.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ Log.print("=============> User "+brokerId1+" ");
+ printCloudletList(newList1);
+
+ Log.print("=============> User "+brokerId2+" ");
+ printCloudletList(newList2);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+ datacenter1.printDebts();
+
+ Log.printLine("NetworkExample3 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+
+ //in this example, the VMAllocatonPolicy in use is SpaceShared. It means that only one VM
+ //is allowed to run on each Pe. As each Host has only one Pe, only one VM can run on each Host.
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerSpaceShared(peList)
+ )
+ ); // This is our machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem,
+ costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(int id){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker"+id);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java
new file mode 100644
index 000000000..bc2f47830
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java
@@ -0,0 +1,251 @@
+/*
+ * Title: CloudSim Toolkit
+ * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
+ * of Clouds
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Copyright (c) 2009, The University of Melbourne, Australia
+ */
+
+package org.cloudbus.cloudsim.examples.network;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.NetworkTopology;
+import org.cloudbus.cloudsim.Pe;
+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.core.CloudSim;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+/**
+ * A simple example showing how to create
+ * a datacenter with one host and a network
+ * topology and and run one cloudlet on it.
+ * Here, instead of using a BRIE file describing
+ * the links, links are inserted in the code.
+ */
+public class NetworkExample4 {
+
+ /** The cloudlet list. */
+ private static List cloudletList;
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting NetworkExample4...");
+
+ try {
+ // First step: Initialize the CloudSim package. It should be called
+ // before creating any entities.
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ //Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
+ Datacenter datacenter0 = createDatacenter("Datacenter_0");
+
+ //Third step: Create Broker
+ DatacenterBroker broker = createBroker();
+ int brokerId = broker.getId();
+
+ //Fourth step: Create one virtual machine
+ vmlist = new ArrayList();
+
+ //VM description
+ int vmid = 0;
+ int mips = 250;
+ long size = 10000; //image size (MB)
+ int ram = 512; //vm memory (MB)
+ long bw = 1000;
+ int pesNumber = 1; //number of cpus
+ String vmm = "Xen"; //VMM name
+
+ //create VM
+ Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
+
+ //add the VM to the vmList
+ vmlist.add(vm1);
+
+ //submit vm list to the broker
+ broker.submitVmList(vmlist);
+
+
+ //Fifth step: Create one Cloudlet
+ cloudletList = new ArrayList();
+
+ //Cloudlet properties
+ int id = 0;
+ long length = 40000;
+ long fileSize = 300;
+ long outputSize = 300;
+ UtilizationModel utilizationModel = new UtilizationModelFull();
+
+ Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
+ cloudlet1.setUserId(brokerId);
+
+ //add the cloudlet to the list
+ cloudletList.add(cloudlet1);
+
+ //submit cloudlet list to the broker
+ broker.submitCloudletList(cloudletList);
+
+ //Sixth step: configure network
+
+ //maps CloudSim entities to BRITE entities
+ NetworkTopology.addLink(datacenter0.getId(),broker.getId(),10.0,10);
+
+ // Seventh step: Starts the simulation
+ CloudSim.startSimulation();
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+
+ CloudSim.stopSimulation();
+
+ printCloudletList(newList);
+
+ //Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+
+ Log.printLine("NetworkExample4 finished!");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("The simulation has been terminated due to an unexpected error");
+ }
+ }
+
+ private static Datacenter createDatacenter(String name){
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ List peList = new ArrayList();
+
+ int mips = 1000;
+
+ // 3. Create PEs and add these into a list.
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
+
+ //4. Create Host with its id and list of PEs and add them to the list of machines
+ int hostId=0;
+ int ram = 2048; //host memory (MB)
+ long storage = 1000000; //host storage
+ int bw = 10000;
+
+ hostList.add(
+ new Host(
+ hostId,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList)
+ )
+ ); // This is our machine
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); //we are not adding SAN devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch, os, vmm, hostList, time_zone, cost, costPerMem,
+ costPerStorage, costPerBw);
+
+
+ // 6. Finally, we need to create a PowerDatacenter object.
+ Datacenter datacenter = null;
+ try {
+ datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return datacenter;
+ }
+
+ //We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
+ //to the specific rules of the simulated scenario
+ private static DatacenterBroker createBroker(){
+
+ DatacenterBroker broker = null;
+ try {
+ broker = new DatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects
+ * @param list list of Cloudlets
+ */
+ private static void printCloudletList(List list) {
+ int size = list.size();
+ Cloudlet cloudlet;
+
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
+ Log.print("SUCCESS");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
+ indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
+ indent + indent + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/datacenter/TestBagofTaskApp.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/datacenter/TestBagofTaskApp.java
new file mode 100755
index 000000000..82e8ccddc
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/datacenter/TestBagofTaskApp.java
@@ -0,0 +1,91 @@
+package org.cloudbus.cloudsim.examples.network.datacenter;
+
+/**
+ * BagofTaskApp is an example of AppCloudlet having three noncommunicating tasks.
+ *
+ *
+ * Please refer to following publication for more details:
+ *
+ * Saurabh Kumar Garg and Rajkumar Buyya, NetworkCloudSim: Modelling Parallel
+ * Applications in Cloud Simulations, Proceedings of the 4th IEEE/ACM
+ * International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS
+ * Press, USA), Melbourne, Australia, December 5-7, 2011.
+ *
+ *
+ * @author Saurabh Kumar Garg
+ * @since CloudSim Toolkit 1.0
+ */
+
+import java.util.List;
+
+import org.cloudbus.cloudsim.UtilizationModel;
+import org.cloudbus.cloudsim.UtilizationModelFull;
+import org.cloudbus.cloudsim.core.CloudSim;
+import org.cloudbus.cloudsim.network.datacenter.AppCloudlet;
+import org.cloudbus.cloudsim.network.datacenter.NetworkCloudlet;
+import org.cloudbus.cloudsim.network.datacenter.NetworkConstants;
+import org.cloudbus.cloudsim.network.datacenter.TaskStage;
+
+public class TestBagofTaskApp extends AppCloudlet {
+
+ public TestBagofTaskApp(int type, int appID, double deadline, int numbervm, int userId) {
+ super(type, appID, deadline, numbervm,userId);
+
+ this.numbervm=this.getnumvm();
+ this.exeTime=getExecTime()/this.numbervm;
+ }
+
+ @Override
+ public void createCloudletList(List vmIdList){
+ //basically, each task runs the simulation and then data is consolidated in one task
+ int executionTime = getExecTime();
+ long memory = 1000;
+ long fileSize = NetworkConstants.FILE_SIZE;
+ long outputSize = NetworkConstants.OUTPUT_SIZE;
+ int pesNumber = NetworkConstants.PES_NUMBER;
+ int stgId=0;
+ int t=NetworkConstants.currentCloudletId;
+ for(int i=0;iexetime)
+ return 2;
+ else if(this.deadline>(exetime/4)) return 4;
+
+ return 4;
+ }
+
+ private int getExecTime() {
+ //use exec constraints
+
+ return 100;
+ }
+
+
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/datacenter/TestExample.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/datacenter/TestExample.java
new file mode 100755
index 000000000..4f14cbb43
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/datacenter/TestExample.java
@@ -0,0 +1,316 @@
+package org.cloudbus.cloudsim.examples.network.datacenter;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+import org.cloudbus.cloudsim.Storage;
+import org.cloudbus.cloudsim.VmSchedulerTimeShared;
+import org.cloudbus.cloudsim.core.CloudSim;
+import org.cloudbus.cloudsim.network.datacenter.EdgeSwitch;
+import org.cloudbus.cloudsim.network.datacenter.NetDatacenterBroker;
+import org.cloudbus.cloudsim.network.datacenter.NetworkConstants;
+import org.cloudbus.cloudsim.network.datacenter.NetworkDatacenter;
+import org.cloudbus.cloudsim.network.datacenter.NetworkHost;
+import org.cloudbus.cloudsim.network.datacenter.NetworkVm;
+import org.cloudbus.cloudsim.network.datacenter.NetworkVmAllocationPolicy;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+
+public class TestExample {
+
+ /** The vmlist. */
+ private static List vmlist;
+
+ /**
+ * Creates main() to run this example.
+ *
+ * @param args
+ * the args
+ */
+ public static void main(String[] args) {
+
+ Log.printLine("Starting CloudSimExample1...");
+
+ try {
+ int num_user = 1; // number of cloud users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace events
+
+ // Initialize the CloudSim library
+ CloudSim.init(num_user, calendar, trace_flag);
+
+ // Second step: Create Datacenters
+ // Datacenters are the resource providers in CloudSim. We need at
+ // list one of them to run a CloudSim simulation
+ NetworkDatacenter datacenter0 = createDatacenter("Datacenter_0");
+
+ // Third step: Create Broker
+ NetDatacenterBroker broker = createBroker();
+ broker.setLinkDC(datacenter0);
+ // broker.setLinkDC(datacenter0);
+ // Fifth step: Create one Cloudlet
+
+ vmlist = new ArrayList();
+
+ // submit vm list to the broker
+
+ broker.submitVmList(vmlist);
+
+ // Sixth step: Starts the simulation
+ CloudSim.startSimulation();
+
+ CloudSim.stopSimulation();
+
+ // Final step: Print results when simulation is over
+ List newList = broker.getCloudletReceivedList();
+ printCloudletList(newList);
+ System.out.println("numberofcloudlet " + newList.size() + " Cached "
+ + NetDatacenterBroker.cachedcloudlet + " Data transfered "
+ + NetworkConstants.totaldatatransfer);
+ // Print the debt of each user to each datacenter
+ datacenter0.printDebts();
+
+ Log.printLine("CloudSimExample1 finished!");
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.printLine("Unwanted errors happen");
+ }
+ }
+
+ /**
+ * Creates the datacenter.
+ *
+ * @param name
+ * the name
+ *
+ * @return the datacenter
+ */
+ private static NetworkDatacenter createDatacenter(String name) {
+
+ // Here are the steps needed to create a PowerDatacenter:
+ // 1. We need to create a list to store
+ // our machine
+
+ List hostList = new ArrayList();
+
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ // List peList = new ArrayList();
+
+ int mips = 1;
+
+ // 3. Create PEs and add these into a list.
+ // peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to
+ // store Pe id and MIPS Rating
+
+ // 4. Create Host with its id and list of PEs and add them to the list
+ // of machines
+ int ram = 2048; // host memory (MB)
+ long storage = 1000000; // host storage
+ int bw = 10000;
+ for (int i = 0; i < NetworkConstants.EdgeSwitchPort * NetworkConstants.AggSwitchPort
+ * NetworkConstants.RootSwitchPort; i++) {
+ // 2. A Machine contains one or more PEs or CPUs/Cores.
+ // In this example, it will have only one core.
+ // 3. Create PEs and add these into an object of PowerPeList.
+ List peList = new ArrayList();
+ peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(1, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(2, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(3, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(4, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(5, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(6, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+ peList.add(new Pe(7, new PeProvisionerSimple(mips))); // need to
+ // store
+ // PowerPe
+ // id and
+ // MIPS
+ // Rating
+
+ // 4. Create PowerHost with its id and list of PEs and add them to
+ // the list of machines
+ hostList.add(new NetworkHost(
+ i,
+ new RamProvisionerSimple(ram),
+ new BwProvisionerSimple(bw),
+ storage,
+ peList,
+ new VmSchedulerTimeShared(peList))); // This is our machine
+ }
+
+ // 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).
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this
+ // resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+ LinkedList storageList = new LinkedList(); // we are
+ // not
+ // adding
+ // SAN
+ // devices by now
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch,
+ os,
+ vmm,
+ hostList,
+ time_zone,
+ cost,
+ costPerMem,
+ costPerStorage,
+ costPerBw);
+
+ // 6. Finally, we need to create a NetworkDatacenter object.
+ NetworkDatacenter datacenter = null;
+ try {
+ datacenter = new NetworkDatacenter(
+ name,
+ characteristics,
+ new NetworkVmAllocationPolicy(hostList),
+ storageList,
+ 0);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // Create Internal Datacenter network
+ CreateNetwork(2, datacenter);
+ return datacenter;
+ }
+
+ // We strongly encourage users to develop their own broker policies, to
+ // submit vms and cloudlets according
+ // to the specific rules of the simulated scenario
+ /**
+ * Creates the broker.
+ *
+ * @return the datacenter broker
+ */
+ private static NetDatacenterBroker createBroker() {
+ NetDatacenterBroker broker = null;
+ try {
+ broker = new NetDatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ return broker;
+ }
+
+ /**
+ * Prints the Cloudlet objects.
+ *
+ * @param list
+ * list of Cloudlets
+ * @throws IOException
+ */
+ private static void printCloudletList(List list) throws IOException {
+ int size = list.size();
+ Cloudlet cloudlet;
+ String indent = " ";
+ Log.printLine();
+ Log.printLine("========== OUTPUT ==========");
+ Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + "Data center ID" + indent + "VM ID"
+ + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
+
+ DecimalFormat dft = new DecimalFormat("###.##");
+ for (int i = 0; i < size; i++) {
+ cloudlet = list.get(i);
+ Log.print(indent + cloudlet.getCloudletId() + indent + indent);
+
+ if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
+ Log.print("SUCCESS");
+ Log.printLine(indent + indent + cloudlet.getResourceId() + indent + indent + indent
+ + cloudlet.getVmId() + indent + indent + dft.format(cloudlet.getActualCPUTime())
+ + indent + indent + dft.format(cloudlet.getExecStartTime()) + indent + indent
+ + dft.format(cloudlet.getFinishTime()));
+ }
+ }
+
+ }
+
+ static void CreateNetwork(int numhost, NetworkDatacenter dc) {
+
+ // Edge Switch
+ EdgeSwitch edgeswitch[] = new EdgeSwitch[1];
+
+ for (int i = 0; i < 1; i++) {
+ edgeswitch[i] = new EdgeSwitch("Edge" + i, NetworkConstants.EDGE_LEVEL, dc);
+ // edgeswitch[i].uplinkswitches.add(null);
+ dc.Switchlist.put(edgeswitch[i].getId(), edgeswitch[i]);
+ // aggswitch[(int)
+ // (i/Constants.AggSwitchPort)].downlinkswitches.add(edgeswitch[i]);
+ }
+
+ for (Host hs : dc.getHostList()) {
+ NetworkHost hs1 = (NetworkHost) hs;
+ hs1.bandwidth = NetworkConstants.BandWidthEdgeHost;
+ int switchnum = (int) (hs.getId() / NetworkConstants.EdgeSwitchPort);
+ edgeswitch[switchnum].hostlist.put(hs.getId(), hs1);
+ dc.HostToSwitchid.put(hs.getId(), edgeswitch[switchnum].getId());
+ hs1.sw = edgeswitch[switchnum];
+ List hslist = hs1.sw.fintimelistHost.get(0D);
+ if (hslist == null) {
+ hslist = new ArrayList();
+ hs1.sw.fintimelistHost.put(0D, hslist);
+ }
+ hslist.add(hs1);
+
+ }
+
+ }
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/topology.brite b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/topology.brite
new file mode 100644
index 000000000..52214f76f
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/network/topology.brite
@@ -0,0 +1,20 @@
+Topology: ( 5 Nodes, 8 Edges )
+Model (1 - RTWaxman): 5 5 5 1 2 0.15000000596046448 0.20000000298023224 1 1 10.0 1024.0
+
+Nodes: ( 5 )
+0 1 3 3 3 -1 RT_NODE
+1 0 3 3 3 -1 RT_NODE
+2 4 3 3 3 -1 RT_NODE
+3 3 1 3 3 -1 RT_NODE
+4 3 3 4 4 -1 RT_NODE
+
+
+Edges: ( 8 )
+0 2 0 3.0 1.1 10.0 -1 -1 E_RT U
+1 2 1 4.0 2.1 10.0 -1 -1 E_RT U
+2 3 0 2.8284271247461903 3.9 10.0 -1 -1 E_RT U
+3 3 1 3.605551275463989 4.1 10.0 -1 -1 E_RT U
+4 4 3 2.0 5.0 10.0 -1 -1 E_RT U
+5 4 2 1.0 4.0 10.0 -1 -1 E_RT U
+6 0 4 2.0 3.0 10.0 -1 -1 E_RT U
+7 1 4 3.0 4.1 10.0 -1 -1 E_RT U
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/power/Constants.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/power/Constants.java
new file mode 100644
index 000000000..e206dc7b2
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/power/Constants.java
@@ -0,0 +1,65 @@
+package org.cloudbus.cloudsim.examples.power;
+
+import org.cloudbus.cloudsim.power.models.PowerModel;
+import org.cloudbus.cloudsim.power.models.PowerModelSpecPowerHpProLiantMl110G4Xeon3040;
+import org.cloudbus.cloudsim.power.models.PowerModelSpecPowerHpProLiantMl110G5Xeon3075;
+
+/**
+ * If you are using any algorithms, policies or workload included in the power package, please cite
+ * the following paper:
+ *
+ * Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
+ * Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
+ * Cloud Data Centers", Concurrency and Computation: Practice and Experience, ISSN: 1532-0626, Wiley
+ * Press, New York, USA, 2011, DOI: 10.1002/cpe.1867
+ *
+ * @author Anton Beloglazov - IBM R&D Australia
+ * @since Jan 6, 2012
+ */
+public class Constants {
+
+ public final static boolean ENABLE_OUTPUT = true;
+ public final static boolean OUTPUT_CSV = false;
+
+ public final static double SCHEDULING_INTERVAL = 300;
+ public final static double SIMULATION_LIMIT = 24 * 60 * 60;
+
+ public final static int CLOUDLET_LENGTH = 2500 * (int) SIMULATION_LIMIT;
+ public final static int CLOUDLET_PES = 1;
+
+ /*
+ * VM instance types:
+ * High-Memory Extra Large Instance: 3.25 EC2 Compute Units, 8.55 GB // too much MIPS
+ * High-CPU Medium Instance: 2.5 EC2 Compute Units, 0.85 GB
+ * Extra Large Instance: 2 EC2 Compute Units, 3.75 GB
+ * Small Instance: 1 EC2 Compute Unit, 1.7 GB
+ * Micro Instance: 0.5 EC2 Compute Unit, 0.633 GB
+ * We decrease the memory size two times to enable oversubscription
+ *
+ */
+ public final static int VM_TYPES = 4;
+ public final static int[] VM_MIPS = { 2500, 2000, 1000, 500 };
+ public final static int[] VM_PES = { 1, 1, 1, 1 };
+ public final static int[] VM_RAM = { 870, 1740, 1740, 613 };
+ public final static int VM_BW = 100000; // 100 Mbit/s
+ public final static int VM_SIZE = 2500; // 2.5 GB
+
+ /*
+ * Host types:
+ * HP ProLiant ML110 G4 (1 x [Xeon 3040 1860 MHz, 2 cores], 4GB)
+ * HP ProLiant ML110 G5 (1 x [Xeon 3075 2660 MHz, 2 cores], 4GB)
+ * We increase the memory size to enable over-subscription (x4)
+ */
+ public final static int HOST_TYPES = 2;
+ public final static int[] HOST_MIPS = { 1860, 2660 };
+ public final static int[] HOST_PES = { 2, 2 };
+ public final static int[] HOST_RAM = { 4096, 4096 };
+ public final static int HOST_BW = 1000000; // 1 Gbit/s
+ public final static int HOST_STORAGE = 1000000; // 1 GB
+
+ public final static PowerModel[] HOST_POWER = {
+ new PowerModelSpecPowerHpProLiantMl110G4Xeon3040(),
+ new PowerModelSpecPowerHpProLiantMl110G5Xeon3075()
+ };
+
+}
diff --git a/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/power/Helper.java b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/power/Helper.java
new file mode 100644
index 000000000..107706fe8
--- /dev/null
+++ b/trunk/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/power/Helper.java
@@ -0,0 +1,779 @@
+package org.cloudbus.cloudsim.examples.power;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+
+import org.cloudbus.cloudsim.Cloudlet;
+import org.cloudbus.cloudsim.CloudletSchedulerDynamicWorkload;
+import org.cloudbus.cloudsim.Datacenter;
+import org.cloudbus.cloudsim.DatacenterBroker;
+import org.cloudbus.cloudsim.DatacenterCharacteristics;
+import org.cloudbus.cloudsim.Host;
+import org.cloudbus.cloudsim.HostDynamicWorkload;
+import org.cloudbus.cloudsim.HostStateHistoryEntry;
+import org.cloudbus.cloudsim.Log;
+import org.cloudbus.cloudsim.Pe;
+import org.cloudbus.cloudsim.Storage;
+import org.cloudbus.cloudsim.Vm;
+import org.cloudbus.cloudsim.VmAllocationPolicy;
+import org.cloudbus.cloudsim.VmSchedulerTimeSharedOverSubscription;
+import org.cloudbus.cloudsim.VmStateHistoryEntry;
+import org.cloudbus.cloudsim.power.PowerDatacenter;
+import org.cloudbus.cloudsim.power.PowerDatacenterBroker;
+import org.cloudbus.cloudsim.power.PowerHost;
+import org.cloudbus.cloudsim.power.PowerHostUtilizationHistory;
+import org.cloudbus.cloudsim.power.PowerVm;
+import org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationAbstract;
+import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
+import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
+import org.cloudbus.cloudsim.util.MathUtil;
+
+/**
+ * The Class Helper.
+ *
+ * If you are using any algorithms, policies or workload included in the power package, please cite
+ * the following paper:
+ *
+ * Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
+ * Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
+ * Cloud Data Centers", Concurrency and Computation: Practice and Experience, ISSN: 1532-0626, Wiley
+ * Press, New York, USA, 2011, DOI: 10.1002/cpe.1867
+ *
+ * @author Anton Beloglazov
+ */
+public class Helper {
+
+ /**
+ * Creates the vm list.
+ *
+ * @param brokerId the broker id
+ * @param vmsNumber the vms number
+ *
+ * @return the list< vm>
+ */
+ public static List createVmList(int brokerId, int vmsNumber) {
+ List vms = new ArrayList();
+ for (int i = 0; i < vmsNumber; i++) {
+ int vmType = i / (int) Math.ceil((double) vmsNumber / Constants.VM_TYPES);
+ vms.add(new PowerVm(
+ i,
+ brokerId,
+ Constants.VM_MIPS[vmType],
+ Constants.VM_PES[vmType],
+ Constants.VM_RAM[vmType],
+ Constants.VM_BW,
+ Constants.VM_SIZE,
+ 1,
+ "Xen",
+ new CloudletSchedulerDynamicWorkload(Constants.VM_MIPS[vmType], Constants.VM_PES[vmType]),
+ Constants.SCHEDULING_INTERVAL));
+ }
+ return vms;
+ }
+
+ /**
+ * Creates the host list.
+ *
+ * @param hostsNumber the hosts number
+ *
+ * @return the list< power host>
+ */
+ public static List createHostList(int hostsNumber) {
+ List hostList = new ArrayList();
+ for (int i = 0; i < hostsNumber; i++) {
+ int hostType = i % Constants.HOST_TYPES;
+
+ List peList = new ArrayList();
+ for (int j = 0; j < Constants.HOST_PES[hostType]; j++) {
+ peList.add(new Pe(j, new PeProvisionerSimple(Constants.HOST_MIPS[hostType])));
+ }
+
+ hostList.add(new PowerHostUtilizationHistory(
+ i,
+ new RamProvisionerSimple(Constants.HOST_RAM[hostType]),
+ new BwProvisionerSimple(Constants.HOST_BW),
+ Constants.HOST_STORAGE,
+ peList,
+ new VmSchedulerTimeSharedOverSubscription(peList),
+ Constants.HOST_POWER[hostType]));
+ }
+ return hostList;
+ }
+
+ /**
+ * Creates the broker.
+ *
+ * @return the datacenter broker
+ */
+ public static DatacenterBroker createBroker() {
+ DatacenterBroker broker = null;
+ try {
+ broker = new PowerDatacenterBroker("Broker");
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(0);
+ }
+ return broker;
+ }
+
+ /**
+ * Creates the datacenter.
+ *
+ * @param name the name
+ * @param datacenterClass the datacenter class
+ * @param hostList the host list
+ * @param vmAllocationPolicy the vm allocation policy
+ * @param simulationLength
+ *
+ * @return the power datacenter
+ *
+ * @throws Exception the exception
+ */
+ public static Datacenter createDatacenter(
+ String name,
+ Class extends Datacenter> datacenterClass,
+ List hostList,
+ VmAllocationPolicy vmAllocationPolicy) throws Exception {
+ String arch = "x86"; // system architecture
+ String os = "Linux"; // operating system
+ String vmm = "Xen";
+ double time_zone = 10.0; // time zone this resource located
+ 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 costPerStorage = 0.001; // the cost of using storage in this resource
+ double costPerBw = 0.0; // the cost of using bw in this resource
+
+ DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
+ arch,
+ os,
+ vmm,
+ hostList,
+ time_zone,
+ cost,
+ costPerMem,
+ costPerStorage,
+ costPerBw);
+
+ Datacenter datacenter = null;
+ try {
+ datacenter = datacenterClass.getConstructor(
+ String.class,
+ DatacenterCharacteristics.class,
+ VmAllocationPolicy.class,
+ List.class,
+ Double.TYPE).newInstance(
+ name,
+ characteristics,
+ vmAllocationPolicy,
+ new LinkedList(),
+ Constants.SCHEDULING_INTERVAL);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(0);
+ }
+
+ return datacenter;
+ }
+
+ /**
+ * Gets the times before host shutdown.
+ *
+ * @param hosts the hosts
+ * @return the times before host shutdown
+ */
+ public static List getTimesBeforeHostShutdown(List hosts) {
+ List timeBeforeShutdown = new LinkedList();
+ for (Host host : hosts) {
+ boolean previousIsActive = true;
+ double lastTimeSwitchedOn = 0;
+ for (HostStateHistoryEntry entry : ((HostDynamicWorkload) host).getStateHistory()) {
+ if (previousIsActive == true && entry.isActive() == false) {
+ timeBeforeShutdown.add(entry.getTime() - lastTimeSwitchedOn);
+ }
+ if (previousIsActive == false && entry.isActive() == true) {
+ lastTimeSwitchedOn = entry.getTime();
+ }
+ previousIsActive = entry.isActive();
+ }
+ }
+ return timeBeforeShutdown;
+ }
+
+ /**
+ * Gets the times before vm migration.
+ *
+ * @param vms the vms
+ * @return the times before vm migration
+ */
+ public static List getTimesBeforeVmMigration(List vms) {
+ List timeBeforeVmMigration = new LinkedList();
+ for (Vm vm : vms) {
+ boolean previousIsInMigration = false;
+ double lastTimeMigrationFinished = 0;
+ for (VmStateHistoryEntry entry : vm.getStateHistory()) {
+ if (previousIsInMigration == true && entry.isInMigration() == false) {
+ timeBeforeVmMigration.add(entry.getTime() - lastTimeMigrationFinished);
+ }
+ if (previousIsInMigration == false && entry.isInMigration() == true) {
+ lastTimeMigrationFinished = entry.getTime();
+ }
+ previousIsInMigration = entry.isInMigration();
+ }
+ }
+ return timeBeforeVmMigration;
+ }
+
+ /**
+ * Prints the results.
+ *
+ * @param datacenter the datacenter
+ * @param lastClock the last clock
+ * @param experimentName the experiment name
+ * @param outputInCsv the output in csv
+ * @param outputFolder the output folder
+ */
+ public static void printResults(
+ PowerDatacenter datacenter,
+ List vms,
+ double lastClock,
+ String experimentName,
+ boolean outputInCsv,
+ String outputFolder) {
+ Log.enable();
+ List hosts = datacenter.getHostList();
+
+ int numberOfHosts = hosts.size();
+ int numberOfVms = vms.size();
+
+ double totalSimulationTime = lastClock;
+ double energy = datacenter.getPower() / (3600 * 1000);
+ int numberOfMigrations = datacenter.getMigrationCount();
+
+ Map slaMetrics = getSlaMetrics(vms);
+
+ double slaOverall = slaMetrics.get("overall");
+ double slaAverage = slaMetrics.get("average");
+ double slaDegradationDueToMigration = slaMetrics.get("underallocated_migration");
+ // double slaTimePerVmWithMigration = slaMetrics.get("sla_time_per_vm_with_migration");
+ // double slaTimePerVmWithoutMigration =
+ // slaMetrics.get("sla_time_per_vm_without_migration");
+ // double slaTimePerHost = getSlaTimePerHost(hosts);
+ double slaTimePerActiveHost = getSlaTimePerActiveHost(hosts);
+
+ double sla = slaTimePerActiveHost * slaDegradationDueToMigration;
+
+ List timeBeforeHostShutdown = getTimesBeforeHostShutdown(hosts);
+
+ int numberOfHostShutdowns = timeBeforeHostShutdown.size();
+
+ double meanTimeBeforeHostShutdown = Double.NaN;
+ double stDevTimeBeforeHostShutdown = Double.NaN;
+ if (!timeBeforeHostShutdown.isEmpty()) {
+ meanTimeBeforeHostShutdown = MathUtil.mean(timeBeforeHostShutdown);
+ stDevTimeBeforeHostShutdown = MathUtil.stDev(timeBeforeHostShutdown);
+ }
+
+ List timeBeforeVmMigration = getTimesBeforeVmMigration(vms);
+ double meanTimeBeforeVmMigration = Double.NaN;
+ double stDevTimeBeforeVmMigration = Double.NaN;
+ if (!timeBeforeVmMigration.isEmpty()) {
+ meanTimeBeforeVmMigration = MathUtil.mean(timeBeforeVmMigration);
+ stDevTimeBeforeVmMigration = MathUtil.stDev(timeBeforeVmMigration);
+ }
+
+ if (outputInCsv) {
+ File folder = new File(outputFolder);
+ if (!folder.exists()) {
+ folder.mkdir();
+ }
+ File folder1 = new File(outputFolder + "/stats");
+ if (!folder1.exists()) {
+ folder1.mkdir();
+ }
+ File folder2 = new File(outputFolder + "/time_before_host_shutdown");
+ if (!folder2.exists()) {
+ folder2.mkdir();
+ }
+ File folder3 = new File(outputFolder + "/time_before_vm_migration");
+ if (!folder3.exists()) {
+ folder3.mkdir();
+ }
+ File folder4 = new File(outputFolder + "/metrics");
+ if (!folder4.exists()) {
+ folder4.mkdir();
+ }
+
+ StringBuilder data = new StringBuilder();
+ String delimeter = ",";
+
+ data.append(experimentName + delimeter);
+ data.append(parseExperimentName(experimentName));
+ data.append(String.format("%d", numberOfHosts) + delimeter);
+ data.append(String.format("%d", numberOfVms) + delimeter);
+ data.append(String.format("%.2f", totalSimulationTime) + delimeter);
+ data.append(String.format("%.5f", energy) + delimeter);
+ data.append(String.format("%d", numberOfMigrations) + delimeter);
+ data.append(String.format("%.10f", sla) + delimeter);
+ data.append(String.format("%.10f", slaTimePerActiveHost) + delimeter);
+ data.append(String.format("%.10f", slaDegradationDueToMigration) + delimeter);
+ data.append(String.format("%.10f", slaOverall) + delimeter);
+ data.append(String.format("%.10f", slaAverage) + delimeter);
+ // data.append(String.format("%.5f", slaTimePerVmWithMigration) + delimeter);
+ // data.append(String.format("%.5f", slaTimePerVmWithoutMigration) + delimeter);
+ // data.append(String.format("%.5f", slaTimePerHost) + delimeter);
+ data.append(String.format("%d", numberOfHostShutdowns) + delimeter);
+ data.append(String.format("%.2f", meanTimeBeforeHostShutdown) + delimeter);
+ data.append(String.format("%.2f", stDevTimeBeforeHostShutdown) + delimeter);
+ data.append(String.format("%.2f", meanTimeBeforeVmMigration) + delimeter);
+ data.append(String.format("%.2f", stDevTimeBeforeVmMigration) + delimeter);
+
+ if (datacenter.getVmAllocationPolicy() instanceof PowerVmAllocationPolicyMigrationAbstract) {
+ PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy = (PowerVmAllocationPolicyMigrationAbstract) datacenter
+ .getVmAllocationPolicy();
+
+ double executionTimeVmSelectionMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryVmSelection());
+ double executionTimeVmSelectionStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryVmSelection());
+ double executionTimeHostSelectionMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryHostSelection());
+ double executionTimeHostSelectionStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryHostSelection());
+ double executionTimeVmReallocationMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryVmReallocation());
+ double executionTimeVmReallocationStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryVmReallocation());
+ double executionTimeTotalMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryTotal());
+ double executionTimeTotalStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryTotal());
+
+ data.append(String.format("%.5f", executionTimeVmSelectionMean) + delimeter);
+ data.append(String.format("%.5f", executionTimeVmSelectionStDev) + delimeter);
+ data.append(String.format("%.5f", executionTimeHostSelectionMean) + delimeter);
+ data.append(String.format("%.5f", executionTimeHostSelectionStDev) + delimeter);
+ data.append(String.format("%.5f", executionTimeVmReallocationMean) + delimeter);
+ data.append(String.format("%.5f", executionTimeVmReallocationStDev) + delimeter);
+ data.append(String.format("%.5f", executionTimeTotalMean) + delimeter);
+ data.append(String.format("%.5f", executionTimeTotalStDev) + delimeter);
+
+ writeMetricHistory(hosts, vmAllocationPolicy, outputFolder + "/metrics/" + experimentName
+ + "_metric");
+ }
+
+ data.append("\n");
+
+ writeDataRow(data.toString(), outputFolder + "/stats/" + experimentName + "_stats.csv");
+ writeDataColumn(timeBeforeHostShutdown, outputFolder + "/time_before_host_shutdown/"
+ + experimentName + "_time_before_host_shutdown.csv");
+ writeDataColumn(timeBeforeVmMigration, outputFolder + "/time_before_vm_migration/"
+ + experimentName + "_time_before_vm_migration.csv");
+
+ } else {
+ Log.setDisabled(false);
+ Log.printLine();
+ Log.printLine(String.format("Experiment name: " + experimentName));
+ Log.printLine(String.format("Number of hosts: " + numberOfHosts));
+ Log.printLine(String.format("Number of VMs: " + numberOfVms));
+ Log.printLine(String.format("Total simulation time: %.2f sec", totalSimulationTime));
+ Log.printLine(String.format("Energy consumption: %.2f kWh", energy));
+ Log.printLine(String.format("Number of VM migrations: %d", numberOfMigrations));
+ Log.printLine(String.format("SLA: %.5f%%", sla * 100));
+ Log.printLine(String.format(
+ "SLA perf degradation due to migration: %.2f%%",
+ slaDegradationDueToMigration * 100));
+ Log.printLine(String.format("SLA time per active host: %.2f%%", slaTimePerActiveHost * 100));
+ Log.printLine(String.format("Overall SLA violation: %.2f%%", slaOverall * 100));
+ Log.printLine(String.format("Average SLA violation: %.2f%%", slaAverage * 100));
+ // Log.printLine(String.format("SLA time per VM with migration: %.2f%%",
+ // slaTimePerVmWithMigration * 100));
+ // Log.printLine(String.format("SLA time per VM without migration: %.2f%%",
+ // slaTimePerVmWithoutMigration * 100));
+ // Log.printLine(String.format("SLA time per host: %.2f%%", slaTimePerHost * 100));
+ Log.printLine(String.format("Number of host shutdowns: %d", numberOfHostShutdowns));
+ Log.printLine(String.format(
+ "Mean time before a host shutdown: %.2f sec",
+ meanTimeBeforeHostShutdown));
+ Log.printLine(String.format(
+ "StDev time before a host shutdown: %.2f sec",
+ stDevTimeBeforeHostShutdown));
+ Log.printLine(String.format(
+ "Mean time before a VM migration: %.2f sec",
+ meanTimeBeforeVmMigration));
+ Log.printLine(String.format(
+ "StDev time before a VM migration: %.2f sec",
+ stDevTimeBeforeVmMigration));
+
+ if (datacenter.getVmAllocationPolicy() instanceof PowerVmAllocationPolicyMigrationAbstract) {
+ PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy = (PowerVmAllocationPolicyMigrationAbstract) datacenter
+ .getVmAllocationPolicy();
+
+ double executionTimeVmSelectionMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryVmSelection());
+ double executionTimeVmSelectionStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryVmSelection());
+ double executionTimeHostSelectionMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryHostSelection());
+ double executionTimeHostSelectionStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryHostSelection());
+ double executionTimeVmReallocationMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryVmReallocation());
+ double executionTimeVmReallocationStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryVmReallocation());
+ double executionTimeTotalMean = MathUtil.mean(vmAllocationPolicy
+ .getExecutionTimeHistoryTotal());
+ double executionTimeTotalStDev = MathUtil.stDev(vmAllocationPolicy
+ .getExecutionTimeHistoryTotal());
+
+ Log.printLine(String.format(
+ "Execution time - VM selection mean: %.5f sec",
+ executionTimeVmSelectionMean));
+ Log.printLine(String.format(
+ "Execution time - VM selection stDev: %.5f sec",
+ executionTimeVmSelectionStDev));
+ Log.printLine(String.format(
+ "Execution time - host selection mean: %.5f sec",
+ executionTimeHostSelectionMean));
+ Log.printLine(String.format(
+ "Execution time - host selection stDev: %.5f sec",
+ executionTimeHostSelectionStDev));
+ Log.printLine(String.format(
+ "Execution time - VM reallocation mean: %.5f sec",
+ executionTimeVmReallocationMean));
+ Log.printLine(String.format(
+ "Execution time - VM reallocation stDev: %.5f sec",
+ executionTimeVmReallocationStDev));
+ Log.printLine(String.format("Execution time - total mean: %.5f sec", executionTimeTotalMean));
+ Log.printLine(String
+ .format("Execution time - total stDev: %.5f sec", executionTimeTotalStDev));
+ }
+ Log.printLine();
+ }
+
+ Log.setDisabled(true);
+ }
+
+ /**
+ * Parses the experiment name.
+ *
+ * @param name the name
+ * @return the string
+ */
+ public static String parseExperimentName(String name) {
+ Scanner scanner = new Scanner(name);
+ StringBuilder csvName = new StringBuilder();
+ scanner.useDelimiter("_");
+ for (int i = 0; i < 4; i++) {
+ if (scanner.hasNext()) {
+ csvName.append(scanner.next() + ",");
+ } else {
+ csvName.append(",");
+ }
+ }
+ scanner.close();
+ return csvName.toString();
+ }
+
+ /**
+ * Gets the sla time per active host.
+ *
+ * @param hosts the hosts
+ * @return the sla time per active host
+ */
+ protected static double getSlaTimePerActiveHost(List hosts) {
+ double slaViolationTimePerHost = 0;
+ double totalTime = 0;
+
+ for (Host _host : hosts) {
+ HostDynamicWorkload host = (HostDynamicWorkload) _host;
+ double previousTime = -1;
+ double previousAllocated = 0;
+ double previousRequested = 0;
+ boolean previousIsActive = true;
+
+ for (HostStateHistoryEntry entry : host.getStateHistory()) {
+ if (previousTime != -1 && previousIsActive) {
+ double timeDiff = entry.getTime() - previousTime;
+ totalTime += timeDiff;
+ if (previousAllocated < previousRequested) {
+ slaViolationTimePerHost += timeDiff;
+ }
+ }
+
+ previousAllocated = entry.getAllocatedMips();
+ previousRequested = entry.getRequestedMips();
+ previousTime = entry.getTime();
+ previousIsActive = entry.isActive();
+ }
+ }
+
+ return slaViolationTimePerHost / totalTime;
+ }
+
+ /**
+ * Gets the sla time per host.
+ *
+ * @param hosts the hosts
+ * @return the sla time per host
+ */
+ protected static double getSlaTimePerHost(List hosts) {
+ double slaViolationTimePerHost = 0;
+ double totalTime = 0;
+
+ for (Host _host : hosts) {
+ HostDynamicWorkload host = (HostDynamicWorkload) _host;
+ double previousTime = -1;
+ double previousAllocated = 0;
+ double previousRequested = 0;
+
+ for (HostStateHistoryEntry entry : host.getStateHistory()) {
+ if (previousTime != -1) {
+ double timeDiff = entry.getTime() - previousTime;
+ totalTime += timeDiff;
+ if (previousAllocated < previousRequested) {
+ slaViolationTimePerHost += timeDiff;
+ }
+ }
+
+ previousAllocated = entry.getAllocatedMips();
+ previousRequested = entry.getRequestedMips();
+ previousTime = entry.getTime();
+ }
+ }
+
+ return slaViolationTimePerHost / totalTime;
+ }
+
+ /**
+ * Gets the sla metrics.
+ *
+ * @param vms the vms
+ * @return the sla metrics
+ */
+ protected static Map getSlaMetrics(List vms) {
+ Map metrics = new HashMap();
+ List