首页 > 解决方案 > 模块错误中的 Omnet++ 未知参数

问题描述

我正在创建一个随机生成的网络,在询问其他节点是否已经知道更新后,节点将发送更新消息。目前更新状态仍然是预定义的。运行模拟时收到此错误消息:

"(omnetpp::cModule)Simplegossip1: Unknown parameter 'updated' -- in module (Sg1) Simplegossip1.node[0] (id=2), at t=0s, event #1" 

这是我的代码:

simplegossip1.ned (我在这里使用代码How to create a random connected graph in OMNeT++?

    simple Sg1
{
    parameters:
        @display("i=block/routing");
        bool updated;
    gates:
        input in[];  // declare in[] and out[] to be vector gates
        output out[];
}

network Simplegossip1
{
    parameters:
        int count;
        double connectedness; // 0.0<x<1.0
    submodules:
        node[count]: Sg1 {
            gates:
                in[];  // removed the size of gate
                out[];
        }
    connections allowunconnected:
       for i=0..count-2, for j=i+1..count-1, if uniform(0,1)<connectedness {
            node[i].out++ --> node[j].in++;
            node[i].in++ <-- node[j].out++;
        }
}

sg1.cc

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>

using namespace omnetpp;

/**
 * First attempt for gossip protocol
 */
class Sg1 : public cSimpleModule
{
public:
    cMessage *askupdated = new cMessage("Ask Update");
    cMessage *updated = new cMessage("Updated");
    cMessage *unupdated = new cMessage("Unupdated");
    cMessage *update = new cMessage("Here is the update");
  protected:
    virtual void forwardMessage(cMessage *msg, int dest);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
    };

Define_Module(Sg1);

void Sg1::initialize()
{
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.
        char msgname[20];
        sprintf(msgname, "tic-%d", getIndex());
        cMessage *msg = new cMessage(msgname);
        scheduleAt(0.0, msg);
    }
}

void Sg1::handleMessage(cMessage *msg)
{
    int n = gateSize("out");
    int k = intuniform(0, n-1);
    int sid = msg->getArrivalGateId();
    bool updatestatus = getParentModule()->par("updated");
    if (msg == askupdated) {
        if (updatestatus == true){
            forwardMessage(updated,sid);
        }
        else {
            forwardMessage(unupdated,sid);
        }
    }
    else if (msg == unupdated) {
        forwardMessage(update,sid);
    }
    else {
        forwardMessage(askupdated,k);
    }
}

void Sg1::forwardMessage(cMessage *msg, int dest)
{
    // In this example, we just pick a random gate to send it on.
    // We draw a random number between 0 and the size of gate `out[]'.
    EV << "Forwarding message " << msg << " on port out[" << dest << "]\n";
    send(msg, "out", dest);
}

还有一个只调用 Simplegossip1 网络的 omnet.ini 文件。

我该如何解决这个问题?提前致谢。

标签: omnet++

解决方案


你必须换行

bool updatestatus = getParentModule()->par("updated");

进入

bool updatestatus = par("updated");

因为updatedSg1not 的父级的参数Sg1


推荐阅读