blob: ea2357111db35abd93c58683a16d2c30051eb1d2 [file] [log] [blame]
Vince Lehman904c2412014-09-23 19:36:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, 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
22#include "test-common.hpp"
Vince Lehman904c2412014-09-23 19:36:11 -050023
24#include "nlsr.hpp"
25#include "communication/sync-logic-handler.hpp"
26
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060027#include <ndn-cxx/util/dummy-client-face.hpp>
28
Vince Lehman904c2412014-09-23 19:36:11 -050029namespace nlsr {
30namespace test {
31
dmcoomes9f936662017-03-02 10:33:09 -060032using std::shared_ptr;
Vince Lehman904c2412014-09-23 19:36:11 -050033
34class SyncLogicFixture : public BaseFixture
35{
36public:
37 SyncLogicFixture()
dmcoomes9f936662017-03-02 10:33:09 -060038 : face(std::make_shared<ndn::util::DummyClientFace>())
39 , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050040 , sync(nlsr.getLsdb().getSyncLogicHandler())
Vince Lehman904c2412014-09-23 19:36:11 -050041 , CONFIG_NETWORK("/ndn")
42 , CONFIG_SITE("/site")
43 , CONFIG_ROUTER_NAME("/%C1.Router/this-router")
44 {
45 nlsr.getConfParameter().setNetwork(CONFIG_NETWORK);
46 nlsr.getConfParameter().setSiteName(CONFIG_SITE);
47 nlsr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
48 nlsr.getConfParameter().buildRouterPrefix();
49 }
50
51 void
Nick Gordon5c467f02016-07-13 13:40:10 -050052 receiveUpdate(std::string prefix, uint64_t seqNo, SyncLogicHandler& p_sync)
Vince Lehman904c2412014-09-23 19:36:11 -050053 {
Ashlesh Gawande415676b2016-12-22 00:26:23 -060054 chronosync::MissingDataInfo info = {ndn::Name(prefix).appendNumber(1), 0, seqNo};
Vince Lehman904c2412014-09-23 19:36:11 -050055
Ashlesh Gawande415676b2016-12-22 00:26:23 -060056 std::vector<chronosync::MissingDataInfo> updates;
Vince Lehman904c2412014-09-23 19:36:11 -050057 updates.push_back(info);
58
59 face->processEvents(ndn::time::milliseconds(1));
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060060 face->sentInterests.clear();
Vince Lehman904c2412014-09-23 19:36:11 -050061
Ashlesh Gawande415676b2016-12-22 00:26:23 -060062 p_sync.onNsyncUpdate(updates);
Vince Lehman904c2412014-09-23 19:36:11 -050063
64 face->processEvents(ndn::time::milliseconds(1));
65 }
66
67public:
dmcoomes9f936662017-03-02 10:33:09 -060068 std::shared_ptr<ndn::util::DummyClientFace> face;
Vince Lehman904c2412014-09-23 19:36:11 -050069 Nlsr nlsr;
Vince Lehmanc11cc202015-01-20 11:41:33 -060070 SyncLogicHandler& sync;
Vince Lehman904c2412014-09-23 19:36:11 -050071
72 const std::string CONFIG_NETWORK;
73 const std::string CONFIG_SITE;
74 const std::string CONFIG_ROUTER_NAME;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050075 const std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING,
76 CoordinateLsa::TYPE_STRING};
Vince Lehman904c2412014-09-23 19:36:11 -050077};
78
79BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
80
Nick Gordon5c467f02016-07-13 13:40:10 -050081BOOST_AUTO_TEST_CASE(UpdateForOtherLS)
Vince Lehman904c2412014-09-23 19:36:11 -050082{
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050083 std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING};
Vince Lehman904c2412014-09-23 19:36:11 -050084
Nick Gordon5c467f02016-07-13 13:40:10 -050085 uint64_t syncSeqNo = 1;
Vince Lehman904c2412014-09-23 19:36:11 -050086
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050087 for (const std::string& lsaType : lsaTypes) {
88 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
89 CONFIG_SITE + "/%C1.Router/other-router/" + lsaType;
Nick Gordone8e03ac2016-07-07 14:24:38 -050090
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050091 receiveUpdate(updateName, syncSeqNo, sync);
Nick Gordon5c467f02016-07-13 13:40:10 -050092
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050093 std::vector<ndn::Interest>& interests = face->sentInterests;
Nick Gordon5c467f02016-07-13 13:40:10 -050094
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050095 std::vector<ndn::Interest>::iterator it = interests.begin();
Nick Gordon5c467f02016-07-13 13:40:10 -050096
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050097 BOOST_REQUIRE_EQUAL(interests.size(), 1);
98
99 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
100 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500101}
102
103BOOST_AUTO_TEST_CASE(UpdateForOtherHR)
104{
dmcoomes9f936662017-03-02 10:33:09 -0600105 Nlsr nlsr_hr(g_ioService, g_scheduler, std::ref(*face), g_keyChain);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500106 SyncLogicHandler& sync_hr(nlsr_hr.getLsdb().getSyncLogicHandler());
Nick Gordon5c467f02016-07-13 13:40:10 -0500107
108 nlsr_hr.getConfParameter().setNetwork(CONFIG_NETWORK);
109 nlsr_hr.getConfParameter().setSiteName(CONFIG_SITE);
110 nlsr_hr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
111 nlsr_hr.getConfParameter().buildRouterPrefix();
112
113 nlsr_hr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
114
115 nlsr_hr.initialize();
116
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500117 uint64_t syncSeqNo = 1;
Nick Gordon5c467f02016-07-13 13:40:10 -0500118
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500119 std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, CoordinateLsa::TYPE_STRING};
Nick Gordon5c467f02016-07-13 13:40:10 -0500120
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500121 for (const std::string& lsaType : lsaTypes) {
122 std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() +
123 CONFIG_SITE + "/%C1.Router/other-router/" + lsaType;
Nick Gordon5c467f02016-07-13 13:40:10 -0500124
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500125 receiveUpdate(updateName, syncSeqNo, sync_hr);
Nick Gordon5c467f02016-07-13 13:40:10 -0500126
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500127 std::vector<ndn::Interest>& interests = face->sentInterests;
128 std::vector<ndn::Interest>::iterator it = interests.begin();
Nick Gordon5c467f02016-07-13 13:40:10 -0500129
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500130 BOOST_REQUIRE_EQUAL(interests.size(), 1);
Nick Gordon5c467f02016-07-13 13:40:10 -0500131
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500132 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
133 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500134}
135
136BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry)
137{
138
dmcoomes9f936662017-03-02 10:33:09 -0600139 Nlsr nlsr_hrdry(g_ioService, g_scheduler, std::ref(*face),g_keyChain);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500140 SyncLogicHandler& sync_hrdry(nlsr_hrdry.getLsdb().getSyncLogicHandler());
Nick Gordon5c467f02016-07-13 13:40:10 -0500141
142 nlsr_hrdry.getConfParameter().setNetwork(CONFIG_NETWORK);
143 nlsr_hrdry.getConfParameter().setSiteName(CONFIG_SITE);
144 nlsr_hrdry.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
145 nlsr_hrdry.getConfParameter().buildRouterPrefix();
146
147 nlsr_hrdry.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
148
149 nlsr_hrdry.initialize();
150
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500151 for (const std::string& lsaType : lsaTypes) {
152
153 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
154 CONFIG_SITE + "/%C1.Router/other-router/" + lsaType;
Nick Gordon5c467f02016-07-13 13:40:10 -0500155
156
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500157 uint64_t syncSeqNo = 1;
Nick Gordon5c467f02016-07-13 13:40:10 -0500158
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500159 receiveUpdate(updateName, syncSeqNo, sync_hrdry);
Nick Gordon5c467f02016-07-13 13:40:10 -0500160
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500161 std::vector<ndn::Interest>& interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500162
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500163 std::vector<ndn::Interest>::iterator it = interests.begin();
Vince Lehman904c2412014-09-23 19:36:11 -0500164
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500165 // In HR dry-state all LSA's should be published
166 BOOST_REQUIRE_EQUAL(interests.size(), 1);
167 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
Nick Gordone8e03ac2016-07-07 14:24:38 -0500168 }
Vince Lehman904c2412014-09-23 19:36:11 -0500169}
170
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500171
Vince Lehman904c2412014-09-23 19:36:11 -0500172BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
173{
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500174 for (const std::string& lsaType : lsaTypes) {
175 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
176 CONFIG_SITE + CONFIG_ROUTER_NAME + lsaType;
Vince Lehman904c2412014-09-23 19:36:11 -0500177
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500178 receiveUpdate(updateName, 1, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500179
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500180 std::vector<ndn::Interest>& interests = face->sentInterests;
181 BOOST_CHECK_EQUAL(interests.size(), 0);
182 }
Vince Lehman904c2412014-09-23 19:36:11 -0500183}
184
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500185
Vince Lehman904c2412014-09-23 19:36:11 -0500186BOOST_AUTO_TEST_CASE(MalformedUpdate)
187{
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500188 for (const std::string& lsaType : lsaTypes) {
189 std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() +
190 CONFIG_ROUTER_NAME + lsaType;
Vince Lehman904c2412014-09-23 19:36:11 -0500191
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500192 std::vector<ndn::Interest>& interests = face->sentInterests;
193 BOOST_CHECK_EQUAL(interests.size(), 0);
194 }
Vince Lehman904c2412014-09-23 19:36:11 -0500195}
196
197BOOST_AUTO_TEST_CASE(SequenceNumber)
198{
199 std::string originRouter = CONFIG_NETWORK + CONFIG_SITE + "/%C1.Router/other-router/";
200
201 Lsdb& lsdb = nlsr.getLsdb();
202
203 // Install Name LSA
204 NamePrefixList nameList;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600205 NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
Vince Lehman904c2412014-09-23 19:36:11 -0500206 lsdb.installNameLsa(lsa);
207
208 // Install Adj LSA
209 AdjacencyList adjList;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600210 AdjLsa adjLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(),
Vince Lehman904c2412014-09-23 19:36:11 -0500211 3 , adjList);
212 lsdb.installAdjLsa(adjLsa);
213
214 // Install Cor LSA
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600215 CoordinateLsa corLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(),
Vince Lehman904c2412014-09-23 19:36:11 -0500216 0,0);
217 lsdb.installCoordinateLsa(corLsa);
218
219 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500220 CONFIG_SITE + "/%C1.Router/other-router/" + NameLsa::TYPE_STRING;
Vince Lehman904c2412014-09-23 19:36:11 -0500221
222 // Lower NameLSA sequence number
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500223 uint64_t lowerSeqNo = 998;
Nick Gordon5c467f02016-07-13 13:40:10 -0500224 receiveUpdate(updateName, lowerSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500225
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600226 std::vector<ndn::Interest>& interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500227 BOOST_REQUIRE_EQUAL(interests.size(), 0);
228
229 // Same NameLSA sequence number
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500230 uint64_t sameSeqNo = 999;
Nick Gordon5c467f02016-07-13 13:40:10 -0500231 receiveUpdate(updateName, sameSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500232
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600233 interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500234 BOOST_REQUIRE_EQUAL(interests.size(), 0);
235
236 // Higher NameLSA sequence number
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500237 uint64_t higherSeqNo = 1000;
Nick Gordon5c467f02016-07-13 13:40:10 -0500238 receiveUpdate(updateName, higherSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500239
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600240 interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500241 BOOST_REQUIRE_EQUAL(interests.size(), 1);
242
243 std::vector<ndn::Interest>::iterator it = interests.begin();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500244 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
Vince Lehman904c2412014-09-23 19:36:11 -0500245}
246
Vince Lehmanc11cc202015-01-20 11:41:33 -0600247BOOST_AUTO_TEST_CASE(UpdatePrefix)
248{
249 ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix();
250 expectedPrefix.append(CONFIG_SITE);
251 expectedPrefix.append(CONFIG_ROUTER_NAME);
252
253 nlsr.initialize();
254
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500255 BOOST_CHECK_EQUAL(sync.m_nameLsaUserPrefix, ndn::Name(expectedPrefix).append(NameLsa::TYPE_STRING));
256 BOOST_CHECK_EQUAL(sync.m_adjLsaUserPrefix, ndn::Name(expectedPrefix).append(AdjLsa::TYPE_STRING));
257 BOOST_CHECK_EQUAL(sync.m_coorLsaUserPrefix, ndn::Name(expectedPrefix).append(CoordinateLsa::TYPE_STRING));
Vince Lehmanc11cc202015-01-20 11:41:33 -0600258}
259
Vince Lehman9d097802015-03-16 17:55:59 -0500260BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649
261{
262 nlsr.initialize();
263
264 // Make sure an adjacency LSA has not been built yet
265 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
266 AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
267 BOOST_REQUIRE(lsa == nullptr);
268
269 // Publish a routing update before an Adjacency LSA is built
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500270 BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, 0));
Vince Lehman9d097802015-03-16 17:55:59 -0500271}
272
Vince Lehman904c2412014-09-23 19:36:11 -0500273BOOST_AUTO_TEST_SUITE_END()
274
275} // namespace test
276} // namespace nlsr