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 | 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 | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 319 | // Bug #2733 |
| 320 | // This test checks that when a face for an inactive node is destroyed, an |
| 321 | // Adjacency LSA build does not postpone the LSA refresh and cause RIB |
| 322 | // entries for other nodes' name prefixes to not be refreshed. |
| 323 | // |
| 324 | // This test is invalid when Issue #2732 is implemented since an Adjacency LSA |
| 325 | // refresh will not cause RIB entries for other nodes' name prefixes to be refreshed. |
| 326 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture) |
| 327 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 328 | std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService); |
| 329 | Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 330 | Lsdb& lsdb = nlsr.getLsdb(); |
| 331 | |
| 332 | // Simulate loading configuration file |
| 333 | ConfParameter& conf = nlsr.getConfParameter(); |
| 334 | conf.setNetwork("/ndn"); |
| 335 | conf.setSiteName("/site"); |
| 336 | conf.setRouterName("/%C1.router/this-router"); |
| 337 | conf.setFirstHelloInterval(0); |
| 338 | conf.setAdjLsaBuildInterval(0); |
| 339 | conf.setRoutingCalcInterval(0); |
| 340 | |
| 341 | // Add neighbors |
| 342 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
| 343 | |
| 344 | uint64_t destroyFaceId = 128; |
| 345 | |
| 346 | // Create an inactive neighbor whose Face will be destroyed |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 347 | Adjacent failNeighbor("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 10, Adjacent::STATUS_INACTIVE, 3, |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 348 | destroyFaceId); |
| 349 | neighbors.insert(failNeighbor); |
| 350 | |
| 351 | // Create an additional active neighbor so an adjacency LSA can be built |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 352 | Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 25, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 353 | neighbors.insert(otherNeighbor); |
| 354 | |
| 355 | // Add a name for the neighbor to advertise |
| 356 | NamePrefixList nameList; |
| 357 | ndn::Name nameToAdvertise("/ndn/neighborB/name"); |
| 358 | nameList.insert(nameToAdvertise); |
| 359 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 360 | NameLsa nameLsa("/ndn/neighborB", 25, ndn::time::system_clock::now(), nameList); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 361 | lsdb.installNameLsa(nameLsa); |
| 362 | |
| 363 | nlsr.initialize(); |
| 364 | |
| 365 | // Simulate successful HELLO responses from neighbor B |
| 366 | lsdb.scheduleAdjLsaBuild(); |
| 367 | |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 368 | // Set up adjacency LSAs |
| 369 | // This router |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 370 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.2"), 25, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 371 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 372 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 373 | lsdb.installAdjLsa(ownAdjLsa); |
| 374 | |
| 375 | // Other ACTIVE router |
| 376 | AdjacencyList otherAdjacencies; |
| 377 | otherAdjacencies.insert(thisRouter); |
| 378 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 379 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 380 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies); |
| 381 | |
| 382 | lsdb.installAdjLsa(otherAdjLsa); |
| 383 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 384 | // Run the scheduler to build an adjacency LSA |
| 385 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 386 | |
| 387 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 388 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
| 389 | BOOST_REQUIRE(lsa != nullptr); |
| 390 | |
| 391 | // Cancel previous LSA expiration event |
| 392 | g_scheduler.cancelEvent(lsa->getExpiringEventId()); |
| 393 | |
| 394 | // Set expiration time for own Adjacency LSA to earlier value for unit-test |
| 395 | // |
| 396 | // Expiration time is negative to offset the GRACE_PERIOD (10 seconds) automatically applied |
| 397 | // to expiration times |
| 398 | ndn::EventId id = lsdb.scheduleAdjLsaExpiration(key, lsa->getLsSeqNo(), -ndn::time::seconds(9)); |
| 399 | lsa->setExpiringEventId(id); |
| 400 | |
| 401 | // Generate a FaceEventDestroyed notification |
| 402 | ndn::nfd::FaceEventNotification event; |
| 403 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 404 | .setFaceId(destroyFaceId); |
| 405 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 406 | 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] | 407 | data->setContent(event.wireEncode()); |
| 408 | nlsr.getKeyChain().sign(*data); |
| 409 | |
| 410 | // Receive the FaceEventDestroyed notification |
| 411 | face->receive(*data); |
| 412 | |
| 413 | // Run the scheduler to expire the Adjacency LSA. The expiration should refresh the RIB |
| 414 | // entries associated with Neighbor B's advertised prefix. |
| 415 | face->sentInterests.clear(); |
| 416 | this->advanceClocks(ndn::time::seconds(1)); |
| 417 | |
| 418 | // The Face should have two sent Interests: the face event and a RIB registration |
| 419 | BOOST_REQUIRE(face->sentInterests.size() > 0); |
| 420 | const ndn::Interest& interest = face->sentInterests.back(); |
| 421 | |
| 422 | ndn::nfd::ControlParameters parameters; |
| 423 | ndn::Name::Component verb; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 424 | BOOST_REQUIRE_NO_THROW(extractRibCommandParameters(interest, |
| 425 | verb, |
| 426 | parameters)); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 427 | BOOST_CHECK_EQUAL(verb, ndn::Name::Component("register")); |
| 428 | BOOST_CHECK_EQUAL(parameters.getName(), nameToAdvertise); |
| 429 | } |
| 430 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 431 | BOOST_AUTO_TEST_CASE(GetCertificate) |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 432 | { |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 433 | // Create certificate |
| 434 | ndn::Name identity("/TestNLSR/identity"); |
| 435 | identity.appendVersion(); |
| 436 | |
| 437 | ndn::KeyChain keyChain; |
| 438 | keyChain.createIdentity(identity); |
| 439 | ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 440 | std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 441 | |
| 442 | const ndn::Name certKey = certificate->getName().getPrefix(-1); |
| 443 | |
| 444 | BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr); |
| 445 | |
| 446 | // Certificate should be retrievable from the CertificateStore |
| 447 | nlsr.loadCertToPublish(certificate); |
| 448 | |
| 449 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 450 | |
| 451 | nlsr.getCertificateStore().clear(); |
| 452 | |
| 453 | // Certificate should be retrievable from the cache |
| 454 | nlsr.addCertificateToCache(certificate); |
| 455 | this->advanceClocks(ndn::time::milliseconds(10)); |
| 456 | |
| 457 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 458 | } |
| 459 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 460 | BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix) |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 461 | { |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 462 | // Simulate loading configuration file |
| 463 | ConfParameter& conf = nlsr.getConfParameter(); |
| 464 | conf.setNetwork("/ndn"); |
| 465 | conf.setSiteName("/site"); |
| 466 | conf.setRouterName("/%C1.router/this-router"); |
| 467 | |
| 468 | nlsr.initialize(); |
| 469 | |
| 470 | BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(), |
| 471 | ndn::Name("/ndn/site/%C1.router/this-router/lsdb")); |
| 472 | } |
| 473 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 474 | BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse) |
| 475 | { |
| 476 | // Configure NLSR |
| 477 | ConfParameter& conf = nlsr.getConfParameter(); |
| 478 | conf.setNetwork("/ndn"); |
| 479 | conf.setSiteName("/site"); |
| 480 | |
| 481 | ndn::Name routerName("/%C1.Router/this-router"); |
| 482 | conf.setRouterName(routerName); |
| 483 | |
| 484 | conf.setAdjLsaBuildInterval(1); |
| 485 | |
| 486 | // Add neighbors |
| 487 | // Router A |
| 488 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 489 | 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] | 490 | neighbors.insert(neighborA); |
| 491 | |
| 492 | // Router B |
| 493 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 494 | 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] | 495 | neighbors.insert(neighborB); |
| 496 | |
| 497 | nlsr.initialize(); |
| 498 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 499 | |
| 500 | // Receive HELLO response from Router A |
| 501 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 502 | this->advanceClocks(ndn::time::seconds(1)); |
| 503 | |
| 504 | ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 505 | |
| 506 | // Adjacency LSA should be built even though other router is INACTIVE |
| 507 | AdjLsa* lsa = lsdb.findAdjLsa(lsaKey); |
| 508 | BOOST_REQUIRE(lsa != nullptr); |
| 509 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1); |
| 510 | |
| 511 | // Receive HELLO response from Router B |
| 512 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 513 | |
| 514 | // Both routers become INACTIVE and HELLO Interests have timed out |
| 515 | for (Adjacent& adjacency : neighbors.getAdjList()) { |
| 516 | adjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 517 | adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 518 | } |
| 519 | |
| 520 | this->advanceClocks(ndn::time::seconds(1)); |
| 521 | |
| 522 | // Adjacency LSA should have been removed since this router's adjacencies are INACTIVE |
| 523 | // and have timed out |
| 524 | lsa = lsdb.findAdjLsa(lsaKey); |
| 525 | BOOST_CHECK(lsa == nullptr); |
| 526 | |
| 527 | // Receive HELLO response from Router A and B |
| 528 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 529 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 530 | this->advanceClocks(ndn::time::seconds(1)); |
| 531 | |
| 532 | // Adjacency LSA should be built |
| 533 | lsa = lsdb.findAdjLsa(lsaKey); |
| 534 | BOOST_REQUIRE(lsa != nullptr); |
| 535 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2); |
| 536 | } |
| 537 | |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 538 | BOOST_AUTO_TEST_CASE(CanonizeUris) |
| 539 | { |
| 540 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 541 | ndn::util::FaceUri faceUriA("udp://10.0.0.1"); |
| 542 | Adjacent neighborA(neighborAName, faceUriA, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 543 | neighbors.insert(neighborA); |
| 544 | |
| 545 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 546 | ndn::util::FaceUri faceUriB("udp://10.0.0.2"); |
| 547 | Adjacent neighborB(neighborBName, faceUriB, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 548 | neighbors.insert(neighborB); |
| 549 | |
| 550 | int nCanonizationsLeft = nlsr.getAdjacencyList().getAdjList().size(); |
| 551 | std::function<void(std::list<Adjacent>::iterator)> thenCallback = |
| 552 | [this, &thenCallback, &nCanonizationsLeft] (std::list<Adjacent>::iterator iterator) { |
| 553 | nCanonizationsLeft--; |
| 554 | nlsr.canonizeNeighborUris(iterator, thenCallback); |
| 555 | }; |
| 556 | nlsr.canonizeNeighborUris(nlsr.getAdjacencyList().getAdjList().begin(), |
| 557 | [thenCallback] (std::list<Adjacent>::iterator iterator) { |
| 558 | thenCallback(iterator); |
| 559 | }); |
| 560 | while (nCanonizationsLeft != 0) { |
| 561 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 562 | } |
| 563 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 564 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborAName).getFaceUri(), |
| 565 | ndn::util::FaceUri("udp4://10.0.0.1:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 566 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 567 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborBName).getFaceUri(), |
| 568 | ndn::util::FaceUri("udp4://10.0.0.2:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 569 | } |
| 570 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame^] | 571 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess) |
| 572 | { |
| 573 | bool hasResult = false; |
| 574 | nlsr.m_validator.m_shouldValidate = false; |
| 575 | |
| 576 | nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) { |
| 577 | hasResult = true; |
| 578 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 579 | BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401); |
| 580 | BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402); |
| 581 | }, |
| 582 | [] (uint32_t code, const std::string& reason) {}); |
| 583 | |
| 584 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 585 | |
| 586 | ndn::nfd::FaceStatus payload1; |
| 587 | payload1.setFaceId(25401); |
| 588 | ndn::nfd::FaceStatus payload2; |
| 589 | payload2.setFaceId(25402); |
| 590 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
| 591 | |
| 592 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 593 | BOOST_CHECK(hasResult); |
| 594 | } |
| 595 | |
| 596 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure) |
| 597 | { |
| 598 | nlsr.m_validator.m_shouldValidate = false; |
| 599 | nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {}, |
| 600 | [this](uint32_t code, const std::string& reason){ |
| 601 | this->nFailureCallbacks++; |
| 602 | }); |
| 603 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 604 | |
| 605 | ndn::Name payload; |
| 606 | this->sendDataset("/localhost/nfd/faces/list", payload); |
| 607 | this->advanceClocks(ndn::time::milliseconds(500)); |
| 608 | |
| 609 | BOOST_CHECK_EQUAL(nFailureCallbacks, 1); |
| 610 | BOOST_CHECK_EQUAL(nSuccessCallbacks, 0); |
| 611 | } |
| 612 | |
| 613 | BOOST_AUTO_TEST_CASE(FaceDatasetProcess) |
| 614 | { |
| 615 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 616 | neighbors.insert(neighborA); |
| 617 | |
| 618 | Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://192.168.0.101:6363"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 619 | neighbors.insert(neighborB); |
| 620 | |
| 621 | ndn::nfd::FaceStatus payload1; |
| 622 | payload1.setFaceId(1) |
| 623 | .setRemoteUri("udp4://192.168.0.100:6363"); |
| 624 | ndn::nfd::FaceStatus payload2; |
| 625 | payload2.setFaceId(2) |
| 626 | .setRemoteUri("udp4://192.168.0.101:6363"); |
| 627 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2}; |
| 628 | |
| 629 | nlsr.processFaceDataset(faceStatuses); |
| 630 | this->advanceClocks(ndn::time::milliseconds(100)); |
| 631 | |
| 632 | AdjacencyList adjList = nlsr.getAdjacencyList(); |
| 633 | |
| 634 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId()); |
| 635 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId()); |
| 636 | } |
| 637 | |
| 638 | BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor) |
| 639 | { |
| 640 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 641 | neighbors.insert(neighborA); |
| 642 | |
| 643 | ndn::nfd::FaceStatus payload; |
| 644 | payload.setFaceId(1) |
| 645 | .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI. |
| 646 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload}; |
| 647 | |
| 648 | nlsr.processFaceDataset(faceStatuses); |
| 649 | this->advanceClocks(ndn::time::milliseconds(100)); |
| 650 | |
| 651 | AdjacencyList adjList = nlsr.getAdjacencyList(); |
| 652 | |
| 653 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0); |
| 654 | } |
| 655 | |
| 656 | BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch) |
| 657 | { |
| 658 | int nNameMatches = 0; |
| 659 | ndn::Name datasetPrefix("/localhost/nfd/faces/list"); |
| 660 | ndn::nfd::CommandOptions options; |
| 661 | ndn::time::milliseconds defaultTimeout = options.getTimeout(); |
| 662 | |
| 663 | ndn::time::seconds fetchInterval(1); |
| 664 | ConfParameter& conf = nlsr.getConfParameter(); |
| 665 | conf.setFaceDatasetFetchInterval(fetchInterval); |
| 666 | conf.setFaceDatasetFetchTries(0); |
| 667 | |
| 668 | nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1), |
| 669 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0)); |
| 670 | |
| 671 | // Elapse the default timeout time of the interest. |
| 672 | this->advanceClocks(defaultTimeout); |
| 673 | |
| 674 | // Check that we have one interest for face list in the sent interests. |
| 675 | for (const ndn::Interest& interest : face->sentInterests) { |
| 676 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 677 | nNameMatches++; |
| 678 | } |
| 679 | } |
| 680 | BOOST_CHECK_EQUAL(nNameMatches, 1); |
| 681 | |
| 682 | // Elapse the clock by the reschedule time (that we set) |
| 683 | this->advanceClocks(fetchInterval); |
| 684 | // Elapse the default timeout on the interest. |
| 685 | this->advanceClocks(defaultTimeout); |
| 686 | // Plus a little more to let the events process. |
| 687 | this->advanceClocks(ndn::time::seconds(1)); |
| 688 | |
| 689 | // Check that we now have two interests |
| 690 | nNameMatches = 0; |
| 691 | for (const ndn::Interest& interest : face->sentInterests) { |
| 692 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 693 | nNameMatches++; |
| 694 | } |
| 695 | } |
| 696 | BOOST_CHECK_EQUAL(nNameMatches, 2); |
| 697 | } |
| 698 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 699 | BOOST_AUTO_TEST_SUITE_END() |
| 700 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 701 | } // namespace test |
| 702 | } // namespace nlsr |