Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | **/ |
| 21 | |
| 22 | #include "route/routing-table-calculator.hpp" |
| 23 | |
| 24 | #include "adjacency-list.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 25 | //#include "lsa.hpp" |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 26 | #include "lsdb.hpp" |
| 27 | #include "nlsr.hpp" |
| 28 | #include "test-common.hpp" |
| 29 | #include "route/map.hpp" |
| 30 | #include "route/routing-table.hpp" |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 31 | #include "adjacent.hpp" |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 32 | |
| 33 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 34 | |
| 35 | namespace nlsr { |
| 36 | namespace test { |
| 37 | |
| 38 | static const ndn::time::system_clock::TimePoint MAX_TIME = |
| 39 | ndn::time::system_clock::TimePoint::max(); |
| 40 | |
| 41 | class LinkStateCalculatorFixture : public BaseFixture |
| 42 | { |
| 43 | public: |
| 44 | LinkStateCalculatorFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 45 | : face(m_ioService, m_keyChain) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 46 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 47 | , confProcessor(conf) |
| 48 | , nlsr(face, m_keyChain, conf) |
| 49 | , routingTable(nlsr.m_routingTable) |
| 50 | , lsdb(nlsr.m_lsdb) |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 51 | { |
| 52 | setUpTopology(); |
| 53 | } |
| 54 | |
| 55 | // Triangle topology with routers A, B, C connected |
| 56 | void setUpTopology() |
| 57 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 58 | Adjacent a(ROUTER_A_NAME, ndn::FaceUri(ROUTER_A_FACE), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
| 59 | Adjacent b(ROUTER_B_NAME, ndn::FaceUri(ROUTER_B_FACE), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
| 60 | Adjacent c(ROUTER_C_NAME, ndn::FaceUri(ROUTER_C_FACE), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 61 | |
| 62 | // Router A |
| 63 | b.setLinkCost(LINK_AB_COST); |
| 64 | c.setLinkCost(LINK_AC_COST); |
| 65 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 66 | AdjacencyList& adjacencyListA = conf.getAdjacencyList(); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 67 | adjacencyListA.insert(b); |
| 68 | adjacencyListA.insert(c); |
| 69 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 70 | AdjLsa adjA(a.getName(), 1, MAX_TIME, 2, adjacencyListA); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 71 | lsdb.installAdjLsa(adjA); |
| 72 | |
| 73 | // Router B |
| 74 | a.setLinkCost(LINK_AB_COST); |
| 75 | c.setLinkCost(LINK_BC_COST); |
| 76 | |
| 77 | AdjacencyList adjacencyListB; |
| 78 | adjacencyListB.insert(a); |
| 79 | adjacencyListB.insert(c); |
| 80 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 81 | AdjLsa adjB(b.getName(), 1, MAX_TIME, 2, adjacencyListB); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 82 | lsdb.installAdjLsa(adjB); |
| 83 | |
| 84 | // Router C |
| 85 | a.setLinkCost(LINK_AC_COST); |
| 86 | b.setLinkCost(LINK_BC_COST); |
| 87 | |
| 88 | AdjacencyList adjacencyListC; |
| 89 | adjacencyListC.insert(a); |
| 90 | adjacencyListC.insert(b); |
| 91 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 92 | AdjLsa adjC(c.getName(), 1, MAX_TIME, 2, adjacencyListC); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 93 | lsdb.installAdjLsa(adjC); |
| 94 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 95 | map.createFromAdjLsdb(lsdb.getAdjLsdb().begin(), lsdb.getAdjLsdb().end()); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 99 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 100 | ConfParameter conf; |
| 101 | DummyConfFileProcessor confProcessor; |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 102 | Nlsr nlsr; |
| 103 | Map map; |
| 104 | |
| 105 | RoutingTable& routingTable; |
| 106 | Lsdb& lsdb; |
| 107 | |
| 108 | static const ndn::Name ROUTER_A_NAME; |
| 109 | static const ndn::Name ROUTER_B_NAME; |
| 110 | static const ndn::Name ROUTER_C_NAME; |
| 111 | |
| 112 | static const std::string ROUTER_A_FACE; |
| 113 | static const std::string ROUTER_B_FACE; |
| 114 | static const std::string ROUTER_C_FACE; |
| 115 | |
| 116 | static const double LINK_AB_COST; |
| 117 | static const double LINK_AC_COST; |
| 118 | static const double LINK_BC_COST; |
| 119 | }; |
| 120 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 121 | const ndn::Name LinkStateCalculatorFixture::ROUTER_A_NAME = "/ndn/site/%C1.Router/this-router"; |
| 122 | const ndn::Name LinkStateCalculatorFixture::ROUTER_B_NAME = "/ndn/site/%C1.Router/b"; |
| 123 | const ndn::Name LinkStateCalculatorFixture::ROUTER_C_NAME = "/ndn/site/%C1.Router/c"; |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 124 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 125 | const std::string LinkStateCalculatorFixture::ROUTER_A_FACE = "udp4://10.0.0.1"; |
| 126 | const std::string LinkStateCalculatorFixture::ROUTER_B_FACE = "udp4://10.0.0.2"; |
| 127 | const std::string LinkStateCalculatorFixture::ROUTER_C_FACE = "udp4://10.0.0.3"; |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 128 | |
| 129 | const double LinkStateCalculatorFixture::LINK_AB_COST = 5; |
| 130 | const double LinkStateCalculatorFixture::LINK_AC_COST = 10; |
| 131 | const double LinkStateCalculatorFixture::LINK_BC_COST = 17; |
| 132 | |
| 133 | BOOST_FIXTURE_TEST_SUITE(TestLinkStateRoutingCalculator, LinkStateCalculatorFixture) |
| 134 | |
| 135 | BOOST_AUTO_TEST_CASE(Basic) |
| 136 | { |
| 137 | LinkStateRoutingTableCalculator calculator(map.getMapSize()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 138 | calculator.calculatePath(map, routingTable, conf, lsdb.getAdjLsdb()); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 139 | |
| 140 | RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME); |
| 141 | BOOST_REQUIRE(entryB != nullptr); |
| 142 | |
| 143 | // Router A should be able to get to B through B and to B through C |
| 144 | NexthopList& bHopList = entryB->getNexthopList(); |
| 145 | BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 2); |
| 146 | |
| 147 | for (const NextHop& hop : bHopList) { |
| 148 | std::string faceUri = hop.getConnectingFaceUri(); |
| 149 | uint64_t cost = hop.getRouteCostAsAdjustedInteger(); |
| 150 | |
| 151 | BOOST_CHECK((faceUri == ROUTER_B_FACE && cost == LINK_AB_COST) || |
| 152 | (faceUri == ROUTER_C_FACE && cost == LINK_AC_COST + LINK_BC_COST)); |
| 153 | |
| 154 | } |
| 155 | |
| 156 | RoutingTableEntry* entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME); |
| 157 | BOOST_REQUIRE(entryC != nullptr); |
| 158 | |
| 159 | // Router A should be able to get to C through C and to C through B |
| 160 | NexthopList& cHopList = entryC->getNexthopList(); |
| 161 | BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 2); |
| 162 | |
| 163 | for (const NextHop& hop : cHopList) { |
| 164 | std::string faceUri = hop.getConnectingFaceUri(); |
| 165 | uint64_t cost = hop.getRouteCostAsAdjustedInteger(); |
| 166 | |
| 167 | BOOST_CHECK((faceUri == ROUTER_C_FACE && cost == LINK_AC_COST) || |
| 168 | (faceUri == ROUTER_B_FACE && cost == LINK_AB_COST + LINK_BC_COST)); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | BOOST_AUTO_TEST_CASE(Asymmetric) |
| 173 | { |
| 174 | // Asymmetric link cost between B and C |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 175 | ndn::Name key = ndn::Name(ROUTER_B_NAME).append(boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY)); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 176 | AdjLsa* lsa = nlsr.m_lsdb.findAdjLsa(key); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 177 | BOOST_REQUIRE(lsa != nullptr); |
| 178 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 179 | auto c = lsa->m_adl.findAdjacent(ROUTER_C_NAME); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 180 | BOOST_REQUIRE(c != conf.getAdjacencyList().end()); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 181 | |
| 182 | double higherLinkCost = LINK_BC_COST + 1; |
| 183 | c->setLinkCost(higherLinkCost); |
| 184 | |
| 185 | // Calculation should consider the link between B and C as having cost = higherLinkCost |
| 186 | LinkStateRoutingTableCalculator calculator(map.getMapSize()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 187 | calculator.calculatePath(map, routingTable, conf, lsdb.getAdjLsdb()); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 188 | |
| 189 | RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME); |
| 190 | BOOST_REQUIRE(entryB != nullptr); |
| 191 | |
| 192 | // Router A should be able to get to B through B and to B through C |
| 193 | NexthopList& bHopList = entryB->getNexthopList(); |
| 194 | BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 2); |
| 195 | |
| 196 | for (const NextHop& hop : bHopList) { |
| 197 | std::string faceUri = hop.getConnectingFaceUri(); |
| 198 | uint64_t cost = hop.getRouteCostAsAdjustedInteger(); |
| 199 | |
| 200 | BOOST_CHECK((faceUri == ROUTER_B_FACE && cost == LINK_AB_COST) || |
| 201 | (faceUri == ROUTER_C_FACE && cost == LINK_AC_COST + higherLinkCost)); |
| 202 | |
| 203 | } |
| 204 | |
| 205 | RoutingTableEntry* entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME); |
| 206 | BOOST_REQUIRE(entryC != nullptr); |
| 207 | |
| 208 | // Router A should be able to get to C through C and to C through B |
| 209 | NexthopList& cHopList = entryC->getNexthopList(); |
| 210 | BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 2); |
| 211 | |
| 212 | for (const NextHop& hop : cHopList) { |
| 213 | std::string faceUri = hop.getConnectingFaceUri(); |
| 214 | uint64_t cost = hop.getRouteCostAsAdjustedInteger(); |
| 215 | |
| 216 | BOOST_CHECK((faceUri == ROUTER_C_FACE && cost == LINK_AC_COST) || |
| 217 | (faceUri == ROUTER_B_FACE && cost == LINK_AB_COST + higherLinkCost)); |
| 218 | } |
| 219 | } |
| 220 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 221 | BOOST_AUTO_TEST_CASE(NonAdjacentCost) |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 222 | { |
| 223 | // Asymmetric link cost between B and C |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 224 | ndn::Name key = ndn::Name(ROUTER_B_NAME).append(boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY)); |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 225 | auto lsa = nlsr.m_lsdb.findAdjLsa(key); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 226 | BOOST_REQUIRE(lsa != nullptr); |
| 227 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 228 | auto c = lsa->m_adl.findAdjacent(ROUTER_C_NAME); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 229 | BOOST_REQUIRE(c != conf.getAdjacencyList().end()); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 230 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 231 | // Break the link between B - C by setting it to a NON_ADJACENT_COST. |
| 232 | c->setLinkCost(Adjacent::NON_ADJACENT_COST); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 233 | |
| 234 | // Calculation should consider the link between B and C as down |
| 235 | LinkStateRoutingTableCalculator calculator(map.getMapSize()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 236 | calculator.calculatePath(map, routingTable, conf, lsdb.getAdjLsdb()); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 237 | |
| 238 | // Router A should be able to get to B through B but not through C |
| 239 | RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME); |
| 240 | BOOST_REQUIRE(entryB != nullptr); |
| 241 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 242 | auto bHopList = entryB->getNexthopList(); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 243 | BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 1); |
| 244 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 245 | const auto nextHopForB = bHopList.getNextHops().begin(); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 246 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 247 | BOOST_CHECK(nextHopForB->getConnectingFaceUri() == ROUTER_B_FACE && |
| 248 | nextHopForB->getRouteCostAsAdjustedInteger() == LINK_AB_COST); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 249 | |
| 250 | // Router A should be able to get to C through C but not through B |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 251 | auto entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 252 | BOOST_REQUIRE(entryC != nullptr); |
| 253 | |
| 254 | NexthopList& cHopList = entryC->getNexthopList(); |
| 255 | BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 1); |
| 256 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 257 | const auto nextHopForC = cHopList.getNextHops().begin(); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 258 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 259 | BOOST_CHECK(nextHopForC->getConnectingFaceUri() == ROUTER_C_FACE && |
| 260 | nextHopForC->getRouteCostAsAdjustedInteger() == LINK_AC_COST); |
| 261 | } |
| 262 | |
| 263 | BOOST_AUTO_TEST_CASE(AsymmetricZeroCostLink) |
| 264 | { |
| 265 | // Asymmetric and zero link cost between B - C, and B - A. |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 266 | ndn::Name keyB = ndn::Name(ROUTER_B_NAME).append(boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY)); |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 267 | auto lsaB = nlsr.m_lsdb.findAdjLsa(keyB); |
| 268 | BOOST_REQUIRE(lsaB != nullptr); |
| 269 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 270 | auto c = lsaB->m_adl.findAdjacent(ROUTER_C_NAME); |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 271 | BOOST_REQUIRE(c != conf.getAdjacencyList().end()); |
| 272 | // Re-adjust link cost to 0 from B-C. However, this should not set B-C cost 0 because C-B |
| 273 | // cost is greater that 0 i.e. 17 |
| 274 | c->setLinkCost(0); |
| 275 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 276 | auto a = lsaB->m_adl.findAdjacent(ROUTER_A_NAME); |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 277 | BOOST_REQUIRE(a != conf.getAdjacencyList().end()); |
| 278 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 279 | ndn::Name keyA = ndn::Name(ROUTER_A_NAME).append(boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY)); |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 280 | auto lsaA = nlsr.m_lsdb.findAdjLsa(keyA); |
| 281 | BOOST_REQUIRE(lsaA != nullptr); |
| 282 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 283 | auto b = lsaA->m_adl.findAdjacent(ROUTER_B_NAME); |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame] | 284 | BOOST_REQUIRE(b != conf.getAdjacencyList().end()); |
| 285 | |
| 286 | // Re-adjust link cost to 0 from both the direction i.e B-A and A-B |
| 287 | a->setLinkCost(0); |
| 288 | b->setLinkCost(0); |
| 289 | |
| 290 | // Calculation should consider 0 link-cost between B and C |
| 291 | LinkStateRoutingTableCalculator calculator(map.getMapSize()); |
| 292 | calculator.calculatePath(map, routingTable, conf, lsdb.getAdjLsdb()); |
| 293 | |
| 294 | // Router A should be able to get to B through B and C |
| 295 | RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME); |
| 296 | BOOST_REQUIRE(entryB != nullptr); |
| 297 | |
| 298 | // Node can have neighbors with zero cost, so the nexthop count should be 2 |
| 299 | NexthopList& bHopList = entryB->getNexthopList(); |
| 300 | BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 2); |
| 301 | |
| 302 | const auto nextHopForB = bHopList.getNextHops().begin(); |
| 303 | // Check if the next hop via B is through A or not after the cost adjustment |
| 304 | BOOST_CHECK(nextHopForB->getConnectingFaceUri() == ROUTER_B_FACE && |
| 305 | nextHopForB->getRouteCostAsAdjustedInteger() == 0); |
| 306 | |
| 307 | // Router A should be able to get to C through C and B |
| 308 | auto entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME); |
| 309 | BOOST_REQUIRE(entryC != nullptr); |
| 310 | |
| 311 | NexthopList& cHopList = entryC->getNexthopList(); |
| 312 | BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 2); |
| 313 | |
| 314 | const auto nextHopForC = cHopList.getNextHops().begin(); |
| 315 | // Check if the nextHop from C is via A or not |
| 316 | BOOST_CHECK(nextHopForC->getConnectingFaceUri() == ROUTER_C_FACE && |
| 317 | nextHopForC->getRouteCostAsAdjustedInteger() == LINK_AC_COST); |
| 318 | |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | BOOST_AUTO_TEST_SUITE_END() |
| 322 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 323 | } // namespace test |
| 324 | } // namespace nlsr |