blob: 13f96a672436190d8bb58d8eaa7d45e5bb9070ef [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/*
Saurab Dulal427e0122019-11-28 11:58:02 -06003 * Copyright (c) 2014-2020, 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
Ashlesh Gawande85998a12017-12-07 22:22:13 -060037using namespace ndn::time_literals;
Vince Lehman904c2412014-09-23 19:36:11 -050038
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050039class LsdbFixture : public UnitTestTimeFixture
Vince Lehman904c2412014-09-23 19:36:11 -050040{
41public:
42 LsdbFixture()
Ashlesh Gawande939b6f82018-12-09 16:51:09 -060043 : face(m_ioService, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060044 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060045 , confProcessor(conf)
46 , nlsr(face, m_keyChain, conf)
47 , lsdb(nlsr.m_lsdb)
Vince Lehman904c2412014-09-23 19:36:11 -050048 , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib")
49 , REGISTER_VERB("register")
50 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050051 addIdentity("/ndn/site/%C1.Router/this-router");
Vince Lehmanf1aa5232014-10-06 17:57:35 -050052
53 nlsr.initialize();
54
Ashlesh Gawande85998a12017-12-07 22:22:13 -060055 advanceClocks(10_ms);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050056 face.sentInterests.clear();
Vince Lehman904c2412014-09-23 19:36:11 -050057 }
58
Vince Lehmanf1aa5232014-10-06 17:57:35 -050059 void
60 extractParameters(ndn::Interest& interest, ndn::Name::Component& verb,
61 ndn::nfd::ControlParameters& extractedParameters)
Vince Lehman904c2412014-09-23 19:36:11 -050062 {
63 const ndn::Name& name = interest.getName();
64 verb = name[REGISTER_COMMAND_PREFIX.size()];
65 const ndn::Name::Component& parameterComponent = name[REGISTER_COMMAND_PREFIX.size() + 1];
66
67 ndn::Block rawParameters = parameterComponent.blockFromValue();
68 extractedParameters.wireDecode(rawParameters);
69 }
70
Vince Lehmanf1aa5232014-10-06 17:57:35 -050071 void
72 areNamePrefixListsEqual(NamePrefixList& lhs, NamePrefixList& rhs)
73 {
Nick Gordonf14ec352017-07-24 16:09:58 -050074
Vince Lehmanf1aa5232014-10-06 17:57:35 -050075 typedef std::list<ndn::Name> NameList;
76
Nick Gordonf14ec352017-07-24 16:09:58 -050077 NameList lhsList = lhs.getNames();
78 NameList rhsList = rhs.getNames();
Vince Lehmanf1aa5232014-10-06 17:57:35 -050079
80 BOOST_REQUIRE_EQUAL(lhsList.size(), rhsList.size());
81
82 NameList::iterator i = lhsList.begin();
83 NameList::iterator j = rhsList.begin();
84
85 for (; i != lhsList.end(); ++i, ++j) {
86 BOOST_CHECK_EQUAL(*i, *j);
87 }
88 }
89
Ashlesh Gawande57a87172020-05-09 19:47:06 -070090 void
91 isFirstNameLsaEqual(const Lsdb& otherLsdb)
92 {
93 auto selfLsaRange = lsdb.getLsdbIterator<NameLsa>();
94 auto otherLsaRange = otherLsdb.getLsdbIterator<NameLsa>();
95
96 if (selfLsaRange.first != selfLsaRange.second && otherLsaRange.first != otherLsaRange.second) {
97 auto ownLsa = std::static_pointer_cast<NameLsa>(*selfLsaRange.first);
98 auto otherLsa = std::static_pointer_cast<NameLsa>(*otherLsaRange.first);
99 BOOST_CHECK_EQUAL(ownLsa->getNpl(), otherLsa->getNpl());
100 return;
101 }
102 BOOST_CHECK(false);
103 }
104
Vince Lehman904c2412014-09-23 19:36:11 -0500105public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500106 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600107 ConfParameter conf;
108 DummyConfFileProcessor confProcessor;
Vince Lehman904c2412014-09-23 19:36:11 -0500109 Nlsr nlsr;
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500110 Lsdb& lsdb;
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500111
Vince Lehman904c2412014-09-23 19:36:11 -0500112 ndn::Name REGISTER_COMMAND_PREFIX;
113 ndn::Name::Component REGISTER_VERB;
114};
115
116BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500117
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500118BOOST_AUTO_TEST_CASE(LsdbSync)
119{
120 ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name");
121 uint64_t oldSeqNo = 82;
122
123 ndn::Name oldInterestName = interestName;
124 oldInterestName.appendNumber(oldSeqNo);
125
126 lsdb.expressInterest(oldInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600127 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500128
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500129 std::vector<ndn::Interest>& interests = face.sentInterests;
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500130
131 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500132
Nick Gordon098aae42017-08-23 15:18:46 -0500133 bool didFindInterest = false;
134 for (const auto& interest : interests) {
135 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
136 }
137
138 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500139 interests.clear();
140
Nick Gordone98480b2017-05-24 11:23:03 -0500141 ndn::time::steady_clock::TimePoint deadline = ndn::time::steady_clock::now() +
142 ndn::time::seconds(LSA_REFRESH_TIME_MAX);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500143
144 // Simulate an LSA interest timeout
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500145 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
146 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600147 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500148
149 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500150
Nick Gordon098aae42017-08-23 15:18:46 -0500151 didFindInterest = false;
152 for (const auto& interest : interests) {
153 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
154 }
155
156 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500157 interests.clear();
158
159 uint64_t newSeqNo = 83;
160
161 ndn::Name newInterestName = interestName;
162 newInterestName.appendNumber(newSeqNo);
163
164 lsdb.expressInterest(newInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600165 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500166
167 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500168
Nick Gordon098aae42017-08-23 15:18:46 -0500169 didFindInterest = false;
170 for (const auto& interest : interests) {
171 didFindInterest = didFindInterest || interest.getName() == newInterestName;
172 }
173
174 BOOST_CHECK(didFindInterest);
175
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500176 interests.clear();
177
178 // Simulate an LSA interest timeout where the sequence number is outdated
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500179 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
180 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600181 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500182
183 // Interest should not be expressed for outdated sequence number
184 BOOST_CHECK_EQUAL(interests.size(), 0);
185}
186
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600187BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
188{
189 // Add a lot of NameLSAs to exceed max packet size
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700190 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600191
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700192 auto nameLsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800193 BOOST_REQUIRE(nameLsa != nullptr);
194 uint64_t seqNo = nameLsa->getSeqNo();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600195
196 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
197
198 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800199 while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600200 nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500201 break;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600202 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700203 lsdb.installLsa(nameLsa);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600204
205 // Create another Lsdb and expressInterest
206 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
207 face.linkTo(face2);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500208
Saurab Dulal427e0122019-11-28 11:58:02 -0600209 ConfParameter conf2(face2, m_keyChain);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600210 std::string config = R"CONF(
211 trust-anchor
212 {
213 type any
214 }
215 )CONF";
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600216 conf2.getValidator().load(config, "config-file-from-string");
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500217 Nlsr nlsr2(face2, m_keyChain, conf2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600218
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600219 Lsdb& lsdb2(nlsr2.m_lsdb);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600220
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500221 advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600222
223 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
224 interestName.appendNumber(seqNo);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500225 lsdb2.expressInterest(interestName, 0/*= timeout count*/);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600226
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500227 advanceClocks(ndn::time::milliseconds(200), 20);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600228
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700229 isFirstNameLsaEqual(lsdb2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600230}
231
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500232BOOST_AUTO_TEST_CASE(SegmentLsaData)
233{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700234 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500235
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700236 auto lsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800237 uint64_t seqNo = lsa->getSeqNo();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500238
239 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
240
241 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800242 while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000243 lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500244 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700245 lsdb.installLsa(lsa);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500246
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800247 ndn::Block expectedDataContent = lsa->wireEncode();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500248
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600249 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500250 interestName.appendNumber(seqNo);
251
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600252 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
253 face.linkTo(face2);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500254
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600255 auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName),
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -0400256 ndn::security::getAcceptAllValidator());
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600257 fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) {
258 ndn::Block block(bufferPtr);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800259 BOOST_CHECK_EQUAL(expectedDataContent, block);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600260 });
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500261
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600262 advanceClocks(ndn::time::milliseconds(1), 100);
263 fetcher->stop();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500264}
265
266BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
267{
268 ndn::Name router("/ndn/cs/%C1.Router/router1");
269 uint64_t seqNo = 12;
270 NamePrefixList prefixList;
271
272 NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
273
274 ndn::Name prefix("/prefix/");
275
276 for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
277 lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
278 }
279
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600280 ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500281 interestName.appendNumber(seqNo);
282
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800283 ndn::Block block = lsa.wireEncode();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600284 lsdb.afterFetchLsa(block.getBuffer(), interestName);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500285
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700286 auto foundLsa = std::static_pointer_cast<NameLsa>(lsdb.findLsa(lsa.getOriginRouter(), lsa.getType()));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500287 BOOST_REQUIRE(foundLsa != nullptr);
288
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800289 BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode());
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500290}
291
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500292BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
293{
akmhoquec7a79b22014-05-26 08:06:19 -0500294 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500295 NamePrefixList npl1;
296
akmhoquefdbddb12014-05-02 18:35:19 -0500297 std::string s1 = "name1";
298 std::string s2 = "name2";
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700299 std::string router1 = "/router1/1";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500300
301 npl1.insert(s1);
302 npl1.insert(s2);
303
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600304 // For NameLsa lsType is name.
305 // 12 is seqNo, randomly generated.
306 // 1800 seconds is the default life time.
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700307 NameLsa nlsa1(router1, 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500308
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600309 Lsdb& lsdb1(nlsr.m_lsdb);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500310
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700311 lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500312
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700313 BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500314
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700315 lsdb1.removeLsa(router1, Lsa::Type::NAME);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500316
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700317 BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500318}
319
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500320BOOST_AUTO_TEST_CASE(InstallNameLsa)
321{
322 // Install lsa with name1 and name2
323 ndn::Name name1("/ndn/name1");
324 ndn::Name name2("/ndn/name2");
325
326 NamePrefixList prefixes;
327 prefixes.insert(name1);
328 prefixes.insert(name2);
329
330 std::string otherRouter("/ndn/site/%C1.router/other-router");
331 ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
332
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600333 NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700334 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500335
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700336 BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter, Lsa::Type::NAME), true);
337 NamePrefixList& nameList = std::static_pointer_cast<NameLsa>(lsdb.findLsa(otherRouter, Lsa::Type::NAME))->getNpl();
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500338
Nick Gordonf14ec352017-07-24 16:09:58 -0500339 BOOST_CHECK_EQUAL(nameList, prefixes);
340 //areNamePrefixListsEqual(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500341
342 // Add a prefix: name3
343 ndn::Name name3("/ndn/name3");
344 prefixes.insert(name3);
345
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600346 NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700347 lsdb.installLsa(std::make_shared<NameLsa>(addLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500348
349 // Lsa should include name1, name2, and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500350 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500351
352 // Remove a prefix: name2
353 prefixes.remove(name2);
354
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600355 NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700356 lsdb.installLsa(std::make_shared<NameLsa>(removeLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500357
358 // Lsa should include name1 and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500359 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500360
361 // Add and remove a prefix: add name2, remove name3
362 prefixes.insert(name2);
363 prefixes.remove(name3);
364
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600365 NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700366 lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500367
368 // Lsa should include name1 and name2
Nick Gordonf14ec352017-07-24 16:09:58 -0500369 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500370
371 // Install a completely new list of prefixes
372 ndn::Name name4("/ndn/name4");
373 ndn::Name name5("/ndn/name5");
374
375 NamePrefixList newPrefixes;
376 newPrefixes.insert(name4);
377 newPrefixes.insert(name5);
378
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600379 NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700380 lsdb.installLsa(std::make_shared<NameLsa>(newLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500381
382 // Lsa should include name4 and name5
Nick Gordonf14ec352017-07-24 16:09:58 -0500383 BOOST_CHECK_EQUAL(nameList, newPrefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500384}
385
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500386BOOST_AUTO_TEST_CASE(TestIsLsaNew)
387{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700388 ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router");
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500389
390 // Install Name LSA
391 NamePrefixList nameList;
392 NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
393
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700394 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500395
396 // Lower NameLSA sequence number
397 uint64_t lowerSeqNo = 998;
Nick Gordon727d4832017-10-13 18:04:25 -0500398 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500399
400 // Same NameLSA sequence number
401 uint64_t sameSeqNo = 999;
Nick Gordon727d4832017-10-13 18:04:25 -0500402 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500403
404 // Higher NameLSA sequence number
405 uint64_t higherSeqNo = 1000;
Nick Gordon727d4832017-10-13 18:04:25 -0500406 BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500407}
408
409BOOST_AUTO_TEST_SUITE_END() // TestLsdb
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500410
Nick Gordonfad8e252016-08-11 14:21:38 -0500411} // namespace test
412} // namespace nlsr