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 | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | #include "nlsr.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 26 | #include "lsa/lsa.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 28 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 29 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/segment-fetcher.hpp> |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 31 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 32 | #include <unistd.h> |
| 33 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 34 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | namespace test { |
| 36 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 37 | class LsdbFixture : public UnitTestTimeFixture |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 38 | { |
| 39 | public: |
| 40 | LsdbFixture() |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 41 | : face(m_ioService, 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) |
| 44 | , nlsr(face, m_keyChain, conf) |
| 45 | , lsdb(nlsr.m_lsdb) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 46 | , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib") |
| 47 | , REGISTER_VERB("register") |
| 48 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 49 | addIdentity("/ndn/site/%C1.Router/this-router"); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 50 | |
| 51 | nlsr.initialize(); |
| 52 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 53 | advanceClocks(10_ms); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 54 | face.sentInterests.clear(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 55 | } |
| 56 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 57 | void |
| 58 | extractParameters(ndn::Interest& interest, ndn::Name::Component& verb, |
| 59 | ndn::nfd::ControlParameters& extractedParameters) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 60 | { |
| 61 | const ndn::Name& name = interest.getName(); |
| 62 | verb = name[REGISTER_COMMAND_PREFIX.size()]; |
| 63 | const ndn::Name::Component& parameterComponent = name[REGISTER_COMMAND_PREFIX.size() + 1]; |
| 64 | |
| 65 | ndn::Block rawParameters = parameterComponent.blockFromValue(); |
| 66 | extractedParameters.wireDecode(rawParameters); |
| 67 | } |
| 68 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 69 | void |
| 70 | areNamePrefixListsEqual(NamePrefixList& lhs, NamePrefixList& rhs) |
| 71 | { |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 72 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 73 | typedef std::list<ndn::Name> NameList; |
| 74 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 75 | NameList lhsList = lhs.getNames(); |
| 76 | NameList rhsList = rhs.getNames(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 77 | |
| 78 | BOOST_REQUIRE_EQUAL(lhsList.size(), rhsList.size()); |
| 79 | |
| 80 | NameList::iterator i = lhsList.begin(); |
| 81 | NameList::iterator j = rhsList.begin(); |
| 82 | |
| 83 | for (; i != lhsList.end(); ++i, ++j) { |
| 84 | BOOST_CHECK_EQUAL(*i, *j); |
| 85 | } |
| 86 | } |
| 87 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 88 | void |
| 89 | isFirstNameLsaEqual(const Lsdb& otherLsdb) |
| 90 | { |
| 91 | auto selfLsaRange = lsdb.getLsdbIterator<NameLsa>(); |
| 92 | auto otherLsaRange = otherLsdb.getLsdbIterator<NameLsa>(); |
| 93 | |
| 94 | if (selfLsaRange.first != selfLsaRange.second && otherLsaRange.first != otherLsaRange.second) { |
| 95 | auto ownLsa = std::static_pointer_cast<NameLsa>(*selfLsaRange.first); |
| 96 | auto otherLsa = std::static_pointer_cast<NameLsa>(*otherLsaRange.first); |
| 97 | BOOST_CHECK_EQUAL(ownLsa->getNpl(), otherLsa->getNpl()); |
| 98 | return; |
| 99 | } |
| 100 | BOOST_CHECK(false); |
| 101 | } |
| 102 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 103 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 104 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 105 | ConfParameter conf; |
| 106 | DummyConfFileProcessor confProcessor; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 107 | Nlsr nlsr; |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 108 | Lsdb& lsdb; |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 109 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 110 | ndn::Name REGISTER_COMMAND_PREFIX; |
| 111 | ndn::Name::Component REGISTER_VERB; |
| 112 | }; |
| 113 | |
| 114 | BOOST_FIXTURE_TEST_SUITE(TestLsdb, LsdbFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 115 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 116 | BOOST_AUTO_TEST_CASE(LsdbSync) |
| 117 | { |
| 118 | ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router2/name"); |
| 119 | uint64_t oldSeqNo = 82; |
| 120 | |
| 121 | ndn::Name oldInterestName = interestName; |
| 122 | oldInterestName.appendNumber(oldSeqNo); |
| 123 | |
| 124 | lsdb.expressInterest(oldInterestName, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 125 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 126 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 127 | std::vector<ndn::Interest>& interests = face.sentInterests; |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 128 | |
| 129 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 130 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 131 | bool didFindInterest = false; |
| 132 | for (const auto& interest : interests) { |
| 133 | didFindInterest = didFindInterest || interest.getName() == oldInterestName; |
| 134 | } |
| 135 | |
| 136 | BOOST_CHECK(didFindInterest); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 137 | interests.clear(); |
| 138 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 139 | ndn::time::steady_clock::TimePoint deadline = ndn::time::steady_clock::now() + |
| 140 | ndn::time::seconds(LSA_REFRESH_TIME_MAX); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 141 | |
| 142 | // Simulate an LSA interest timeout |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 143 | lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout", |
| 144 | oldInterestName, 0, deadline, interestName, oldSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 145 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 146 | |
| 147 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 148 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 149 | didFindInterest = false; |
| 150 | for (const auto& interest : interests) { |
| 151 | didFindInterest = didFindInterest || interest.getName() == oldInterestName; |
| 152 | } |
| 153 | |
| 154 | BOOST_CHECK(didFindInterest); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 155 | interests.clear(); |
| 156 | |
| 157 | uint64_t newSeqNo = 83; |
| 158 | |
| 159 | ndn::Name newInterestName = interestName; |
| 160 | newInterestName.appendNumber(newSeqNo); |
| 161 | |
| 162 | lsdb.expressInterest(newInterestName, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 163 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 164 | |
| 165 | BOOST_REQUIRE(interests.size() > 0); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 166 | |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 167 | didFindInterest = false; |
| 168 | for (const auto& interest : interests) { |
| 169 | didFindInterest = didFindInterest || interest.getName() == newInterestName; |
| 170 | } |
| 171 | |
| 172 | BOOST_CHECK(didFindInterest); |
| 173 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 174 | interests.clear(); |
| 175 | |
| 176 | // Simulate an LSA interest timeout where the sequence number is outdated |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 177 | lsdb.onFetchLsaError(ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT, "Timeout", |
| 178 | oldInterestName, 0, deadline, interestName, oldSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 179 | advanceClocks(10_ms); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 180 | |
| 181 | // Interest should not be expressed for outdated sequence number |
| 182 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 183 | } |
| 184 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 185 | BOOST_AUTO_TEST_CASE(LsdbSegmentedData) |
| 186 | { |
| 187 | // Add a lot of NameLSAs to exceed max packet size |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 188 | ndn::Name originRouter("/ndn/site/%C1.Router/this-router"); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 189 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 190 | auto nameLsa = lsdb.findLsa<NameLsa>(originRouter); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 191 | BOOST_REQUIRE(nameLsa != nullptr); |
| 192 | uint64_t seqNo = nameLsa->getSeqNo(); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 193 | |
| 194 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 195 | |
| 196 | int nPrefixes = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 197 | while (nameLsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 198 | nameLsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 199 | break; |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 200 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 201 | lsdb.installLsa(nameLsa); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 202 | |
| 203 | // Create another Lsdb and expressInterest |
| 204 | ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true}); |
| 205 | face.linkTo(face2); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 206 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 207 | ConfParameter conf2(face2, m_keyChain); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 208 | std::string config = R"CONF( |
| 209 | trust-anchor |
| 210 | { |
| 211 | type any |
| 212 | } |
| 213 | )CONF"; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 214 | conf2.getValidator().load(config, "config-file-from-string"); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 215 | Nlsr nlsr2(face2, m_keyChain, conf2); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 216 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 217 | Lsdb& lsdb2(nlsr2.m_lsdb); |
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(10), 10); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 220 | |
| 221 | ndn::Name interestName("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/NAME"); |
| 222 | interestName.appendNumber(seqNo); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 223 | lsdb2.expressInterest(interestName, 0/*= timeout count*/); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 224 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 225 | advanceClocks(ndn::time::milliseconds(200), 20); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 226 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 227 | isFirstNameLsaEqual(lsdb2); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 228 | } |
| 229 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 230 | BOOST_AUTO_TEST_CASE(SegmentLsaData) |
| 231 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 232 | ndn::Name originRouter("/ndn/site/%C1.Router/this-router"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 233 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 234 | auto lsa = lsdb.findLsa<NameLsa>(originRouter); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 235 | uint64_t seqNo = lsa->getSeqNo(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 236 | |
| 237 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 238 | |
| 239 | int nPrefixes = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 240 | while (lsa->wireEncode().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 241 | lsa->addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
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 | lsdb.installLsa(lsa); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 244 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 245 | ndn::Block expectedDataContent = lsa->wireEncode(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 246 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 247 | 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] | 248 | interestName.appendNumber(seqNo); |
| 249 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 250 | ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true}); |
| 251 | face.linkTo(face2); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 252 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 253 | auto fetcher = ndn::util::SegmentFetcher::start(face2, ndn::Interest(interestName), |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 254 | ndn::security::getAcceptAllValidator()); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 255 | fetcher->onComplete.connect([&expectedDataContent] (ndn::ConstBufferPtr bufferPtr) { |
| 256 | ndn::Block block(bufferPtr); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(expectedDataContent, block); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 258 | }); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 259 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 260 | advanceClocks(ndn::time::milliseconds(1), 100); |
| 261 | fetcher->stop(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData) |
| 265 | { |
| 266 | ndn::Name router("/ndn/cs/%C1.Router/router1"); |
| 267 | uint64_t seqNo = 12; |
| 268 | NamePrefixList prefixList; |
| 269 | |
| 270 | NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList); |
| 271 | |
| 272 | ndn::Name prefix("/prefix/"); |
| 273 | |
| 274 | for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) { |
| 275 | lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes)); |
| 276 | } |
| 277 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 278 | 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] | 279 | interestName.appendNumber(seqNo); |
| 280 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 281 | ndn::Block block = lsa.wireEncode(); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 282 | lsdb.afterFetchLsa(block.getBuffer(), interestName); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 283 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 284 | 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] | 285 | BOOST_REQUIRE(foundLsa != nullptr); |
| 286 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 287 | BOOST_CHECK_EQUAL(foundLsa->wireEncode(), lsa.wireEncode()); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 290 | BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists) |
| 291 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 292 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 293 | NamePrefixList npl1; |
| 294 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 295 | std::string s1 = "name1"; |
| 296 | std::string s2 = "name2"; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 297 | std::string router1 = "/router1/1"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 298 | |
| 299 | npl1.insert(s1); |
| 300 | npl1.insert(s2); |
| 301 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 302 | // For NameLsa lsType is name. |
| 303 | // 12 is seqNo, randomly generated. |
| 304 | // 1800 seconds is the default life time. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 305 | NameLsa nlsa1(router1, 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 306 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 307 | Lsdb& lsdb1(nlsr.m_lsdb); |
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 | lsdb1.installLsa(std::make_shared<NameLsa>(nlsa1)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 310 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 311 | BOOST_CHECK(lsdb1.doesLsaExist(router1, Lsa::Type::NAME)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 312 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 313 | lsdb1.removeLsa(router1, Lsa::Type::NAME); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 314 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 315 | BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(router1, Lsa::Type::NAME), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 316 | } |
| 317 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 318 | BOOST_AUTO_TEST_CASE(InstallNameLsa) |
| 319 | { |
| 320 | // Install lsa with name1 and name2 |
| 321 | ndn::Name name1("/ndn/name1"); |
| 322 | ndn::Name name2("/ndn/name2"); |
| 323 | |
| 324 | NamePrefixList prefixes; |
| 325 | prefixes.insert(name1); |
| 326 | prefixes.insert(name2); |
| 327 | |
| 328 | std::string otherRouter("/ndn/site/%C1.router/other-router"); |
| 329 | ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max(); |
| 330 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 331 | NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 332 | lsdb.installLsa(std::make_shared<NameLsa>(lsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 333 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 334 | BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter, Lsa::Type::NAME), true); |
| 335 | 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] | 336 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(nameList, prefixes); |
| 338 | //areNamePrefixListsEqual(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 339 | |
| 340 | // Add a prefix: name3 |
| 341 | ndn::Name name3("/ndn/name3"); |
| 342 | prefixes.insert(name3); |
| 343 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 344 | NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 345 | lsdb.installLsa(std::make_shared<NameLsa>(addLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 346 | |
| 347 | // Lsa should include name1, name2, and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 348 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 349 | |
| 350 | // Remove a prefix: name2 |
| 351 | prefixes.remove(name2); |
| 352 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 353 | NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 354 | lsdb.installLsa(std::make_shared<NameLsa>(removeLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 355 | |
| 356 | // Lsa should include name1 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 | // Add and remove a prefix: add name2, remove name3 |
| 360 | prefixes.insert(name2); |
| 361 | prefixes.remove(name3); |
| 362 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 363 | NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 364 | lsdb.installLsa(std::make_shared<NameLsa>(addAndRemoveLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 365 | |
| 366 | // Lsa should include name1 and name2 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 367 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 368 | |
| 369 | // Install a completely new list of prefixes |
| 370 | ndn::Name name4("/ndn/name4"); |
| 371 | ndn::Name name5("/ndn/name5"); |
| 372 | |
| 373 | NamePrefixList newPrefixes; |
| 374 | newPrefixes.insert(name4); |
| 375 | newPrefixes.insert(name5); |
| 376 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 377 | NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 378 | lsdb.installLsa(std::make_shared<NameLsa>(newLsa)); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 379 | |
| 380 | // Lsa should include name4 and name5 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 381 | BOOST_CHECK_EQUAL(nameList, newPrefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 384 | BOOST_AUTO_TEST_CASE(TestIsLsaNew) |
| 385 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 386 | ndn::Name originRouter("/ndn/memphis/%C1.Router/other-router"); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 387 | |
| 388 | // Install Name LSA |
| 389 | NamePrefixList nameList; |
| 390 | NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList); |
| 391 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 392 | lsdb.installLsa(std::make_shared<NameLsa>(lsa)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 393 | |
| 394 | // Lower NameLSA sequence number |
| 395 | uint64_t lowerSeqNo = 998; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 396 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 397 | |
| 398 | // Same NameLSA sequence number |
| 399 | uint64_t sameSeqNo = 999; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 400 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 401 | |
| 402 | // Higher NameLSA sequence number |
| 403 | uint64_t higherSeqNo = 1000; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 404 | BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | BOOST_AUTO_TEST_SUITE_END() // TestLsdb |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 408 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 409 | } // namespace test |
| 410 | } // namespace nlsr |