我使用的是Omnet ++ 4.6,我創建了一個類來繼承AODVRouting。現在,我在我的新類中創建了一個覆蓋父類的handleMessage()
的函數。編譯器指示該函數確實被覆蓋。我鍵入一個EV<<
命令將該函數的開頭打印到事件日誌,但它不打印到事件日誌。問題是什麼??覆蓋功能不執行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
我這樣做,這不是我意思。由於某種原因,我傾向於認爲我的重寫函數沒有被調用......只有父類函數被調用:( –