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 | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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" |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 23 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 24 | #include "test-common.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 25 | #include "lsa/lsa.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 26 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 29 | #include <ndn-cxx/util/segment-fetcher.hpp> |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 30 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 31 | #include <unistd.h> |
| 32 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 34 | namespace test { |
| 35 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 36 | class LsdbFixture : public UnitTestTimeFixture |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | LsdbFixture() |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 40 | : face(m_ioService, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 41 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 42 | , confProcessor(conf) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 43 | , lsdb(face, m_keyChain, conf) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 44 | , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib") |
| 45 | , REGISTER_VERB("register") |
| 46 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 47 | addIdentity("/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 |
| 54 | extractParameters(ndn::Interest& interest, ndn::Name::Component& verb, |
| 55 | ndn::nfd::ControlParameters& extractedParameters) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 56 | { |
| 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 Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 65 | void |
| 66 | areNamePrefixListsEqual(NamePrefixList& lhs, NamePrefixList& rhs) |
| 67 | { |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 68 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 69 | typedef std::list<ndn::Name> NameList; |
| 70 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 71 | NameList lhsList = lhs.getNames(); |
| 72 | NameList rhsList = rhs.getNames(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 73 | |
| 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 Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 84 | 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 Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 99 | 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 Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 129 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 130 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 131 | ConfParameter conf; |
| 132 | DummyConfFileProcessor confProcessor; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 133 | Lsdb lsdb; |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 134 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 135 | ndn::Name REGISTER_COMMAND_PREFIX; |
| 136 | ndn::Name::Component REGISTER_VERB; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 137 | |
| 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 Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 146 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 147 | BOOST_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 Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 156 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 157 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 158 | std::vector<ndn::Interest>& interests = face.sentInterests; |
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 | bool didFindInterest = false; |
| 163 | for (const auto& interest : interests) { |
| 164 | didFindInterest = didFindInterest || interest.getName() == oldInterestName; |
| 165 | } |
| 166 | |
| 167 | BOOST_CHECK(didFindInterest); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 168 | interests.clear(); |
| 169 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 170 | ndn::time::steady_clock::TimePoint deadline = ndn::time::steady_clock::now() + |
| 171 | ndn::time::seconds(LSA_REFRESH_TIME_MAX); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 172 | |
| 173 | // Simulate an LSA interest timeout |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 174 | lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout", |
| 175 | oldInterestName, 0, deadline, interestName, oldSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 176 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 177 | |
| 178 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 179 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 180 | didFindInterest = false; |
| 181 | for (const auto& interest : interests) { |
| 182 | didFindInterest = didFindInterest || interest.getName() == oldInterestName; |
| 183 | } |
| 184 | |
| 185 | BOOST_CHECK(didFindInterest); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 186 | 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 Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 194 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 195 | |
| 196 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 197 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 198 | didFindInterest = false; |
| 199 | for (const auto& interest : interests) { |
| 200 | didFindInterest = didFindInterest || interest.getName() == newInterestName; |
| 201 | } |
| 202 | |
| 203 | BOOST_CHECK(didFindInterest); |
| 204 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 205 | interests.clear(); |
| 206 | |
| 207 | // Simulate an LSA interest timeout where the sequence number is outdated |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 208 | lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout", |
| 209 | oldInterestName, 0, deadline, interestName, oldSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 210 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 211 | |
| 212 | // Interest should not be expressed for outdated sequence number |
| 213 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 214 | } |
| 215 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 216 | BOOST_AUTO_TEST_CASE(LsdbSegmentedData) |
| 217 | { |
| 218 | // Add a lot of NameLSAs to exceed max packet size |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 219 | ndn::Name originRouter("/ndn/site/%C1.Router/this-router"); |
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 | auto nameLsa = lsdb.findLsa<NameLsa>(originRouter); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 222 | BOOST_REQUIRE(nameLsa != nullptr); |
| 223 | uint64_t seqNo = nameLsa->getSeqNo(); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 224 | |
| 225 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 226 | |
| 227 | int nPrefixes = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 228 | while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 229 | nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 230 | break; |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 231 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 232 | lsdb.installLsa(nameLsa); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 233 | |
| 234 | // Create another Lsdb and expressInterest |
| 235 | ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true}); |
| 236 | face.linkTo(face2); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 237 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 238 | ConfParameter conf2(face2, m_keyChain); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 239 | std::string config = R"CONF( |
| 240 | trust-anchor |
| 241 | { |
| 242 | type any |
| 243 | } |
| 244 | )CONF"; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 245 | conf2.getValidator().load(config, "config-file-from-string"); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 246 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 247 | Lsdb lsdb2(face2, m_keyChain, conf2); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 248 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 249 | advanceClocks(ndn::time::milliseconds(10), 10); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 250 | |
| 251 | ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME"); |
| 252 | interestName.appendNumber(seqNo); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 253 | lsdb2.expressInterest(interestName, 0/*= timeout count*/); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 254 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 255 | advanceClocks(ndn::time::milliseconds(200), 20); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 256 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 257 | isFirstNameLsaEqual(lsdb2); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 258 | } |
| 259 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 260 | BOOST_AUTO_TEST_CASE(SegmentLsaData) |
| 261 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 262 | ndn::Name originRouter("/ndn/site/%C1.Router/this-router"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 263 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 264 | auto lsa = lsdb.findLsa<NameLsa>(originRouter); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 265 | uint64_t seqNo = lsa->getSeqNo(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 266 | |
| 267 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 268 | |
| 269 | int nPrefixes = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 270 | while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 271 | lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 272 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 273 | lsdb.installLsa(lsa); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 274 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 275 | ndn::Block expectedDataContent = lsa->wireEncode(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 276 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 277 | 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] | 278 | interestName.appendNumber(seqNo); |
| 279 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 280 | ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true}); |
| 281 | face.linkTo(face2); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 282 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 283 | auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName), |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 284 | ndn::security::getAcceptAllValidator()); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 285 | fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) { |
| 286 | ndn::Block block(bufferPtr); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 287 | BOOST_CHECK_EQUAL(expectedDataContent, block); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 288 | }); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 289 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 290 | advanceClocks(ndn::time::milliseconds(1), 100); |
| 291 | fetcher->stop(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | BOOST_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 Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 308 | 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] | 309 | interestName.appendNumber(seqNo); |
| 310 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 311 | ndn::Block block = lsa.wireEncode(); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 312 | lsdb.afterFetchLsa(block.getBuffer(), interestName); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 313 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 314 | 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] | 315 | BOOST_REQUIRE(foundLsa != nullptr); |
| 316 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 317 | BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode()); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 320 | BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists) |
| 321 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 322 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 323 | NamePrefixList npl1; |
| 324 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 325 | std::string s1 = "name1"; |
| 326 | std::string s2 = "name2"; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 327 | std::string router1 = "/router1/1"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 328 | |
| 329 | npl1.insert(s1); |
| 330 | npl1.insert(s2); |
| 331 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 332 | // For NameLsa lsType is name. |
| 333 | // 12 is seqNo, randomly generated. |
| 334 | // 1800 seconds is the default life time. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 335 | NameLsa nlsa1(router1, 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 336 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 337 | Lsdb& lsdb1(lsdb); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 338 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 339 | lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 340 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 341 | BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 342 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 343 | lsdb1.removeLsa(router1, Lsa::Type::NAME); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 344 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 348 | BOOST_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 Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 361 | NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 362 | lsdb.installLsa(std::make_shared<NameLsa>(lsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 363 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 364 | 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 Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 366 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 367 | BOOST_CHECK_EQUAL(nameList, prefixes); |
| 368 | //areNamePrefixListsEqual(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 369 | |
| 370 | // Add a prefix: name3 |
| 371 | ndn::Name name3("/ndn/name3"); |
| 372 | prefixes.insert(name3); |
| 373 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 374 | NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 375 | lsdb.installLsa(std::make_shared<NameLsa>(addLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 376 | |
| 377 | // Lsa should include name1, name2, and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 378 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 379 | |
| 380 | // Remove a prefix: name2 |
| 381 | prefixes.remove(name2); |
| 382 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 383 | NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 384 | lsdb.installLsa(std::make_shared<NameLsa>(removeLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 385 | |
| 386 | // Lsa should include name1 and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 387 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 388 | |
| 389 | // Add and remove a prefix: add name2, remove name3 |
| 390 | prefixes.insert(name2); |
| 391 | prefixes.remove(name3); |
| 392 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 393 | NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 394 | lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 395 | |
| 396 | // Lsa should include name1 and name2 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 397 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 398 | |
| 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 Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 407 | NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 408 | lsdb.installLsa(std::make_shared<NameLsa>(newLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 409 | |
| 410 | // Lsa should include name4 and name5 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 411 | BOOST_CHECK_EQUAL(nameList, newPrefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 414 | BOOST_AUTO_TEST_CASE(TestIsLsaNew) |
| 415 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 416 | ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router"); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 417 | |
| 418 | // Install Name LSA |
| 419 | NamePrefixList nameList; |
| 420 | NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList); |
| 421 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 422 | lsdb.installLsa(std::make_shared<NameLsa>(lsa)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 423 | |
| 424 | // Lower NameLSA sequence number |
| 425 | uint64_t lowerSeqNo = 998; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 426 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 427 | |
| 428 | // Same NameLSA sequence number |
| 429 | uint64_t sameSeqNo = 999; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 430 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 431 | |
| 432 | // Higher NameLSA sequence number |
| 433 | uint64_t higherSeqNo = 1000; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 434 | BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 435 | } |
| 436 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 437 | BOOST_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 Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 501 | BOOST_AUTO_TEST_SUITE_END() // TestLsdb |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 502 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 503 | } // namespace test |
| 504 | } // namespace nlsr |