How to connect a dynamic module to a static module in OMNet ++

I have a project about computing clouds, and I'm using Omnet ++. I am trying to create a random number of dynamic modules to represent virtual machines. Now I can do it, but I can’t connect the new dynamic module to the static module, which is the core of virtual machines. The OMNet ++ User Guide explains how to connect a dynamic module to another dynamic module, but not a dynamic one, but a static one.

Can anyone help?

+4
source share
1 answer

I created a dynamic module and connected it to a static module using this code:

void Txc::initialize() { if(strcmp( getName(), "txc" ) ==0){ index =0; cModuleType *moduleType = cModuleType::get("createmoduledynamically.Txc"); cModule *module = moduleType->create("node", getParentModule(), 10 , index);//createScheduleInit() module->setGateSize("in", 2); module->setGateSize("out", 2); gate("out",0)->connectTo(module->gate("in",0)); module->gate("out",0)->connectTo(gate("in",0)); cMessage *msg = new cMessage("Data"); send(msg,"out", 0); } } void Txc::handleMessage(cMessage *msg) { cModule *mod = getParentModule()->getSubmodule("txc"); Txc * txcMod = check_and_cast<Txc *>(mod); txcMod->index++; if(txcMod->index<10){ cModuleType *moduleType = cModuleType::get("createmoduledynamically.Txc"); cModule *module = moduleType->create("node", getParentModule(), 10 , txcMod->index);//createScheduleInit() module->setGateSize("in", 2); module->setGateSize("out", 2); gate("out",1)->connectTo(module->gate("in",0)); module->gate("out",0)->connectTo(gate("in",1)); module->callInitialize(); send(msg, "out", 1); } } 

having only one module created in a static network file:

submodules: txc: Txc;

Hope this would be helpful.

0
source

Source: https://habr.com/ru/post/1482515/


All Articles