如何在omnet++无线主机中添加新的应用模块

how to add a new application module in wireless host in omnet ++

我的问题是这样的:我在 omnet++ 中创建了一个自定义主机,其中包含一个名为 my_app see image 1. I want this module to behave like an application that generates messages and also get notified when a message is received from the lower layers. when I add hosts in the network and run the simulation I get the following errors. 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++;
        }
}
`

请帮帮我。 谢谢

这很难说,但我的猜测是您每次添加一些新的 类 项目时都必须重新生成 Makefile。还要确保将 .cc 和 .h 文件添加到 'source' 文件夹中。 (通常在 OMNeT++ 项目中默认为 'src')。也有可能您正在使用一个单独的项目,该项目通过链接使用 INET 项目,并且您以某种方式仅启动 INET 项目而不是您自己的项目。