Как объединить сообщение в omnet ++ - PullRequest
0 голосов
/ 14 марта 2020

У меня есть три модуля в моей модели. 1. Клиент: отправка сообщений в агрегатор; 2. Агрегатор: объединяет сообщения от клиента и передает его на сервер. 3.Server: удаление сообщений.

Теперь на узлах агрегации сообщения объединяются с событием тайм-аута. Таймер запускается, когда сообщения поступают в узел агрегатора. Как только таймер завершает узел агрегатора, перенаправляет объединенное сообщение на сервер. .

См. Следующий код:

Клиент. cc

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


using namespace omnetpp;

//Client Module
class Client : public cSimpleModule {
protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
    virtual cMessage *generateNewMessage();
private:
    int seq=0;
    cMessage *message;

};


Define_Module(Client);

void Client :: initialize()
{
    //scheduling first sending
    scheduleAt(simTime(),new cMessage);
}

void Client :: handleMessage(cMessage *msg){
    //generate and send message
    message = generateNewMessage();
    send(message,"out");
    //schedule next call
    scheduleAt(simTime()+exponential(1.0),msg);
}

cMessage *Client::generateNewMessage()
{
    // Generate a message with a different name every time.
    char msgname[20];
    sprintf(msgname, "msg-%d", ++seq);
    cMessage *msg = new cMessage(msgname);
    return msg;
}

агрегатор. cc

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


using namespace omnetpp;


class Aggregator : public cSimpleModule{
protected:
   virtual void initialize() override;
   virtual void handleMessage(cMessage *msg) override;
   virtual cMessage *concateMsg(cMessage *msg);
private:
   cMessage *con_message;
   simtime_t timeout;//timeout;
   cMessage *timeoutEvent;//holds pointer to the timeout self message

};
Define_Module(Aggregator);

void Aggregator :: initialize()
{
   timeout=5.0;
   timeoutEvent=new cMessage("timeout");
   //initialize the timer
   scheduleAt(simTime()+timeout,timeoutEvent);
}
void Aggregator :: handleMessage(cMessage *msg)
{
   if(msg==timeoutEvent)
   {
       //send the concatenated message to the server
       send(con_message,"out");
   }
   else{
       con_message=concateMsg(msg);
   }
}

cMessage *Aggregator::concateMsg(cMessage *msg)
{
   // concatenation of messages
   cMessage *s1 = new cMessage("s1");
   s1=msg;
   msg=msg+s1;
   return msg;
}

сервер. cc



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


using namespace omnetpp;



class Server : public cSimpleModule{

    virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Server);

void Server :: handleMessage(cMessage *msg)
{
    EV <<"Message arrived at destination";
    bubble("Arrived at Destination");
    delete msg;
}

Я получаю ошибку в агрегаторе. cc.

20:05:59 **** Incremental Build of configuration release for project Aggregation ****
make MODE=release all 
cd src && /usr/bin/make
make[1]: Entering directory '/c/Users/ADITI/Documents/omnetpp-5.6.1/samples/my_projects/Aggregation/src'
aggregator.cc
aggregator.cc:50:24: error: no matching constructor for initialization of 'omnetpp::cMessage'
    cMessage *s1 = new cMessage(s1);
                       ^        ~~
C:/Users/ADITI/Documents/omnetpp-5.6.1/include/omnetpp/cmessage.h:172:5: note: candidate constructor not viable: no known conversion from 'omnetpp::cMessage *' to 'const omnetpp::cMessage' for 1st argument; dereference the argument with *
    cMessage(const cMessage& msg);
    ^
C:/Users/ADITI/Documents/omnetpp-5.6.1/include/omnetpp/cmessage.h:177:14: note: candidate constructor not viable: no known conversion from 'omnetpp::cMessage *' to 'const char *' for 1st argument
    explicit cMessage(const char *name=nullptr, short kind=0);
             ^
aggregator.cc:52:12: error: invalid operands to binary expression ('omnetpp::cMessage *' and 'omnetpp::cMessage *')
    msg=msg+s1;
        ~~~^~~
2 errors generated.
make[1]: *** [Makefile:104: ../out/clang-release/src/aggregator.o] Error 1
make[1]: Leaving directory '/c/Users/ADITI/Documents/omnetpp-5.6.1/samples/my_projects/Aggregation/src'
make: *** [Makefile:2: all] Error 2
"make MODE=release all" terminated with exit code 2. Build might be incomplete.

20:06:00 Build Failed. 4 errors, 0 warnings. (took 1s.546ms)


Что я здесь не так делаю? Пожалуйста, помогите.

...