Omnet ++:在作为复合模块的子模块调用时找不到类

时间:2016-09-25 05:02:55

标签: c++ omnet++

我正在创建一个简单的omnet ++模拟。部分模拟使用称为数据包生成器的简单模块。它将成为名为 complete 的项目中复合模块的一部分。但是,当我尝试在复合模块中使用 packetGenerator 时,我在尝试运行模拟时收到以下错误消息:

  

网络设置期间模块(omnetpp :: cModule)net.tx(id = 2)出错:Class" packetGenerator"找不到 - 也许它的代码没有链接,或者类没有在Register_Class()中注册,或者在模块和通道的情况下,使用Define_Module()/ Define_Channel()。

是的,我进入了属性 - >项目引用并引用了 packetGenerator 项目(如图所示)。我也称为Define_Module(packetGenerator),如 packetGenerator.cc

中所示

我已经推断出问题发生在复合模块的子模块部分,但我不知道如何解决这个问题。任何帮助表示赞赏。如果我在 TransmitterNode 复合模块中省略了 packetGenerator 子模块,那么模拟运行正常(并且什么都不做,因为还没有功能)。

packetGenerator.cc (在项目 packetGenerator 中)

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include <AppMessage_m.h>
using namespace omnetpp;

//Simple module responsible for continuously generating AppMessage messages
class packetGenerator: public cSimpleModule {

  private:
    cMessage* event;
    int seqno;
    int senderId;

  public:
    packetGenerator();
    virtual ~packetGenerator();

  protected:

    virtual void initialize() override;

    virtual void handleMessage(cMessage *msg) override;

    virtual AppMessage* generateMessage();
};

Define_Module(packetGenerator);

packetGenerator::packetGenerator() {
    event = nullptr;
    seqno = 0;
}

packetGenerator::~packetGenerator() {
    cancelAndDelete(event);
}

void packetGenerator::initialize() {

    senderId = par("nodeIdentifier");
    event = new cMessage("event");
    scheduleAt(0.0, event);
}

void packetGenerator::handleMessage(cMessage* msg) {

    WATCH(seqno);

    //Go here when the new message is scheduled to be sent (after the delay)
    if (msg == event) {
        send(generateMessage(), "out");
        simtime_t delay = par("iatDistribution");
        scheduleAt(simTime() + delay, event);
    }

    //If we receive a message that isn't our timer-expiry message (e.g. from the MAC), go here
    else {
        AppMessage* appmsg = check_and_cast<AppMessage*>(msg);
        EV << "Message received" << endl;
        EV << "Message kind: " << msg->getKind() << endl;
        delete appmsg;
    }

}

AppMessage* packetGenerator::generateMessage() {


    simtime_t timeStamp = simTime();
    int sequenceNumber = seqno;
    seqno++;
    int msgSize = par("messageSize");

    char messageName[30];
    sprintf(messageName, "Message from %d", senderId);

    AppMessage* msg = new AppMessage(messageName);
    msg->setTimeStamp(timeStamp);
    msg->setSenderId(senderId);
    msg->setSequenceNumber(sequenceNumber);
    msg->setMsgSize(msgSize);

    return msg;
}

net.ned (项目内完成

package complete;
import packetgenerator.packetGenerator;

module TransmitterNode
{
    parameters:
        int nodeIdentifier; //These need to be unique in the simulation
        double nodeXPosition;
        double nodeYPosition;
        @display("bgb=468,188;i=device/cellphone");
    gates:
    submodules:      
        packetGenerator: packetGenerator {
            @display("p=79,90;i=block/source");
        }
    connections:
}

network net
{
    submodules:
        tx: TransmitterNode;
    connections:
}

properties

2 个答案:

答案 0 :(得分:2)

项目packetGenerator必须构建为共享库,并选中Export this shared/static library for other projects |中的复选框ProjectProperties | OMNeT++ | Makemake |选择root或src目录| Options... | Target

答案 1 :(得分:0)

我有同样的问题。发现软件包错误后已解决。就像您使用的是“包完成”一样,也许这是一个问题。如果发现像“ complete.linklayer。**”之类的错误,则可以在错误窗口中看到,因此,可能需要更改错误中提到的包完整和建议的实际需要的包。我认为,按照您的问题,您也有同样的问题。我只是在说我的经历。让我们尝试一下。