Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 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 | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 88 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 89 | |
| 90 | BOOST_REQUIRE_EQUAL(interests.size(), 2); |
| 91 | |
| 92 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/"); |
| 93 | |
| 94 | ++it; |
| 95 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/"); |
| 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_CASE(UpdateForOtherHR) |
| 99 | { |
| 100 | Nlsr nlsr_hr(g_ioService, g_scheduler, ndn::ref(*face)); |
| 101 | SyncLogicHandler& sync_hr(nlsr_hr.getSyncLogicHandler()); |
| 102 | |
| 103 | nlsr_hr.getConfParameter().setNetwork(CONFIG_NETWORK); |
| 104 | nlsr_hr.getConfParameter().setSiteName(CONFIG_SITE); |
| 105 | nlsr_hr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME); |
| 106 | nlsr_hr.getConfParameter().buildRouterPrefix(); |
| 107 | |
| 108 | nlsr_hr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 109 | |
| 110 | nlsr_hr.initialize(); |
| 111 | |
| 112 | std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() + |
| 113 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 114 | |
| 115 | uint64_t syncSeqNo = 0; |
| 116 | syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20); |
| 117 | |
| 118 | receiveUpdate(updateName, syncSeqNo, sync_hr); |
| 119 | |
| 120 | std::vector<ndn::Interest>& interests = face->sentInterests; |
| 121 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 122 | |
| 123 | BOOST_REQUIRE_EQUAL(interests.size(), 2); |
| 124 | |
| 125 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/"); |
| 126 | |
| 127 | ++it; |
| 128 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/"); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry) |
| 132 | { |
| 133 | |
| 134 | Nlsr nlsr_hrdry(g_ioService, g_scheduler, ndn::ref(*face)); |
| 135 | SyncLogicHandler& sync_hrdry(nlsr_hrdry.getSyncLogicHandler()); |
| 136 | |
| 137 | nlsr_hrdry.getConfParameter().setNetwork(CONFIG_NETWORK); |
| 138 | nlsr_hrdry.getConfParameter().setSiteName(CONFIG_SITE); |
| 139 | nlsr_hrdry.getConfParameter().setRouterName(CONFIG_ROUTER_NAME); |
| 140 | nlsr_hrdry.getConfParameter().buildRouterPrefix(); |
| 141 | |
| 142 | nlsr_hrdry.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN); |
| 143 | |
| 144 | nlsr_hrdry.initialize(); |
| 145 | |
| 146 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 147 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 148 | |
| 149 | |
| 150 | uint64_t syncSeqNo = 1; |
| 151 | syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20); |
| 152 | receiveUpdate(updateName, syncSeqNo, sync_hrdry); |
| 153 | |
| 154 | std::vector<ndn::Interest>& interests = face->sentInterests; |
| 155 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 156 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 157 | BOOST_REQUIRE_EQUAL(interests.size(), 3); |
| 158 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 159 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/"); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 160 | |
| 161 | ++it; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 162 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/"); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 163 | |
| 164 | ++it; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 165 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/"); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 166 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | BOOST_AUTO_TEST_CASE(NoUpdateForSelf) |
| 170 | { |
| 171 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 172 | CONFIG_SITE + CONFIG_ROUTER_NAME; |
| 173 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 174 | receiveUpdate(updateName, 1, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 175 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 176 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 178 | } |
| 179 | |
| 180 | BOOST_AUTO_TEST_CASE(MalformedUpdate) |
| 181 | { |
| 182 | std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 183 | CONFIG_ROUTER_NAME; |
| 184 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 185 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 186 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 187 | } |
| 188 | |
| 189 | BOOST_AUTO_TEST_CASE(SequenceNumber) |
| 190 | { |
| 191 | std::string originRouter = CONFIG_NETWORK + CONFIG_SITE + "/%C1.Router/other-router/"; |
| 192 | |
| 193 | Lsdb& lsdb = nlsr.getLsdb(); |
| 194 | |
| 195 | // Install Name LSA |
| 196 | NamePrefixList nameList; |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 197 | NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 198 | lsdb.installNameLsa(lsa); |
| 199 | |
| 200 | // Install Adj LSA |
| 201 | AdjacencyList adjList; |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 202 | AdjLsa adjLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(), |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 203 | 3 , adjList); |
| 204 | lsdb.installAdjLsa(adjLsa); |
| 205 | |
| 206 | // Install Cor LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 207 | CoordinateLsa corLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(), |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 208 | 0,0); |
| 209 | lsdb.installCoordinateLsa(corLsa); |
| 210 | |
| 211 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
| 212 | CONFIG_SITE + "/%C1.Router/other-router/"; |
| 213 | |
| 214 | // Lower NameLSA sequence number |
| 215 | uint64_t lowerSeqNo = static_cast<uint64_t>(998) << 40; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 216 | receiveUpdate(updateName, lowerSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 217 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 218 | std::vector<ndn::Interest>& interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 219 | BOOST_REQUIRE_EQUAL(interests.size(), 0); |
| 220 | |
| 221 | // Same NameLSA sequence number |
| 222 | uint64_t sameSeqNo = static_cast<uint64_t>(999) << 40; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 223 | receiveUpdate(updateName, sameSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 224 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 225 | interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 226 | BOOST_REQUIRE_EQUAL(interests.size(), 0); |
| 227 | |
| 228 | // Higher NameLSA sequence number |
| 229 | uint64_t higherSeqNo = static_cast<uint64_t>(1000) << 40; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 230 | receiveUpdate(updateName, higherSeqNo, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 231 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 232 | interests = face->sentInterests; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 233 | BOOST_REQUIRE_EQUAL(interests.size(), 1); |
| 234 | |
| 235 | std::vector<ndn::Interest>::iterator it = interests.begin(); |
| 236 | BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "name/"); |
| 237 | } |
| 238 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 239 | BOOST_AUTO_TEST_CASE(UpdatePrefix) |
| 240 | { |
| 241 | ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix(); |
| 242 | expectedPrefix.append(CONFIG_SITE); |
| 243 | expectedPrefix.append(CONFIG_ROUTER_NAME); |
| 244 | |
| 245 | nlsr.initialize(); |
| 246 | |
| 247 | BOOST_CHECK_EQUAL(sync.m_updatePrefix, expectedPrefix); |
| 248 | } |
| 249 | |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 250 | BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649 |
| 251 | { |
| 252 | nlsr.initialize(); |
| 253 | |
| 254 | // Make sure an adjacency LSA has not been built yet |
| 255 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 256 | AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key); |
| 257 | BOOST_REQUIRE(lsa == nullptr); |
| 258 | |
| 259 | // Publish a routing update before an Adjacency LSA is built |
| 260 | BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate()); |
| 261 | } |
| 262 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 263 | BOOST_AUTO_TEST_SUITE_END() |
| 264 | |
| 265 | } // namespace test |
| 266 | } // namespace nlsr |