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 | /* |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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" |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 23 | #include "logger.hpp" |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 24 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 25 | #include "tests/io-key-chain-fixture.hpp" |
| 26 | #include "tests/test-common.hpp" |
| 27 | |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 28 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 33 | class MockNfdMgmtFixture : public IoKeyChainFixture |
| 34 | { |
| 35 | public: |
| 36 | /** \brief send one WireEncodable in reply to StatusDataset request |
| 37 | * \param prefix dataset prefix without version and segment |
| 38 | * \param payload payload block |
| 39 | * \note payload must fit in one Data |
| 40 | * \pre Interest for dataset has been expressed, sendDataset has not been invoked |
| 41 | */ |
| 42 | template<typename T> |
| 43 | void |
| 44 | sendDataset(const ndn::Name& prefix, const T& payload) |
| 45 | { |
| 46 | BOOST_CONCEPT_ASSERT((ndn::WireEncodable<T>)); |
| 47 | |
| 48 | this->sendDatasetReply(prefix, payload.wireEncode()); |
| 49 | } |
| 50 | |
| 51 | /** \brief send two WireEncodables in reply to StatusDataset request |
| 52 | * \param prefix dataset prefix without version and segment |
| 53 | * \param payload1 first vector item |
| 54 | * \param payload2 second vector item |
| 55 | * \note all payloads must fit in one Data |
| 56 | * \pre Interest for dataset has been expressed, sendDataset has not been invoked |
| 57 | */ |
| 58 | template<typename T1, typename T2> |
| 59 | void |
| 60 | sendDataset(const ndn::Name& prefix, const T1& payload1, const T2& payload2) |
| 61 | { |
| 62 | BOOST_CONCEPT_ASSERT((ndn::WireEncodable<T1>)); |
| 63 | BOOST_CONCEPT_ASSERT((ndn::WireEncodable<T2>)); |
| 64 | |
| 65 | ndn::encoding::EncodingBuffer buffer; |
| 66 | payload2.wireEncode(buffer); |
| 67 | payload1.wireEncode(buffer); |
| 68 | |
| 69 | this->sendDatasetReply(prefix, buffer); |
| 70 | } |
| 71 | |
| 72 | /** \brief send a payload in reply to StatusDataset request |
| 73 | * \param name dataset prefix without version and segment |
| 74 | * \param contentArgs passed to Data::setContent |
| 75 | */ |
| 76 | template<typename ...ContentArgs> |
| 77 | void |
| 78 | sendDatasetReply(ndn::Name name, ContentArgs&&... contentArgs) |
| 79 | { |
| 80 | name.appendVersion().appendSegment(0); |
| 81 | |
| 82 | // These warnings assist in debugging when nfdc does not receive StatusDataset. |
| 83 | // They usually indicate a misspelled prefix or incorrect timing in the test case. |
| 84 | if (m_face.sentInterests.empty()) { |
| 85 | BOOST_WARN_MESSAGE(false, "no Interest expressed"); |
| 86 | } |
| 87 | else { |
| 88 | BOOST_WARN_MESSAGE(m_face.sentInterests.back().getName().isPrefixOf(name), |
| 89 | "last Interest " << m_face.sentInterests.back().getName() << |
| 90 | " cannot be satisfied by this Data " << name); |
| 91 | } |
| 92 | |
| 93 | auto data = std::make_shared<ndn::Data>(name); |
| 94 | data->setFreshnessPeriod(1_s); |
| 95 | data->setFinalBlock(name[-1]); |
| 96 | data->setContent(std::forward<ContentArgs>(contentArgs)...); |
| 97 | signData(*data); |
| 98 | m_face.receive(*data); |
| 99 | } |
| 100 | |
| 101 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 102 | ndn::DummyClientFace m_face{m_io, m_keyChain, {true, true}}; |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 103 | }; |
| 104 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 105 | class NlsrFixture : public MockNfdMgmtFixture |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 106 | { |
| 107 | public: |
| 108 | NlsrFixture() |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 109 | : conf(m_face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 110 | , confProcessor(conf) |
| 111 | , nlsr(m_face, m_keyChain, conf) |
| 112 | , lsdb(nlsr.m_lsdb) |
| 113 | , neighbors(conf.getAdjacencyList()) |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 114 | , nSuccessCallbacks(0) |
| 115 | , nFailureCallbacks(0) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 116 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 117 | m_keyChain.createIdentity(conf.getRouterPrefix()); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
| 121 | receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver) |
| 122 | { |
| 123 | ndn::Name dataName(sender); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 124 | dataName.append("NLSR") |
| 125 | .append("INFO") |
| 126 | .append(ndn::tlv::GenericNameComponent, receiver.wireEncode()) |
| 127 | .appendVersion(); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 128 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 129 | ndn::Data data(dataName); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 130 | nlsr.m_helloProtocol.onContentValidated(data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 131 | } |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 132 | |
| 133 | public: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 134 | ConfParameter conf; |
| 135 | DummyConfFileProcessor confProcessor; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 136 | Nlsr nlsr; |
| 137 | Lsdb& lsdb; |
| 138 | AdjacencyList& neighbors; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 139 | uint32_t nSuccessCallbacks; |
| 140 | uint32_t nFailureCallbacks; |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 141 | ndn::signal::ScopedConnection connection; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture) |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 145 | |
| 146 | BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors) |
| 147 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 148 | // Simulate loading configuration file |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 149 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 150 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 151 | neighbors.insert(neighborA); |
| 152 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 153 | Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 154 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 155 | neighbors.insert(neighborB); |
| 156 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 157 | Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 158 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 159 | neighbors.insert(neighborC); |
| 160 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 161 | conf.setHyperbolicState(HYPERBOLIC_STATE_ON); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 162 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 163 | Nlsr nlsr2(m_face, m_keyChain, conf); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 164 | |
Davide Pesavento | d8d6bbc | 2020-11-24 21:38:44 -0500 | [diff] [blame] | 165 | for (const auto& neighbor : neighbors.getAdjList()) { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 166 | BOOST_CHECK_EQUAL(neighbor.getLinkCost(), 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost) |
| 171 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 172 | // Simulate loading configuration file |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 173 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 174 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 175 | neighbors.insert(neighborA); |
| 176 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 177 | Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 178 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 179 | neighbors.insert(neighborB); |
| 180 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 181 | Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 182 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 183 | neighbors.insert(neighborC); |
| 184 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 185 | Nlsr nlsr2(m_face, m_keyChain, conf); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 186 | |
Davide Pesavento | d8d6bbc | 2020-11-24 21:38:44 -0500 | [diff] [blame] | 187 | for (const auto& neighbor : neighbors.getAdjList()) { |
| 188 | BOOST_CHECK_NE(neighbor.getLinkCost(), 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 192 | BOOST_AUTO_TEST_CASE(SetEventIntervals) |
| 193 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 194 | // Simulate loading configuration file |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 195 | conf.setAdjLsaBuildInterval(3); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 196 | conf.setRoutingCalcInterval(9); |
| 197 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 198 | Nlsr nlsr2(m_face, m_keyChain, conf); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 199 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 200 | const Lsdb& lsdb = nlsr2.m_lsdb; |
| 201 | const RoutingTable& rt = nlsr2.m_routingTable; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 202 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(lsdb.m_adjLsaBuildInterval, 3_s); |
| 204 | BOOST_CHECK_EQUAL(rt.m_routingCalcInterval, 9_s); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 205 | } |
| 206 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 207 | BOOST_AUTO_TEST_CASE(FaceCreateEvent) |
| 208 | { |
| 209 | // Setting constants for the unit test |
Junxiao Shi | 771a0de | 2023-08-09 00:03:21 +0000 | [diff] [blame] | 210 | const uint32_t faceId = 128; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 211 | const std::string faceUri = "udp4://10.0.0.1:6363"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 212 | |
| 213 | Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 214 | Adjacent::STATUS_INACTIVE, 0, 0); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 215 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 216 | BOOST_REQUIRE_EQUAL(conf.getAdjacencyList().insert(neighbor), true); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 217 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 218 | this->advanceClocks(10_ms); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 219 | |
| 220 | // Build, sign, and send the Face Event |
| 221 | ndn::nfd::FaceEventNotification event; |
| 222 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 223 | .setRemoteUri(faceUri) |
| 224 | .setFaceId(faceId); |
Eric Newberry | 04bfe04 | 2021-03-26 11:06:05 -0700 | [diff] [blame] | 225 | 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] | 226 | data->setFreshnessPeriod(1_s); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 227 | data->setContent(event.wireEncode()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 228 | m_keyChain.sign(*data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 229 | m_face.receive(*data); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 230 | |
| 231 | // Move the clocks forward so that the Face processes the event. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 232 | this->advanceClocks(10_ms); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 233 | |
| 234 | // Need to explicitly provide a FaceUri object, because the |
| 235 | // conversion will attempt to create Name objects. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 236 | auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri)); |
| 237 | BOOST_REQUIRE(iterator != conf.getAdjacencyList().end()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 238 | BOOST_CHECK_EQUAL(iterator->getFaceId(), faceId); |
| 239 | } |
| 240 | |
| 241 | BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch) |
| 242 | { |
| 243 | // Setting constants for the unit test |
Junxiao Shi | 771a0de | 2023-08-09 00:03:21 +0000 | [diff] [blame] | 244 | const uint32_t faceId = 128; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 245 | const std::string eventUri = "udp4://10.0.0.1:6363"; |
| 246 | const std::string neighborUri = "udp4://10.0.0.2:6363"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 247 | |
| 248 | Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(neighborUri), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 249 | Adjacent::STATUS_INACTIVE, 0, 0); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 250 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 251 | conf.getAdjacencyList().insert(neighbor); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 252 | |
| 253 | // Build, sign, and send the Face Event |
| 254 | ndn::nfd::FaceEventNotification event; |
| 255 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 256 | .setRemoteUri(eventUri) |
| 257 | .setFaceId(faceId); |
Eric Newberry | 04bfe04 | 2021-03-26 11:06:05 -0700 | [diff] [blame] | 258 | 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] | 259 | data->setFreshnessPeriod(1_s); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 260 | data->setContent(event.wireEncode()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 261 | m_keyChain.sign(*data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 262 | m_face.receive(*data); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 263 | |
| 264 | // Move the clocks forward so that the Face processes the event. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 265 | this->advanceClocks(10_ms); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 266 | |
| 267 | // The Face URIs did not match, so this neighbor should be unconfigured. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 268 | auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(neighborUri)); |
| 269 | BOOST_REQUIRE(iterator != conf.getAdjacencyList().end()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(iterator->getFaceId(), 0); |
| 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured) |
| 274 | { |
Junxiao Shi | 771a0de | 2023-08-09 00:03:21 +0000 | [diff] [blame] | 275 | const uint32_t neighborFaceId = 128; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 276 | const std::string faceUri = "udp4://10.0.0.1:6363"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 277 | |
| 278 | Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10, |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 279 | Adjacent::STATUS_ACTIVE, 0, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 280 | conf.getAdjacencyList().insert(neighbor); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 281 | |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 282 | // Let NLSR start the face monitor |
| 283 | this->advanceClocks(10_ms); |
| 284 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 285 | // Build, sign, and send the Face Event |
| 286 | ndn::nfd::FaceEventNotification event; |
| 287 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 288 | .setRemoteUri(faceUri) |
Junxiao Shi | 771a0de | 2023-08-09 00:03:21 +0000 | [diff] [blame] | 289 | .setFaceId(neighborFaceId); |
Eric Newberry | 04bfe04 | 2021-03-26 11:06:05 -0700 | [diff] [blame] | 290 | 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] | 291 | data->setFreshnessPeriod(1_s); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 292 | data->setContent(event.wireEncode()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 293 | m_keyChain.sign(*data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 294 | m_face.receive(*data); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 295 | |
| 296 | // Move the clocks forward so that the Face processes the event. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 297 | this->advanceClocks(10_ms); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 298 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 299 | auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri)); |
| 300 | BOOST_REQUIRE(iterator != conf.getAdjacencyList().end()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 301 | BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId); |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 302 | |
| 303 | // Resend same event notification again |
| 304 | m_face.sentInterests.clear(); |
Eric Newberry | 04bfe04 | 2021-03-26 11:06:05 -0700 | [diff] [blame] | 305 | data->setName(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(1)); |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 306 | m_keyChain.sign(*data); |
| 307 | m_face.receive(*data); |
| 308 | this->advanceClocks(10_ms); |
| 309 | |
| 310 | for (const auto& interest : m_face.sentInterests) { |
| 311 | // Should not re-register prefix since this is the same event notification |
| 312 | if (ndn::Name("/localhost/nfd/rib/register").isPrefixOf(interest.getName())) { |
| 313 | BOOST_CHECK(false); |
| 314 | } |
| 315 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 316 | } |
| 317 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 318 | BOOST_AUTO_TEST_CASE(FaceDestroyEvent) |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 319 | { |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 320 | // Add active neighbors |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 321 | AdjacencyList& neighbors = conf.getAdjacencyList(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 322 | uint64_t destroyFaceId = 128; |
| 323 | |
| 324 | // Create a neighbor whose Face will be destroyed |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 325 | Adjacent failNeighbor("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), |
| 326 | 10, Adjacent::STATUS_ACTIVE, 0, destroyFaceId); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 327 | neighbors.insert(failNeighbor); |
| 328 | |
| 329 | // 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] | 330 | Adjacent otherNeighbor("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), |
| 331 | 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 332 | neighbors.insert(otherNeighbor); |
| 333 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 334 | // Set HelloInterest lifetime as 10 seconds so that neighbors are not marked INACTIVE |
| 335 | // upon timeout before this test ends |
| 336 | conf.setInterestResendTime(10); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 337 | |
| 338 | // Simulate successful HELLO responses |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 339 | lsdb.scheduleAdjLsaBuild(); |
| 340 | |
| 341 | // Set up adjacency LSAs |
| 342 | // This router |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 343 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.3"), |
| 344 | 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 345 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 346 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 347 | ndn::time::system_clock::now(), neighbors); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 348 | lsdb.installLsa(std::make_shared<AdjLsa>(ownAdjLsa)); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 349 | |
| 350 | // Router that will fail |
| 351 | AdjacencyList failAdjacencies; |
| 352 | failAdjacencies.insert(thisRouter); |
| 353 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 354 | AdjLsa failAdjLsa("/ndn/neighborA", 10, |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 355 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 356 | failAdjacencies); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 357 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 358 | lsdb.installLsa(std::make_shared<AdjLsa>(failAdjLsa)); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 359 | |
| 360 | // Other router |
| 361 | AdjacencyList otherAdjacencies; |
| 362 | otherAdjacencies.insert(thisRouter); |
| 363 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 364 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 365 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 366 | otherAdjacencies); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 367 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 368 | lsdb.installLsa(std::make_shared<AdjLsa>(otherAdjLsa)); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 369 | |
| 370 | // Run the scheduler to build an adjacency LSA |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 371 | this->advanceClocks(10_ms); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 372 | |
| 373 | // Make sure an adjacency LSA was built |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 374 | auto lsa = lsdb.findLsa(conf.getRouterPrefix(), Lsa::Type::ADJACENCY); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 375 | BOOST_REQUIRE(lsa != nullptr); |
| 376 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 377 | uint32_t lastAdjLsaSeqNo = lsa->getSeqNo(); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 378 | nlsr.m_lsdb.m_sequencingManager.setAdjLsaSeq(lastAdjLsaSeqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 379 | |
| 380 | this->advanceClocks(1500_ms, 10); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 381 | |
| 382 | // Make sure the routing table was calculated |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 383 | RoutingTableEntry* rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName()); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 384 | BOOST_REQUIRE(rtEntry != nullptr); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 385 | BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().size(), 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 386 | |
| 387 | // Receive FaceEventDestroyed notification |
| 388 | ndn::nfd::FaceEventNotification event; |
| 389 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 390 | .setFaceId(destroyFaceId); |
| 391 | |
Eric Newberry | 04bfe04 | 2021-03-26 11:06:05 -0700 | [diff] [blame] | 392 | 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] | 393 | data->setFreshnessPeriod(1_s); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 394 | data->setContent(event.wireEncode()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 395 | m_keyChain.sign(*data); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 396 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 397 | m_face.receive(*data); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 398 | |
| 399 | // Run the scheduler to build an adjacency LSA |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 400 | this->advanceClocks(10_ms); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 401 | |
| 402 | Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName()); |
| 403 | |
| 404 | BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0); |
| 405 | BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(), |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 406 | conf.getInterestRetryNumber()); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 407 | BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE); |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 408 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 409 | lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix()); |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 410 | BOOST_REQUIRE(lsa != nullptr); |
| 411 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(lsa->getSeqNo(), lastAdjLsaSeqNo + 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 413 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 414 | this->advanceClocks(15_s, 10); |
| 415 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 416 | // Make sure the routing table was recalculated |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 417 | rtEntry = nlsr.m_routingTable.findRoutingTableEntry(failNeighbor.getName()); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 418 | BOOST_CHECK(rtEntry == nullptr); |
| 419 | } |
| 420 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 421 | BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse) |
| 422 | { |
| 423 | // Configure NLSR |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 424 | conf.setAdjLsaBuildInterval(1); |
| 425 | |
| 426 | // Add neighbors |
| 427 | // Router A |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 428 | ndn::Name neighborAName("/ndn/site/%C1.Router/routerA"); |
| 429 | Adjacent neighborA(neighborAName, ndn::FaceUri("udp4://10.0.0.1"), |
| 430 | 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 431 | neighbors.insert(neighborA); |
| 432 | |
| 433 | // Router B |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 434 | ndn::Name neighborBName("/ndn/site/%C1.Router/routerB"); |
| 435 | Adjacent neighborB(neighborBName, ndn::FaceUri("udp4://10.0.0.1"), |
| 436 | 0, Adjacent::STATUS_INACTIVE, 0, 0); |
| 437 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 438 | neighbors.insert(neighborB); |
| 439 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 440 | this->advanceClocks(10_ms); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 441 | |
| 442 | // Receive HELLO response from Router A |
| 443 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 444 | this->advanceClocks(1_s, 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 445 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 446 | // Adjacency LSA should be built even though other router is INACTIVE |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 447 | auto lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix()); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 448 | BOOST_REQUIRE(lsa != nullptr); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 449 | BOOST_CHECK_EQUAL(lsa->getAdl().size(), 1); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 450 | |
| 451 | // Receive HELLO response from Router B |
| 452 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 453 | |
| 454 | // Both routers become INACTIVE and HELLO Interests have timed out |
| 455 | for (Adjacent& adjacency : neighbors.getAdjList()) { |
| 456 | adjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 457 | adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 458 | } |
| 459 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 460 | this->advanceClocks(1_s, 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 461 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 462 | // Adjacency LSA should have been removed since this router's adjacencies are |
| 463 | // INACTIVE and have timed out |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 464 | lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix()); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 465 | BOOST_CHECK(lsa == nullptr); |
| 466 | |
| 467 | // Receive HELLO response from Router A and B |
| 468 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 469 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 470 | this->advanceClocks(1_s, 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 471 | |
| 472 | // Adjacency LSA should be built |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 473 | lsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix()); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 474 | BOOST_REQUIRE(lsa != nullptr); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 475 | BOOST_CHECK_EQUAL(lsa->getAdl().size(), 2); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 476 | } |
| 477 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 478 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess) |
| 479 | { |
| 480 | bool hasResult = false; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 481 | |
| 482 | nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) { |
| 483 | hasResult = true; |
| 484 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 485 | BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401); |
| 486 | BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402); |
| 487 | }, |
| 488 | [] (uint32_t code, const std::string& reason) {}); |
| 489 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 490 | this->advanceClocks(100_ms, 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 491 | |
| 492 | ndn::nfd::FaceStatus payload1; |
| 493 | payload1.setFaceId(25401); |
| 494 | ndn::nfd::FaceStatus payload2; |
| 495 | payload2.setFaceId(25402); |
| 496 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
| 497 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 498 | this->advanceClocks(100_ms, 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 499 | BOOST_CHECK(hasResult); |
| 500 | } |
| 501 | |
| 502 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure) |
| 503 | { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 504 | nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {}, |
| 505 | [this](uint32_t code, const std::string& reason){ |
| 506 | this->nFailureCallbacks++; |
| 507 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 508 | this->advanceClocks(100_ms, 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 509 | |
| 510 | ndn::Name payload; |
| 511 | this->sendDataset("/localhost/nfd/faces/list", payload); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 512 | this->advanceClocks(100_ms, 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 513 | |
| 514 | BOOST_CHECK_EQUAL(nFailureCallbacks, 1); |
| 515 | BOOST_CHECK_EQUAL(nSuccessCallbacks, 0); |
| 516 | } |
| 517 | |
| 518 | BOOST_AUTO_TEST_CASE(FaceDatasetProcess) |
| 519 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 520 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"), |
| 521 | 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 522 | neighbors.insert(neighborA); |
| 523 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 524 | Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://192.168.0.101:6363"), |
| 525 | 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 526 | neighbors.insert(neighborB); |
| 527 | |
| 528 | ndn::nfd::FaceStatus payload1; |
| 529 | payload1.setFaceId(1) |
| 530 | .setRemoteUri("udp4://192.168.0.100:6363"); |
| 531 | ndn::nfd::FaceStatus payload2; |
| 532 | payload2.setFaceId(2) |
| 533 | .setRemoteUri("udp4://192.168.0.101:6363"); |
| 534 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2}; |
| 535 | |
| 536 | nlsr.processFaceDataset(faceStatuses); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 537 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 538 | AdjacencyList adjList = conf.getAdjacencyList(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 539 | |
| 540 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId()); |
| 541 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId()); |
| 542 | } |
| 543 | |
| 544 | BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor) |
| 545 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 546 | 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] | 547 | neighbors.insert(neighborA); |
| 548 | |
| 549 | ndn::nfd::FaceStatus payload; |
| 550 | payload.setFaceId(1) |
| 551 | .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI. |
| 552 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload}; |
| 553 | |
| 554 | nlsr.processFaceDataset(faceStatuses); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 555 | this->advanceClocks(20_ms, 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 556 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 557 | AdjacencyList adjList = conf.getAdjacencyList(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 558 | |
| 559 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0); |
| 560 | } |
| 561 | |
| 562 | BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch) |
| 563 | { |
| 564 | int nNameMatches = 0; |
| 565 | ndn::Name datasetPrefix("/localhost/nfd/faces/list"); |
| 566 | ndn::nfd::CommandOptions options; |
| 567 | ndn::time::milliseconds defaultTimeout = options.getTimeout(); |
| 568 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 569 | int fetchInterval(1); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 570 | conf.setFaceDatasetFetchInterval(fetchInterval); |
| 571 | conf.setFaceDatasetFetchTries(0); |
| 572 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 573 | // Elapse the default timeout time of the interest. |
| 574 | this->advanceClocks(defaultTimeout); |
| 575 | |
| 576 | // 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] | 577 | for (const auto& interest : m_face.sentInterests) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 578 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 579 | nNameMatches++; |
| 580 | } |
| 581 | } |
| 582 | BOOST_CHECK_EQUAL(nNameMatches, 1); |
| 583 | |
| 584 | // Elapse the clock by the reschedule time (that we set) |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 585 | this->advanceClocks(ndn::time::seconds(fetchInterval)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 586 | // Elapse the default timeout on the interest. |
| 587 | this->advanceClocks(defaultTimeout); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 588 | |
| 589 | // Check that we now have two interests |
| 590 | nNameMatches = 0; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 591 | for (const auto& interest : m_face.sentInterests) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 592 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 593 | nNameMatches++; |
| 594 | } |
| 595 | } |
| 596 | BOOST_CHECK_EQUAL(nNameMatches, 2); |
| 597 | } |
| 598 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 599 | BOOST_AUTO_TEST_SUITE_END() |
| 600 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 601 | } // namespace test |
| 602 | } // namespace nlsr |