blob: dba45ca9137dac871e99478d24802ac9b4cb9378 [file] [log] [blame]
akmhoqueba094742014-02-28 11:47:21 -06001#ifndef NLSR_RTC_HPP
2#define NLSR_RTC_HPP
3
4#include <list>
5#include <iostream>
6
7namespace nlsr
8{
9
akmhoque5a44dd42014-03-12 18:11:32 -050010 class Map;
11 class RoutingTable;
12 class Nlsr;
akmhoqueba094742014-02-28 11:47:21 -060013
14
akmhoque5a44dd42014-03-12 18:11:32 -050015 using namespace std;
akmhoqueba094742014-02-28 11:47:21 -060016
akmhoque5a44dd42014-03-12 18:11:32 -050017 class RoutingTableCalculator
18 {
19 public:
20 RoutingTableCalculator()
akmhoqueba094742014-02-28 11:47:21 -060021 {
akmhoque5a44dd42014-03-12 18:11:32 -050022 }
23 RoutingTableCalculator(int rn)
akmhoqueba094742014-02-28 11:47:21 -060024 {
akmhoque5a44dd42014-03-12 18:11:32 -050025 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);
akmhoqueba094742014-02-28 11:47:21 -060036
akmhoque5a44dd42014-03-12 18:11:32 -050037 void allocateLinks();
38 void allocateLinkCosts();
39 void freeLinks();
40 void freeLinksCosts();
akmhoqueba094742014-02-28 11:47:21 -060041
akmhoque5a44dd42014-03-12 18:11:32 -050042 void setNoLink(int nl)
akmhoqueba094742014-02-28 11:47:21 -060043 {
akmhoque5a44dd42014-03-12 18:11:32 -050044 vNoLink=nl;
45 }
akmhoqueba094742014-02-28 11:47:21 -060046
akmhoque5a44dd42014-03-12 18:11:32 -050047 protected:
akmhoque05d5fcf2014-04-15 14:58:45 -050048 double** adjMatrix;
akmhoque5a44dd42014-03-12 18:11:32 -050049 int numOfRouter;
akmhoqueba094742014-02-28 11:47:21 -060050
akmhoque5a44dd42014-03-12 18:11:32 -050051 int vNoLink;
akmhoque05d5fcf2014-04-15 14:58:45 -050052 int* links;
53 double* linkCosts;
akmhoque5a44dd42014-03-12 18:11:32 -050054 };
akmhoqueba094742014-02-28 11:47:21 -060055
akmhoque5a44dd42014-03-12 18:11:32 -050056 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 }
akmhoqueba094742014-02-28 11:47:21 -060067
akmhoqueba094742014-02-28 11:47:21 -060068
akmhoque5a44dd42014-03-12 18:11:32 -050069 void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);
akmhoqueba094742014-02-28 11:47:21 -060070
akmhoqueba094742014-02-28 11:47:21 -060071
akmhoque5a44dd42014-03-12 18:11:32 -050072 private:
73 void doDijkstraPathCalculation(int sourceRouter);
akmhoque05d5fcf2014-04-15 14:58:45 -050074 void sortQueueByDistance(int* Q, double* dist,int start,int element);
75 int isNotExplored(int* Q, int u,int start, int element);
akmhoque5a44dd42014-03-12 18:11:32 -050076 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);
81
82 void allocateParent();
83 void allocateDistance();
84 void freeParent();
85 void freeDistance();
86
87
88
89
90 private:
akmhoque05d5fcf2014-04-15 14:58:45 -050091 int* m_parent;
92 double* m_distance;
akmhoque5a44dd42014-03-12 18:11:32 -050093
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;
akmhoque05d5fcf2014-04-15 14:58:45 -0500109 m_isDryRun=0;
akmhoque5a44dd42014-03-12 18:11:32 -0500110 }
111 HypRoutingTableCalculator(int rn, int idr)
112 : MATH_PI(3.141592654)
113 {
114 numOfRouter=rn;
akmhoque05d5fcf2014-04-15 14:58:45 -0500115 m_isDryRun=idr;
akmhoque5a44dd42014-03-12 18:11:32 -0500116 }
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:
akmhoque05d5fcf2014-04-15 14:58:45 -0500133 bool m_isDryRun;
akmhoque5a44dd42014-03-12 18:11:32 -0500134
akmhoque05d5fcf2014-04-15 14:58:45 -0500135 int* m_linkFaces;
136 double* m_distanceToNeighbor;
137 double* m_distFromNbrToDest;
akmhoque5a44dd42014-03-12 18:11:32 -0500138
139 const double MATH_PI;
140
141 };
akmhoqueba094742014-02-28 11:47:21 -0600142
143}//namespace nlsr
144
145#endif