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