blob: 24291795fde2bdc9931793d263f68b52140e4f48 [file] [log] [blame]
Yanbiao Lid7c96362015-01-30 23:58:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Li6db75f02016-01-16 12:25:23 +08003 * Copyright (c) 2014-2016, Regents of the University of California,
Yanbiao Lid7c96362015-01-30 23:58:24 -08004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "rib/auto-prefix-propagator.hpp"
27
28#include "tests/test-common.hpp"
29#include "tests/identity-management-fixture.hpp"
30#include <ndn-cxx/util/dummy-client-face.hpp>
31
32namespace nfd {
33namespace rib {
34namespace tests {
35
36NFD_LOG_INIT("AutoPrefixPropagatorTest");
37
38const Name TEST_LINK_LOCAL_NFD_PREFIX("/localhop/nfd");
39const time::milliseconds TEST_PREFIX_PROPAGATION_TIMEOUT(1000);
40
41class AutoPrefixPropagatorFixture : public nfd::tests::IdentityManagementFixture
42 , public nfd::tests::UnitTestTimeFixture
43{
44public:
45 AutoPrefixPropagatorFixture()
46 : m_face(ndn::util::makeDummyClientFace(nfd::tests::UnitTestTimeFixture::g_io, {true, true}))
47 , m_controller(*m_face, m_keyChain)
48 , m_propagator(m_controller, m_keyChain, m_rib)
49 , m_requests(m_face->sentInterests)
50 , m_entries(m_propagator.m_propagatedEntries)
51 {
52 m_propagator.enable();
53 m_propagator.m_controlParameters
54 .setCost(15)
55 .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)// set origin to client.
56 .setFaceId(0);// the remote hub will take the input face as the faceId.
57 m_propagator.m_commandOptions
58 .setPrefix(TEST_LINK_LOCAL_NFD_PREFIX)
59 .setTimeout(TEST_PREFIX_PROPAGATION_TIMEOUT);
60 }
61
62public: // helpers for test
63 bool
64 insertEntryToRib(const Name& name, const uint64_t& faceId = 0)
65 {
66 if (m_rib.find(name) != m_rib.end()) {
67 NFD_LOG_INFO("RIB entry already exists: " << name);
68 return false;
69 }
70
71 Route route;
72 route.faceId = faceId;
73 m_rib.insert(name, route);
74 advanceClocks(time::milliseconds(1));
75
76 return m_rib.find(name) != m_rib.end(); // return whether afterInserEntry will be triggered
77 }
78
79 bool
80 eraseEntryFromRib(const Name& name)
81 {
82 if (m_rib.find(name) == m_rib.end()) {
83 NFD_LOG_INFO("RIB entry does not exist: " << name);
84 return false;
85 }
86
87 std::vector<Route> routeList;
88 std::copy(m_rib.find(name)->second->begin(), m_rib.find(name)->second->end(),
89 std::back_inserter(routeList));
90 for (auto&& route : routeList) {
91 m_rib.erase(name, route);
92 }
93 advanceClocks(time::milliseconds(1));
94
95 return m_rib.find(name) == m_rib.end(); // return whether afterEraseEntry will be triggered
96 }
97
98 void
99 connectToHub()
100 {
101 insertEntryToRib("/localhop/nfd");
102 }
103
104 void
105 disconnectFromHub()
106 {
107 eraseEntryFromRib("/localhop/nfd");
108 }
109
110public: // helpers for check
111 enum class CheckRequestResult {
112 OK,
113 OUT_OF_BOUNDARY,
114 INVALID_N_COMPONENTS,
115 WRONG_COMMAND_PREFIX,
116 WRONG_VERB,
117 INVALID_PARAMETERS,
118 WRONG_REGISTERING_PREFIX
119 };
120
121 /**
122 * @brief check a request at specified index
123 *
124 * @param idx the index of the specified request in m_requests
125 * @param verb the expected verb of request
126 * @param registeringPrefix the expected registering prefix of request
127
128 * @retval OK the specified request has a valid name, the right verb, a valid ControlParameters
129 * and the right registering prefix
130 * @retval OUT_OF_BOUNDARY the specified index out of boundary
131 * @retval INVALID_N_COMPONENTS the number of components of the request name is invalid
132 * @retval WRONG_COMMAND_PREFIX the command prefix of the request is wrong
133 * @retval WRONG_VERB the command verb of the request is wrong
134 * @retval INVALID_PARAMETERS no valid parameters can be decoded from the request's name
135 * @retval WRONG_REGISTERING_PREFIX the registering prefix of the request is wrong
136 */
137 CheckRequestResult
138 checkRequest(size_t idx, const std::string& verb, const Name& registeringPrefix)
139 {
140 Name requestName;
141 try {
142 requestName = m_requests.at(idx).getName();
143 }
144 catch (const std::out_of_range&) {
145 return CheckRequestResult::OUT_OF_BOUNDARY;
146 }
147
148 if (requestName.size() < 5) {
149 return CheckRequestResult::INVALID_N_COMPONENTS;
150 }
151
152 if (requestName.getPrefix(2) != TEST_LINK_LOCAL_NFD_PREFIX) {
153 return CheckRequestResult::WRONG_COMMAND_PREFIX;
154 }
155
156 if (requestName.get(3) != Name::Component(verb)) {
157 return CheckRequestResult::WRONG_VERB;
158 }
159
160 ControlParameters parameters;
161 try {
162 parameters.wireDecode(requestName.get(4).blockFromValue());
163 }
164 catch (const tlv::Error&) {
165 return CheckRequestResult::INVALID_PARAMETERS;
166 }
167
168 if (parameters.getName() != registeringPrefix) {
169 return CheckRequestResult::WRONG_REGISTERING_PREFIX;
170 }
171
172 return CheckRequestResult::OK;
173 }
174
175protected:
176 shared_ptr<ndn::util::DummyClientFace> m_face;
177 ndn::nfd::Controller m_controller;
178 Rib m_rib;
179 AutoPrefixPropagator m_propagator;
180 std::vector<Interest>& m_requests; // store sent out requests
181 AutoPrefixPropagator::PropagatedEntryList& m_entries; // store propagated entries
182};
183
184std::ostream&
185operator<<(std::ostream &os, const AutoPrefixPropagatorFixture::CheckRequestResult& result)
186{
187 switch (result) {
188 case AutoPrefixPropagatorFixture::CheckRequestResult::OK:
189 os << "OK";
190 break;
191 case AutoPrefixPropagatorFixture::CheckRequestResult::OUT_OF_BOUNDARY:
192 os << "OUT_OF_BOUNDARY";
193 break;
194 case AutoPrefixPropagatorFixture::CheckRequestResult::INVALID_N_COMPONENTS:
195 os << "INVALID_N_COMPONENTS";
196 break;
197 case AutoPrefixPropagatorFixture::CheckRequestResult::WRONG_COMMAND_PREFIX:
198 os << "WRONG_COMMAND_PREFIX";
199 break;
200 case AutoPrefixPropagatorFixture::CheckRequestResult::WRONG_VERB:
201 os << "WRONG_VERB";
202 break;
203 case AutoPrefixPropagatorFixture::CheckRequestResult::INVALID_PARAMETERS:
204 os << "INVALID_PARAMETERS";
205 break;
206 case AutoPrefixPropagatorFixture::CheckRequestResult::WRONG_REGISTERING_PREFIX:
207 os << "WRONG_REGISTERING_PREFIX";
208 break;
209 default:
210 break;
211 }
212
213 return os;
214}
215
216BOOST_AUTO_TEST_SUITE(Rib)
217
218BOOST_FIXTURE_TEST_SUITE(TestAutoPrefixPropagator, AutoPrefixPropagatorFixture)
219
220BOOST_AUTO_TEST_CASE(EnableDisable)
221{
222 connectToHub();
223 BOOST_REQUIRE(addIdentity("/test/A"));
224
225 auto testPropagateRevokeBasic = [this] () -> bool {
226 m_propagator.m_propagatedEntries.clear();
227
228 if (!insertEntryToRib("/test/A/app")) {
229 return false;
230 }
231 m_entries["/test/A"].succeed(nullptr);
232 if (!eraseEntryFromRib("/test/A/app")) {
233 return false;
234 }
235 return true;
236 };
237
238 m_propagator.disable();
239 BOOST_REQUIRE(testPropagateRevokeBasic());
240 BOOST_CHECK(m_requests.empty());
241
242 m_propagator.enable();
243 BOOST_REQUIRE(testPropagateRevokeBasic());
244 BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
245 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
246 BOOST_CHECK_EQUAL(checkRequest(1, "unregister", "/test/A"), CheckRequestResult::OK);
247}
248
249BOOST_AUTO_TEST_CASE(LoadConfiguration)
250{
251 ConfigFile config;
252 config.addSectionHandler("auto_prefix_propagate",
253 bind(&AutoPrefixPropagator::loadConfig, &m_propagator, _1));
254
255 const std::string CONFIG_STRING =
256 "auto_prefix_propagate\n"
257 "{\n"
258 " cost 11\n"
259 " timeout 22\n"
260 " refresh_interval 33\n"
261 " base_retry_wait 44\n"
262 " max_retry_wait 55\n"
263 "}";
264 config.parse(CONFIG_STRING, true, "test-auto-prefix-propagator");
265
266 BOOST_CHECK_EQUAL(m_propagator.m_controlParameters.getCost(), 11);
267 BOOST_CHECK_EQUAL(m_propagator.m_controlParameters.getOrigin(), ndn::nfd::ROUTE_ORIGIN_CLIENT);
268 BOOST_CHECK_EQUAL(m_propagator.m_controlParameters.getFaceId(), 0);
269
270 BOOST_CHECK_EQUAL(m_propagator.m_commandOptions.getPrefix(), TEST_LINK_LOCAL_NFD_PREFIX);
271 BOOST_CHECK_EQUAL(m_propagator.m_commandOptions.getTimeout(), time::milliseconds(22));
272
273 BOOST_CHECK_EQUAL(m_propagator.m_refreshInterval, time::seconds(33));
274 BOOST_CHECK_EQUAL(m_propagator.m_baseRetryWait, time::seconds(44));
275 BOOST_CHECK_EQUAL(m_propagator.m_maxRetryWait, time::seconds(55));
276}
277
278BOOST_AUTO_TEST_SUITE(Helpers)
279
280BOOST_AUTO_TEST_CASE(GetPrefixPropagationParameters)
281{
282 BOOST_REQUIRE(addIdentity("/test/A"));
283 BOOST_REQUIRE(addIdentity("/test/A/B"));
284 BOOST_REQUIRE(addIdentity("/test/C/nrd"));
285
286 auto parameters1 = m_propagator.getPrefixPropagationParameters("/none/A/B/app");
287 auto parameters2 = m_propagator.getPrefixPropagationParameters("/test/A/B/app");
288 auto parameters3 = m_propagator.getPrefixPropagationParameters("/test/C/D/app");
289
290 BOOST_CHECK(!parameters1.isValid);
291
292 BOOST_CHECK(parameters2.isValid);
293 BOOST_CHECK_EQUAL(parameters2.parameters.getName(), "/test/A");
294 BOOST_CHECK_EQUAL(parameters2.options.getSigningInfo().getSignerName(), "/test/A");
295
296 BOOST_CHECK(parameters3.isValid);
297 BOOST_CHECK_EQUAL(parameters3.parameters.getName(), "/test/C");
298 BOOST_CHECK_EQUAL(parameters3.options.getSigningInfo().getSignerName(), "/test/C/nrd");
299}
300
301BOOST_AUTO_TEST_CASE(CheckCurrentPropagatedPrefix)
302{
303 BOOST_REQUIRE(addIdentity("/test/A"));
304 BOOST_REQUIRE(addIdentity("/test/B/nrd"));
305 BOOST_REQUIRE(addIdentity("/test/A/B"));
306
307 BOOST_CHECK(!m_propagator.doesCurrentPropagatedPrefixWork("/test/E")); // does not exist
308 BOOST_CHECK(!m_propagator.doesCurrentPropagatedPrefixWork("/test/A/B")); // has a better option
309 BOOST_CHECK(m_propagator.doesCurrentPropagatedPrefixWork("/test/A"));
310 BOOST_CHECK(m_propagator.doesCurrentPropagatedPrefixWork("/test/B"));
311}
312
313BOOST_AUTO_TEST_CASE(RedoPropagation)
314{
315 connectToHub();
316 BOOST_REQUIRE(addIdentity("/test/A"));
317 BOOST_REQUIRE(addIdentity("/test/B"));
318 BOOST_REQUIRE(addIdentity("/test/B/C"));
319 BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
320 BOOST_REQUIRE(insertEntryToRib("/test/B/C/app"));
321 BOOST_REQUIRE(insertEntryToRib("/test/B/D/app"));
322
323 auto testRedoPropagation = [this] (const Name& signingIdentity) {
324 m_requests.clear();
325
326 m_entries[signingIdentity].setSigningIdentity(signingIdentity);
327
328 auto parameters = m_propagator.m_controlParameters;
329 auto options = m_propagator.m_commandOptions;
330 ndn::security::SigningInfo info(ndn::security::SigningInfo::SIGNER_TYPE_ID, signingIdentity);
331 m_propagator.redoPropagation(m_entries.find(signingIdentity),
332 parameters.setName(signingIdentity),
333 options.setSigningInfo(info),
334 time::seconds(0));
335 advanceClocks(time::milliseconds(1));
336 };
337
338 testRedoPropagation("/test/A"); // current propagated prefix still works
339 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
340 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
341 BOOST_CHECK(m_entries.find("test/A") != m_entries.end());
342
343 BOOST_CHECK_NO_THROW(m_keyChain.deleteIdentity("/test/B"));
344 testRedoPropagation("/test/B"); // signingIdentity no longer exists
345 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
346 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/B/C"), CheckRequestResult::OK);
347 BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
348 BOOST_CHECK(m_entries.find("/test/B/C") != m_entries.end());
349
350 testRedoPropagation("/test/B"); // no alternative identity
351 BOOST_CHECK(m_requests.empty());
352 BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
353
354 m_entries["/test/B/C"].succeed(nullptr);
355 testRedoPropagation("/test/B"); // alternative identity has been propagated
356 BOOST_CHECK(m_requests.empty());
357 BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
358
359 BOOST_REQUIRE(addIdentity("/test/B/"));
360 testRedoPropagation("/test/B/C"); // better option exists: /test/B
361 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
362 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/B"), CheckRequestResult::OK);
363 BOOST_CHECK(m_entries.find("test/B/C") == m_entries.end());
364}
365
366BOOST_AUTO_TEST_SUITE_END() // Helpers
367
368BOOST_AUTO_TEST_SUITE(PropagateRevokeSemantics)
369
370BOOST_AUTO_TEST_CASE(Basic)
371{
372 connectToHub(); // ensure connectivity to the hub
373 BOOST_REQUIRE(addIdentity("/test/A"));
374
375 BOOST_REQUIRE(insertEntryToRib("/test/A/app")); // ensure afterInsertEntry signal emitted
376 m_entries["/test/A"].succeed(nullptr); // ensure there is a valid entry inserted
377 BOOST_REQUIRE(eraseEntryFromRib("/test/A/app")); // ensure afterEraseEntry signal emitted
378
379 BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
380 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
381 BOOST_CHECK_EQUAL(checkRequest(1, "unregister", "/test/A"), CheckRequestResult::OK);
382}
383
384BOOST_AUTO_TEST_CASE(LocalPrefix)
385{
386 connectToHub();
387 BOOST_REQUIRE(addIdentity("/localhost/A"));
388
389 BOOST_REQUIRE(insertEntryToRib("/localhost/A/app"));
390 BOOST_CHECK(m_requests.empty());
391
392 m_propagator.m_propagatedEntries["/localhost/A"].succeed(nullptr);
393 BOOST_REQUIRE(eraseEntryFromRib("/localhost/A/app"));
394 BOOST_CHECK(m_requests.empty());
395}
396
397BOOST_AUTO_TEST_CASE(InvalidPropagationParameters)
398{
399 connectToHub();
400
401 // no identity can be found
402 BOOST_CHECK(!m_propagator.getPrefixPropagationParameters("/test/A/app").isValid);
403
404 BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
405 BOOST_CHECK(m_requests.empty());
406
407 m_entries["/test/A"].succeed(nullptr);
408 BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
409 BOOST_CHECK(m_requests.empty());
410}
411
412BOOST_AUTO_TEST_CASE(NoHubConnectivity)
413{
414 BOOST_REQUIRE(addIdentity("/test/A"));
415
416 BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
417 BOOST_CHECK(m_requests.empty());
418
419 m_entries["/test/A"].succeed(nullptr);
420 BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
421 BOOST_CHECK(m_requests.empty());
422}
423
Yanbiao Li6db75f02016-01-16 12:25:23 +0800424BOOST_AUTO_TEST_CASE(ProcessSuspendedEntries)
425{
426 BOOST_REQUIRE(addIdentity("/test/A"));
427
428 BOOST_REQUIRE(insertEntryToRib("/test/A/app1"));
429 BOOST_REQUIRE(insertEntryToRib("/test/A/app2"));
430 BOOST_CHECK(m_requests.empty()); // no propagation because no hub is connected
431 BOOST_CHECK_EQUAL(m_entries.size(), 1); // /test/A was suspended
432
433 BOOST_REQUIRE(eraseEntryFromRib("/test/A/app2"));
434 BOOST_CHECK_EQUAL(m_entries.size(), 1); // /test/A was kept for app1
435
436 // repeat the scenario that leads to BUG 3362.
437 // ensure there is no improper assertion.
438 BOOST_REQUIRE(insertEntryToRib("/test/A/app2"));
439}
440
Yanbiao Lid7c96362015-01-30 23:58:24 -0800441BOOST_AUTO_TEST_CASE(PropagatedEntryExists)
442{
443 connectToHub();
444 BOOST_REQUIRE(addIdentity("/test/A"));
445 BOOST_REQUIRE(insertEntryToRib("/test/A/app1"));
446
447 m_requests.clear();
448 BOOST_REQUIRE(insertEntryToRib("/test/A/app2")); // /test/A has been propagated by /test/A/app1
449 BOOST_CHECK(m_requests.empty());
450}
451
452BOOST_AUTO_TEST_CASE(PropagatedEntryShouldKeep)
453{
454 connectToHub();
455 BOOST_REQUIRE(addIdentity("/test/A"));
456 BOOST_REQUIRE(insertEntryToRib("/test/A/app1"));
457 BOOST_REQUIRE(insertEntryToRib("/test/A/app2"));
458
459 m_requests.clear();
460 BOOST_REQUIRE(eraseEntryFromRib("/test/A/app2")); // /test/A should be kept for /test/A/app1
461 BOOST_CHECK(m_requests.empty());
462}
463
464BOOST_AUTO_TEST_CASE(BackOffRetryPolicy)
465{
466 m_propagator.m_commandOptions.setTimeout(time::milliseconds(1));
467 m_propagator.m_baseRetryWait = time::seconds(1);
468 m_propagator.m_maxRetryWait = time::seconds(2);
469
470 connectToHub();
471 BOOST_REQUIRE(addIdentity("/test/A"));
472 BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
473
474 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
475 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
476
Junxiao Shi0de23a22015-12-03 20:07:02 +0000477 advanceClocks(time::milliseconds(10), time::milliseconds(1050)); // wait for the 1st retry
Yanbiao Lid7c96362015-01-30 23:58:24 -0800478 BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
479 BOOST_CHECK_EQUAL(checkRequest(1, "register", "/test/A"), CheckRequestResult::OK);
480
Junxiao Shi0de23a22015-12-03 20:07:02 +0000481 advanceClocks(time::milliseconds(10), time::milliseconds(2050)); // wait for the 2nd retry, 2 times
Yanbiao Lid7c96362015-01-30 23:58:24 -0800482 BOOST_REQUIRE_EQUAL(m_requests.size(), 3);
483 BOOST_CHECK_EQUAL(checkRequest(2, "register", "/test/A"), CheckRequestResult::OK);
484
Junxiao Shi0de23a22015-12-03 20:07:02 +0000485 advanceClocks(time::milliseconds(10), time::milliseconds(2050)); // wait for the 3rd retry, reach the upper bound
Yanbiao Lid7c96362015-01-30 23:58:24 -0800486 BOOST_REQUIRE_EQUAL(m_requests.size(), 4);
487 BOOST_CHECK_EQUAL(checkRequest(3, "register", "/test/A"), CheckRequestResult::OK);
488}
489
490BOOST_AUTO_TEST_SUITE_END() // PropagateRevokeSemantics
491
492BOOST_AUTO_TEST_SUITE(PropagatedEntryStateChanges)
493
494BOOST_AUTO_TEST_CASE(AfterRibInsert)
495{
496 BOOST_REQUIRE(addIdentity("/test/A"));
497
498 auto testAfterRibInsert = [this] (const Name& ribEntryPrefix) {
499 m_requests.clear();
500 m_propagator.m_propagatedEntries.clear(); // ensure entry does not exist
501
502 auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
503 m_propagator.afterRibInsert(propagateParameters.parameters, propagateParameters.options);
504 advanceClocks(time::milliseconds(1));
505 };
506
507 testAfterRibInsert("/test/A/app1");
508 BOOST_CHECK(m_requests.empty()); // no connectivity now
509 BOOST_CHECK(m_entries.find("/test/A") != m_entries.end());
510
511 connectToHub();
512 testAfterRibInsert("/test/A/app2");
513 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
514 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
515 BOOST_CHECK(m_entries.find("/test/A") != m_entries.end());
516}
517
518BOOST_AUTO_TEST_CASE(AfterRibErase)
519{
520 BOOST_REQUIRE(addIdentity("/test/A"));
521
522 auto testAfterRibInsert = [this] (const Name& localUnregPrefix) {
523 m_requests.clear();
524
525 auto propagateParameters = m_propagator.getPrefixPropagationParameters(localUnregPrefix);
526 m_propagator.afterRibErase(propagateParameters.parameters.unsetCost(),
527 propagateParameters.options);
528 advanceClocks(time::milliseconds(1));
529 };
530
531 m_entries["/test/A"].succeed(nullptr);
532 testAfterRibInsert("/test/A/app");
533 BOOST_CHECK(m_requests.empty()); // no connectivity
534 BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
535
536 connectToHub();
537 m_entries["/test/A"].fail(nullptr);
538 testAfterRibInsert("/test/A/app");
539 BOOST_CHECK(m_requests.empty()); // previous propagation has not succeeded
540 BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
541
542 m_entries["/test/A"].succeed(nullptr);
543 testAfterRibInsert("/test/A/app");
544 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
545 BOOST_CHECK_EQUAL(checkRequest(0, "unregister", "/test/A"), CheckRequestResult::OK);
546 BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
547}
548
549BOOST_AUTO_TEST_CASE(AfterHubConnectDisconnect)
550{
551 BOOST_REQUIRE(addIdentity("/test/A"));
552 BOOST_REQUIRE(addIdentity("/test/B"));
553 BOOST_REQUIRE(addIdentity("/test/C"));
554 BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
555 BOOST_REQUIRE(insertEntryToRib("/test/B/app"));
556
557 // recorder the prefixes that will be propagated in order
558 std::vector<Name> propagatedPrefixes;
559
560 BOOST_CHECK(m_requests.empty()); // no request because there is no connectivity to the hub now
561 BOOST_REQUIRE_EQUAL(m_entries.size(), 2); // valid entries will be kept
562
563 connectToHub(); // 2 cached entries will be processed
564 for (auto&& entry : m_entries) {
565 propagatedPrefixes.push_back(entry.first);
566 }
567
568 BOOST_REQUIRE(insertEntryToRib("/test/C/app")); // will be processed directly
569 propagatedPrefixes.push_back("/test/C");
570 BOOST_REQUIRE_EQUAL(m_entries.size(), 3);
571
572 BOOST_REQUIRE(m_entries["/test/A"].isPropagating());
573 BOOST_REQUIRE(m_entries["/test/B"].isPropagating());
574 BOOST_REQUIRE(m_entries["/test/C"].isPropagating());
575
576 disconnectFromHub(); // all 3 entries are initialized
577 BOOST_CHECK(m_entries["/test/A"].isNew());
578 BOOST_CHECK(m_entries["/test/B"].isNew());
579 BOOST_CHECK(m_entries["/test/C"].isNew());
580
581 connectToHub(); // all 3 entries will be processed
582 for (auto&& entry : m_entries) {
583 propagatedPrefixes.push_back(entry.first);
584 }
585
586 BOOST_REQUIRE_EQUAL(m_requests.size(), 6);
587 BOOST_REQUIRE_EQUAL(propagatedPrefixes.size(), 6);
588 BOOST_CHECK_EQUAL(checkRequest(0, "register", propagatedPrefixes[0]), CheckRequestResult::OK);
589 BOOST_CHECK_EQUAL(checkRequest(1, "register", propagatedPrefixes[1]), CheckRequestResult::OK);
590 BOOST_CHECK_EQUAL(checkRequest(2, "register", propagatedPrefixes[2]), CheckRequestResult::OK);
591 BOOST_CHECK_EQUAL(checkRequest(3, "register", propagatedPrefixes[3]), CheckRequestResult::OK);
592 BOOST_CHECK_EQUAL(checkRequest(4, "register", propagatedPrefixes[4]), CheckRequestResult::OK);
593 BOOST_CHECK_EQUAL(checkRequest(5, "register", propagatedPrefixes[5]), CheckRequestResult::OK);
594}
595
596BOOST_AUTO_TEST_CASE(AfterPropagateSucceed)
597{
598 bool wasRefreshEventTriggered = false;
599 auto testAfterPropagateSucceed = [&] (const Name& ribEntryPrefix) {
600 m_requests.clear();
601 wasRefreshEventTriggered = false;
602
603 auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
604 m_propagator.afterPropagateSucceed(propagateParameters.parameters, propagateParameters.options,
605 [&]{ wasRefreshEventTriggered = true; });
606 advanceClocks(time::milliseconds(1));
607 };
608
609 BOOST_REQUIRE(addIdentity("/test/A"));
610 m_propagator.m_refreshInterval = time::seconds(0); // event will be executed at once
611 m_entries["/test/A"].startPropagation(); // set to be in PROPAGATING state
612
613 testAfterPropagateSucceed("/test/A/app"); // will trigger refresh event
614 BOOST_CHECK(wasRefreshEventTriggered);
615 BOOST_CHECK(m_requests.empty());
616
617 m_entries.erase(m_entries.find("/test/A")); // set to be in RELEASED state
618 testAfterPropagateSucceed("/test/A/app"); // will call startRevocation
619 BOOST_CHECK(!wasRefreshEventTriggered);
620 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
621 BOOST_CHECK_EQUAL(checkRequest(0, "unregister", "/test/A"), CheckRequestResult::OK);
622}
623
624BOOST_AUTO_TEST_CASE(AfterPropagateFail)
625{
626 bool wasRetryEventTriggered = false;
627 auto testAfterPropagateFail = [&] (const Name& ribEntryPrefix) {
628 m_requests.clear();
629 wasRetryEventTriggered = false;
630
631 auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
632 m_propagator.afterPropagateFail(400, "test", propagateParameters.parameters, propagateParameters.options,
633 time::seconds(0), [&]{ wasRetryEventTriggered = true; });
634 advanceClocks(time::milliseconds(1));
635 };
636
637 BOOST_REQUIRE(addIdentity("/test/A"));
638 m_entries["/test/A"].startPropagation(); // set to be in PROPAGATING state
639
640 testAfterPropagateFail("/test/A/app"); // will trigger retry event
641 BOOST_CHECK(wasRetryEventTriggered);
642 BOOST_CHECK(m_requests.empty());
643
644 m_entries.erase(m_entries.find("/test/A")); // set to be in RELEASED state
645 testAfterPropagateFail("/test/A/app"); // will do nothing
646 BOOST_CHECK(!wasRetryEventTriggered);
647 BOOST_CHECK(m_requests.empty());
648}
649
650BOOST_AUTO_TEST_CASE(AfterRevokeSucceed)
651{
652 auto testAfterRevokeSucceed = [&] (const Name& ribEntryPrefix) {
653 m_requests.clear();
654 auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
655 m_propagator.afterRevokeSucceed(propagateParameters.parameters,
656 propagateParameters.options,
657 time::seconds(0));
658 advanceClocks(time::milliseconds(1));
659 };
660
661 BOOST_REQUIRE(addIdentity("/test/A"));
662
663 testAfterRevokeSucceed("/test/A/app"); // in RELEASED state
664 BOOST_CHECK(m_requests.empty());
665
666 m_entries["/test/A"].fail(nullptr); // in PROPAGATE_FAIL state
667 testAfterRevokeSucceed("/test/A/app");
668 BOOST_CHECK(m_requests.empty());
669
670 m_entries["/test/A"].succeed(nullptr); // in PROPAGATED state
671 testAfterRevokeSucceed("/test/A/app");
672 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
673 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
674
675 m_entries["/test/A"].startPropagation(); // in PROPAGATING state
676 testAfterRevokeSucceed("/test/A/app");
677 BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
678 BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
679}
680
681BOOST_AUTO_TEST_SUITE_END() // PropagatedEntryStateChanges
682
683BOOST_AUTO_TEST_SUITE_END() // TestAutoPrefixPropagator
684BOOST_AUTO_TEST_SUITE_END() // Rib
685
686} // namespace tests
687} // namespace rib
688} // namespace nfd