blob: 78e0fb971fd4b9a23f2ba53df91c08e9208ed407 [file] [log] [blame]
Vince Lehman09131122014-09-09 17:10:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, 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
Vince Lehman02e32992015-03-11 12:31:20 -050022#include "test-common.hpp"
Vince Lehman199e9cf2015-04-07 13:22:16 -050023#include "control-commands.hpp"
Vince Lehman09131122014-09-09 17:10:11 -050024
Vince Lehman02e32992015-03-11 12:31:20 -050025#include "nlsr.hpp"
26
Junxiao Shi3e5120c2016-09-10 16:58:34 +000027#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
Vince Lehman02e32992015-03-11 12:31:20 -050028#include <ndn-cxx/util/dummy-client-face.hpp>
Vince Lehman09131122014-09-09 17:10:11 -050029
30namespace nlsr {
31namespace test {
32
dmcoomes9f936662017-03-02 10:33:09 -060033using std::shared_ptr;
Vince Lehman09131122014-09-09 17:10:11 -050034
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050035class NlsrFixture : public UnitTestTimeFixture
36{
37public:
38 NlsrFixture()
Nick Gordon9461afb2017-04-25 15:54:50 -050039 : face(std::make_shared<ndn::util::DummyClientFace>(g_ioService))
dmcoomes9f936662017-03-02 10:33:09 -060040 , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050041 , lsdb(nlsr.getLsdb())
42 , neighbors(nlsr.getAdjacencyList())
43 {
44 }
45
46 void
47 receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver)
48 {
49 ndn::Name dataName(sender);
50 dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion();
51
dmcoomes9f936662017-03-02 10:33:09 -060052 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(dataName);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050053
54 nlsr.m_helloProtocol.onContentValidated(data);
Nick Gordon9461afb2017-04-25 15:54:50 -050055 }
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050056
57public:
dmcoomes9f936662017-03-02 10:33:09 -060058 std::shared_ptr<ndn::util::DummyClientFace> face;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050059 Nlsr nlsr;
60 Lsdb& lsdb;
61 AdjacencyList& neighbors;
62};
63
64BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
Vince Lehman09131122014-09-09 17:10:11 -050065
66BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
67{
Vince Lehman09131122014-09-09 17:10:11 -050068 // Simulate loading configuration file
Nick Gordone9733ed2017-04-26 10:48:39 -050069 Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050070 neighbors.insert(neighborA);
71
Nick Gordone9733ed2017-04-26 10:48:39 -050072 Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050073 neighbors.insert(neighborB);
74
Nick Gordone9733ed2017-04-26 10:48:39 -050075 Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050076 neighbors.insert(neighborC);
77
78 nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
Ashlesh Gawande415676b2016-12-22 00:26:23 -060079 nlsr.getConfParameter().setNetwork(ndn::Name("/test"));
Vince Lehman09131122014-09-09 17:10:11 -050080
81 nlsr.initialize();
82
83 std::list<Adjacent> neighborList = neighbors.getAdjList();
84 for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) {
85 BOOST_CHECK_EQUAL(it->getLinkCost(), 0);
86 }
87}
88
89BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
90{
Vince Lehman09131122014-09-09 17:10:11 -050091 // Simulate loading configuration file
Nick Gordone9733ed2017-04-26 10:48:39 -050092 Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050093 neighbors.insert(neighborA);
94
Nick Gordone9733ed2017-04-26 10:48:39 -050095 Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050096 neighbors.insert(neighborB);
97
Nick Gordone9733ed2017-04-26 10:48:39 -050098 Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehman09131122014-09-09 17:10:11 -050099 neighbors.insert(neighborC);
100
101 nlsr.initialize();
102
103 std::list<Adjacent> neighborList = neighbors.getAdjList();
104 for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) {
105 BOOST_CHECK(it->getLinkCost() != 0);
106 }
107}
108
Vince Lehman7b616582014-10-17 16:25:39 -0500109BOOST_AUTO_TEST_CASE(SetEventIntervals)
110{
Vince Lehman7b616582014-10-17 16:25:39 -0500111 // Simulate loading configuration file
112 ConfParameter& conf = nlsr.getConfParameter();
113 conf.setAdjLsaBuildInterval(3);
114 conf.setFirstHelloInterval(6);
115 conf.setRoutingCalcInterval(9);
116
117 nlsr.initialize();
118
Vince Lehman50df6b72015-03-03 12:06:40 -0600119 const Lsdb& lsdb = nlsr.getLsdb();
Vince Lehman7b616582014-10-17 16:25:39 -0500120 const RoutingTable& rt = nlsr.getRoutingTable();
121
Vince Lehman50df6b72015-03-03 12:06:40 -0600122 BOOST_CHECK_EQUAL(lsdb.getAdjLsaBuildInterval(), ndn::time::seconds(3));
Vince Lehman7b616582014-10-17 16:25:39 -0500123 BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6);
124 BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9));
125}
126
Vince Lehman02e32992015-03-11 12:31:20 -0500127BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
128{
dmcoomes9f936662017-03-02 10:33:09 -0600129 std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService);
130 Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain);
Vince Lehman41b173e2015-05-07 14:13:26 -0500131 Lsdb& lsdb = nlsr.getLsdb();
Vince Lehman02e32992015-03-11 12:31:20 -0500132
133 // Simulate loading configuration file
134 ConfParameter& conf = nlsr.getConfParameter();
135 conf.setNetwork("/ndn");
136 conf.setSiteName("/site");
137 conf.setRouterName("/%C1.router/this-router");
138 conf.setAdjLsaBuildInterval(0);
139 conf.setRoutingCalcInterval(0);
140
141 // Add active neighbors
142 AdjacencyList& neighbors = nlsr.getAdjacencyList();
Vince Lehman02e32992015-03-11 12:31:20 -0500143 uint64_t destroyFaceId = 128;
144
145 // Create a neighbor whose Face will be destroyed
Nick Gordone9733ed2017-04-26 10:48:39 -0500146 Adjacent failNeighbor("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 10, Adjacent::STATUS_ACTIVE, 0,
Vince Lehman02e32992015-03-11 12:31:20 -0500147 destroyFaceId);
148 neighbors.insert(failNeighbor);
149
150 // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
Nick Gordone9733ed2017-04-26 10:48:39 -0500151 Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman02e32992015-03-11 12:31:20 -0500152 neighbors.insert(otherNeighbor);
153
154 nlsr.initialize();
155
156 // Simulate successful HELLO responses
Vince Lehman41b173e2015-05-07 14:13:26 -0500157 lsdb.scheduleAdjLsaBuild();
158
159 // Set up adjacency LSAs
160 // This router
Nick Gordone9733ed2017-04-26 10:48:39 -0500161 Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.3"), 10, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman41b173e2015-05-07 14:13:26 -0500162
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600163 AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors);
Vince Lehman41b173e2015-05-07 14:13:26 -0500164 lsdb.installAdjLsa(ownAdjLsa);
165
166 // Router that will fail
167 AdjacencyList failAdjacencies;
168 failAdjacencies.insert(thisRouter);
169
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600170 AdjLsa failAdjLsa("/ndn/neighborA", 10,
Vince Lehman41b173e2015-05-07 14:13:26 -0500171 ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, failAdjacencies);
172
173 lsdb.installAdjLsa(failAdjLsa);
174
175 // Other router
176 AdjacencyList otherAdjacencies;
177 otherAdjacencies.insert(thisRouter);
178
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600179 AdjLsa otherAdjLsa("/ndn/neighborB", 10,
Vince Lehman41b173e2015-05-07 14:13:26 -0500180 ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies);
181
182 lsdb.installAdjLsa(otherAdjLsa);
Vince Lehman02e32992015-03-11 12:31:20 -0500183
184 // Run the scheduler to build an adjacency LSA
185 this->advanceClocks(ndn::time::milliseconds(1));
186
187 // Make sure an adjacency LSA was built
188 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
Vince Lehman41b173e2015-05-07 14:13:26 -0500189 AdjLsa* lsa = lsdb.findAdjLsa(key);
Vince Lehman02e32992015-03-11 12:31:20 -0500190 BOOST_REQUIRE(lsa != nullptr);
191
alvy46ccaae2015-06-25 14:13:39 -0500192 uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500193 nlsr.getLsdb().getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo);
Vince Lehman02e32992015-03-11 12:31:20 -0500194
195 // Make sure the routing table was calculated
196 RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
197 BOOST_REQUIRE(rtEntry != nullptr);
198 BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().getSize(), 1);
199
200 // Receive FaceEventDestroyed notification
201 ndn::nfd::FaceEventNotification event;
202 event.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
203 .setFaceId(destroyFaceId);
204
dmcoomes9f936662017-03-02 10:33:09 -0600205 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Vince Lehman02e32992015-03-11 12:31:20 -0500206 data->setContent(event.wireEncode());
207 nlsr.getKeyChain().sign(*data);
208
209 face->receive(*data);
210
211 // Run the scheduler to build an adjacency LSA
212 this->advanceClocks(ndn::time::milliseconds(1));
213
214 Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName());
215
216 BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0);
217 BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(),
218 nlsr.getConfParameter().getInterestRetryNumber());
219 BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE);
alvy46ccaae2015-06-25 14:13:39 -0500220
221 lsa = lsdb.findAdjLsa(key);
222 BOOST_REQUIRE(lsa != nullptr);
223
224 BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1);
Vince Lehman02e32992015-03-11 12:31:20 -0500225
226 // Make sure the routing table was recalculated
227 rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
228 BOOST_CHECK(rtEntry == nullptr);
229}
230
Vince Lehman199e9cf2015-04-07 13:22:16 -0500231// Bug #2733
232// This test checks that when a face for an inactive node is destroyed, an
233// Adjacency LSA build does not postpone the LSA refresh and cause RIB
234// entries for other nodes' name prefixes to not be refreshed.
235//
236// This test is invalid when Issue #2732 is implemented since an Adjacency LSA
237// refresh will not cause RIB entries for other nodes' name prefixes to be refreshed.
238BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture)
239{
dmcoomes9f936662017-03-02 10:33:09 -0600240 std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService);
241 Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain);
Vince Lehman199e9cf2015-04-07 13:22:16 -0500242 Lsdb& lsdb = nlsr.getLsdb();
243
244 // Simulate loading configuration file
245 ConfParameter& conf = nlsr.getConfParameter();
246 conf.setNetwork("/ndn");
247 conf.setSiteName("/site");
248 conf.setRouterName("/%C1.router/this-router");
249 conf.setFirstHelloInterval(0);
250 conf.setAdjLsaBuildInterval(0);
251 conf.setRoutingCalcInterval(0);
252
253 // Add neighbors
254 AdjacencyList& neighbors = nlsr.getAdjacencyList();
255
256 uint64_t destroyFaceId = 128;
257
258 // Create an inactive neighbor whose Face will be destroyed
Nick Gordone9733ed2017-04-26 10:48:39 -0500259 Adjacent failNeighbor("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 10, Adjacent::STATUS_INACTIVE, 3,
Vince Lehman199e9cf2015-04-07 13:22:16 -0500260 destroyFaceId);
261 neighbors.insert(failNeighbor);
262
263 // Create an additional active neighbor so an adjacency LSA can be built
Nick Gordone9733ed2017-04-26 10:48:39 -0500264 Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 25, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman199e9cf2015-04-07 13:22:16 -0500265 neighbors.insert(otherNeighbor);
266
267 // Add a name for the neighbor to advertise
268 NamePrefixList nameList;
269 ndn::Name nameToAdvertise("/ndn/neighborB/name");
270 nameList.insert(nameToAdvertise);
271
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600272 NameLsa nameLsa("/ndn/neighborB", 25, ndn::time::system_clock::now(), nameList);
Vince Lehman199e9cf2015-04-07 13:22:16 -0500273 lsdb.installNameLsa(nameLsa);
274
275 nlsr.initialize();
276
277 // Simulate successful HELLO responses from neighbor B
278 lsdb.scheduleAdjLsaBuild();
279
Vince Lehman41b173e2015-05-07 14:13:26 -0500280 // Set up adjacency LSAs
281 // This router
Nick Gordone9733ed2017-04-26 10:48:39 -0500282 Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.2"), 25, Adjacent::STATUS_ACTIVE, 0, 256);
Vince Lehman41b173e2015-05-07 14:13:26 -0500283
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600284 AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors);
Vince Lehman41b173e2015-05-07 14:13:26 -0500285 lsdb.installAdjLsa(ownAdjLsa);
286
287 // Other ACTIVE router
288 AdjacencyList otherAdjacencies;
289 otherAdjacencies.insert(thisRouter);
290
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600291 AdjLsa otherAdjLsa("/ndn/neighborB", 10,
Vince Lehman41b173e2015-05-07 14:13:26 -0500292 ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies);
293
294 lsdb.installAdjLsa(otherAdjLsa);
295
Vince Lehman199e9cf2015-04-07 13:22:16 -0500296 // Run the scheduler to build an adjacency LSA
297 this->advanceClocks(ndn::time::milliseconds(1));
298
299 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
300 AdjLsa* lsa = lsdb.findAdjLsa(key);
301 BOOST_REQUIRE(lsa != nullptr);
302
303 // Cancel previous LSA expiration event
304 g_scheduler.cancelEvent(lsa->getExpiringEventId());
305
306 // Set expiration time for own Adjacency LSA to earlier value for unit-test
307 //
308 // Expiration time is negative to offset the GRACE_PERIOD (10 seconds) automatically applied
309 // to expiration times
310 ndn::EventId id = lsdb.scheduleAdjLsaExpiration(key, lsa->getLsSeqNo(), -ndn::time::seconds(9));
311 lsa->setExpiringEventId(id);
312
313 // Generate a FaceEventDestroyed notification
314 ndn::nfd::FaceEventNotification event;
315 event.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
316 .setFaceId(destroyFaceId);
317
dmcoomes9f936662017-03-02 10:33:09 -0600318 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
Vince Lehman199e9cf2015-04-07 13:22:16 -0500319 data->setContent(event.wireEncode());
320 nlsr.getKeyChain().sign(*data);
321
322 // Receive the FaceEventDestroyed notification
323 face->receive(*data);
324
325 // Run the scheduler to expire the Adjacency LSA. The expiration should refresh the RIB
326 // entries associated with Neighbor B's advertised prefix.
327 face->sentInterests.clear();
328 this->advanceClocks(ndn::time::seconds(1));
329
330 // The Face should have two sent Interests: the face event and a RIB registration
331 BOOST_REQUIRE(face->sentInterests.size() > 0);
332 const ndn::Interest& interest = face->sentInterests.back();
333
334 ndn::nfd::ControlParameters parameters;
335 ndn::Name::Component verb;
Nick Gordonb50e51b2016-07-22 16:05:57 -0500336 BOOST_REQUIRE_NO_THROW(extractRibCommandParameters(interest,
337 verb,
338 parameters));
Vince Lehman199e9cf2015-04-07 13:22:16 -0500339 BOOST_CHECK_EQUAL(verb, ndn::Name::Component("register"));
340 BOOST_CHECK_EQUAL(parameters.getName(), nameToAdvertise);
341}
342
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500343BOOST_AUTO_TEST_CASE(GetCertificate)
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500344{
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500345 // Create certificate
346 ndn::Name identity("/TestNLSR/identity");
347 identity.appendVersion();
348
349 ndn::KeyChain keyChain;
350 keyChain.createIdentity(identity);
351 ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity);
dmcoomes9f936662017-03-02 10:33:09 -0600352 std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500353
354 const ndn::Name certKey = certificate->getName().getPrefix(-1);
355
356 BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr);
357
358 // Certificate should be retrievable from the CertificateStore
359 nlsr.loadCertToPublish(certificate);
360
361 BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
362
363 nlsr.getCertificateStore().clear();
364
365 // Certificate should be retrievable from the cache
366 nlsr.addCertificateToCache(certificate);
367 this->advanceClocks(ndn::time::milliseconds(10));
368
369 BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
370}
371
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500372BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix)
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -0500373{
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -0500374 // Simulate loading configuration file
375 ConfParameter& conf = nlsr.getConfParameter();
376 conf.setNetwork("/ndn");
377 conf.setSiteName("/site");
378 conf.setRouterName("/%C1.router/this-router");
379
380 nlsr.initialize();
381
382 BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(),
383 ndn::Name("/ndn/site/%C1.router/this-router/lsdb"));
384}
385
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500386BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
387{
388 // Configure NLSR
389 ConfParameter& conf = nlsr.getConfParameter();
390 conf.setNetwork("/ndn");
391 conf.setSiteName("/site");
392
393 ndn::Name routerName("/%C1.Router/this-router");
394 conf.setRouterName(routerName);
395
396 conf.setAdjLsaBuildInterval(1);
397
398 // Add neighbors
399 // Router A
400 ndn::Name neighborAName("/ndn/site/%C1.router/routerA");
Nick Gordone9733ed2017-04-26 10:48:39 -0500401 Adjacent neighborA(neighborAName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500402 neighbors.insert(neighborA);
403
404 // Router B
405 ndn::Name neighborBName("/ndn/site/%C1.router/routerB");
Nick Gordone9733ed2017-04-26 10:48:39 -0500406 Adjacent neighborB(neighborBName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500407 neighbors.insert(neighborB);
408
409 nlsr.initialize();
410 this->advanceClocks(ndn::time::milliseconds(1));
411
412 // Receive HELLO response from Router A
413 receiveHelloData(neighborAName, conf.getRouterPrefix());
414 this->advanceClocks(ndn::time::seconds(1));
415
416 ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING);
417
418 // Adjacency LSA should be built even though other router is INACTIVE
419 AdjLsa* lsa = lsdb.findAdjLsa(lsaKey);
420 BOOST_REQUIRE(lsa != nullptr);
421 BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1);
422
423 // Receive HELLO response from Router B
424 receiveHelloData(neighborBName, conf.getRouterPrefix());
425
426 // Both routers become INACTIVE and HELLO Interests have timed out
427 for (Adjacent& adjacency : neighbors.getAdjList()) {
428 adjacency.setStatus(Adjacent::STATUS_INACTIVE);
429 adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
430 }
431
432 this->advanceClocks(ndn::time::seconds(1));
433
434 // Adjacency LSA should have been removed since this router's adjacencies are INACTIVE
435 // and have timed out
436 lsa = lsdb.findAdjLsa(lsaKey);
437 BOOST_CHECK(lsa == nullptr);
438
439 // Receive HELLO response from Router A and B
440 receiveHelloData(neighborAName, conf.getRouterPrefix());
441 receiveHelloData(neighborBName, conf.getRouterPrefix());
442 this->advanceClocks(ndn::time::seconds(1));
443
444 // Adjacency LSA should be built
445 lsa = lsdb.findAdjLsa(lsaKey);
446 BOOST_REQUIRE(lsa != nullptr);
447 BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2);
448}
449
Nick Gordon9461afb2017-04-25 15:54:50 -0500450BOOST_AUTO_TEST_CASE(CanonizeUris)
451{
452 ndn::Name neighborAName("/ndn/site/%C1.router/routerA");
Nick Gordone9733ed2017-04-26 10:48:39 -0500453 ndn::util::FaceUri faceUriA("udp://10.0.0.1");
454 Adjacent neighborA(neighborAName, faceUriA, 0, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordon9461afb2017-04-25 15:54:50 -0500455 neighbors.insert(neighborA);
456
457 ndn::Name neighborBName("/ndn/site/%C1.router/routerB");
Nick Gordone9733ed2017-04-26 10:48:39 -0500458 ndn::util::FaceUri faceUriB("udp://10.0.0.2");
459 Adjacent neighborB(neighborBName, faceUriB, 0, Adjacent::STATUS_INACTIVE, 0, 0);
Nick Gordon9461afb2017-04-25 15:54:50 -0500460 neighbors.insert(neighborB);
461
462 int nCanonizationsLeft = nlsr.getAdjacencyList().getAdjList().size();
463 std::function<void(std::list<Adjacent>::iterator)> thenCallback =
464 [this, &thenCallback, &nCanonizationsLeft] (std::list<Adjacent>::iterator iterator) {
465 nCanonizationsLeft--;
466 nlsr.canonizeNeighborUris(iterator, thenCallback);
467 };
468 nlsr.canonizeNeighborUris(nlsr.getAdjacencyList().getAdjList().begin(),
469 [thenCallback] (std::list<Adjacent>::iterator iterator) {
470 thenCallback(iterator);
471 });
472 while (nCanonizationsLeft != 0) {
473 this->advanceClocks(ndn::time::milliseconds(1));
474 }
475
Nick Gordone9733ed2017-04-26 10:48:39 -0500476 BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborAName).getFaceUri(),
477 ndn::util::FaceUri("udp4://10.0.0.1:6363"));
Nick Gordon9461afb2017-04-25 15:54:50 -0500478
Nick Gordone9733ed2017-04-26 10:48:39 -0500479 BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborBName).getFaceUri(),
480 ndn::util::FaceUri("udp4://10.0.0.2:6363"));
Nick Gordon9461afb2017-04-25 15:54:50 -0500481}
482
Vince Lehman09131122014-09-09 17:10:11 -0500483BOOST_AUTO_TEST_SUITE_END()
484
Nick Gordonfad8e252016-08-11 14:21:38 -0500485} // namespace test
486} // namespace nlsr