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