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 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 22 | #include "communication/sync-logic-handler.hpp" |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 23 | #include "test-common.hpp" |
| 24 | #include "common.hpp" |
| 25 | #include "nlsr.hpp" |
| 26 | #include "logger.hpp" |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 27 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 29 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 33 | using std::shared_ptr; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 34 | |
| 35 | class SyncLogicFixture : public BaseFixture |
| 36 | { |
| 37 | public: |
| 38 | SyncLogicFixture() |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 39 | : face(std::make_shared<ndn::util::DummyClientFace>()) |
| 40 | , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain) |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 41 | , testIsLsaNew([] (const ndn::Name& name, const std::string& lsaType, |
| 42 | const uint64_t sequenceNumber) { |
| 43 | return true; |
| 44 | }) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 45 | , CONFIG_NETWORK("/ndn") |
| 46 | , CONFIG_SITE("/site") |
| 47 | , CONFIG_ROUTER_NAME("/%C1.Router/this-router") |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 48 | , OTHER_ROUTER_NAME("/%C1.Router/other-router/") |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 49 | { |
| 50 | nlsr.getConfParameter().setNetwork(CONFIG_NETWORK); |
| 51 | nlsr.getConfParameter().setSiteName(CONFIG_SITE); |
| 52 | nlsr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME); |
| 53 | nlsr.getConfParameter().buildRouterPrefix(); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 54 | |
| 55 | conf.setNetwork(CONFIG_NETWORK); |
| 56 | conf.setSiteName(CONFIG_SITE); |
| 57 | conf.setRouterName(CONFIG_ROUTER_NAME); |
| 58 | conf.buildRouterPrefix(); |
| 59 | INIT_LOGGERS("/tmp", "TRACE"); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 63 | receiveUpdate(std::string prefix, uint64_t seqNo, SyncLogicHandler& p_sync) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 64 | { |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 65 | chronosync::MissingDataInfo info = {ndn::Name(prefix).appendNumber(1), 0, seqNo}; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 66 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 67 | std::vector<chronosync::MissingDataInfo> updates; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 68 | updates.push_back(info); |
| 69 | |
| 70 | face->processEvents(ndn::time::milliseconds(1)); |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 71 | face->sentInterests.clear(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 72 | |
Ashlesh Gawande | 7600c90 | 2017-06-21 13:28:35 -0500 | [diff] [blame] | 73 | p_sync.onChronoSyncUpdate(updates); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 74 | |
| 75 | face->processEvents(ndn::time::milliseconds(1)); |
| 76 | } |
| 77 | |
| 78 | public: |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 79 | std::shared_ptr<ndn::util::DummyClientFace> face; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 80 | Nlsr nlsr; |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 81 | ConfParameter conf; |
| 82 | IsLsaNew testIsLsaNew; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 83 | |
| 84 | const std::string CONFIG_NETWORK; |
| 85 | const std::string CONFIG_SITE; |
| 86 | const std::string CONFIG_ROUTER_NAME; |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 87 | const std::string OTHER_ROUTER_NAME; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 88 | const std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING, |
| 89 | CoordinateLsa::TYPE_STRING}; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture) |
| 93 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 94 | /* Tests that when SyncLogicHandler receives an LSA of either Name or |
| 95 | Adjacency type that appears to be newer, it will emit to its signal |
| 96 | with those LSA details. |
| 97 | */ |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 98 | BOOST_AUTO_TEST_CASE(UpdateForOtherLS) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 99 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 100 | SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf}; |
| 101 | sync.createSyncSocket(conf.getChronosyncPrefix()); |
| 102 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 103 | std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING}; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 104 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 105 | uint64_t syncSeqNo = 1; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 106 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 107 | for (const std::string& lsaType : lsaTypes) { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 108 | std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE |
| 109 | + OTHER_ROUTER_NAME + lsaType; |
| 110 | |
| 111 | // Actual testing done here -- signal function callback |
| 112 | ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect( |
| 113 | [&, this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) { |
| 114 | BOOST_CHECK_EQUAL(ndn::Name{updateName}, routerName); |
| 115 | BOOST_CHECK_EQUAL(sequenceNumber, syncSeqNo); |
| 116 | }); |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 117 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 118 | receiveUpdate(updateName, syncSeqNo, sync); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 119 | } |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 122 | /* Tests that when SyncLogicHandler in HR mode receives an LSA of |
| 123 | either Coordinate or Name type that appears to be newer, it will |
| 124 | emit to its signal with those LSA details. |
| 125 | */ |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 126 | BOOST_AUTO_TEST_CASE(UpdateForOtherHR) |
| 127 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 128 | conf.setHyperbolicState(HYPERBOLIC_STATE_ON); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 129 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 130 | SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf}; |
| 131 | sync.createSyncSocket(conf.getChronosyncPrefix()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 132 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 133 | uint64_t syncSeqNo = 1; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 134 | std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, CoordinateLsa::TYPE_STRING}; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 135 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 136 | for (const std::string& lsaType : lsaTypes) { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 137 | std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE |
| 138 | + OTHER_ROUTER_NAME + lsaType; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 139 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 140 | ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect( |
| 141 | [& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) { |
| 142 | BOOST_CHECK_EQUAL(ndn::Name{updateName}, routerName); |
| 143 | BOOST_CHECK_EQUAL(sequenceNumber, syncSeqNo); |
| 144 | }); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 145 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 146 | receiveUpdate(updateName, syncSeqNo, sync); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 147 | } |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 148 | } |
| 149 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 150 | /* Tests that when SyncLogicHandler in HR-dry mode receives an LSA of |
| 151 | any type that appears to be newer, it will emit to its signal with |
| 152 | those LSA details. |
| 153 | */ |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 154 | BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry) |
| 155 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 156 | conf.setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 157 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 158 | SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf}; |
| 159 | sync.createSyncSocket(conf.getChronosyncPrefix()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 160 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 161 | for (const std::string& lsaType : lsaTypes) { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 162 | uint64_t syncSeqNo = 1; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 163 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 164 | std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE |
| 165 | + OTHER_ROUTER_NAME + lsaType; |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 166 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 167 | ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect( |
| 168 | [& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) { |
| 169 | BOOST_CHECK_EQUAL(ndn::Name{updateName}, routerName); |
| 170 | BOOST_CHECK_EQUAL(sequenceNumber, syncSeqNo); |
| 171 | }); |
| 172 | |
| 173 | receiveUpdate(updateName, syncSeqNo, sync); |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 174 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 175 | } |
| 176 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 177 | /* Tests that when SyncLogicHandler receives an update for an LSA with |
| 178 | details matching this router's details, it will *not* emit to its |
| 179 | signal those LSA details. |
| 180 | */ |
Nick Gordon | 0f1bf1d | 2017-06-22 15:40:27 -0500 | [diff] [blame] | 181 | BOOST_AUTO_TEST_CASE(NoUpdateForSelf) |
| 182 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 183 | const uint64_t sequenceNumber = 1; |
| 184 | |
| 185 | SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf}; |
| 186 | sync.createSyncSocket(conf.getChronosyncPrefix()); |
| 187 | |
Nick Gordon | 0f1bf1d | 2017-06-22 15:40:27 -0500 | [diff] [blame] | 188 | for (const std::string& lsaType : lsaTypes) { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 189 | // To ensure that we get correctly-separated components, create |
| 190 | // and modify a Name to hand off. |
| 191 | ndn::Name updateName = ndn::Name{conf.getLsaPrefix()}; |
| 192 | updateName.append(CONFIG_SITE).append(CONFIG_ROUTER_NAME).append(lsaType); |
Nick Gordon | 0f1bf1d | 2017-06-22 15:40:27 -0500 | [diff] [blame] | 193 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 194 | ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect( |
| 195 | [& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) { |
| 196 | BOOST_FAIL("Updates for self should not be emitted!"); |
| 197 | }); |
Nick Gordon | 0f1bf1d | 2017-06-22 15:40:27 -0500 | [diff] [blame] | 198 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 199 | receiveUpdate(updateName.toUri(), sequenceNumber, sync); |
Nick Gordon | 0f1bf1d | 2017-06-22 15:40:27 -0500 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 203 | /* Tests that when SyncLogicHandler receives an update for an LSA with |
| 204 | details that do not match the expected format, it will *not* emit |
| 205 | to its signal those LSA details. |
| 206 | */ |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 207 | BOOST_AUTO_TEST_CASE(MalformedUpdate) |
| 208 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 209 | const uint64_t sequenceNumber = 1; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 210 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 211 | SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf}; |
| 212 | sync.createSyncSocket(conf.getChronosyncPrefix()); |
| 213 | |
| 214 | for (const std::string& lsaType : lsaTypes) { |
| 215 | ndn::Name updateName{CONFIG_SITE}; |
| 216 | updateName.append(CONFIG_ROUTER_NAME).append(lsaType); |
| 217 | |
| 218 | ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect( |
| 219 | [& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) { |
| 220 | BOOST_FAIL("Malformed updates should not be emitted!"); |
| 221 | }); |
| 222 | |
| 223 | receiveUpdate(updateName.toUri(), sequenceNumber, sync); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 224 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 225 | } |
| 226 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 227 | /* Tests that when SyncLogicHandler receives an update for an LSA with |
| 228 | details that do not appear to be new, it will *not* emit to its |
| 229 | signal those LSA details. |
| 230 | */ |
| 231 | BOOST_AUTO_TEST_CASE(LsaNotNew) |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 232 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 233 | auto testLsaAlwaysFalse = [] (const ndn::Name& routerName, const std::string& lsaType, |
| 234 | const uint64_t& sequenceNumber) { |
| 235 | return false; |
| 236 | }; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 237 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 238 | const uint64_t sequenceNumber = 1; |
| 239 | SyncLogicHandler sync{std::ref(*face), testLsaAlwaysFalse, conf}; |
| 240 | sync.createSyncSocket(conf.getChronosyncPrefix()); |
| 241 | ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect( |
| 242 | [& ,this] (const ndn::Name& routerName, const uint64_t& sequenceNumber) { |
| 243 | BOOST_FAIL("An update for an LSA with non-new sequence number should not emit!"); |
| 244 | }); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 245 | |
| 246 | std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() + |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 247 | CONFIG_SITE + "/%C1.Router/other-router/" + NameLsa::TYPE_STRING; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 248 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 249 | receiveUpdate(updateName, sequenceNumber, sync); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 250 | } |
| 251 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 252 | /* Tests that SyncLogicHandler successfully concatenates configured |
| 253 | variables together to form the necessary prefixes to advertise |
| 254 | through ChronoSync. |
| 255 | */ |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 256 | BOOST_AUTO_TEST_CASE(UpdatePrefix) |
| 257 | { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 258 | |
| 259 | SyncLogicHandler sync{std::ref(*face), testIsLsaNew, conf}; |
| 260 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 261 | ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix(); |
| 262 | expectedPrefix.append(CONFIG_SITE); |
| 263 | expectedPrefix.append(CONFIG_ROUTER_NAME); |
| 264 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 265 | sync.buildUpdatePrefix(); |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 266 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 267 | BOOST_CHECK_EQUAL(sync.m_nameLsaUserPrefix, |
| 268 | ndn::Name(expectedPrefix).append(NameLsa::TYPE_STRING)); |
| 269 | BOOST_CHECK_EQUAL(sync.m_adjLsaUserPrefix, |
| 270 | ndn::Name(expectedPrefix).append(AdjLsa::TYPE_STRING)); |
| 271 | BOOST_CHECK_EQUAL(sync.m_coorLsaUserPrefix, |
| 272 | ndn::Name(expectedPrefix).append(CoordinateLsa::TYPE_STRING)); |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 273 | } |
| 274 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 275 | /* Tests that SyncLogicHandler's socket will be created when |
| 276 | Nlsr::initialize is called, preventing use of sync before the |
| 277 | socket is created. |
| 278 | |
| 279 | NB: This test is as much an Nlsr class test as a SyncLogicHandler |
| 280 | class test, but it rides the line and ends up here. |
| 281 | */ |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 282 | BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649 |
| 283 | { |
| 284 | nlsr.initialize(); |
| 285 | |
| 286 | // Make sure an adjacency LSA has not been built yet |
| 287 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 288 | AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key); |
| 289 | BOOST_REQUIRE(lsa == nullptr); |
| 290 | |
| 291 | // Publish a routing update before an Adjacency LSA is built |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 292 | BOOST_CHECK_NO_THROW(nlsr.getLsdb().getSyncLogicHandler() |
| 293 | .publishRoutingUpdate(AdjLsa::TYPE_STRING, 0)); |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 296 | BOOST_AUTO_TEST_SUITE_END() |
| 297 | |
| 298 | } // namespace test |
| 299 | } // namespace nlsr |