📄 locserver.h
字号:
#ifndef _DSRAgent_h#define _DSRAgent_h#include <stdarg.h>#include <object.h>#include <agent.h>#include <trace.h>#include <packet.h>#include <cmu/priqueue.h>#include <cmu/mac.h>#include "hdr_hgps.h"#include "hgpsagent.h"#include "hgpsrouter.h"#include "hgpsrequesttable.h"#define SMALLEST_GRID 250#define BIGGEST_MASK 32#define LIVE_CONN_TIMEOUT 20.0 #define LOC_TIMEOUT1_INTEVAL 10.5#define LOC_TIMEOUT2_INTEVAL 21 //better than nothing, in desperation#define RT_RQ_PERIOD 0.5#define RT_RQ_MAX_PERIOD 10#define HGPS_LOC_STARTUP_JITTER 1.5#define MAX_UPDATE_INTEVAL 50.0#define TRIGGER_PERIOD 2#define CACHE_VALID_TIME 30#define MAX_FP_TABLE_SIZE 60class LocServerPeriodicHandler;class LocServerTriggerHandler;class HGPSRouter;class HGPSAgent;class LocTable;typedef struct{ nsaddr_t id; location loc; double lastupdate_time; double timeout;}loc_entry;class LocServer { public: /* i'll indicate my intention of finding dst's location*/ bool getLocation(nsaddr_t dst, location &loc); /* i'll call this function passing an update packet in*/ void recvUpdate(Packet *packet); /* similar */ void recvQuery(Packet *packet, bool dst_loc_failure); /* this function is called when a query response pkt arrives. you should call HGPSAgent::notifyLocation(nsaddr_t id, location loc) */ void recvQueryResponse(Packet *packet); /* transmission failure handling function*/ void xmitFailureLoc(Packet *pkt); /* add connection entry to the live_connections table */ void addUpdateLiveConn(nsaddr_t id, location loc); /* purge errorneous location cache entries */ void purgeLocCache(nsaddr_t id); /* update location cache information */ void updateLocCache(nsaddr_t id, location loc, double timeout); /* check for expiring updates*/ void checkExpiringUpdates(); /* periodic update of my location information */ void updateLoc(int level); void checkPeriodicUpdateLoc(); /* log table size */ void logTableSize(); /* finding a node's smallest grid number */ location getGrid(double x, double y); location getGrid(); location getGridPos(double &x, double &y); void getPos(double &x, double &y); void start(); void sleep();// bool inSameGrid(location src, location dst); void setRouter(HGPSRouter *r); void setMobileNode(MobileNode *m); double getSpeed(); /* function called by hgpsrouter to piggyback FP info*/ void piggybackFP(Packet *); /* function to leave a FP whenever i move out */ void updateFPGrid(location grid); /* function to process FP update information */ void recvFPUpdate(Packet *pkt); /* clear up FP table once I move */ void dumpFPTable(); LocServer(HGPSAgent *p); ~LocServer(); MobileNode *mynode; int max_mask; location myloc; HGPSAgent *parent; protected: /* return the smallest grid number I am in */ HGPSRouter *router; double max_len; LocServerPeriodicHandler *loc_periodic_handler; LocServerTriggerHandler *loc_trigger_handler; Event *trigger_event; Event *loc_periodic_event; HGPSRequestTable request_table; LocTable *table; LocTable *loc_cache; LocTable *live_connections; location curr_loc; double prev_x; double prev_y; int prev_level; double prev_timeout; loc_entry fp_table[MAX_FP_TABLE_SIZE]; int fp_table_num; int fp_table_tail; double *expiration_times;};class LocServerPeriodicHandler : public Handler { public: LocServerPeriodicHandler(LocServer *s); virtual void handle(Event *e); private: LocServer *locserver;};class LocServerTriggerHandler : public Handler { public: LocServerTriggerHandler(LocServer *s, HGPSAgent *p); virtual void handle(Event *e); location prev_location; private: LocServer *locserver; HGPSAgent *parent; int counter;};class LocTable { public: int size; bool chopoff; int used_size; loc_entry *table; bool findClosest(nsaddr_t myaddr, location myloc,nsaddr_t dst, struct route_entry *nt,loc_entry &, double lastupdate_time); bool findClosestInGrid(nsaddr_t myaddr, location myloc,nsaddr_t dst, location dst_loc,struct route_entry *nt,loc_entry &, double lastupdate_time); void findClosestExceptDst(nsaddr_t myaddr, location myloc,nsaddr_t dst,struct route_entry *nt,location update_loc,loc_entry &); bool findClosestinRT(nsaddr_t myaddr, location myloc,nsaddr_t dst,struct route_entry *nt,loc_entry &, bool in_same_grid); loc_entry *getEntry(nsaddr_t dst, double now); void addUpdateEntry(nsaddr_t id, location loc,double timeout); void deleteEntry(nsaddr_t id); void cleanTable(); int printTableNum(); LocTable(int max_entry,bool chop); ~LocTable();};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -