Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 2 | /* |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2014-2025, The University of Memphis, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -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 | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 20 | */ |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 21 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 22 | #include "route/name-prefix-table.hpp" |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame^] | 23 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 24 | #include "route/fib.hpp" |
| 25 | #include "route/routing-table.hpp" |
| 26 | #include "lsdb.hpp" |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 27 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 28 | #include "tests/io-key-chain-fixture.hpp" |
| 29 | #include "tests/test-common.hpp" |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 30 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 31 | namespace nlsr::tests { |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 32 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 33 | class NamePrefixTableFixture : public IoKeyChainFixture |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 34 | { |
| 35 | public: |
| 36 | NamePrefixTableFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 37 | : lsdb(face, m_keyChain, conf) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 38 | , fib(face, m_scheduler, conf.getAdjacencyList(), conf, m_keyChain) |
| 39 | , rt(m_scheduler, lsdb, conf) |
| 40 | , npt(conf.getRouterPrefix(), fib, rt, rt.afterRoutingChange, lsdb.onLsdbModified) |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 41 | { |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 44 | bool |
| 45 | isNameInNpt(const ndn::Name& name) |
| 46 | { |
| 47 | auto it = std::find_if(npt.begin(), npt.end(), |
| 48 | [&] (const auto& entry) { return name == entry->getNamePrefix(); }); |
| 49 | return it != npt.end(); |
| 50 | } |
| 51 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 52 | private: |
| 53 | ndn::Scheduler m_scheduler{m_io}; |
| 54 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 55 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 56 | ndn::DummyClientFace face{m_io, m_keyChain}; |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 57 | ConfParameter conf{face, m_keyChain}; |
| 58 | DummyConfFileProcessor confProcessor{conf}; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 59 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 60 | Lsdb lsdb; |
| 61 | Fib fib; |
| 62 | RoutingTable rt; |
| 63 | NamePrefixTable npt; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | BOOST_AUTO_TEST_SUITE(TestNamePrefixTable) |
| 67 | |
| 68 | BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture) |
| 69 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 70 | rt.m_routingCalcInterval = 0_s; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 71 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 72 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 73 | |
| 74 | ndn::Name buptRouterName("/ndn/cn/edu/bupt/%C1.Router/bupthub"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 75 | Adjacent bupt(buptRouterName, ndn::FaceUri("udp4://10.0.0.2"), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 76 | |
| 77 | // This router's Adjacency LSA |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 78 | conf.getAdjacencyList().insert(bupt); |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 79 | AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1, time::system_clock::now() + 3600_s, conf.getAdjacencyList()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 80 | lsdb.installLsa(std::make_shared<AdjLsa>(thisRouterAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 81 | |
| 82 | // BUPT Adjacency LSA |
| 83 | AdjacencyList buptAdjacencies; |
| 84 | buptAdjacencies.insert(thisRouter); |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 85 | AdjLsa buptAdjLsa(buptRouterName, 1, time::system_clock::now() + 5_s, buptAdjacencies); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 86 | lsdb.installLsa(std::make_shared<AdjLsa>(buptAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 87 | |
| 88 | // BUPT Name LSA |
| 89 | ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt"); |
Nick Gordon | 96861ca | 2017-10-17 18:25:21 -0500 | [diff] [blame] | 90 | NamePrefixList buptNames{buptAdvertisedName}; |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 91 | NameLsa buptNameLsa(buptRouterName, 1, time::system_clock::now() + 5_s, buptNames); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 92 | lsdb.installLsa(std::make_shared<NameLsa>(buptNameLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 93 | |
| 94 | // Advance clocks to expire LSAs |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 95 | this->advanceClocks(15_s); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 96 | |
| 97 | // LSA expirations should cause NPT entries to be completely removed |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 98 | auto it = npt.begin(); |
| 99 | BOOST_CHECK(it == npt.end()); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 100 | |
| 101 | // Install new name LSA |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 102 | NameLsa buptNewNameLsa(buptRouterName, 12, time::system_clock::now() + 3600_s, buptNames); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 103 | lsdb.installLsa(std::make_shared<NameLsa>(buptNewNameLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 104 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 105 | this->advanceClocks(1_s); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 106 | |
| 107 | // Install new adjacency LSA |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 108 | AdjLsa buptNewAdjLsa(buptRouterName, 12, time::system_clock::now() + 3600_s, buptAdjacencies); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 109 | lsdb.installLsa(std::make_shared<AdjLsa>(buptNewAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 110 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 111 | this->advanceClocks(1_s); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 112 | |
| 113 | // Each NPT entry should have a destination router |
| 114 | it = npt.begin(); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 115 | BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptRouterName); |
| 116 | BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1); |
| 117 | BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 118 | |
| 119 | ++it; |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 120 | BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptAdvertisedName); |
| 121 | BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1); |
| 122 | BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | BOOST_FIXTURE_TEST_CASE(AddEntryToPool, NamePrefixTableFixture) |
| 126 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 127 | RoutingTablePoolEntry rtpe1("router1"); |
| 128 | |
| 129 | npt.addRtpeToPool(rtpe1); |
| 130 | |
| 131 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1); |
| 132 | BOOST_CHECK_EQUAL(*(npt.m_rtpool.find("router1")->second), rtpe1); |
| 133 | } |
| 134 | |
| 135 | BOOST_FIXTURE_TEST_CASE(RemoveEntryFromPool, NamePrefixTableFixture) |
| 136 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 137 | RoutingTablePoolEntry rtpe1("router1", 0); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 138 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 139 | |
| 140 | npt.addRtpeToPool(rtpe1); |
| 141 | |
| 142 | npt.deleteRtpeFromPool(rtpePtr); |
| 143 | |
| 144 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 0); |
| 145 | BOOST_CHECK_EQUAL(npt.m_rtpool.count("router1"), 0); |
| 146 | } |
| 147 | |
| 148 | BOOST_FIXTURE_TEST_CASE(AddRoutingEntryToNptEntry, NamePrefixTableFixture) |
| 149 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 150 | RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 151 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 152 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
| 153 | |
| 154 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 155 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 156 | auto nItr = std::find_if(npt.m_table.begin(), |
| 157 | npt.m_table.end(), |
| 158 | [&] (const auto& entry) { |
| 159 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 160 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 161 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 162 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 163 | auto rItr = std::find(rtpeList.begin(), rtpeList.end(), rtpePtr); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 164 | BOOST_CHECK_EQUAL(**rItr, *rtpePtr); |
| 165 | } |
| 166 | |
| 167 | BOOST_FIXTURE_TEST_CASE(RemoveRoutingEntryFromNptEntry, NamePrefixTableFixture) |
| 168 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 169 | RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0); |
| 170 | |
| 171 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 172 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1)); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 173 | |
| 174 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 175 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/altrtr"); |
| 176 | |
| 177 | npt.removeEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 178 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 179 | auto nItr = std::find_if(npt.m_table.begin(), |
| 180 | npt.m_table.end(), |
| 181 | [&] (const auto& entry) { |
| 182 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 183 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 184 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 185 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 186 | |
| 187 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 188 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 191 | BOOST_FIXTURE_TEST_CASE(AddNptEntryPtrToRoutingEntry, NamePrefixTableFixture) |
| 192 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 193 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 194 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1)); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 195 | |
| 196 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 197 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 198 | auto nItr = std::find_if(npt.m_table.begin(), |
| 199 | npt.m_table.end(), |
| 200 | [&] (const auto& entry) { |
| 201 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 202 | }); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 203 | |
| 204 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
| 205 | |
| 206 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 207 | |
| 208 | auto& namePrefixPtrs = rtpeList.front()->namePrefixTableEntries; |
| 209 | |
| 210 | auto nptIterator = namePrefixPtrs.find(npte1.getNamePrefix()); |
| 211 | BOOST_REQUIRE(nptIterator != namePrefixPtrs.end()); |
| 212 | auto nptSharedPtr = nptIterator->second.lock(); |
| 213 | BOOST_CHECK_EQUAL(*nptSharedPtr, npte1); |
| 214 | } |
| 215 | |
| 216 | BOOST_FIXTURE_TEST_CASE(RemoveNptEntryPtrFromRoutingEntry, NamePrefixTableFixture) |
| 217 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 218 | NamePrefixTableEntry npte1("/ndn/memphis/rtr1"); |
| 219 | NamePrefixTableEntry npte2("/ndn/memphis/rtr2"); |
| 220 | RoutingTableEntry rte1("/ndn/memphis/destination1"); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 221 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1)); |
| 222 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte2)); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 223 | |
| 224 | npt.addEntry(npte1.getNamePrefix(), rte1.getDestination()); |
| 225 | // We have to add two entries, otherwise the routing pool entry will be deleted. |
| 226 | npt.addEntry(npte2.getNamePrefix(), rte1.getDestination()); |
| 227 | npt.removeEntry(npte2.getNamePrefix(), rte1.getDestination()); |
| 228 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 229 | auto nItr = std::find_if(npt.m_table.begin(), |
| 230 | npt.m_table.end(), |
| 231 | [&] (const auto& entry) { |
| 232 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 233 | }); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 234 | |
| 235 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
| 236 | |
| 237 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 238 | |
| 239 | auto& namePrefixPtrs = rtpeList.front()->namePrefixTableEntries; |
| 240 | |
| 241 | // We should have removed the second one |
| 242 | BOOST_CHECK_EQUAL(namePrefixPtrs.size(), 1); |
| 243 | |
| 244 | auto nptIterator = namePrefixPtrs.find(npte1.getNamePrefix()); |
| 245 | |
| 246 | BOOST_REQUIRE(nptIterator != namePrefixPtrs.end()); |
| 247 | auto nptSharedPtr = nptIterator->second.lock(); |
| 248 | BOOST_CHECK_EQUAL(*nptSharedPtr, npte1); |
| 249 | } |
| 250 | |
| 251 | BOOST_FIXTURE_TEST_CASE(RoutingTableUpdate, NamePrefixTableFixture) |
| 252 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 253 | const ndn::Name destination = ndn::Name{"/ndn/destination1"}; |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame] | 254 | NextHop hop1{ndn::FaceUri("upd4://10.0.0.1"), 0}; |
| 255 | NextHop hop2{ndn::FaceUri("upd4://10.0.0.2"), 1}; |
| 256 | NextHop hop3{ndn::FaceUri("upd4://10.0.0.3"), 2}; |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 257 | const NamePrefixTableEntry entry1{"/ndn/router1"}; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 258 | npt.addEntry(entry1.getNamePrefix(), destination); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 259 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 260 | rt.addNextHop(destination, hop1); |
| 261 | rt.addNextHop(destination, hop2); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 262 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 263 | npt.updateWithNewRoute(rt.m_rTable); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 264 | |
| 265 | // At this point the NamePrefixTableEntry should have two NextHops. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 266 | auto nameIterator = std::find_if(npt.begin(), npt.end(), |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 267 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 268 | return entry1.getNamePrefix() == entry->getNamePrefix(); |
| 269 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 270 | BOOST_REQUIRE(nameIterator != npt.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 271 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 272 | auto iterator = npt.m_rtpool.find(destination); |
| 273 | BOOST_REQUIRE(iterator != npt.m_rtpool.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 274 | auto nextHops = (iterator->second)->getNexthopList(); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 275 | BOOST_CHECK_EQUAL(nextHops.size(), 2); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 276 | |
| 277 | // Add the other NextHop |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 278 | rt.addNextHop(destination, hop3); |
| 279 | npt.updateWithNewRoute(rt.m_rTable); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 280 | |
| 281 | // At this point the NamePrefixTableEntry should have three NextHops. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 282 | nameIterator = std::find_if(npt.begin(), npt.end(), |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 283 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 284 | return entry1.getNamePrefix() == entry->getNamePrefix(); |
| 285 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 286 | BOOST_REQUIRE(nameIterator != npt.end()); |
| 287 | iterator = npt.m_rtpool.find(destination); |
| 288 | BOOST_REQUIRE(iterator != npt.m_rtpool.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 289 | nextHops = (iterator->second)->getNexthopList(); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 290 | BOOST_CHECK_EQUAL(nextHops.size(), 3); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 291 | } |
| 292 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 293 | BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, NamePrefixTableFixture) |
| 294 | { |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 295 | auto testTimePoint = time::system_clock::now(); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 296 | NamePrefixList npl1; |
| 297 | ndn::Name n1("name1"); |
| 298 | ndn::Name n2("name2"); |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame^] | 299 | PrefixInfo p1 = PrefixInfo(n1, 0); |
| 300 | PrefixInfo p2 = PrefixInfo(n2, 0); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 301 | ndn::Name router1("/router1/1"); |
| 302 | |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame^] | 303 | npl1.insert(p1); |
| 304 | npl1.insert(p2); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 305 | |
| 306 | NameLsa nlsa1(router1, 12, testTimePoint, npl1); |
| 307 | std::shared_ptr<Lsa> lsaPtr = std::make_shared<NameLsa>(nlsa1); |
| 308 | |
| 309 | BOOST_CHECK(npt.begin() == npt.end()); |
| 310 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {}); |
| 311 | BOOST_CHECK_EQUAL(npt.m_table.size(), 3); // Router + 2 names |
| 312 | |
| 313 | BOOST_CHECK(isNameInNpt(n1)); |
| 314 | BOOST_CHECK(isNameInNpt(n2)); |
| 315 | |
| 316 | ndn::Name n3("name3"); |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame^] | 317 | PrefixInfo p3 = PrefixInfo(n3, 0); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 318 | auto nlsa = std::static_pointer_cast<NameLsa>(lsaPtr); |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame^] | 319 | nlsa->removeName(p2); |
| 320 | nlsa->addName(p3); |
| 321 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::UPDATED, {p3}, {p2}); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 322 | BOOST_CHECK(isNameInNpt(n1)); |
| 323 | BOOST_CHECK(!isNameInNpt(n2)); // Removed |
| 324 | BOOST_CHECK(isNameInNpt(n3)); |
| 325 | |
| 326 | BOOST_CHECK_EQUAL(npt.m_table.size(), 3); // Still router + 2 names |
| 327 | |
| 328 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
| 329 | BOOST_CHECK_EQUAL(npt.m_table.size(), 0); |
| 330 | |
| 331 | // Adj and Coordinate LSAs router |
| 332 | ndn::Name router2("/router2/2"); |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 333 | AdjLsa adjLsa(router2, 12, testTimePoint, conf.getAdjacencyList()); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 334 | lsaPtr = std::make_shared<AdjLsa>(adjLsa); |
| 335 | BOOST_CHECK(npt.begin() == npt.end()); |
| 336 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {}); |
| 337 | BOOST_CHECK_EQUAL(npt.m_table.size(), 1); |
| 338 | BOOST_CHECK(isNameInNpt(router2)); |
| 339 | |
| 340 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
| 341 | BOOST_CHECK_EQUAL(npt.m_table.size(), 0); |
| 342 | |
| 343 | ndn::Name router3("/router3/3"); |
| 344 | CoordinateLsa corLsa(router3, 12, testTimePoint, 2, {3}); |
| 345 | lsaPtr = std::make_shared<CoordinateLsa>(corLsa); |
| 346 | BOOST_CHECK(npt.begin() == npt.end()); |
| 347 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {}); |
| 348 | BOOST_CHECK_EQUAL(npt.m_table.size(), 1); |
| 349 | BOOST_CHECK(isNameInNpt(router3)); |
| 350 | |
| 351 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
| 352 | BOOST_CHECK_EQUAL(npt.m_table.size(), 0); |
| 353 | } |
| 354 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 355 | BOOST_AUTO_TEST_SUITE_END() |
| 356 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 357 | } // namespace nlsr::tests |