簡體   English   中英

如何在omnet ++中的無線主機中添加新的應用程序模塊

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

我的問題是這樣的:我在omnet ++中創建了一個名為my_app的簡單模塊的自定義主機,請參見圖1 我希望該模塊的行為類似於生成消息的應用程序,並且在收到來自較低層的消息時也會得到通知。 當我在網絡中添加主機並運行模擬時,出現以下錯誤。 見圖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文件添加到“源”文件夾中。 (通常在OMNeT ++項目中默認為'src')。 也有可能您通過鏈接使用正在使用INET項目的單獨項目,並且以某種方式僅啟動了INET項目,而不是自己的項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM