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