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