akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014 University of Memphis, |
| 4 | * Regents of the University of California |
| 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | * \author A K M Mahmudul Hoque <ahoque1@memphis.edu> |
| 21 | * |
| 22 | **/ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 23 | #ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP |
| 24 | #define NLSR_ROUTING_TABLE_CALCULATOR_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | |
| 26 | #include <list> |
| 27 | #include <iostream> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 28 | #include <boost/cstdint.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | |
| 30 | namespace nlsr { |
| 31 | |
| 32 | class Map; |
| 33 | class RoutingTable; |
| 34 | class Nlsr; |
| 35 | |
| 36 | class RoutingTableCalculator |
| 37 | { |
| 38 | public: |
| 39 | RoutingTableCalculator() |
| 40 | { |
| 41 | } |
| 42 | RoutingTableCalculator(int rn) |
| 43 | { |
| 44 | numOfRouter = rn; |
| 45 | } |
| 46 | protected: |
| 47 | void |
| 48 | allocateAdjMatrix(); |
| 49 | |
| 50 | void |
| 51 | initMatrix(); |
| 52 | |
| 53 | void |
| 54 | makeAdjMatrix(Nlsr& pnlsr, Map pMap); |
| 55 | |
| 56 | void |
| 57 | printAdjMatrix(); |
| 58 | |
| 59 | int |
| 60 | getNumOfLinkfromAdjMatrix(int sRouter); |
| 61 | |
| 62 | void |
| 63 | freeAdjMatrix(); |
| 64 | |
| 65 | void |
| 66 | adjustAdMatrix(int source, int link, double linkCost); |
| 67 | |
| 68 | void |
| 69 | getLinksFromAdjMatrix(int* links, double* linkCosts, int source); |
| 70 | |
| 71 | void |
| 72 | allocateLinks(); |
| 73 | |
| 74 | void |
| 75 | allocateLinkCosts(); |
| 76 | |
| 77 | void |
| 78 | freeLinks(); |
| 79 | |
| 80 | void |
| 81 | freeLinksCosts(); |
| 82 | |
| 83 | void |
| 84 | setNoLink(int nl) |
| 85 | { |
| 86 | vNoLink = nl; |
| 87 | } |
| 88 | |
| 89 | protected: |
| 90 | double** adjMatrix; |
| 91 | int numOfRouter; |
| 92 | |
| 93 | int vNoLink; |
| 94 | int* links; |
| 95 | double* linkCosts; |
| 96 | }; |
| 97 | |
| 98 | class LinkStateRoutingTableCalculator: public RoutingTableCalculator |
| 99 | { |
| 100 | public: |
| 101 | LinkStateRoutingTableCalculator(int rn) |
| 102 | : EMPTY_PARENT(-12345) |
| 103 | , INF_DISTANCE(2147483647) |
| 104 | , NO_MAPPING_NUM(-1) |
| 105 | , NO_NEXT_HOP(-12345) |
| 106 | { |
| 107 | numOfRouter = rn; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void |
| 112 | calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 113 | |
| 114 | |
| 115 | private: |
| 116 | void |
| 117 | doDijkstraPathCalculation(int sourceRouter); |
| 118 | |
| 119 | void |
| 120 | sortQueueByDistance(int* Q, double* dist, int start, int element); |
| 121 | |
| 122 | int |
| 123 | isNotExplored(int* Q, int u, int start, int element); |
| 124 | |
| 125 | void |
| 126 | printAllLsPath(int sourceRouter); |
| 127 | |
| 128 | void |
| 129 | printLsPath(int destRouter); |
| 130 | |
| 131 | void |
| 132 | addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt, |
| 133 | Map& pMap, int sourceRouter); |
| 134 | |
| 135 | int |
| 136 | getLsNextHop(int dest, int source); |
| 137 | |
| 138 | void |
| 139 | allocateParent(); |
| 140 | |
| 141 | void |
| 142 | allocateDistance(); |
| 143 | |
| 144 | void |
| 145 | freeParent(); |
| 146 | |
| 147 | void |
| 148 | freeDistance(); |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | private: |
| 154 | int* m_parent; |
| 155 | double* m_distance; |
| 156 | |
| 157 | |
| 158 | const int EMPTY_PARENT; |
| 159 | const double INF_DISTANCE; |
| 160 | const int NO_MAPPING_NUM; |
| 161 | const int NO_NEXT_HOP; |
| 162 | |
| 163 | }; |
| 164 | |
| 165 | class HypRoutingTableCalculator: public RoutingTableCalculator |
| 166 | { |
| 167 | public: |
| 168 | HypRoutingTableCalculator(int rn) |
| 169 | : MATH_PI(3.141592654) |
| 170 | { |
| 171 | numOfRouter = rn; |
| 172 | m_isDryRun = 0; |
| 173 | } |
| 174 | |
| 175 | HypRoutingTableCalculator(int rn, int idr) |
| 176 | : MATH_PI(3.141592654) |
| 177 | { |
| 178 | numOfRouter = rn; |
| 179 | m_isDryRun = idr; |
| 180 | } |
| 181 | |
| 182 | void |
| 183 | calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 184 | |
| 185 | private: |
| 186 | void |
| 187 | allocateLinkFaces(); |
| 188 | |
| 189 | void |
| 190 | allocateDistanceToNeighbor(); |
| 191 | |
| 192 | void |
| 193 | allocateDistFromNbrToDest(); |
| 194 | |
| 195 | void |
| 196 | freeLinkFaces(); |
| 197 | |
| 198 | void |
| 199 | freeDistanceToNeighbor(); |
| 200 | |
| 201 | void |
| 202 | freeDistFromNbrToDest(); |
| 203 | |
| 204 | double |
| 205 | getHyperbolicDistance(Nlsr& pnlsr, Map& pMap, int src, int dest); |
| 206 | |
| 207 | void |
| 208 | addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap, |
| 209 | RoutingTable& rt, int noFaces, int dest); |
| 210 | |
| 211 | private: |
| 212 | bool m_isDryRun; |
| 213 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 214 | std::vector<std::string> m_linkFaceUris; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 215 | double* m_distanceToNeighbor; |
| 216 | double* m_distFromNbrToDest; |
| 217 | |
| 218 | const double MATH_PI; |
| 219 | |
| 220 | }; |
| 221 | |
| 222 | }//namespace nlsr |
| 223 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 224 | #endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP |