blob: adeaa6d1c790cc4f8579c882a74818a50dd60b33 [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/*
Junxiao Shib8752932024-01-07 15:18:46 +00003 * Copyright (c) 2014-2024, 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"
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070023#include "route/fib.hpp"
24#include "route/routing-table.hpp"
25#include "lsdb.hpp"
Vince Lehmancae33b62015-06-05 09:21:30 -050026
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040027#include "tests/io-key-chain-fixture.hpp"
28#include "tests/test-common.hpp"
Vince Lehmancae33b62015-06-05 09:21:30 -050029
30namespace nlsr {
31namespace test {
32
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);
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060079 AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1,
Ashlesh Gawande57a87172020-05-09 19:47:06 -070080 ndn::time::system_clock::now() + 3600_s,
Ashlesh Gawande85998a12017-12-07 22:22:13 -060081 conf.getAdjacencyList());
Vince Lehmancae33b62015-06-05 09:21:30 -050082
Ashlesh Gawande57a87172020-05-09 19:47:06 -070083 lsdb.installLsa(std::make_shared<AdjLsa>(thisRouterAdjLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -050084
85 // BUPT Adjacency LSA
86 AdjacencyList buptAdjacencies;
87 buptAdjacencies.insert(thisRouter);
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060088 AdjLsa buptAdjLsa(buptRouterName, 1,
Vince Lehmancae33b62015-06-05 09:21:30 -050089 ndn::time::system_clock::now() + ndn::time::seconds(5),
Junxiao Shib8752932024-01-07 15:18:46 +000090 buptAdjacencies);
Vince Lehmancae33b62015-06-05 09:21:30 -050091
Ashlesh Gawande57a87172020-05-09 19:47:06 -070092 lsdb.installLsa(std::make_shared<AdjLsa>(buptAdjLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -050093
94 // BUPT Name LSA
95 ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt");
96
Nick Gordon96861ca2017-10-17 18:25:21 -050097 NamePrefixList buptNames{buptAdvertisedName};
Vince Lehmancae33b62015-06-05 09:21:30 -050098
Ashlesh Gawande57a87172020-05-09 19:47:06 -070099 NameLsa buptNameLsa(buptRouterName, 1, ndn::time::system_clock::now() + ndn::time::seconds(5),
Vince Lehmancae33b62015-06-05 09:21:30 -0500100 buptNames);
101
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700102 lsdb.installLsa(std::make_shared<NameLsa>(buptNameLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -0500103
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 Gawanded02c3882015-12-29 16:02:51 -0600112 NameLsa buptNewNameLsa(buptRouterName, 12,
Vince Lehmancae33b62015-06-05 09:21:30 -0500113 ndn::time::system_clock::now() + ndn::time::seconds(3600),
114 buptNames);
115
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700116 lsdb.installLsa(std::make_shared<NameLsa>(buptNewNameLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -0500117
118 this->advanceClocks(ndn::time::seconds(1));
119
120 // Install new adjacency LSA
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600121 AdjLsa buptNewAdjLsa(buptRouterName, 12,
Vince Lehmancae33b62015-06-05 09:21:30 -0500122 ndn::time::system_clock::now() + ndn::time::seconds(3600),
Junxiao Shib8752932024-01-07 15:18:46 +0000123 buptAdjacencies);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700124 lsdb.installLsa(std::make_shared<AdjLsa>(buptNewAdjLsa));
Vince Lehmancae33b62015-06-05 09:21:30 -0500125
126 this->advanceClocks(ndn::time::seconds(1));
127
128 // Each NPT entry should have a destination router
129 it = npt.begin();
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500130 BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptRouterName);
131 BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1);
132 BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName);
Vince Lehmancae33b62015-06-05 09:21:30 -0500133
134 ++it;
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500135 BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptAdvertisedName);
136 BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1);
137 BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500138}
139
140BOOST_FIXTURE_TEST_CASE(AddEntryToPool, NamePrefixTableFixture)
141{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500142 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
150BOOST_FIXTURE_TEST_CASE(RemoveEntryFromPool, NamePrefixTableFixture)
151{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500152 RoutingTablePoolEntry rtpe1("router1", 0);
dmcoomes9f936662017-03-02 10:33:09 -0600153 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500154
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
163BOOST_FIXTURE_TEST_CASE(AddRoutingEntryToNptEntry, NamePrefixTableFixture)
164{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500165 RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0);
dmcoomes9f936662017-03-02 10:33:09 -0600166 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1);
Nick Gordonb50e51b2016-07-22 16:05:57 -0500167 NamePrefixTableEntry npte1("/ndn/memphis/rtr2");
168
169 npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1");
170
171 NamePrefixTable::NptEntryList::iterator nItr =
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500172 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 Gordonb50e51b2016-07-22 16:05:57 -0500177
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500178 std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList();
dmcoomes9f936662017-03-02 10:33:09 -0600179 std::list<std::shared_ptr<RoutingTablePoolEntry>>::iterator rItr =
Nick Gordonb50e51b2016-07-22 16:05:57 -0500180 std::find(rtpeList.begin(),
181 rtpeList.end(),
182 rtpePtr);
183 BOOST_CHECK_EQUAL(**rItr, *rtpePtr);
184}
185
186BOOST_FIXTURE_TEST_CASE(RemoveRoutingEntryFromNptEntry, NamePrefixTableFixture)
187{
Nick Gordonb50e51b2016-07-22 16:05:57 -0500188 RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0);
189
190 NamePrefixTableEntry npte1("/ndn/memphis/rtr2");
Davide Pesaventod90338d2021-01-07 17:50:05 -0500191 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1));
Nick Gordonb50e51b2016-07-22 16:05:57 -0500192
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 Gordonc0c6bcf2017-08-15 18:11:21 -0500199 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 Gordonb50e51b2016-07-22 16:05:57 -0500204
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500205 std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList();
Nick Gordonb50e51b2016-07-22 16:05:57 -0500206
207 BOOST_CHECK_EQUAL(rtpeList.size(), 1);
208 BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1);
Vince Lehmancae33b62015-06-05 09:21:30 -0500209}
210
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500211BOOST_FIXTURE_TEST_CASE(AddNptEntryPtrToRoutingEntry, NamePrefixTableFixture)
212{
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500213 NamePrefixTableEntry npte1("/ndn/memphis/rtr2");
Davide Pesaventod90338d2021-01-07 17:50:05 -0500214 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1));
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500215
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
237BOOST_FIXTURE_TEST_CASE(RemoveNptEntryPtrFromRoutingEntry, NamePrefixTableFixture)
238{
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500239 NamePrefixTableEntry npte1("/ndn/memphis/rtr1");
240 NamePrefixTableEntry npte2("/ndn/memphis/rtr2");
241 RoutingTableEntry rte1("/ndn/memphis/destination1");
Davide Pesaventod90338d2021-01-07 17:50:05 -0500242 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1));
243 npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte2));
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500244
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
273BOOST_FIXTURE_TEST_CASE(RoutingTableUpdate, NamePrefixTableFixture)
274{
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500275 const ndn::Name destination = ndn::Name{"/ndn/destination1"};
Junxiao Shi6593a432023-08-21 10:50:28 +0000276 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 Gordonc0c6bcf2017-08-15 18:11:21 -0500279 const NamePrefixTableEntry entry1{"/ndn/router1"};
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600280 npt.addEntry(entry1.getNamePrefix(), destination);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500281
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700282 rt.addNextHop(destination, hop1);
283 rt.addNextHop(destination, hop2);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500284
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700285 npt.updateWithNewRoute(rt.m_rTable);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500286
287 // At this point the NamePrefixTableEntry should have two NextHops.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600288 auto nameIterator = std::find_if(npt.begin(), npt.end(),
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500289 [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) {
290 return entry1.getNamePrefix() == entry->getNamePrefix();
291 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600292 BOOST_REQUIRE(nameIterator != npt.end());
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500293
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600294 auto iterator = npt.m_rtpool.find(destination);
295 BOOST_REQUIRE(iterator != npt.m_rtpool.end());
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500296 auto nextHops = (iterator->second)->getNexthopList();
Nick Gordonff9a6272017-10-12 13:38:29 -0500297 BOOST_CHECK_EQUAL(nextHops.size(), 2);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500298
299 // Add the other NextHop
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700300 rt.addNextHop(destination, hop3);
301 npt.updateWithNewRoute(rt.m_rTable);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500302
303 // At this point the NamePrefixTableEntry should have three NextHops.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600304 nameIterator = std::find_if(npt.begin(), npt.end(),
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500305 [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) {
306 return entry1.getNamePrefix() == entry->getNamePrefix();
307 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600308 BOOST_REQUIRE(nameIterator != npt.end());
309 iterator = npt.m_rtpool.find(destination);
310 BOOST_REQUIRE(iterator != npt.m_rtpool.end());
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500311 nextHops = (iterator->second)->getNexthopList();
Nick Gordonff9a6272017-10-12 13:38:29 -0500312 BOOST_CHECK_EQUAL(nextHops.size(), 3);
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500313}
314
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700315BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, NamePrefixTableFixture)
316{
Davide Pesavento658fd852023-05-10 22:15:03 -0400317 auto testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700318 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 Shib8752932024-01-07 15:18:46 +0000352 AdjLsa adjLsa(router2, 12, testTimePoint, conf.getAdjacencyList());
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700353 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 Lehmancae33b62015-06-05 09:21:30 -0500374BOOST_AUTO_TEST_SUITE_END()
375
376} // namespace test
377} // namespace nlsr