GridSim 5.0 beta

gridsim
Class GridSimCore

Object
  extended by Thread
      extended by Sim_entity
          extended by GridSimCore
All Implemented Interfaces:
Cloneable, Runnable
Direct Known Subclasses:
AbstractGIS, AbstractRC, GridInformationService, GridResource, GridResourceWithFailure, GridSim, GridSimShutdown

public class GridSimCore
extends Sim_entity

Since GridSim version 3.0, this is the overall class of GridSim package, that must be extended by other GridSim entities. It inherits event management and threaded entity features from the Sim_entity class. This class adds networking and event delivery features, which allow synchronous or asynchronous communication for service access or delivery.

All classes that extend this class can implement a method called Sim_entity.body(), which is automatically invoked when a simulation runs, since it is expected to be responsible for simulating entity behavior. In addition, Sim_entity.body() method is the place to receive incoming events.

The entities that extend this class can be instantiated with or without networked I/O ports. A networked GridSim entity gains communication capability via the objects of GridSim's I/O entity classes, Input and Output classes. Each I/O entity will have a unique name assuming each GridSim entity that the user creates has a unique name. For example, a resource entity with the name Resource2, will have an input entity whose name is prefixed with Input_, making the input entity's full name Input_Resource2, which is expected to be unique. Input_Resource2 entity handles all incoming events. A resource has an output entity whose name is prefixed with Output_, e.g. Output_Resource2. Output_Resource2 entity handles all outgoing events.

The I/O entities are concurrent entities, but they are visible within the GridSim entity and are able to communicate with other GridSim entities by sending messages.

There are two ways to send a message or object to an entity, i.e. with or without I/O port. Below shows the differences:

Since GridSim 3.1, a network extension has been incorporated into this simulation infrastructure. To make use of this, you need to create a resource entity only using GridSimCore(String, Link) constructors. Then you need to attach this entity into the overall network topology, i.e. connecting this entity to a router, etc. See the examples provided in the package for more details.

Another important feature of a network extension is the ability to ping to a particular entity by using ping(int, int) or pingBlockingCall(int, int) overloading methods.

However, there are few conditions to be met:

Since:
GridSim Toolkit 3.0
Author:
Anthony Sulistio
See Also:
Sim_entity, Output, Input
Invariant:
$none

Nested Class Summary
 
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  Sim_port input
          Reading data received via input port
protected static int NETWORK_TYPE
          Specifies which type of network to be used.
protected  Sim_port output
          Sending data via output port to external entities
 
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected GridSimCore(String name)
          Allocates a new GridSim object without NETWORK communication channels: "input" and "output" Sim_port.
protected GridSimCore(String name, double baudRate)
          Allocates a new GridSim object with NETWORK communication channels: "input" and "output" Sim_port.
protected GridSimCore(String name, Link link)
          Allocates a new GridSim object with NETWORK communication channels: "input" and "output" Sim_port.
 
Method Summary
protected  void finalizeGridSimulation()
          It terminates the entities of this object that manage NETWORK communication channels
 Link getLink()
          Returns the Link that connects this entity to other entities if Network Extensions are being used.
protected  InfoPacket getPingResult()
          Gets the first available ping result in the event queue.
protected  boolean isNetworked()
          Check type of entity
protected  boolean ping(int entityID, int size)
          Pings to a particular entity ID with a given packet size.
protected  boolean ping(int entityID, int size, double delay, int netServiceLevel)
          Pings to a particular entity ID with a given packet size.
protected  boolean ping(String entityName, int size)
          Pings to a particular entity ID with a given packet size.
protected  boolean ping(String entityName, int size, double delay, int netServiceLevel)
          Pings to a particular entity ID with a given packet size.
protected  InfoPacket pingBlockingCall(int entityID, int size)
          Pings to a particular entity ID with a given packet size.
protected  InfoPacket pingBlockingCall(int entityID, int size, double delay, int netServiceLevel)
          Pings to a particular entity ID with a given packet size.
protected  InfoPacket pingBlockingCall(String entityName, int size)
          Pings to a particular entity ID with a given packet size.
protected  InfoPacket pingBlockingCall(String entityName, int size, double delay, int netServiceLevel)
          Pings to a particular entity ID with a given packet size.
protected  void send(int entityID, double delay, int gridSimTag)
          Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.
protected  void send(int entityID, double delay, int gridSimTag, Object data)
          Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.
protected  void send(Sim_port destPort, double delay, int gridSimTag)
          Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.
protected  void send(Sim_port destPort, double delay, int gridSimTag, Object data)
          Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.
protected  void send(String entityName, double delay, int gridSimTag)
          Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.
protected  void send(String entityName, double delay, int gridSimTag, Object data)
          Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.
 boolean setBackgroundTraffic(TrafficGenerator gen)
          Sets the background traffic generator for this entity.
 boolean setBackgroundTraffic(TrafficGenerator gen, Collection userName)
          Sets the background traffic generator for this entity.
protected  void terminateIOEntities()
          It terminates Entities managing NETWORK communication channels.
 
Methods inherited from class Sim_entity
add_generator, add_param, add_port, body, clone, get_id, get_name, get_port, get_port, get_stat, run, send_on, set_invisible, set_stat, sim_cancel, sim_completed, sim_current, sim_get_next, sim_get_next, sim_hold_for, sim_hold, sim_pause_for, sim_pause_for, sim_pause_until, sim_pause_until, sim_pause, sim_process_for, sim_process_for, sim_process_until, sim_process_until, sim_process, sim_putback, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_select, sim_trace, sim_wait_for, sim_wait_for, sim_wait_for, sim_wait, sim_waiting, sim_waiting
 
Methods inherited from class Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

input

protected Sim_port input
Reading data received via input port


output

protected Sim_port output
Sending data via output port to external entities


NETWORK_TYPE

protected static int NETWORK_TYPE
Specifies which type of network to be used. By default, the simulation uses the gridsim.net package or differentiated network service. To change this default property, please use the GridSim.initNetworkType(int) method before the simulation starts.

See Also:
GridSim.initNetworkType(int), GridSimTags.NET_PACKET_LEVEL, GridSimTags.NET_FLOW_LEVEL, GridSimTags.NET_BUFFER_PACKET_LEVEL
Constructor Detail

GridSimCore

protected GridSimCore(String name)
               throws Exception
Allocates a new GridSim object without NETWORK communication channels: "input" and "output" Sim_port. In summary, this object has NO network communication or bandwidth speed.

Parameters:
name - the name to be associated with this entity (as required by Sim_entity class from simjava package)
Throws:
Exception - This happens when creating this entity before initializing GridSim package or this entity name is null or empty
See Also:
GridSim.init(int, Calendar, boolean, String[], String[], String), Sim_entity
Pre Condition:
name != null
Post Condition:
$none

GridSimCore

protected GridSimCore(String name,
                      double baudRate)
               throws Exception
Allocates a new GridSim object with NETWORK communication channels: "input" and "output" Sim_port. In addition, this method will create Input and Output object.

However, this is the old approach using one-to-all connection where you can not specify a network topology and there is no wired link from this entity to others. Use GridSimCore(String, Link) instead.

Parameters:
name - the name to be associated with this entity (as required by Sim_entity class from simjava package)
baudRate - network communication or bandwidth speed
Throws:
Exception - This happens when creating this entity before initializing GridSim package or this entity name is null or empty
See Also:
GridSim.init(int, Calendar, boolean, String[], String[], String), Sim_entity, Input, Output
Pre Condition:
name != null, baudRate > 0.0
Post Condition:
$none

GridSimCore

protected GridSimCore(String name,
                      Link link)
               throws Exception
Allocates a new GridSim object with NETWORK communication channels: "input" and "output" Sim_port. In addition, this method will create Input and Output object.

You need to manually create the network topology, i.e. connecting this entity to a router/other entity.

Parameters:
name - the name to be associated with this entity (as required by Sim_entity class from simjava package)
link - the link that this GridSim entity will use to communicate with other GridSim or Network entities.
Throws:
Exception - This happens when creating this entity before initializing GridSim package or this entity name is null or empty
See Also:
GridSim.init(int, Calendar, boolean, String[], String[], String), Sim_entity, Input, Output
Pre Condition:
name != null, link != null
Post Condition:
$none
Method Detail

getLink

public Link getLink()
Returns the Link that connects this entity to other entities if Network Extensions are being used.

Returns:
a Link object
Pre Condition:
$none
Post Condition:
$none

setBackgroundTraffic

public boolean setBackgroundTraffic(TrafficGenerator gen)
Sets the background traffic generator for this entity.

When simulation starts, the Output entity will automatically sends junk packets to resource entities.

Parameters:
gen - a background traffic generator
Returns:
true if successful, false otherwise
Pre Condition:
gen != null
Post Condition:
$none

setBackgroundTraffic

public boolean setBackgroundTraffic(TrafficGenerator gen,
                                    Collection userName)
Sets the background traffic generator for this entity.

When simulation starts, the Output entity will automatically sends junk packets to resource entities and other entities.
NOTE: Sending background traffic to itself is not supported.

Parameters:
gen - a background traffic generator
userName - a collection of user entity name (in String object).
Returns:
true if successful, false otherwise
Pre Condition:
gen != null, userName != null
Post Condition:
$none

ping

protected boolean ping(int entityID,
                       int size)
Pings to a particular entity ID with a given packet size.

This method is a non-blocking call, meaning you need to get the ping result by calling getPingResult(). The return value of this method is just an indication whether ping() has successfully sent or not.

Parameters:
entityID - the destination entity ID
size - the ping packet size
Returns:
true if successful, false otherwise
Pre Condition:
entityID > 0, size >= 0
Post Condition:
$none

ping

protected boolean ping(String entityName,
                       int size)
Pings to a particular entity ID with a given packet size.

This method is a non-blocking call, meaning you need to get the ping result by calling getPingResult(). The return value of this method is just an indication whether ping() has successfully sent or not.

Parameters:
entityName - the destination entity name
size - the ping packet size
Returns:
true if successful, false otherwise
Pre Condition:
entityName != null, size >= 0
Post Condition:
$none

ping

protected boolean ping(String entityName,
                       int size,
                       double delay,
                       int netServiceLevel)
Pings to a particular entity ID with a given packet size.

This method is a non-blocking call, meaning you need to get the ping result by calling getPingResult(). The return value of this method is just an indication whether ping() has successfully sent or not.

Parameters:
entityName - the destination entity name
size - the ping packet size
delay - the delay time for submitting this ping request
netServiceLevel - level of service for ping packet (only applicable to certain PacketScheduler, such as SCFQScheduler.
Returns:
true if successful, false otherwise
Pre Condition:
entityName != null, size >= 0, delay >= 0, netServiceLevel >= 0
Post Condition:
$none

ping

protected boolean ping(int entityID,
                       int size,
                       double delay,
                       int netServiceLevel)
Pings to a particular entity ID with a given packet size.

This method is a non-blocking call, meaning you need to get the ping result by calling getPingResult(). The return value of this method is just an indication whether ping() has successfully sent or not.

Parameters:
entityID - the destination entity ID
size - the ping packet size
delay - the delay time for submitting this ping request
netServiceLevel - level of service for ping packet (only applicable to certain PacketScheduler, such as SCFQScheduler.
Returns:
true if successful, false otherwise
Pre Condition:
entityID > 0, size >= 0, delay >= 0, netServiceLevel >= 0
Post Condition:
$none

pingBlockingCall

protected InfoPacket pingBlockingCall(int entityID,
                                      int size,
                                      double delay,
                                      int netServiceLevel)
Pings to a particular entity ID with a given packet size.

This method is a blocking call, meaning it will keep waiting until it gets the ping result back.

Parameters:
entityID - the destination entity ID
size - the ping packet size
delay - the delay time for submitting this ping request
netServiceLevel - level of service for ping packet (only applicable to certain PacketScheduler, such as SCFQScheduler.
Returns:
a ping result in InfoPacket object or null if unexpected error happens.
Pre Condition:
entityID > 0, size >= 0, delay >= 0, netServiceLevel >= 0
Post Condition:
$none

pingBlockingCall

protected InfoPacket pingBlockingCall(int entityID,
                                      int size)
Pings to a particular entity ID with a given packet size.

This method is a blocking call, meaning it will keep waiting until it gets the ping result back.

Parameters:
entityID - the destination entity ID
size - the ping packet size
Returns:
a ping result in InfoPacket object or null if unexpected error happens.
Pre Condition:
entityID > 0, size >= 0
Post Condition:
$none

pingBlockingCall

protected InfoPacket pingBlockingCall(String entityName,
                                      int size)
Pings to a particular entity ID with a given packet size.

This method is a blocking call, meaning it will keep waiting until it gets the ping result back.

Parameters:
entityName - the destination entity name
size - the ping packet size
Returns:
a ping result in InfoPacket object or null if unexpected error happens.
Pre Condition:
entityName != null, size >= 0
Post Condition:
$none

pingBlockingCall

protected InfoPacket pingBlockingCall(String entityName,
                                      int size,
                                      double delay,
                                      int netServiceLevel)
Pings to a particular entity ID with a given packet size.

This method is a blocking call, meaning it will keep waiting until it gets the ping result back.

Parameters:
entityName - the destination entity name
size - the ping packet size
delay - the delay time for submitting this ping request
netServiceLevel - level of service for ping packet (only applicable to certain PacketScheduler, such as SCFQScheduler.
Returns:
a ping result in InfoPacket object or null if unexpected error happens.
Pre Condition:
entityName != null, size >= 0, delay >= 0, netServiceLevel >= 0
Post Condition:
$none

getPingResult

protected InfoPacket getPingResult()
Gets the first available ping result in the event queue.

Returns:
a ping result in InfoPacket object or null if unexpected error happens.
Pre Condition:
$none
Post Condition:
$none

terminateIOEntities

protected void terminateIOEntities()
It terminates Entities managing NETWORK communication channels. It can be invoked explicity to shutdown NETWORK communication channels. It is advisable for all entities extending GridSim class, explicitly invoke this method to terminate Input and Output entities created by the constructor: GridSim.GridSim(String, double)

Pre Condition:
$none
Post Condition:
$none

finalizeGridSimulation

protected void finalizeGridSimulation()
It terminates the entities of this object that manage NETWORK communication channels

See Also:
terminateIOEntities()
Pre Condition:
$none
Post Condition:
$none

isNetworked

protected boolean isNetworked()
Check type of entity

Returns:
true if entity has NETWORK communication channel, otherwise it returns false
Pre Condition:
$none
Post Condition:
$result == true || false

send

protected void send(String entityName,
                    double delay,
                    int gridSimTag)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.

It is recommended to use send() method with an output port if the network bandwidth plays an important role in this simulation. However, the entity must have the network entities, i.e. Input and Output port (specified during the creation of the entity by giving a baud rate or bandwidth speed). Below is an example on how to do:

... // other code
// object is the entity or message you want to send
// size is the object size in bytes (rough estimation)
// destination id is the entity ID you want to send the object to
IO_data data = new IO_data(object, size, destinationID);


// If this entity extends from GridSim class, then you should use it
// otherwise need to create a new Sim_port object
Sim_port port = super.output;

// delay is the simulation time delay
// tag is the event type (user-defined or choose one from GridSimTags class)
send(port, delay, tag, data);
... // remaining other code

Parameters:
entityName - the name of the destination entity
delay - how long from the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0.0
gridSimTag - an user-defined number representing the type of an event/message
Pre Condition:
entityName != null, delay >= 0.0
Post Condition:
$none

send

protected void send(String entityName,
                    double delay,
                    int gridSimTag,
                    Object data)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.

It is recommended to use send() method with an output port if the network bandwidth plays an important role in this simulation. However, the entity must have the network entities, i.e. Input and Output port (specified during the creation of the entity by giving a baud rate or bandwidth speed). Below is an example on how to do:

... // other code
// object is the entity or message you want to send
// size is the object size in bytes (rough estimation)
// destination id is the entity ID you want to send the object to
IO_data data = new IO_data(object, size, destinationID);


// If this entity extends from GridSim class, then you should use it
// otherwise need to create a new Sim_port object
Sim_port port = super.output;

// delay is the simulation time delay
// tag is the event type (user-defined or choose one from GridSimTags class)
send(port, delay, tag, data);
... // remaining other code

Parameters:
entityName - the name of the destination entity
delay - how long from the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0.0
gridSimTag - an user-defined number representing the type of an event/message
data - A reference to data to be sent with the event
Pre Condition:
entityName != null, delay >= 0.0, data != null
Post Condition:
$none

send

protected void send(int entityID,
                    double delay,
                    int gridSimTag)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.

It is recommended to use send() method with an output port if the network bandwidth plays an important role in this simulation. However, the entity must have the network entities, i.e. Input and Output port (specified during the creation of the entity by giving a baud rate or bandwidth speed). Below is an example on how to do:

... // other code
// object is the entity or message you want to send
// size is the object size in bytes (rough estimation)
// destination id is the entity ID you want to send the object to
IO_data data = new IO_data(object, size, destinationID);


// If this entity extends from GridSim class, then you should use it
// otherwise need to create a new Sim_port object
Sim_port port = super.output;

// delay is the simulation time delay
// tag is the event type (user-defined or choose one from GridSimTags class)
send(port, delay, tag, data);
... // remaining other code

Parameters:
entityID - the id number of the destination entity
delay - how long from the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0.0
gridSimTag - an user-defined number representing the type of an event/message
Pre Condition:
entityID > 0, delay >= 0.0
Post Condition:
$none

send

protected void send(int entityID,
                    double delay,
                    int gridSimTag,
                    Object data)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.

It is recommended to use send() method with an output port if the network bandwidth plays an important role in this simulation. However, the entity must have the network entities, i.e. Input and Output port (specified during the creation of the entity by giving a baud rate or bandwidth speed). Below is an example on how to do:

... // other code
// object is the entity or message you want to send
// size is the object size in bytes (rough estimation)
// destination id is the entity ID you want to send the object to
IO_data data = new IO_data(object, size, destinationID);


// If this entity extends from GridSim class, then you should use it
// otherwise need to create a new Sim_port object
Sim_port port = super.output;

// delay is the simulation time delay
// tag is the event type (user-defined or choose one from GridSimTags class)
send(port, delay, tag, data);
... // remaining other code

Parameters:
entityID - the id number of the destination entity
delay - how long from the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0.0
gridSimTag - an user-defined number representing the type of an event/message
data - A reference to data to be sent with the event
Pre Condition:
entityID > 0, delay >= 0.0, data != null
Post Condition:
$none

send

protected void send(Sim_port destPort,
                    double delay,
                    int gridSimTag)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.

It is recommended to use send() method with an output port if the network bandwidth plays an important role in this simulation. However, the entity must have the network entities, i.e. Input and Output port (specified during the creation of the entity by giving a baud rate or bandwidth speed). Below is an example on how to do:

... // other code
// object is the entity or message you want to send
// size is the object size in bytes (rough estimation)
// destination id is the entity ID you want to send the object to
IO_data data = new IO_data(object, size, destinationID);


// If this entity extends from GridSim class, then you should use it
// otherwise need to create a new Sim_port object
Sim_port port = super.output;

// delay is the simulation time delay
// tag is the event type (user-defined or choose one from GridSimTags class)
send(port, delay, tag, data);
... // remaining other code

Parameters:
destPort - A reference to the port to send the event out of
delay - how long from the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0.0
gridSimTag - an user-defined number representing the type of an event/message
Pre Condition:
destPort != null, delay >= 0.0
Post Condition:
$none

send

protected void send(Sim_port destPort,
                    double delay,
                    int gridSimTag,
                    Object data)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.

It is recommended to use send() method with an output port if the network bandwidth plays an important role in this simulation. However, the entity must have the network entities, i.e. Input and Output port (specified during the creation of the entity by giving a baud rate or bandwidth speed). Below is an example on how to do:

... // other code
// object is the entity or message you want to send
// size is the object size in bytes (rough estimation)
// destination id is the entity ID you want to send the object to
IO_data data = new IO_data(object, size, destinationID);


// If this entity extends from GridSim class, then you should use it
// otherwise need to create a new Sim_port object
Sim_port port = super.output;

// delay is the simulation time delay
// tag is the event type (user-defined or choose one from GridSimTags class)
send(port, delay, tag, data);
... // remaining other code

Parameters:
destPort - A reference to the port to send the event out of
delay - how long from the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0.0
gridSimTag - an user-defined number representing the type of an event/message
data - an object of type IO_data
See Also:
IO_data
Pre Condition:
destPort != null, delay >= 0.0, data != null
Post Condition:
$none

GridSim 5.0 beta

The University of Melbourne, Australia, 2009