How to invoke finish() individually on modules in omnet++

*爱你&永不变心* 提交于 2019-12-11 03:43:07

问题


I am using Omnet++ and creating a scenario where a sender keeps sending packets to a receiver (uni-directional communication from sender to receiver) and I have set a counter on both the simple modules of sender and receiver.

Since the sender's counter counts down to zero first than the receiver, the simulation run well but it does not record statistics since all that is done at the receiver.

after the counter is decreased to zero both the modules invoke a finish() function.

sender::finish()
{
 EV << "message limit reached \n";
 cancelAndDelete(myEvent);
}

receiver's finish function:

void receiver::finish()
{
  EV << "mean:   "<< iatStats.getMean() << endl;
  EV << "std.dev:   " << iatStats.getStddev() << endl;
  EV << "variance:  " << iatStats.getVariance() << endl;

  iatStats.recordAs("Inter-Arrival Times");
  recordScalar("#IAT", interAT_diff);
}

here iat is calculation for inter-arrival time between the packets at the receiver.

After the simulation runs, the sender's finish() is invoked first and the simulation stops and no data is recorded in /results folder only blank .vec or .sca files exist.

also the terminal says simulation fault: core dumped

The problem is how can I "pause" the sender block once the counter is run out and let the receiver invoke it's finish() function so that I could see the stats and also record all the data I need?

Hope the description is clear enough. Thanks


回答1:


So it turns out that calling two finishes for individual modules isn't the right thing to. hence, to tackle the situation I renamed the finish() function in the sender block to done(). This helps the simulator to provide a better functionality and the when the counter on the receiver comes to zero the finish() function is invoked and all the data collection occurs perfectly and it even gets displayed on the message console.

any other name instead of finish() needs to be used when using separate modules e.g. stopBlock() or done() or any generic name. Make sure that finish() is invoked ONLY ONCE in the complete simulation.

The reason is finish() function is for the complete Omnet++ environment and if any one block/module invokes it first the other modules will stop functioning.



来源:https://stackoverflow.com/questions/33397097/how-to-invoke-finish-individually-on-modules-in-omnet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!