blob: 0db16e6d23d1c9cc7ecb31c0e4e40a41c28aa5ff [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -04002/*
Davide Pesavento658fd852023-05-10 22:15:03 -04003 * Copyright (c) 2014-2023, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040020 */
Vince Lehman7c603292014-09-11 17:48:16 -050021
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050022#include "lsdb.hpp"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080023#include "lsa/lsa.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050024#include "name-prefix-list.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050025
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040026#include "tests/io-key-chain-fixture.hpp"
27#include "tests/test-common.hpp"
28
29#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
30#include <ndn-cxx/security/validator-null.hpp>
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050031#include <ndn-cxx/util/segment-fetcher.hpp>
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060032
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050033#include <unistd.h>
34
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050036namespace test {
37
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040038class LsdbFixture : public IoKeyChainFixture
Vince Lehman904c2412014-09-23 19:36:11 -050039{
40public:
41 LsdbFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040042 : face(m_io, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060043 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060044 , confProcessor(conf)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070045 , lsdb(face, m_keyChain, conf)
Vince Lehman904c2412014-09-23 19:36:11 -050046 {
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040047 m_keyChain.createIdentity("/ndn/site/%C1.Router/this-router");
Vince Lehmanf1aa5232014-10-06 17:57:35 -050048
Ashlesh Gawande85998a12017-12-07 22:22:13 -060049 advanceClocks(10_ms);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050050 face.sentInterests.clear();
Vince Lehman904c2412014-09-23 19:36:11 -050051 }
52
Vince Lehmanf1aa5232014-10-06 17:57:35 -050053 void
Ashlesh Gawande57a87172020-05-09 19:47:06 -070054 isFirstNameLsaEqual(const Lsdb& otherLsdb)
55 {
56 auto selfLsaRange = lsdb.getLsdbIterator<NameLsa>();
57 auto otherLsaRange = otherLsdb.getLsdbIterator<NameLsa>();
58
59 if (selfLsaRange.first != selfLsaRange.second && otherLsaRange.first != otherLsaRange.second) {
60 auto ownLsa = std::static_pointer_cast<NameLsa>(*selfLsaRange.first);
61 auto otherLsa = std::static_pointer_cast<NameLsa>(*otherLsaRange.first);
62 BOOST_CHECK_EQUAL(ownLsa->getNpl(), otherLsa->getNpl());
63 return;
64 }
65 BOOST_CHECK(false);
66 }
67
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070068 void
69 checkSignalResult(LsdbUpdate updateType,
70 const std::shared_ptr<Lsa>& lsaPtr,
71 const std::list<ndn::Name>& namesToAdd,
72 const std::list<ndn::Name>& namesToRemove)
73 {
74 BOOST_CHECK(updateHappened);
75 BOOST_CHECK_EQUAL(lsaPtrCheck->getOriginRouter(), lsaPtr->getOriginRouter());
76 BOOST_CHECK_EQUAL(lsaPtrCheck->getType(), lsaPtr->getType());
77 BOOST_CHECK(updateType == updateTypeCheck);
78 BOOST_CHECK(namesToAdd == namesToAddCheck);
79 BOOST_CHECK(namesToRemove == namesToRemoveCheck);
80 updateHappened = false;
81 }
82
83 void
84 connectSignal()
85 {
86 lsdb.onLsdbModified.connect(
87 [&] (std::shared_ptr<Lsa> lsa, LsdbUpdate updateType,
88 const auto& namesToAdd, const auto& namesToRemove) {
89 lsaPtrCheck = lsa;
90 updateTypeCheck = updateType;
91 namesToAddCheck = namesToAdd;
92 namesToRemoveCheck = namesToRemove;
93 updateHappened = true;
94 }
95 );
96 }
97
Vince Lehman904c2412014-09-23 19:36:11 -050098public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000099 ndn::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600100 ConfParameter conf;
101 DummyConfFileProcessor confProcessor;
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700102 Lsdb lsdb;
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500103
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700104 LsdbUpdate updateTypeCheck = LsdbUpdate::INSTALLED;
105 std::list<ndn::Name> namesToAddCheck;
106 std::list<ndn::Name> namesToRemoveCheck;
107 std::shared_ptr<Lsa> lsaPtrCheck = nullptr;
108 bool updateHappened = false;
Vince Lehman904c2412014-09-23 19:36:11 -0500109};
110
111BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500112
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500113BOOST_AUTO_TEST_CASE(LsdbSync)
114{
115 ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name");
116 uint64_t oldSeqNo = 82;
117
118 ndn::Name oldInterestName = interestName;
119 oldInterestName.appendNumber(oldSeqNo);
120
Alexander Afanasyev135288c2022-04-23 23:06:56 -0400121 lsdb.expressInterest(oldInterestName, 0, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600122 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500123
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500124 std::vector<ndn::Interest>& interests = face.sentInterests;
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500125
126 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500127
Nick Gordon098aae42017-08-23 15:18:46 -0500128 bool didFindInterest = false;
129 for (const auto& interest : interests) {
130 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
131 }
132
133 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500134 interests.clear();
135
Davide Pesavento658fd852023-05-10 22:15:03 -0400136 auto deadline = ndn::time::steady_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_MAX);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500137
138 // Simulate an LSA interest timeout
Junxiao Shi43f37a02023-08-09 00:09:00 +0000139 lsdb.onFetchLsaError(ndn::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500140 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600141 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500142
143 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500144
Nick Gordon098aae42017-08-23 15:18:46 -0500145 didFindInterest = false;
146 for (const auto& interest : interests) {
147 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
148 }
149
150 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500151 interests.clear();
152
153 uint64_t newSeqNo = 83;
154
155 ndn::Name newInterestName = interestName;
156 newInterestName.appendNumber(newSeqNo);
157
Alexander Afanasyev135288c2022-04-23 23:06:56 -0400158 lsdb.expressInterest(newInterestName, 0, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600159 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500160
161 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500162
Nick Gordon098aae42017-08-23 15:18:46 -0500163 didFindInterest = false;
164 for (const auto& interest : interests) {
165 didFindInterest = didFindInterest || interest.getName() == newInterestName;
166 }
167
168 BOOST_CHECK(didFindInterest);
169
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500170 interests.clear();
171
172 // Simulate an LSA interest timeout where the sequence number is outdated
Junxiao Shi43f37a02023-08-09 00:09:00 +0000173 lsdb.onFetchLsaError(ndn::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500174 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600175 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500176
177 // Interest should not be expressed for outdated sequence number
178 BOOST_CHECK_EQUAL(interests.size(), 0);
179}
180
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600181BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
182{
183 // Add a lot of NameLSAs to exceed max packet size
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700184 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600185
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700186 auto nameLsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800187 BOOST_REQUIRE(nameLsa != nullptr);
188 uint64_t seqNo = nameLsa->getSeqNo();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600189
190 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
191
192 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800193 while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600194 nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500195 break;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600196 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700197 lsdb.installLsa(nameLsa);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600198
199 // Create another Lsdb and expressInterest
Junxiao Shi43f37a02023-08-09 00:09:00 +0000200 ndn::DummyClientFace face2(m_io, m_keyChain, {true, true});
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600201 face.linkTo(face2);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500202
Saurab Dulal427e0122019-11-28 11:58:02 -0600203 ConfParameter conf2(face2, m_keyChain);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600204 std::string config = R"CONF(
205 trust-anchor
206 {
207 type any
208 }
209 )CONF";
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600210 conf2.getValidator().load(config, "config-file-from-string");
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600211
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700212 Lsdb lsdb2(face2, m_keyChain, conf2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600213
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500214 advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600215
216 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
217 interestName.appendNumber(seqNo);
Alexander Afanasyev135288c2022-04-23 23:06:56 -0400218 lsdb2.expressInterest(interestName, 0/*= timeout count*/, 0);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600219
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500220 advanceClocks(ndn::time::milliseconds(200), 20);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600221
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700222 isFirstNameLsaEqual(lsdb2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600223}
224
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500225BOOST_AUTO_TEST_CASE(SegmentLsaData)
226{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700227 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500228
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700229 auto lsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800230 uint64_t seqNo = lsa->getSeqNo();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500231
232 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
233
234 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800235 while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000236 lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500237 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700238 lsdb.installLsa(lsa);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500239
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800240 ndn::Block expectedDataContent = lsa->wireEncode();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500241
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600242 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500243 interestName.appendNumber(seqNo);
244
Junxiao Shi43f37a02023-08-09 00:09:00 +0000245 ndn::DummyClientFace face2(m_io, m_keyChain, {true, true});
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600246 face.linkTo(face2);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500247
Junxiao Shi43f37a02023-08-09 00:09:00 +0000248 auto fetcher = ndn::SegmentFetcher::start(face2, ndn::Interest(interestName),
249 ndn::security::getAcceptAllValidator());
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600250 fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) {
251 ndn::Block block(bufferPtr);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800252 BOOST_CHECK_EQUAL(expectedDataContent, block);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600253 });
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500254
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600255 advanceClocks(ndn::time::milliseconds(1), 100);
256 fetcher->stop();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500257}
258
259BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
260{
261 ndn::Name router("/ndn/cs/%C1.Router/router1");
262 uint64_t seqNo = 12;
263 NamePrefixList prefixList;
264
265 NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
266
267 ndn::Name prefix("/prefix/");
268
269 for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
270 lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
271 }
272
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600273 ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500274 interestName.appendNumber(seqNo);
275
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800276 ndn::Block block = lsa.wireEncode();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600277 lsdb.afterFetchLsa(block.getBuffer(), interestName);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500278
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700279 auto foundLsa = std::static_pointer_cast<NameLsa>(lsdb.findLsa(lsa.getOriginRouter(), lsa.getType()));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500280 BOOST_REQUIRE(foundLsa != nullptr);
281
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800282 BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode());
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500283}
284
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500285BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
286{
Davide Pesavento658fd852023-05-10 22:15:03 -0400287 auto testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500288 NamePrefixList npl1;
289
akmhoquefdbddb12014-05-02 18:35:19 -0500290 std::string s1 = "name1";
291 std::string s2 = "name2";
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700292 std::string router1 = "/router1/1";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500293
294 npl1.insert(s1);
295 npl1.insert(s2);
296
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600297 // For NameLsa lsType is name.
298 // 12 is seqNo, randomly generated.
299 // 1800 seconds is the default life time.
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700300 NameLsa nlsa1(router1, 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500301
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700302 Lsdb& lsdb1(lsdb);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500303
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700304 lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500305
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700306 BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500307
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700308 lsdb1.removeLsa(router1, Lsa::Type::NAME);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500309
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700310 BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500311}
312
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500313BOOST_AUTO_TEST_CASE(InstallNameLsa)
314{
315 // Install lsa with name1 and name2
316 ndn::Name name1("/ndn/name1");
317 ndn::Name name2("/ndn/name2");
318
319 NamePrefixList prefixes;
320 prefixes.insert(name1);
321 prefixes.insert(name2);
322
323 std::string otherRouter("/ndn/site/%C1.router/other-router");
Davide Pesavento658fd852023-05-10 22:15:03 -0400324 const auto MAX_TIME = ndn::time::system_clock::time_point::max();
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500325
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600326 NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700327 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500328
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700329 BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter, Lsa::Type::NAME), true);
330 NamePrefixList& nameList = std::static_pointer_cast<NameLsa>(lsdb.findLsa(otherRouter, Lsa::Type::NAME))->getNpl();
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500331
Nick Gordonf14ec352017-07-24 16:09:58 -0500332 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500333
334 // Add a prefix: name3
335 ndn::Name name3("/ndn/name3");
336 prefixes.insert(name3);
337
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600338 NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700339 lsdb.installLsa(std::make_shared<NameLsa>(addLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500340
341 // Lsa should include name1, name2, and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500342 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500343
344 // Remove a prefix: name2
Junxiao Shi52f16642023-08-15 00:18:35 +0000345 prefixes.erase(name2);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500346
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600347 NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700348 lsdb.installLsa(std::make_shared<NameLsa>(removeLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500349
350 // Lsa should include name1 and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500351 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500352
353 // Add and remove a prefix: add name2, remove name3
354 prefixes.insert(name2);
Junxiao Shi52f16642023-08-15 00:18:35 +0000355 prefixes.erase(name3);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500356
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600357 NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700358 lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500359
360 // Lsa should include name1 and name2
Nick Gordonf14ec352017-07-24 16:09:58 -0500361 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500362
363 // Install a completely new list of prefixes
364 ndn::Name name4("/ndn/name4");
365 ndn::Name name5("/ndn/name5");
366
367 NamePrefixList newPrefixes;
368 newPrefixes.insert(name4);
369 newPrefixes.insert(name5);
370
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600371 NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700372 lsdb.installLsa(std::make_shared<NameLsa>(newLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500373
374 // Lsa should include name4 and name5
Nick Gordonf14ec352017-07-24 16:09:58 -0500375 BOOST_CHECK_EQUAL(nameList, newPrefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500376}
377
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500378BOOST_AUTO_TEST_CASE(TestIsLsaNew)
379{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700380 ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router");
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500381
382 // Install Name LSA
383 NamePrefixList nameList;
Davide Pesavento658fd852023-05-10 22:15:03 -0400384 NameLsa lsa(originRouter, 999, ndn::time::system_clock::time_point::max(), nameList);
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500385
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700386 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500387
388 // Lower NameLSA sequence number
389 uint64_t lowerSeqNo = 998;
Nick Gordon727d4832017-10-13 18:04:25 -0500390 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500391
392 // Same NameLSA sequence number
393 uint64_t sameSeqNo = 999;
Nick Gordon727d4832017-10-13 18:04:25 -0500394 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500395
396 // Higher NameLSA sequence number
397 uint64_t higherSeqNo = 1000;
Nick Gordon727d4832017-10-13 18:04:25 -0500398 BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500399}
400
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700401BOOST_AUTO_TEST_CASE(LsdbSignals)
402{
403 connectSignal();
404 auto testTimePoint = ndn::time::system_clock::now() + 3600_s;
405 ndn::Name router2("/router2");
406 AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList());
407 std::shared_ptr<Lsa> lsaPtr = std::make_shared<AdjLsa>(adjLsa);
408 lsdb.installLsa(lsaPtr);
409 checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
410
411 adjLsa.setSeqNo(13);
412 updateHappened = false;
413 lsaPtr = std::make_shared<AdjLsa>(adjLsa);
414 lsdb.installLsa(lsaPtr);
415 BOOST_CHECK(!updateHappened);
416
417 Adjacent adj("Neighbor1");
418 adjLsa.setSeqNo(14);
419 adjLsa.addAdjacent(adj);
420 lsaPtr = std::make_shared<AdjLsa>(adjLsa);
421 lsdb.installLsa(lsaPtr);
422 checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {}, {});
423
424 lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::ADJACENCY);
425 checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {});
426
427 // Name LSA
428 NamePrefixList npl1{"name1", "name2"};
429 NameLsa nameLsa(router2, 12, testTimePoint, npl1);
430 lsaPtr = std::make_shared<NameLsa>(nameLsa);
431 lsdb.installLsa(lsaPtr);
432 checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
433
434 nameLsa.setSeqNo(13);
435 lsaPtr = std::make_shared<NameLsa>(nameLsa);
436 lsdb.installLsa(lsaPtr);
437 BOOST_CHECK(!updateHappened);
438
439 NamePrefixList npl2{"name2", "name3"};
440 NameLsa nameLsa2(router2, 14, testTimePoint, npl2);
441 lsaPtr = std::make_shared<NameLsa>(nameLsa2);
442 lsdb.installLsa(lsaPtr);
443 checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {"name3"}, {"name1"});
444
445 lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::NAME);
446 checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {});
447
448 // Coordinate LSA
449 lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 12, testTimePoint, 2.5, {30}));
450 lsdb.installLsa(lsaPtr);
451 checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
452
453 lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 13, testTimePoint, 2.5, {30}));
454 lsdb.installLsa(lsaPtr);
455 BOOST_CHECK(!updateHappened);
456
457 lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 14, testTimePoint, 2.5, {40}));
458 lsdb.installLsa(lsaPtr);
459 checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {}, {});
460
461 lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::COORDINATE);
462 checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {});
463}
464
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500465BOOST_AUTO_TEST_SUITE_END() // TestLsdb
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500466
Nick Gordonfad8e252016-08-11 14:21:38 -0500467} // namespace test
468} // namespace nlsr