blob: db1c60b8837325a18b75f95c6d185aeb9b7d258d [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 Gawande0db4d4d2020-02-05 20:30:02 -080025#include "lsa/lsa.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050026#include "name-prefix-list.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060028#include <ndn-cxx/util/dummy-client-face.hpp>
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050029#include <ndn-cxx/util/segment-fetcher.hpp>
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060030
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050031#include <unistd.h>
32
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050033namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050034namespace test {
35
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050036class LsdbFixture : public UnitTestTimeFixture
Vince Lehman904c2412014-09-23 19:36:11 -050037{
38public:
39 LsdbFixture()
Ashlesh Gawande939b6f82018-12-09 16:51:09 -060040 : face(m_ioService, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060041 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060042 , confProcessor(conf)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070043 , lsdb(face, m_keyChain, conf)
Vince Lehman904c2412014-09-23 19:36:11 -050044 , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib")
45 , REGISTER_VERB("register")
46 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050047 addIdentity("/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
54 extractParameters(ndn::Interest& interest, ndn::Name::Component& verb,
55 ndn::nfd::ControlParameters& extractedParameters)
Vince Lehman904c2412014-09-23 19:36:11 -050056 {
57 const ndn::Name& name = interest.getName();
58 verb = name[REGISTER_COMMAND_PREFIX.size()];
59 const ndn::Name::Component& parameterComponent = name[REGISTER_COMMAND_PREFIX.size() + 1];
60
61 ndn::Block rawParameters = parameterComponent.blockFromValue();
62 extractedParameters.wireDecode(rawParameters);
63 }
64
Vince Lehmanf1aa5232014-10-06 17:57:35 -050065 void
66 areNamePrefixListsEqual(NamePrefixList& lhs, NamePrefixList& rhs)
67 {
Nick Gordonf14ec352017-07-24 16:09:58 -050068
Vince Lehmanf1aa5232014-10-06 17:57:35 -050069 typedef std::list<ndn::Name> NameList;
70
Nick Gordonf14ec352017-07-24 16:09:58 -050071 NameList lhsList = lhs.getNames();
72 NameList rhsList = rhs.getNames();
Vince Lehmanf1aa5232014-10-06 17:57:35 -050073
74 BOOST_REQUIRE_EQUAL(lhsList.size(), rhsList.size());
75
76 NameList::iterator i = lhsList.begin();
77 NameList::iterator j = rhsList.begin();
78
79 for (; i != lhsList.end(); ++i, ++j) {
80 BOOST_CHECK_EQUAL(*i, *j);
81 }
82 }
83
Ashlesh Gawande57a87172020-05-09 19:47:06 -070084 void
85 isFirstNameLsaEqual(const Lsdb& otherLsdb)
86 {
87 auto selfLsaRange = lsdb.getLsdbIterator<NameLsa>();
88 auto otherLsaRange = otherLsdb.getLsdbIterator<NameLsa>();
89
90 if (selfLsaRange.first != selfLsaRange.second && otherLsaRange.first != otherLsaRange.second) {
91 auto ownLsa = std::static_pointer_cast<NameLsa>(*selfLsaRange.first);
92 auto otherLsa = std::static_pointer_cast<NameLsa>(*otherLsaRange.first);
93 BOOST_CHECK_EQUAL(ownLsa->getNpl(), otherLsa->getNpl());
94 return;
95 }
96 BOOST_CHECK(false);
97 }
98
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070099 void
100 checkSignalResult(LsdbUpdate updateType,
101 const std::shared_ptr<Lsa>& lsaPtr,
102 const std::list<ndn::Name>& namesToAdd,
103 const std::list<ndn::Name>& namesToRemove)
104 {
105 BOOST_CHECK(updateHappened);
106 BOOST_CHECK_EQUAL(lsaPtrCheck->getOriginRouter(), lsaPtr->getOriginRouter());
107 BOOST_CHECK_EQUAL(lsaPtrCheck->getType(), lsaPtr->getType());
108 BOOST_CHECK(updateType == updateTypeCheck);
109 BOOST_CHECK(namesToAdd == namesToAddCheck);
110 BOOST_CHECK(namesToRemove == namesToRemoveCheck);
111 updateHappened = false;
112 }
113
114 void
115 connectSignal()
116 {
117 lsdb.onLsdbModified.connect(
118 [&] (std::shared_ptr<Lsa> lsa, LsdbUpdate updateType,
119 const auto& namesToAdd, const auto& namesToRemove) {
120 lsaPtrCheck = lsa;
121 updateTypeCheck = updateType;
122 namesToAddCheck = namesToAdd;
123 namesToRemoveCheck = namesToRemove;
124 updateHappened = true;
125 }
126 );
127 }
128
Vince Lehman904c2412014-09-23 19:36:11 -0500129public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500130 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600131 ConfParameter conf;
132 DummyConfFileProcessor confProcessor;
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700133 Lsdb lsdb;
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500134
Vince Lehman904c2412014-09-23 19:36:11 -0500135 ndn::Name REGISTER_COMMAND_PREFIX;
136 ndn::Name::Component REGISTER_VERB;
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700137
138 LsdbUpdate updateTypeCheck = LsdbUpdate::INSTALLED;
139 std::list<ndn::Name> namesToAddCheck;
140 std::list<ndn::Name> namesToRemoveCheck;
141 std::shared_ptr<Lsa> lsaPtrCheck = nullptr;
142 bool updateHappened = false;
Vince Lehman904c2412014-09-23 19:36:11 -0500143};
144
145BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500146
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500147BOOST_AUTO_TEST_CASE(LsdbSync)
148{
149 ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name");
150 uint64_t oldSeqNo = 82;
151
152 ndn::Name oldInterestName = interestName;
153 oldInterestName.appendNumber(oldSeqNo);
154
155 lsdb.expressInterest(oldInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600156 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500157
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500158 std::vector<ndn::Interest>& interests = face.sentInterests;
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500159
160 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500161
Nick Gordon098aae42017-08-23 15:18:46 -0500162 bool didFindInterest = false;
163 for (const auto& interest : interests) {
164 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
165 }
166
167 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500168 interests.clear();
169
Nick Gordone98480b2017-05-24 11:23:03 -0500170 ndn::time::steady_clock::TimePoint deadline = ndn::time::steady_clock::now() +
171 ndn::time::seconds(LSA_REFRESH_TIME_MAX);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500172
173 // Simulate an LSA interest timeout
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500174 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
175 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600176 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500177
178 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500179
Nick Gordon098aae42017-08-23 15:18:46 -0500180 didFindInterest = false;
181 for (const auto& interest : interests) {
182 didFindInterest = didFindInterest || interest.getName() == oldInterestName;
183 }
184
185 BOOST_CHECK(didFindInterest);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500186 interests.clear();
187
188 uint64_t newSeqNo = 83;
189
190 ndn::Name newInterestName = interestName;
191 newInterestName.appendNumber(newSeqNo);
192
193 lsdb.expressInterest(newInterestName, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600194 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500195
196 BOOST_REQUIRE(interests.size() > 0);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500197
Nick Gordon098aae42017-08-23 15:18:46 -0500198 didFindInterest = false;
199 for (const auto& interest : interests) {
200 didFindInterest = didFindInterest || interest.getName() == newInterestName;
201 }
202
203 BOOST_CHECK(didFindInterest);
204
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500205 interests.clear();
206
207 // Simulate an LSA interest timeout where the sequence number is outdated
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500208 lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout",
209 oldInterestName, 0, deadline, interestName, oldSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600210 advanceClocks(10_ms);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500211
212 // Interest should not be expressed for outdated sequence number
213 BOOST_CHECK_EQUAL(interests.size(), 0);
214}
215
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600216BOOST_AUTO_TEST_CASE(LsdbSegmentedData)
217{
218 // Add a lot of NameLSAs to exceed max packet size
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700219 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600220
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700221 auto nameLsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800222 BOOST_REQUIRE(nameLsa != nullptr);
223 uint64_t seqNo = nameLsa->getSeqNo();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600224
225 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
226
227 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800228 while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600229 nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500230 break;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600231 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700232 lsdb.installLsa(nameLsa);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600233
234 // Create another Lsdb and expressInterest
235 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
236 face.linkTo(face2);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500237
Saurab Dulal427e0122019-11-28 11:58:02 -0600238 ConfParameter conf2(face2, m_keyChain);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600239 std::string config = R"CONF(
240 trust-anchor
241 {
242 type any
243 }
244 )CONF";
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600245 conf2.getValidator().load(config, "config-file-from-string");
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600246
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700247 Lsdb lsdb2(face2, m_keyChain, conf2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600248
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500249 advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600250
251 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME");
252 interestName.appendNumber(seqNo);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500253 lsdb2.expressInterest(interestName, 0/*= timeout count*/);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600254
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500255 advanceClocks(ndn::time::milliseconds(200), 20);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600256
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700257 isFirstNameLsaEqual(lsdb2);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600258}
259
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500260BOOST_AUTO_TEST_CASE(SegmentLsaData)
261{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700262 ndn::Name originRouter("/ndn/site/%C1.Router/this-router");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500263
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700264 auto lsa = lsdb.findLsa<NameLsa>(originRouter);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800265 uint64_t seqNo = lsa->getSeqNo();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500266
267 ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/");
268
269 int nPrefixes = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800270 while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) {
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000271 lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500272 }
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700273 lsdb.installLsa(lsa);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500274
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800275 ndn::Block expectedDataContent = lsa->wireEncode();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500276
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600277 ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500278 interestName.appendNumber(seqNo);
279
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600280 ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
281 face.linkTo(face2);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500282
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600283 auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName),
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -0400284 ndn::security::getAcceptAllValidator());
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600285 fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) {
286 ndn::Block block(bufferPtr);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800287 BOOST_CHECK_EQUAL(expectedDataContent, block);
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600288 });
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500289
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600290 advanceClocks(ndn::time::milliseconds(1), 100);
291 fetcher->stop();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500292}
293
294BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData)
295{
296 ndn::Name router("/ndn/cs/%C1.Router/router1");
297 uint64_t seqNo = 12;
298 NamePrefixList prefixList;
299
300 NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList);
301
302 ndn::Name prefix("/prefix/");
303
304 for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) {
305 lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes));
306 }
307
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600308 ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500309 interestName.appendNumber(seqNo);
310
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800311 ndn::Block block = lsa.wireEncode();
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600312 lsdb.afterFetchLsa(block.getBuffer(), interestName);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500313
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700314 auto foundLsa = std::static_pointer_cast<NameLsa>(lsdb.findLsa(lsa.getOriginRouter(), lsa.getType()));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500315 BOOST_REQUIRE(foundLsa != nullptr);
316
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800317 BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode());
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500318}
319
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500320BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
321{
akmhoquec7a79b22014-05-26 08:06:19 -0500322 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500323 NamePrefixList npl1;
324
akmhoquefdbddb12014-05-02 18:35:19 -0500325 std::string s1 = "name1";
326 std::string s2 = "name2";
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700327 std::string router1 = "/router1/1";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500328
329 npl1.insert(s1);
330 npl1.insert(s2);
331
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600332 // For NameLsa lsType is name.
333 // 12 is seqNo, randomly generated.
334 // 1800 seconds is the default life time.
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700335 NameLsa nlsa1(router1, 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500336
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700337 Lsdb& lsdb1(lsdb);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500338
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700339 lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500340
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700341 BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500342
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700343 lsdb1.removeLsa(router1, Lsa::Type::NAME);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500344
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700345 BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500346}
347
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500348BOOST_AUTO_TEST_CASE(InstallNameLsa)
349{
350 // Install lsa with name1 and name2
351 ndn::Name name1("/ndn/name1");
352 ndn::Name name2("/ndn/name2");
353
354 NamePrefixList prefixes;
355 prefixes.insert(name1);
356 prefixes.insert(name2);
357
358 std::string otherRouter("/ndn/site/%C1.router/other-router");
359 ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max();
360
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600361 NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700362 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500363
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700364 BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter, Lsa::Type::NAME), true);
365 NamePrefixList& nameList = std::static_pointer_cast<NameLsa>(lsdb.findLsa(otherRouter, Lsa::Type::NAME))->getNpl();
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500366
Nick Gordonf14ec352017-07-24 16:09:58 -0500367 BOOST_CHECK_EQUAL(nameList, prefixes);
368 //areNamePrefixListsEqual(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500369
370 // Add a prefix: name3
371 ndn::Name name3("/ndn/name3");
372 prefixes.insert(name3);
373
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600374 NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700375 lsdb.installLsa(std::make_shared<NameLsa>(addLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500376
377 // Lsa should include name1, name2, and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500378 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500379
380 // Remove a prefix: name2
381 prefixes.remove(name2);
382
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600383 NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700384 lsdb.installLsa(std::make_shared<NameLsa>(removeLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500385
386 // Lsa should include name1 and name3
Nick Gordonf14ec352017-07-24 16:09:58 -0500387 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500388
389 // Add and remove a prefix: add name2, remove name3
390 prefixes.insert(name2);
391 prefixes.remove(name3);
392
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600393 NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700394 lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500395
396 // Lsa should include name1 and name2
Nick Gordonf14ec352017-07-24 16:09:58 -0500397 BOOST_CHECK_EQUAL(nameList, prefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500398
399 // Install a completely new list of prefixes
400 ndn::Name name4("/ndn/name4");
401 ndn::Name name5("/ndn/name5");
402
403 NamePrefixList newPrefixes;
404 newPrefixes.insert(name4);
405 newPrefixes.insert(name5);
406
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600407 NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700408 lsdb.installLsa(std::make_shared<NameLsa>(newLsa));
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500409
410 // Lsa should include name4 and name5
Nick Gordonf14ec352017-07-24 16:09:58 -0500411 BOOST_CHECK_EQUAL(nameList, newPrefixes);
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500412}
413
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500414BOOST_AUTO_TEST_CASE(TestIsLsaNew)
415{
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700416 ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router");
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500417
418 // Install Name LSA
419 NamePrefixList nameList;
420 NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
421
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700422 lsdb.installLsa(std::make_shared<NameLsa>(lsa));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500423
424 // Lower NameLSA sequence number
425 uint64_t lowerSeqNo = 998;
Nick Gordon727d4832017-10-13 18:04:25 -0500426 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500427
428 // Same NameLSA sequence number
429 uint64_t sameSeqNo = 999;
Nick Gordon727d4832017-10-13 18:04:25 -0500430 BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500431
432 // Higher NameLSA sequence number
433 uint64_t higherSeqNo = 1000;
Nick Gordon727d4832017-10-13 18:04:25 -0500434 BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500435}
436
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700437BOOST_AUTO_TEST_CASE(LsdbSignals)
438{
439 connectSignal();
440 auto testTimePoint = ndn::time::system_clock::now() + 3600_s;
441 ndn::Name router2("/router2");
442 AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList());
443 std::shared_ptr<Lsa> lsaPtr = std::make_shared<AdjLsa>(adjLsa);
444 lsdb.installLsa(lsaPtr);
445 checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
446
447 adjLsa.setSeqNo(13);
448 updateHappened = false;
449 lsaPtr = std::make_shared<AdjLsa>(adjLsa);
450 lsdb.installLsa(lsaPtr);
451 BOOST_CHECK(!updateHappened);
452
453 Adjacent adj("Neighbor1");
454 adjLsa.setSeqNo(14);
455 adjLsa.addAdjacent(adj);
456 lsaPtr = std::make_shared<AdjLsa>(adjLsa);
457 lsdb.installLsa(lsaPtr);
458 checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {}, {});
459
460 lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::ADJACENCY);
461 checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {});
462
463 // Name LSA
464 NamePrefixList npl1{"name1", "name2"};
465 NameLsa nameLsa(router2, 12, testTimePoint, npl1);
466 lsaPtr = std::make_shared<NameLsa>(nameLsa);
467 lsdb.installLsa(lsaPtr);
468 checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
469
470 nameLsa.setSeqNo(13);
471 lsaPtr = std::make_shared<NameLsa>(nameLsa);
472 lsdb.installLsa(lsaPtr);
473 BOOST_CHECK(!updateHappened);
474
475 NamePrefixList npl2{"name2", "name3"};
476 NameLsa nameLsa2(router2, 14, testTimePoint, npl2);
477 lsaPtr = std::make_shared<NameLsa>(nameLsa2);
478 lsdb.installLsa(lsaPtr);
479 checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {"name3"}, {"name1"});
480
481 lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::NAME);
482 checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {});
483
484 // Coordinate LSA
485 lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 12, testTimePoint, 2.5, {30}));
486 lsdb.installLsa(lsaPtr);
487 checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {});
488
489 lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 13, testTimePoint, 2.5, {30}));
490 lsdb.installLsa(lsaPtr);
491 BOOST_CHECK(!updateHappened);
492
493 lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 14, testTimePoint, 2.5, {40}));
494 lsdb.installLsa(lsaPtr);
495 checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {}, {});
496
497 lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::COORDINATE);
498 checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {});
499}
500
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500501BOOST_AUTO_TEST_SUITE_END() // TestLsdb
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500502
Nick Gordonfad8e252016-08-11 14:21:38 -0500503} // namespace test
504} // namespace nlsr