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