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); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame^] | 55 | /* |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | void |
| 57 | printAdjMatrix(); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame^] | 58 | */ |
| 59 | void |
| 60 | writeAdjMatrixLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 61 | |
| 62 | int |
| 63 | getNumOfLinkfromAdjMatrix(int sRouter); |
| 64 | |
| 65 | void |
| 66 | freeAdjMatrix(); |
| 67 | |
| 68 | void |
| 69 | adjustAdMatrix(int source, int link, double linkCost); |
| 70 | |
| 71 | void |
| 72 | getLinksFromAdjMatrix(int* links, double* linkCosts, int source); |
| 73 | |
| 74 | void |
| 75 | allocateLinks(); |
| 76 | |
| 77 | void |
| 78 | allocateLinkCosts(); |
| 79 | |
| 80 | void |
| 81 | freeLinks(); |
| 82 | |
| 83 | void |
| 84 | freeLinksCosts(); |
| 85 | |
| 86 | void |
| 87 | setNoLink(int nl) |
| 88 | { |
| 89 | vNoLink = nl; |
| 90 | } |
| 91 | |
| 92 | protected: |
| 93 | double** adjMatrix; |
| 94 | int numOfRouter; |
| 95 | |
| 96 | int vNoLink; |
| 97 | int* links; |
| 98 | double* linkCosts; |
| 99 | }; |
| 100 | |
| 101 | class LinkStateRoutingTableCalculator: public RoutingTableCalculator |
| 102 | { |
| 103 | public: |
| 104 | LinkStateRoutingTableCalculator(int rn) |
| 105 | : EMPTY_PARENT(-12345) |
| 106 | , INF_DISTANCE(2147483647) |
| 107 | , NO_MAPPING_NUM(-1) |
| 108 | , NO_NEXT_HOP(-12345) |
| 109 | { |
| 110 | numOfRouter = rn; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | void |
| 115 | calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 116 | |
| 117 | |
| 118 | private: |
| 119 | void |
| 120 | doDijkstraPathCalculation(int sourceRouter); |
| 121 | |
| 122 | void |
| 123 | sortQueueByDistance(int* Q, double* dist, int start, int element); |
| 124 | |
| 125 | int |
| 126 | isNotExplored(int* Q, int u, int start, int element); |
| 127 | |
| 128 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 129 | addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt, |
| 130 | Map& pMap, int sourceRouter); |
| 131 | |
| 132 | int |
| 133 | getLsNextHop(int dest, int source); |
| 134 | |
| 135 | void |
| 136 | allocateParent(); |
| 137 | |
| 138 | void |
| 139 | allocateDistance(); |
| 140 | |
| 141 | void |
| 142 | freeParent(); |
| 143 | |
| 144 | void |
| 145 | freeDistance(); |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | private: |
| 151 | int* m_parent; |
| 152 | double* m_distance; |
| 153 | |
| 154 | |
| 155 | const int EMPTY_PARENT; |
| 156 | const double INF_DISTANCE; |
| 157 | const int NO_MAPPING_NUM; |
| 158 | const int NO_NEXT_HOP; |
| 159 | |
| 160 | }; |
| 161 | |
| 162 | class HypRoutingTableCalculator: public RoutingTableCalculator |
| 163 | { |
| 164 | public: |
| 165 | HypRoutingTableCalculator(int rn) |
| 166 | : MATH_PI(3.141592654) |
| 167 | { |
| 168 | numOfRouter = rn; |
| 169 | m_isDryRun = 0; |
| 170 | } |
| 171 | |
| 172 | HypRoutingTableCalculator(int rn, int idr) |
| 173 | : MATH_PI(3.141592654) |
| 174 | { |
| 175 | numOfRouter = rn; |
| 176 | m_isDryRun = idr; |
| 177 | } |
| 178 | |
| 179 | void |
| 180 | calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 181 | |
| 182 | private: |
| 183 | void |
| 184 | allocateLinkFaces(); |
| 185 | |
| 186 | void |
| 187 | allocateDistanceToNeighbor(); |
| 188 | |
| 189 | void |
| 190 | allocateDistFromNbrToDest(); |
| 191 | |
| 192 | void |
| 193 | freeLinkFaces(); |
| 194 | |
| 195 | void |
| 196 | freeDistanceToNeighbor(); |
| 197 | |
| 198 | void |
| 199 | freeDistFromNbrToDest(); |
| 200 | |
| 201 | double |
| 202 | getHyperbolicDistance(Nlsr& pnlsr, Map& pMap, int src, int dest); |
| 203 | |
| 204 | void |
| 205 | addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap, |
| 206 | RoutingTable& rt, int noFaces, int dest); |
| 207 | |
| 208 | private: |
| 209 | bool m_isDryRun; |
| 210 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 211 | std::vector<std::string> m_linkFaceUris; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 212 | double* m_distanceToNeighbor; |
| 213 | double* m_distFromNbrToDest; |
| 214 | |
| 215 | const double MATH_PI; |
| 216 | |
| 217 | }; |
| 218 | |
| 219 | }//namespace nlsr |
| 220 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 221 | #endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP |