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