📄 landmark.h
字号:
// Author: Satish Kumar, kkumar@isi.edu#ifndef landmark_h_#define landmark_h_#include <agent.h>#include <ip.h>#include <delay.h>#include <scheduler.h>#include <queue.h>#include <trace.h>#include <arp.h>#include <ll.h>#include <mac.h>#include <priqueue.h>#include <mobilenode.h>#include "tags.h"#include "agent-list.h"typedef double Time;#define ROUTER_PORT 255#define QUERY_PORT 0#define NOT_CHILD 0#define IS_CHILD 1#define NOT_POTL_CHILD 2 // Not within appropriate vicinity#define NO_PARENT 60000#define OLD_ENTRY 0 // Object already exists in list#define NEW_ENTRY 1 // New object created in list#define OLD_MESSAGE 2 // Old information; Object not added to list#define ENTRY_NOT_FOUND 3 // Object not found#define NEW_CHILD 4 // New child added#define OLD_CHILD_TAGS_CHANGED 5#define TRUE 1#define FALSE 0#define MAX_ENERGY 100000#define MAX_LEVELS 8#define MAX_CHILDREN 30#define MAX_DEMOTION_RECORDS 20#define INITIAL_WAIT_TIME 10.0#define PERIODIC_WAIT_TIME 60.0#define LM_STARTUP_JITTER 10.0 // secs to jitter LM's periodic adverts#define IP_HDR_SIZE 20 // 20 byte IP header as in the Internet#define WAIT_TIME 2 // 1s for each hop; round-trip is 2#define MAX_TIMEOUT 200 // Value divided by local population density and // level to compute promotion timeout at node#define CONST_TIMEOUT 10 // Constant portion of timeout across levels#define LOW_FREQ_UPDATE 300#define PROMO_TIMEOUT_MULTIPLES 1 // Used in promotion timer#define DEMOTION 0 // update pkt should advertise demotion#define PERIODIC_ADVERTS 1 // periodic update for each level node is at#define UNICAST_ADVERT_CHILD 2#define UNICAST_ADVERT_PARENT 3#define GLOBAL_ADVERT 4 // global advertisement from root LM#define QUERY_PKT 5 // query/response pkt#define DIR_QUERY_PKT 6#define DIR_RESPONSE_PKT 7#define OBJECT_QUERY_PKT 8#define OBJECT_RESPONSE_PKT 9#define HASH_PKT 10#define HASH_ACK_PKT 11#define REHASH_PKT 12#define FLOOD 0#define UNICAST 1#define SUPPRESS 2#define DEMOTION_RATIO 1.3#define DEMOTION_DIFF 5000#define NO_NEXT_HOP 50000#define MAX_CACHE_ITEMS 200#define NO_GLOBAL_LM 60000class TagMobilityHandler;class TagAdvtHandler;//class TagCache {//public:// int obj_name_;// int origin_time_;// double X_;// double Y_;//};// Used in aggregationclass aggreg_taglist {public: aggreg_taglist() { marked_ = 0; next_ = NULL;} int obj_name_; int marked_; aggreg_taglist *next_;};class LMAddrs {public: LMAddrs() { lmaddr_ = 0; num_lm_addrs_ = 0; } ~LMAddrs() { delete_lm_addrs(); } void add_lm_addr(int64_t lmaddr) { int i = 0; assert(num_lm_addrs_ >= 0); if(num_lm_addrs_) { int64_t *tmp_addrs = new int64_t[num_lm_addrs_]; for(i = 0; i < num_lm_addrs_; ++i) { tmp_addrs[i] = lmaddr_[i]; } delete[] lmaddr_; lmaddr_ = new int64_t[num_lm_addrs_+1]; for(i = 0; i < num_lm_addrs_; ++i) { lmaddr_[i] = tmp_addrs[i]; } delete[] tmp_addrs; } else lmaddr_ = new int64_t[num_lm_addrs_+1]; lmaddr_[num_lm_addrs_] = lmaddr; ++num_lm_addrs_; } void delete_lm_addrs() { if(!num_lm_addrs_) return; num_lm_addrs_ = 0; delete[] lmaddr_; lmaddr_ = NULL; } void get_lm_addrs(int *num_lm_addrs, int64_t **lmaddr) { *num_lm_addrs = num_lm_addrs_; *lmaddr = NULL; if(num_lm_addrs_) { *lmaddr = new int64_t[num_lm_addrs_]; for(int i = 0; i < num_lm_addrs_; ++i) { (*lmaddr)[i] = lmaddr_[i]; } } } int match_lm_addr(int *addr, int level) { int i[8]; int num_addrs = 0; int match = FALSE; assert(level < 8); for(num_addrs = 0; num_addrs < num_lm_addrs_; ++num_addrs) { i[7] = (lmaddr_[num_addrs] >> 56) & 0xFF; i[6] = (lmaddr_[num_addrs] >> 48) & 0xFF; i[5] = (lmaddr_[num_addrs] >> 40) & 0xFF; i[4] = (lmaddr_[num_addrs] >> 32) & 0xFF; i[3] = (lmaddr_[num_addrs] >> 24) & 0xFF; i[2] = (lmaddr_[num_addrs] >> 16) & 0xFF; i[1] = (lmaddr_[num_addrs] >> 8) & 0xFF; i[0] = (lmaddr_[num_addrs]) & 0xFF; match = TRUE; for(int j = 7; j >= level; --j) { if(addr[j] != i[j]) { match = FALSE; break; } } if(match == TRUE) return(match); } return(match); }private: int64_t *lmaddr_; int num_lm_addrs_;};// We need a separate record to keep track of old demotion messages so that// the same msg is not forwarded more than once. We cant use the potl children// or potl parent list for this because the entry is deleted on demotion.class RecentMsgRecord {public: RecentMsgRecord() { id_ = 60000; level_ = -1; origin_time_ = 0; } nsaddr_t id_; int level_; int origin_time_;};class NodeIDList {public: NodeIDList() { next_ = NULL; } nsaddr_t dst_node_; nsaddr_t dst_next_hop_; int next_hop_level_; NodeIDList *next_;};class LMNode { friend class ParentChildrenList; friend class LandmarkAgent; friend class PromotionTimer;public: LMNode(nsaddr_t id, nsaddr_t next_hop, int num_hops, int level, int num_children, int energy, int origin_time, double update_time) { id_ = id; lmaddr_ = new LMAddrs; next_hop_ = next_hop; child_flag_ = NOT_CHILD; num_hops_ = num_hops; level_ = level; num_children_ = num_children; energy_ = energy; last_upd_origin_time_ = origin_time; last_upd_seqnum_ = -1; last_update_rcvd_ = update_time; tag_list_ = NULL; next_ = NULL; } ~LMNode() { compr_taglist *tag_ptr1, *tag_ptr2; tag_ptr1 = tag_list_; while(tag_ptr1) { tag_ptr2 = tag_ptr1; tag_ptr1 = tag_ptr1->next_; delete tag_ptr2; } delete lmaddr_; } nsaddr_t id_; // ID of this node LMAddrs *lmaddr_; // Landmark addresses of this node nsaddr_t next_hop_; // Next hop to reach this node int child_flag_; // indicates whether this node is a child int num_hops_; // number of hops away int level_; // level of the child node int num_children_; // Number of children that this node has int energy_; // Energy reserves of the child node int last_upd_origin_time_; // Origin time of last update int last_upd_seqnum_; // Seqnum of last upd; used to distinguish // different messages originated at same time double last_update_rcvd_; // Time at which last update received compr_taglist *tag_list_; // Tag advertisements of this node LMNode *next_; void copy_tag_list(compr_taglist *taglist);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -