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