覆盖功能不执行EV<<命令?

时间:2015-10-17 20:36:33

标签: override omnet++ tcpreplay

我使用的是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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

  • 确保已注册的类具有宏&gt;&gt; Define_Module(....); (似乎已经完成)
  • 确保Class已链接&gt;&gt;你应该能够得到完整的清单 通过使用&#34; -h运行模拟中的所有注册类 类&#34;选项
  • 验证ned文件中的名称是否与配置文件cc
  • 相同
  • 尝试右键单击项目的文件夹 属性&gt;&gt; Omnet ++&gt;&gt; Makemake&gt;&gt;应用