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