|
GridSim 5.0 beta | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object Thread Sim_entity GridSimCore
public class GridSimCore
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:
send(int, double, int, Object)
,
send(int, double, int)
, send(String,double,int)
,
or send(String, double, int, Object)
method.
These methods will send an event directly to the destination entity
without using I/O port. Regardless how big the size of the
Object data is,
event arrival time = current simulation time + delay time
For example: send(destID, delay, tag, obj).
On the destinated entity, by creating a Sim_event object:
send(Sim_port, double, int, Object)
or
send(Sim_port, double, int)
method.
These methods will send an event to the destination entity with I/O port. The size of the Object data sent is taken into a consideration for determining the event arrival time.
For example: send(ouputPort, delay, tag, obj) where
obj MUST be of type IO_data.
On the destinated entity, by creating a Sim_event object:
Output.body()
method.
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:
Link
and Router
.
GridSim
or
GridSimCore
. GridResource
class is not effected as it
already has the below code.
... // other code
public void body() {
Sim_event ev = new Sim_event();
while (Sim_system.running()) {
super.sim_get_next(ev);
// Entity's behaviour for handling ping request
if (ev.get_tag() == GridSimTags.INFOPKT_SUBMIT) {
processPingRequest(ev);
continue; // skip the rest
}
... // other code for handling other incoming requests
}
}
private void processPingRequest(Sim_event ev) {
InfoPacket pkt = (InfoPacket) ev.get_data();
pkt.setTag(GridSimTags.INFOPKT_RETURN);
pkt.setDestID( pkt.getSrcID() );
// sends back to the sender
super.send(super.output, GridSimTags.SCHEDULE_NOW,
GridSimTags.INFOPKT_RETURN,
new IO_data(pkt,pkt.getSize(),pkt.getSrcID()) );
}
Sim_entity
,
Output
,
Input
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 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 |
---|
protected Sim_port input
protected Sim_port output
protected static int NETWORK_TYPE
GridSim.initNetworkType(int)
method before the
simulation starts.
GridSim.initNetworkType(int)
,
GridSimTags.NET_PACKET_LEVEL
,
GridSimTags.NET_FLOW_LEVEL
,
GridSimTags.NET_BUFFER_PACKET_LEVEL
Constructor Detail |
---|
protected GridSimCore(String name) throws Exception
name
- the name to be associated with this entity (as
required by Sim_entity class from simjava package)
Exception
- This happens when creating this entity before
initializing GridSim package or this entity name is
null or emptyGridSim.init(int, Calendar, boolean, String[], String[],
String)
,
Sim_entity
protected GridSimCore(String name, double baudRate) throws Exception
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.
name
- the name to be associated with this entity (as
required by Sim_entity class from simjava package)baudRate
- network communication or bandwidth speed
Exception
- This happens when creating this entity before
initializing GridSim package or this entity name is
null or emptyGridSim.init(int, Calendar, boolean, String[], String[],
String)
,
Sim_entity
,
Input
,
Output
protected GridSimCore(String name, Link link) throws Exception
You need to manually create the network topology, i.e. connecting this entity to a router/other entity.
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.
Exception
- This happens when creating this entity before
initializing GridSim package or this entity name is
null or emptyGridSim.init(int, Calendar, boolean, String[], String[],
String)
,
Sim_entity
,
Input
,
Output
Method Detail |
---|
public Link getLink()
public boolean setBackgroundTraffic(TrafficGenerator gen)
When simulation starts, the Output entity will automatically sends junk packets to resource entities.
gen
- a background traffic generator
public boolean setBackgroundTraffic(TrafficGenerator gen, Collection userName)
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.
gen
- a background traffic generatoruserName
- a collection of user entity name (in String object).
protected boolean ping(int entityID, int 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.
entityID
- the destination entity IDsize
- the ping packet size
protected boolean ping(String entityName, int 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.
entityName
- the destination entity namesize
- the ping packet size
protected boolean ping(String entityName, int size, double delay, int netServiceLevel)
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.
entityName
- the destination entity namesize
- the ping packet sizedelay
- the delay time for submitting this ping requestnetServiceLevel
- level of service for ping packet (only
applicable to certain PacketScheduler, such as
SCFQScheduler
.
protected boolean ping(int entityID, int size, double delay, int netServiceLevel)
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.
entityID
- the destination entity IDsize
- the ping packet sizedelay
- the delay time for submitting this ping requestnetServiceLevel
- level of service for ping packet (only
applicable to certain PacketScheduler, such as
SCFQScheduler
.
protected InfoPacket pingBlockingCall(int entityID, int size, double delay, int netServiceLevel)
This method is a blocking call, meaning it will keep waiting until it gets the ping result back.
entityID
- the destination entity IDsize
- the ping packet sizedelay
- the delay time for submitting this ping requestnetServiceLevel
- level of service for ping packet (only
applicable to certain PacketScheduler, such as
SCFQScheduler
.
protected InfoPacket pingBlockingCall(int entityID, int size)
This method is a blocking call, meaning it will keep waiting until it gets the ping result back.
entityID
- the destination entity IDsize
- the ping packet size
protected InfoPacket pingBlockingCall(String entityName, int size)
This method is a blocking call, meaning it will keep waiting until it gets the ping result back.
entityName
- the destination entity namesize
- the ping packet size
protected InfoPacket pingBlockingCall(String entityName, int size, double delay, int netServiceLevel)
This method is a blocking call, meaning it will keep waiting until it gets the ping result back.
entityName
- the destination entity namesize
- the ping packet sizedelay
- the delay time for submitting this ping requestnetServiceLevel
- level of service for ping packet (only
applicable to certain PacketScheduler, such as
SCFQScheduler
.
protected InfoPacket getPingResult()
protected void terminateIOEntities()
GridSim.GridSim(String, double)
protected void finalizeGridSimulation()
terminateIOEntities()
protected boolean isNetworked()
protected void send(String entityName, double delay, int gridSimTag)
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
entityName
- the name of the destination entitydelay
- 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.0gridSimTag
- an user-defined number representing the type of
an event/messageprotected void send(String entityName, double delay, int gridSimTag, Object data)
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
entityName
- the name of the destination entitydelay
- 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.0gridSimTag
- an user-defined number representing the type of
an event/messagedata
- A reference to data to be sent with the eventprotected void send(int entityID, double delay, int gridSimTag)
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
entityID
- the id number of the destination entitydelay
- 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.0gridSimTag
- an user-defined number representing the type of
an event/messageprotected void send(int entityID, double delay, int gridSimTag, Object data)
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
entityID
- the id number of the destination entitydelay
- 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.0gridSimTag
- an user-defined number representing the type of
an event/messagedata
- A reference to data to be sent with the eventprotected void send(Sim_port destPort, double delay, int gridSimTag)
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
destPort
- A reference to the port to send the event out ofdelay
- 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.0gridSimTag
- an user-defined number representing the type of
an event/messageprotected void send(Sim_port destPort, double delay, int gridSimTag, Object data)
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
destPort
- A reference to the port to send the event out ofdelay
- 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.0gridSimTag
- an user-defined number representing the type of
an event/messagedata
- an object of type IO_dataIO_data
|
GridSim 5.0 beta | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |