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