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 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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" |
Nick Gordon | 098aae4 | 2017-08-23 15:18:46 -0500 | [diff] [blame] | 23 | #include "test-common.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 24 | #include "nlsr.hpp" |
| 25 | #include "lsa.hpp" |
| 26 | #include "name-prefix-list.hpp" |
| 27 | #include <boost/test/unit_test.hpp> |
| 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 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | namespace test { |
| 34 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 35 | using std::shared_ptr; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 36 | |
| 37 | class LsdbFixture : public BaseFixture |
| 38 | { |
| 39 | public: |
| 40 | LsdbFixture() |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 41 | : face(std::make_shared<ndn::util::DummyClientFace>(g_ioService)) |
| 42 | , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain) |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 43 | , lsdb(nlsr.getLsdb()) |
| 44 | , conf(nlsr.getConfParameter()) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 45 | , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib") |
| 46 | , REGISTER_VERB("register") |
| 47 | { |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 48 | conf.setNetwork("/ndn"); |
| 49 | conf.setSiteName("/site"); |
| 50 | conf.setRouterName("/%C1.router/this-router"); |
| 51 | |
| 52 | nlsr.initialize(); |
| 53 | |
| 54 | face->processEvents(ndn::time::milliseconds(1)); |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 55 | face->sentInterests.clear(); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 56 | |
| 57 | INIT_LOGGERS("/tmp", "DEBUG"); |
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: |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 92 | std::shared_ptr<ndn::util::DummyClientFace> face; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 93 | Nlsr nlsr; |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 94 | Lsdb& lsdb; |
| 95 | ConfParameter& conf; |
| 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); |
| 112 | face->processEvents(ndn::time::milliseconds(1)); |
| 113 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [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 | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 132 | face->processEvents(ndn::time::milliseconds(1)); |
| 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); |
| 150 | face->processEvents(ndn::time::milliseconds(1)); |
| 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 | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 166 | face->processEvents(ndn::time::milliseconds(1)); |
| 167 | |
| 168 | // Interest should not be expressed for outdated sequence number |
| 169 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 170 | } |
| 171 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 172 | BOOST_AUTO_TEST_CASE(SegmentLsaData) |
| 173 | { |
| 174 | ndn::Name router("/ndn/cs/%C1.Router/router1"); |
| 175 | uint64_t seqNo = 12; |
| 176 | NamePrefixList prefixList; |
| 177 | |
| 178 | NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList); |
| 179 | |
| 180 | ndn::Name prefix("/ndn/edu/memphis/netlab/research/nlsr/test/prefix/"); |
| 181 | |
| 182 | int nPrefixes = 0; |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 183 | while (lsa.serialize().size() < ndn::MAX_NDN_PACKET_SIZE) { |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 184 | lsa.addName(ndn::Name(prefix).appendNumber(++nPrefixes)); |
| 185 | } |
| 186 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 187 | std::string expectedDataContent = lsa.serialize(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 188 | lsdb.installNameLsa(lsa); |
| 189 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 190 | ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 191 | interestName.appendNumber(seqNo); |
| 192 | |
| 193 | ndn::Interest interest(interestName); |
| 194 | |
| 195 | lsdb.processInterest(ndn::Name(), interest); |
| 196 | face->processEvents(ndn::time::milliseconds(1)); |
| 197 | |
| 198 | std::vector<ndn::Data> data = face->sentData; |
| 199 | std::string recvDataContent; |
| 200 | for (unsigned int i = 0; i < data.size(); ++i) |
| 201 | { |
| 202 | const ndn::Block& nameBlock = data[i].getContent(); |
| 203 | |
| 204 | std::string nameBlockContent(reinterpret_cast<char const*>(nameBlock.value()), |
| 205 | nameBlock.value_size()); |
| 206 | recvDataContent += nameBlockContent; |
| 207 | } |
| 208 | |
| 209 | BOOST_CHECK_EQUAL(expectedDataContent, recvDataContent); |
| 210 | } |
| 211 | |
| 212 | BOOST_AUTO_TEST_CASE(ReceiveSegmentedLsaData) |
| 213 | { |
| 214 | ndn::Name router("/ndn/cs/%C1.Router/router1"); |
| 215 | uint64_t seqNo = 12; |
| 216 | NamePrefixList prefixList; |
| 217 | |
| 218 | NameLsa lsa(router, seqNo, ndn::time::system_clock::now(), prefixList); |
| 219 | |
| 220 | ndn::Name prefix("/prefix/"); |
| 221 | |
| 222 | for (int nPrefixes = 0; nPrefixes < 3; ++nPrefixes) { |
| 223 | lsa.addName(ndn::Name(prefix).appendNumber(nPrefixes)); |
| 224 | } |
| 225 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 226 | ndn::Name interestName("/ndn/NLSR/LSA/cs/%C1.Router/router1/NAME/"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 227 | interestName.appendNumber(seqNo); |
| 228 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 229 | const ndn::ConstBufferPtr bufferPtr = std::make_shared<ndn::Buffer>(lsa.serialize().c_str(), |
| 230 | lsa.serialize().size()); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 231 | lsdb.afterFetchLsa(bufferPtr, interestName); |
| 232 | |
| 233 | NameLsa* foundLsa = lsdb.findNameLsa(lsa.getKey()); |
| 234 | BOOST_REQUIRE(foundLsa != nullptr); |
| 235 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(foundLsa->serialize(), lsa.serialize()); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 239 | BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists) |
| 240 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 241 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 242 | NamePrefixList npl1; |
| 243 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 244 | std::string s1 = "name1"; |
| 245 | std::string s2 = "name2"; |
| 246 | std::string router1 = "router1/1"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 247 | |
| 248 | npl1.insert(s1); |
| 249 | npl1.insert(s2); |
| 250 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 251 | //For NameLsa lsType is name. |
| 252 | //12 is seqNo, randomly generated. |
| 253 | //1800 is the default life time. |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 254 | NameLsa nlsa1(ndn::Name("/router1/1"), 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 255 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 256 | Lsdb lsdb1(nlsr, g_scheduler); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 257 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 258 | lsdb1.installNameLsa(nlsa1); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 259 | lsdb1.writeNameLsdbLog(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 260 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 261 | BOOST_CHECK(lsdb1.doesLsaExist(ndn::Name("/router1/1/NAME"), Lsa::Type::NAME)); |
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.removeNameLsa(router1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 264 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 265 | 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] | 266 | } |
| 267 | |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 268 | BOOST_AUTO_TEST_CASE(InstallNameLsa) |
| 269 | { |
| 270 | // Install lsa with name1 and name2 |
| 271 | ndn::Name name1("/ndn/name1"); |
| 272 | ndn::Name name2("/ndn/name2"); |
| 273 | |
| 274 | NamePrefixList prefixes; |
| 275 | prefixes.insert(name1); |
| 276 | prefixes.insert(name2); |
| 277 | |
| 278 | std::string otherRouter("/ndn/site/%C1.router/other-router"); |
| 279 | ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max(); |
| 280 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 281 | NameLsa lsa(otherRouter, 1, MAX_TIME, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 282 | lsdb.installNameLsa(lsa); |
| 283 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 284 | BOOST_REQUIRE_EQUAL(lsdb.doesLsaExist(otherRouter + "/NAME", Lsa::Type::NAME), true); |
| 285 | NamePrefixList& nameList = lsdb.findNameLsa(otherRouter + "/NAME")->getNpl(); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 286 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 287 | BOOST_CHECK_EQUAL(nameList, prefixes); |
| 288 | //areNamePrefixListsEqual(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 289 | |
| 290 | // Add a prefix: name3 |
| 291 | ndn::Name name3("/ndn/name3"); |
| 292 | prefixes.insert(name3); |
| 293 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 294 | NameLsa addLsa(otherRouter, 2, MAX_TIME, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 295 | lsdb.installNameLsa(addLsa); |
| 296 | |
| 297 | // Lsa should include name1, name2, and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 299 | |
| 300 | // Remove a prefix: name2 |
| 301 | prefixes.remove(name2); |
| 302 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 303 | NameLsa removeLsa(otherRouter, 3, MAX_TIME, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 304 | lsdb.installNameLsa(removeLsa); |
| 305 | |
| 306 | // Lsa should include name1 and name3 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 307 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 308 | |
| 309 | // Add and remove a prefix: add name2, remove name3 |
| 310 | prefixes.insert(name2); |
| 311 | prefixes.remove(name3); |
| 312 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 313 | NameLsa addAndRemoveLsa(otherRouter, 4, MAX_TIME, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 314 | lsdb.installNameLsa(addAndRemoveLsa); |
| 315 | |
| 316 | // Lsa should include name1 and name2 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 317 | BOOST_CHECK_EQUAL(nameList, prefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 318 | |
| 319 | // Install a completely new list of prefixes |
| 320 | ndn::Name name4("/ndn/name4"); |
| 321 | ndn::Name name5("/ndn/name5"); |
| 322 | |
| 323 | NamePrefixList newPrefixes; |
| 324 | newPrefixes.insert(name4); |
| 325 | newPrefixes.insert(name5); |
| 326 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 327 | NameLsa newLsa(otherRouter, 5, MAX_TIME, newPrefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 328 | lsdb.installNameLsa(newLsa); |
| 329 | |
| 330 | // Lsa should include name4 and name5 |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 331 | BOOST_CHECK_EQUAL(nameList, newPrefixes); |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 332 | } |
| 333 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 334 | BOOST_AUTO_TEST_CASE(TestIsLsaNew) |
| 335 | { |
| 336 | const ndn::Name::Component CONFIG_NETWORK{"/ndn"}; |
| 337 | const ndn::Name::Component CONFIG_SITE{"/memphis"}; |
| 338 | ndn::Name originRouter{}; |
| 339 | originRouter.append(CONFIG_NETWORK).append(CONFIG_SITE).append("/%C1.Router/other-router"); |
| 340 | |
| 341 | // Install Name LSA |
| 342 | NamePrefixList nameList; |
| 343 | NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList); |
| 344 | |
| 345 | lsdb.installNameLsa(lsa); |
| 346 | |
| 347 | // Lower NameLSA sequence number |
| 348 | uint64_t lowerSeqNo = 998; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 349 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, lowerSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 350 | |
| 351 | // Same NameLSA sequence number |
| 352 | uint64_t sameSeqNo = 999; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 353 | BOOST_CHECK(!lsdb.isLsaNew(originRouter, Lsa::Type::NAME, sameSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 354 | |
| 355 | // Higher NameLSA sequence number |
| 356 | uint64_t higherSeqNo = 1000; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 357 | BOOST_CHECK(lsdb.isLsaNew(originRouter, Lsa::Type::NAME, higherSeqNo)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | BOOST_AUTO_TEST_SUITE_END() // TestLsdb |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 361 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 362 | } // namespace test |
| 363 | } // namespace nlsr |