blob: 987686e7b8e00cc7277b08beb2b2659d84ebeecc [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
akmhoque1fd8c1e2014-02-19 19:41:49 -06007namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -06008{
akmhoque298385a2014-02-13 14:13:09 -06009
akmhoque1fd8c1e2014-02-19 19:41:49 -060010 class Map;
11 class RoutingTable;
12 class Nlsr;
akmhoque298385a2014-02-13 14:13:09 -060013
14
akmhoque1fd8c1e2014-02-19 19:41:49 -060015 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060016
akmhoque1fd8c1e2014-02-19 19:41:49 -060017 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);
akmhoque298385a2014-02-13 14:13:09 -060036
akmhoque1fd8c1e2014-02-19 19:41:49 -060037 void allocateLinks();
38 void allocateLinkCosts();
39 void freeLinks();
40 void freeLinksCosts();
akmhoque298385a2014-02-13 14:13:09 -060041
akmhoque1fd8c1e2014-02-19 19:41:49 -060042 void setNoLink(int nl)
43 {
44 vNoLink=nl;
45 }
akmhoque298385a2014-02-13 14:13:09 -060046
akmhoque1fd8c1e2014-02-19 19:41:49 -060047 protected:
48 double ** adjMatrix;
49 int numOfRouter;
akmhoque298385a2014-02-13 14:13:09 -060050
akmhoque1fd8c1e2014-02-19 19:41:49 -060051 int vNoLink;
52 int *links;
53 double *linkCosts;
54 };
akmhoque298385a2014-02-13 14:13:09 -060055
akmhoque1fd8c1e2014-02-19 19:41:49 -060056 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 }
akmhoque298385a2014-02-13 14:13:09 -060067
akmhoque298385a2014-02-13 14:13:09 -060068
akmhoque1fd8c1e2014-02-19 19:41:49 -060069 void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
akmhoque298385a2014-02-13 14:13:09 -060070
akmhoque298385a2014-02-13 14:13:09 -060071
akmhoque1fd8c1e2014-02-19 19:41:49 -060072 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);
akmhoque298385a2014-02-13 14:13:09 -060081
akmhoque1fd8c1e2014-02-19 19:41:49 -060082 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 };
akmhoque298385a2014-02-13 14:13:09 -0600142
akmhoqueb1710aa2014-02-19 17:13:36 -0600143}//namespace nlsr
144
akmhoque298385a2014-02-13 14:13:09 -0600145#endif