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