⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntable.h

📁 CBRP协议(移动adhoc中基于分簇的路由协议)ns2下的源码
💻 H
字号:
/* ntable.h -*- c++ -*-NeighborTable is maintained by each node.   */#ifndef ntable_h_#define ntable_h_#include "config.h"#include "scheduler.h"#include "queue.h"#include "cbrpagent.h"#define BIG   250#define MAX_NODE_NUM                  150  #define CBRP_BROADCAST_JITTER 0.15#define CBRP_STARTUP_JITTER 0.1     #define CLUSTER_UNDECIDED              0#define CLUSTER_MEMBER                 1#define CLUSTER_HEAD                   2#define LINK_BIDIRECTIONAL             3#define LINK_TO                        4  //from me TO the other#define LINK_FROM                      5 // to me FROM the other#define TIMEOUT_INTEVAL                 3.0#define BROADCAST_INTEVAL                   2.0typedef unsigned int uint;/* NOTE: we depend on bzero setting the booleans to ``false''   but if false != 0, so many things are screwed up, I don't   know what to say... */class NeighborTablePeriodicHandler;class NeighborTableTimeoutHandler;class NeighborTableCFormationHandler;class ntable_ent {public:  ntable_ent() { bzero(this, sizeof(struct ntable_ent));}  nsaddr_t     neighbor;         //target node   uint         neighbor_status;  //whether neighbor is a cluster member,                                  //head or undecided  uint         link_status;      // whether the link with this neighbor is                                 // bidirectional or unidirectional link  double       last_update;      //last update time for this entry  Packet*      n_pkt;  Event*       timeout_event;    //time out event sent out  ntable_ent   *next;            //pointer to the next entry};class nexthop_ent {public:  nexthop_ent() { bzero(this,sizeof(struct nexthop_ent)); }  nsaddr_t     next_node;  Event*       timeout_event;  nexthop_ent  *next;};class adjtable_ent {public:  adjtable_ent() { bzero(this, sizeof(struct adjtable_ent));}  nsaddr_t     neighbor_cluster; //the neighboring cluster head  nexthop_ent  *next_hop;        //the next hop node in order to reach neighbor_cluster   adjtable_ent *next;            //pointer to the next adjtable_ent};class nextnode {public:  nextnode() {bzero(this,sizeof(struct nextnode));}  nsaddr_t    the_node;  nsaddr_t    dest_status;  double      last_updated;};       class NeighborTable {  friend class NeighborTablePeriodicHandler;  //The handler function inside is invoked periodically to send out BROADCAST messages  friend class NeighborTableTimeoutHandler;   // The handler function inside is invoked to remove outdated neighbortable entry  friend class NeighborTableCFormationHandler; // The handler function is invoked to perform cluster formation algorithm.  friend class NeighborTableCContentionHandler; // The handler function is invoked to resolve cluster head contention  friend class CBRP_Agent;                                                                                           public:    NeighborTable(CBRP_Agent *a_);    void AddUpdateEntry(ntable_ent *ent);    int DeleteEntry(nsaddr_t dest);    ntable_ent *GetEntry(nsaddr_t dest);    bool isNeighbor(nsaddr_t addr);    /* we chose a lazy way to implement the two-hop-topology database       it's implemented using an array whose index X is the node X one        can reach in two hop s and the element kept at the index would        contain info. on the 1-hop-neighbor in order to reach X This is        not a good solution for large sized network, nevertheless it's        simple to keep and fast to check The function AddUpdateQuickAdj(..)        is for updating this array.       -Jinyang */    void AddUpdateQuickAdj(nsaddr_t dest, uint dest_status, nsaddr_t next_node);    nsaddr_t GetQuickNextNode(nsaddr_t dest);    bool existsLink(nsaddr_t from, nsaddr_t to);    /* we kept two cluster adjacency tables, one(primary) is for keeping info. abt two-hop away neighbor clusters    the other one (!primary) is for keeping info. abt 3-hop away neighboring clusters */    void AddUpdateAdj(nsaddr_t dest, nsaddr_t next_hop, int primary);    void DeleteAdjEntry(nsaddr_t dest,int primary);    adjtable_ent *GetAdjEntry(nsaddr_t dest_cluster, int primary);    int RemainingLoop();    void InitLoop();    ntable_ent *NextLoop();    Packet *getUpdatePacket();    Packet *getBroadcastPacket();    void processUpdate(Packet *);    void startUp();#ifdef CBRP_DEBUG    char *printNeighbors();    char *printHELLOpkt(Packet *p);    char *PrintTwoHopNeighbors();#endif    uint no_of_clusterheads;    uint my_status;  //whether I am undecided, cluster head or member only    uint my_size;    uint adjtable_size;    Event *periodic_event;    Event *c_form_event;    Event *c_contention_event;    NeighborTablePeriodicHandler *periodic_handler;    NeighborTableTimeoutHandler *timeout_handler;    NeighborTableCFormationHandler *c_formation_handler;    NeighborTableCContentionHandler *c_contention_handler;  protected:    void lostClusterHeads();    nextnode *adjtable;    adjtable_ent *adjtable_1;    adjtable_ent *adjtable_2;  private:    CBRP_Agent *a;    ntable_ent *head;    ntable_ent *prev;    ntable_ent *now;    int         in_contention;    int         maxelts;    int         ctr;    double *last_update;  // a supplementary table used to updating the main one};        class NeighborTablePeriodicHandler : public Handler {    public:    NeighborTablePeriodicHandler(CBRP_Agent *a_, NeighborTable *t_);    virtual void handle(Event *e);  private:    NeighborTable *t;    CBRP_Agent *a;    Event *periodic_event_;};class NeighborTableTimeoutHandler : public Handler {    public:    NeighborTableTimeoutHandler(CBRP_Agent *a_, NeighborTable *t_);     virtual void handle(Event *e);    int checkAdjTimeout(Event *e, int primary);  private:    NeighborTable *t;    CBRP_Agent *a;};class NeighborTableCFormationHandler : public Handler {  public:    NeighborTableCFormationHandler(CBRP_Agent *a_, NeighborTable *t_);    virtual void handle(Event *e);  private:    NeighborTable *t;    CBRP_Agent *a;};class NeighborTableCContentionHandler: public Handler {  public:    NeighborTableCContentionHandler(CBRP_Agent *a_, NeighborTable *t_);    virtual void handle(Event *e);  private:    NeighborTable *t;    CBRP_Agent *a;}; #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -