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