blob: cba183b6fc80baf4289a28f8859d232067a612cc [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#ifndef NLSR_RTC_HPP
2#define NLSR_RTC_HPP
3
4#include <list>
5#include <iostream>
6
7
8
9class Map;
10class RoutingTable;
11class nlsr;
12
13
14using namespace std;
15
16class RoutingTableCalculator
17{
18public:
19 RoutingTableCalculator()
20 {
21 }
22 RoutingTableCalculator(int rn)
23 {
24 numOfRouter=rn;
25 }
26protected:
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
46protected:
47 double ** adjMatrix;
48 int numOfRouter;
49
50 int vNoLink;
51 int *links;
52 double *linkCosts;
53};
54
55class LinkStateRoutingTableCalculator: public RoutingTableCalculator
56{
57public:
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
71private:
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
89private:
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
101class HypRoutingTableCalculator: public RoutingTableCalculator
102{
103public:
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
119private:
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
131private:
132 int isDryRun;
133
134 int *linkFaces;
135 double *distanceToNeighbor;
136 double *distFromNbrToDest;
137
138 const double MATH_PI;
139
140};
141
142#endif