ns-allinone-2.33_ZRP.tar.gz

  • PUDN用户
    了解作者
  • C++ Builder
    开发工具
  • 28KB
    文件大小
  • gz
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 165
    下载次数
  • 2010-10-29 22:19
    上传日期
zrp protocol in ns-2.33
ns-allinone-2.33_ZRP.tar.gz
  • ns-allinone-2.33
  • ns-2.33
  • zrp
  • zrp.cc
    109.3KB
  • zrp.h
    28.4KB
  • constants.h
    2.3KB
内容介绍
#ifndef _zrp_h_ #define _zrp_h_ /* [SECTION-1]------------------------------------------------------------------ * INIT SECTION:- HEADERS AND PRE-PROCESSOR MACROS. * ----------------------------------------------------------------------------- */ #include <config.h> #include <assert.h rel='nofollow' onclick='return false;'> #include <agent.h rel='nofollow' onclick='return false;'> #include <packet.h> #include <ip.h> #include <delay.h> #include <scheduler.h> #include <queue.h> #include <trace.h> #include <arp.h rel='nofollow' onclick='return false;'> #include <ll.h> #include <mac.h> #include <priqueue.h> #include <delay.h> #include <random.h> #include <object.h> #include <route.h> #include <cmu-trace.h> #include "constants.h" #if defined(WIN32) && !defined(snprintf) #define snprintf _snprintf #endif /* WIN32 && !snprintf */ #if !defined(NULL) /* Defining NULL = 0 */ #define NULL 0 #endif /* [SECTION-2]------------------------------------------------------------------ * NDP (NEIGHBOR DISCOVERY PROTOCOL):- SUBSECTIONS CONTAINS FOLLOWING THINGS: * 1) NEIGHBOR-LIST (Neighbor Table) * 2) BEACON-TRANSMIT TIMER (Periodic Beacon Xmission) * 3) ACK-TIMEOUT TIMER (ACK-Timeout Checking) * 4) NDP AGENT (Neighbor Discovery Agent) * ----------------------------------------------------------------------------- * [SUB-SECTION-2.1]------------------------------------------------------------ * NEIGHBOR-LIST:- NEIGHBOR TABLE AND ASSOCIATED FUNCTIONS * ----------------------------------------------------------------------------- */ /*! \class Neighbor \brief This class contains NEIGHBOR NODE information. */ class Neighbor { public: nsaddr_t addr_; // 32 bit Address Time lastack_; // Last ACK received Time int linkStatus_; // Link-Status with this Neighbor int AckTOCount_; // No-of-times ACK-TO has occured with this Nb Neighbor *next_; // Pointer to Next Element // Constructors... Neighbor() : addr_(-1), lastack_(-1), linkStatus_(LINKDOWN), next_(NULL) {} // Initialize with Invalid Entries Neighbor(nsaddr_t addr, Time lastack, int linkStatus) : addr_(addr), lastack_(lastack), linkStatus_(linkStatus), AckTOCount_(0), next_(NULL) {} }; /*! \class NeighborList \brief This class is the linked-list of Neighbor class. */ class NeighborList { public: Neighbor *head_; // Pointer to head int numNeighbors_; // Number of Neighbors // Constructors... NeighborList() : head_(NULL), numNeighbors_(0) {} // Methods... void addNeighbor(nsaddr_t addr, Time lastack, int linkStatus); int findNeighbor(nsaddr_t addr, Neighbor **handle); int isEmpty(); void removeNeighbor(Neighbor *prev, Neighbor *toBeDeleted); void purgeDownNeighbors(); void freeList(); void printNeighbors(); }; class ZRPAgent; // Pre-Declaration... [Needed for Timers] /* [SUB-SECTION-2.2]------------------------------------------------------------ * BEACON-TRANSMIT TIMER:- PERIODIC BEACON XMISSION * ----------------------------------------------------------------------------- */ /*! \class NDPBeaconTransmitTimer \brief This class implements a BEACON Transmit Timer, who periodically sends beacons to NEIGHBOR nodes. */ class NDPBeaconTransmitTimer : public Handler { public: // Data... ZRPAgent *agent_; // Pointer to ZRP-Agent Event intr_; int beacon_period_; // Inter-Beacon-Time int beacon_period_jitter_; // Jitter added to Inter-Beacon-Time int neighbor_ack_timeout_; // Only for Logging // Constructor... NDPBeaconTransmitTimer(ZRPAgent* agent) : agent_(agent), beacon_period_(DEFAULT_BEACON_PERIOD), beacon_period_jitter_(DEFAULT_BEACON_PERIOD_JITTER), neighbor_ack_timeout_(DEFAULT_NEIGHBOR_ACK_TIMEOUT) {} void handle(Event*); // function handling the event void start(double thistime); }; /* [SUB-SECTION-2.3]------------------------------------------------------------ * ACK-TIMEOUT TIMER:- ACK-TIMEOUT CHECKING * ----------------------------------------------------------------------------- */ /*! \class NDPAckTimer \brief This class implements a Acknoledgement TimeOut Timer, who checks that ACK is received or not for sent beacon. */ class NDPAckTimer : public Handler { public: ZRPAgent *agent_; // Pointer to ZRP-Agent Event intr_; int neighbor_ack_timeout_; // Time before a neighbor must send ACK // Constructor... NDPAckTimer(ZRPAgent* agent) : agent_(agent), neighbor_ack_timeout_(DEFAULT_NEIGHBOR_ACK_TIMEOUT) {} void handle(Event*); // function handling the event void start(); }; /* [SUB-SECTION-2.4]------------------------------------------------------------ * NDP AGENT:- NEIGHBOR DISCOVERY AGENT * ----------------------------------------------------------------------------- */ /*! \class NDPAgent \brief This class implements the Neighbor Discovery Protocol (NDP). */ class NDPAgent { public: // Data... ZRPAgent *agent_; // Pointer to ZRP-Agent NeighborList neighborLst_; // Neighbor List NDPBeaconTransmitTimer BeaconTransmitTimer_; // Beacon-Xmit-Timer NDPAckTimer AckTimer_; // ACK-TO-Timer int startup_jitter_; // For starting the Timers // Constructors... /*! \fn NDPAgent(ZRPAgent *) This constructor is called by the constructor of ZRP. It initializes different compenents in NDP. */ NDPAgent(ZRPAgent *agent) : agent_(agent), BeaconTransmitTimer_(agent), AckTimer_(agent), startup_jitter_(DEFAULT_STARTUP_JITTER) {} // Methods... /*! \fn void startUp() This is called by ZRPAgent::startUp() method. It does following tasks: \n - Starts the Beacon-Transmit-Timer. \n - Clears the Neighbor-List. */ void startUp(); /*! \fn void recv_NDP_BEACON(Packet* p) This function is called whenever ZRP receives an NDP_BEACON packet. On receving 'NDP_BEACON', node sends 'NDP_BEACON_ACK' to the sender. But it does not add this neighbor, because node stores only symmetric links. */ void recv_NDP_BEACON(Packet* p); /*! \fn void recv_NDP_BEACON_ACK(Packet* p) This function is called whenever ZRP receives an NDP_BEACON_ACK packet. \n - If it's a new neighbor, node adds the neighbor to its 'NEIGHBOR_TABLE' and notifies IARP to rebuild the 'INNER_ROUTING_TABLE' and 'PERIPHERAL_NODE_TABLE'. \n - If it's an existing neighbor, it updates 'LAST_ACK_TIME' for that neighbor. */ void recv_NDP_BEACON_ACK(Packet* p); /*! \fn void print_tables() This function prints the Neighbor-List. It also prints which Neighbors are UP and which are DOWN. */ void print_tables(); }; /* [SECTION-3]------------------------------------------------------------------ * IARP (INTRA-ZONE ROUTING PROTOCOL):- SUBSECTIONS CONTAINS FOLLOWING THINGS: * 1) LINKSTATE LIST (Topology Table) * 2) PERIPHERAL-NODE LIST (Peripheral-Node Table) * 3) INNER-ROUTE LIST (Inner-Route Table) * 4) UPDATE-DETECT LIST (Update-detect Cache) * 5) PERIODIC-UPDATE TIMER (Periodic Update Xmission) * 6) EXPIRATION-CHECK TIMER (For Expiration of LinkState and Routes) * 7) IARP AGENT (IntrA-Zone Routing Agent) * ----------------------------------------------------------------------------- * [SUB-SECTION-3.1]------------------------------------------------------------ * LINKSTATE LIST:- TOPOLOGY TABLE * ----------------------------------------------------------------------------- */ class LinkState { public: // Data... nsaddr_t src_; // 32 bits nsaddr_t dest_; // 32 bits int seq_; // sequence number int isup_; // Link State LINKUP[1]/LINKDOWN[0] Time expiry_; // Link Expiry Time LinkState *next_; // Pointer to Next Element // Constructors... LinkState() : src_(-1), dest_(-1), seq_(-1), isup_(-1), expiry_(-1.0), next_(NULL) {} LinkState(nsaddr_t src, nsaddr_t dest, int seq, int isup, Time expiry) { src_ = src; dest_ = dest; seq_ = seq; isup_ = isup; expiry_ = expiry; next_ = NULL; } }; class LinkStateList { public: // Data... LinkState *head_; int numLinks_; // Constructors... LinkStateList() : head_(NULL), numLinks_(0) {} // Methods... void addLink(nsaddr_t src, nsaddr_t dest, int seq, int isup, Time expiry); in
评论
    相关推荐