我的问题是这样的:我使用简单的模块my_app see image 1在omnet ++中创建了一个自定义主机。我希望该模块的行为类似于生成消息的应用程序,并且在收到来自较低层的消息时也会得到通知。当我在网络中添加主机并运行模拟时,出现以下错误。 see image 2
这是我的c ++文件(my_app.cc和my_app.h)`
#ifndef __MYAPP_MY_APP_H_
#define __MYAPP_MY_APP_H_
#include <omnetpp.h>
using namespace omnetpp;
/**
* TODO - Generated class
*/
class My_app : public cSimpleModule
{
int type;
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
#endif`
my_app.cc`
#include "my_app.h"
Define_Module(My_app);
void My_app::initialize()
{
this->type=par("type");
if (this->type==1){ // 1 for source
cMessage *msg=new cMessage("welcome");
send(msg,"out");
}
}
void My_app::handleMessage(cMessage *msg)
{
if (msg->arrivedOn("My_app_In"))
{
if (this->type==2){ // 2 for sink
delete(msg);
}
else
{
cMessage *msg=new cMessage("welcome");
send(msg,"My_app_Out");
}
}
else
{
error("Incorrect gate");
}
}
` 这是ned文件。 my_app.ned
`package myapp.simulations;
//
// TODO auto-generated module
//
simple My_app
{
parameters:
int type;
gates:
input My_app_In;
output My_app_Out;
}`
host.ned
`package myapp.simulations;
import inet.applications.contract.IUDPApp;
import inet.applications.pingapp.PingApp;
import inet.common.lifecycle.NodeStatus;
import inet.common.packet.PcapRecorder;
import inet.linklayer.contract.IExternalNic;
import inet.linklayer.contract.ITunNic;
import inet.linklayer.contract.IWiredNic;
import inet.linklayer.contract.IWirelessNic;
import inet.linklayer.loopback.LoopbackInterface;
import inet.mobility.contract.IMobility;
import inet.networklayer.contract.IRoutingTable;
import inet.networklayer.common.InterfaceTable;
import inet.networklayer.contract.INetworkLayer;
import inet.power.contract.IEnergyStorage;
import inet.power.contract.IEnergyGenerator;
import inet.applications.contract.IUDPApp;
import inet.transportlayer.contract.IUDP;
module Host
{
parameters:
@display("bgb=486,475");
@networkNode;
@labels(node,ethernet-node,wireless-node);
bool hasStatus = default(false);
int numExtInterfaces = default(0);
int numRadios = default(0); // the number of radios in the router. by default no wireless
int numPcapRecorders = default(0); // no of PcapRecorders.
int numTunInterfaces = default(0);
string mobilityType = default(numRadios > 0 ? "StationaryMobility" : "");
string networkLayerType = default("IPv4NetworkLayer");
string routingTableType = default("IPv4RoutingTable");
bool forwarding = default(true);
bool multicastForwarding = default(false);
string energyStorageType = default("");
string energyGeneratorType = default("");
routingTable.forwarding = forwarding;
routingTable.multicastForwarding = multicastForwarding; // for IPv4, IPv6, Generic
*.interfaceTableModule = default(absPath(".interfaceTable"));
*.routingTableModule = default(routingTableType != "" ? absPath(".routingTable") : "");
*.energySourceModule = default(energyStorageType != "" ? absPath(".energyStorage") : "");
*.mobilityModule = default(mobilityType != "" ? absPath(".mobility") : "");
string udpType = default(firstAvailableOrEmpty("UDP"));
@display("i=block/circle");
gates:
input radioIn[numRadios] @directIn;
submodules:
My_app: My_app {
@display("p=271,150");
}
status: NodeStatus if hasStatus {
@display("p=50,50");
}
energyStorage: <energyStorageType> like IEnergyStorage if energyStorageType != "" {
parameters:
@display("p=50,100;i=block/plug;is=s");
}
energyGenerator: <energyGeneratorType> like IEnergyGenerator if energyGeneratorType != "" {
parameters:
@display("p=50,150;i=block/plug;is=s");
}
// optional mobility module. Required only if wireless cards are present
mobility: <mobilityType> like IMobility if mobilityType != "" {
parameters:
@display("p=53,200");
}
// network layer
networkLayer: <networkLayerType> like INetworkLayer {
parameters:
@display("p=271,281;q=queue");
}
// routing table
routingTable: <routingTableType> like IRoutingTable if routingTableType != "" {
parameters:
@display("p=53,250;is=s");
}
// linklayer
interfaceTable: InterfaceTable {
parameters:
@display("p=53,300;is=s");
}
pcapRecorder[numPcapRecorders]: PcapRecorder {
@display("p=53,350,r,10");
}
lo0: LoopbackInterface {
@display("p=145,406");
}
wlan[numRadios]: <default("Ieee80211Nic")> like IWirelessNic {
parameters:
@display("p=407,406,row,60;q=queue");
}
connections allowunconnected:
networkLayer.transportOut++ --> My_app.My_app_In;
networkLayer.transportIn++ <-- My_app.My_app_Out;
// connections to network outside
networkLayer.ifOut++ --> lo0.upperLayerIn;
lo0.upperLayerOut --> networkLayer.ifIn++;
for i=0..sizeof(radioIn)-1 {
radioIn[i] --> { @display("m=s"); } --> wlan[i].radioIn;
wlan[i].upperLayerOut --> networkLayer.ifIn++;
wlan[i].upperLayerIn <-- networkLayer.ifOut++;
}
}
`
请帮助我。 谢谢
答案 0 :(得分:0)
很难说,但是我的猜测是,每当您在项目中添加一些新类时,您都必须重新生成Makefile。还要确保将.cc和.h文件添加到“源”文件夹中。 (通常在OMNeT ++项目中默认为'src')。通过链接到一个正在使用INET项目的单独项目,也有可能以某种方式仅启动INET项目,而不是您自己的项目。