blob: 76b0fd36097a348eb7edfd1e5427f30d7b5d64fe [file] [log] [blame]
Vince Lehman09131122014-09-09 17:10:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0b1b7d92019-05-22 15:37:18 +00002/*
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -06003 * Copyright (c) 2014-2019, The University of Memphis,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
Vince Lehman09131122014-09-09 17:10: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/>.
Junxiao Shi0b1b7d92019-05-22 15:37:18 +000020 */
Vince Lehman09131122014-09-09 17:10:11 -050021
Ashlesh Gawande3909aa12017-07-28 16:01:35 -050022#include "nlsr.hpp"
Vince Lehman02e32992015-03-11 12:31:20 -050023#include "test-common.hpp"
Vince Lehman199e9cf2015-04-07 13:22:16 -050024#include "control-commands.hpp"
Nick Gordonc0c6bcf2017-08-15 18:11:21 -050025#include "logger.hpp"
Vince Lehman09131122014-09-09 17:10:11 -050026
Junxiao Shi3e5120c2016-09-10 16:58:34 +000027#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
Vince Lehman09131122014-09-09 17:10:11 -050028
29namespace nlsr {
30namespace test {
31
Ashlesh Gawande85998a12017-12-07 22:22:13 -060032using namespace ndn::time_literals;
Vince Lehman09131122014-09-09 17:10:11 -050033
Nick Gordond5c1a372016-10-31 13:56:23 -050034class NlsrFixture : public MockNfdMgmtFixture
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050035{
36public:
37 NlsrFixture()
Ashlesh Gawande85998a12017-12-07 22:22:13 -060038 : conf(m_face)
39 , confProcessor(conf)
40 , nlsr(m_face, m_keyChain, conf)
41 , lsdb(nlsr.m_lsdb)
42 , neighbors(conf.getAdjacencyList())
Nick Gordond5c1a372016-10-31 13:56:23 -050043 , nSuccessCallbacks(0)
44 , nFailureCallbacks(0)
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050045 {
Ashlesh Gawande85998a12017-12-07 22:22:13 -060046 addIdentity(conf.getRouterPrefix());
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050047 }
48
49 void
50 receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver)
51 {
52 ndn::Name dataName(sender);
53 dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion();
54
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050055 ndn::Data data(dataName);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050056
57 nlsr.m_helloProtocol.onContentValidated(data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050058 }
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050059
60public:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060061 ConfParameter conf;
62 DummyConfFileProcessor confProcessor;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050063 Nlsr nlsr;
64 Lsdb& lsdb;
65 AdjacencyList& neighbors;
Nick Gordond5c1a372016-10-31 13:56:23 -050066 uint32_t nSuccessCallbacks;
67 uint32_t nFailureCallbacks;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050068};
69
70BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
Vince Lehman09131122014-09-09 17:10:11 -050071
72BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
73{
Vince Lehman09131122014-09-09 17:10:11 -050074 // Simulate loading configuration file
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050075 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25,
Nick Gordon727d4832017-10-13 18:04:25 -050076 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050077 neighbors.insert(neighborA);
78
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050079 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10,
Nick Gordon727d4832017-10-13 18:04:25 -050080 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050081 neighbors.insert(neighborB);
82
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050083 Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17,
Nick Gordon727d4832017-10-13 18:04:25 -050084 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050085 neighbors.insert(neighborC);
86
Ashlesh Gawande85998a12017-12-07 22:22:13 -060087 conf.setHyperbolicState(HYPERBOLIC_STATE_ON);
Vince Lehman09131122014-09-09 17:10:11 -050088
89 nlsr.initialize();
90
91 std::list<Adjacent> neighborList = neighbors.getAdjList();
92 for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) {
93 BOOST_CHECK_EQUAL(it->getLinkCost(), 0);
94 }
95}
96
97BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
98{
Vince Lehman09131122014-09-09 17:10:11 -050099 // Simulate loading configuration file
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500100 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25,
Nick Gordon727d4832017-10-13 18:04:25 -0500101 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -0500102 neighbors.insert(neighborA);
103
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500104 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500105 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -0500106 neighbors.insert(neighborB);
107
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500108 Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17,
Nick Gordon727d4832017-10-13 18:04:25 -0500109 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -0500110 neighbors.insert(neighborC);
111
112 nlsr.initialize();
113
114 std::list<Adjacent> neighborList = neighbors.getAdjList();
115 for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) {
116 BOOST_CHECK(it->getLinkCost() != 0);
117 }
118}
119
Vince Lehman7b616582014-10-17 16:25:39 -0500120BOOST_AUTO_TEST_CASE(SetEventIntervals)
121{
Vince Lehman7b616582014-10-17 16:25:39 -0500122 // Simulate loading configuration file
Vince Lehman7b616582014-10-17 16:25:39 -0500123 conf.setAdjLsaBuildInterval(3);
124 conf.setFirstHelloInterval(6);
125 conf.setRoutingCalcInterval(9);
126
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600127 Nlsr nlsr2(m_face, m_keyChain, conf);
Vince Lehman7b616582014-10-17 16:25:39 -0500128
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600129 const Lsdb& lsdb = nlsr2.m_lsdb;
130 const RoutingTable& rt = nlsr2.m_routingTable;
Vince Lehman7b616582014-10-17 16:25:39 -0500131
Ashlesh Gawande15052402018-12-12 20:20:00 -0600132 BOOST_CHECK_EQUAL(lsdb.m_adjLsaBuildInterval, ndn::time::seconds(3));
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600133 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
Vince Lehman7b616582014-10-17 16:25:39 -0500134 BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9));
135}
136
Nick Gordond5c1a372016-10-31 13:56:23 -0500137BOOST_AUTO_TEST_CASE(FaceCreateEvent)
138{
139 // Setting constants for the unit test
140 const uint32_t faceId = 1;
141 const std::string faceUri = "udp4://10.0.0.1:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500142
143 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500144 Adjacent::STATUS_INACTIVE, 0, 0);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500145
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600146 BOOST_REQUIRE_EQUAL(conf.getAdjacencyList().insert(neighbor), 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500147
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600148 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500149
150 // Build, sign, and send the Face Event
151 ndn::nfd::FaceEventNotification event;
152 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
153 .setRemoteUri(faceUri)
154 .setFaceId(faceId);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600155 auto data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000156 data->setFreshnessPeriod(1_s);
Nick Gordond5c1a372016-10-31 13:56:23 -0500157 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600158 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500159 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500160
161 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600162 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500163
164 // Need to explicitly provide a FaceUri object, because the
165 // conversion will attempt to create Name objects.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600166 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri));
167 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500168 BOOST_CHECK_EQUAL(iterator->getFaceId(), faceId);
169}
170
171BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch)
172{
173 // Setting constants for the unit test
174 const uint32_t faceId = 1;
175 const std::string eventUri = "udp4://10.0.0.1:6363";
176 const std::string neighborUri = "udp4://10.0.0.2:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500177
178 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(neighborUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500179 Adjacent::STATUS_INACTIVE, 0, 0);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500180
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600181 conf.getAdjacencyList().insert(neighbor);
Nick Gordond5c1a372016-10-31 13:56:23 -0500182
183 // Build, sign, and send the Face Event
184 ndn::nfd::FaceEventNotification event;
185 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
186 .setRemoteUri(eventUri)
187 .setFaceId(faceId);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600188 auto data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000189 data->setFreshnessPeriod(1_s);
Nick Gordond5c1a372016-10-31 13:56:23 -0500190 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600191 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500192 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500193
194 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600195 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500196
197 // The Face URIs did not match, so this neighbor should be unconfigured.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600198 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(neighborUri));
199 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500200 BOOST_CHECK_EQUAL(iterator->getFaceId(), 0);
201}
202
203BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured)
204{
205 // Setting constants for the unit test
206 const uint32_t eventFaceId = 1;
207 const uint32_t neighborFaceId = 2;
208 const std::string faceUri = "udp4://10.0.0.1:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500209
210 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500211 Adjacent::STATUS_ACTIVE, 0, neighborFaceId);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600212 conf.getAdjacencyList().insert(neighbor);
Nick Gordond5c1a372016-10-31 13:56:23 -0500213
214 // Build, sign, and send the Face Event
215 ndn::nfd::FaceEventNotification event;
216 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
217 .setRemoteUri(faceUri)
218 .setFaceId(eventFaceId);
219 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000220 data->setFreshnessPeriod(1_s);
Nick Gordond5c1a372016-10-31 13:56:23 -0500221 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600222 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500223 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500224
225 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600226 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500227
228 // Since the neighbor was already configured, this (simply erroneous) event should have no effect.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600229 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri));
230 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500231 BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId);
232}
233
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500234BOOST_AUTO_TEST_CASE(FaceDestroyEvent)
Vince Lehman02e32992015-03-11 12:31:20 -0500235{
Vince Lehman02e32992015-03-11 12:31:20 -0500236 // Add active neighbors
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600237 AdjacencyList& neighbors = conf.getAdjacencyList();
Vince Lehman02e32992015-03-11 12:31:20 -0500238 uint64_t destroyFaceId = 128;
239
240 // Create a neighbor whose Face will be destroyed
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500241 Adjacent failNeighbor("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"),
242 10, Adjacent::STATUS_ACTIVE, 0, destroyFaceId);
Vince Lehman02e32992015-03-11 12:31:20 -0500243 neighbors.insert(failNeighbor);
244
245 // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500246 Adjacent otherNeighbor("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"),
247 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman02e32992015-03-11 12:31:20 -0500248 neighbors.insert(otherNeighbor);
249
250 nlsr.initialize();
251
252 // Simulate successful HELLO responses
Vince Lehman41b173e2015-05-07 14:13:26 -0500253 lsdb.scheduleAdjLsaBuild();
254
255 // Set up adjacency LSAs
256 // This router
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500257 Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.3"),
258 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman41b173e2015-05-07 14:13:26 -0500259
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500260 AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10,
261 ndn::time::system_clock::now(), 1, neighbors);
Vince Lehman41b173e2015-05-07 14:13:26 -0500262 lsdb.installAdjLsa(ownAdjLsa);
263
264 // Router that will fail
265 AdjacencyList failAdjacencies;
266 failAdjacencies.insert(thisRouter);
267
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600268 AdjLsa failAdjLsa("/ndn/neighborA", 10,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500269 ndn::time::system_clock::now() + ndn::time::seconds(3600),
270 1, failAdjacencies);
Vince Lehman41b173e2015-05-07 14:13:26 -0500271
272 lsdb.installAdjLsa(failAdjLsa);
273
274 // Other router
275 AdjacencyList otherAdjacencies;
276 otherAdjacencies.insert(thisRouter);
277
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600278 AdjLsa otherAdjLsa("/ndn/neighborB", 10,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500279 ndn::time::system_clock::now() + ndn::time::seconds(3600),
280 1, otherAdjacencies);
Vince Lehman41b173e2015-05-07 14:13:26 -0500281
282 lsdb.installAdjLsa(otherAdjLsa);
Vince Lehman02e32992015-03-11 12:31:20 -0500283
284 // Run the scheduler to build an adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600285 this->advanceClocks(10_ms);
Vince Lehman02e32992015-03-11 12:31:20 -0500286
287 // Make sure an adjacency LSA was built
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600288 ndn::Name key = ndn::Name(conf.getRouterPrefix())
Nick Gordon727d4832017-10-13 18:04:25 -0500289 .append(std::to_string(Lsa::Type::ADJACENCY));
Vince Lehman41b173e2015-05-07 14:13:26 -0500290 AdjLsa* lsa = lsdb.findAdjLsa(key);
Vince Lehman02e32992015-03-11 12:31:20 -0500291 BOOST_REQUIRE(lsa != nullptr);
292
alvy46ccaae2015-06-25 14:13:39 -0500293 uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo();
Ashlesh Gawande15052402018-12-12 20:20:00 -0600294 nlsr.m_lsdb.m_sequencingManager.setAdjLsaSeq(lastAdjLsaSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600295
296 this->advanceClocks(1500_ms, 10);
Vince Lehman02e32992015-03-11 12:31:20 -0500297
298 // Make sure the routing table was calculated
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600299 RoutingTableEntry* rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName());
Vince Lehman02e32992015-03-11 12:31:20 -0500300 BOOST_REQUIRE(rtEntry != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500301 BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().size(), 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500302
303 // Receive FaceEventDestroyed notification
304 ndn::nfd::FaceEventNotification event;
305 event.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
306 .setFaceId(destroyFaceId);
307
dmcoomes9f936662017-03-02 10:33:09 -0600308 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000309 data->setFreshnessPeriod(1_s);
Vince Lehman02e32992015-03-11 12:31:20 -0500310 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600311 m_keyChain.sign(*data);
Vince Lehman02e32992015-03-11 12:31:20 -0500312
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500313 m_face.receive(*data);
Vince Lehman02e32992015-03-11 12:31:20 -0500314
315 // Run the scheduler to build an adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600316 this->advanceClocks(10_ms);
Vince Lehman02e32992015-03-11 12:31:20 -0500317
318 Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName());
319
320 BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0);
321 BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(),
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600322 conf.getInterestRetryNumber());
Vince Lehman02e32992015-03-11 12:31:20 -0500323 BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE);
alvy46ccaae2015-06-25 14:13:39 -0500324
325 lsa = lsdb.findAdjLsa(key);
326 BOOST_REQUIRE(lsa != nullptr);
327
328 BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500329
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600330 this->advanceClocks(15_s, 10);
331
Vince Lehman02e32992015-03-11 12:31:20 -0500332 // Make sure the routing table was recalculated
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600333 rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName());
Vince Lehman02e32992015-03-11 12:31:20 -0500334 BOOST_CHECK(rtEntry == nullptr);
335}
336
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500337BOOST_AUTO_TEST_CASE(GetCertificate)
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500338{
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500339 // Create certificate
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500340 ndn::Name identityName("/TestNLSR/identity");
341 identityName.appendVersion();
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500342
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600343 ndn::security::pib::Identity identity = m_keyChain.createIdentity(identityName);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500344
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500345 ndn::security::v2::Certificate certificate =
346 identity.getDefaultKey().getDefaultCertificate();
347
348 const ndn::Name certKey = certificate.getKeyName();
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500349
350 BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr);
351
352 // Certificate should be retrievable from the CertificateStore
353 nlsr.loadCertToPublish(certificate);
354
355 BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
356
357 nlsr.getCertificateStore().clear();
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500358}
359
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500360BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
361{
362 // Configure NLSR
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500363 conf.setAdjLsaBuildInterval(1);
364
365 // Add neighbors
366 // Router A
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500367 ndn::Name neighborAName("/ndn/site/%C1.Router/routerA");
368 Adjacent neighborA(neighborAName, ndn::FaceUri("udp4://10.0.0.1"),
369 0, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500370 neighbors.insert(neighborA);
371
372 // Router B
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500373 ndn::Name neighborBName("/ndn/site/%C1.Router/routerB");
374 Adjacent neighborB(neighborBName, ndn::FaceUri("udp4://10.0.0.1"),
375 0, Adjacent::STATUS_INACTIVE, 0, 0);
376
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500377 neighbors.insert(neighborB);
378
379 nlsr.initialize();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500380
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600381 this->advanceClocks(10_ms);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500382
383 // Receive HELLO response from Router A
384 receiveHelloData(neighborAName, conf.getRouterPrefix());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600385 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500386
Nick Gordon727d4832017-10-13 18:04:25 -0500387 ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500388
389 // Adjacency LSA should be built even though other router is INACTIVE
390 AdjLsa* lsa = lsdb.findAdjLsa(lsaKey);
391 BOOST_REQUIRE(lsa != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500392 BOOST_CHECK_EQUAL(lsa->getAdl().size(), 1);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500393
394 // Receive HELLO response from Router B
395 receiveHelloData(neighborBName, conf.getRouterPrefix());
396
397 // Both routers become INACTIVE and HELLO Interests have timed out
398 for (Adjacent& adjacency : neighbors.getAdjList()) {
399 adjacency.setStatus(Adjacent::STATUS_INACTIVE);
400 adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
401 }
402
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600403 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500404
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500405 // Adjacency LSA should have been removed since this router's adjacencies are
406 // INACTIVE and have timed out
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500407 lsa = lsdb.findAdjLsa(lsaKey);
408 BOOST_CHECK(lsa == nullptr);
409
410 // Receive HELLO response from Router A and B
411 receiveHelloData(neighborAName, conf.getRouterPrefix());
412 receiveHelloData(neighborBName, conf.getRouterPrefix());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600413 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500414
415 // Adjacency LSA should be built
416 lsa = lsdb.findAdjLsa(lsaKey);
417 BOOST_REQUIRE(lsa != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500418 BOOST_CHECK_EQUAL(lsa->getAdl().size(), 2);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500419}
420
Nick Gordond5c1a372016-10-31 13:56:23 -0500421BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess)
422{
423 bool hasResult = false;
Nick Gordond5c1a372016-10-31 13:56:23 -0500424
425 nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) {
426 hasResult = true;
427 BOOST_CHECK_EQUAL(faces.size(), 2);
428 BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401);
429 BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402);
430 },
431 [] (uint32_t code, const std::string& reason) {});
432
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600433 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500434
435 ndn::nfd::FaceStatus payload1;
436 payload1.setFaceId(25401);
437 ndn::nfd::FaceStatus payload2;
438 payload2.setFaceId(25402);
439 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
440
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600441 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500442 BOOST_CHECK(hasResult);
443}
444
445BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure)
446{
Nick Gordond5c1a372016-10-31 13:56:23 -0500447 nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {},
448 [this](uint32_t code, const std::string& reason){
449 this->nFailureCallbacks++;
450 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600451 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500452
453 ndn::Name payload;
454 this->sendDataset("/localhost/nfd/faces/list", payload);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600455 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500456
457 BOOST_CHECK_EQUAL(nFailureCallbacks, 1);
458 BOOST_CHECK_EQUAL(nSuccessCallbacks, 0);
459}
460
461BOOST_AUTO_TEST_CASE(FaceDatasetProcess)
462{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500463 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"),
464 25, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500465 neighbors.insert(neighborA);
466
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500467 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://192.168.0.101:6363"),
468 10, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500469 neighbors.insert(neighborB);
470
471 ndn::nfd::FaceStatus payload1;
472 payload1.setFaceId(1)
473 .setRemoteUri("udp4://192.168.0.100:6363");
474 ndn::nfd::FaceStatus payload2;
475 payload2.setFaceId(2)
476 .setRemoteUri("udp4://192.168.0.101:6363");
477 std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2};
478
479 nlsr.processFaceDataset(faceStatuses);
Nick Gordond5c1a372016-10-31 13:56:23 -0500480
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600481 AdjacencyList adjList = conf.getAdjacencyList();
Nick Gordond5c1a372016-10-31 13:56:23 -0500482
483 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId());
484 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId());
485}
486
487BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor)
488{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500489 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500490 neighbors.insert(neighborA);
491
492 ndn::nfd::FaceStatus payload;
493 payload.setFaceId(1)
494 .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI.
495 std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload};
496
497 nlsr.processFaceDataset(faceStatuses);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600498 this->advanceClocks(20_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500499
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600500 AdjacencyList adjList = conf.getAdjacencyList();
Nick Gordond5c1a372016-10-31 13:56:23 -0500501
502 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0);
503}
504
505BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch)
506{
507 int nNameMatches = 0;
508 ndn::Name datasetPrefix("/localhost/nfd/faces/list");
509 ndn::nfd::CommandOptions options;
510 ndn::time::milliseconds defaultTimeout = options.getTimeout();
511
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500512 int fetchInterval(1);
Nick Gordond5c1a372016-10-31 13:56:23 -0500513 conf.setFaceDatasetFetchInterval(fetchInterval);
514 conf.setFaceDatasetFetchTries(0);
515
516 nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1),
517 std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0));
518
519 // Elapse the default timeout time of the interest.
520 this->advanceClocks(defaultTimeout);
521
522 // Check that we have one interest for face list in the sent interests.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600523 for (const auto& interest : m_face.sentInterests) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500524 if (datasetPrefix.isPrefixOf(interest.getName())) {
525 nNameMatches++;
526 }
527 }
528 BOOST_CHECK_EQUAL(nNameMatches, 1);
529
530 // Elapse the clock by the reschedule time (that we set)
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500531 this->advanceClocks(ndn::time::seconds(fetchInterval));
Nick Gordond5c1a372016-10-31 13:56:23 -0500532 // Elapse the default timeout on the interest.
533 this->advanceClocks(defaultTimeout);
Nick Gordond5c1a372016-10-31 13:56:23 -0500534
535 // Check that we now have two interests
536 nNameMatches = 0;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600537 for (const auto& interest : m_face.sentInterests) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500538 if (datasetPrefix.isPrefixOf(interest.getName())) {
539 nNameMatches++;
540 }
541 }
542 BOOST_CHECK_EQUAL(nNameMatches, 2);
543}
544
Vince Lehman09131122014-09-09 17:10:11 -0500545BOOST_AUTO_TEST_SUITE_END()
546
Nick Gordonfad8e252016-08-11 14:21:38 -0500547} // namespace test
548} // namespace nlsr