1

我需要在运行时创建一个节点,其参数与其他节点相似。为此,我在 ned 文件中创建了一个动态节点:-

host_send4: meshnode {
        parameters:
            @dynamic;
            @display("p=1000,535;r=200,green;i=device/smallrouter");
}

为了在 C++ 文件中实现这个节点,我添加了这个代码:-

    cModuleType *meshnode1 = cModuleType::get("inet.networklayer.manetrouting.PASER.meshnode");
    cModule *mod = meshnode1->createScheduleInit("host_send4", this);
    cDisplayString& dispstr =  mod->getDisplayString();
    dispstr.parse("p=1000,535;r=200,green;i=device/smallrouter");

    mod->buildInside();
    mod->scheduleStart(simTime()+5*beaconInterval);

但我无法正确构建它。我想我需要这方面的任何例子。谁能帮我指出一个在 INETMANET 的 mixim 或任何其他 oment 框架中的示例,该功能已经实现。谢谢你的帮助。

我也想静态地创建一个节点,它会在稍后的时间点出现在模拟中。是否有可能,是否有任何关于 INET 或其他 OMNET 框架中节点的运行时外观和消失的示例。

4

1 回答 1

2

OMNeT++ 用户手册有专门的一节。根据这个你不需要buildInside()scheduleStart()使用时createScheduleInit()

在 Veins框架中可以看到如何执行此操作的示例 - 更准确地说是在TraCIScenarioManager中。对您来说重要的几行可能是:

cModule* parentmod = getParentModule();
if (!parentmod) error("Parent Module not found");

cModuleType* nodeType = cModuleType::get(type.c_str());
if (!nodeType) error("Module Type \"%s\" not found", type.c_str());

cModule* mod = nodeType->create(name.c_str(), parentmod, nodeVectorIndex, nodeVectorIndex);
mod->finalizeParameters();
mod->getDisplayString().parse(displayString.c_str());
mod->buildInside();
mod->scheduleStart(simTime() + updateInterval);
于 2015-04-30T11:55:00.590 回答