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