blob: cba183b6fc80baf4289a28f8859d232067a612cc [file] [log] [blame]
akmhoque79d355f2014-02-04 15:11:16 -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 }
akmhoque3fdf7612014-02-04 21:18:23 -060026protected:
akmhoque79d355f2014-02-04 15:11:16 -060027 void allocateAdjMatrix();
akmhoquef7c2c7c2014-02-06 11:32:43 -060028 void initMatrix();
akmhoque79d355f2014-02-04 15:11:16 -060029 void makeAdjMatrix(nlsr& pnlsr,Map pMap);
akmhoque3fdf7612014-02-04 21:18:23 -060030 void printAdjMatrix();
31 int getNumOfLinkfromAdjMatrix(int sRouter);
akmhoque79d355f2014-02-04 15:11:16 -060032 void freeAdjMatrix();
akmhoque3fdf7612014-02-04 21:18:23 -060033 void adjustAdMatrix(int source, int link, double linkCost);
34 void getLinksFromAdjMatrix(int *links, double *linkCosts, int source);
akmhoque79d355f2014-02-04 15:11:16 -060035
akmhoquef7c2c7c2014-02-06 11:32:43 -060036 void allocateLinks();
37 void allocateLinkCosts();
38 void freeLinks();
39 void freeLinksCosts();
40
41 void setNoLink(int nl)
42 {
43 vNoLink=nl;
44 }
45
akmhoque79d355f2014-02-04 15:11:16 -060046protected:
47 double ** adjMatrix;
48 int numOfRouter;
akmhoquef7c2c7c2014-02-06 11:32:43 -060049
50 int vNoLink;
51 int *links;
52 double *linkCosts;
akmhoque79d355f2014-02-04 15:11:16 -060053};
54
55class LinkStateRoutingTableCalculator: public RoutingTableCalculator
56{
57public:
58 LinkStateRoutingTableCalculator(int rn)
akmhoque3fdf7612014-02-04 21:18:23 -060059 : EMPTY_PARENT(-12345)
60 , INF_DISTANCE(2147483647)
61 , NO_MAPPING_NUM(-1)
akmhoquef7c2c7c2014-02-06 11:32:43 -060062 , NO_NEXT_HOP(-12345)
akmhoque79d355f2014-02-04 15:11:16 -060063 {
64 numOfRouter=rn;
65 }
akmhoquef7c2c7c2014-02-06 11:32:43 -060066
akmhoque79d355f2014-02-04 15:11:16 -060067
68 void calculatePath(Map& pMap, RoutingTable& rt, nlsr& pnlsr);
akmhoque3fdf7612014-02-04 21:18:23 -060069
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);
akmhoquef7c2c7c2014-02-06 11:32:43 -060077 void addAllLsNextHopsToRoutingTable(nlsr& pnlsr, RoutingTable& rt,
78 Map& pMap,int sourceRouter);
79 int getLsNextHop(int dest, int source);
akmhoque3fdf7612014-02-04 21:18:23 -060080
81 void allocateParent();
82 void allocateDistance();
83 void freeParent();
84 void freeDistance();
85
akmhoquef7c2c7c2014-02-06 11:32:43 -060086
akmhoque3fdf7612014-02-04 21:18:23 -060087
88
89private:
90 int *parent;
91 double *distance;
92
akmhoquef7c2c7c2014-02-06 11:32:43 -060093
akmhoque3fdf7612014-02-04 21:18:23 -060094 const int EMPTY_PARENT;
95 const double INF_DISTANCE;
96 const int NO_MAPPING_NUM;
akmhoquef7c2c7c2014-02-06 11:32:43 -060097 const int NO_NEXT_HOP;
akmhoque79d355f2014-02-04 15:11:16 -060098
99};
100
101class HypRoutingTableCalculator: public RoutingTableCalculator
102{
103public:
104 HypRoutingTableCalculator(int rn)
akmhoquef7c2c7c2014-02-06 11:32:43 -0600105 : MATH_PI(3.141592654)
akmhoque79d355f2014-02-04 15:11:16 -0600106 {
107 numOfRouter=rn;
akmhoquef7c2c7c2014-02-06 11:32:43 -0600108 isDryRun=0;
109 }
110 HypRoutingTableCalculator(int rn, int idr)
111 : MATH_PI(3.141592654)
112 {
113 numOfRouter=rn;
114 isDryRun=idr;
akmhoque79d355f2014-02-04 15:11:16 -0600115 }
116
117 void calculatePath(Map& pMap, RoutingTable& rt, nlsr& pnlsr);
118
akmhoquef7c2c7c2014-02-06 11:32:43 -0600119private:
120 void allocateLinkFaces();
121 void allocateDistanceToNeighbor();
122 void allocateDistFromNbrToDest();
123 void freeLinkFaces();
124 void freeDistanceToNeighbor();
125 void freeDistFromNbrToDest();
akmhoque79d355f2014-02-04 15:11:16 -0600126
akmhoquef7c2c7c2014-02-06 11:32:43 -0600127 double getHyperbolicDistance(nlsr& pnlsr,Map& pMap, int src, int dest);
128 void addHypNextHopsToRoutingTable(nlsr& pnlsr,Map& pMap,
129 RoutingTable& rt, int noFaces,int dest);
akmhoque79d355f2014-02-04 15:11:16 -0600130
akmhoquef7c2c7c2014-02-06 11:32:43 -0600131private:
132 int isDryRun;
133
134 int *linkFaces;
135 double *distanceToNeighbor;
136 double *distFromNbrToDest;
137
138 const double MATH_PI;
akmhoque79d355f2014-02-04 15:11:16 -0600139
140};
141
142#endif