2
votes

I am creating a simple omnet++ simulation. Part of that simulation uses a simple module called a packet generator. It will become part of a compound module inside a project called complete. However, when I try to use packetGenerator in a compound module, I get the following error message when trying to run a simulation:

Error in module (omnetpp::cModule) net.tx (id=2) during network setup: Class "packetGenerator" not found -- perhaps its code was not linked in, or the class wasn't registered with Register_Class(), or in the case of modules and channels, with Define_Module()/Define_Channel().

Yes, I went into properties-->project references and referred to the packetGenerator project (as seen in the image). I have also called Define_Module(packetGenerator), as seen in packetGenerator.cc

I have deduced that the problem occurs in the submodules section of the compound module, but I am not sure how to fix this. Any assistance is appreciated. If I omit the inclusion of the packetGenerator submodule in the TransmitterNode compound module, then the simulation will run fine (and do nothing, since there is no functionality yet).

packetGenerator.cc (inside the project 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 (inside the project complete)

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
You should build packetGenerator to shared library and check the checkbox "Export this shared/static library for other projects".Jerzy D.
Thank you. This solved the problem.Razorfoot

2 Answers

2
votes

Project packetGenerator has to be built as shared library and checked the checkbox Export this shared/static library for other projects in Project | Properties | OMNeT++ | Makemake | selection of root or src directory | Options... | Target.

0
votes

I had the same issue. It has been resolved after finding the package is wrong. Like you are using "package complete", maybe this is creating a problem. You can see in the window of the errors if you found that like "complete.linklayer.**" so maybe the package complete needs to change accordingly mentioned in the errors and suggested actually required package. As per your question, I think, you have same problem. I am just talking about my experience. Let's have a try.