[omnet 6] Dynamic creation of vector module in omnet 6

249 views
Skip to first unread message

eegea

unread,
Mar 18, 2022, 5:45:06 AM3/18/22
to OMNeT++ Users
Hi all,
I have been wondering how to dynamically create a vector of modules with Omnet 6. I need to create some modules from  the info (such as position) that I get from a txt file.
In previous versions it was possible to just add a
node[nodes]: Host {
}
in the network NED and just use:
cModule* mod = nodeType->create(moduleName.c_str(), parentmod, nodeVectorIndex);

            mod->finalizeParameters();
            mod->getDisplayString().parse(moduleDisplayString.c_str());
            mod->buildInside();
In the module where I read the file. It just increased the elements of the list. Now, in omnet 6, in cmodule.cc lines 253 to 256 it checks if the node[] vector exists and the size that it was given in the NED. It refuses to create the module if the index is already occupied (is there any way to force not to create the Host before my file manager?) or if the index is greater than the maximum size. If the @dynamic tag is added to the NED, the it complains that no  submodule named "node" is present because it ignores it in cnednetworkbuilder.cc l. 788.
It is inconvenient because I have to fix the maximum size in advance. And it seems that it is not possible to add nodes to that vector from a truly dynamic source, like  from a message from a SUMO TraCI server.
Of course, I can just add submodules to the parent module without a vector. But this is also inconvenient, when you go to analyze the results file and it is no longer sorted by module vector and so on.

So, is there any way to do this that I am not aware of?

Thanks a lot

eegea

unread,
Mar 21, 2022, 5:31:51 AM3/21/22
to OMNeT++ Users
Hi,
I just found the solution (it is not documented yet for OMNET 6):
It is necessary to first increment the vector size:
parentmod->setSubmoduleVectorSize("node", nodeVectorIndex + 1);
cModule* mod = nodeType->create(moduleName.c_str(), parentmod, nodeVectorIndex);

The size of the vector can be set to 0 in the NED file.
Reply all
Reply to author
Forward
0 new messages