|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbcds.phison.sim.SimCore<V,E>
public class SimCore<V,E>
Implements a minimal core of a discrete-event simulator targeted at path-oriented networks. Essentially, it keeps the (simulated) time, handles the event list, and activates processing modules and callback funcions. The simulated time is an integer (Java's int type).
Complementary information such as topology,
link capacities, and random number generator, is kept in a separate
structure of type SimGlobals
which provides an execution context,
mainly for the benefit of processing modules.
This context, whose instance is received from the caller, contains
both private and shared data. Examples of private data are
the topology object and the modules list, while the statistical collector
is a shared object. The restriction observed on a a shared resource,
is that the resource itself and its fields are never reassigned.
This class expects only one non-null object in the context
instance, namely,
the list of processing modules (field pmreg), of type
PmRegistry
.
Additionally, a reference to a global
"options" structure (of type SimParams
) is also kept and
passed on to processing modules. This structure is treated as
containing read-only (that is, input only) data.
The event list contains future events. It is organized as a priority
queue, sorted by simulated
time. The event to be removed next is the one closest in time to the
previous event (or the first one, when the simulation starts). Every time
an event is removed from the event queue, the method
processEventOnCurrentTime(EventEntry)
is called, with the removed event entry as parameter. The entry consists
of the event type and an arbitrary event parameter that varies according to
the event type.
Notes:
Nested Class Summary | |
---|---|
class |
SimCore.EventEntry
The class EventEntry combines in a single structure an event type and an event parameter. |
Constructor Summary | |
---|---|
SimCore(SimGlobals<V,E> context,
SimParams opt)
Creates a new instance. |
Method Summary | |
---|---|
void |
advanceTime(int new_time)
Extracts and processes all events previous to new_time and
sets the simulation time to the new time. |
void |
callProcessingModules(SimEvents ev,
ConnectionInfo<V,E> request)
Iterates over the processing modules list and calls each module's run method with ev and request as
parameters. |
SimGlobals<V,E> |
ctx()
Returns the context associated to this simulator. |
void |
enqueueCall(int clock,
NullaryProc procedure)
Inserts an event that will provoke that the procedure 's
NullaryProc.run() method be called at time clock . |
void |
enqueueEvent(SimEvents ev,
ConnectionInfo<V,E> rq)
Enqueues a future event whose time is taken from rq.clock . |
ConnRequestErrorCode |
getLastBlockingReason()
Returns the reason why the last connection request has failed. |
long |
getSimStartTime()
Returns the computer's time in milliseconds recorded when start() was called, or 0 if the simulation has not
started. |
long |
getSimStopTime()
Returns the computer's time in milliseconds recorded when stop() was called, or 0 if the simulation has not stopped. |
int |
getTime()
Returns the current (simulated) time. |
SimParams |
opt()
Returns the options associated to this simulator. |
void |
processEnqueuedEventsPreviousTo(int time_limit)
Extracts all the events whose time are less than time_limit . |
void |
setLastBlockingReason(ConnRequestErrorCode ec)
Sets the reason why a given connection is rejected. |
void |
shutdownProcessingModules()
Iterates over the processing modules list and calls each module's shutdown method. |
void |
start()
Starts the simulation by calling advancingTime(0). |
void |
stop()
Stops the simulation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimCore(SimGlobals<V,E> context, SimParams opt)
context
and opt
are saved so that they can be passed on to processing modules.
The current time is set to -1, which will be the time seen by
processing modules at setup time. The event queue is created
empty.
Method Detail |
---|
public void start()
java.lang.RuntimeException
- if it is called more than once.public void stop()
processEnqueuedEventsPreviousTo(int)
to process all pending events
up to the maximum time set for the simulation and then records
the simulation stop time that can later be retrived by calling
getSimStopTime()
.
public ConnRequestErrorCode getLastBlockingReason()
public void setLastBlockingReason(ConnRequestErrorCode ec)
public void enqueueEvent(SimEvents ev, ConnectionInfo<V,E> rq)
rq.clock
. This time must
not be in the past, that is, its value must be larger than
getTime()
. The parameter rq
is not necessarily
a connection information object; instead, it is a convenient
container for items that are typically needed when processing
an event. Each call to this method should receive a new instance
in rq
; failing to do so means that information might
be overwritten in undesirable ways. Also, the caller is responsible
for any subsequent alteration of the object attributes.
When the event is extracted from the event list, it is passed to the processing modules.
If more than one event is inserted with the same time (clock), they
are enqueued in the order of their arrival.
See enqueueCall(int, NullaryProc)
for more details and
limitations.
If the requested insertion time is beyond the maximum simulation time, the request is silently ignored.
java.lang.IllegalArgumentException
- if the event time is in the past.public void enqueueCall(int clock, NullaryProc procedure)
procedure
's
NullaryProc.run()
method be called at time clock
. The event is
enqueued with type TIMED_EVENT.
The value of clock
must be larger than
getTime()
.
If more than one event is inserted with the same time (clock), they are enqueued in the order of their arrival. For this purpose, a small time increment D is employed so that the time used in the queue is clock + D. The value of D is incremented with each event enqueued within the same integer clock. One consequence of this approach is that is a limit on the number of events can can be added for a given (integer) time, which currently is 1000000 (one million events). Unless the program is run with assertions active, no error is reported if this limit is surpassed. Surpassing it means that the event time will be wrong, for D would be ≥ 1.
If the requested insertion time is beyond the maximum simulation time, the request is silently ignored.
java.lang.IllegalArgumentException
- if the event time is in the past.public void processEnqueuedEventsPreviousTo(int time_limit)
time_limit
. The
simulation time is updated and the method
processEventOnCurrentTime(bcds.phison.sim.SimCore.EventEntry)
is called with each extracted event
as parameter.
public void advanceTime(int new_time)
new_time
and
sets the simulation time to the new time. It does nothing if
the current time is already new_time.
java.lang.RuntimeException
- if new_time
is smaller than the
current time.
LimitReachedException
- if the new time is past the maximum
allowed time.public SimGlobals<V,E> ctx()
public SimParams opt()
public int getTime()
public long getSimStartTime()
start()
was called, or 0 if the simulation has not
started.
public long getSimStopTime()
stop()
was called, or 0 if the simulation has not stopped.
public void callProcessingModules(SimEvents ev, ConnectionInfo<V,E> request)
ev
and request
as
parameters. After all modules have been activated, sets the
last blocking reason to ConnRequestErrorCode.NONE.
public void shutdownProcessingModules()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |