Omnet ++如何子类化我自己的节点

时间:2017-11-03 13:18:04

标签: c++ omnet++

我已经在omnet ++中编写了我的节点。这里称为SAodv的是示例代码。整个代码表示简单的模块行为。

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <omnetpp.h>
#include "aodvrreqmsg_m.h"
#include "aodvrrepmsg_m.h"
#include "pingmsg_m.h"
#include "self_ping_retransmit_m.h"
#include "aodvrerrmsg_m.h"

using namespace omnetpp;

struct ID_table_element
{
    std::string src_node_ip;
    double last_id;
};

struct Routing_table_element
{
    std::string destination;
    std::string next_hop;
    int hop_count;
    double dst_seq;
    int lifetime;
};

struct Ping_table_element
{
    std::string destination;
    int id;
    int received; //0 - no , 1-yes
};

class SAodv : public cSimpleModule
{
    private:
        long ping_replies_received = 0;
        long messages_sent = 0;
        long rreqs_sent = 0;
        long rreps_sent = 0;
        long rrers_sent = 0;
        long rreqs_generated = 0;
        long rreps_generated = 0;
        long rrers_generated = 0;

  protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
    virtual void finish() override;
    virtual AodvRREQmsg *generateRREQ(const char* src_mac, const char* src, const char* dst, int hop_count, double rreq_id, const char* dst_ip, long dst_seq, const char* src_ip, long src_seq);
    ...
    ...
    ...
    ...
    virtual int return_host_id(const char* node_name);
    double current_rreq_id;
    long current_seq_id;
    int mobility_direction;
    std::list<ID_table_element> id_table;
    std::list<Routing_table_element> routing_table;
    std::list<Ping_table_element> ping_table;

};

Define_Module(SAodv);

现在我想使用此节点的功能并仅更改某些功能。我试过这个。

#include "aodvrreqmsg_m.h"
#include "aodvrrepmsg_m.h"
#include "pingmsg_m.h"
#include "self_ping_retransmit_m.h"
#include "aodvrerrmsg_m.h"

using namespace omnetpp;

struct ID_table_element
{
    std::string src_node_ip;
    double last_id;
};

struct Routing_table_element
{
    std::string destination;
    std::string next_hop;
    int hop_count;
    double dst_seq;
    int lifetime;
};

struct Ping_table_element
{
    std::string destination;
    int id;
    int received; //0 - no , 1-yes
};

class AODV_rreq_attack : public SAodv
{
};

Define_Module(AODV_rreq_attack);

但我甚至无法建立它有以下错误:

cannot convert 'AODV_rreq_attack*' to 'omnetpp::cModule*' in initialization aodv_rreq_attack.cc /SimpleAodvRouting  line 45 C/C++ Problem - in Define_module row

expected class-name before '{' token    aodv_rreq_attack.cc /SimpleAodvRouting  line 42 C/C++ Problem - risght after class

如何扩展现有类并仅覆盖某些选定的函数?是否也应在我的NED文件中指定extends

0 个答案:

没有答案