blob: 021743cc16f4ca16c9aa7e04818cd3fb776df34a [file] [log] [blame]
Vince Lehman904c2412014-09-23 19:36:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
dmcoomescf8d0ed2017-02-21 11:39:01 -06003 * Copyright (c) 2014-2018, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
Vince Lehman904c2412014-09-23 19:36:11 -05006 *
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 Lehman904c2412014-09-23 19:36:11 -050020 **/
21
Vince Lehman904c2412014-09-23 19:36:11 -050022#include "communication/sync-logic-handler.hpp"
Nick Gordon8f23b5d2017-08-31 17:53:07 -050023#include "test-common.hpp"
24#include "common.hpp"
25#include "nlsr.hpp"
Nick Gordon727d4832017-10-13 18:04:25 -050026#include "lsa.hpp"
Vince Lehman904c2412014-09-23 19:36:11 -050027
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060028#include <ndn-cxx/util/dummy-client-face.hpp>
29
Vince Lehman904c2412014-09-23 19:36:11 -050030namespace nlsr {
31namespace test {
32
dmcoomes9f936662017-03-02 10:33:09 -060033using std::shared_ptr;
Vince Lehman904c2412014-09-23 19:36:11 -050034
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050035class SyncLogicFixture : public UnitTestTimeFixture
Vince Lehman904c2412014-09-23 19:36:11 -050036{
37public:
38 SyncLogicFixture()
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050039 : face(m_ioService, m_keyChain)
40 , nlsr(m_ioService, m_scheduler, face, m_keyChain)
Nick Gordon727d4832017-10-13 18:04:25 -050041 , testIsLsaNew([] (const ndn::Name& name, const Lsa::Type& lsaType,
Nick Gordon8f23b5d2017-08-31 17:53:07 -050042 const uint64_t sequenceNumber) {
43 return true;
44 })
Vince Lehman904c2412014-09-23 19:36:11 -050045 , CONFIG_NETWORK("/ndn")
46 , CONFIG_SITE("/site")
47 , CONFIG_ROUTER_NAME("/%C1.Router/this-router")
Nick Gordon8f23b5d2017-08-31 17:53:07 -050048 , OTHER_ROUTER_NAME("/%C1.Router/other-router/")
Vince Lehman904c2412014-09-23 19:36:11 -050049 {
50 nlsr.getConfParameter().setNetwork(CONFIG_NETWORK);
51 nlsr.getConfParameter().setSiteName(CONFIG_SITE);
52 nlsr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
53 nlsr.getConfParameter().buildRouterPrefix();
Nick Gordon8f23b5d2017-08-31 17:53:07 -050054
55 conf.setNetwork(CONFIG_NETWORK);
56 conf.setSiteName(CONFIG_SITE);
57 conf.setRouterName(CONFIG_ROUTER_NAME);
58 conf.buildRouterPrefix();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050059
60 addIdentity(conf.getRouterPrefix());
Vince Lehman904c2412014-09-23 19:36:11 -050061 }
62
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050063 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 Lehman904c2412014-09-23 19:36:11 -050072 void
Nick Gordon5c467f02016-07-13 13:40:10 -050073 receiveUpdate(std::string prefix, uint64_t seqNo, SyncLogicHandler& p_sync)
Vince Lehman904c2412014-09-23 19:36:11 -050074 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050075 this->advanceClocks(ndn::time::milliseconds(1), 10);
76 face.sentInterests.clear();
Vince Lehman904c2412014-09-23 19:36:11 -050077
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050078 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 Lehman904c2412014-09-23 19:36:11 -050088
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050089 this->advanceClocks(ndn::time::milliseconds(1), 10);
Vince Lehman904c2412014-09-23 19:36:11 -050090 }
91
92public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050093 ndn::util::DummyClientFace face;
Vince Lehman904c2412014-09-23 19:36:11 -050094 Nlsr nlsr;
Nick Gordon8f23b5d2017-08-31 17:53:07 -050095 ConfParameter conf;
Nick Gordon727d4832017-10-13 18:04:25 -050096 SyncLogicHandler::IsLsaNew testIsLsaNew;
Vince Lehman904c2412014-09-23 19:36:11 -050097
98 const std::string CONFIG_NETWORK;
99 const std::string CONFIG_SITE;
100 const std::string CONFIG_ROUTER_NAME;
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500101 const std::string OTHER_ROUTER_NAME;
Nick Gordon727d4832017-10-13 18:04:25 -0500102 const std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::ADJACENCY,
103 Lsa::Type::COORDINATE};
Vince Lehman904c2412014-09-23 19:36:11 -0500104};
105
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500106using boost::mpl::int_;
107using Protocols = boost::mpl::vector<int_<SYNC_PROTOCOL_CHRONOSYNC>, int_<SYNC_PROTOCOL_PSYNC>>;
108
Vince Lehman904c2412014-09-23 19:36:11 -0500109BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
110
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500111/* 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 Gawande32ec3fd2018-07-18 13:42:32 -0500115BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateForOtherLS, SyncProtocol, Protocols)
Vince Lehman904c2412014-09-23 19:36:11 -0500116{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500117 setSyncProtocol<SyncProtocol::value>();
118
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500119 SyncLogicHandler sync{face, testIsLsaNew, conf};
Ashlesh Gawande48101072018-05-30 17:53:06 -0500120 sync.createSyncLogic(conf.getChronosyncPrefix());
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500121
Nick Gordon727d4832017-10-13 18:04:25 -0500122 std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::ADJACENCY};
Vince Lehman904c2412014-09-23 19:36:11 -0500123
Nick Gordon5c467f02016-07-13 13:40:10 -0500124 uint64_t syncSeqNo = 1;
Vince Lehman904c2412014-09-23 19:36:11 -0500125
Nick Gordon727d4832017-10-13 18:04:25 -0500126 for (const Lsa::Type& lsaType : lsaTypes) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500127 std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE
Nick Gordon727d4832017-10-13 18:04:25 -0500128 + OTHER_ROUTER_NAME + std::to_string(lsaType);
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500129
130 // Actual testing done here -- signal function callback
131 ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
Ashlesh Gawandee6ba9152018-03-30 01:15:00 -0500132 [&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500133 BOOST_CHECK_EQUAL(ndn::Name{updateName}, routerName);
134 BOOST_CHECK_EQUAL(sequenceNumber, syncSeqNo);
135 });
Nick Gordone8e03ac2016-07-07 14:24:38 -0500136
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500137 receiveUpdate<SyncProtocol::value>(updateName, syncSeqNo, sync);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500138 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500139}
140
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500141/* 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 Gawande32ec3fd2018-07-18 13:42:32 -0500145BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateForOtherHR, SyncProtocol, Protocols)
Nick Gordon5c467f02016-07-13 13:40:10 -0500146{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500147 setSyncProtocol<SyncProtocol::value>();
148
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500149 conf.setHyperbolicState(HYPERBOLIC_STATE_ON);
Nick Gordon5c467f02016-07-13 13:40:10 -0500150
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500151 SyncLogicHandler sync{face, testIsLsaNew, conf};
Ashlesh Gawande48101072018-05-30 17:53:06 -0500152 sync.createSyncLogic(conf.getChronosyncPrefix());
Nick Gordon5c467f02016-07-13 13:40:10 -0500153
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500154 uint64_t syncSeqNo = 1;
Nick Gordon727d4832017-10-13 18:04:25 -0500155 std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::COORDINATE};
Nick Gordon5c467f02016-07-13 13:40:10 -0500156
Nick Gordon727d4832017-10-13 18:04:25 -0500157 for (const Lsa::Type& lsaType : lsaTypes) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500158 std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE
Nick Gordon727d4832017-10-13 18:04:25 -0500159 + OTHER_ROUTER_NAME + std::to_string(lsaType);
Nick Gordon5c467f02016-07-13 13:40:10 -0500160
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500161 ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
Ashlesh Gawandee6ba9152018-03-30 01:15:00 -0500162 [&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500163 BOOST_CHECK_EQUAL(ndn::Name{updateName}, routerName);
164 BOOST_CHECK_EQUAL(sequenceNumber, syncSeqNo);
165 });
Nick Gordon5c467f02016-07-13 13:40:10 -0500166
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500167 receiveUpdate<SyncProtocol::value>(updateName, syncSeqNo, sync);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500168 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500169}
170
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500171/* 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 Gawande32ec3fd2018-07-18 13:42:32 -0500175BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateForOtherHRDry, SyncProtocol, Protocols)
Nick Gordon5c467f02016-07-13 13:40:10 -0500176{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500177 setSyncProtocol<SyncProtocol::value>();
178
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500179 conf.setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
Nick Gordon5c467f02016-07-13 13:40:10 -0500180
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500181 SyncLogicHandler sync{face, testIsLsaNew, conf};
Ashlesh Gawande48101072018-05-30 17:53:06 -0500182 sync.createSyncLogic(conf.getChronosyncPrefix());
Nick Gordon5c467f02016-07-13 13:40:10 -0500183
Nick Gordon727d4832017-10-13 18:04:25 -0500184 for (const Lsa::Type& lsaType : lsaTypes) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500185 uint64_t syncSeqNo = 1;
Nick Gordon5c467f02016-07-13 13:40:10 -0500186
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500187 std::string updateName = conf.getLsaPrefix().toUri() + CONFIG_SITE
Nick Gordon727d4832017-10-13 18:04:25 -0500188 + OTHER_ROUTER_NAME + std::to_string(lsaType);
Nick Gordon5c467f02016-07-13 13:40:10 -0500189
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500190 ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
Ashlesh Gawandee6ba9152018-03-30 01:15:00 -0500191 [&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500192 BOOST_CHECK_EQUAL(ndn::Name{updateName}, routerName);
193 BOOST_CHECK_EQUAL(sequenceNumber, syncSeqNo);
194 });
195
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500196 receiveUpdate<SyncProtocol::value>(updateName, syncSeqNo, sync);
Nick Gordone8e03ac2016-07-07 14:24:38 -0500197 }
Vince Lehman904c2412014-09-23 19:36:11 -0500198}
199
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500200/* 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 Gawande32ec3fd2018-07-18 13:42:32 -0500204BOOST_AUTO_TEST_CASE_TEMPLATE(NoUpdateForSelf, SyncProtocol, Protocols)
Nick Gordon0f1bf1d2017-06-22 15:40:27 -0500205{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500206 setSyncProtocol<SyncProtocol::value>();
207
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500208 const uint64_t sequenceNumber = 1;
209
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500210 SyncLogicHandler sync{face, testIsLsaNew, conf};
Ashlesh Gawande48101072018-05-30 17:53:06 -0500211 sync.createSyncLogic(conf.getChronosyncPrefix());
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500212
Nick Gordon727d4832017-10-13 18:04:25 -0500213 for (const Lsa::Type& lsaType : lsaTypes) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500214 // 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 Gordon727d4832017-10-13 18:04:25 -0500217 updateName.append(CONFIG_SITE).append(CONFIG_ROUTER_NAME).append(std::to_string(lsaType));
Nick Gordon0f1bf1d2017-06-22 15:40:27 -0500218
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500219 ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
Ashlesh Gawandee6ba9152018-03-30 01:15:00 -0500220 [&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500221 BOOST_FAIL("Updates for self should not be emitted!");
222 });
Nick Gordon0f1bf1d2017-06-22 15:40:27 -0500223
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500224 receiveUpdate<SyncProtocol::value>(updateName.toUri(), sequenceNumber, sync);
Nick Gordon0f1bf1d2017-06-22 15:40:27 -0500225 }
226}
227
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500228/* 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 Gawande32ec3fd2018-07-18 13:42:32 -0500232BOOST_AUTO_TEST_CASE_TEMPLATE(MalformedUpdate, SyncProtocol, Protocols)
Vince Lehman904c2412014-09-23 19:36:11 -0500233{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500234 setSyncProtocol<SyncProtocol::value>();
235
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500236 const uint64_t sequenceNumber = 1;
Vince Lehman904c2412014-09-23 19:36:11 -0500237
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500238 SyncLogicHandler sync{face, testIsLsaNew, conf};
Ashlesh Gawande48101072018-05-30 17:53:06 -0500239 sync.createSyncLogic(conf.getChronosyncPrefix());
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500240
Nick Gordon727d4832017-10-13 18:04:25 -0500241 for (const Lsa::Type& lsaType : lsaTypes) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500242 ndn::Name updateName{CONFIG_SITE};
Nick Gordon727d4832017-10-13 18:04:25 -0500243 updateName.append(CONFIG_ROUTER_NAME).append(std::to_string(lsaType));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500244
245 ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
Ashlesh Gawandee6ba9152018-03-30 01:15:00 -0500246 [&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500247 BOOST_FAIL("Malformed updates should not be emitted!");
248 });
249
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500250 receiveUpdate<SyncProtocol::value>(updateName.toUri(), sequenceNumber, sync);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500251 }
Vince Lehman904c2412014-09-23 19:36:11 -0500252}
253
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500254/* 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 Gawande32ec3fd2018-07-18 13:42:32 -0500258BOOST_AUTO_TEST_CASE_TEMPLATE(LsaNotNew, SyncProtocol, Protocols)
Vince Lehman904c2412014-09-23 19:36:11 -0500259{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500260 setSyncProtocol<SyncProtocol::value>();
261
Nick Gordon727d4832017-10-13 18:04:25 -0500262 auto testLsaAlwaysFalse = [] (const ndn::Name& routerName, const Lsa::Type& lsaType,
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500263 const uint64_t& sequenceNumber) {
264 return false;
265 };
Vince Lehman904c2412014-09-23 19:36:11 -0500266
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500267 const uint64_t sequenceNumber = 1;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500268 SyncLogicHandler sync{face, testLsaAlwaysFalse, conf};
Ashlesh Gawande48101072018-05-30 17:53:06 -0500269 sync.createSyncLogic(conf.getChronosyncPrefix());
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500270 ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
Ashlesh Gawandee6ba9152018-03-30 01:15:00 -0500271 [&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500272 BOOST_FAIL("An update for an LSA with non-new sequence number should not emit!");
273 });
Vince Lehman904c2412014-09-23 19:36:11 -0500274
275 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
Nick Gordon727d4832017-10-13 18:04:25 -0500276 CONFIG_SITE + "/%C1.Router/other-router/" +
277 std::to_string(Lsa::Type::NAME);
Vince Lehman904c2412014-09-23 19:36:11 -0500278
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500279 receiveUpdate<SyncProtocol::value>(updateName, sequenceNumber, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500280}
281
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500282/* Tests that SyncLogicHandler successfully concatenates configured
283 variables together to form the necessary prefixes to advertise
284 through ChronoSync.
285 */
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500286BOOST_AUTO_TEST_CASE_TEMPLATE(UpdatePrefix, SyncProtocol, Protocols)
Vince Lehmanc11cc202015-01-20 11:41:33 -0600287{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500288 setSyncProtocol<SyncProtocol::value>();
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500289
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500290 SyncLogicHandler sync{face, testIsLsaNew, conf};
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500291
Vince Lehmanc11cc202015-01-20 11:41:33 -0600292 ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix();
293 expectedPrefix.append(CONFIG_SITE);
294 expectedPrefix.append(CONFIG_ROUTER_NAME);
295
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500296 sync.buildUpdatePrefix();
Vince Lehmanc11cc202015-01-20 11:41:33 -0600297
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500298 BOOST_CHECK_EQUAL(sync.m_nameLsaUserPrefix,
Nick Gordon727d4832017-10-13 18:04:25 -0500299 ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::NAME)));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500300 BOOST_CHECK_EQUAL(sync.m_adjLsaUserPrefix,
Nick Gordon727d4832017-10-13 18:04:25 -0500301 ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::ADJACENCY)));
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500302 BOOST_CHECK_EQUAL(sync.m_coorLsaUserPrefix,
Nick Gordon727d4832017-10-13 18:04:25 -0500303 ndn::Name(expectedPrefix).append(std::to_string(Lsa::Type::COORDINATE)));
Vince Lehmanc11cc202015-01-20 11:41:33 -0600304}
305
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500306/* 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 Gordon727d4832017-10-13 18:04:25 -0500310 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 Gordon8f23b5d2017-08-31 17:53:07 -0500312 */
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500313BOOST_AUTO_TEST_CASE_TEMPLATE(createSyncLogicOnInitialization, SyncProtocol, Protocols) // Bug #2649
Vince Lehman9d097802015-03-16 17:55:59 -0500314{
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500315 setSyncProtocol<SyncProtocol::value>();
Vince Lehman9d097802015-03-16 17:55:59 -0500316 nlsr.initialize();
317
318 // Make sure an adjacency LSA has not been built yet
Nick Gordon727d4832017-10-13 18:04:25 -0500319 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
Vince Lehman9d097802015-03-16 17:55:59 -0500320 AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
321 BOOST_REQUIRE(lsa == nullptr);
322
323 // Publish a routing update before an Adjacency LSA is built
Nick Gordon8f23b5d2017-08-31 17:53:07 -0500324 BOOST_CHECK_NO_THROW(nlsr.getLsdb().getSyncLogicHandler()
Nick Gordon727d4832017-10-13 18:04:25 -0500325 .publishRoutingUpdate(Lsa::Type::ADJACENCY, 0));
Vince Lehman9d097802015-03-16 17:55:59 -0500326}
327
Vince Lehman904c2412014-09-23 19:36:11 -0500328BOOST_AUTO_TEST_SUITE_END()
329
330} // namespace test
331} // namespace nlsr