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 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 22 | #include "nlsr.hpp" |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 23 | #include "test-common.hpp" |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 24 | #include "control-commands.hpp" |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 25 | #include "logger.hpp" |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 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 | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 28 | |
| 29 | namespace nlsr { |
| 30 | namespace test { |
| 31 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 32 | using std::shared_ptr; |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 33 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 34 | class NlsrFixture : public MockNfdMgmtFixture |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | NlsrFixture() |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 38 | : nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 39 | , lsdb(nlsr.getLsdb()) |
| 40 | , neighbors(nlsr.getAdjacencyList()) |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 41 | , nSuccessCallbacks(0) |
| 42 | , nFailureCallbacks(0) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 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); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 55 | } |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 56 | |
| 57 | public: |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 58 | Nlsr nlsr; |
| 59 | Lsdb& lsdb; |
| 60 | AdjacencyList& neighbors; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 61 | uint32_t nSuccessCallbacks; |
| 62 | uint32_t nFailureCallbacks; |
| 63 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture) |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 67 | |
| 68 | BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors) |
| 69 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 70 | // Simulate loading configuration file |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 71 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 72 | neighbors.insert(neighborA); |
| 73 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 74 | Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 75 | neighbors.insert(neighborB); |
| 76 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 77 | Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 78 | neighbors.insert(neighborC); |
| 79 | |
| 80 | nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 81 | nlsr.getConfParameter().setNetwork(ndn::Name("/test")); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 82 | |
| 83 | nlsr.initialize(); |
| 84 | |
| 85 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 86 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 87 | BOOST_CHECK_EQUAL(it->getLinkCost(), 0); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost) |
| 92 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 93 | // Simulate loading configuration file |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 94 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 95 | neighbors.insert(neighborA); |
| 96 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 97 | Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 98 | neighbors.insert(neighborB); |
| 99 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 100 | Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 101 | neighbors.insert(neighborC); |
| 102 | |
| 103 | nlsr.initialize(); |
| 104 | |
| 105 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 106 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 107 | BOOST_CHECK(it->getLinkCost() != 0); |
| 108 | } |
| 109 | } |
| 110 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 111 | BOOST_AUTO_TEST_CASE(SetEventIntervals) |
| 112 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 113 | // Simulate loading configuration file |
| 114 | ConfParameter& conf = nlsr.getConfParameter(); |
| 115 | conf.setAdjLsaBuildInterval(3); |
| 116 | conf.setFirstHelloInterval(6); |
| 117 | conf.setRoutingCalcInterval(9); |
| 118 | |
| 119 | nlsr.initialize(); |
| 120 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 121 | const Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 122 | const RoutingTable& rt = nlsr.getRoutingTable(); |
| 123 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL(lsdb.getAdjLsaBuildInterval(), ndn::time::seconds(3)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 125 | BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6); |
| 126 | BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9)); |
| 127 | } |
| 128 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 129 | BOOST_AUTO_TEST_CASE(FaceCreateEvent) |
| 130 | { |
| 131 | // Setting constants for the unit test |
| 132 | const uint32_t faceId = 1; |
| 133 | const std::string faceUri = "udp4://10.0.0.1:6363"; |
| 134 | Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(faceUri), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 135 | BOOST_REQUIRE_EQUAL(nlsr.getAdjacencyList().insert(neighbor), 0); |
| 136 | |
| 137 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 138 | |
| 139 | // Build, sign, and send the Face Event |
| 140 | ndn::nfd::FaceEventNotification event; |
| 141 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 142 | .setRemoteUri(faceUri) |
| 143 | .setFaceId(faceId); |
| 144 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
| 145 | data->setContent(event.wireEncode()); |
| 146 | nlsr.getKeyChain().sign(*data); |
| 147 | face->receive(*data); |
| 148 | |
| 149 | // Move the clocks forward so that the Face processes the event. |
| 150 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 151 | |
| 152 | // Need to explicitly provide a FaceUri object, because the |
| 153 | // conversion will attempt to create Name objects. |
| 154 | auto iterator = nlsr.getAdjacencyList().findAdjacent(ndn::util::FaceUri(faceUri)); |
| 155 | BOOST_REQUIRE(iterator != nlsr.getAdjacencyList().end()); |
| 156 | BOOST_CHECK_EQUAL(iterator->getFaceId(), faceId); |
| 157 | } |
| 158 | |
| 159 | BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch) |
| 160 | { |
| 161 | // Setting constants for the unit test |
| 162 | const uint32_t faceId = 1; |
| 163 | const std::string eventUri = "udp4://10.0.0.1:6363"; |
| 164 | const std::string neighborUri = "udp4://10.0.0.2:6363"; |
| 165 | Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(neighborUri), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 166 | nlsr.getAdjacencyList().insert(neighbor); |
| 167 | |
| 168 | // Build, sign, and send the Face Event |
| 169 | ndn::nfd::FaceEventNotification event; |
| 170 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 171 | .setRemoteUri(eventUri) |
| 172 | .setFaceId(faceId); |
| 173 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
| 174 | data->setContent(event.wireEncode()); |
| 175 | nlsr.getKeyChain().sign(*data); |
| 176 | face->receive(*data); |
| 177 | |
| 178 | // Move the clocks forward so that the Face processes the event. |
| 179 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 180 | |
| 181 | // The Face URIs did not match, so this neighbor should be unconfigured. |
| 182 | auto iterator = nlsr.getAdjacencyList().findAdjacent(ndn::util::FaceUri(neighborUri)); |
| 183 | BOOST_REQUIRE(iterator != nlsr.getAdjacencyList().end()); |
| 184 | BOOST_CHECK_EQUAL(iterator->getFaceId(), 0); |
| 185 | } |
| 186 | |
| 187 | BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured) |
| 188 | { |
| 189 | // Setting constants for the unit test |
| 190 | const uint32_t eventFaceId = 1; |
| 191 | const uint32_t neighborFaceId = 2; |
| 192 | const std::string faceUri = "udp4://10.0.0.1:6363"; |
| 193 | Adjacent neighbor("/ndn/neighborA", ndn::util::FaceUri(faceUri), 10, Adjacent::STATUS_ACTIVE, 0, neighborFaceId); |
| 194 | nlsr.getAdjacencyList().insert(neighbor); |
| 195 | |
| 196 | // Build, sign, and send the Face Event |
| 197 | ndn::nfd::FaceEventNotification event; |
| 198 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 199 | .setRemoteUri(faceUri) |
| 200 | .setFaceId(eventFaceId); |
| 201 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
| 202 | data->setContent(event.wireEncode()); |
| 203 | nlsr.getKeyChain().sign(*data); |
| 204 | face->receive(*data); |
| 205 | |
| 206 | // Move the clocks forward so that the Face processes the event. |
| 207 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 208 | |
| 209 | // Since the neighbor was already configured, this (simply erroneous) event should have no effect. |
| 210 | auto iterator = nlsr.getAdjacencyList().findAdjacent(ndn::util::FaceUri(faceUri)); |
| 211 | BOOST_REQUIRE(iterator != nlsr.getAdjacencyList().end()); |
| 212 | BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId); |
| 213 | } |
| 214 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 215 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture) |
| 216 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 217 | std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService); |
| 218 | Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 219 | Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 220 | |
| 221 | // Simulate loading configuration file |
| 222 | ConfParameter& conf = nlsr.getConfParameter(); |
| 223 | conf.setNetwork("/ndn"); |
| 224 | conf.setSiteName("/site"); |
| 225 | conf.setRouterName("/%C1.router/this-router"); |
| 226 | conf.setAdjLsaBuildInterval(0); |
| 227 | conf.setRoutingCalcInterval(0); |
| 228 | |
| 229 | // Add active neighbors |
| 230 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 231 | uint64_t destroyFaceId = 128; |
| 232 | |
| 233 | // Create a neighbor whose Face will be destroyed |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 234 | Adjacent failNeighbor("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 10, Adjacent::STATUS_ACTIVE, 0, |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 235 | destroyFaceId); |
| 236 | neighbors.insert(failNeighbor); |
| 237 | |
| 238 | // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 239 | Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 240 | neighbors.insert(otherNeighbor); |
| 241 | |
| 242 | nlsr.initialize(); |
| 243 | |
| 244 | // Simulate successful HELLO responses |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 245 | lsdb.scheduleAdjLsaBuild(); |
| 246 | |
| 247 | // Set up adjacency LSAs |
| 248 | // This router |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 249 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.3"), 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 250 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 251 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 252 | lsdb.installAdjLsa(ownAdjLsa); |
| 253 | |
| 254 | // Router that will fail |
| 255 | AdjacencyList failAdjacencies; |
| 256 | failAdjacencies.insert(thisRouter); |
| 257 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 258 | AdjLsa failAdjLsa("/ndn/neighborA", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 259 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, failAdjacencies); |
| 260 | |
| 261 | lsdb.installAdjLsa(failAdjLsa); |
| 262 | |
| 263 | // Other router |
| 264 | AdjacencyList otherAdjacencies; |
| 265 | otherAdjacencies.insert(thisRouter); |
| 266 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 267 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 268 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies); |
| 269 | |
| 270 | lsdb.installAdjLsa(otherAdjLsa); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 271 | |
| 272 | // Run the scheduler to build an adjacency LSA |
| 273 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 274 | |
| 275 | // Make sure an adjacency LSA was built |
| 276 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 277 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 278 | BOOST_REQUIRE(lsa != nullptr); |
| 279 | |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 280 | uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 281 | nlsr.getLsdb().getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 282 | |
| 283 | // Make sure the routing table was calculated |
| 284 | RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 285 | BOOST_REQUIRE(rtEntry != nullptr); |
| 286 | BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().getSize(), 1); |
| 287 | |
| 288 | // Receive FaceEventDestroyed notification |
| 289 | ndn::nfd::FaceEventNotification event; |
| 290 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 291 | .setFaceId(destroyFaceId); |
| 292 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 293 | 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] | 294 | data->setContent(event.wireEncode()); |
| 295 | nlsr.getKeyChain().sign(*data); |
| 296 | |
| 297 | face->receive(*data); |
| 298 | |
| 299 | // Run the scheduler to build an adjacency LSA |
| 300 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 301 | |
| 302 | Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName()); |
| 303 | |
| 304 | BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0); |
| 305 | BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(), |
| 306 | nlsr.getConfParameter().getInterestRetryNumber()); |
| 307 | BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE); |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 308 | |
| 309 | lsa = lsdb.findAdjLsa(key); |
| 310 | BOOST_REQUIRE(lsa != nullptr); |
| 311 | |
| 312 | BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 313 | |
| 314 | // Make sure the routing table was recalculated |
| 315 | rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 316 | BOOST_CHECK(rtEntry == nullptr); |
| 317 | } |
| 318 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 319 | BOOST_AUTO_TEST_CASE(GetCertificate) |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 320 | { |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 321 | // Create certificate |
| 322 | ndn::Name identity("/TestNLSR/identity"); |
| 323 | identity.appendVersion(); |
| 324 | |
| 325 | ndn::KeyChain keyChain; |
| 326 | keyChain.createIdentity(identity); |
| 327 | ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 328 | std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 329 | |
| 330 | const ndn::Name certKey = certificate->getName().getPrefix(-1); |
| 331 | |
| 332 | BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr); |
| 333 | |
| 334 | // Certificate should be retrievable from the CertificateStore |
| 335 | nlsr.loadCertToPublish(certificate); |
| 336 | |
| 337 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 338 | |
| 339 | nlsr.getCertificateStore().clear(); |
| 340 | |
| 341 | // Certificate should be retrievable from the cache |
| 342 | nlsr.addCertificateToCache(certificate); |
| 343 | this->advanceClocks(ndn::time::milliseconds(10)); |
| 344 | |
| 345 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 346 | } |
| 347 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 348 | BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix) |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 349 | { |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 350 | // Simulate loading configuration file |
| 351 | ConfParameter& conf = nlsr.getConfParameter(); |
| 352 | conf.setNetwork("/ndn"); |
| 353 | conf.setSiteName("/site"); |
| 354 | conf.setRouterName("/%C1.router/this-router"); |
| 355 | |
| 356 | nlsr.initialize(); |
| 357 | |
| 358 | BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(), |
| 359 | ndn::Name("/ndn/site/%C1.router/this-router/lsdb")); |
| 360 | } |
| 361 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 362 | BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse) |
| 363 | { |
| 364 | // Configure NLSR |
| 365 | ConfParameter& conf = nlsr.getConfParameter(); |
| 366 | conf.setNetwork("/ndn"); |
| 367 | conf.setSiteName("/site"); |
| 368 | |
| 369 | ndn::Name routerName("/%C1.Router/this-router"); |
| 370 | conf.setRouterName(routerName); |
| 371 | |
| 372 | conf.setAdjLsaBuildInterval(1); |
| 373 | |
| 374 | // Add neighbors |
| 375 | // Router A |
| 376 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 377 | Adjacent neighborA(neighborAName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 378 | neighbors.insert(neighborA); |
| 379 | |
| 380 | // Router B |
| 381 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 382 | Adjacent neighborB(neighborBName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 383 | neighbors.insert(neighborB); |
| 384 | |
| 385 | nlsr.initialize(); |
| 386 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 387 | |
| 388 | // Receive HELLO response from Router A |
| 389 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 390 | this->advanceClocks(ndn::time::seconds(1)); |
| 391 | |
| 392 | ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 393 | |
| 394 | // Adjacency LSA should be built even though other router is INACTIVE |
| 395 | AdjLsa* lsa = lsdb.findAdjLsa(lsaKey); |
| 396 | BOOST_REQUIRE(lsa != nullptr); |
| 397 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1); |
| 398 | |
| 399 | // Receive HELLO response from Router B |
| 400 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 401 | |
| 402 | // Both routers become INACTIVE and HELLO Interests have timed out |
| 403 | for (Adjacent& adjacency : neighbors.getAdjList()) { |
| 404 | adjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 405 | adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 406 | } |
| 407 | |
| 408 | this->advanceClocks(ndn::time::seconds(1)); |
| 409 | |
| 410 | // Adjacency LSA should have been removed since this router's adjacencies are INACTIVE |
| 411 | // and have timed out |
| 412 | lsa = lsdb.findAdjLsa(lsaKey); |
| 413 | BOOST_CHECK(lsa == nullptr); |
| 414 | |
| 415 | // Receive HELLO response from Router A and B |
| 416 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 417 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 418 | this->advanceClocks(ndn::time::seconds(1)); |
| 419 | |
| 420 | // Adjacency LSA should be built |
| 421 | lsa = lsdb.findAdjLsa(lsaKey); |
| 422 | BOOST_REQUIRE(lsa != nullptr); |
| 423 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2); |
| 424 | } |
| 425 | |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 426 | BOOST_AUTO_TEST_CASE(CanonizeUris) |
| 427 | { |
| 428 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 429 | ndn::util::FaceUri faceUriA("udp://10.0.0.1"); |
| 430 | Adjacent neighborA(neighborAName, faceUriA, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 431 | neighbors.insert(neighborA); |
| 432 | |
| 433 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 434 | ndn::util::FaceUri faceUriB("udp://10.0.0.2"); |
| 435 | Adjacent neighborB(neighborBName, faceUriB, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 436 | neighbors.insert(neighborB); |
| 437 | |
| 438 | int nCanonizationsLeft = nlsr.getAdjacencyList().getAdjList().size(); |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 439 | std::function<void(void)> finallyCallback = [this] { |
| 440 | nlsr.initialize(); |
| 441 | }; |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 442 | std::function<void(std::list<Adjacent>::iterator)> thenCallback = |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 443 | [this, &thenCallback, &finallyCallback, &nCanonizationsLeft] (std::list<Adjacent>::iterator iterator) { |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 444 | nCanonizationsLeft--; |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 445 | nlsr.canonizeNeighborUris(iterator, thenCallback, finallyCallback); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 446 | }; |
| 447 | nlsr.canonizeNeighborUris(nlsr.getAdjacencyList().getAdjList().begin(), |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 448 | [&thenCallback, &finallyCallback] (std::list<Adjacent>::iterator iterator) { |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 449 | thenCallback(iterator); |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 450 | }, |
| 451 | finallyCallback); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 452 | while (nCanonizationsLeft != 0) { |
| 453 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 454 | } |
| 455 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 456 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborAName).getFaceUri(), |
| 457 | ndn::util::FaceUri("udp4://10.0.0.1:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 458 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 459 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborBName).getFaceUri(), |
| 460 | ndn::util::FaceUri("udp4://10.0.0.2:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 461 | } |
| 462 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 463 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess) |
| 464 | { |
| 465 | bool hasResult = false; |
| 466 | nlsr.m_validator.m_shouldValidate = false; |
| 467 | |
| 468 | nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) { |
| 469 | hasResult = true; |
| 470 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 471 | BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401); |
| 472 | BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402); |
| 473 | }, |
| 474 | [] (uint32_t code, const std::string& reason) {}); |
| 475 | |
| 476 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 477 | |
| 478 | ndn::nfd::FaceStatus payload1; |
| 479 | payload1.setFaceId(25401); |
| 480 | ndn::nfd::FaceStatus payload2; |
| 481 | payload2.setFaceId(25402); |
| 482 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
| 483 | |
| 484 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 485 | BOOST_CHECK(hasResult); |
| 486 | } |
| 487 | |
| 488 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure) |
| 489 | { |
| 490 | nlsr.m_validator.m_shouldValidate = false; |
| 491 | nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {}, |
| 492 | [this](uint32_t code, const std::string& reason){ |
| 493 | this->nFailureCallbacks++; |
| 494 | }); |
| 495 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 496 | |
| 497 | ndn::Name payload; |
| 498 | this->sendDataset("/localhost/nfd/faces/list", payload); |
| 499 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 500 | |
| 501 | BOOST_CHECK_EQUAL(nFailureCallbacks, 1); |
| 502 | BOOST_CHECK_EQUAL(nSuccessCallbacks, 0); |
| 503 | } |
| 504 | |
| 505 | BOOST_AUTO_TEST_CASE(FaceDatasetProcess) |
| 506 | { |
| 507 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 508 | neighbors.insert(neighborA); |
| 509 | |
| 510 | Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://192.168.0.101:6363"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 511 | neighbors.insert(neighborB); |
| 512 | |
| 513 | ndn::nfd::FaceStatus payload1; |
| 514 | payload1.setFaceId(1) |
| 515 | .setRemoteUri("udp4://192.168.0.100:6363"); |
| 516 | ndn::nfd::FaceStatus payload2; |
| 517 | payload2.setFaceId(2) |
| 518 | .setRemoteUri("udp4://192.168.0.101:6363"); |
| 519 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2}; |
| 520 | |
| 521 | nlsr.processFaceDataset(faceStatuses); |
| 522 | this->advanceClocks(ndn::time::milliseconds(100)); |
| 523 | |
| 524 | AdjacencyList adjList = nlsr.getAdjacencyList(); |
| 525 | |
| 526 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId()); |
| 527 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId()); |
| 528 | } |
| 529 | |
| 530 | BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor) |
| 531 | { |
| 532 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 533 | neighbors.insert(neighborA); |
| 534 | |
| 535 | ndn::nfd::FaceStatus payload; |
| 536 | payload.setFaceId(1) |
| 537 | .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI. |
| 538 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload}; |
| 539 | |
| 540 | nlsr.processFaceDataset(faceStatuses); |
| 541 | this->advanceClocks(ndn::time::milliseconds(100)); |
| 542 | |
| 543 | AdjacencyList adjList = nlsr.getAdjacencyList(); |
| 544 | |
| 545 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0); |
| 546 | } |
| 547 | |
| 548 | BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch) |
| 549 | { |
| 550 | int nNameMatches = 0; |
| 551 | ndn::Name datasetPrefix("/localhost/nfd/faces/list"); |
| 552 | ndn::nfd::CommandOptions options; |
| 553 | ndn::time::milliseconds defaultTimeout = options.getTimeout(); |
| 554 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 555 | int fetchInterval(1); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 556 | ConfParameter& conf = nlsr.getConfParameter(); |
| 557 | conf.setFaceDatasetFetchInterval(fetchInterval); |
| 558 | conf.setFaceDatasetFetchTries(0); |
| 559 | |
| 560 | nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1), |
| 561 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0)); |
| 562 | |
| 563 | // Elapse the default timeout time of the interest. |
| 564 | this->advanceClocks(defaultTimeout); |
| 565 | |
| 566 | // Check that we have one interest for face list in the sent interests. |
| 567 | for (const ndn::Interest& interest : face->sentInterests) { |
| 568 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 569 | nNameMatches++; |
| 570 | } |
| 571 | } |
| 572 | BOOST_CHECK_EQUAL(nNameMatches, 1); |
| 573 | |
| 574 | // Elapse the clock by the reschedule time (that we set) |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 575 | this->advanceClocks(ndn::time::seconds(fetchInterval)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 576 | // Elapse the default timeout on the interest. |
| 577 | this->advanceClocks(defaultTimeout); |
| 578 | // Plus a little more to let the events process. |
| 579 | this->advanceClocks(ndn::time::seconds(1)); |
| 580 | |
| 581 | // Check that we now have two interests |
| 582 | nNameMatches = 0; |
| 583 | for (const ndn::Interest& interest : face->sentInterests) { |
| 584 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 585 | nNameMatches++; |
| 586 | } |
| 587 | } |
| 588 | BOOST_CHECK_EQUAL(nNameMatches, 2); |
| 589 | } |
| 590 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 591 | BOOST_AUTO_TEST_SUITE_END() |
| 592 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 593 | } // namespace test |
| 594 | } // namespace nlsr |