Omnet++ 错误:NED类型';myApp';由于缺少基类型或接口,无法完全解析?
在我的项目中, 我实现了一个名为myApp的新类,它继承自ApplicationBase和UdpSocket类。当我构建我的项目时,我没有收到任何错误,但是当我用IDE调试C/C++应用程序时,它会在错误部分显示第一个错误。当我运行make时,命令行显示第二个错误: myApp.ned、myApp.h和myApp.cc的代码如下: 我确实在项目参考中包含了inet库,并尝试了发布在中的解决方案Omnet++ 错误:NED类型';myApp';由于缺少基类型或接口,无法完全解析?,omnet++,inet,Omnet++,Inet,在我的项目中, 我实现了一个名为myApp的新类,它继承自ApplicationBase和UdpSocket类。当我构建我的项目时,我没有收到任何错误,但是当我用IDE调试C/C++应用程序时,它会在错误部分显示第一个错误。当我运行make时,命令行显示第二个错误: myApp.ned、myApp.h和myApp.cc的代码如下: 我确实在项目参考中包含了inet库,并尝试了发布在中的解决方案 导入inet.applications.contract.IApp; 像IApp这样的简单myApp
导入inet.applications.contract.IApp;
像IApp这样的简单myApp
{
参数:
int localPort=default(-1);//本地UDP端口号(-1:使用临时端口)
int destPort;//远程UDP端口号
字符串packetName=默认值(“myApp”);
string interfaceTableModule;//interfaceTableModule的路径
double helloInterval@unit(s)=默认值(5s);//应该多久发送一次hello消息
volatile double sendInterval@unit(s);//通常应为随机值,例如指数(1)
double startTime@unit(s)=默认值(this.sendInterval);//应用程序开始时间(第一个数据包的开始)
双停止时间@unit(s)=默认值(-1s);//完成发送的时间,-1s表示永远
double maxVariance=default(1);//这是确定何时发送第一条hello消息的随机值的最大值
可变双广播延迟@单位=默认值(统一(0秒,0.01秒));
int timeToLive=default(-1);//如果不是-1,则将发送数据包的TTL(IPv4)或跃点限制(IPv6)字段设置为此值
bool dontFragment=default(false);//如果为true,则要求IP在路由过程中不分割消息
int-typeOfService=default(-1);//如果不是-1,则将已发送数据包的ToS(IPv4)或流量类(IPv6)字段设置为此值
string multicastInterface=default(“”;//如果不为空,请在套接字上设置多播输出接口选项(应为接口名称)
bool receiveBroadcast=default(false);//如果为true,则使套接字接收广播数据包
bool joinLocalMulticastGroups=default(false);//如果为true,则使套接字从本地接口上设置的所有多播组接收数据包
@类别(myApp);
盖茨:
输入socketIn@标签(UdpControlInfo/up);
输出插座输出@标签(UdpControlInfo/down);
}
#ifndef MYAPP_H_
#定义MYAPP_H_
#包括“inet/common/INETDefs.h”
#包括“inet/applications/base/ApplicationBase.h”
#包括“inet/transportlayer/contract/udp/UdpSocket.h”
#包括“inet/transportlayer/contract/udp/UdpControlInfo_m.h”
#包括“inet/common/ModuleAccess.h”
#包括“inet/common/TimeTag\u m.h”
#包括“inet/common/packet/packet.h”
#包括“inet/common/lifecycle/ModuleOperations.h”
#包括“inet/common/IProtocolRegistrationListener.h”
#包括“inet/common/ProtocolTag_m.h”
#包括“inet/linklayer/common/InterfaceTag_m.h”
#包括“inet/networklayer/contract/IInterfaceTable.h”
#包括“inet/networklayer/contract/ipv4/Ipv4Address.h”
#包括“inet/networklayer/ipv4/IIpv4RoutingTable.h”
#包括“inet/networklayer/ipv4/ipv4头文件\u m.h”
#包括“inet/networklayer/ipv4/Ipv4InterfaceData.h”
#包括“inet/networklayer/common/FragmentationTag_m.h”
#包括“inet/networklayer/common/L3AddressResolver.h”
#包括“HelloMsg_m.h”
#包括“XedMsg_m.h”
#包括
#包括
#包括
#包括
使用名称空间omnetpp;
使用名称空间inet;
使用名称空间std;
类myApp:public ApplicationBase,public UdpSocket::ICallback
{
受保护的:
//枚举SelfMsgKinds{START=1,SEND,STOP};
int localPort=-1,destPort=-1;
bool dontFragment=false;
const char*packetName=nullptr;
同步启动时间;
同时停止时间;
//陈述
UdpSocket插座;
cMessage*selfMsg=nullptr;
cModule*host=nullptr;
cMessage*event=nullptr;
cPar*广播延迟=空PTR;
无符号整数序列号=0;
simtime_t helloInterval;
i可接口*ift=nullptr;
InterfaceEntry*interface80211ptr=nullptr;
int interfaceId=-1;
列出邻居;
ipv4地址源;
/**********X**********/
第X类
{
公众:
L3Address发起者地址,目的地址地址;
无符号整数随机;
XED(常量L3Address和原始地址,常量L3Address和目标地址,无符号整数随机)
:originatorAddr(originatorAddr),destinationAddr(destinationAddr),random(random){};
布尔运算符==(常数x和其他)常数
{
返回this->originatorAddr==other.originatorAddr&&this->destinationAddr==other.destinationAddr
&&此->随机==other.random;
}
};
列出lr、ls;
/**********MTLSD**********/
类MTLSD
{
公众:
L3Address发起者地址,目的地址地址;
字符*位置;
同步时间;
MTLSD(常量L3Address&始发地址、常量L3Address&目的地址、字符*位置、同步时间)
:originatorAddr(originatorAddr),destinationAddr(destinationAddr),position(position),time(time){};
布尔运算符==(常量MTLSD和其他)常量
{
返回this->originatorAddr==other.originatorAddr&&this->destinationAddr==other.destinationAddr
&&此->位置==other.position&&this->time==time;
}
};
受保护的:
virtual int numInitStages()常量重写{return NUM_INIT_STAGES;}
虚拟无效初始化(int阶段)覆盖;
虚拟void handleMessageWhenUp(cMessage*msg)覆盖;
无效handleSelfMessage(cMessage*msg);
/*虚拟void processStart();
import inet.applications.contract.IApp;
simple myApp like IApp
{
parameters:
int localPort = default(-1); // local UDP port number (-1: use ephemeral port)
int destPort; // remote UDP port number
string packetName = default("myApp");
string interfaceTableModule; // The path to the InterfaceTable module
double helloInterval @unit(s) = default(5s); // how often hello messages should be sent out
volatile double sendInterval @unit(s); // should usually be a random value, e.g. exponential(1)
double startTime @unit(s) = default(this.sendInterval); // application start time (start of the first packet)
double stopTime @unit(s) = default(-1s); // time of finishing sending, -1s means forever
double maxVariance = default(1); // This is the maximum of a random value to determine when the first hello message will be sent out
volatile double broadcastDelay @unit(s) = default(uniform(0s,0.01s));
int timeToLive = default(-1); // if not -1, set the TTL (IPv4) or Hop Limit (IPv6) field of sent packets to this value
bool dontFragment = default(false); // if true, asks IP to not fragment the message during routing
int typeOfService = default(-1); // if not -1, set the ToS (IPv4) or Traffic Class (IPv6) field of sent packets to this value
string multicastInterface = default(""); // if not empty, set the multicast output interface option on the socket (interface name expected)
bool receiveBroadcast = default(false); // if true, makes the socket receive broadcast packets
bool joinLocalMulticastGroups = default(false); // if true, makes the socket receive packets from all multicast groups set on local interfaces
@class(myApp);
gates:
input socketIn @labels(UdpControlInfo/up);
output socketOut @labels(UdpControlInfo/down);
}
#ifndef MYAPP_H_
#define MYAPP_H_
#include "inet/common/INETDefs.h"
#include "inet/applications/base/ApplicationBase.h"
#include "inet/transportlayer/contract/udp/UdpSocket.h"
#include "inet/transportlayer/contract/udp/UdpControlInfo_m.h"
#include "inet/common/ModuleAccess.h"
#include "inet/common/TimeTag_m.h"
#include "inet/common/packet/Packet.h"
#include "inet/common/lifecycle/ModuleOperations.h"
#include "inet/common/IProtocolRegistrationListener.h"
#include "inet/common/ProtocolTag_m.h"
#include "inet/linklayer/common/InterfaceTag_m.h"
#include "inet/networklayer/contract/IInterfaceTable.h"
#include "inet/networklayer/contract/ipv4/Ipv4Address.h"
#include "inet/networklayer/ipv4/IIpv4RoutingTable.h"
#include "inet/networklayer/ipv4/Ipv4Header_m.h"
#include "inet/networklayer/ipv4/Ipv4InterfaceData.h"
#include "inet/networklayer/common/FragmentationTag_m.h"
#include "inet/networklayer/common/L3AddressResolver.h"
#include "HelloMsg_m.h"
#include "XedMsg_m.h"
#include <omnetpp.h>
#include <vector>
#include <random>
#include <algorithm>
using namespace omnetpp;
using namespace inet;
using namespace std;
class myApp : public ApplicationBase, public UdpSocket::ICallback
{
protected:
//enum SelfMsgKinds { START = 1, SEND, STOP };
int localPort = -1, destPort = -1;
bool dontFragment = false;
const char *packetName = nullptr;
simtime_t startTime;
simtime_t stopTime;
// state
UdpSocket socket;
cMessage *selfMsg = nullptr;
cModule *host = nullptr;
cMessage *event = nullptr;
cPar *broadcastDelay = nullptr;
unsigned int sequencenumber = 0;
simtime_t helloInterval;
IInterfaceTable *ift = nullptr;
InterfaceEntry *interface80211ptr = nullptr;
int interfaceId = -1;
list<L3Address> neighbors;
Ipv4Address source;
/********** XED **********/
class XED
{
public:
L3Address originatorAddr, destinationAddr;
unsigned int random;
XED(const L3Address& originatorAddr, const L3Address& destinationAddr, unsigned int random)
: originatorAddr(originatorAddr), destinationAddr(destinationAddr), random(random) {};
bool operator==(const XED& other) const
{
return this->originatorAddr == other.originatorAddr && this->destinationAddr == other.destinationAddr
&& this->random == other.random;
}
};
list<XED> lr,ls;
/********** MTLSD **********/
class MTLSD
{
public:
L3Address originatorAddr, destinationAddr;
char *position;
simtime_t time;
MTLSD(const L3Address& originatorAddr, const L3Address& destinationAddr, char *position, simtime_t time)
: originatorAddr(originatorAddr), destinationAddr(destinationAddr), position(position), time(time) {};
bool operator==(const MTLSD& other) const
{
return this->originatorAddr == other.originatorAddr && this->destinationAddr == other.destinationAddr
&& this->position == other.position && this->time == time;
}
};
protected:
virtual int numInitStages() const override { return NUM_INIT_STAGES; }
virtual void initialize(int stage) override;
virtual void handleMessageWhenUp(cMessage *msg) override;
void handleSelfMessage(cMessage *msg);
/*virtual void processStart();
virtual void processSend();
virtual void processStop();*/
// lifecycle
virtual void handleStartOperation(LifecycleOperation *operation) override { start(); }
virtual void handleStopOperation(LifecycleOperation *operation) override { stop(); }
virtual void handleCrashOperation(LifecycleOperation *operation) override { stop(); }
void start();
void stop();
virtual void socketDataArrived(UdpSocket *socket, Packet *packet) override;
virtual void socketErrorArrived(UdpSocket *socket, Indication *indication) override;
virtual void socketClosed(UdpSocket *socket) override;
//virtual void generateMTLSDPacket();
//virtual Packet *generateXEDPacket();
virtual double generateRandom();
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/TagBase_m.h"
#include "inet/networklayer/common/L3AddressTag_m.h"
#include <iterator>
using namespace std;
Define_Module(myApp);
myApp::~myApp()
{
EV << "App destructor" << endl;
cancelAndDelete(selfMsg);
}
void myApp::initialize(int stage)
{
ApplicationBase::initialize(stage);
if (stage == INITSTAGE_LOCAL)
{
sequencenumber = 0;
ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
event = new cMessage("event");
broadcastDelay = &par("broadcastDelay");
helloInterval = par("helloInterval");
localPort = par("localPort");
destPort = par("destPort");
packetName = par("packetName");
startTime = par("startTime");
stopTime = par("stopTime");
}
else if (stage == INITSTAGE_ROUTING_PROTOCOLS)
{
registerService(Protocol::manet, nullptr, gate("socketIn"));
registerProtocol(Protocol::manet, gate("socketOut"), nullptr);
}
}
void myApp::handleSelfMessage(cMessage *msg)
{
if (msg == event)
{
auto hello = makeShared<HelloMsg>();
Ipv4Address source = (interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress());
hello->setChunkLength(b(128));
hello->setSrcAddress(source);
sequencenumber += 2;
hello->setSequencenumber(sequencenumber);
hello->setNextAddress(source);
hello->setHopdistance(1);
auto packet = new Packet("Hello", hello);
packet->addTagIfAbsent<L3AddressReq>()->setDestAddress(Ipv4Address(255, 255, 255, 255));
packet->addTagIfAbsent<L3AddressReq>()->setSrcAddress(source);
packet->addTagIfAbsent<InterfaceReq>()->setInterfaceId(interface80211ptr->getInterfaceId());
packet->addTagIfAbsent<PacketProtocolTag>()->setProtocol(&Protocol::manet);
packet->addTagIfAbsent<DispatchProtocolReq>()->setProtocol(&Protocol::ipv4);
send(packet, "socketOut");
packet = nullptr;
hello = nullptr;
scheduleAt(simTime()+helloInterval+broadcastDelay->doubleValue(), event);
}
}
void myApp::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage())
{
handleSelfMessage(msg);
}
else if (check_and_cast<Packet *>(msg)->getTag<PacketProtocolTag>()->getProtocol() == &Protocol::manet)
{
auto recHello = staticPtrCast<HelloMsg>(check_and_cast<Packet *>(msg)->peekData<HelloMsg>()->dupShared());
if (msg->arrivedOn("socketIn"))
{
bubble("Received hello message");
Ipv4Address source = interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress();
Ipv4Address src;
unsigned int msgsequencenumber;
int numHops;
Ipv4Address next;
src = recHello->getSrcAddress();
msgsequencenumber = recHello->getSequencenumber();
next = recHello->getNextAddress();
numHops = recHello->getHopdistance();
if (src == source)
{
EV_INFO << "Hello msg dropped. This message returned to the original creator.\n";
delete msg;
return;
}
else
{
neighbors.push_back(src);
/*list<XED>::iterator findIter = find(ls.begin()->destinationAddr, ls.end()->destinationAddr, src);
if (findIter != ls.end()->destinationAddr)
{
}*/
source = (interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress());
//socket.bind(source, localPort);
auto xed = makeShared<XedMsg>();
xed->setChunkLength(b(128)); ///size of XED message in bits
xed->setSrcAddress(source);
xed->setDstAddress(src);
double random = generateRandom();
xed->setRandom(random);
//XED item = XED(source, src, random);
//ls.push_back(item);
auto packet = new Packet("XED", xed);
packet->addTagIfAbsent<L3AddressReq>()->setDestAddress(src);
packet->addTagIfAbsent<L3AddressReq>()->setSrcAddress(source);
packet->addTagIfAbsent<InterfaceReq>()->setInterfaceId(interfaceId);
packet->addTagIfAbsent<PacketProtocolTag>()->setProtocol(&Protocol::ipv4);
packet->addTagIfAbsent<DispatchProtocolReq>()->setProtocol(&Protocol::ipv4);
socket.setOutputGate(gate("socketOut"));
socket.setCallback(this);
socket.bind(source, localPort);
//emit(packetSentSignal, packet);
socket.sendTo(packet, src, destPort);
//send(packet, "socketOut");
packet = nullptr;
xed = nullptr;
/*Ipv4Address source = (interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress());
EV << "I am node " << source << ", my neighbors are : " << endl;
list<L3Address>::iterator it;
for (it = neighbors.begin(); it != neighbors.end(); ++it)
{
EV << it. << endl;
}
for (auto const& i : neighbors)
{
EV << i.str() << endl;
}*/
EV << "I am your neighbor " << src.str();
}
delete msg;
}
else if (check_and_cast<Packet *>(msg)->getTag<PacketProtocolTag>()->getProtocol() == &Protocol::ipv4)
{
EV << "Xed message received" << endl;
//auto recXed = staticPtrCast<XedMsg>(check_and_cast<Packet *>(msg)->peekData<XedMsg>()->dupShared());
}
else
throw cRuntimeError("Message arrived on unknown gate %s", msg->getArrivalGate()->getName());
}
}
void myApp::start()
{
/*socket.setOutputGate(gate("socketOut"));
socket.setCallback(this);*/
int num_80211 = 0;
InterfaceEntry *ie;
InterfaceEntry *i_face;
const char *name;
for (int i = 0; i < ift->getNumInterfaces(); i++)
{
ie = ift->getInterface(i);
name = ie->getInterfaceName();
if (strstr(name, "wlan") != nullptr)
{
i_face = ie;
num_80211++;
interfaceId = i;
}
}
if (num_80211 == 1)
{
interface80211ptr = i_face;
interfaceId = interface80211ptr->getInterfaceId();
}
else
throw cRuntimeError("Node has found %i 80211 interfaces", num_80211);
scheduleAt(simTime() + uniform(0.0, par("maxVariance").doubleValue()), event);
}
double myApp::generateRandom()
{
double lower_bound = 10000;
double upper_bound = 100000;
uniform_real_distribution<double> unif(lower_bound,upper_bound);
default_random_engine re;
double a_random_double = unif(re);
return a_random_double;
}
void myApp::stop()
{
cancelEvent(event);
socket.close();
delayActiveOperationFinish(par("stopOperationTimeout"));
}
void myApp::socketDataArrived(UdpSocket *socket, Packet *packet)
{
emit(packetReceivedSignal, packet);
EV_INFO << "Received packet: " << UdpSocket::getReceivedPacketInfo(packet) << endl;
}
void myApp::socketErrorArrived(UdpSocket *socket, Indication *indication)
{
EV_WARN << "Ignoring UDP error report " << indication->getName() << endl;
delete indication;
}
void myApp::socketClosed(UdpSocket *socket)
{
if (operationalState == State::STOPPING_OPERATION)
startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime"));
}
Error: NED type 'myApp' could not be fully resolved due to a missing base type or interface, at /home/bocuhra/Downloads/omnetpp-5.4.1/samples/SaaS/myApp.ned:18
myApp.cc
HelloMsg_m.cc
XedMsg_m.cc
Creating executable: out/gcc-release//SaaS
/usr/bin/ld: cannot find -lINET
collect2: error: ld returned 1 exit status
Makefile:104: recipe for target 'out/gcc-release//SaaS' failed
make: *** [out/gcc-release//SaaS] Error 1