简体   繁体   English

如何在OMNet ++中将动态模块连接到静态模块

[英]How to connect dynamic module to static module in OMNet++

I have a project about computing clouds and I am using Omnet++. 我有一个关于计算云的项目,我正在使用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. OMNet ++的用户手册介绍了如何将动态模块连接到另一个动态模块,而不是动态模块到静态模块。

Can any one help please? 有人可以帮忙吗?

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; 子模块:txc:Txc;

Hopefully this would be useful. 希望这会很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM