When I run the example in veins 5.0, I know Multi stage can be defined by numInitStages()
function. But I don't know when or why the value of stages changes from 0 to 1 in the BaseModule.cc
files.
void BaseModule::initialize(int stage)
The simulation environment is responsible for calling subsequent stages during initialization.
For example, let's assume that one defines for a module:
int numInitStages() const { return 3; }
When the simulation is starting, the simulation environment calls:
initialize(0);
initialize(1);
initialize(2);
What is important: the simulation environment calls initialize(0)
for every module, then it calls initialize(1)
for every module whose numInitStages()
returns 2 or more, then it calls initialize(2)
for every module whose numInitStages()
returns 3 or more, etc.
Thanks to this, we are sure that initialize(1)
will be called after calling
initialize(0)
in all modules. As a consequence, we may decide - for example - that an address is assigned in stage=1, and a socket that uses this address is opened in stage=2.
Reference: OMNeT++ Simulation Manual