#include <csimul.h>
Inheritance diagram for cSimulation:
cSimulation is the central class in OMNeT++, and it has only one instance, the global variable simulation
. It holds the modules, manages setting up a simulation, running and finishing it, etc.
Most cSimulation methods are used internally (e.g. by the user interface libraries (Envir, Cmdenv, Tkenv) to set up and run simulations).
Some methods which can be of interest when programming simple modules: getUniqueNumber(), moduleByPath(), module(), snapshot().
Public Member Functions | |
Constructor, destructor. | |
cSimulation (const cSimulation &r) | |
cSimulation (const char *name) | |
virtual | ~cSimulation () |
Redefined cObject member functions. | |
virtual cPolymorphic * | dup () const |
virtual void | forEachChild (cVisitor *v) |
virtual void | writeContents (std::ostream &os) |
virtual std::string | fullPath () const |
virtual const char * | fullPath (char *buffer, int bufsize) const |
cSimulation & | operator= (const cSimulation &) |
Accessing modules. | |
int | registerModule (cModule *mod) |
void | deregisterModule (cModule *mod) |
int | lastModuleId () const |
cModule * | moduleByPath (const char *modulepath) const |
cModule * | module (int id) const |
cModule & | operator[] (int id) const |
void | setSystemModule (cModule *p) |
cModule * | systemModule () const |
Setting up and finishing a simulation run. | |
void | setScheduler (cScheduler *sched) |
cScheduler * | scheduler () const |
void | loadNedFile (const char *nedfile) |
void | setupNetwork (cNetworkType *net, int run_num) |
void | startRun () |
void | callFinish () |
void | endRun () |
void | deleteNetwork () |
Information about the current simulation run. | |
cNetworkType * | networkType () const |
int | runNumber () const |
void | setSimTime (simtime_t time) |
simtime_t | simTime () const |
long | eventNumber () const |
Scheduling and context switching during simulation. | |
cSimpleModule * | selectNextModule () |
cMessage * | guessNextEvent () |
cSimpleModule * | guessNextModule () |
simtime_t | guessNextSimtime () |
void | doOneEvent (cSimpleModule *m) |
void | transferTo (cSimpleModule *p) |
void | transferToMain () |
void | setContextModule (cModule *p) |
void | setContextType (int ctxtype) |
void | setGlobalContext () |
cSimpleModule * | runningModule () const |
cModule * | contextModule () const |
int | contextType () const |
cSimpleModule * | contextSimpleModule () const |
Miscellaneous. | |
unsigned long | getUniqueNumber () |
bool | snapshot (cObject *obj, const char *label) |
Friends | |
class | cSimpleModule |
|
Copy constructor is not supported: This function gives an error (throws cRuntimeError) via operator= when called.
|
|
Constructor.
|
|
Destructor.
|
|
Recursively calls finish() on the modules of the network. This method simply invokes callfinish() on the system module. |
|
Returns the module currently in context.
|
|
Returns the module currently in context as a simple module. If the module in context is not a simple module, returns NULL. This is a convenience function which simply calls contextModule(). |
|
Return value only valid if contextModule()!=NULL. Returns one of: CTX_BUILD, CTX_INITIALIZE, CTX_EVENT, CTX_FINISH depending on what the module in context is doing. |
|
Cleans up the network currently set up. This involves deleting all modules and deleting the messages in the scheduled-event list. |
|
Deregisters the module from cSimulation. It is called internally from cModule destructor. |
|
Executes one event. The argument should be the module returned by selectNextModule(); that is, the module to which the next event (lowest timestamp event in the FES) belongs. Also increments the event number (returned by eventNumber()). |
|
Dupping is not implemented for this class. This function gives an error (throws cRuntimeError) via operator= when called. Reimplemented from cObject. |
|
Should be called at the end of a simulation run.
|
|
Returns sequence number of current event.
|
|
Calls v->visit(this) for each contained object. See cObject for more details. Reimplemented from cObject. |
|
Returns the name of the simulation object, "simulation".
Reimplemented from cObject. |
|
Redefined. (Reason: a C++ rule that overloaded virtual methods must be redefined together.) Reimplemented from cObject. |
|
This function is guaranteed to return a different integer every time it is called (usually 0, 1, 2, . ..). This method is recommended over incrementing a global variable because it works also with distributed execution. Useful for generating unique network addresses, etc. |
|
To be called between events from the environment of the simulation (e.g. from Tkenv), this function returns a pointer to the event at the head of the FES. It is only guaranteed to be the next event with sequential simulation; with parallel, distributed or real-time simulation there might be another event coming from other processes with a yet smaller timestamp. This method is careful not to change anything. It never throws an exception, and especially, it does NOT invoke the scheduler (see cScheduler) because e.g. its parallel simulation incarnations might do subtle things to keep events synchronized in various partitions of the parallel simulation. |
|
To be called between events from the environment of the simulation (e.g. from Tkenv), this function returns the module associated with the event at the head of the FES. It returns NULL if the FES is empty, there is no module associated with the event, or the module has already finished. Based on guessNextEvent(); see further comments there. |
|
To be called between events from the environment of the simulation (e.g. Tkenv), this function returns the simulation time of the event at the head of the FES. In contrast, simTime() returns the time of the last executed (or currently executing) event. Returns a negative value if the FES is empty. Based on guessNextEvent(); see further comments there. |
|
Returns highest used module ID.
|
|
Load a NED file and create dynamic module types from it. Works only if src/netbuilder sources are linked in. |
|
Looks up a module by ID. If the module doesn't exist, returns NULL. |
|
Finds a module by its path. Inclusion of the name of the toplevel module in the path is optional. Returns NULL if not found. |
|
Returns the cNetworkType object that was used to set up the current simulation model.
|
|
Assignment is not supported by this class: this method throws a cRuntimeError when called.
|
|
DEPRECATED because it might return null reference; use module(int) instead. Same as module(int), only this returns reference instead of pointer. |
|
Registers the module in cSimulation and assigns a module Id. It is called internally during module creation. The Id of a deleted module is not issued again to another module, because we want module Ids to be unique during the whole simulation. |
|
Returns the currently executing simple module.
|
|
Returns the current run number. A run is the execution of a model with a given set of parameter settings. Runs can be defined in omnetpp.ini. |
|
Returns the scheduler object.
|
|
The scheduler function. Returns the module to which the next event (lowest timestamp event in the FES) belongs. If there's no more event (FES is empty), it throws cTerminationException. A NULL return value means that there's no error but execution was stopped by the user (e.g. with STOP button on the GUI) while selectNextModule() --or rather, the installed cScheduler object-- was waiting for external synchronization. |
|
Sets the module in context. Used internally. |
|
Sets the context type (see CTX_xxx constants). Used internally. |
|
Sets global context. Used internally. |
|
Installs a scheduler object. It doesn't need to be deleted in the destructor, that will be done externally. |
|
WARNING: INTERNAL USE ONLY. This method should NEVER be invoked from simulation models, only from scheduler classes subclassed from cScheduler. |
|
Designates the system module, the top-level module in the model.
|
|
Builds a new network. Relies on cNetworkType::setupNetwork(). |
|
Returns current simulation time.
|
|
Writes a snapshot of the given object and its children to the textual snapshot file. This method is called internally from cSimpleModule's snapshot(). |
|
Should be called after setupNetwork(), but before the first doOneEvent() call. Includes initialization of the modules, that is, invokes callInitialize() on the system module. |
|
Returns pointer to the system module, the top-level module in the model.
|
|
Switches to simple module's coroutine. This method is invoked from doOneEvent() for activity()-based modules. |
|
Switches to main coroutine.
|
|
Writes textual information about this object to the stream. See cObject for more details. Reimplemented from cObject. |