handleMessage():未知协议:id = 47,名称= udp-网络初始化期间在模块(inet :: MessageDispatcher)中

时间:2019-05-20 14:07:50

标签: omnet++ inet

我试图广播一个数据包以便发现邻居,当我运行模拟时,我得到了这个错误: handleMessage():未知协议:id = 47,名称= udp-在网络初始化期间,模块(inet :: MessageDispatcher)SaaS.host [0] .at(id = 77)中

我的代码:

#ifndef MYAPP_H_
#define MYAPP_H_

#include "inet/common/INETDefs.h"
#include "inet/transportlayer/contract/udp/UdpSocket.h"

#include <omnetpp.h>

using namespace omnetpp;
using namespace inet;

class myApp : public cSimpleModule, public UdpSocket::ICallback
{
    protected:
        int localPort = -1, destPort = -1;
        bool dontFragment = false;
        const char *packetName = nullptr;
        UdpSocket socket;
        cMessage *selfMsg = nullptr;

    protected:

        void initialize() override;

        void socketDataArrived(UdpSocket *socket, Packet *packet) override;
        void socketErrorArrived(UdpSocket *socket, Indication *indication) override;
        void socketClosed(UdpSocket *socket) override;

    public:
       myApp() {}
       ~myApp();
};



#endif /* MYAPP_H_ */

#include "myApp.h"
#include "inet/applications/base/ApplicationPacket_m.h"
#include "inet/applications/udpapp/UdpBasicApp.h"
#include "inet/common/ModuleAccess.h"
#include "inet/common/TagBase_m.h"
#include "inet/common/TimeTag_m.h"
#include "inet/common/lifecycle/ModuleOperations.h"
#include "inet/common/packet/Packet.h"
#include "inet/networklayer/common/FragmentationTag_m.h"
#include "inet/networklayer/common/L3AddressResolver.h"
#include "inet/transportlayer/contract/udp/UdpControlInfo_m.h"

Define_Module(myApp);

myApp::~myApp()
{
    EV << "App destructor" << endl;
    cancelAndDelete(selfMsg);
}

void myApp::initialize()
{
        localPort = par("localPort");
        destPort = par("destPort");
        packetName = par("packetName");
        socket.setOutputGate(gate("socketOut"));
        socket.bind(localPort);
        socket.setBroadcast(true);
        socket.setCallback(this);
        std::ostringstream str;
        str << getId();
        Packet *packet = new Packet(str.str().c_str());
        if(dontFragment)
            packet->addTagIfAbsent<FragmentationReq>()->setDontFragment(true);
        const auto& payload = makeShared<ApplicationPacket>();
        payload->setChunkLength(B(par("messageLength")));
        payload->addTag<CreationTimeTag>()->setCreationTime(simTime());
        packet->insertAtBack(payload);
        L3Address address;
        L3AddressResolver().tryResolve("255.255.255.255", address);
        emit(packetSentSignal, packet);
        socket.sendTo(packet, address, destPort);
}

void myApp::socketDataArrived(UdpSocket *socket, Packet *packet)
{
    EV << "Data Arrived " << endl;
}

 void myApp::socketErrorArrived(UdpSocket *socket, Indication *indication)
{
    EV << "Error Arrived" << endl;
}

void myApp::socketClosed(UdpSocket *socket)
{
    EV << "Close socket" << endl;
}

我不知道该怎么做,我需要发现邻居,然后向每个邻居发送不同的数据包。

0 个答案:

没有答案