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