Omnet++ handleMessage():未知协议:在网络初始化期间,id=47,name=udp--in模块(inet::MessageDispatcher)
我试图广播一个数据包以发现邻居,当我运行模拟时,我得到以下错误: handleMessage():未知协议:id=47,name=udp--在网络初始化期间,位于模块(inet::MessageDispatcher)SaaS.host[0].at(id=77)中 我的代码:Omnet++ handleMessage():未知协议:在网络初始化期间,id=47,name=udp--in模块(inet::MessageDispatcher),omnet++,inet,Omnet++,Inet,我试图广播一个数据包以发现邻居,当我运行模拟时,我得到以下错误: handleMessage():未知协议:id=47,name=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/
#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;
}
\ifndef MYAPP\u H_
#定义MYAPP_H_
#包括“inet/common/INETDefs.h”
#包括“inet/transportlayer/contract/udp/UdpSocket.h”
#包括
使用名称空间omnetpp;
使用名称空间inet;
类myApp:public cSimpleModule,public UdpSocket::ICallback
{
受保护的:
int localPort=-1,destPort=-1;
bool dontFragment=false;
const char*packetName=nullptr;
UdpSocket插座;
cMessage*selfMsg=nullptr;
受保护的:
void initialize()覆盖;
void socketDataArrived(UdpSocket*socket,Packet*Packet)覆盖;
无效套接字错误到达(UdpSocket*套接字,指示*指示)覆盖;
void socketClosed(UdpSocket*socket)覆盖;
公众:
myApp(){}
~myApp();
};
#endif/*MYAPP_H_*/
#包括“myApp.h”
#包括“inet/applications/base/ApplicationPacket\u m.h”
#包括“inet/applications/udpapp/UdpBasicApp.h”
#包括“inet/common/ModuleAccess.h”
#包括“inet/common/TagBase\u m.h”
#包括“inet/common/TimeTag\u m.h”
#包括“inet/common/lifecycle/ModuleOperations.h”
#包括“inet/common/packet/packet.h”
#包括“inet/networklayer/common/FragmentationTag_m.h”
#包括“inet/networklayer/common/L3AddressResolver.h”
#包括“inet/transportlayer/contract/udp/UdpControlInfo_m.h”
定义_模块(myApp);
myApp::~myApp()
{
EV setChunkLength(B(par(“messageLength”));
有效负载->添加标签()->setCreationTime(simTime());
数据包->插入包(有效负载);
L3地址;
L3AddressResolver().tryResolve(“255.255.255.255”,地址);
发射(包发送信号、包);
socket.sendTo(数据包、地址、目的端口);
}
void myApp::socketDataArrived(UdpSocket*socket,Packet*Packet)
{
电动汽车