-1

我正在使用 Omnet++ 4.6,并创建了一个类来继承 AODVRouting。现在,我在我的新类中创建了一个handleMessage()从父类覆盖的函数。编译器指示该函数确实被覆盖。我输入了一个EV<<命令将函数的开始打印到事件日志,但它没有打印到事件日志。问题是什么??

父类中的函数是虚拟的和受保护的。这是我继承的class.cc:

//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 


#include "MalAODVRouter.h"
#include "IPv4ControlInfo.h"

Define_Module(MalAODVRouter);
MalAODVRouter::MalAODVRouter()
{
    AODVRouting::AODVRouting();
}
void MalAODVRouter::initialize(int stage)
{
    AODVRouting::initialize(stage);
}

void MalAODVRouter::handleMessage(cMessage *msg)
{
    std::cout<<"Mal Host Activity"<<endl;
    EV <<"Mal Host Activity \n";
    this->bubble("Mal Host Activity");


    //capturedMsgs++;
    //if (capturedMsgs==1) // One out of every 10 packets (frequency of replay)
    //{
        cMessage *ReplayMsg = msg->dup();
        std::cout<<"Done Duplicating MSG"<<endl;
        EV<<"Done Duplicating MSG \n";

        /*UDPPacket *udpPacket = dynamic_cast<UDPPacket *>(msg);
        AODVControlPacket *ctrlPacket = check_and_cast<AODVControlPacket *>(udpPacket->decapsulate());
        IPv4ControlInfo *udpProtocolCtrlInfo = dynamic_cast<IPv4ControlInfo *>(udpPacket->getControlInfo());
        ASSERT(udpProtocolCtrlInfo != NULL);
        IPv4Address sourceAddr = udpProtocolCtrlInfo->getSrcAddr();         //get Source Address
        IPv4Address destinationAddr = udpProtocolCtrlInfo->getDestAddr();   //get Destination Address
        IPv4Address addr = getSelfIPAddress();
        if (addr != destinationAddr)      // if it is not destined for "Eve"
        {
            UDPPacket *ReplayUDPPacket = udpPacket;
            AODVControlPacket *ReplayCtrlPacket = check_and_cast<AODVControlPacket *>(ReplayUDPPacket->decapsulate());
            IPv4ControlInfo *ReplayUDPProtocolCtrlInfo = dynamic_cast<IPv4ControlInfo *>(ReplayUDPPacket->getControlInfo());
            ASSERT(ReplayUDPProtocolCtrlInfo != NULL);
            ReplayUDPProtocolCtrlInfo->setSrcAddr(sourceAddr);          //Forge Source
            ReplayUDPProtocolCtrlInfo->setDestAddr(destinationAddr);    //Keep Destination

*/

            //we can add a delay before sending the copy of the message again (10 time units)
        scheduleAt(simTime() + 1, ReplayMsg);
        //sendDelayed(ReplayMsg, 0.1,"ipOut");
        ReplayedMsgs++;
        std::cout<<"Launched Replay Packet!\n";
        EV<<"Launched Replay Packet!\n";
        this->bubble("Attack");

            //this->capturedMsgs=0;
       // }
    //}
    AODVRouting::handleMessage(msg);
    std::cout<<"Finished handling msg"<<endl;
    EV<<"Finished handling msg"<<endl;

}

/*void MalAODVRouter::finish()
{

    recordScalar("captured Msgs", capturedMsgs);
    recordScalar("Replayed Msgs", ReplayedMsgs);

    }*/


MalAODVRouter::~MalAODVRouter()
{
    AODVRouting::~AODVRouting();
}

这是我的 .h 文件:

//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef __COPS_MALAODVROUTER_H_
#define __COPS_MALAODVROUTER_H_
#include "AODVRouting.h"
#include <omnetpp.h>


/**
 * TODO - Generated class
 */

class MalAODVRouter : public AODVRouting
{
protected:
    virtual void initialize(int stage) override;
    virtual void handleMessage(cMessage *msg) override;

public:
    MalAODVRouter();
    //finish();
    ~MalAODVRouter();
    int capturedMsgs=0;
    int ReplayedMsgs=0;

};

#endif
4

2 回答 2

1

为了查看自己生成的消息,EV您需要将日志查看器切换到“模块输出”模式。开始模拟,然后在右下角的窗口中按最右边的图标。

于 2015-10-17T21:52:27.817 回答
0
  • 确保已注册类具有宏 >> Define_Module(....); (似乎完成了)
  • 确保 Class 已链接 >> 您应该能够通过使用“-h classes”选项运行它来获得模拟中所有已注册类的完整列表
  • 验证ned文件中的名称是否与配置文件cc一致
  • 试试这个右键单击项目的文件夹 Properties >> Omnet++ >> Makemake >> Apply
于 2016-11-17T14:36:32.460 回答