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