Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 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. |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -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/>. |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 20 | **/ |
| 21 | |
| 22 | #include "test-common.hpp" |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 23 | |
| 24 | #include "nlsr.hpp" |
| 25 | #include "communication/sync-logic-handler.hpp" |
| 26 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 28 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 29 | namespace nlsr { |
| 30 | namespace test { |
| 31 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 32 | using ndn::shared_ptr; |
| 33 | |
| 34 | class SyncLogicFixture : public BaseFixture |
| 35 | { |
| 36 | public: |
| 37 | SyncLogicFixture() |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 38 | : face(make_shared<ndn::util::DummyClientFace>()) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 39 | , nlsr(g_ioService, g_scheduler, ndn::ref(*face)) |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 40 | , sync(nlsr.getSyncLogicHandler()) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 41 | , CONFIG_NETWORK("/ndn") |
| 42 | , CONFIG_SITE("/site") |
| 43 | , CONFIG_ROUTER_NAME("/%C1.Router/this-router") |
| 44 | { |
| 45 | nlsr.getConfParameter().setNetwork(CONFIG_NETWORK); |
| 46 | nlsr.getConfParameter().setSiteName(CONFIG_SITE); |
| 47 | nlsr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME); |
| 48 | nlsr.getConfParameter().buildRouterPrefix(); |
| 49 | } |
| 50 | |
| 51 | void |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 52 | receiveUpdate(std::string prefix, uint64_t seqNo, SyncLogicHandler& p_sync) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 53 | { |
| 54 | Sync::MissingDataInfo info = {prefix, 0, seqNo}; |
| 55 | |
| 56 | std::vector<Sync::MissingDataInfo> updates; |
| 57 | updates.push_back(info); |
| 58 | |
| 59 | face->processEvents(ndn::time::milliseconds(1)); |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 60 | face->sentInterests.clear(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 61 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 62 | p_sync.onNsyncUpdate(updates, NULL); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 63 | |
| 64 | face->processEvents(ndn::time::milliseconds(1)); |
| 65 | } |
| 66 | |
| 67 | public: |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 68 | shared_ptr<ndn::util::DummyClientFace> face; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 69 | Nlsr nlsr; |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 70 | SyncLogicHandler& sync; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 71 | |
| 72 | const std::string CONFIG_NETWORK; |
| 73 | const std::string CONFIG_SITE; |
| 74 | const std::string CONFIG_ROUTER_NAME; |
| 75 | }; |
| 76 | |
| 77 | BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture) |
| 78 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 79 | BOOST_AUTO_TEST_CASE(UpdateForOtherLS) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 80 | { |
| 81 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 82 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 83 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 84 | uint64_t syncSeqNo = 1; |
| 85 | receiveUpdate(updateName, syncSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 86 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 87 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 88 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 89 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 90 | |
| 91 | BOOST_REQUIRE_EQUAL(interests.size(), 2); |
| 92 | |
| 93 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/"); |
| 94 | |
| 95 | ++it; |
| 96 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/"); |
| 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(UpdateForOtherHR) |
| 100 | { |
| 101 | Nlsr nlsr_hr(g_ioService, g_scheduler, ndn::ref(*face)); |
| 102 | SyncLogicHandler& sync_hr(nlsr_hr.getSyncLogicHandler()); |
| 103 | |
| 104 | nlsr_hr.getConfParameter().setNetwork(CONFIG_NETWORK); |
| 105 | nlsr_hr.getConfParameter().setSiteName(CONFIG_SITE); |
| 106 | nlsr_hr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME); |
| 107 | nlsr_hr.getConfParameter().buildRouterPrefix(); |
| 108 | |
| 109 | nlsr_hr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 110 | |
| 111 | nlsr_hr.initialize(); |
| 112 | |
| 113 | std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() + |
| 114 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 115 | |
| 116 | uint64_t syncSeqNo = 0; |
| 117 | syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20); |
| 118 | |
| 119 | receiveUpdate(updateName, syncSeqNo, sync_hr); |
| 120 | |
| 121 | std::vector<ndn::Interest>& interests = face->sentInterests; |
| 122 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 123 | |
| 124 | BOOST_REQUIRE_EQUAL(interests.size(), 2); |
| 125 | |
| 126 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/"); |
| 127 | |
| 128 | ++it; |
| 129 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/"); |
| 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry) |
| 133 | { |
| 134 | |
| 135 | Nlsr nlsr_hrdry(g_ioService, g_scheduler, ndn::ref(*face)); |
| 136 | SyncLogicHandler& sync_hrdry(nlsr_hrdry.getSyncLogicHandler()); |
| 137 | |
| 138 | nlsr_hrdry.getConfParameter().setNetwork(CONFIG_NETWORK); |
| 139 | nlsr_hrdry.getConfParameter().setSiteName(CONFIG_SITE); |
| 140 | nlsr_hrdry.getConfParameter().setRouterName(CONFIG_ROUTER_NAME); |
| 141 | nlsr_hrdry.getConfParameter().buildRouterPrefix(); |
| 142 | |
| 143 | nlsr_hrdry.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN); |
| 144 | |
| 145 | nlsr_hrdry.initialize(); |
| 146 | |
| 147 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 148 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 149 | |
| 150 | |
| 151 | uint64_t syncSeqNo = 1; |
| 152 | syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20); |
| 153 | receiveUpdate(updateName, syncSeqNo, sync_hrdry); |
| 154 | |
| 155 | std::vector<ndn::Interest>& interests = face->sentInterests; |
| 156 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 157 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 158 | BOOST_REQUIRE_EQUAL(interests.size(), 3); |
| 159 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 160 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/"); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 161 | |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 162 | if (nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
| 163 | ++it; |
| 164 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/"); |
| 165 | } |
| 166 | else if (nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) { |
| 167 | ++it; |
| 168 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/"); |
| 169 | } |
| 170 | else { |
| 171 | ++it; |
| 172 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/"); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 173 | |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 174 | ++it; |
| 175 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/"); |
| 176 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | BOOST_AUTO_TEST_CASE(NoUpdateForSelf) |
| 180 | { |
| 181 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 182 | CONFIG_SITE + CONFIG_ROUTER_NAME; |
| 183 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 184 | receiveUpdate(updateName, 1, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 185 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 186 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 188 | } |
| 189 | |
| 190 | BOOST_AUTO_TEST_CASE(MalformedUpdate) |
| 191 | { |
| 192 | std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 193 | CONFIG_ROUTER_NAME; |
| 194 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 195 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 197 | } |
| 198 | |
| 199 | BOOST_AUTO_TEST_CASE(SequenceNumber) |
| 200 | { |
| 201 | std::string originRouter = CONFIG_NETWORK + CONFIG_SITE + "/%C1.Router/other-router/"; |
| 202 | |
| 203 | Lsdb& lsdb = nlsr.getLsdb(); |
| 204 | |
| 205 | // Install Name LSA |
| 206 | NamePrefixList nameList; |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 207 | NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 208 | lsdb.installNameLsa(lsa); |
| 209 | |
| 210 | // Install Adj LSA |
| 211 | AdjacencyList adjList; |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 212 | AdjLsa adjLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(), |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 213 | 3 , adjList); |
| 214 | lsdb.installAdjLsa(adjLsa); |
| 215 | |
| 216 | // Install Cor LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 217 | CoordinateLsa corLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(), |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 218 | 0,0); |
| 219 | lsdb.installCoordinateLsa(corLsa); |
| 220 | |
| 221 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 222 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 223 | |
| 224 | // Lower NameLSA sequence number |
| 225 | uint64_t lowerSeqNo = static_cast<uint64_t>(998) << 40; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 226 | receiveUpdate(updateName, lowerSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 227 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 228 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 229 | BOOST_REQUIRE_EQUAL(interests.size(), 0); |
| 230 | |
| 231 | // Same NameLSA sequence number |
| 232 | uint64_t sameSeqNo = static_cast<uint64_t>(999) << 40; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 233 | receiveUpdate(updateName, sameSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 234 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 235 | interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 236 | BOOST_REQUIRE_EQUAL(interests.size(), 0); |
| 237 | |
| 238 | // Higher NameLSA sequence number |
| 239 | uint64_t higherSeqNo = static_cast<uint64_t>(1000) << 40; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 240 | receiveUpdate(updateName, higherSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 241 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 242 | interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 243 | BOOST_REQUIRE_EQUAL(interests.size(), 1); |
| 244 | |
| 245 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 246 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "name/"); |
| 247 | } |
| 248 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 249 | BOOST_AUTO_TEST_CASE(UpdatePrefix) |
| 250 | { |
| 251 | ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix(); |
| 252 | expectedPrefix.append(CONFIG_SITE); |
| 253 | expectedPrefix.append(CONFIG_ROUTER_NAME); |
| 254 | |
| 255 | nlsr.initialize(); |
| 256 | |
| 257 | BOOST_CHECK_EQUAL(sync.m_updatePrefix, expectedPrefix); |
| 258 | } |
| 259 | |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 260 | BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649 |
| 261 | { |
| 262 | nlsr.initialize(); |
| 263 | |
| 264 | // Make sure an adjacency LSA has not been built yet |
| 265 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 266 | AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key); |
| 267 | BOOST_REQUIRE(lsa == nullptr); |
| 268 | |
| 269 | // Publish a routing update before an Adjacency LSA is built |
| 270 | BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate()); |
| 271 | } |
| 272 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 273 | BOOST_AUTO_TEST_SUITE_END() |
| 274 | |
| 275 | } // namespace test |
| 276 | } // namespace nlsr |