-1

I'm using Omnet++ 4.6 and I created a class to inherit AODVRouting. Now, I created a function in my new class that overrides handleMessage() from the parent class. Compiler indicates that the function is indeed overridden. I typed an EV<< command to print the start of the function to event log, yet it does not print to the event log. What is the problem??

Function in the the parent class is virtual and protected. This is my inherited 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();
}

And this is my .h file:

//
// 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
Shaikha TheGreen
  • 115
  • 2
  • 12

2 Answers2

1

In order to view own messages generated by EV you need to switch log viewer to "module output" mode. Start the simulation, and in the bottom right window press the rightmost icon.

Jerzy D.
  • 6,707
  • 2
  • 16
  • 22
  • I did that, it's not what I meant. For some reason I'm tending to think that my overriding function is not invoked... Only the parent class function is invoked :( – Shaikha TheGreen Oct 18 '15 at 14:48
0
  • Make sure Class is registered has the macro >> Define_Module(....); (seems done)
  • Make sure Class is linked >> you should be able to get a full list of all registered classes in your simulation by running it with the "-h classes" option
  • Verify that the name in the ned file is the same as the configuration file cc
  • try this right click on the folder of the project Properties >> Omnet++ >> Makemake >> Apply
Mour_Ka
  • 270
  • 1
  • 15