akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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 Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 20 | */ |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 21 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 22 | #include "lsdb.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 23 | #include "lsa/lsa.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 24 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 26 | #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 Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/util/segment-fetcher.hpp> |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 32 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 33 | #include <unistd.h> |
| 34 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 36 | namespace test { |
| 37 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 38 | class LsdbFixture : public IoKeyChainFixture |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | LsdbFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 42 | : face(m_io, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 43 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 44 | , confProcessor(conf) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 45 | , lsdb(face, m_keyChain, conf) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 46 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 47 | m_keyChain.createIdentity("/ndn/site/%C1.Router/this-router"); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 48 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 49 | advanceClocks(10_ms); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 50 | face.sentInterests.clear(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 53 | void |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 54 | areNamePrefixListsEqual(NamePrefixList& lhs, NamePrefixList& rhs) |
| 55 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 56 | auto lhsList = lhs.getNames(); |
| 57 | auto rhsList = rhs.getNames(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 58 | BOOST_REQUIRE_EQUAL(lhsList.size(), rhsList.size()); |
| 59 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 60 | auto i = lhsList.begin(); |
| 61 | auto j = rhsList.begin(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 62 | for (; i != lhsList.end(); ++i, ++j) { |
| 63 | BOOST_CHECK_EQUAL(*i, *j); |
| 64 | } |
| 65 | } |
| 66 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 67 | void |
| 68 | isFirstNameLsaEqual(const Lsdb& otherLsdb) |
| 69 | { |
| 70 | auto selfLsaRange = lsdb.getLsdbIterator<NameLsa>(); |
| 71 | auto otherLsaRange = otherLsdb.getLsdbIterator<NameLsa>(); |
| 72 | |
| 73 | if (selfLsaRange.first != selfLsaRange.second && otherLsaRange.first != otherLsaRange.second) { |
| 74 | auto ownLsa = std::static_pointer_cast<NameLsa>(*selfLsaRange.first); |
| 75 | auto otherLsa = std::static_pointer_cast<NameLsa>(*otherLsaRange.first); |
| 76 | BOOST_CHECK_EQUAL(ownLsa->getNpl(), otherLsa->getNpl()); |
| 77 | return; |
| 78 | } |
| 79 | BOOST_CHECK(false); |
| 80 | } |
| 81 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 82 | void |
| 83 | checkSignalResult(LsdbUpdate updateType, |
| 84 | const std::shared_ptr<Lsa>& lsaPtr, |
| 85 | const std::list<ndn::Name>& namesToAdd, |
| 86 | const std::list<ndn::Name>& namesToRemove) |
| 87 | { |
| 88 | BOOST_CHECK(updateHappened); |
| 89 | BOOST_CHECK_EQUAL(lsaPtrCheck->getOriginRouter(), lsaPtr->getOriginRouter()); |
| 90 | BOOST_CHECK_EQUAL(lsaPtrCheck->getType(), lsaPtr->getType()); |
| 91 | BOOST_CHECK(updateType == updateTypeCheck); |
| 92 | BOOST_CHECK(namesToAdd == namesToAddCheck); |
| 93 | BOOST_CHECK(namesToRemove == namesToRemoveCheck); |
| 94 | updateHappened = false; |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | connectSignal() |
| 99 | { |
| 100 | lsdb.onLsdbModified.connect( |
| 101 | [&] (std::shared_ptr<Lsa> lsa, LsdbUpdate updateType, |
| 102 | const auto& namesToAdd, const auto& namesToRemove) { |
| 103 | lsaPtrCheck = lsa; |
| 104 | updateTypeCheck = updateType; |
| 105 | namesToAddCheck = namesToAdd; |
| 106 | namesToRemoveCheck = namesToRemove; |
| 107 | updateHappened = true; |
| 108 | } |
| 109 | ); |
| 110 | } |
| 111 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 112 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 113 | ndn::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 114 | ConfParameter conf; |
| 115 | DummyConfFileProcessor confProcessor; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 116 | Lsdb lsdb; |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 117 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 118 | LsdbUpdate updateTypeCheck = LsdbUpdate::INSTALLED; |
| 119 | std::list<ndn::Name> namesToAddCheck; |
| 120 | std::list<ndn::Name> namesToRemoveCheck; |
| 121 | std::shared_ptr<Lsa> lsaPtrCheck = nullptr; |
| 122 | bool updateHappened = false; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 126 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 127 | BOOST_AUTO_TEST_CASE(LsdbSync) |
| 128 | { |
| 129 | ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name"); |
| 130 | uint64_t oldSeqNo = 82; |
| 131 | |
| 132 | ndn::Name oldInterestName = interestName; |
| 133 | oldInterestName.appendNumber(oldSeqNo); |
| 134 | |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 135 | lsdb.expressInterest(oldInterestName, 0, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 136 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 137 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 138 | std::vector<ndn::Interest>& interests = face.sentInterests; |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 139 | |
| 140 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 141 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 142 | bool didFindInterest = false; |
| 143 | for (const auto& interest : interests) { |
| 144 | didFindInterest = didFindInterest || interest.getName() == oldInterestName; |
| 145 | } |
| 146 | |
| 147 | BOOST_CHECK(didFindInterest); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 148 | interests.clear(); |
| 149 | |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 150 | auto deadline = ndn::time::steady_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_MAX); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 151 | |
| 152 | // Simulate an LSA interest timeout |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 153 | lsdb.onFetchLsaError(ndn::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout", |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 154 | oldInterestName, 0, deadline, interestName, oldSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 155 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 156 | |
| 157 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 158 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 159 | didFindInterest = false; |
| 160 | for (const auto& interest : interests) { |
| 161 | didFindInterest = didFindInterest || interest.getName() == oldInterestName; |
| 162 | } |
| 163 | |
| 164 | BOOST_CHECK(didFindInterest); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 165 | interests.clear(); |
| 166 | |
| 167 | uint64_t newSeqNo = 83; |
| 168 | |
| 169 | ndn::Name newInterestName = interestName; |
| 170 | newInterestName.appendNumber(newSeqNo); |
| 171 | |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 172 | lsdb.expressInterest(newInterestName, 0, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 173 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 174 | |
| 175 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 176 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 177 | didFindInterest = false; |
| 178 | for (const auto& interest : interests) { |
| 179 | didFindInterest = didFindInterest || interest.getName() == newInterestName; |
| 180 | } |
| 181 | |
| 182 | BOOST_CHECK(didFindInterest); |
| 183 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 184 | interests.clear(); |
| 185 | |
| 186 | // Simulate an LSA interest timeout where the sequence number is outdated |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 187 | lsdb.onFetchLsaError(ndn::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout", |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 188 | oldInterestName, 0, deadline, interestName, oldSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 189 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 190 | |
| 191 | // Interest should not be expressed for outdated sequence number |
| 192 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 193 | } |
| 194 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 195 | BOOST_AUTO_TEST_CASE(LsdbSegmentedData) |
| 196 | { |
| 197 | // Add a lot of NameLSAs to exceed max packet size |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 198 | ndn::Name originRouter("/ndn/site/%C1.Router/this-router"); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 199 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 200 | auto nameLsa = lsdb.findLsa<NameLsa>(originRouter); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 201 | BOOST_REQUIRE(nameLsa != nullptr); |
| 202 | uint64_t seqNo = nameLsa->getSeqNo(); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 203 | |
| 204 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 205 | |
| 206 | int nPrefixes = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 207 | while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 208 | nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 209 | break; |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 210 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 211 | lsdb.installLsa(nameLsa); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 212 | |
| 213 | // Create another Lsdb and expressInterest |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 214 | ndn::DummyClientFace face2(m_io, m_keyChain, {true, true}); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 215 | face.linkTo(face2); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 216 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 217 | ConfParameter conf2(face2, m_keyChain); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 218 | std::string config = R"CONF( |
| 219 | trust-anchor |
| 220 | { |
| 221 | type any |
| 222 | } |
| 223 | )CONF"; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 224 | conf2.getValidator().load(config, "config-file-from-string"); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 225 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 226 | Lsdb lsdb2(face2, m_keyChain, conf2); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 227 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 228 | advanceClocks(ndn::time::milliseconds(10), 10); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 229 | |
| 230 | ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME"); |
| 231 | interestName.appendNumber(seqNo); |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 232 | lsdb2.expressInterest(interestName, 0/*= timeout count*/, 0); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 233 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 234 | advanceClocks(ndn::time::milliseconds(200), 20); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 235 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 236 | isFirstNameLsaEqual(lsdb2); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 237 | } |
| 238 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 239 | BOOST_AUTO_TEST_CASE(SegmentLsaData) |
| 240 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 241 | ndn::Name originRouter("/ndn/site/%C1.Router/this-router"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 242 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 243 | auto lsa = lsdb.findLsa<NameLsa>(originRouter); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 244 | uint64_t seqNo = lsa->getSeqNo(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 245 | |
| 246 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 247 | |
| 248 | int nPrefixes = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 249 | while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 250 | lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 251 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 252 | lsdb.installLsa(lsa); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 253 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 254 | ndn::Block expectedDataContent = lsa->wireEncode(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 255 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 256 | ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME/"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 257 | interestName.appendNumber(seqNo); |
| 258 | |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 259 | ndn::DummyClientFace face2(m_io, m_keyChain, {true, true}); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 260 | face.linkTo(face2); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 261 | |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 262 | auto fetcher = ndn::SegmentFetcher::start(face2, ndn::Interest(interestName), |
| 263 | ndn::security::getAcceptAllValidator()); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 264 | fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) { |
| 265 | ndn::Block block(bufferPtr); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 266 | BOOST_CHECK_EQUAL(expectedDataContent, block); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 267 | }); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 268 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 269 | advanceClocks(ndn::time::milliseconds(1), 100); |
| 270 | fetcher->stop(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData) |
| 274 | { |
| 275 | ndn::Name router("/ndn/cs/%C1.Router/router1"); |
| 276 | uint64_t seqNo = 12; |
| 277 | NamePrefixList prefixList; |
| 278 | |
| 279 | NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList); |
| 280 | |
| 281 | ndn::Name prefix("/prefix/"); |
| 282 | |
| 283 | for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) { |
| 284 | lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes)); |
| 285 | } |
| 286 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 287 | ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 288 | interestName.appendNumber(seqNo); |
| 289 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 290 | ndn::Block block = lsa.wireEncode(); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 291 | lsdb.afterFetchLsa(block.getBuffer(), interestName); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 292 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 293 | auto foundLsa = std::static_pointer_cast<NameLsa>(lsdb.findLsa(lsa.getOriginRouter(), lsa.getType())); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 294 | BOOST_REQUIRE(foundLsa != nullptr); |
| 295 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 296 | BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode()); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 299 | BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists) |
| 300 | { |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 301 | auto testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 302 | NamePrefixList npl1; |
| 303 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 304 | std::string s1 = "name1"; |
| 305 | std::string s2 = "name2"; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 306 | std::string router1 = "/router1/1"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 307 | |
| 308 | npl1.insert(s1); |
| 309 | npl1.insert(s2); |
| 310 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 311 | // For NameLsa lsType is name. |
| 312 | // 12 is seqNo, randomly generated. |
| 313 | // 1800 seconds is the default life time. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 314 | NameLsa nlsa1(router1, 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 315 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 316 | Lsdb& lsdb1(lsdb); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 317 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 318 | lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 319 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 320 | BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 321 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 322 | lsdb1.removeLsa(router1, Lsa::Type::NAME); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 323 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 325 | } |
| 326 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 327 | BOOST_AUTO_TEST_CASE(InstallNameLsa) |
| 328 | { |
| 329 | // Install lsa with name1 and name2 |
| 330 | ndn::Name name1("/ndn/name1"); |
| 331 | ndn::Name name2("/ndn/name2"); |
| 332 | |
| 333 | NamePrefixList prefixes; |
| 334 | prefixes.insert(name1); |
| 335 | prefixes.insert(name2); |
| 336 | |
| 337 | std::string otherRouter("/ndn/site/%C1.router/other-router"); |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 338 | const auto MAX_TIME = ndn::time::system_clock::time_point::max(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 339 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 340 | NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 341 | lsdb.installLsa(std::make_shared<NameLsa>(lsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 342 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 343 | BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter, Lsa::Type::NAME), true); |
| 344 | NamePrefixList& nameList = std::static_pointer_cast<NameLsa>(lsdb.findLsa(otherRouter, Lsa::Type::NAME))->getNpl(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 345 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 346 | BOOST_CHECK_EQUAL(nameList, prefixes); |
| 347 | //areNamePrefixListsEqual(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 348 | |
| 349 | // Add a prefix: name3 |
| 350 | ndn::Name name3("/ndn/name3"); |
| 351 | prefixes.insert(name3); |
| 352 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 353 | NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 354 | lsdb.installLsa(std::make_shared<NameLsa>(addLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 355 | |
| 356 | // Lsa should include name1, name2, and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 357 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 358 | |
| 359 | // Remove a prefix: name2 |
Junxiao Shi | 52f1664 | 2023-08-15 00:18:35 +0000 | [diff] [blame] | 360 | prefixes.erase(name2); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 361 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 362 | NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 363 | lsdb.installLsa(std::make_shared<NameLsa>(removeLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 364 | |
| 365 | // Lsa should include name1 and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 366 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 367 | |
| 368 | // Add and remove a prefix: add name2, remove name3 |
| 369 | prefixes.insert(name2); |
Junxiao Shi | 52f1664 | 2023-08-15 00:18:35 +0000 | [diff] [blame] | 370 | prefixes.erase(name3); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 371 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 372 | NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 373 | lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 374 | |
| 375 | // Lsa should include name1 and name2 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 376 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 377 | |
| 378 | // Install a completely new list of prefixes |
| 379 | ndn::Name name4("/ndn/name4"); |
| 380 | ndn::Name name5("/ndn/name5"); |
| 381 | |
| 382 | NamePrefixList newPrefixes; |
| 383 | newPrefixes.insert(name4); |
| 384 | newPrefixes.insert(name5); |
| 385 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 386 | NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 387 | lsdb.installLsa(std::make_shared<NameLsa>(newLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 388 | |
| 389 | // Lsa should include name4 and name5 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(nameList, newPrefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 391 | } |
| 392 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 393 | BOOST_AUTO_TEST_CASE(TestIsLsaNew) |
| 394 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 395 | ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router"); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 396 | |
| 397 | // Install Name LSA |
| 398 | NamePrefixList nameList; |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 399 | NameLsa lsa(originRouter, 999, ndn::time::system_clock::time_point::max(), nameList); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 400 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 401 | lsdb.installLsa(std::make_shared<NameLsa>(lsa)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 402 | |
| 403 | // Lower NameLSA sequence number |
| 404 | uint64_t lowerSeqNo = 998; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 405 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 406 | |
| 407 | // Same NameLSA sequence number |
| 408 | uint64_t sameSeqNo = 999; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 409 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 410 | |
| 411 | // Higher NameLSA sequence number |
| 412 | uint64_t higherSeqNo = 1000; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 413 | BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 414 | } |
| 415 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 416 | BOOST_AUTO_TEST_CASE(LsdbSignals) |
| 417 | { |
| 418 | connectSignal(); |
| 419 | auto testTimePoint = ndn::time::system_clock::now() + 3600_s; |
| 420 | ndn::Name router2("/router2"); |
| 421 | AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList()); |
| 422 | std::shared_ptr<Lsa> lsaPtr = std::make_shared<AdjLsa>(adjLsa); |
| 423 | lsdb.installLsa(lsaPtr); |
| 424 | checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {}); |
| 425 | |
| 426 | adjLsa.setSeqNo(13); |
| 427 | updateHappened = false; |
| 428 | lsaPtr = std::make_shared<AdjLsa>(adjLsa); |
| 429 | lsdb.installLsa(lsaPtr); |
| 430 | BOOST_CHECK(!updateHappened); |
| 431 | |
| 432 | Adjacent adj("Neighbor1"); |
| 433 | adjLsa.setSeqNo(14); |
| 434 | adjLsa.addAdjacent(adj); |
| 435 | lsaPtr = std::make_shared<AdjLsa>(adjLsa); |
| 436 | lsdb.installLsa(lsaPtr); |
| 437 | checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {}, {}); |
| 438 | |
| 439 | lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::ADJACENCY); |
| 440 | checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {}); |
| 441 | |
| 442 | // Name LSA |
| 443 | NamePrefixList npl1{"name1", "name2"}; |
| 444 | NameLsa nameLsa(router2, 12, testTimePoint, npl1); |
| 445 | lsaPtr = std::make_shared<NameLsa>(nameLsa); |
| 446 | lsdb.installLsa(lsaPtr); |
| 447 | checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {}); |
| 448 | |
| 449 | nameLsa.setSeqNo(13); |
| 450 | lsaPtr = std::make_shared<NameLsa>(nameLsa); |
| 451 | lsdb.installLsa(lsaPtr); |
| 452 | BOOST_CHECK(!updateHappened); |
| 453 | |
| 454 | NamePrefixList npl2{"name2", "name3"}; |
| 455 | NameLsa nameLsa2(router2, 14, testTimePoint, npl2); |
| 456 | lsaPtr = std::make_shared<NameLsa>(nameLsa2); |
| 457 | lsdb.installLsa(lsaPtr); |
| 458 | checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {"name3"}, {"name1"}); |
| 459 | |
| 460 | lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::NAME); |
| 461 | checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {}); |
| 462 | |
| 463 | // Coordinate LSA |
| 464 | lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 12, testTimePoint, 2.5, {30})); |
| 465 | lsdb.installLsa(lsaPtr); |
| 466 | checkSignalResult(LsdbUpdate::INSTALLED, lsaPtr, {}, {}); |
| 467 | |
| 468 | lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 13, testTimePoint, 2.5, {30})); |
| 469 | lsdb.installLsa(lsaPtr); |
| 470 | BOOST_CHECK(!updateHappened); |
| 471 | |
| 472 | lsaPtr = std::make_shared<CoordinateLsa>(CoordinateLsa("router1", 14, testTimePoint, 2.5, {40})); |
| 473 | lsdb.installLsa(lsaPtr); |
| 474 | checkSignalResult(LsdbUpdate::UPDATED, lsaPtr, {}, {}); |
| 475 | |
| 476 | lsdb.removeLsa(lsaPtrCheck->getOriginRouter(), Lsa::Type::COORDINATE); |
| 477 | checkSignalResult(LsdbUpdate::REMOVED, lsaPtr, {}, {}); |
| 478 | } |
| 479 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 480 | BOOST_AUTO_TEST_SUITE_END() // TestLsdb |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 481 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 482 | } // namespace test |
| 483 | } // namespace nlsr |