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