Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 6 | * |
| 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 Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 20 | **/ |
| 21 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 22 | #include "test-common.hpp" |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 23 | #include "control-commands.hpp" |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 24 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 25 | #include "nlsr.hpp" |
| 26 | |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 27 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 33 | using std::shared_ptr; |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 34 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 35 | class NlsrFixture : public UnitTestTimeFixture |
| 36 | { |
| 37 | public: |
| 38 | NlsrFixture() |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 39 | : face(std::make_shared<ndn::util::DummyClientFace>()) |
| 40 | , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 41 | , 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 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 52 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(dataName); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 53 | |
| 54 | nlsr.m_helloProtocol.onContentValidated(data); |
| 55 | } |
| 56 | |
| 57 | public: |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 58 | std::shared_ptr<ndn::util::DummyClientFace> face; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 59 | Nlsr nlsr; |
| 60 | Lsdb& lsdb; |
| 61 | AdjacencyList& neighbors; |
| 62 | }; |
| 63 | |
| 64 | BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture) |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 65 | |
| 66 | BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors) |
| 67 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 68 | // Simulate loading configuration file |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 69 | Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 70 | neighbors.insert(neighborA); |
| 71 | |
| 72 | Adjacent neighborB("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 73 | neighbors.insert(neighborB); |
| 74 | |
| 75 | Adjacent neighborC("/ndn/neighborC", "uri://faceC", 17, Adjacent::STATUS_INACTIVE, 0, 0); |
| 76 | neighbors.insert(neighborC); |
| 77 | |
| 78 | nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 79 | |
| 80 | nlsr.initialize(); |
| 81 | |
| 82 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 83 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 84 | BOOST_CHECK_EQUAL(it->getLinkCost(), 0); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost) |
| 89 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 90 | // Simulate loading configuration file |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 91 | Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 92 | neighbors.insert(neighborA); |
| 93 | |
| 94 | Adjacent neighborB("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 95 | neighbors.insert(neighborB); |
| 96 | |
| 97 | Adjacent neighborC("/ndn/neighborC", "uri://faceC", 17, Adjacent::STATUS_INACTIVE, 0, 0); |
| 98 | neighbors.insert(neighborC); |
| 99 | |
| 100 | nlsr.initialize(); |
| 101 | |
| 102 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 103 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 104 | BOOST_CHECK(it->getLinkCost() != 0); |
| 105 | } |
| 106 | } |
| 107 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 108 | BOOST_AUTO_TEST_CASE(SetEventIntervals) |
| 109 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 110 | // Simulate loading configuration file |
| 111 | ConfParameter& conf = nlsr.getConfParameter(); |
| 112 | conf.setAdjLsaBuildInterval(3); |
| 113 | conf.setFirstHelloInterval(6); |
| 114 | conf.setRoutingCalcInterval(9); |
| 115 | |
| 116 | nlsr.initialize(); |
| 117 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 118 | const Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 119 | const RoutingTable& rt = nlsr.getRoutingTable(); |
| 120 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(lsdb.getAdjLsaBuildInterval(), ndn::time::seconds(3)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6); |
| 123 | BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9)); |
| 124 | } |
| 125 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 126 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture) |
| 127 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 128 | std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService); |
| 129 | Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 130 | Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 131 | |
| 132 | // Simulate loading configuration file |
| 133 | ConfParameter& conf = nlsr.getConfParameter(); |
| 134 | conf.setNetwork("/ndn"); |
| 135 | conf.setSiteName("/site"); |
| 136 | conf.setRouterName("/%C1.router/this-router"); |
| 137 | conf.setAdjLsaBuildInterval(0); |
| 138 | conf.setRoutingCalcInterval(0); |
| 139 | |
| 140 | // Add active neighbors |
| 141 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 142 | uint64_t destroyFaceId = 128; |
| 143 | |
| 144 | // Create a neighbor whose Face will be destroyed |
| 145 | Adjacent failNeighbor("/ndn/neighborA", "uri://faceA", 10, Adjacent::STATUS_ACTIVE, 0, |
| 146 | destroyFaceId); |
| 147 | neighbors.insert(failNeighbor); |
| 148 | |
| 149 | // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 150 | Adjacent otherNeighbor("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 151 | neighbors.insert(otherNeighbor); |
| 152 | |
| 153 | nlsr.initialize(); |
| 154 | |
| 155 | // Simulate successful HELLO responses |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 156 | lsdb.scheduleAdjLsaBuild(); |
| 157 | |
| 158 | // Set up adjacency LSAs |
| 159 | // This router |
| 160 | Adjacent thisRouter(conf.getRouterPrefix(), "uri://faceB", 10, Adjacent::STATUS_ACTIVE, 0, 256); |
| 161 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 162 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 163 | lsdb.installAdjLsa(ownAdjLsa); |
| 164 | |
| 165 | // Router that will fail |
| 166 | AdjacencyList failAdjacencies; |
| 167 | failAdjacencies.insert(thisRouter); |
| 168 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 169 | AdjLsa failAdjLsa("/ndn/neighborA", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 170 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, failAdjacencies); |
| 171 | |
| 172 | lsdb.installAdjLsa(failAdjLsa); |
| 173 | |
| 174 | // Other router |
| 175 | AdjacencyList otherAdjacencies; |
| 176 | otherAdjacencies.insert(thisRouter); |
| 177 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 178 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 179 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies); |
| 180 | |
| 181 | lsdb.installAdjLsa(otherAdjLsa); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 182 | |
| 183 | // Run the scheduler to build an adjacency LSA |
| 184 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 185 | |
| 186 | // Make sure an adjacency LSA was built |
| 187 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 188 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 189 | BOOST_REQUIRE(lsa != nullptr); |
| 190 | |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 191 | uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo(); |
| 192 | nlsr.getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 193 | |
| 194 | // Make sure the routing table was calculated |
| 195 | RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 196 | BOOST_REQUIRE(rtEntry != nullptr); |
| 197 | BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().getSize(), 1); |
| 198 | |
| 199 | // Receive FaceEventDestroyed notification |
| 200 | ndn::nfd::FaceEventNotification event; |
| 201 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 202 | .setFaceId(destroyFaceId); |
| 203 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 204 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 205 | data->setContent(event.wireEncode()); |
| 206 | nlsr.getKeyChain().sign(*data); |
| 207 | |
| 208 | face->receive(*data); |
| 209 | |
| 210 | // Run the scheduler to build an adjacency LSA |
| 211 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 212 | |
| 213 | Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName()); |
| 214 | |
| 215 | BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0); |
| 216 | BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(), |
| 217 | nlsr.getConfParameter().getInterestRetryNumber()); |
| 218 | BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE); |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 219 | |
| 220 | lsa = lsdb.findAdjLsa(key); |
| 221 | BOOST_REQUIRE(lsa != nullptr); |
| 222 | |
| 223 | BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 224 | |
| 225 | // Make sure the routing table was recalculated |
| 226 | rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 227 | BOOST_CHECK(rtEntry == nullptr); |
| 228 | } |
| 229 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 230 | // Bug #2733 |
| 231 | // This test checks that when a face for an inactive node is destroyed, an |
| 232 | // Adjacency LSA build does not postpone the LSA refresh and cause RIB |
| 233 | // entries for other nodes' name prefixes to not be refreshed. |
| 234 | // |
| 235 | // This test is invalid when Issue #2732 is implemented since an Adjacency LSA |
| 236 | // refresh will not cause RIB entries for other nodes' name prefixes to be refreshed. |
| 237 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture) |
| 238 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 239 | std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService); |
| 240 | Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 241 | Lsdb& lsdb = nlsr.getLsdb(); |
| 242 | |
| 243 | // Simulate loading configuration file |
| 244 | ConfParameter& conf = nlsr.getConfParameter(); |
| 245 | conf.setNetwork("/ndn"); |
| 246 | conf.setSiteName("/site"); |
| 247 | conf.setRouterName("/%C1.router/this-router"); |
| 248 | conf.setFirstHelloInterval(0); |
| 249 | conf.setAdjLsaBuildInterval(0); |
| 250 | conf.setRoutingCalcInterval(0); |
| 251 | |
| 252 | // Add neighbors |
| 253 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
| 254 | |
| 255 | uint64_t destroyFaceId = 128; |
| 256 | |
| 257 | // Create an inactive neighbor whose Face will be destroyed |
| 258 | Adjacent failNeighbor("/ndn/neighborA", "uri://faceA", 10, Adjacent::STATUS_INACTIVE, 3, |
| 259 | destroyFaceId); |
| 260 | neighbors.insert(failNeighbor); |
| 261 | |
| 262 | // Create an additional active neighbor so an adjacency LSA can be built |
| 263 | Adjacent otherNeighbor("/ndn/neighborB", "uri://faceB", 25, Adjacent::STATUS_ACTIVE, 0, 256); |
| 264 | neighbors.insert(otherNeighbor); |
| 265 | |
| 266 | // Add a name for the neighbor to advertise |
| 267 | NamePrefixList nameList; |
| 268 | ndn::Name nameToAdvertise("/ndn/neighborB/name"); |
| 269 | nameList.insert(nameToAdvertise); |
| 270 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 271 | NameLsa nameLsa("/ndn/neighborB", 25, ndn::time::system_clock::now(), nameList); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 272 | lsdb.installNameLsa(nameLsa); |
| 273 | |
| 274 | nlsr.initialize(); |
| 275 | |
| 276 | // Simulate successful HELLO responses from neighbor B |
| 277 | lsdb.scheduleAdjLsaBuild(); |
| 278 | |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 279 | // Set up adjacency LSAs |
| 280 | // This router |
| 281 | Adjacent thisRouter(conf.getRouterPrefix(), "uri://faceB", 25, Adjacent::STATUS_ACTIVE, 0, 256); |
| 282 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 283 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 284 | lsdb.installAdjLsa(ownAdjLsa); |
| 285 | |
| 286 | // Other ACTIVE router |
| 287 | AdjacencyList otherAdjacencies; |
| 288 | otherAdjacencies.insert(thisRouter); |
| 289 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 290 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 291 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies); |
| 292 | |
| 293 | lsdb.installAdjLsa(otherAdjLsa); |
| 294 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 295 | // Run the scheduler to build an adjacency LSA |
| 296 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 297 | |
| 298 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 299 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
| 300 | BOOST_REQUIRE(lsa != nullptr); |
| 301 | |
| 302 | // Cancel previous LSA expiration event |
| 303 | g_scheduler.cancelEvent(lsa->getExpiringEventId()); |
| 304 | |
| 305 | // Set expiration time for own Adjacency LSA to earlier value for unit-test |
| 306 | // |
| 307 | // Expiration time is negative to offset the GRACE_PERIOD (10 seconds) automatically applied |
| 308 | // to expiration times |
| 309 | ndn::EventId id = lsdb.scheduleAdjLsaExpiration(key, lsa->getLsSeqNo(), -ndn::time::seconds(9)); |
| 310 | lsa->setExpiringEventId(id); |
| 311 | |
| 312 | // Generate a FaceEventDestroyed notification |
| 313 | ndn::nfd::FaceEventNotification event; |
| 314 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 315 | .setFaceId(destroyFaceId); |
| 316 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 317 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 318 | data->setContent(event.wireEncode()); |
| 319 | nlsr.getKeyChain().sign(*data); |
| 320 | |
| 321 | // Receive the FaceEventDestroyed notification |
| 322 | face->receive(*data); |
| 323 | |
| 324 | // Run the scheduler to expire the Adjacency LSA. The expiration should refresh the RIB |
| 325 | // entries associated with Neighbor B's advertised prefix. |
| 326 | face->sentInterests.clear(); |
| 327 | this->advanceClocks(ndn::time::seconds(1)); |
| 328 | |
| 329 | // The Face should have two sent Interests: the face event and a RIB registration |
| 330 | BOOST_REQUIRE(face->sentInterests.size() > 0); |
| 331 | const ndn::Interest& interest = face->sentInterests.back(); |
| 332 | |
| 333 | ndn::nfd::ControlParameters parameters; |
| 334 | ndn::Name::Component verb; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 335 | BOOST_REQUIRE_NO_THROW(extractRibCommandParameters(interest, |
| 336 | verb, |
| 337 | parameters)); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 338 | BOOST_CHECK_EQUAL(verb, ndn::Name::Component("register")); |
| 339 | BOOST_CHECK_EQUAL(parameters.getName(), nameToAdvertise); |
| 340 | } |
| 341 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 342 | BOOST_AUTO_TEST_CASE(GetCertificate) |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 343 | { |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 344 | // Create certificate |
| 345 | ndn::Name identity("/TestNLSR/identity"); |
| 346 | identity.appendVersion(); |
| 347 | |
| 348 | ndn::KeyChain keyChain; |
| 349 | keyChain.createIdentity(identity); |
| 350 | ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame^] | 351 | std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 352 | |
| 353 | const ndn::Name certKey = certificate->getName().getPrefix(-1); |
| 354 | |
| 355 | BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr); |
| 356 | |
| 357 | // Certificate should be retrievable from the CertificateStore |
| 358 | nlsr.loadCertToPublish(certificate); |
| 359 | |
| 360 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 361 | |
| 362 | nlsr.getCertificateStore().clear(); |
| 363 | |
| 364 | // Certificate should be retrievable from the cache |
| 365 | nlsr.addCertificateToCache(certificate); |
| 366 | this->advanceClocks(ndn::time::milliseconds(10)); |
| 367 | |
| 368 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 369 | } |
| 370 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 371 | BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix) |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 372 | { |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 373 | // Simulate loading configuration file |
| 374 | ConfParameter& conf = nlsr.getConfParameter(); |
| 375 | conf.setNetwork("/ndn"); |
| 376 | conf.setSiteName("/site"); |
| 377 | conf.setRouterName("/%C1.router/this-router"); |
| 378 | |
| 379 | nlsr.initialize(); |
| 380 | |
| 381 | BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(), |
| 382 | ndn::Name("/ndn/site/%C1.router/this-router/lsdb")); |
| 383 | } |
| 384 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 385 | BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse) |
| 386 | { |
| 387 | // Configure NLSR |
| 388 | ConfParameter& conf = nlsr.getConfParameter(); |
| 389 | conf.setNetwork("/ndn"); |
| 390 | conf.setSiteName("/site"); |
| 391 | |
| 392 | ndn::Name routerName("/%C1.Router/this-router"); |
| 393 | conf.setRouterName(routerName); |
| 394 | |
| 395 | conf.setAdjLsaBuildInterval(1); |
| 396 | |
| 397 | // Add neighbors |
| 398 | // Router A |
| 399 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
| 400 | Adjacent neighborA(neighborAName, "uri://faceA", 0, Adjacent::STATUS_INACTIVE, 0, 0); |
| 401 | neighbors.insert(neighborA); |
| 402 | |
| 403 | // Router B |
| 404 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
| 405 | Adjacent neighborB(neighborBName, "uri://faceA", 0, Adjacent::STATUS_INACTIVE, 0, 0); |
| 406 | neighbors.insert(neighborB); |
| 407 | |
| 408 | nlsr.initialize(); |
| 409 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 410 | |
| 411 | // Receive HELLO response from Router A |
| 412 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 413 | this->advanceClocks(ndn::time::seconds(1)); |
| 414 | |
| 415 | ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 416 | |
| 417 | // Adjacency LSA should be built even though other router is INACTIVE |
| 418 | AdjLsa* lsa = lsdb.findAdjLsa(lsaKey); |
| 419 | BOOST_REQUIRE(lsa != nullptr); |
| 420 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1); |
| 421 | |
| 422 | // Receive HELLO response from Router B |
| 423 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 424 | |
| 425 | // Both routers become INACTIVE and HELLO Interests have timed out |
| 426 | for (Adjacent& adjacency : neighbors.getAdjList()) { |
| 427 | adjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 428 | adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 429 | } |
| 430 | |
| 431 | this->advanceClocks(ndn::time::seconds(1)); |
| 432 | |
| 433 | // Adjacency LSA should have been removed since this router's adjacencies are INACTIVE |
| 434 | // and have timed out |
| 435 | lsa = lsdb.findAdjLsa(lsaKey); |
| 436 | BOOST_CHECK(lsa == nullptr); |
| 437 | |
| 438 | // Receive HELLO response from Router A and B |
| 439 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 440 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 441 | this->advanceClocks(ndn::time::seconds(1)); |
| 442 | |
| 443 | // Adjacency LSA should be built |
| 444 | lsa = lsdb.findAdjLsa(lsaKey); |
| 445 | BOOST_REQUIRE(lsa != nullptr); |
| 446 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2); |
| 447 | } |
| 448 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 449 | BOOST_AUTO_TEST_SUITE_END() |
| 450 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 451 | } // namespace test |
| 452 | } // namespace nlsr |