blob: 229c00416160d85e37f47301dec0070628a74f48 [file] [log] [blame]
Vince Lehman09131122014-09-09 17:10:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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/>.
Vince Lehman09131122014-09-09 17:10:11 -050020 **/
21
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");
Nick Gordond5c1a372016-10-31 13:56:23 -0500156 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600157 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500158 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500159
160 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600161 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500162
163 // Need to explicitly provide a FaceUri object, because the
164 // conversion will attempt to create Name objects.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600165 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri));
166 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500167 BOOST_CHECK_EQUAL(iterator->getFaceId(), faceId);
168}
169
170BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch)
171{
172 // Setting constants for the unit test
173 const uint32_t faceId = 1;
174 const std::string eventUri = "udp4://10.0.0.1:6363";
175 const std::string neighborUri = "udp4://10.0.0.2:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500176
177 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(neighborUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500178 Adjacent::STATUS_INACTIVE, 0, 0);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500179
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600180 conf.getAdjacencyList().insert(neighbor);
Nick Gordond5c1a372016-10-31 13:56:23 -0500181
182 // Build, sign, and send the Face Event
183 ndn::nfd::FaceEventNotification event;
184 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
185 .setRemoteUri(eventUri)
186 .setFaceId(faceId);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600187 auto data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Nick Gordond5c1a372016-10-31 13:56:23 -0500188 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600189 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500190 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500191
192 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600193 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500194
195 // The Face URIs did not match, so this neighbor should be unconfigured.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600196 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(neighborUri));
197 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500198 BOOST_CHECK_EQUAL(iterator->getFaceId(), 0);
199}
200
201BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured)
202{
203 // Setting constants for the unit test
204 const uint32_t eventFaceId = 1;
205 const uint32_t neighborFaceId = 2;
206 const std::string faceUri = "udp4://10.0.0.1:6363";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500207
208 Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10,
Nick Gordon727d4832017-10-13 18:04:25 -0500209 Adjacent::STATUS_ACTIVE, 0, neighborFaceId);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600210 conf.getAdjacencyList().insert(neighbor);
Nick Gordond5c1a372016-10-31 13:56:23 -0500211
212 // Build, sign, and send the Face Event
213 ndn::nfd::FaceEventNotification event;
214 event.setKind(ndn::nfd::FACE_EVENT_CREATED)
215 .setRemoteUri(faceUri)
216 .setFaceId(eventFaceId);
217 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
218 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600219 m_keyChain.sign(*data);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500220 m_face.receive(*data);
Nick Gordond5c1a372016-10-31 13:56:23 -0500221
222 // Move the clocks forward so that the Face processes the event.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600223 this->advanceClocks(10_ms);
Nick Gordond5c1a372016-10-31 13:56:23 -0500224
225 // Since the neighbor was already configured, this (simply erroneous) event should have no effect.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600226 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri));
227 BOOST_REQUIRE(iterator != conf.getAdjacencyList().end());
Nick Gordond5c1a372016-10-31 13:56:23 -0500228 BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId);
229}
230
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500231BOOST_AUTO_TEST_CASE(FaceDestroyEvent)
Vince Lehman02e32992015-03-11 12:31:20 -0500232{
Vince Lehman02e32992015-03-11 12:31:20 -0500233 // Add active neighbors
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600234 AdjacencyList& neighbors = conf.getAdjacencyList();
Vince Lehman02e32992015-03-11 12:31:20 -0500235 uint64_t destroyFaceId = 128;
236
237 // Create a neighbor whose Face will be destroyed
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500238 Adjacent failNeighbor("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"),
239 10, Adjacent::STATUS_ACTIVE, 0, destroyFaceId);
Vince Lehman02e32992015-03-11 12:31:20 -0500240 neighbors.insert(failNeighbor);
241
242 // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500243 Adjacent otherNeighbor("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"),
244 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman02e32992015-03-11 12:31:20 -0500245 neighbors.insert(otherNeighbor);
246
247 nlsr.initialize();
248
249 // Simulate successful HELLO responses
Vince Lehman41b173e2015-05-07 14:13:26 -0500250 lsdb.scheduleAdjLsaBuild();
251
252 // Set up adjacency LSAs
253 // This router
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500254 Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.3"),
255 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman41b173e2015-05-07 14:13:26 -0500256
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500257 AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10,
258 ndn::time::system_clock::now(), 1, neighbors);
Vince Lehman41b173e2015-05-07 14:13:26 -0500259 lsdb.installAdjLsa(ownAdjLsa);
260
261 // Router that will fail
262 AdjacencyList failAdjacencies;
263 failAdjacencies.insert(thisRouter);
264
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600265 AdjLsa failAdjLsa("/ndn/neighborA", 10,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500266 ndn::time::system_clock::now() + ndn::time::seconds(3600),
267 1, failAdjacencies);
Vince Lehman41b173e2015-05-07 14:13:26 -0500268
269 lsdb.installAdjLsa(failAdjLsa);
270
271 // Other router
272 AdjacencyList otherAdjacencies;
273 otherAdjacencies.insert(thisRouter);
274
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600275 AdjLsa otherAdjLsa("/ndn/neighborB", 10,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500276 ndn::time::system_clock::now() + ndn::time::seconds(3600),
277 1, otherAdjacencies);
Vince Lehman41b173e2015-05-07 14:13:26 -0500278
279 lsdb.installAdjLsa(otherAdjLsa);
Vince Lehman02e32992015-03-11 12:31:20 -0500280
281 // Run the scheduler to build an adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600282 this->advanceClocks(10_ms);
Vince Lehman02e32992015-03-11 12:31:20 -0500283
284 // Make sure an adjacency LSA was built
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600285 ndn::Name key = ndn::Name(conf.getRouterPrefix())
Nick Gordon727d4832017-10-13 18:04:25 -0500286 .append(std::to_string(Lsa::Type::ADJACENCY));
Vince Lehman41b173e2015-05-07 14:13:26 -0500287 AdjLsa* lsa = lsdb.findAdjLsa(key);
Vince Lehman02e32992015-03-11 12:31:20 -0500288 BOOST_REQUIRE(lsa != nullptr);
289
alvy46ccaae2015-06-25 14:13:39 -0500290 uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo();
Ashlesh Gawande15052402018-12-12 20:20:00 -0600291 nlsr.m_lsdb.m_sequencingManager.setAdjLsaSeq(lastAdjLsaSeqNo);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600292
293 this->advanceClocks(1500_ms, 10);
Vince Lehman02e32992015-03-11 12:31:20 -0500294
295 // Make sure the routing table was calculated
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600296 RoutingTableEntry* rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName());
Vince Lehman02e32992015-03-11 12:31:20 -0500297 BOOST_REQUIRE(rtEntry != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500298 BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().size(), 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500299
300 // Receive FaceEventDestroyed notification
301 ndn::nfd::FaceEventNotification event;
302 event.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
303 .setFaceId(destroyFaceId);
304
dmcoomes9f936662017-03-02 10:33:09 -0600305 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Vince Lehman02e32992015-03-11 12:31:20 -0500306 data->setContent(event.wireEncode());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600307 m_keyChain.sign(*data);
Vince Lehman02e32992015-03-11 12:31:20 -0500308
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500309 m_face.receive(*data);
Vince Lehman02e32992015-03-11 12:31:20 -0500310
311 // Run the scheduler to build an adjacency LSA
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600312 this->advanceClocks(10_ms);
Vince Lehman02e32992015-03-11 12:31:20 -0500313
314 Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName());
315
316 BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0);
317 BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(),
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600318 conf.getInterestRetryNumber());
Vince Lehman02e32992015-03-11 12:31:20 -0500319 BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE);
alvy46ccaae2015-06-25 14:13:39 -0500320
321 lsa = lsdb.findAdjLsa(key);
322 BOOST_REQUIRE(lsa != nullptr);
323
324 BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500325
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600326 this->advanceClocks(15_s, 10);
327
Vince Lehman02e32992015-03-11 12:31:20 -0500328 // Make sure the routing table was recalculated
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600329 rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName());
Vince Lehman02e32992015-03-11 12:31:20 -0500330 BOOST_CHECK(rtEntry == nullptr);
331}
332
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500333BOOST_AUTO_TEST_CASE(GetCertificate)
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500334{
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500335 // Create certificate
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500336 ndn::Name identityName("/TestNLSR/identity");
337 identityName.appendVersion();
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500338
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600339 ndn::security::pib::Identity identity = m_keyChain.createIdentity(identityName);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500340
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500341 ndn::security::v2::Certificate certificate =
342 identity.getDefaultKey().getDefaultCertificate();
343
344 const ndn::Name certKey = certificate.getKeyName();
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500345
346 BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr);
347
348 // Certificate should be retrievable from the CertificateStore
349 nlsr.loadCertToPublish(certificate);
350
351 BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
352
353 nlsr.getCertificateStore().clear();
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500354}
355
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500356BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
357{
358 // Configure NLSR
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500359 conf.setAdjLsaBuildInterval(1);
360
361 // Add neighbors
362 // Router A
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500363 ndn::Name neighborAName("/ndn/site/%C1.Router/routerA");
364 Adjacent neighborA(neighborAName, ndn::FaceUri("udp4://10.0.0.1"),
365 0, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500366 neighbors.insert(neighborA);
367
368 // Router B
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500369 ndn::Name neighborBName("/ndn/site/%C1.Router/routerB");
370 Adjacent neighborB(neighborBName, ndn::FaceUri("udp4://10.0.0.1"),
371 0, Adjacent::STATUS_INACTIVE, 0, 0);
372
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500373 neighbors.insert(neighborB);
374
375 nlsr.initialize();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500376
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600377 this->advanceClocks(10_ms);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500378
379 // Receive HELLO response from Router A
380 receiveHelloData(neighborAName, conf.getRouterPrefix());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600381 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500382
Nick Gordon727d4832017-10-13 18:04:25 -0500383 ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY));
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500384
385 // Adjacency LSA should be built even though other router is INACTIVE
386 AdjLsa* lsa = lsdb.findAdjLsa(lsaKey);
387 BOOST_REQUIRE(lsa != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500388 BOOST_CHECK_EQUAL(lsa->getAdl().size(), 1);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500389
390 // Receive HELLO response from Router B
391 receiveHelloData(neighborBName, conf.getRouterPrefix());
392
393 // Both routers become INACTIVE and HELLO Interests have timed out
394 for (Adjacent& adjacency : neighbors.getAdjList()) {
395 adjacency.setStatus(Adjacent::STATUS_INACTIVE);
396 adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
397 }
398
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600399 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500400
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500401 // Adjacency LSA should have been removed since this router's adjacencies are
402 // INACTIVE and have timed out
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500403 lsa = lsdb.findAdjLsa(lsaKey);
404 BOOST_CHECK(lsa == nullptr);
405
406 // Receive HELLO response from Router A and B
407 receiveHelloData(neighborAName, conf.getRouterPrefix());
408 receiveHelloData(neighborBName, conf.getRouterPrefix());
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600409 this->advanceClocks(1_s, 10);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500410
411 // Adjacency LSA should be built
412 lsa = lsdb.findAdjLsa(lsaKey);
413 BOOST_REQUIRE(lsa != nullptr);
Nick Gordonff9a6272017-10-12 13:38:29 -0500414 BOOST_CHECK_EQUAL(lsa->getAdl().size(), 2);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500415}
416
Nick Gordond5c1a372016-10-31 13:56:23 -0500417BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess)
418{
419 bool hasResult = false;
Nick Gordond5c1a372016-10-31 13:56:23 -0500420
421 nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) {
422 hasResult = true;
423 BOOST_CHECK_EQUAL(faces.size(), 2);
424 BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401);
425 BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402);
426 },
427 [] (uint32_t code, const std::string& reason) {});
428
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600429 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500430
431 ndn::nfd::FaceStatus payload1;
432 payload1.setFaceId(25401);
433 ndn::nfd::FaceStatus payload2;
434 payload2.setFaceId(25402);
435 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
436
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600437 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500438 BOOST_CHECK(hasResult);
439}
440
441BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure)
442{
Nick Gordond5c1a372016-10-31 13:56:23 -0500443 nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {},
444 [this](uint32_t code, const std::string& reason){
445 this->nFailureCallbacks++;
446 });
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600447 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500448
449 ndn::Name payload;
450 this->sendDataset("/localhost/nfd/faces/list", payload);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600451 this->advanceClocks(100_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500452
453 BOOST_CHECK_EQUAL(nFailureCallbacks, 1);
454 BOOST_CHECK_EQUAL(nSuccessCallbacks, 0);
455}
456
457BOOST_AUTO_TEST_CASE(FaceDatasetProcess)
458{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500459 Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"),
460 25, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500461 neighbors.insert(neighborA);
462
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500463 Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://192.168.0.101:6363"),
464 10, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500465 neighbors.insert(neighborB);
466
467 ndn::nfd::FaceStatus payload1;
468 payload1.setFaceId(1)
469 .setRemoteUri("udp4://192.168.0.100:6363");
470 ndn::nfd::FaceStatus payload2;
471 payload2.setFaceId(2)
472 .setRemoteUri("udp4://192.168.0.101:6363");
473 std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2};
474
475 nlsr.processFaceDataset(faceStatuses);
Nick Gordond5c1a372016-10-31 13:56:23 -0500476
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600477 AdjacencyList adjList = conf.getAdjacencyList();
Nick Gordond5c1a372016-10-31 13:56:23 -0500478
479 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId());
480 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId());
481}
482
483BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor)
484{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500485 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 -0500486 neighbors.insert(neighborA);
487
488 ndn::nfd::FaceStatus payload;
489 payload.setFaceId(1)
490 .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI.
491 std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload};
492
493 nlsr.processFaceDataset(faceStatuses);
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600494 this->advanceClocks(20_ms, 5);
Nick Gordond5c1a372016-10-31 13:56:23 -0500495
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600496 AdjacencyList adjList = conf.getAdjacencyList();
Nick Gordond5c1a372016-10-31 13:56:23 -0500497
498 BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0);
499}
500
501BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch)
502{
503 int nNameMatches = 0;
504 ndn::Name datasetPrefix("/localhost/nfd/faces/list");
505 ndn::nfd::CommandOptions options;
506 ndn::time::milliseconds defaultTimeout = options.getTimeout();
507
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500508 int fetchInterval(1);
Nick Gordond5c1a372016-10-31 13:56:23 -0500509 conf.setFaceDatasetFetchInterval(fetchInterval);
510 conf.setFaceDatasetFetchTries(0);
511
512 nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1),
513 std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0));
514
515 // Elapse the default timeout time of the interest.
516 this->advanceClocks(defaultTimeout);
517
518 // Check that we have one interest for face list in the sent interests.
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600519 for (const auto& interest : m_face.sentInterests) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500520 if (datasetPrefix.isPrefixOf(interest.getName())) {
521 nNameMatches++;
522 }
523 }
524 BOOST_CHECK_EQUAL(nNameMatches, 1);
525
526 // Elapse the clock by the reschedule time (that we set)
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500527 this->advanceClocks(ndn::time::seconds(fetchInterval));
Nick Gordond5c1a372016-10-31 13:56:23 -0500528 // Elapse the default timeout on the interest.
529 this->advanceClocks(defaultTimeout);
Nick Gordond5c1a372016-10-31 13:56:23 -0500530
531 // Check that we now have two interests
532 nNameMatches = 0;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600533 for (const auto& interest : m_face.sentInterests) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500534 if (datasetPrefix.isPrefixOf(interest.getName())) {
535 nNameMatches++;
536 }
537 }
538 BOOST_CHECK_EQUAL(nNameMatches, 2);
539}
540
Vince Lehman09131122014-09-09 17:10:11 -0500541BOOST_AUTO_TEST_SUITE_END()
542
Nick Gordonfad8e252016-08-11 14:21:38 -0500543} // namespace test
544} // namespace nlsr