c++ - Omnet++ (INET) 在运行时创建或出现节点

标签 c++ omnet++ inet

我需要在运行时创建一个节点,其参数与其他节点相似。为此,我在 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 框架中节点的运行时出现和消失是否可能,是否有任何示例。

最佳答案

OMNeT++ 用户手册有一个 section致力于此。根据这一点,当使用 createScheduleInit() 时,您不需要 buildInside()scheduleStart()

可以在 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);

关于c++ - Omnet++ (INET) 在运行时创建或出现节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29966300/

相关文章:

c++ - 使用 C++/Visual C++ 控制光标和键盘

c++ - INET无线接口(interface)表模块参数

linux - 为 omnet++ 编译 INET 框架时出错

c++ - 是否可以将其他文件类型添加到 Visual Studios 清理程序中?

c++ - 尝试使用 RAII 捕获?

c++ - 另一个子模块错误的omnet访问方法-没有匹配函数调用 ‘check_and_cast(cModule*&)’

c++ - 使用 TraCIDemo11p 定期发送消息

java - 安装成功后Omnet++ 5.4.1在Ubuntu 18.10上运行错误

Perl:如何在 X 秒后获得 IO::Socket::INET 超时?

java - GetStringUTFChars 及其字符串复制行为