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