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