%description: Test initialize() and finish() of a channel; e.g. simulation.getContext() and simulation.getContextType() should be correctly set. %file: test.ned simple Node { gates: inout g; } channel TestChannel { } network Test { submodules: a: Node; b: Node; connections: a.g <--> TestChannel <--> b.g; } %file: test.cc #include using namespace omnetpp; namespace @TESTNAME@ { class TestChannel: public cIdealChannel { public: TestChannel() { } virtual void initialize() override { ASSERT(getSimulation()->getContext() == this); ASSERT(getSimulation()->getContextType() == CTX_INITIALIZE); EV << "- " << getFullPath() << " initialize\n"; } virtual void processMessage(cMessage *msg, simtime_t t, result_t& result) override { //FIXME this fails: ASSERT(getSimulation()->getContext() == this); ASSERT(getSimulation()->getContextType() == CTX_EVENT); EV << "- " << getFullPath() << " process: \"" << msg->getName() << "\"\n"; cIdealChannel::processMessage(msg, t, result); } virtual void finish() override { ASSERT(getSimulation()->getContext() == this); ASSERT(getSimulation()->getContextType() == CTX_FINISH); EV << "- " << getFullPath() << " finish\n"; } }; Define_Channel(TestChannel); class Node : public cSimpleModule { public: Node() { } virtual void initialize() override { ASSERT(getSimulation()->getContext() == this); ASSERT(getSimulation()->getContextType() == CTX_INITIALIZE); EV << "- " << getFullPath() << " initialize\n"; scheduleAt(1, new cMessage("timer")); } virtual void handleMessage(cMessage *msg) override { ASSERT(getSimulation()->getContext() == this); ASSERT(getSimulation()->getContextType() == CTX_EVENT); EV << "- " << getFullPath() << " handleMessage: \"" << msg->getName() << "\"\n"; if (msg->isSelfMessage()) send(new cMessage("packet"), "g$o"); delete msg; } virtual void finish() override { ASSERT(getSimulation()->getContext() == this); ASSERT(getSimulation()->getContextType() == CTX_FINISH); EV << "- " << getFullPath() << " finish\n"; } }; Define_Module(Node); }; // namespace %inifile: test.ini [General] network = Test cmdenv-express-mode = false cmdenv-event-banners = false %contains: stdout Initializing... - Test.a.g$o.channel initialize - Test.b.g$o.channel initialize - Test.a initialize - Test.b initialize Running simulation... - Test.a handleMessage: "timer" - Test.a.g$o.channel process: "packet" - Test.b handleMessage: "timer" - Test.b.g$o.channel process: "packet" - Test.b handleMessage: "packet" - Test.a handleMessage: "packet" No more events, simulation completed -- at t=1s, event #4 Calling finish() at end of Run #0... - Test.a.g$o.channel finish - Test.b.g$o.channel finish - Test.a finish - Test.b finish