Simulation

public interface Simulation

An interface to be implemented by a class that manages simulation execution, controlling all the simulation life cycle.

Author:Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho

See also: CloudSim

Fields

ANY_EVT

Predicate<SimEvent> ANY_EVT

A standard predicate that matches any event.

NULL

Simulation NULL

An attribute that implements the Null Object Design Pattern for Simulation objects.

Methods

abort

void abort()

Aborts the simulation without finishing the processing of entities in the entities list, what may give unexpected results.

Use this method just if you want to abandon the simulation an usually ignore the results.

addEntity

void addEntity(CloudSimEntity e)

Adds a new entity to the simulation. Each CloudSimEntity object register itself when it is instantiated.

Parameters:
  • e – The new entity

addOnClockTickListener

Simulation addOnClockTickListener(EventListener<EventInfo> listener)

Adds a EventListener object that will be notified every time when the simulation clock advances. Notifications are sent in a second interval to avoid notification flood. Thus, if the clock changes, for instance, from 1.0, to 1.1, 2.0, 2.1, 2.2, 2.5 and then 3.2, notifications will just be sent for the times 1, 2 and 3 that represent the integer part of the simulation time.

Parameters:
  • listener – the event listener to add

addOnEventProcessingListener

Simulation addOnEventProcessingListener(EventListener<SimEvent> listener)

Adds a EventListener object that will be notified when any event is processed by CloudSim. When this Listener is notified, it will receive the SimEvent that was processed.

Parameters:
  • listener – the event listener to add

addOnSimulationPauseListener

Simulation addOnSimulationPauseListener(EventListener<EventInfo> listener)

Adds an EventListener object that will be notified when the simulation is paused. When this Listener is notified, it will receive an EventInfo informing the time the pause occurred.

This object is just information about the event that happened. In fact, it isn’t generated an actual {@limk SimEvent} for a pause event because there is not need for that.

Parameters:
  • listener – the event listener to add

addOnSimulationStartListener

Simulation addOnSimulationStartListener(EventListener<EventInfo> listener)

cancel

SimEvent cancel(SimEntity src, Predicate<SimEvent> p)

Cancels the first event from the future event queue that matches a given predicate and was sent by a given entity, then removes it from the queue.

Parameters:
  • src – Id of entity that scheduled the event
  • p – the event selection predicate
Returns:

the removed event or SimEvent.NULL if not found

cancelAll

boolean cancelAll(SimEntity src, Predicate<SimEvent> p)

Cancels all events from the future event queue that matches a given predicate and were sent by a given entity, then removes those ones from the queue.

Parameters:
  • src – Id of entity that scheduled the event
  • p – the event selection predicate
Returns:

true if at least one event has been cancelled; false otherwise

clock

double clock()

Gets the current simulation time in seconds.

See also: .isRunning()

clockInHours

double clockInHours()

Gets the current simulation time in hours.

See also: .isRunning()

clockInMinutes

double clockInMinutes()

Gets the current simulation time in minutes.

See also: .isRunning()

findFirstDeferred

SimEvent findFirstDeferred(SimEntity dest, Predicate<SimEvent> p)

Find first deferred event matching a predicate.

Parameters:
  • dest – Id of entity that the event has to be sent to
  • p – the event selection predicate
Returns:

the first matched event or SimEvent.NULL if not found

getCalendar

Calendar getCalendar()

Gets a new copy of initial simulation Calendar.

Returns:a new copy of Calendar object

getCloudInfoService

CloudInformationService getCloudInfoService()

Gets the CloudInformationService.

Returns:the Entity

getDatacenterList

Set<Datacenter> getDatacenterList()

Sends a request to Cloud Information Service (CIS) entity to get the list of all Cloud Datacenter IDs.

Returns:a List containing Datacenter IDs

getEntityList

List<SimEntity> getEntityList()

Returns a read-only list of entities created for the simulation.

getMinTimeBetweenEvents

double getMinTimeBetweenEvents()

Returns the minimum time between events (in seconds). Events within shorter periods after the last event are discarded.

Returns:the minimum time between events (in seconds).

getNetworkTopology

NetworkTopology getNetworkTopology()

Gets the network topology used for Network simulations.

getNumEntities

int getNumEntities()

Get the current number of entities in the simulation.

Returns:The number of entities

getNumberOfFutureEvents

long getNumberOfFutureEvents(Predicate<SimEvent> predicate)

Gets the number of events in the future queue which match a given predicate.

Parameters:
  • predicate – the predicate to filter the list of future events.
Returns:

the number of future events which match the predicate

holdEntity

void holdEntity(SimEntity src, long delay)

Holds an entity for some time.

Parameters:
  • src – id of entity to be held
  • delay – How many seconds after the current time the entity has to be held

isPaused

boolean isPaused()

Checks if the simulation is paused.

isRunning

boolean isRunning()

Check if the simulation is still running. Even if the simulation is paused, the method returns true to indicate that the simulation is in fact active yet.

This method should be used by entities to check if they should continue executing.

isTerminationTimeSet

boolean isTerminationTimeSet()

isTimeToTerminateSimulationUnderRequest

boolean isTimeToTerminateSimulationUnderRequest()

pause

boolean pause()

Requests the simulation to be paused as soon as possible.

Returns:true if the simulation was paused, false if it was already paused or has finished

pause

boolean pause(double time)

Requests the simulation to be paused at a given time. The method schedules the pause request and then returns immediately.

Parameters:
  • time – the time at which the simulation has to be paused
Returns:

true if pause request was successfully received (the given time is greater than or equal to the current simulation time), false otherwise.

pauseEntity

void pauseEntity(SimEntity src, double delay)

Pauses an entity for some time.

Parameters:
  • src – id of entity to be paused
  • delay – the time period for which the entity will be inactive

removeOnClockTickListener

boolean removeOnClockTickListener(EventListener<? extends EventInfo> listener)

Removes a listener from the onClockTickListener List.

Parameters:
  • listener – the listener to remove
Returns:

true if the listener was found and removed, false otherwise

removeOnEventProcessingListener

boolean removeOnEventProcessingListener(EventListener<SimEvent> listener)

Removes a listener from the onEventProcessingListener List.

Parameters:
  • listener – the listener to remove
Returns:

true if the listener was found and removed, false otherwise

removeOnSimulationPauseListener

boolean removeOnSimulationPauseListener(EventListener<EventInfo> listener)

Removes a listener from the onSimulationPausedListener List.

Parameters:
  • listener – the listener to remove
Returns:

true if the listener was found and removed, false otherwise

resume

boolean resume()

This method is called if one wants to resume the simulation that has previously been paused.

Returns:true if the simulation has been restarted or false if it wasn’t paused.

select

SimEvent select(SimEntity dest, Predicate<SimEvent> p)

Selects the first deferred event that matches a given predicate and removes it from the queue.

Parameters:
  • dest – entity that the event has to be sent to
  • p – the event selection predicate
Returns:

the removed event or SimEvent.NULL if not found

send

void send(SimEvent evt)

Sends an event where all data required is defined inside the event instance.

Parameters:
  • evt – the event to send

send

void send(SimEntity src, SimEntity dest, double delay, int tag, Object data)

Sends an event from one entity to another.

Parameters:
  • src – entity that scheduled the event
  • dest – entity that the event will be sent to
  • delay – How many seconds after the current simulation time the event should be sent
  • tag – the tag that classifies the event
  • data – the data to be sent inside the event

sendFirst

void sendFirst(SimEvent evt)

Sends an event where all data required is defined inside the event instance, adding it to the beginning of the queue in order to give priority to it.

Parameters:
  • evt – the event to send

sendFirst

void sendFirst(SimEntity src, SimEntity dest, double delay, int tag, Object data)

Sends an event from one entity to another, adding it to the beginning of the queue in order to give priority to it.

Parameters:
  • src – entity that scheduled the event
  • dest – entity that the event will be sent to
  • delay – How many seconds after the current simulation time the event should be sent
  • tag – the tag that classifies the event
  • data – the data to be sent inside the event

sendNow

void sendNow(SimEntity src, SimEntity dest, int tag, Object data)

Sends an event from one entity to another without delaying the message.

Parameters:
  • src – entity that scheduled the event
  • dest – entity that the event will be sent to
  • tag – the tag that classifies the event
  • data – the data to be sent inside the event

setIdForEntitiesWithoutOne

static <T extends ChangeableId> boolean setIdForEntitiesWithoutOne(List<? extends T> list)

Defines IDs for a list of ChangeableId entities that don’t have one already assigned. Such entities can be a Cloudlet, Vm or any object that implements ChangeableId.

Parameters:
  • <T> – the type of entities to define an ID
  • list – list of objects to define an ID
Returns:

true if the List has any Entity, false if it’s empty

setIdForEntitiesWithoutOne

static <T extends ChangeableId> boolean setIdForEntitiesWithoutOne(List<? extends T> list, T lastEntity)

Defines IDs for a list of ChangeableId entities that don’t have one already assigned. Such entities can be a Cloudlet, Vm or any object that implements ChangeableId.

Parameters:
  • <T> – the type of entities to define an ID
  • list – list of objects to define an ID
  • lastEntity – the last created Entity which its ID will be used as the base for the next IDs
Returns:

true if the List has any Entity, false if it’s empty

setNetworkTopology

void setNetworkTopology(NetworkTopology networkTopology)

Sets the network topology used for Network simulations.

Parameters:
  • networkTopology – the network topology to set

start

double start()

Starts simulation execution and waits for all entities to finish, i.e. until all entities threads reach non-RUNNABLE state or there are no more events in the future event queue.

Note: This method should be called just after all the entities have been setup and added. The method blocks until the simulation is ended.

Throws:
  • UnsupportedOperationException – When the simulation has already run once. If you paused the simulation and wants to resume it, you must use resume() instead of calling the current method.
Returns:

the last clock time

terminate

boolean terminate()

Forces the termination of the simulation before it ends.

Returns:true if the simulation was running and the termination request was accepted, false if the simulation was not started yet

terminateAt

boolean terminateAt(double time)

Schedules the termination of the simulation for a given time (in seconds).

If a termination time is set, the simulation stays running even if there is no event to process. It keeps waiting for new dynamic events, such as the creation of Cloudlets and VMs at runtime. If no event happens, the clock is increased to simulate time passing. The clock increment is defined according to: (i) the lower Datacenter.getSchedulingInterval() between existing Datacenters; or (ii) getMinTimeBetweenEvents() in case no Datacenter has its schedulingInterval set.

Parameters:
  • time – the time at which the simulation has to be terminated (in seconds)
Returns:

true if the time given is greater than the current simulation time, false otherwise

wait

void wait(CloudSimEntity src, Predicate<SimEvent> p)

Sets the state of an entity to SimEntity.State.WAITING, making it to wait for events that satisfy a given predicate. Only such events will be passed to the entity. This is done to avoid unnecessary context Datacenter.

Parameters:
  • src – entity that scheduled the event
  • p – the event selection predicate

waiting

long waiting(SimEntity dest, Predicate<SimEvent> p)

Gets the number of events in the deferred event queue that are targeted to a given entity and match a given predicate.

Parameters:
  • dest – Id of entity that the event has to be sent to
  • p – the event selection predicate