blob: 0547c6c63620d7ac72e8b342976ce00e6cef48e4 [file] [log] [blame]
Vince Lehman904c2412014-09-23 19:36:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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
Vince Lehman904c2412014-09-23 19:36:11 -050032using ndn::shared_ptr;
33
34class SyncLogicFixture : public BaseFixture
35{
36public:
37 SyncLogicFixture()
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060038 : face(make_shared<ndn::util::DummyClientFace>())
Vince Lehman904c2412014-09-23 19:36:11 -050039 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
Vince Lehmanc11cc202015-01-20 11:41:33 -060040 , sync(nlsr.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 {
54 Sync::MissingDataInfo info = {prefix, 0, seqNo};
55
56 std::vector<Sync::MissingDataInfo> updates;
57 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
Nick Gordon5c467f02016-07-13 13:40:10 -050062 p_sync.onNsyncUpdate(updates, NULL);
Vince Lehman904c2412014-09-23 19:36:11 -050063
64 face->processEvents(ndn::time::milliseconds(1));
65 }
66
67public:
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060068 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;
75};
76
77BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
78
Nick Gordon5c467f02016-07-13 13:40:10 -050079BOOST_AUTO_TEST_CASE(UpdateForOtherLS)
Vince Lehman904c2412014-09-23 19:36:11 -050080{
81 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
82 CONFIG_SITE + "/%C1.Router/other-router/";
83
Nick Gordon5c467f02016-07-13 13:40:10 -050084 uint64_t syncSeqNo = 1;
85 receiveUpdate(updateName, syncSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -050086
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060087 std::vector<ndn::Interest>& interests = face->sentInterests;
Nick Gordon5c467f02016-07-13 13:40:10 -050088 std::vector<ndn::Interest>::iterator it = interests.begin();
89
90 BOOST_REQUIRE_EQUAL(interests.size(), 2);
91
92 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
93
94 ++it;
95 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
96}
97
98BOOST_AUTO_TEST_CASE(UpdateForOtherHR)
99{
100 Nlsr nlsr_hr(g_ioService, g_scheduler, ndn::ref(*face));
101 SyncLogicHandler& sync_hr(nlsr_hr.getSyncLogicHandler());
102
103 nlsr_hr.getConfParameter().setNetwork(CONFIG_NETWORK);
104 nlsr_hr.getConfParameter().setSiteName(CONFIG_SITE);
105 nlsr_hr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
106 nlsr_hr.getConfParameter().buildRouterPrefix();
107
108 nlsr_hr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
109
110 nlsr_hr.initialize();
111
112 std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() +
113 CONFIG_SITE + "/%C1.Router/other-router/";
114
115 uint64_t syncSeqNo = 0;
116 syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20);
117
118 receiveUpdate(updateName, syncSeqNo, sync_hr);
119
120 std::vector<ndn::Interest>& interests = face->sentInterests;
121 std::vector<ndn::Interest>::iterator it = interests.begin();
122
123 BOOST_REQUIRE_EQUAL(interests.size(), 2);
124
125 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
126
127 ++it;
128 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
129}
130
131BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry)
132{
133
134 Nlsr nlsr_hrdry(g_ioService, g_scheduler, ndn::ref(*face));
135 SyncLogicHandler& sync_hrdry(nlsr_hrdry.getSyncLogicHandler());
136
137 nlsr_hrdry.getConfParameter().setNetwork(CONFIG_NETWORK);
138 nlsr_hrdry.getConfParameter().setSiteName(CONFIG_SITE);
139 nlsr_hrdry.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
140 nlsr_hrdry.getConfParameter().buildRouterPrefix();
141
142 nlsr_hrdry.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
143
144 nlsr_hrdry.initialize();
145
146 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
147 CONFIG_SITE + "/%C1.Router/other-router/";
148
149
150 uint64_t syncSeqNo = 1;
151 syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20);
152 receiveUpdate(updateName, syncSeqNo, sync_hrdry);
153
154 std::vector<ndn::Interest>& interests = face->sentInterests;
155 std::vector<ndn::Interest>::iterator it = interests.begin();
156
Vince Lehman904c2412014-09-23 19:36:11 -0500157 BOOST_REQUIRE_EQUAL(interests.size(), 3);
158
alvy49b1c0c2014-12-19 13:57:46 -0600159 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
Vince Lehman904c2412014-09-23 19:36:11 -0500160
161 ++it;
alvy49b1c0c2014-12-19 13:57:46 -0600162 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
Vince Lehman904c2412014-09-23 19:36:11 -0500163
164 ++it;
alvy49b1c0c2014-12-19 13:57:46 -0600165 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
Nick Gordon5c467f02016-07-13 13:40:10 -0500166
Vince Lehman904c2412014-09-23 19:36:11 -0500167}
168
169BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
170{
171 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
172 CONFIG_SITE + CONFIG_ROUTER_NAME;
173
Nick Gordon5c467f02016-07-13 13:40:10 -0500174 receiveUpdate(updateName, 1, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500175
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600176 std::vector<ndn::Interest>& interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500177 BOOST_CHECK_EQUAL(interests.size(), 0);
178}
179
180BOOST_AUTO_TEST_CASE(MalformedUpdate)
181{
182 std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() +
183 CONFIG_ROUTER_NAME;
184
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600185 std::vector<ndn::Interest>& interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500186 BOOST_CHECK_EQUAL(interests.size(), 0);
187}
188
189BOOST_AUTO_TEST_CASE(SequenceNumber)
190{
191 std::string originRouter = CONFIG_NETWORK + CONFIG_SITE + "/%C1.Router/other-router/";
192
193 Lsdb& lsdb = nlsr.getLsdb();
194
195 // Install Name LSA
196 NamePrefixList nameList;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600197 NameLsa lsa(originRouter, 999, ndn::time::system_clock::TimePoint::max(), nameList);
Vince Lehman904c2412014-09-23 19:36:11 -0500198 lsdb.installNameLsa(lsa);
199
200 // Install Adj LSA
201 AdjacencyList adjList;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600202 AdjLsa adjLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(),
Vince Lehman904c2412014-09-23 19:36:11 -0500203 3 , adjList);
204 lsdb.installAdjLsa(adjLsa);
205
206 // Install Cor LSA
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600207 CoordinateLsa corLsa(originRouter, 1000, ndn::time::system_clock::TimePoint::max(),
Vince Lehman904c2412014-09-23 19:36:11 -0500208 0,0);
209 lsdb.installCoordinateLsa(corLsa);
210
211 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
212 CONFIG_SITE + "/%C1.Router/other-router/";
213
214 // Lower NameLSA sequence number
215 uint64_t lowerSeqNo = static_cast<uint64_t>(998) << 40;
Nick Gordon5c467f02016-07-13 13:40:10 -0500216 receiveUpdate(updateName, lowerSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500217
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600218 std::vector<ndn::Interest>& interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500219 BOOST_REQUIRE_EQUAL(interests.size(), 0);
220
221 // Same NameLSA sequence number
222 uint64_t sameSeqNo = static_cast<uint64_t>(999) << 40;
Nick Gordon5c467f02016-07-13 13:40:10 -0500223 receiveUpdate(updateName, sameSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500224
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600225 interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500226 BOOST_REQUIRE_EQUAL(interests.size(), 0);
227
228 // Higher NameLSA sequence number
229 uint64_t higherSeqNo = static_cast<uint64_t>(1000) << 40;
Nick Gordon5c467f02016-07-13 13:40:10 -0500230 receiveUpdate(updateName, higherSeqNo, sync);
Vince Lehman904c2412014-09-23 19:36:11 -0500231
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -0600232 interests = face->sentInterests;
Vince Lehman904c2412014-09-23 19:36:11 -0500233 BOOST_REQUIRE_EQUAL(interests.size(), 1);
234
235 std::vector<ndn::Interest>::iterator it = interests.begin();
236 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "name/");
237}
238
Vince Lehmanc11cc202015-01-20 11:41:33 -0600239BOOST_AUTO_TEST_CASE(UpdatePrefix)
240{
241 ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix();
242 expectedPrefix.append(CONFIG_SITE);
243 expectedPrefix.append(CONFIG_ROUTER_NAME);
244
245 nlsr.initialize();
246
247 BOOST_CHECK_EQUAL(sync.m_updatePrefix, expectedPrefix);
248}
249
Vince Lehman9d097802015-03-16 17:55:59 -0500250BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649
251{
252 nlsr.initialize();
253
254 // Make sure an adjacency LSA has not been built yet
255 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
256 AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
257 BOOST_REQUIRE(lsa == nullptr);
258
259 // Publish a routing update before an Adjacency LSA is built
260 BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate());
261}
262
Vince Lehman904c2412014-09-23 19:36:11 -0500263BOOST_AUTO_TEST_SUITE_END()
264
265} // namespace test
266} // namespace nlsr