akmhoque | 3d06e79 | 2014-05-27 16:23:20 -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, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 19 | */ |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 20 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 21 | #include "route/routing-table.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 22 | #include "nlsr.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 23 | #include "route/routing-table-entry.hpp" |
| 24 | #include "route/nexthop.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 25 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 26 | #include "tests/io-key-chain-fixture.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 27 | #include "tests/test-common.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 28 | |
| 29 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 30 | namespace test { |
| 31 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 32 | class RoutingTableFixture : public IoKeyChainFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 34 | private: |
| 35 | ndn::Scheduler m_scheduler{m_io}; |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 36 | |
| 37 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 38 | ndn::DummyClientFace face{m_io, m_keyChain, {true, true}}; |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 39 | ConfParameter conf{face, m_keyChain}; |
| 40 | DummyConfFileProcessor confProcessor{conf}; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 41 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 42 | Lsdb lsdb{face, m_keyChain, conf}; |
| 43 | RoutingTable rt{m_scheduler, lsdb, conf}; |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 44 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 45 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 46 | BOOST_AUTO_TEST_SUITE(TestRoutingTable) |
| 47 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 48 | BOOST_FIXTURE_TEST_CASE(AddNextHop, RoutingTableFixture) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 49 | { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 50 | NextHop nh1; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 51 | const std::string DEST_ROUTER = "destRouter"; |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 52 | rt.addNextHop(DEST_ROUTER, nh1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 53 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(rt.findRoutingTableEntry(DEST_ROUTER)->getDestination(), DEST_ROUTER); |
| 55 | } |
| 56 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 57 | const uint8_t RoutingTableData1[] = { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 58 | // Header |
| 59 | 0x90, 0x20, |
| 60 | // Routing table entry |
| 61 | 0x91, 0x1e, |
| 62 | // Destination |
| 63 | 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x13, |
| 64 | // Nexthop |
| 65 | 0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f, 0xfa, 0x66, |
| 66 | 0x66, 0x66, 0x66, 0x66, 0x66 |
| 67 | }; |
| 68 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 69 | const uint8_t RoutingTableData2[] = { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 70 | // Header |
| 71 | 0x90, 0x00 |
| 72 | }; |
| 73 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 74 | BOOST_FIXTURE_TEST_CASE(Encode, RoutingTableFixture) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 75 | { |
| 76 | NextHop nexthops; |
| 77 | nexthops.setConnectingFaceUri("nexthop"); |
| 78 | nexthops.setRouteCost(1.65); |
| 79 | rt.addNextHop("dest1", nexthops); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 80 | BOOST_TEST(rt.wireEncode() == RoutingTableData1, boost::test_tools::per_element()); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 83 | BOOST_FIXTURE_TEST_CASE(EncodeEmpty, RoutingTableFixture) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 84 | { |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 85 | BOOST_TEST(rt.wireEncode() == RoutingTableData2, boost::test_tools::per_element()); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 88 | BOOST_FIXTURE_TEST_CASE(Decode, RoutingTableFixture) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 89 | { |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 90 | RoutingTableStatus rtStatus(ndn::Block{RoutingTableData1}); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 91 | |
| 92 | auto it1 = rtStatus.m_rTable.begin(); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 93 | ndn::Name des1 = it1->getDestination(); |
| 94 | BOOST_CHECK_EQUAL(des1, "dest1"); |
| 95 | |
| 96 | auto it2 = it1->getNexthopList().begin(); |
| 97 | BOOST_CHECK_EQUAL(it2->getConnectingFaceUri(), "nexthop"); |
| 98 | BOOST_CHECK_EQUAL(it2->getRouteCost(), 1.65); |
| 99 | |
| 100 | BOOST_CHECK_EQUAL(rtStatus.m_rTable.size(), 1); |
| 101 | } |
| 102 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 103 | BOOST_FIXTURE_TEST_CASE(OutputStream, RoutingTableFixture) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 104 | { |
| 105 | NextHop nexthops; |
| 106 | nexthops.setConnectingFaceUri("nexthop"); |
| 107 | nexthops.setRouteCost(99); |
| 108 | rt.addNextHop("dest1", nexthops); |
| 109 | |
| 110 | std::ostringstream os; |
| 111 | os << rt; |
| 112 | |
| 113 | BOOST_CHECK_EQUAL(os.str(), |
| 114 | "Routing Table:\n" |
| 115 | " Destination: /dest1\n" |
| 116 | " NextHop(Uri: nexthop, Cost: 99)\n"); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 117 | } |
| 118 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 119 | BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, RoutingTableFixture) |
| 120 | { |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 121 | auto testTimePoint = ndn::time::system_clock::now() + 3600_s; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 122 | ndn::Name router2("/router2"); |
| 123 | AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList()); |
| 124 | std::shared_ptr<Lsa> lsaPtr = std::make_shared<AdjLsa>(adjLsa); |
| 125 | BOOST_CHECK(!rt.m_isRouteCalculationScheduled); |
| 126 | lsdb.installLsa(lsaPtr); |
| 127 | BOOST_CHECK(rt.m_isRouteCalculationScheduled); |
| 128 | |
| 129 | // After 15_s (by default) routing table calculation is done |
| 130 | advanceClocks(15_s); |
| 131 | BOOST_CHECK(!rt.m_isRouteCalculationScheduled); |
| 132 | |
| 133 | // Update to installed LSA |
| 134 | std::shared_ptr<Lsa> lsaPtr2 = std::make_shared<AdjLsa>(adjLsa); |
| 135 | auto adjPtr = std::static_pointer_cast<AdjLsa>(lsaPtr2); |
| 136 | adjPtr->addAdjacent(Adjacent("router3")); |
| 137 | adjPtr->setSeqNo(13); |
| 138 | lsdb.installLsa(lsaPtr2); |
| 139 | BOOST_CHECK(rt.m_isRouteCalculationScheduled); |
| 140 | |
| 141 | // Insert a neighbor so that AdjLsa can be installed |
| 142 | AdjacencyList adjl; |
| 143 | Adjacent ownAdj(conf.getRouterPrefix()); |
| 144 | ownAdj.setStatus(Adjacent::STATUS_ACTIVE); |
| 145 | adjl.insert(ownAdj); |
| 146 | AdjLsa adjLsa4("/router4", 12, testTimePoint, 2, adjl); |
| 147 | lsaPtr = std::make_shared<AdjLsa>(adjLsa4); |
| 148 | lsdb.installLsa(lsaPtr); |
| 149 | |
| 150 | Adjacent adj("/router4"); |
| 151 | adj.setStatus(Adjacent::STATUS_ACTIVE); |
| 152 | conf.getAdjacencyList().insert(adj); |
| 153 | lsdb.scheduleAdjLsaBuild(); |
| 154 | BOOST_CHECK_EQUAL(rt.m_rTable.size(), 0); |
| 155 | advanceClocks(15_s); |
| 156 | BOOST_CHECK_EQUAL(rt.m_rTable.size(), 1); |
| 157 | |
| 158 | rt.wireEncode(); |
| 159 | BOOST_CHECK(rt.m_wire.isValid()); |
| 160 | BOOST_CHECK_GT(rt.m_wire.size(), 0); |
| 161 | |
| 162 | // Remove own Adj Lsa - Make sure routing table is wiped out |
| 163 | conf.getAdjacencyList().setStatusOfNeighbor("/router4", Adjacent::STATUS_INACTIVE); |
| 164 | conf.getAdjacencyList().setTimedOutInterestCount("/router4", HELLO_RETRIES_MAX); |
| 165 | lsdb.scheduleAdjLsaBuild(); |
| 166 | advanceClocks(15_s); |
| 167 | BOOST_CHECK_EQUAL(rt.m_rTable.size(), 0); |
| 168 | BOOST_CHECK(!rt.m_wire.isValid()); |
| 169 | |
| 170 | // Check that HR routing is scheduled, once Coordinate LSA is added |
| 171 | BOOST_CHECK(!rt.m_isRouteCalculationScheduled); |
| 172 | rt.m_hyperbolicState = HYPERBOLIC_STATE_ON; |
| 173 | CoordinateLsa clsa("router5", 12, testTimePoint, 2.5, {30.0}); |
| 174 | auto clsaPtr = std::make_shared<CoordinateLsa>(clsa); |
| 175 | lsdb.installLsa(clsaPtr); |
| 176 | BOOST_CHECK(rt.m_isRouteCalculationScheduled); |
| 177 | |
| 178 | Adjacent router5("/router5"); |
| 179 | router5.setStatus(Adjacent::STATUS_ACTIVE); |
| 180 | conf.getAdjacencyList().insert(router5); |
| 181 | conf.getAdjacencyList().setStatusOfNeighbor("/router5", Adjacent::STATUS_ACTIVE); |
| 182 | advanceClocks(15_s); |
| 183 | rt.wireEncode(); |
| 184 | BOOST_CHECK(rt.m_wire.isValid()); |
| 185 | BOOST_CHECK_GT(rt.m_wire.size(), 0); |
| 186 | BOOST_CHECK(!rt.m_isRouteCalculationScheduled); |
| 187 | |
| 188 | // Emulate HelloProtocol neighbor down |
| 189 | conf.getAdjacencyList().setStatusOfNeighbor("/router5", Adjacent::STATUS_INACTIVE); |
| 190 | rt.scheduleRoutingTableCalculation(); |
| 191 | advanceClocks(15_s); |
| 192 | BOOST_CHECK_EQUAL(rt.m_rTable.size(), 0); |
| 193 | BOOST_CHECK(!rt.m_wire.isValid()); |
| 194 | } |
| 195 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 196 | BOOST_AUTO_TEST_SUITE_END() |
| 197 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 198 | } // namespace test |
| 199 | } // namespace nlsr |