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 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 7 | namespace nlsr |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 8 | { |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 9 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 10 | class Map; |
| 11 | class RoutingTable; |
| 12 | class Nlsr; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 13 | |
| 14 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 15 | using namespace std; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 16 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 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); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 36 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 37 | void allocateLinks(); |
| 38 | void allocateLinkCosts(); |
| 39 | void freeLinks(); |
| 40 | void freeLinksCosts(); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 41 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 42 | void setNoLink(int nl) |
| 43 | { |
| 44 | vNoLink=nl; |
| 45 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 46 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 47 | protected: |
| 48 | double ** adjMatrix; |
| 49 | int numOfRouter; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 50 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 51 | int vNoLink; |
| 52 | int *links; |
| 53 | double *linkCosts; |
| 54 | }; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 55 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 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 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 67 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 68 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 69 | void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 70 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 71 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 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); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 81 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame^] | 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 | }; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 142 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 143 | }//namespace nlsr |
| 144 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 145 | #endif |