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 | |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 30 | #include <ndn-cxx/name.hpp> |
| 31 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | namespace nlsr { |
| 33 | |
| 34 | class Map; |
| 35 | class RoutingTable; |
| 36 | class Nlsr; |
| 37 | |
| 38 | class RoutingTableCalculator |
| 39 | { |
| 40 | public: |
| 41 | RoutingTableCalculator() |
| 42 | { |
| 43 | } |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 44 | RoutingTableCalculator(size_t nRouters) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | { |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 46 | m_nRouters = nRouters; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | } |
| 48 | protected: |
| 49 | void |
| 50 | allocateAdjMatrix(); |
| 51 | |
| 52 | void |
| 53 | initMatrix(); |
| 54 | |
| 55 | void |
| 56 | makeAdjMatrix(Nlsr& pnlsr, Map pMap); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 57 | |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 58 | void |
| 59 | writeAdjMatrixLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | |
| 61 | int |
| 62 | getNumOfLinkfromAdjMatrix(int sRouter); |
| 63 | |
| 64 | void |
| 65 | freeAdjMatrix(); |
| 66 | |
| 67 | void |
| 68 | adjustAdMatrix(int source, int link, double linkCost); |
| 69 | |
| 70 | void |
| 71 | getLinksFromAdjMatrix(int* links, double* linkCosts, int source); |
| 72 | |
| 73 | void |
| 74 | allocateLinks(); |
| 75 | |
| 76 | void |
| 77 | allocateLinkCosts(); |
| 78 | |
| 79 | void |
| 80 | freeLinks(); |
| 81 | |
| 82 | void |
| 83 | freeLinksCosts(); |
| 84 | |
| 85 | void |
| 86 | setNoLink(int nl) |
| 87 | { |
| 88 | vNoLink = nl; |
| 89 | } |
| 90 | |
| 91 | protected: |
| 92 | double** adjMatrix; |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 93 | size_t m_nRouters; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 94 | |
| 95 | int vNoLink; |
| 96 | int* links; |
| 97 | double* linkCosts; |
| 98 | }; |
| 99 | |
| 100 | class LinkStateRoutingTableCalculator: public RoutingTableCalculator |
| 101 | { |
| 102 | public: |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 103 | LinkStateRoutingTableCalculator(size_t nRouters) |
| 104 | : RoutingTableCalculator(nRouters) |
| 105 | , EMPTY_PARENT(-12345) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | , INF_DISTANCE(2147483647) |
| 107 | , NO_MAPPING_NUM(-1) |
| 108 | , NO_NEXT_HOP(-12345) |
| 109 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | } |
| 111 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 112 | void |
| 113 | calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr); |
| 114 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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 |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt, |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 127 | Map& pMap, uint32_t sourceRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | |
| 129 | int |
| 130 | getLsNextHop(int dest, int source); |
| 131 | |
| 132 | void |
| 133 | allocateParent(); |
| 134 | |
| 135 | void |
| 136 | allocateDistance(); |
| 137 | |
| 138 | void |
| 139 | freeParent(); |
| 140 | |
| 141 | void |
| 142 | freeDistance(); |
| 143 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 144 | private: |
| 145 | int* m_parent; |
| 146 | double* m_distance; |
| 147 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 148 | const int EMPTY_PARENT; |
| 149 | const double INF_DISTANCE; |
| 150 | const int NO_MAPPING_NUM; |
| 151 | const int NO_NEXT_HOP; |
| 152 | |
| 153 | }; |
| 154 | |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 155 | class AdjacencyList; |
| 156 | class Lsdb; |
| 157 | |
| 158 | class HyperbolicRoutingCalculator |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 159 | { |
| 160 | public: |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 161 | HyperbolicRoutingCalculator(size_t nRouters, bool isDryRun, ndn::Name thisRouterName) |
| 162 | : m_nRouters(nRouters) |
| 163 | , m_isDryRun(isDryRun) |
| 164 | , m_thisRouterName(thisRouterName) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 165 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 169 | calculatePaths(Map& map, RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 170 | |
| 171 | private: |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 172 | double |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 173 | getHyperbolicDistance(Map& map, Lsdb& lsdb, ndn::Name src, ndn::Name dest); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 174 | |
| 175 | void |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 176 | addNextHop(ndn::Name destinationRouter, std::string faceUri, double cost, RoutingTable& rt); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 177 | |
| 178 | private: |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 179 | const size_t m_nRouters; |
| 180 | const bool m_isDryRun; |
| 181 | const ndn::Name m_thisRouterName; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 182 | |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame^] | 183 | static const double MATH_PI; |
| 184 | static const double UNKNOWN_DISTANCE; |
| 185 | static const double UNKNOWN_RADIUS; |
| 186 | static const int32_t ROUTER_NOT_FOUND; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | }//namespace nlsr |
| 190 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 191 | #endif //NLSR_ROUTING_TABLE_CALCULATOR_HPP |