akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame^] | 1 | #ifndef NLSR_RTC_HPP |
| 2 | #define NLSR_RTC_HPP |
| 3 | |
| 4 | #include <list> |
| 5 | #include <iostream> |
| 6 | |
| 7 | namespace nlsr |
| 8 | { |
| 9 | |
| 10 | class Map; |
| 11 | class RoutingTable; |
| 12 | class Nlsr; |
| 13 | |
| 14 | |
| 15 | using namespace std; |
| 16 | |
| 17 | class RoutingTableCalculator |
| 18 | { |
| 19 | public: |
| 20 | RoutingTableCalculator() |
| 21 | { |
| 22 | } |
| 23 | RoutingTableCalculator(int rn) |
| 24 | { |
| 25 | numOfRouter=rn; |
| 26 | } |
| 27 | protected: |
| 28 | void allocateAdjMatrix(); |
| 29 | void initMatrix(); |
| 30 | void makeAdjMatrix(Nlsr& pnlsr,Map pMap); |
| 31 | void printAdjMatrix(); |
| 32 | int getNumOfLinkfromAdjMatrix(int sRouter); |
| 33 | void freeAdjMatrix(); |
| 34 | void adjustAdMatrix(int source, int link, double linkCost); |
| 35 | void getLinksFromAdjMatrix(int *links, double *linkCosts, int source); |
| 36 | |
| 37 | void allocateLinks(); |
| 38 | void allocateLinkCosts(); |
| 39 | void freeLinks(); |
| 40 | void freeLinksCosts(); |
| 41 | |
| 42 | void setNoLink(int nl) |
| 43 | { |
| 44 | vNoLink=nl; |
| 45 | } |
| 46 | |
| 47 | protected: |
| 48 | double ** adjMatrix; |
| 49 | int numOfRouter; |
| 50 | |
| 51 | int vNoLink; |
| 52 | int *links; |
| 53 | double *linkCosts; |
| 54 | }; |
| 55 | |
| 56 | class LinkStateRoutingTableCalculator: public RoutingTableCalculator |
| 57 | { |
| 58 | public: |
| 59 | LinkStateRoutingTableCalculator(int rn) |
| 60 | : EMPTY_PARENT(-12345) |
| 61 | , INF_DISTANCE(2147483647) |
| 62 | , NO_MAPPING_NUM(-1) |
| 63 | , NO_NEXT_HOP(-12345) |
| 64 | { |
| 65 | numOfRouter=rn; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 70 | |
| 71 | |
| 72 | private: |
| 73 | void doDijkstraPathCalculation(int sourceRouter); |
| 74 | void sortQueueByDistance(int *Q, double *dist,int start,int element); |
| 75 | int isNotExplored(int *Q, int u,int start, int element); |
| 76 | void printAllLsPath(int sourceRouter); |
| 77 | void printLsPath(int destRouter); |
| 78 | void addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt, |
| 79 | Map& pMap,int sourceRouter); |
| 80 | int getLsNextHop(int dest, int source); |
| 81 | |
| 82 | void allocateParent(); |
| 83 | void allocateDistance(); |
| 84 | void freeParent(); |
| 85 | void freeDistance(); |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | private: |
| 91 | int *parent; |
| 92 | double *distance; |
| 93 | |
| 94 | |
| 95 | const int EMPTY_PARENT; |
| 96 | const double INF_DISTANCE; |
| 97 | const int NO_MAPPING_NUM; |
| 98 | const int NO_NEXT_HOP; |
| 99 | |
| 100 | }; |
| 101 | |
| 102 | class HypRoutingTableCalculator: public RoutingTableCalculator |
| 103 | { |
| 104 | public: |
| 105 | HypRoutingTableCalculator(int rn) |
| 106 | : MATH_PI(3.141592654) |
| 107 | { |
| 108 | numOfRouter=rn; |
| 109 | isDryRun=0; |
| 110 | } |
| 111 | HypRoutingTableCalculator(int rn, int idr) |
| 112 | : MATH_PI(3.141592654) |
| 113 | { |
| 114 | numOfRouter=rn; |
| 115 | isDryRun=idr; |
| 116 | } |
| 117 | |
| 118 | void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 119 | |
| 120 | private: |
| 121 | void allocateLinkFaces(); |
| 122 | void allocateDistanceToNeighbor(); |
| 123 | void allocateDistFromNbrToDest(); |
| 124 | void freeLinkFaces(); |
| 125 | void freeDistanceToNeighbor(); |
| 126 | void freeDistFromNbrToDest(); |
| 127 | |
| 128 | double getHyperbolicDistance(Nlsr& pnlsr,Map& pMap, int src, int dest); |
| 129 | void addHypNextHopsToRoutingTable(Nlsr& pnlsr,Map& pMap, |
| 130 | RoutingTable& rt, int noFaces,int dest); |
| 131 | |
| 132 | private: |
| 133 | int isDryRun; |
| 134 | |
| 135 | int *linkFaces; |
| 136 | double *distanceToNeighbor; |
| 137 | double *distFromNbrToDest; |
| 138 | |
| 139 | const double MATH_PI; |
| 140 | |
| 141 | }; |
| 142 | |
| 143 | }//namespace nlsr |
| 144 | |
| 145 | #endif |