cSimulation Class Reference
[Simulation core classesInternal classes]

#include <csimul.h>

Inheritance diagram for cSimulation:

cObject cPolymorphic List of all members.

Detailed Description

Simulation manager class.

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 cPolymorphicdup () 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
cSimulationoperator= (const cSimulation &)
Accessing modules.
int registerModule (cModule *mod)
void deregisterModule (cModule *mod)
int lastModuleId () const
cModulemoduleByPath (const char *modulepath) const
cModulemodule (int id) const
cModuleoperator[] (int id) const
void setSystemModule (cModule *p)
cModulesystemModule () const
Setting up and finishing a simulation run.
void setScheduler (cScheduler *sched)
cSchedulerscheduler () 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.
cNetworkTypenetworkType () const
int runNumber () const
void setSimTime (simtime_t time)
simtime_t simTime () const
long eventNumber () const
Scheduling and context switching during simulation.
cSimpleModuleselectNextModule ()
cMessageguessNextEvent ()
cSimpleModuleguessNextModule ()
simtime_t guessNextSimtime ()
void doOneEvent (cSimpleModule *m)
void transferTo (cSimpleModule *p)
void transferToMain ()
void setContextModule (cModule *p)
void setContextType (int ctxtype)
void setGlobalContext ()
cSimpleModulerunningModule () const
cModulecontextModule () const
int contextType () const
cSimpleModulecontextSimpleModule () const
Miscellaneous.
unsigned long getUniqueNumber ()
bool snapshot (cObject *obj, const char *label)

Friends

class cSimpleModule


Constructor & Destructor Documentation

cSimulation::cSimulation const cSimulation r  ) 
 

Copy constructor is not supported: This function gives an error (throws cRuntimeError) via operator= when called.

cSimulation::cSimulation const char *  name  )  [explicit]
 

Constructor.

virtual cSimulation::~cSimulation  )  [virtual]
 

Destructor.


Member Function Documentation

void cSimulation::callFinish  ) 
 

Recursively calls finish() on the modules of the network.

This method simply invokes callfinish() on the system module.

cModule* cSimulation::contextModule  )  const [inline]
 

Returns the module currently in context.

cSimpleModule* cSimulation::contextSimpleModule  )  const
 

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().

int cSimulation::contextType  )  const [inline]
 

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.

void cSimulation::deleteNetwork  ) 
 

Cleans up the network currently set up.

This involves deleting all modules and deleting the messages in the scheduled-event list.

void cSimulation::deregisterModule cModule mod  ) 
 

Deregisters the module from cSimulation.

It is called internally from cModule destructor.

void cSimulation::doOneEvent cSimpleModule m  ) 
 

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()).

virtual cPolymorphic* cSimulation::dup  )  const [inline, virtual]
 

Dupping is not implemented for this class.

This function gives an error (throws cRuntimeError) via operator= when called.

Reimplemented from cObject.

void cSimulation::endRun  ) 
 

Should be called at the end of a simulation run.

long cSimulation::eventNumber  )  const [inline]
 

Returns sequence number of current event.

virtual void cSimulation::forEachChild cVisitor v  )  [virtual]
 

Calls v->visit(this) for each contained object.

See cObject for more details.

Reimplemented from cObject.

virtual const char* cSimulation::fullPath char *  buffer,
int  bufsize
const [virtual]
 

Returns the name of the simulation object, "simulation".

Reimplemented from cObject.

virtual std::string cSimulation::fullPath  )  const [virtual]
 

Redefined.

(Reason: a C++ rule that overloaded virtual methods must be redefined together.)

Reimplemented from cObject.

unsigned long cSimulation::getUniqueNumber  ) 
 

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.

cMessage* cSimulation::guessNextEvent  ) 
 

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.

cSimpleModule* cSimulation::guessNextModule  ) 
 

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.

simtime_t cSimulation::guessNextSimtime  ) 
 

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.

int cSimulation::lastModuleId  )  const [inline]
 

Returns highest used module ID.

void cSimulation::loadNedFile const char *  nedfile  ) 
 

Load a NED file and create dynamic module types from it.

Works only if src/netbuilder sources are linked in.

cModule* cSimulation::module int  id  )  const [inline]
 

Looks up a module by ID.

If the module doesn't exist, returns NULL.

cModule* cSimulation::moduleByPath const char *  modulepath  )  const
 

Finds a module by its path.

Inclusion of the name of the toplevel module in the path is optional. Returns NULL if not found.

cNetworkType* cSimulation::networkType  )  const [inline]
 

Returns the cNetworkType object that was used to set up the current simulation model.

cSimulation& cSimulation::operator= const cSimulation  )  [inline]
 

Assignment is not supported by this class: this method throws a cRuntimeError when called.

cModule& cSimulation::operator[] int  id  )  const [inline]
 

DEPRECATED because it might return null reference; use module(int) instead.

Same as module(int), only this returns reference instead of pointer.

int cSimulation::registerModule cModule mod  ) 
 

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.

cSimpleModule* cSimulation::runningModule  )  const [inline]
 

Returns the currently executing simple module.

int cSimulation::runNumber  )  const [inline]
 

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.

cScheduler* cSimulation::scheduler  )  const [inline]
 

Returns the scheduler object.

cSimpleModule* cSimulation::selectNextModule  ) 
 

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.

void cSimulation::setContextModule cModule p  ) 
 

Sets the module in context.

Used internally.

void cSimulation::setContextType int  ctxtype  )  [inline]
 

Sets the context type (see CTX_xxx constants).

Used internally.

void cSimulation::setGlobalContext  )  [inline]
 

Sets global context.

Used internally.

void cSimulation::setScheduler cScheduler sched  ) 
 

Installs a scheduler object.

It doesn't need to be deleted in the destructor, that will be done externally.

void cSimulation::setSimTime simtime_t  time  )  [inline]
 

WARNING: INTERNAL USE ONLY.

This method should NEVER be invoked from simulation models, only from scheduler classes subclassed from cScheduler.

void cSimulation::setSystemModule cModule p  ) 
 

Designates the system module, the top-level module in the model.

void cSimulation::setupNetwork cNetworkType net,
int  run_num
 

Builds a new network.

Relies on cNetworkType::setupNetwork().

simtime_t cSimulation::simTime  )  const [inline]
 

Returns current simulation time.

bool cSimulation::snapshot cObject obj,
const char *  label
 

Writes a snapshot of the given object and its children to the textual snapshot file.

This method is called internally from cSimpleModule's snapshot().

void cSimulation::startRun  ) 
 

Should be called after setupNetwork(), but before the first doOneEvent() call.

Includes initialization of the modules, that is, invokes callInitialize() on the system module.

cModule* cSimulation::systemModule  )  const [inline]
 

Returns pointer to the system module, the top-level module in the model.

void cSimulation::transferTo cSimpleModule p  ) 
 

Switches to simple module's coroutine.

This method is invoked from doOneEvent() for activity()-based modules.

void cSimulation::transferToMain  ) 
 

Switches to main coroutine.

virtual void cSimulation::writeContents std::ostream &  os  )  [virtual]
 

Writes textual information about this object to the stream.

See cObject for more details.

Reimplemented from cObject.


The documentation for this class was generated from the following file:
Generated on Sat Oct 21 17:47:57 2006 for OMNeT++/OMNEST Simulation Library by  doxygen 1.4.6