%description: test dynamic module creation: - creating a compound module - finalizeParameters(), buildInside() called implicitly from callInitialize() - test that parameters and gate vectors get properly set up %file: test.ned import testlib.*; // will be dynamically instantiated module BoxedSink { parameters: int numGates; string other = default("foo"); gates: input in[numGates]; submodules: sink: Sink; connections allowunconnected: in[0] --> sink.in; } simple Creator { } network Test { submodules: creator: Creator; dump: Dump; } %file: creator.cc #include using namespace omnetpp; namespace @TESTNAME@ { class Creator : public cSimpleModule { public: Creator() : cSimpleModule(16384) { } void activity() override; }; Define_Module(Creator); void Creator::activity() { cModuleType *sinkType = cModuleType::get("BoxedSink"); cModule *sink = sinkType->create("boxedSink", getParentModule()); sink->callInitialize(); sendDirect(new cMessage("hello"), 1, 0, sink->gate("in", 0)); } }; %inifile: test.ini [General] network = Test cmdenv-express-mode = false cmdenv-event-banners = false **.boxedSink.numGates = 3 # Note: boxedSink.other will be assigned automatically %contains: stdout module Test: Test { parameters: @isNetwork submodules: module Test.creator: Creator { } module Test.boxedSink: BoxedSink { parameters: numGates = 3 other = "foo" gates: in[0]: not connected in[1]: not connected in[2]: not connected submodules: module Test.boxedSink.sink: testlib.Sink { gates: in: <-- .in[0] } } } %contains-regex: stdout Initializing Sink.* Sink received msg hello.* Sink finishing, received msgs: 1