OMNET++ How to retain all functions in AODVRouting

2019-09-17 11:29发布

问题:

I'm writting a simple module to simulate a misbehaved node that inherits all functions from AODRouting, and overriding sendAODVPacket function by dropping the AODV packet once it has received it. The .h file as follows:

#ifndef __PROJECT1_SELFISHBASENODE_H_
#define __PROJECT1_SELFISHBASENODE_H_

#include <omnetpp.h>
#include "AODVRouting.h"

using namespace inet;

class SelfishBaseNode : public AODVRouting
{

protected:
virtual void initialize();
virtual void sendAODVPacket(AODVControlPacket *packet, const L3Address&     destAddr, unsigned int timeToLive, double delay) override;

};

#endif

The CC file as follows:

#include "SelfishBaseNode.h"
#include <string.h>
#include <omnetpp.h>

Define_Module(SelfishBaseNode);

void SelfishBaseNode::initialize()
{
}


void SelfishBaseNode::sendAODVPacket(AODVControlPacket *packet, const L3Address& destAddr, unsigned int timeToLive, double delay)
{
    EV << "Received message, dropping message now\n";
    delete packet;
}

.NED file as follows:

package project1;


import inet.node.aodv.AODVRouter;

module snode extends AODVRouter
{
    parameters:
    //@networkNode;
    @display("i=device/wifilaptop");
    @labels(wireless-node);
    @class(SelfishBaseNode);

       submodules:
        bad: SelfishBaseNode {
        @display("p=273,350");
    }
}

When I rebuild my project, i got these error:

SelfishBaseNode.h:35:18: error: 'sendAODVPacket' marked 'override' but does not override any member functions.

Any ideas how to fix this?

回答1:

The method sendAODVPacket() is declared in AODVRouting.h without virtual. You should add virtual before declaration of sendAODVPacket() in AODVRouting class in AODVRouting.h



标签: c++ omnet++ inet