blob: 56e862bacaf6ea3c077652997dcb858cc12c8cf9 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -05002/**
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
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"
26#include "lsa.hpp"
27#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
Vince Lehman904c2412014-09-23 19:36:11 -050090public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050091 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060092 ConfParameter conf;
93 DummyConfFileProcessor confProcessor;
Vince Lehman904c2412014-09-23 19:36:11 -050094 Nlsr nlsr;
Vince Lehmanf1aa5232014-10-06 17:57:35 -050095 Lsdb& lsdb;
Vince Lehmanf1aa5232014-10-06 17:57:35 -050096
Vince Lehman904c2412014-09-23 19:36:11 -050097 ndn::Name REGISTER_COMMAND_PREFIX;
98 ndn::Name::Component REGISTER_VERB;
99};
100
101BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500102
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500103BOOST_AUTO_TEST_CASE(LsdbSync)
104{
105 ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name");
106 uint64_t oldSeqNo = 82;
107
108 ndn::Name oldInterestName = interestName;
109 oldInterestName.appendNumber(oldSeqNo);
110
111 lsdb.expressInterest(oldInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600112 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500113
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500114 std::vector<ndn::Interest>& interests = face.sentInterests;
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500115
116 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500117
Nick Gordon098aae42017-08-23 15:18:46 -0500118 bool didFindInterest = false;
119 for (const auto& interest : interests) {
120 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
121 }
122
123 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500124 interests.clear();
125
Nick Gordone98480b2017-05-24 11:23:03 -0500126 ndn::time::steady_clock::TimePoint deadline = ndn::time::steady_clock::now() +
127 ndn::time::seconds(LSA_REFRESH_TIME_MAX);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500128
129 // Simulate an LSA interest timeout
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500130 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
131 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600132 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500133
134 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500135
Nick Gordon098aae42017-08-23 15:18:46 -0500136 didFindInterest = false;
137 for (const auto& interest : interests) {
138 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
139 }
140
141 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500142 interests.clear();
143
144 uint64_t newSeqNo = 83;
145
146 ndn::Name newInterestName = interestName;
147 newInterestName.appendNumber(newSeqNo);
148
149 lsdb.expressInterest(newInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600150 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500151
152 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500153
Nick Gordon098aae42017-08-23 15:18:46 -0500154 didFindInterest = false;
155 for (const auto& interest : interests) {
156 didFindInterest = didFindInterest || interest.getName() == newInterestName;
157 }
158
159 BOOST_CHECK(didFindInterest);
160
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500161 interests.clear();
162
163 // Simulate an LSA interest timeout where the sequence number is outdated
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500164 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
165 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600166 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500167
168 // Interest should not be expressed for outdated sequence number
169 BOOST_CHECK_EQUAL(interests.size(), 0);
170}
171
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600172BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
173{
174 // Add a lot of NameLSAs to exceed max packet size
175 ndn::Name lsaKey("/ndn/site/%C1.Router/this-router/NAME");
176
177 NameLsa* nameLsa = lsdb.findNameLsa(lsaKey);
178 uint64_t seqNo = nameLsa->getLsSeqNo();
179
180 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
181
182 int nPrefixes = 0;
183 while (nameLsa->serialize().size() < ndn::MAX_NDN_PACKET_SIZE) {
184 nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500185 break;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600186 }
187 lsdb.installNameLsa(*nameLsa);
188
189 // Create another Lsdb and expressInterest
190 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
191 face.linkTo(face2);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500192
Saurab Dulal427e0122019-11-28 11:58:02 -0600193 ConfParameter conf2(face2, m_keyChain);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600194 std::string config = R"CONF(
195 trust-anchor
196 {
197 type any
198 }
199 )CONF";
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600200 conf2.getValidator().load(config, "config-file-from-string");
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500201 Nlsr nlsr2(face2, m_keyChain, conf2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600202
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600203 Lsdb& lsdb2(nlsr2.m_lsdb);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600204
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500205 advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600206
207 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
208 interestName.appendNumber(seqNo);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500209 lsdb2.expressInterest(interestName, 0/*= timeout count*/);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600210
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500211 advanceClocks(ndn::time::milliseconds(200), 20);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600212
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500213 BOOST_CHECK_EQUAL(lsdb.getNameLsdb().front().getNpl(), lsdb2.getNameLsdb().back().getNpl());
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600214}
215
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500216BOOST_AUTO_TEST_CASE(SegmentLsaData)
217{
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000218 ndn::Name lsaKey("/ndn/site/%C1.Router/this-router/NAME");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500219
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000220 NameLsa* lsa = lsdb.findNameLsa(lsaKey);
221 uint64_t seqNo = lsa->getLsSeqNo();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500222
223 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
224
225 int nPrefixes = 0;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000226 while (lsa->serialize().size() < ndn::MAX_NDN_PACKET_SIZE) {
227 lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500228 }
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000229 lsdb.installNameLsa(*lsa);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500230
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000231 std::string expectedDataContent = lsa->serialize();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500232
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600233 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500234 interestName.appendNumber(seqNo);
235
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600236 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
237 face.linkTo(face2);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500238
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600239 auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName),
240 ndn::security::v2::getAcceptAllValidator());
241 fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) {
242 ndn::Block block(bufferPtr);
243 BOOST_CHECK_EQUAL(expectedDataContent, readString(block));
244 });
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500245
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600246 advanceClocks(ndn::time::milliseconds(1), 100);
247 fetcher->stop();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500248}
249
250BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
251{
252 ndn::Name router("/ndn/cs/%C1.Router/router1");
253 uint64_t seqNo = 12;
254 NamePrefixList prefixList;
255
256 NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
257
258 ndn::Name prefix("/prefix/");
259
260 for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
261 lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
262 }
263
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600264 ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500265 interestName.appendNumber(seqNo);
266
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600267 ndn::Block block = ndn::encoding::makeStringBlock(ndn::tlv::Content, lsa.serialize());
268 lsdb.afterFetchLsa(block.getBuffer(), interestName);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500269
270 NameLsa* foundLsa = lsdb.findNameLsa(lsa.getKey());
271 BOOST_REQUIRE(foundLsa != nullptr);
272
Nick Gordonfaf49f42017-10-23 12:36:28 -0500273 BOOST_CHECK_EQUAL(foundLsa->serialize(), lsa.serialize());
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500274}
275
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500276BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
277{
akmhoquec7a79b22014-05-26 08:06:19 -0500278 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500279 NamePrefixList npl1;
280
akmhoquefdbddb12014-05-02 18:35:19 -0500281 std::string s1 = "name1";
282 std::string s2 = "name2";
283 std::string router1 = "router1/1";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500284
285 npl1.insert(s1);
286 npl1.insert(s2);
287
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600288 // For NameLsa lsType is name.
289 // 12 is seqNo, randomly generated.
290 // 1800 seconds is the default life time.
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600291 NameLsa nlsa1(ndn::Name("/router1/1"), 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500292
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600293 Lsdb& lsdb1(nlsr.m_lsdb);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500294
akmhoque31d1d4b2014-05-05 22:08:14 -0500295 lsdb1.installNameLsa(nlsa1);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700296 lsdb1.writeNameLsdbLog();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500297
Nick Gordon727d4832017-10-13 18:04:25 -0500298 BOOST_CHECK(lsdb1.doesLsaExist(ndn::Name("/router1/1/NAME"), Lsa::Type::NAME));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500299
akmhoque31d1d4b2014-05-05 22:08:14 -0500300 lsdb1.removeNameLsa(router1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500301
Nick Gordon727d4832017-10-13 18:04:25 -0500302 BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(ndn::Name("/router1/1"), Lsa::Type::NAME), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500303}
304
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500305BOOST_AUTO_TEST_CASE(InstallNameLsa)
306{
307 // Install lsa with name1 and name2
308 ndn::Name name1("/ndn/name1");
309 ndn::Name name2("/ndn/name2");
310
311 NamePrefixList prefixes;
312 prefixes.insert(name1);
313 prefixes.insert(name2);
314
315 std::string otherRouter("/ndn/site/%C1.router/other-router");
316 ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
317
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600318 NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500319 lsdb.installNameLsa(lsa);
320
Nick Gordon727d4832017-10-13 18:04:25 -0500321 BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter + "/NAME", Lsa::Type::NAME), true);
322 NamePrefixList& nameList = lsdb.findNameLsa(otherRouter + "/NAME")->getNpl();
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500323
Nick Gordonf14ec352017-07-24 16:09:58 -0500324 BOOST_CHECK_EQUAL(nameList, prefixes);
325 //areNamePrefixListsEqual(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500326
327 // Add a prefix: name3
328 ndn::Name name3("/ndn/name3");
329 prefixes.insert(name3);
330
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600331 NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500332 lsdb.installNameLsa(addLsa);
333
334 // Lsa should include name1, name2, and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500335 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500336
337 // Remove a prefix: name2
338 prefixes.remove(name2);
339
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600340 NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500341 lsdb.installNameLsa(removeLsa);
342
343 // Lsa should include name1 and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500344 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500345
346 // Add and remove a prefix: add name2, remove name3
347 prefixes.insert(name2);
348 prefixes.remove(name3);
349
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600350 NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500351 lsdb.installNameLsa(addAndRemoveLsa);
352
353 // Lsa should include name1 and name2
Nick Gordonf14ec352017-07-24 16:09:58 -0500354 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500355
356 // Install a completely new list of prefixes
357 ndn::Name name4("/ndn/name4");
358 ndn::Name name5("/ndn/name5");
359
360 NamePrefixList newPrefixes;
361 newPrefixes.insert(name4);
362 newPrefixes.insert(name5);
363
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600364 NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500365 lsdb.installNameLsa(newLsa);
366
367 // Lsa should include name4 and name5
Nick Gordonf14ec352017-07-24 16:09:58 -0500368 BOOST_CHECK_EQUAL(nameList, newPrefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500369}
370
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500371BOOST_AUTO_TEST_CASE(TestIsLsaNew)
372{
373 const ndn::Name::Component CONFIG_NETWORK{"/ndn"};
374 const ndn::Name::Component CONFIG_SITE{"/memphis"};
375 ndn::Name originRouter{};
376 originRouter.append(CONFIG_NETWORK).append(CONFIG_SITE).append("/%C1.Router/other-router");
377
378 // Install Name LSA
379 NamePrefixList nameList;
380 NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
381
382 lsdb.installNameLsa(lsa);
383
384 // Lower NameLSA sequence number
385 uint64_t lowerSeqNo = 998;
Nick Gordon727d4832017-10-13 18:04:25 -0500386 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500387
388 // Same NameLSA sequence number
389 uint64_t sameSeqNo = 999;
Nick Gordon727d4832017-10-13 18:04:25 -0500390 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500391
392 // Higher NameLSA sequence number
393 uint64_t higherSeqNo = 1000;
Nick Gordon727d4832017-10-13 18:04:25 -0500394 BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500395}
396
397BOOST_AUTO_TEST_SUITE_END() // TestLsdb
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500398
Nick Gordonfad8e252016-08-11 14:21:38 -0500399} // namespace test
400} // namespace nlsr