blob: 317cc6b511f5d2714e3eb98bcfd6313442abc8d8 [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 Pesaventod90338d2021-01-07 17:50:05 -05003 * Copyright (c) 2014-2021, 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"
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000023
Nick Gordon098aae42017-08-23 15:18:46 -050024#include "test-common.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050025#include "nlsr.hpp"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080026#include "lsa/lsa.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027#include "name-prefix-list.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050028
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060029#include <ndn-cxx/util/dummy-client-face.hpp>
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050030#include <ndn-cxx/util/segment-fetcher.hpp>
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060031
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050032#include <unistd.h>
33
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050034namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035namespace test {
36
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050037class LsdbFixture : public UnitTestTimeFixture
Vince Lehman904c2412014-09-23 19:36:11 -050038{
39public:
40 LsdbFixture()
Ashlesh Gawande939b6f82018-12-09 16:51:09 -060041 : face(m_ioService, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060042 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060043 , confProcessor(conf)
44 , nlsr(face, m_keyChain, conf)
45 , lsdb(nlsr.m_lsdb)
Vince Lehman904c2412014-09-23 19:36:11 -050046 , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib")
47 , REGISTER_VERB("register")
48 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050049 addIdentity("/ndn/site/%C1.Router/this-router");
Vince Lehmanf1aa5232014-10-06 17:57:35 -050050
51 nlsr.initialize();
52
Ashlesh Gawande85998a12017-12-07 22:22:13 -060053 advanceClocks(10_ms);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050054 face.sentInterests.clear();
Vince Lehman904c2412014-09-23 19:36:11 -050055 }
56
Vince Lehmanf1aa5232014-10-06 17:57:35 -050057 void
58 extractParameters(ndn::Interest& interest, ndn::Name::Component& verb,
59 ndn::nfd::ControlParameters& extractedParameters)
Vince Lehman904c2412014-09-23 19:36:11 -050060 {
61 const ndn::Name& name = interest.getName();
62 verb = name[REGISTER_COMMAND_PREFIX.size()];
63 const ndn::Name::Component& parameterComponent = name[REGISTER_COMMAND_PREFIX.size() + 1];
64
65 ndn::Block rawParameters = parameterComponent.blockFromValue();
66 extractedParameters.wireDecode(rawParameters);
67 }
68
Vince Lehmanf1aa5232014-10-06 17:57:35 -050069 void
70 areNamePrefixListsEqual(NamePrefixList& lhs, NamePrefixList& rhs)
71 {
Nick Gordonf14ec352017-07-24 16:09:58 -050072
Vince Lehmanf1aa5232014-10-06 17:57:35 -050073 typedef std::list<ndn::Name> NameList;
74
Nick Gordonf14ec352017-07-24 16:09:58 -050075 NameList lhsList = lhs.getNames();
76 NameList rhsList = rhs.getNames();
Vince Lehmanf1aa5232014-10-06 17:57:35 -050077
78 BOOST_REQUIRE_EQUAL(lhsList.size(), rhsList.size());
79
80 NameList::iterator i = lhsList.begin();
81 NameList::iterator j = rhsList.begin();
82
83 for (; i != lhsList.end(); ++i, ++j) {
84 BOOST_CHECK_EQUAL(*i, *j);
85 }
86 }
87
Ashlesh Gawande57a87172020-05-09 19:47:06 -070088 void
89 isFirstNameLsaEqual(const Lsdb& otherLsdb)
90 {
91 auto selfLsaRange = lsdb.getLsdbIterator<NameLsa>();
92 auto otherLsaRange = otherLsdb.getLsdbIterator<NameLsa>();
93
94 if (selfLsaRange.first != selfLsaRange.second && otherLsaRange.first != otherLsaRange.second) {
95 auto ownLsa = std::static_pointer_cast<NameLsa>(*selfLsaRange.first);
96 auto otherLsa = std::static_pointer_cast<NameLsa>(*otherLsaRange.first);
97 BOOST_CHECK_EQUAL(ownLsa->getNpl(), otherLsa->getNpl());
98 return;
99 }
100 BOOST_CHECK(false);
101 }
102
Vince Lehman904c2412014-09-23 19:36:11 -0500103public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500104 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600105 ConfParameter conf;
106 DummyConfFileProcessor confProcessor;
Vince Lehman904c2412014-09-23 19:36:11 -0500107 Nlsr nlsr;
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500108 Lsdb& lsdb;
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500109
Vince Lehman904c2412014-09-23 19:36:11 -0500110 ndn::Name REGISTER_COMMAND_PREFIX;
111 ndn::Name::Component REGISTER_VERB;
112};
113
114BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500115
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500116BOOST_AUTO_TEST_CASE(LsdbSync)
117{
118 ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name");
119 uint64_t oldSeqNo = 82;
120
121 ndn::Name oldInterestName = interestName;
122 oldInterestName.appendNumber(oldSeqNo);
123
124 lsdb.expressInterest(oldInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600125 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500126
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500127 std::vector<ndn::Interest>& interests = face.sentInterests;
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500128
129 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500130
Nick Gordon098aae42017-08-23 15:18:46 -0500131 bool didFindInterest = false;
132 for (const auto& interest : interests) {
133 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
134 }
135
136 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500137 interests.clear();
138
Nick Gordone98480b2017-05-24 11:23:03 -0500139 ndn::time::steady_clock::TimePoint deadline = ndn::time::steady_clock::now() +
140 ndn::time::seconds(LSA_REFRESH_TIME_MAX);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500141
142 // Simulate an LSA interest timeout
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500143 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
144 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600145 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500146
147 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500148
Nick Gordon098aae42017-08-23 15:18:46 -0500149 didFindInterest = false;
150 for (const auto& interest : interests) {
151 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
152 }
153
154 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500155 interests.clear();
156
157 uint64_t newSeqNo = 83;
158
159 ndn::Name newInterestName = interestName;
160 newInterestName.appendNumber(newSeqNo);
161
162 lsdb.expressInterest(newInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600163 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500164
165 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500166
Nick Gordon098aae42017-08-23 15:18:46 -0500167 didFindInterest = false;
168 for (const auto& interest : interests) {
169 didFindInterest = didFindInterest || interest.getName() == newInterestName;
170 }
171
172 BOOST_CHECK(didFindInterest);
173
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500174 interests.clear();
175
176 // Simulate an LSA interest timeout where the sequence number is outdated
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500177 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
178 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600179 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500180
181 // Interest should not be expressed for outdated sequence number
182 BOOST_CHECK_EQUAL(interests.size(), 0);
183}
184
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600185BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
186{
187 // Add a lot of NameLSAs to exceed max packet size
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700188 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600189
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700190 auto nameLsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800191 BOOST_REQUIRE(nameLsa != nullptr);
192 uint64_t seqNo = nameLsa->getSeqNo();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600193
194 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
195
196 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800197 while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600198 nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500199 break;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600200 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700201 lsdb.installLsa(nameLsa);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600202
203 // Create another Lsdb and expressInterest
204 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
205 face.linkTo(face2);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500206
Saurab Dulal427e0122019-11-28 11:58:02 -0600207 ConfParameter conf2(face2, m_keyChain);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600208 std::string config = R"CONF(
209 trust-anchor
210 {
211 type any
212 }
213 )CONF";
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600214 conf2.getValidator().load(config, "config-file-from-string");
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500215 Nlsr nlsr2(face2, m_keyChain, conf2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600216
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600217 Lsdb& lsdb2(nlsr2.m_lsdb);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600218
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500219 advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600220
221 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
222 interestName.appendNumber(seqNo);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500223 lsdb2.expressInterest(interestName, 0/*= timeout count*/);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600224
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500225 advanceClocks(ndn::time::milliseconds(200), 20);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600226
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700227 isFirstNameLsaEqual(lsdb2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600228}
229
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500230BOOST_AUTO_TEST_CASE(SegmentLsaData)
231{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700232 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500233
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700234 auto lsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800235 uint64_t seqNo = lsa->getSeqNo();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500236
237 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
238
239 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800240 while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000241 lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500242 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700243 lsdb.installLsa(lsa);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500244
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800245 ndn::Block expectedDataContent = lsa->wireEncode();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500246
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600247 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500248 interestName.appendNumber(seqNo);
249
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600250 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
251 face.linkTo(face2);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500252
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600253 auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName),
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -0400254 ndn::security::getAcceptAllValidator());
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600255 fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) {
256 ndn::Block block(bufferPtr);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800257 BOOST_CHECK_EQUAL(expectedDataContent, block);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600258 });
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500259
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600260 advanceClocks(ndn::time::milliseconds(1), 100);
261 fetcher->stop();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500262}
263
264BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
265{
266 ndn::Name router("/ndn/cs/%C1.Router/router1");
267 uint64_t seqNo = 12;
268 NamePrefixList prefixList;
269
270 NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
271
272 ndn::Name prefix("/prefix/");
273
274 for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
275 lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
276 }
277
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600278 ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500279 interestName.appendNumber(seqNo);
280
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800281 ndn::Block block = lsa.wireEncode();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600282 lsdb.afterFetchLsa(block.getBuffer(), interestName);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500283
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700284 auto foundLsa = std::static_pointer_cast<NameLsa>(lsdb.findLsa(lsa.getOriginRouter(), lsa.getType()));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500285 BOOST_REQUIRE(foundLsa != nullptr);
286
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800287 BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode());
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500288}
289
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500290BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
291{
akmhoquec7a79b22014-05-26 08:06:19 -0500292 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500293 NamePrefixList npl1;
294
akmhoquefdbddb12014-05-02 18:35:19 -0500295 std::string s1 = "name1";
296 std::string s2 = "name2";
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700297 std::string router1 = "/router1/1";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500298
299 npl1.insert(s1);
300 npl1.insert(s2);
301
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600302 // For NameLsa lsType is name.
303 // 12 is seqNo, randomly generated.
304 // 1800 seconds is the default life time.
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700305 NameLsa nlsa1(router1, 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500306
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600307 Lsdb& lsdb1(nlsr.m_lsdb);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500308
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700309 lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500310
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700311 BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500312
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700313 lsdb1.removeLsa(router1, Lsa::Type::NAME);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500314
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700315 BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500316}
317
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500318BOOST_AUTO_TEST_CASE(InstallNameLsa)
319{
320 // Install lsa with name1 and name2
321 ndn::Name name1("/ndn/name1");
322 ndn::Name name2("/ndn/name2");
323
324 NamePrefixList prefixes;
325 prefixes.insert(name1);
326 prefixes.insert(name2);
327
328 std::string otherRouter("/ndn/site/%C1.router/other-router");
329 ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
330
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600331 NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700332 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500333
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700334 BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter, Lsa::Type::NAME), true);
335 NamePrefixList& nameList = std::static_pointer_cast<NameLsa>(lsdb.findLsa(otherRouter, Lsa::Type::NAME))->getNpl();
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500336
Nick Gordonf14ec352017-07-24 16:09:58 -0500337 BOOST_CHECK_EQUAL(nameList, prefixes);
338 //areNamePrefixListsEqual(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500339
340 // Add a prefix: name3
341 ndn::Name name3("/ndn/name3");
342 prefixes.insert(name3);
343
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600344 NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700345 lsdb.installLsa(std::make_shared<NameLsa>(addLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500346
347 // Lsa should include name1, name2, and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500348 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500349
350 // Remove a prefix: name2
351 prefixes.remove(name2);
352
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600353 NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700354 lsdb.installLsa(std::make_shared<NameLsa>(removeLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500355
356 // Lsa should include name1 and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500357 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500358
359 // Add and remove a prefix: add name2, remove name3
360 prefixes.insert(name2);
361 prefixes.remove(name3);
362
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600363 NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700364 lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500365
366 // Lsa should include name1 and name2
Nick Gordonf14ec352017-07-24 16:09:58 -0500367 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500368
369 // Install a completely new list of prefixes
370 ndn::Name name4("/ndn/name4");
371 ndn::Name name5("/ndn/name5");
372
373 NamePrefixList newPrefixes;
374 newPrefixes.insert(name4);
375 newPrefixes.insert(name5);
376
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600377 NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700378 lsdb.installLsa(std::make_shared<NameLsa>(newLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500379
380 // Lsa should include name4 and name5
Nick Gordonf14ec352017-07-24 16:09:58 -0500381 BOOST_CHECK_EQUAL(nameList, newPrefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500382}
383
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500384BOOST_AUTO_TEST_CASE(TestIsLsaNew)
385{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700386 ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router");
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500387
388 // Install Name LSA
389 NamePrefixList nameList;
390 NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
391
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700392 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500393
394 // Lower NameLSA sequence number
395 uint64_t lowerSeqNo = 998;
Nick Gordon727d4832017-10-13 18:04:25 -0500396 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500397
398 // Same NameLSA sequence number
399 uint64_t sameSeqNo = 999;
Nick Gordon727d4832017-10-13 18:04:25 -0500400 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500401
402 // Higher NameLSA sequence number
403 uint64_t higherSeqNo = 1000;
Nick Gordon727d4832017-10-13 18:04:25 -0500404 BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500405}
406
407BOOST_AUTO_TEST_SUITE_END() // TestLsdb
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500408
Nick Gordonfad8e252016-08-11 14:21:38 -0500409} // namespace test
410} // namespace nlsr