使用omnet ++覆盖函数

时间:2015-05-16 15:37:47

标签: c++ override omnet++ inet

如何在omnet ++中覆盖包含类的函数?
当我尝试像在c ++中那样覆盖函数时,我得到了重新定义错误。

  

重新定义“handleMessage(cMessage * msg)”

这是当前的代码:

#include "MalAODVRouter.h"
#include "AODVRouting.cc"
#include "AODVRouting.h"

Define_Module(MalAODVRouter);

void AODVRouting::handleMessage(cMessage *msg) // Error here
{
    //-----------------------------------------------------Added to Simulate COPS

        std::string currentMsg=msg->getName();

            if(BF->CheckBloom(currentMsg)==1)
                bubble("Replayed!!");
            else
                {
                    BF->AddToBloom(currentMsg);
                    bubble("Legit Packet");
                    std::cout<<"Legitimate. Packet is added to the Bloom Filter.\n";
                }
     //-----------------------------------------------------------------------------

    if (!isOperational) {
        if (msg->isSelfMessage())
            throw cRuntimeError("Model error: self msg '%s' received when isOperational "
                "is false", msg->getName());

        EV_ERROR << "Application is turned off, dropping '" << msg->getName()
            << "' message\n";
        delete msg;
    }

    if (msg->isSelfMessage()) {
        if (dynamic_cast<WaitForRREP *>(msg))
            handleWaitForRREP((WaitForRREP *)msg);
        else if (msg == helloMsgTimer)
            sendHelloMessagesIfNeeded();
        else if (msg == expungeTimer)
            expungeRoutes();
        else if (msg == counterTimer) {
            rreqCount = rerrCount = 0;
            scheduleAt(simTime() + 1, counterTimer);
        }
        else if (msg == rrepAckTimer)
            handleRREPACKTimer();
        else if (msg == blacklistTimer)
            handleBlackListTimer();
        else
            throw cRuntimeError("Unknown self message");
    }
    else {
        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();
        unsigned int arrivalPacketTTL = udpProtocolCtrlInfo->getTimeToLive();

        switch (ctrlPacket->getPacketType()) {
            case RREQ:
                handleRREQ(check_and_cast<AODVRREQ *>(ctrlPacket), sourceAddr,
                    arrivalPacketTTL);
                break;
            case RREP:
                handleRREP(check_and_cast<AODVRREP *>(ctrlPacket), sourceAddr);
                break;
            case RERR:
                handleRERR(check_and_cast<AODVRERR *>(ctrlPacket), sourceAddr);
                break;
            case RREPACK:
                handleRREPACK(check_and_cast<AODVRREPACK *>(ctrlPacket), sourceAddr);
                break;
            default:
                throw cRuntimeError("AODV Control Packet arrived with undefined packet "
                    "type: %d", ctrlPacket->getPacketType());
        }
        delete udpPacket;
    }
}

1 个答案:

答案 0 :(得分:0)

您有两个版本的AODVRouting::handleMessage(cMessage *msg)功能。来自#include "AODVRouting.cc" AODVRouting.cc 中的一个来自您当前文件中的一个,您已粘贴代码,但我们不知道该名称。

从当前文件中删除#include "AODVRouting.cc"行,或重命名您的类,使其不与AODVRouting类名称重叠。