Class DatacenterSimple

java.lang.Object
org.cloudbus.cloudsim.core.CloudSimEntity
org.cloudbus.cloudsim.datacenters.DatacenterSimple
All Implemented Interfaces:
Cloneable, Comparable<SimEntity>, Runnable, Identifiable, Nameable, SimEntity, Sizeable, Datacenter, TimeZoned, PowerAware<PowerModelDatacenter>
Direct Known Subclasses:
NetworkDatacenter

public class DatacenterSimple
extends CloudSimEntity
implements Datacenter
Implements the basic features of a Virtualized Cloud Datacenter. It deals with processing of VM queries (i.e., handling of VMs) instead of processing Cloudlet-related queries.
Since:
CloudSim Toolkit 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov
  • Constructor Details

  • Method Details

    • processEvent

      public void processEvent​(SimEvent evt)
      Description copied from interface: SimEntity
      Processes events or services that are available for the entity. This method is invoked by the CloudSim class whenever there is an event in the deferred queue, which needs to be processed by the entity.
      Specified by:
      processEvent in interface SimEntity
      Parameters:
      evt - information about the event just happened
    • processPingRequest

      protected void processPingRequest​(SimEvent evt)
      Processes a ping request.
      Parameters:
      evt - information about the event just happened
    • processCloudlet

      protected void processCloudlet​(SimEvent evt, int type)
      Processes a Cloudlet based on the event type.
      Parameters:
      evt - information about the event just happened
      type - event type
    • processCloudletSubmit

      protected void processCloudletSubmit​(SimEvent evt, boolean ack)
      Processes the submission of a Cloudlet by a DatacenterBroker.
      Parameters:
      evt - information about the event just happened
      ack - indicates if the event's sender expects to receive an acknowledge message when the event finishes to be processed
    • getCloudletProcessingUpdateInterval

      protected double getCloudletProcessingUpdateInterval​(double nextFinishingCloudletTime)
      Gets the time when the next update of cloudlets has to be performed. This is the minimum value between the getSchedulingInterval() and the given time (if the scheduling interval is enable, i.e. if it's greater than 0), which represents when the next update of Cloudlets processing has to be performed.
      Parameters:
      nextFinishingCloudletTime - the predicted completion time of the earliest finishing cloudlet (which is a relative delay from the current simulation time), or Double.MAX_VALUE if there is no next Cloudlet to execute
      Returns:
      next time cloudlets processing will be updated (a relative delay from the current simulation time)
      See Also:
      updateCloudletProcessing()
    • processCloudletResume

      protected void processCloudletResume​(Cloudlet cloudlet, boolean ack)
      Processes a Cloudlet resume request.
      Parameters:
      cloudlet - cloudlet to be resumed
      ack - indicates if the event's sender expects to receive an acknowledge message when the event finishes to be processed
    • processCloudletPause

      protected void processCloudletPause​(Cloudlet cloudlet, boolean ack)
      Processes a Cloudlet pause request.
      Parameters:
      cloudlet - cloudlet to be paused
      ack - indicates if the event's sender expects to receive an acknowledge message when the event finishes to be processed
    • processCloudletCancel

      protected void processCloudletCancel​(Cloudlet cloudlet)
      Processes a Cloudlet cancel request.
      Parameters:
      cloudlet - cloudlet to be canceled
    • processVmDestroy

      protected void processVmDestroy​(SimEvent evt, boolean ack)
      Process the event sent by a Broker, requesting the destruction of a given VM created in this Datacenter. This Datacenter may send, upon request, the status back to the Broker.
      Parameters:
      evt - information about the event just happened
      ack - indicates if the event's sender expects to receive an acknowledge message when the event finishes to be processed
    • finishVmMigration

      protected void finishVmMigration​(SimEvent evt, boolean ack)
      Finishes the process of migrating a VM.
      Parameters:
      evt - information about the event just happened
      ack - indicates if the event's sender expects to receive an acknowledge message when the event finishes to be processed
      See Also:
      CloudSimTags.VM_MIGRATE
    • updateCloudletProcessing

      protected double updateCloudletProcessing()
      Updates processing of each Host, that fires the update of VMs, which in turn updates cloudlets running in this Datacenter. After that, the method schedules the next processing update. It is necessary because Hosts and VMs are simple objects, not entities. So, they don't receive events and updating cloudlets inside them must be called from the outside.
      Returns:
      the predicted completion time of the earliest finishing cloudlet (which is a relative delay from the current simulation time), or Double.MAX_VALUE if there is no next Cloudlet to execute or it isn't time to update the cloudlets
    • requestVmMigration

      public void requestVmMigration​(Vm sourceVm)
      Description copied from interface: Datacenter
      Sends an event to request the migration of a Vm to some suitable Host on this Datacenter. A suitable Host will try to be found when the migration request message is processed by the Datacenter. If you want VM migrations to be performed automatically, use a VmAllocationPolicyMigration.
      Specified by:
      requestVmMigration in interface Datacenter
      Parameters:
      sourceVm - the VM to be migrated
      See Also:
      Datacenter.requestVmMigration(Vm, Host), Datacenter.getVmAllocationPolicy()
    • requestVmMigration

      public void requestVmMigration​(Vm sourceVm, Host targetHost)
      Description copied from interface: Datacenter
      Sends an event to request the migration of a Vm to a given target Host on this Datacenter. If you want VM migrations to be performed automatically, use a VmAllocationPolicyMigration.
      Specified by:
      requestVmMigration in interface Datacenter
      Parameters:
      sourceVm - the VM to be migrated
      targetHost - the target Host to migrate the VM to
      See Also:
      Datacenter.requestVmMigration(Vm), Datacenter.getVmAllocationPolicy()
    • shutdown

      public void shutdown()
      Description copied from interface: SimEntity
      Shuts down the entity. This method is invoked by the CloudSim before the simulation finishes. If you want to save data in log files this is the method in which the corresponding code would be placed.
      Specified by:
      shutdown in interface SimEntity
      Overrides:
      shutdown in class CloudSimEntity
    • startInternal

      protected void startInternal()
      Description copied from class: CloudSimEntity
      Defines the logic to be performed by the entity when the simulation starts.
      Specified by:
      startInternal in class CloudSimEntity
    • getHostList

      public <T extends Host> List<T> getHostList()
      Description copied from interface: Datacenter
      Gets an unmodifiable host list.
      Specified by:
      getHostList in interface Datacenter
      Type Parameters:
      T - The generic type
      Returns:
      the host list
    • getActiveHostStream

      public Stream<? extends Host> getActiveHostStream()
      Description copied from interface: Datacenter
      Gets a Stream containing the active Hosts inside the Datacenter.
      Specified by:
      getActiveHostStream in interface Datacenter
      Returns:
      the active host Stream
    • getCharacteristics

      public DatacenterCharacteristics getCharacteristics()
      Description copied from interface: Datacenter
      Gets the Datacenter characteristics.
      Specified by:
      getCharacteristics in interface Datacenter
      Returns:
      the Datacenter characteristics
    • getVmAllocationPolicy

      public VmAllocationPolicy getVmAllocationPolicy()
      Description copied from interface: Datacenter
      Gets the policy to be used by the Datacenter to allocate VMs into hosts.
      Specified by:
      getVmAllocationPolicy in interface Datacenter
      Returns:
      the VM allocation policy
      See Also:
      VmAllocationPolicy
    • setVmAllocationPolicy

      public final Datacenter setVmAllocationPolicy​(VmAllocationPolicy vmAllocationPolicy)
      Sets the policy to be used by the Datacenter to allocate VMs into hosts.
      Parameters:
      vmAllocationPolicy - the new vm allocation policy
    • getLastProcessTime

      protected double getLastProcessTime()
      Gets the last time some cloudlet was processed in the Datacenter.
      Returns:
      the last process time
    • setLastProcessTime

      protected final void setLastProcessTime​(double lastProcessTime)
      Sets the last time some cloudlet was processed in the Datacenter.
      Parameters:
      lastProcessTime - the new last process time
    • getDatacenterStorage

      public DatacenterStorage getDatacenterStorage()
      Description copied from interface: Datacenter
      Gets the storage of the Datacenter.
      Specified by:
      getDatacenterStorage in interface Datacenter
      Returns:
      the storage
    • setDatacenterStorage

      public final void setDatacenterStorage​(DatacenterStorage datacenterStorage)
      Description copied from interface: Datacenter
      Sets the storage of the Datacenter.
      Specified by:
      setDatacenterStorage in interface Datacenter
      Parameters:
      datacenterStorage - the new storage
    • getSchedulingInterval

      public double getSchedulingInterval()
      Description copied from interface: Datacenter
      Gets the scheduling interval to process each event received by the Datacenter (in seconds). This value defines the interval in which processing of Cloudlets will be updated. The interval doesn't affect the processing of such cloudlets, it only defines in which interval the processing will be updated. For instance, if it is set an interval of 10 seconds, the processing of cloudlets will be updated at every 10 seconds. Trying to get the amount of instructions the cloudlet has executed after 5 seconds, by means of Cloudlet.getFinishedLengthSoFar(Datacenter), won't return an updated value. This way, one should set the scheduling interval to 5 to get updated data. As longer is the interval, faster will be the simulation execution.

      The default value is zero, which indicates no scheduling interval is set and the simulation state is updated only when a cloudlet is finished. That ensures the highest performance but may not be desired if you want to collect some simulation data in a defined time interval.

      Specified by:
      getSchedulingInterval in interface Datacenter
      Returns:
      the scheduling interval (in seconds)
    • setSchedulingInterval

      public final Datacenter setSchedulingInterval​(double schedulingInterval)
      Description copied from interface: Datacenter
      Sets the scheduling delay to process each event received by the Datacenter (in seconds).
      Specified by:
      setSchedulingInterval in interface Datacenter
      Parameters:
      schedulingInterval - the new scheduling interval (in seconds)
      Returns:
      See Also:
      Datacenter.getSchedulingInterval()
    • getTimeZone

      public double getTimeZone()
      Description copied from interface: TimeZoned
      Gets the time zone offset, a value between [-12 and 12], in which the object is physically located.
      Specified by:
      getTimeZone in interface TimeZoned
      Returns:
      the time zone offset
    • setTimeZone

      public final Datacenter setTimeZone​(double timeZone)
      Description copied from interface: TimeZoned
      Sets the time zone offset between [-12 and 12].
      Specified by:
      setTimeZone in interface TimeZoned
      Parameters:
      timeZone - the new time zone offset
      Returns:
    • getHost

      public Host getHost​(int index)
      Description copied from interface: Datacenter
      Gets a Host in a given position inside the Host List.
      Specified by:
      getHost in interface Datacenter
      Parameters:
      index - the position of the List to get the Host
      Returns:
    • getActiveHostsNumber

      public long getActiveHostsNumber()
      Description copied from interface: Datacenter
      Gets the current number of Hosts that are powered on inside the Datacenter.
      Specified by:
      getActiveHostsNumber in interface Datacenter
      Returns:
      See Also:
      Host.isActive()
    • size

      public long size()
      Description copied from interface: Datacenter
      Gets the total number of existing Hosts in this Datacenter, which indicates the Datacenter's size.
      Specified by:
      size in interface Datacenter
      Specified by:
      size in interface Sizeable
      Returns:
    • getHostById

      public Host getHostById​(long id)
      Description copied from interface: Datacenter
      Gets a Host from its id.
      Specified by:
      getHostById in interface Datacenter
      Parameters:
      id - the ID of the Host to get from the List.
      Returns:
      the Host if found or Host.NULL otherwise
    • addHostList

      public <T extends Host> Datacenter addHostList​(List<T> hostList)
      Description copied from interface: Datacenter
      Physically expands the Datacenter by adding a List of new Hosts (physical machines) to it. Hosts can be added before or after the simulation has started. If a Host is added during simulation execution, in case VMs are added dynamically too, they may be allocated to this new Host, depending on the VmAllocationPolicy.

      If an ID is not assigned to a Host, the method assigns one.

      Specified by:
      addHostList in interface Datacenter
      Parameters:
      hostList - the List of new hosts to be added
      Returns:
      See Also:
      Datacenter.getVmAllocationPolicy()
    • addHost

      public <T extends Host> Datacenter addHost​(T host)
      Description copied from interface: Datacenter
      Physically expands the Datacenter by adding a new Host (physical machine) to it. Hosts can be added before or after the simulation has started. If a Host is added during simulation execution, in case VMs are added dynamically too, they may be allocated to this new Host, depending on the VmAllocationPolicy.

      If an ID is not assigned to the given Host, the method assigns one.

      Specified by:
      addHost in interface Datacenter
      Parameters:
      host - the new host to be added
      Returns:
      See Also:
      Datacenter.getVmAllocationPolicy()
    • removeHost

      public <T extends Host> Datacenter removeHost​(T host)
      Description copied from interface: Datacenter
      Removes a Host from its Datacenter.
      Specified by:
      removeHost in interface Datacenter
      Parameters:
      host - the new host to be removed from its assigned Datacenter
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals​(Object object)
      Overrides:
      equals in class CloudSimEntity
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class CloudSimEntity
    • getBandwidthPercentForMigration

      public double getBandwidthPercentForMigration()
      Description copied from interface: Datacenter
      Gets the percentage of the bandwidth allocated to a Host to migrate VMs. It's a value between [0 and 1] (where 1 is 100%). The default value is 0.5, meaning only 50% of the bandwidth will be allowed for migration, while the remaining will be used for VM services.
      Specified by:
      getBandwidthPercentForMigration in interface Datacenter
      Returns:
      See Also:
      Datacenter.DEF_BW_PERCENT_FOR_MIGRATION
    • setBandwidthPercentForMigration

      public void setBandwidthPercentForMigration​(double bandwidthPercentForMigration)
      Description copied from interface: Datacenter
      Sets the percentage of the bandwidth allocated to a Host to migrate VMs. It's a value between [0 and 1] (where 1 is 100%). The default value is 0.5, meaning only 50% of the bandwidth will be allowed for migration, while the remaining will be used for VM services.
      Specified by:
      setBandwidthPercentForMigration in interface Datacenter
      Parameters:
      bandwidthPercentForMigration - the bandwidth migration percentage to set
    • addOnHostAvailableListener

      public Datacenter addOnHostAvailableListener​(EventListener<HostEventInfo> listener)
      Description copied from interface: Datacenter
      Adds a EventListener object that will be notified every time a new Host is available for the Datacenter during simulation runtime. If the Datacenter.addHost(Host) or Datacenter.addHostList(List) is called before the simulation starts, the listeners will not be notified.
      Specified by:
      addOnHostAvailableListener in interface Datacenter
      Parameters:
      listener - the event listener to add
      Returns:
    • addOnVmMigrationFinishListener

      public Datacenter addOnVmMigrationFinishListener​(EventListener<DatacenterVmMigrationEventInfo> listener)
      Description copied from interface: Datacenter
      Adds a EventListener object that will be notified every time a VM migration is finished either successfully or not.
      Specified by:
      addOnVmMigrationFinishListener in interface Datacenter
      Parameters:
      listener - the event listener to add
      Returns:
    • isMigrationsEnabled

      public boolean isMigrationsEnabled()
      Description copied from interface: Datacenter
      Checks if migrations are enabled.
      Specified by:
      isMigrationsEnabled in interface Datacenter
      Returns:
      true, if migrations are enable; false otherwise
    • enableMigrations

      public final Datacenter enableMigrations()
      Description copied from interface: Datacenter
      Enable VM migrations.
      Specified by:
      enableMigrations in interface Datacenter
      Returns:
      See Also:
      Datacenter.getHostSearchRetryDelay()
    • disableMigrations

      public final Datacenter disableMigrations()
      Description copied from interface: Datacenter
      Disable VM migrations.
      Specified by:
      disableMigrations in interface Datacenter
      Returns:
    • getPowerModel

      public PowerModelDatacenter getPowerModel()
      Description copied from interface: PowerAware
      Gets the model defining how the entity consumes power.
      Specified by:
      getPowerModel in interface PowerAware<PowerModelDatacenter>
      Returns:
    • setPowerModel

      public final void setPowerModel​(PowerModelDatacenter powerModel)
      Description copied from interface: PowerAware
      Sets the model defining how the entity consumes power.
      Specified by:
      setPowerModel in interface PowerAware<PowerModelDatacenter>
      Parameters:
      powerModel - the model to set
    • getHostSearchRetryDelay

      public double getHostSearchRetryDelay()
      Description copied from interface: Datacenter
      Gets the time interval before trying to find suitable Hosts to migrate VMs from an under or overload Host again.
      Specified by:
      getHostSearchRetryDelay in interface Datacenter
      Returns:
      the Host search delay (in seconds)
    • setHostSearchRetryDelay

      public Datacenter setHostSearchRetryDelay​(double delay)
      Description copied from interface: Datacenter
      Sets the time interval before trying to find suitable Hosts to migrate VMs from an under or overload Host again.
      Specified by:
      setHostSearchRetryDelay in interface Datacenter
      Parameters:
      delay - the new delay to set (in seconds). Give a positive value to define an actual delay or a negative value to indicate a new Host search for VM migration must be tried as soon as possible
      Returns: