blob: cd4d0d2e84a731c5f31f1b00f7c21130f00f7321 [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/*
Davide Pesaventod90338d2021-01-07 17:50:05 -05003 * Copyright (c) 2014-2021, 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
Nick Gordond5c1a372016-10-31 13:56:23 -050032class NlsrFixture : public MockNfdMgmtFixture
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050033{
34public:
35 NlsrFixture()
Saurab Dulal427e0122019-11-28 11:58:02 -060036 : conf(m_face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060037 , confProcessor(conf)
38 , nlsr(m_face, m_keyChain, conf)
39 , lsdb(nlsr.m_lsdb)
40 , neighbors(conf.getAdjacencyList())
Nick Gordond5c1a372016-10-31 13:56:23 -050041 , nSuccessCallbacks(0)
42 , nFailureCallbacks(0)
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050043 {
Ashlesh Gawande85998a12017-12-07 22:22:13 -060044 addIdentity(conf.getRouterPrefix());
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050045 }
46
47 void
48 receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver)
49 {
50 ndn::Name dataName(sender);
51 dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion();
52
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050053 ndn::Data data(dataName);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050054
55 nlsr.m_helloProtocol.onContentValidated(data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050056 }
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050057
58public:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060059 ConfParameter conf;
60 DummyConfFileProcessor confProcessor;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050061 Nlsr nlsr;
62 Lsdb& lsdb;
63 AdjacencyList& neighbors;
Nick Gordond5c1a372016-10-31 13:56:23 -050064 uint32_t nSuccessCallbacks;
65 uint32_t nFailureCallbacks;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050066 ndn::util::signal::ScopedConnection connection;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050067};
68
69BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
Vince Lehman09131122014-09-09 17:10:11 -050070
71BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
72{
Vince Lehman09131122014-09-09 17:10:11 -050073 // Simulate loading configuration file
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050074 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25,
Nick Gordon727d4832017-10-13 18:04:25 -050075 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050076 neighbors.insert(neighborA);
77
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050078 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10,
Nick Gordon727d4832017-10-13 18:04:25 -050079 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050080 neighbors.insert(neighborB);
81
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050082 Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17,
Nick Gordon727d4832017-10-13 18:04:25 -050083 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050084 neighbors.insert(neighborC);
85
Ashlesh Gawande85998a12017-12-07 22:22:13 -060086 conf.setHyperbolicState(HYPERBOLIC_STATE_ON);
Vince Lehman09131122014-09-09 17:10:11 -050087
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070088 Nlsr nlsr2(m_face, m_keyChain, conf);
Vince Lehman09131122014-09-09 17:10:11 -050089
Davide Pesaventod8d6bbc2020-11-24 21:38:44 -050090 for (const auto& neighbor : neighbors.getAdjList()) {
Ashlesh Gawande57a87172020-05-09 19:47:06 -070091 BOOST_CHECK_EQUAL(neighbor.getLinkCost(), 0);
Vince Lehman09131122014-09-09 17:10:11 -050092 }
93}
94
95BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
96{
Vince Lehman09131122014-09-09 17:10:11 -050097 // Simulate loading configuration file
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050098 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25,
Nick Gordon727d4832017-10-13 18:04:25 -050099 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -0500100 neighbors.insert(neighborA);
101
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500102 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500103 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -0500104 neighbors.insert(neighborB);
105
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500106 Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17,
Nick Gordon727d4832017-10-13 18:04:25 -0500107 Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -0500108 neighbors.insert(neighborC);
109
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700110 Nlsr nlsr2(m_face, m_keyChain, conf);
Vince Lehman09131122014-09-09 17:10:11 -0500111
Davide Pesaventod8d6bbc2020-11-24 21:38:44 -0500112 for (const auto& neighbor : neighbors.getAdjList()) {
113 BOOST_CHECK_NE(neighbor.getLinkCost(), 0);
Vince Lehman09131122014-09-09 17:10:11 -0500114 }
115}
116
Vince Lehman7b616582014-10-17 16:25:39 -0500117BOOST_AUTO_TEST_CASE(SetEventIntervals)
118{
Vince Lehman7b616582014-10-17 16:25:39 -0500119 // Simulate loading configuration file
Vince Lehman7b616582014-10-17 16:25:39 -0500120 conf.setAdjLsaBuildInterval(3);
Vince Lehman7b616582014-10-17 16:25:39 -0500121 conf.setRoutingCalcInterval(9);
122
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600123 Nlsr nlsr2(m_face, m_keyChain, conf);
Vince Lehman7b616582014-10-17 16:25:39 -0500124
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600125 const Lsdb& lsdb = nlsr2.m_lsdb;
126 const RoutingTable& rt = nlsr2.m_routingTable;
Vince Lehman7b616582014-10-17 16:25:39 -0500127
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700128 BOOST_CHECK_EQUAL(lsdb.m_adjLsaBuildInterval, 3_s);
129 BOOST_CHECK_EQUAL(rt.m_routingCalcInterval, 9_s);
Vince Lehman7b616582014-10-17 16:25:39 -0500130}
131
Nick Gordond5c1a372016-10-31 13:56:23 -0500132BOOST_AUTO_TEST_CASE(FaceCreateEvent)
133{
134 // Setting constants for the unit test
135 const uint32_t faceId = 1;
136 const std::string faceUri = "udp4://10.0.0.1:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500137
138 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500139 Adjacent::STATUS_INACTIVE, 0, 0);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500140
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800141 BOOST_REQUIRE_EQUAL(conf.getAdjacencyList().insert(neighbor), true);
Nick Gordond5c1a372016-10-31 13:56:23 -0500142
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600143 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500144
145 // Build, sign, and send the Face Event
146 ndn::nfd::FaceEventNotification event;
147 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
148 .setRemoteUri(faceUri)
149 .setFaceId(faceId);
Eric Newberry04bfe042021-03-26 11:06:05 -0700150 auto data = std::make_shared<ndn::Data>(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(0));
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000151 data->setFreshnessPeriod(1_s);
Nick Gordond5c1a372016-10-31 13:56:23 -0500152 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600153 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500154 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500155
156 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600157 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500158
159 // Need to explicitly provide a FaceUri object, because the
160 // conversion will attempt to create Name objects.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600161 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri));
162 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500163 BOOST_CHECK_EQUAL(iterator->getFaceId(), faceId);
164}
165
166BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch)
167{
168 // Setting constants for the unit test
169 const uint32_t faceId = 1;
170 const std::string eventUri = "udp4://10.0.0.1:6363";
171 const std::string neighborUri = "udp4://10.0.0.2:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500172
173 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(neighborUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500174 Adjacent::STATUS_INACTIVE, 0, 0);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500175
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600176 conf.getAdjacencyList().insert(neighbor);
Nick Gordond5c1a372016-10-31 13:56:23 -0500177
178 // Build, sign, and send the Face Event
179 ndn::nfd::FaceEventNotification event;
180 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
181 .setRemoteUri(eventUri)
182 .setFaceId(faceId);
Eric Newberry04bfe042021-03-26 11:06:05 -0700183 auto data = std::make_shared<ndn::Data>(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(0));
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000184 data->setFreshnessPeriod(1_s);
Nick Gordond5c1a372016-10-31 13:56:23 -0500185 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600186 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500187 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500188
189 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600190 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500191
192 // The Face URIs did not match, so this neighbor should be unconfigured.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600193 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(neighborUri));
194 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500195 BOOST_CHECK_EQUAL(iterator->getFaceId(), 0);
196}
197
198BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured)
199{
Ashlesh Gawande41878572019-09-29 00:16:02 -0500200 // So if NLSR gets the notification and registers prefixes it
201 // will change the Id to 1 and our tests will fail
202 // Need to disable registrationReply in dummy face and have own registration reply in the future
203 const uint32_t neighborFaceId = 1;
Nick Gordond5c1a372016-10-31 13:56:23 -0500204 const std::string faceUri = "udp4://10.0.0.1:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500205
206 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10,
Ashlesh Gawande41878572019-09-29 00:16:02 -0500207 Adjacent::STATUS_ACTIVE, 0, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600208 conf.getAdjacencyList().insert(neighbor);
Nick Gordond5c1a372016-10-31 13:56:23 -0500209
Ashlesh Gawande41878572019-09-29 00:16:02 -0500210 // Let NLSR start the face monitor
211 this->advanceClocks(10_ms);
212
Nick Gordond5c1a372016-10-31 13:56:23 -0500213 // Build, sign, and send the Face Event
214 ndn::nfd::FaceEventNotification event;
215 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
216 .setRemoteUri(faceUri)
Ashlesh Gawande41878572019-09-29 00:16:02 -0500217 .setFaceId(neighborFaceId); // Does not matter what we set here, dummy face always returns 1
Eric Newberry04bfe042021-03-26 11:06:05 -0700218 auto data = std::make_shared<ndn::Data>(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(0));
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000219 data->setFreshnessPeriod(1_s);
Nick Gordond5c1a372016-10-31 13:56:23 -0500220 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600221 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500222 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500223
224 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600225 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500226
Ashlesh Gawande41878572019-09-29 00:16:02 -0500227 // Check that the neighbor is configured with the face id of 1
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600228 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri));
229 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500230 BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId);
Ashlesh Gawande41878572019-09-29 00:16:02 -0500231
232 // Resend same event notification again
233 m_face.sentInterests.clear();
Eric Newberry04bfe042021-03-26 11:06:05 -0700234 data->setName(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(1));
Ashlesh Gawande41878572019-09-29 00:16:02 -0500235 m_keyChain.sign(*data);
236 m_face.receive(*data);
237 this->advanceClocks(10_ms);
238
239 for (const auto& interest : m_face.sentInterests) {
240 // Should not re-register prefix since this is the same event notification
241 if (ndn::Name("/localhost/nfd/rib/register").isPrefixOf(interest.getName())) {
242 BOOST_CHECK(false);
243 }
244 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500245}
246
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500247BOOST_AUTO_TEST_CASE(FaceDestroyEvent)
Vince Lehman02e32992015-03-11 12:31:20 -0500248{
Vince Lehman02e32992015-03-11 12:31:20 -0500249 // Add active neighbors
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600250 AdjacencyList& neighbors = conf.getAdjacencyList();
Vince Lehman02e32992015-03-11 12:31:20 -0500251 uint64_t destroyFaceId = 128;
252
253 // Create a neighbor whose Face will be destroyed
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500254 Adjacent failNeighbor("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"),
255 10, Adjacent::STATUS_ACTIVE, 0, destroyFaceId);
Vince Lehman02e32992015-03-11 12:31:20 -0500256 neighbors.insert(failNeighbor);
257
258 // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500259 Adjacent otherNeighbor("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"),
260 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman02e32992015-03-11 12:31:20 -0500261 neighbors.insert(otherNeighbor);
262
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500263 // Set HelloInterest lifetime as 10 seconds so that neighbors are not marked INACTIVE
264 // upon timeout before this test ends
265 conf.setInterestResendTime(10);
Vince Lehman02e32992015-03-11 12:31:20 -0500266
267 // Simulate successful HELLO responses
Vince Lehman41b173e2015-05-07 14:13:26 -0500268 lsdb.scheduleAdjLsaBuild();
269
270 // Set up adjacency LSAs
271 // This router
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500272 Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.3"),
273 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman41b173e2015-05-07 14:13:26 -0500274
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500275 AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10,
276 ndn::time::system_clock::now(), 1, neighbors);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700277 lsdb.installLsa(std::make_shared<AdjLsa>(ownAdjLsa));
Vince Lehman41b173e2015-05-07 14:13:26 -0500278
279 // Router that will fail
280 AdjacencyList failAdjacencies;
281 failAdjacencies.insert(thisRouter);
282
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600283 AdjLsa failAdjLsa("/ndn/neighborA", 10,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500284 ndn::time::system_clock::now() + ndn::time::seconds(3600),
285 1, failAdjacencies);
Vince Lehman41b173e2015-05-07 14:13:26 -0500286
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700287 lsdb.installLsa(std::make_shared<AdjLsa>(failAdjLsa));
Vince Lehman41b173e2015-05-07 14:13:26 -0500288
289 // Other router
290 AdjacencyList otherAdjacencies;
291 otherAdjacencies.insert(thisRouter);
292
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600293 AdjLsa otherAdjLsa("/ndn/neighborB", 10,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500294 ndn::time::system_clock::now() + ndn::time::seconds(3600),
295 1, otherAdjacencies);
Vince Lehman41b173e2015-05-07 14:13:26 -0500296
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700297 lsdb.installLsa(std::make_shared<AdjLsa>(otherAdjLsa));
Vince Lehman02e32992015-03-11 12:31:20 -0500298
299 // Run the scheduler to build an adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600300 this->advanceClocks(10_ms);
Vince Lehman02e32992015-03-11 12:31:20 -0500301
302 // Make sure an adjacency LSA was built
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700303 auto lsa = lsdb.findLsa(conf.getRouterPrefix(), Lsa::Type::ADJACENCY);
Vince Lehman02e32992015-03-11 12:31:20 -0500304 BOOST_REQUIRE(lsa != nullptr);
305
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800306 uint32_t lastAdjLsaSeqNo = lsa->getSeqNo();
Ashlesh Gawande15052402018-12-12 20:20:00 -0600307 nlsr.m_lsdb.m_sequencingManager.setAdjLsaSeq(lastAdjLsaSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600308
309 this->advanceClocks(1500_ms, 10);
Vince Lehman02e32992015-03-11 12:31:20 -0500310
311 // Make sure the routing table was calculated
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600312 RoutingTableEntry* rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName());
Vince Lehman02e32992015-03-11 12:31:20 -0500313 BOOST_REQUIRE(rtEntry != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500314 BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().size(), 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500315
316 // Receive FaceEventDestroyed notification
317 ndn::nfd::FaceEventNotification event;
318 event.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
319 .setFaceId(destroyFaceId);
320
Eric Newberry04bfe042021-03-26 11:06:05 -0700321 auto data = std::make_shared<ndn::Data>(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(0));
Junxiao Shi0b1b7d92019-05-22 15:37:18 +0000322 data->setFreshnessPeriod(1_s);
Vince Lehman02e32992015-03-11 12:31:20 -0500323 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600324 m_keyChain.sign(*data);
Vince Lehman02e32992015-03-11 12:31:20 -0500325
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500326 m_face.receive(*data);
Vince Lehman02e32992015-03-11 12:31:20 -0500327
328 // Run the scheduler to build an adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600329 this->advanceClocks(10_ms);
Vince Lehman02e32992015-03-11 12:31:20 -0500330
331 Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName());
332
333 BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0);
334 BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(),
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600335 conf.getInterestRetryNumber());
Vince Lehman02e32992015-03-11 12:31:20 -0500336 BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE);
alvy46ccaae2015-06-25 14:13:39 -0500337
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700338 lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix());
alvy46ccaae2015-06-25 14:13:39 -0500339 BOOST_REQUIRE(lsa != nullptr);
340
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800341 BOOST_CHECK_EQUAL(lsa->getSeqNo(), lastAdjLsaSeqNo + 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500342
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600343 this->advanceClocks(15_s, 10);
344
Vince Lehman02e32992015-03-11 12:31:20 -0500345 // Make sure the routing table was recalculated
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600346 rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName());
Vince Lehman02e32992015-03-11 12:31:20 -0500347 BOOST_CHECK(rtEntry == nullptr);
348}
349
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500350BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
351{
352 // Configure NLSR
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500353 conf.setAdjLsaBuildInterval(1);
354
355 // Add neighbors
356 // Router A
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500357 ndn::Name neighborAName("/ndn/site/%C1.Router/routerA");
358 Adjacent neighborA(neighborAName, ndn::FaceUri("udp4://10.0.0.1"),
359 0, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500360 neighbors.insert(neighborA);
361
362 // Router B
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500363 ndn::Name neighborBName("/ndn/site/%C1.Router/routerB");
364 Adjacent neighborB(neighborBName, ndn::FaceUri("udp4://10.0.0.1"),
365 0, Adjacent::STATUS_INACTIVE, 0, 0);
366
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500367 neighbors.insert(neighborB);
368
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600369 this->advanceClocks(10_ms);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500370
371 // Receive HELLO response from Router A
372 receiveHelloData(neighborAName, conf.getRouterPrefix());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600373 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500374
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500375 // Adjacency LSA should be built even though other router is INACTIVE
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700376 auto lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix());
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500377 BOOST_REQUIRE(lsa != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500378 BOOST_CHECK_EQUAL(lsa->getAdl().size(), 1);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500379
380 // Receive HELLO response from Router B
381 receiveHelloData(neighborBName, conf.getRouterPrefix());
382
383 // Both routers become INACTIVE and HELLO Interests have timed out
384 for (Adjacent& adjacency : neighbors.getAdjList()) {
385 adjacency.setStatus(Adjacent::STATUS_INACTIVE);
386 adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
387 }
388
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600389 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500390
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500391 // Adjacency LSA should have been removed since this router's adjacencies are
392 // INACTIVE and have timed out
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700393 lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix());
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500394 BOOST_CHECK(lsa == nullptr);
395
396 // Receive HELLO response from Router A and B
397 receiveHelloData(neighborAName, conf.getRouterPrefix());
398 receiveHelloData(neighborBName, conf.getRouterPrefix());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600399 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500400
401 // Adjacency LSA should be built
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700402 lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix());
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500403 BOOST_REQUIRE(lsa != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500404 BOOST_CHECK_EQUAL(lsa->getAdl().size(), 2);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500405}
406
Nick Gordond5c1a372016-10-31 13:56:23 -0500407BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess)
408{
409 bool hasResult = false;
Nick Gordond5c1a372016-10-31 13:56:23 -0500410
411 nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) {
412 hasResult = true;
413 BOOST_CHECK_EQUAL(faces.size(), 2);
414 BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401);
415 BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402);
416 },
417 [] (uint32_t code, const std::string& reason) {});
418
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600419 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500420
421 ndn::nfd::FaceStatus payload1;
422 payload1.setFaceId(25401);
423 ndn::nfd::FaceStatus payload2;
424 payload2.setFaceId(25402);
425 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
426
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600427 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500428 BOOST_CHECK(hasResult);
429}
430
431BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure)
432{
Nick Gordond5c1a372016-10-31 13:56:23 -0500433 nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {},
434 [this](uint32_t code, const std::string& reason){
435 this->nFailureCallbacks++;
436 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600437 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500438
439 ndn::Name payload;
440 this->sendDataset("/localhost/nfd/faces/list", payload);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600441 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500442
443 BOOST_CHECK_EQUAL(nFailureCallbacks, 1);
444 BOOST_CHECK_EQUAL(nSuccessCallbacks, 0);
445}
446
447BOOST_AUTO_TEST_CASE(FaceDatasetProcess)
448{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500449 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"),
450 25, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500451 neighbors.insert(neighborA);
452
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500453 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://192.168.0.101:6363"),
454 10, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500455 neighbors.insert(neighborB);
456
457 ndn::nfd::FaceStatus payload1;
458 payload1.setFaceId(1)
459 .setRemoteUri("udp4://192.168.0.100:6363");
460 ndn::nfd::FaceStatus payload2;
461 payload2.setFaceId(2)
462 .setRemoteUri("udp4://192.168.0.101:6363");
463 std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2};
464
465 nlsr.processFaceDataset(faceStatuses);
Nick Gordond5c1a372016-10-31 13:56:23 -0500466
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600467 AdjacencyList adjList = conf.getAdjacencyList();
Nick Gordond5c1a372016-10-31 13:56:23 -0500468
469 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId());
470 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId());
471}
472
473BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor)
474{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500475 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 -0500476 neighbors.insert(neighborA);
477
478 ndn::nfd::FaceStatus payload;
479 payload.setFaceId(1)
480 .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI.
481 std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload};
482
483 nlsr.processFaceDataset(faceStatuses);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600484 this->advanceClocks(20_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500485
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600486 AdjacencyList adjList = conf.getAdjacencyList();
Nick Gordond5c1a372016-10-31 13:56:23 -0500487
488 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0);
489}
490
491BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch)
492{
493 int nNameMatches = 0;
494 ndn::Name datasetPrefix("/localhost/nfd/faces/list");
495 ndn::nfd::CommandOptions options;
496 ndn::time::milliseconds defaultTimeout = options.getTimeout();
497
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500498 int fetchInterval(1);
Nick Gordond5c1a372016-10-31 13:56:23 -0500499 conf.setFaceDatasetFetchInterval(fetchInterval);
500 conf.setFaceDatasetFetchTries(0);
501
Nick Gordond5c1a372016-10-31 13:56:23 -0500502 // Elapse the default timeout time of the interest.
503 this->advanceClocks(defaultTimeout);
504
505 // Check that we have one interest for face list in the sent interests.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600506 for (const auto& interest : m_face.sentInterests) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500507 if (datasetPrefix.isPrefixOf(interest.getName())) {
508 nNameMatches++;
509 }
510 }
511 BOOST_CHECK_EQUAL(nNameMatches, 1);
512
513 // Elapse the clock by the reschedule time (that we set)
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500514 this->advanceClocks(ndn::time::seconds(fetchInterval));
Nick Gordond5c1a372016-10-31 13:56:23 -0500515 // Elapse the default timeout on the interest.
516 this->advanceClocks(defaultTimeout);
Nick Gordond5c1a372016-10-31 13:56:23 -0500517
518 // Check that we now have two interests
519 nNameMatches = 0;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600520 for (const auto& interest : m_face.sentInterests) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500521 if (datasetPrefix.isPrefixOf(interest.getName())) {
522 nNameMatches++;
523 }
524 }
525 BOOST_CHECK_EQUAL(nNameMatches, 2);
526}
527
Vince Lehman09131122014-09-09 17:10:11 -0500528BOOST_AUTO_TEST_SUITE_END()
529
Nick Gordonfad8e252016-08-11 14:21:38 -0500530} // namespace test
531} // namespace nlsr