4

I have a project about computing clouds and I am using Omnet++. I trying to create a random number of dynamic modules to represent the virtual machines. I am able now to do that but I am not able to connect the new dynamic module to a static module which represents the core of virtual machines. The user manual of OMNet++ explains how to connect dynamic module to another dynamic module but not dynamic to static one.

Can any one help please?

1 Answers1

0

I have created a dynamic module and connect 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);
    }
}

while having only one module created in the static network file:

submodules: txc: Txc;

Hopefully this would be useful.

Mahmoud Bahnasy
  • 119
  • 1
  • 3