blob: 5d10dd84a666c24a60ce813f1f471239b4074f3a [file] [log] [blame]
Vince Lehmancae33b62015-06-05 09:21:30 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande57a87172020-05-09 19:47:06 -07002/*
awlane6d7c37f2025-03-07 11:53:58 -06003 * Copyright (c) 2014-2025, The University of Memphis,
Vince Lehmancae33b62015-06-05 09:21:30 -05004 * 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 Gawande57a87172020-05-09 19:47:06 -070020 */
Vince Lehmancae33b62015-06-05 09:21:30 -050021
Nick Gordonc0c6bcf2017-08-15 18:11:21 -050022#include "route/name-prefix-table.hpp"
awlane6d7c37f2025-03-07 11:53:58 -060023#include "name-prefix-list.hpp"
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070024#include "route/fib.hpp"
25#include "route/routing-table.hpp"
26#include "lsdb.hpp"
Vince Lehmancae33b62015-06-05 09:21:30 -050027
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040028#include "tests/io-key-chain-fixture.hpp"
29#include "tests/test-common.hpp"
Vince Lehmancae33b62015-06-05 09:21:30 -050030
Davide Pesavento288141a2024-02-13 17:30:35 -050031namespace nlsr::tests {
Vince Lehmancae33b62015-06-05 09:21:30 -050032
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040033class NamePrefixTableFixture : public IoKeyChainFixture
Vince Lehmancae33b62015-06-05 09:21:30 -050034{
35public:
36 NamePrefixTableFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040037 : lsdb(face, m_keyChain, conf)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070038 , 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 Lehmancae33b62015-06-05 09:21:30 -050041 {
Vince Lehmancae33b62015-06-05 09:21:30 -050042 }
43
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070044 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 Pesavento8de8a8b2022-05-12 01:26:43 -040052private:
53 ndn::Scheduler m_scheduler{m_io};
54
Vince Lehmancae33b62015-06-05 09:21:30 -050055public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000056 ndn::DummyClientFace face{m_io, m_keyChain};
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040057 ConfParameter conf{face, m_keyChain};
58 DummyConfFileProcessor confProcessor{conf};
Vince Lehmancae33b62015-06-05 09:21:30 -050059
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070060 Lsdb lsdb;
61 Fib fib;
62 RoutingTable rt;
63 NamePrefixTable npt;
Vince Lehmancae33b62015-06-05 09:21:30 -050064};
65
66BOOST_AUTO_TEST_SUITE(TestNamePrefixTable)
67
68BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
69{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070070 rt.m_routingCalcInterval = 0_s;
Vince Lehmancae33b62015-06-05 09:21:30 -050071
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050072 Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_ACTIVE, 0, 0);
Vince Lehmancae33b62015-06-05 09:21:30 -050073
74 ndn::Name buptRouterName("/ndn/cn/edu/bupt/%C1.Router/bupthub");
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050075 Adjacent bupt(buptRouterName, ndn::FaceUri("udp4://10.0.0.2"), 0, Adjacent::STATUS_ACTIVE, 0, 0);
Vince Lehmancae33b62015-06-05 09:21:30 -050076
77 // This router's Adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -060078 conf.getAdjacencyList().insert(bupt);
Davide Pesavento288141a2024-02-13 17:30:35 -050079 AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1, time::system_clock::now() + 3600_s, conf.getAdjacencyList());
Ashlesh Gawande57a87172020-05-09 19:47:06 -070080 lsdb.installLsa(std::make_shared<AdjLsa>(thisRouterAdjLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -050081
82 // BUPT Adjacency LSA
83 AdjacencyList buptAdjacencies;
84 buptAdjacencies.insert(thisRouter);
Davide Pesavento288141a2024-02-13 17:30:35 -050085 AdjLsa buptAdjLsa(buptRouterName, 1, time::system_clock::now() + 5_s, buptAdjacencies);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070086 lsdb.installLsa(std::make_shared<AdjLsa>(buptAdjLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -050087
88 // BUPT Name LSA
89 ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt");
Nick Gordon96861ca2017-10-17 18:25:21 -050090 NamePrefixList buptNames{buptAdvertisedName};
Davide Pesavento288141a2024-02-13 17:30:35 -050091 NameLsa buptNameLsa(buptRouterName, 1, time::system_clock::now() + 5_s, buptNames);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070092 lsdb.installLsa(std::make_shared<NameLsa>(buptNameLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -050093
94 // Advance clocks to expire LSAs
Davide Pesavento288141a2024-02-13 17:30:35 -050095 this->advanceClocks(15_s);
Vince Lehmancae33b62015-06-05 09:21:30 -050096
97 // LSA expirations should cause NPT entries to be completely removed
Davide Pesavento288141a2024-02-13 17:30:35 -050098 auto it = npt.begin();
99 BOOST_CHECK(it == npt.end());
Vince Lehmancae33b62015-06-05 09:21:30 -0500100
101 // Install new name LSA
Davide Pesavento288141a2024-02-13 17:30:35 -0500102 NameLsa buptNewNameLsa(buptRouterName, 12, time::system_clock::now() + 3600_s, buptNames);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700103 lsdb.installLsa(std::make_shared<NameLsa>(buptNewNameLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -0500104
Davide Pesavento288141a2024-02-13 17:30:35 -0500105 this->advanceClocks(1_s);
Vince Lehmancae33b62015-06-05 09:21:30 -0500106
107 // Install new adjacency LSA
Davide Pesavento288141a2024-02-13 17:30:35 -0500108 AdjLsa buptNewAdjLsa(buptRouterName, 12, time::system_clock::now() + 3600_s, buptAdjacencies);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700109 lsdb.installLsa(std::make_shared<AdjLsa>(buptNewAdjLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -0500110
Davide Pesavento288141a2024-02-13 17:30:35 -0500111 this->advanceClocks(1_s);
Vince Lehmancae33b62015-06-05 09:21:30 -0500112
113 // Each NPT entry should have a destination router
114 it = npt.begin();
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500115 BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptRouterName);
116 BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1);
117 BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName);
Vince Lehmancae33b62015-06-05 09:21:30 -0500118
119 ++it;
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500120 BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptAdvertisedName);
121 BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1);
122 BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500123}
124
125BOOST_FIXTURE_TEST_CASE(AddEntryToPool, NamePrefixTableFixture)
126{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500127 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
135BOOST_FIXTURE_TEST_CASE(RemoveEntryFromPool, NamePrefixTableFixture)
136{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500137 RoutingTablePoolEntry rtpe1("router1", 0);
dmcoomes9f936662017-03-02 10:33:09 -0600138 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500139
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
148BOOST_FIXTURE_TEST_CASE(AddRoutingEntryToNptEntry, NamePrefixTableFixture)
149{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500150 RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0);
dmcoomes9f936662017-03-02 10:33:09 -0600151 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500152 NamePrefixTableEntry npte1("/ndn/memphis/rtr2");
153
154 npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1");
155
Davide Pesavento288141a2024-02-13 17:30:35 -0500156 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 Gordonb50e51b2016-07-22 16:05:57 -0500161
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500162 std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList();
Davide Pesavento288141a2024-02-13 17:30:35 -0500163 auto rItr = std::find(rtpeList.begin(), rtpeList.end(), rtpePtr);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500164 BOOST_CHECK_EQUAL(**rItr, *rtpePtr);
165}
166
167BOOST_FIXTURE_TEST_CASE(RemoveRoutingEntryFromNptEntry, NamePrefixTableFixture)
168{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500169 RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0);
170
171 NamePrefixTableEntry npte1("/ndn/memphis/rtr2");
Davide Pesaventod90338d2021-01-07 17:50:05 -0500172 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1));
Nick Gordonb50e51b2016-07-22 16:05:57 -0500173
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 Pesavento288141a2024-02-13 17:30:35 -0500179 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 Gordonb50e51b2016-07-22 16:05:57 -0500184
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500185 std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList();
Nick Gordonb50e51b2016-07-22 16:05:57 -0500186
187 BOOST_CHECK_EQUAL(rtpeList.size(), 1);
188 BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1);
Vince Lehmancae33b62015-06-05 09:21:30 -0500189}
190
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500191BOOST_FIXTURE_TEST_CASE(AddNptEntryPtrToRoutingEntry, NamePrefixTableFixture)
192{
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500193 NamePrefixTableEntry npte1("/ndn/memphis/rtr2");
Davide Pesaventod90338d2021-01-07 17:50:05 -0500194 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1));
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500195
196 npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1");
197
Davide Pesavento288141a2024-02-13 17:30:35 -0500198 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 Gordonc0c6bcf2017-08-15 18:11:21 -0500203
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
216BOOST_FIXTURE_TEST_CASE(RemoveNptEntryPtrFromRoutingEntry, NamePrefixTableFixture)
217{
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500218 NamePrefixTableEntry npte1("/ndn/memphis/rtr1");
219 NamePrefixTableEntry npte2("/ndn/memphis/rtr2");
220 RoutingTableEntry rte1("/ndn/memphis/destination1");
Davide Pesaventod90338d2021-01-07 17:50:05 -0500221 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1));
222 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte2));
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500223
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 Pesavento288141a2024-02-13 17:30:35 -0500229 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 Gordonc0c6bcf2017-08-15 18:11:21 -0500234
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
251BOOST_FIXTURE_TEST_CASE(RoutingTableUpdate, NamePrefixTableFixture)
252{
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500253 const ndn::Name destination = ndn::Name{"/ndn/destination1"};
Junxiao Shi6593a432023-08-21 10:50:28 +0000254 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 Gordonc0c6bcf2017-08-15 18:11:21 -0500257 const NamePrefixTableEntry entry1{"/ndn/router1"};
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600258 npt.addEntry(entry1.getNamePrefix(), destination);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500259
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700260 rt.addNextHop(destination, hop1);
261 rt.addNextHop(destination, hop2);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500262
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700263 npt.updateWithNewRoute(rt.m_rTable);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500264
265 // At this point the NamePrefixTableEntry should have two NextHops.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600266 auto nameIterator = std::find_if(npt.begin(), npt.end(),
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500267 [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) {
268 return entry1.getNamePrefix() == entry->getNamePrefix();
269 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600270 BOOST_REQUIRE(nameIterator != npt.end());
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500271
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600272 auto iterator = npt.m_rtpool.find(destination);
273 BOOST_REQUIRE(iterator != npt.m_rtpool.end());
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500274 auto nextHops = (iterator->second)->getNexthopList();
Nick Gordonff9a6272017-10-12 13:38:29 -0500275 BOOST_CHECK_EQUAL(nextHops.size(), 2);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500276
277 // Add the other NextHop
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700278 rt.addNextHop(destination, hop3);
279 npt.updateWithNewRoute(rt.m_rTable);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500280
281 // At this point the NamePrefixTableEntry should have three NextHops.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600282 nameIterator = std::find_if(npt.begin(), npt.end(),
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500283 [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) {
284 return entry1.getNamePrefix() == entry->getNamePrefix();
285 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600286 BOOST_REQUIRE(nameIterator != npt.end());
287 iterator = npt.m_rtpool.find(destination);
288 BOOST_REQUIRE(iterator != npt.m_rtpool.end());
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500289 nextHops = (iterator->second)->getNexthopList();
Nick Gordonff9a6272017-10-12 13:38:29 -0500290 BOOST_CHECK_EQUAL(nextHops.size(), 3);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500291}
292
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700293BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, NamePrefixTableFixture)
294{
Davide Pesavento288141a2024-02-13 17:30:35 -0500295 auto testTimePoint = time::system_clock::now();
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700296 NamePrefixList npl1;
297 ndn::Name n1("name1");
298 ndn::Name n2("name2");
awlane6d7c37f2025-03-07 11:53:58 -0600299 PrefixInfo p1 = PrefixInfo(n1, 0);
300 PrefixInfo p2 = PrefixInfo(n2, 0);
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700301 ndn::Name router1("/router1/1");
302
awlane6d7c37f2025-03-07 11:53:58 -0600303 npl1.insert(p1);
304 npl1.insert(p2);
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700305
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");
awlane6d7c37f2025-03-07 11:53:58 -0600317 PrefixInfo p3 = PrefixInfo(n3, 0);
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700318 auto nlsa = std::static_pointer_cast<NameLsa>(lsaPtr);
awlane6d7c37f2025-03-07 11:53:58 -0600319 nlsa->removeName(p2);
320 nlsa->addName(p3);
321 npt.updateFromLsdb(lsaPtr, LsdbUpdate::UPDATED, {p3}, {p2});
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700322 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 Shib8752932024-01-07 15:18:46 +0000333 AdjLsa adjLsa(router2, 12, testTimePoint, conf.getAdjacencyList());
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700334 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 Lehmancae33b62015-06-05 09:21:30 -0500355BOOST_AUTO_TEST_SUITE_END()
356
Davide Pesavento288141a2024-02-13 17:30:35 -0500357} // namespace nlsr::tests