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