akmhoque | 79d355f | 2014-02-04 15:11:16 -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 | } |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 26 | protected: |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 27 | void allocateAdjMatrix(); |
| 28 | void makeAdjMatrix(nlsr& pnlsr,Map pMap); |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 29 | void printAdjMatrix(); |
| 30 | int getNumOfLinkfromAdjMatrix(int sRouter); |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 31 | void freeAdjMatrix(); |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 32 | void adjustAdMatrix(int source, int link, double linkCost); |
| 33 | void getLinksFromAdjMatrix(int *links, double *linkCosts, int source); |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | double ** adjMatrix; |
| 37 | int numOfRouter; |
| 38 | }; |
| 39 | |
| 40 | class LinkStateRoutingTableCalculator: public RoutingTableCalculator |
| 41 | { |
| 42 | public: |
| 43 | LinkStateRoutingTableCalculator(int rn) |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 44 | : EMPTY_PARENT(-12345) |
| 45 | , INF_DISTANCE(2147483647) |
| 46 | , NO_MAPPING_NUM(-1) |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 47 | { |
| 48 | numOfRouter=rn; |
| 49 | } |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 50 | void setNoLink(int nl) |
| 51 | { |
| 52 | vNoLink=nl; |
| 53 | } |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 54 | |
| 55 | void calculatePath(Map& pMap, RoutingTable& rt, nlsr& pnlsr); |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 56 | |
| 57 | |
| 58 | private: |
| 59 | void doDijkstraPathCalculation(int sourceRouter); |
| 60 | void sortQueueByDistance(int *Q, double *dist,int start,int element); |
| 61 | int isNotExplored(int *Q, int u,int start, int element); |
| 62 | void printAllLsPath(int sourceRouter); |
| 63 | void printLsPath(int destRouter); |
| 64 | |
| 65 | void allocateParent(); |
| 66 | void allocateDistance(); |
| 67 | void freeParent(); |
| 68 | void freeDistance(); |
| 69 | |
| 70 | void allocateLinks(); |
| 71 | void allocateLinkCosts(); |
| 72 | void freeLinks(); |
| 73 | void freeLinksCosts(); |
| 74 | |
| 75 | |
| 76 | private: |
| 77 | int *parent; |
| 78 | double *distance; |
| 79 | |
| 80 | int vNoLink; |
| 81 | int *links; |
| 82 | double *linkCosts; |
| 83 | const int EMPTY_PARENT; |
| 84 | const double INF_DISTANCE; |
| 85 | const int NO_MAPPING_NUM; |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 86 | |
| 87 | }; |
| 88 | |
| 89 | class HypRoutingTableCalculator: public RoutingTableCalculator |
| 90 | { |
| 91 | public: |
| 92 | HypRoutingTableCalculator(int rn) |
| 93 | { |
| 94 | numOfRouter=rn; |
| 95 | } |
| 96 | |
| 97 | void calculatePath(Map& pMap, RoutingTable& rt, nlsr& pnlsr); |
| 98 | |
| 99 | }; |
| 100 | |
| 101 | class HypDryRoutingTableCalculator: public RoutingTableCalculator |
| 102 | { |
| 103 | public: |
| 104 | HypDryRoutingTableCalculator(int rn) |
| 105 | { |
| 106 | numOfRouter=rn; |
| 107 | } |
| 108 | |
| 109 | void calculatePath(Map& pMap, RoutingTable& rt, nlsr& pnlsr); |
| 110 | |
| 111 | }; |
| 112 | |
| 113 | #endif |