Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 26 | #include "mgmt/rib-manager.hpp" |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 27 | |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 28 | #include "manager-common-fixture.hpp" |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 29 | #include "tests/daemon/rib/fib-updates-common.hpp" |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 30 | |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/lp/tags.hpp> |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 32 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
| 33 | #include <ndn-cxx/mgmt/nfd/rib-entry.hpp> |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 34 | |
| 35 | #include <boost/property_tree/info_parser.hpp> |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 36 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::tests { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 38 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 39 | struct ConfigurationStatus |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 40 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 41 | bool isLocalhostConfigured; |
| 42 | bool isLocalhopConfigured; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 45 | static ConfigSection |
| 46 | getValidatorConfigSection() |
| 47 | { |
| 48 | ConfigSection section; |
| 49 | section.put("trust-anchor.type", "any"); |
| 50 | return section; |
| 51 | } |
| 52 | |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 53 | static ConfigSection |
| 54 | makeSection(const std::string& config) |
| 55 | { |
| 56 | std::istringstream inputStream(config); |
| 57 | ConfigSection section; |
| 58 | boost::property_tree::read_info(inputStream, section); |
| 59 | return section; |
| 60 | } |
| 61 | |
| 62 | static ConfigSection |
| 63 | getLocalhopValidatorConfigSection() |
| 64 | { |
| 65 | std::string config = R"CONF( |
| 66 | rule |
| 67 | { |
| 68 | id rule-id1 |
| 69 | for interest |
| 70 | filter |
| 71 | { |
| 72 | type name |
| 73 | name /localhop/nfd/rib |
| 74 | relation is-prefix-of |
| 75 | } |
| 76 | checker |
| 77 | { |
| 78 | type customized |
| 79 | sig-type ecdsa-sha256 |
| 80 | key-locator |
| 81 | { |
| 82 | type name |
| 83 | name /TrustAnchor-identity/Derived-identity |
| 84 | relation is-prefix-of |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | rule |
| 89 | { |
| 90 | id rule-id2 |
| 91 | for data |
| 92 | filter |
| 93 | { |
| 94 | type name |
| 95 | name /TrustAnchor-identity/Derived-identity/KEY |
| 96 | relation is-prefix-of |
| 97 | } |
| 98 | checker |
| 99 | { |
| 100 | type customized |
| 101 | sig-type ecdsa-sha256 |
| 102 | key-locator |
| 103 | { |
| 104 | type name |
| 105 | name /TrustAnchor-identity |
| 106 | relation is-prefix-of |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | trust-anchor |
| 111 | { |
| 112 | type file |
| 113 | file-name signer.ndncert |
| 114 | } |
| 115 | )CONF"; |
| 116 | return makeSection(config); |
| 117 | } |
| 118 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 119 | class RibManagerFixture : public ManagerCommonFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 120 | { |
| 121 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 122 | RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib) |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 123 | : m_status(status) |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 124 | , m_anchorId("/TrustAnchor-identity") |
| 125 | , m_derivedId("/TrustAnchor-identity/Derived-identity") |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 126 | , m_nfdController(m_face, m_keyChain) |
| 127 | , m_fibUpdater(m_rib, m_nfdController) |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame] | 128 | , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 129 | { |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 130 | auto anchorIdentity = m_keyChain.createIdentity(m_anchorId); |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 131 | saveIdentityCert(m_anchorId, "signer.ndncert", true); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 132 | |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 133 | auto derivedKey = m_keyChain.createIdentity(m_derivedId).getDefaultKey(); |
| 134 | auto derivedSelfSigned = derivedKey.getDefaultCertificate(); |
| 135 | ndn::security::MakeCertificateOptions opts; |
| 136 | opts.validity = derivedSelfSigned.getValidityPeriod(); |
| 137 | auto derivedCert = m_keyChain.makeCertificate(derivedSelfSigned, |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 138 | ndn::security::signingByIdentity(anchorIdentity), |
| 139 | opts); |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 140 | m_keyChain.setDefaultCertificate(derivedKey, derivedCert); |
| 141 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 142 | if (m_status.isLocalhostConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 143 | m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 144 | } |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 145 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 146 | if (m_status.isLocalhopConfigured) { |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 147 | m_manager.enableLocalhop(getLocalhopValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 148 | } |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 149 | else { |
| 150 | m_manager.disableLocalhop(); |
| 151 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 152 | |
| 153 | registerWithNfd(); |
| 154 | |
| 155 | if (shouldClearRib) { |
| 156 | clearRib(); |
| 157 | } |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 158 | |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 159 | m_face.onSendInterest.connect([=] (const Interest& interest) { |
| 160 | if (interest.matchesData(derivedCert) && |
| 161 | m_status.isLocalhopConfigured && |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 162 | interest.getTag<lp::NextHopFaceIdTag>() != nullptr) { |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 163 | m_face.put(derivedCert); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 164 | } |
| 165 | }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | private: |
| 169 | void |
| 170 | registerWithNfd() |
| 171 | { |
| 172 | m_manager.registerWithNfd(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 173 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 174 | |
| 175 | auto replyFibAddCommand = [this] (const Interest& interest) { |
Davide Pesavento | 6d6f207 | 2022-09-12 23:08:34 -0400 | [diff] [blame] | 176 | ControlParameters params(interest.getName().at(4).blockFromValue()); |
Junxiao Shi | fde3f54 | 2016-07-10 19:54:53 +0000 | [diff] [blame] | 177 | BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib"); |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 178 | params.setFaceId(1) |
| 179 | .setCost(0); |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 180 | ControlResponse resp; |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 181 | resp.setCode(200) |
| 182 | .setBody(params.wireEncode()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 183 | |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 184 | auto data = make_shared<Data>(interest.getName()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 185 | data->setContent(resp.wireEncode()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 186 | m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); |
| 187 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 188 | m_face.getIoService().post([this, data] { m_face.receive(*data); }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 189 | }; |
| 190 | |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 191 | const Name commandPrefix("/localhost/nfd/fib/add-nexthop"); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 192 | for (const auto& command : m_face.sentInterests) { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 193 | if (commandPrefix.isPrefixOf(command.getName())) { |
| 194 | replyFibAddCommand(command); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 195 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | // clear commands and responses |
| 200 | m_responses.clear(); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 201 | m_face.sentInterests.clear(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 204 | void |
| 205 | clearRib() |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 206 | { |
| 207 | while (!m_rib.empty()) { |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 208 | m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | public: |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 213 | static ControlParameters |
| 214 | makeRegisterParameters(const Name& name, uint64_t faceId = 0, |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 215 | time::milliseconds expiry = time::milliseconds::max()) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 216 | { |
| 217 | return ControlParameters() |
| 218 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 219 | .setFaceId(faceId) |
| 220 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 221 | .setCost(10) |
| 222 | .setFlags(0) |
| 223 | .setExpirationPeriod(expiry); |
| 224 | } |
| 225 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 226 | static ControlParameters |
| 227 | makeUnregisterParameters(const Name& name, uint64_t faceId = 0) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 228 | { |
| 229 | return ControlParameters() |
| 230 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 231 | .setFaceId(faceId) |
| 232 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 235 | protected: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 236 | ConfigurationStatus m_status; |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 237 | Name m_anchorId; |
| 238 | Name m_derivedId; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 239 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 240 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 241 | rib::Rib m_rib; |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 242 | MockFibUpdater m_fibUpdater; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 243 | RibManager m_manager; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 244 | }; |
| 245 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 246 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 247 | BOOST_AUTO_TEST_SUITE(TestRibManager) |
| 248 | |
| 249 | class AddTopPrefixFixture : public RibManagerFixture |
| 250 | { |
| 251 | public: |
| 252 | AddTopPrefixFixture() |
| 253 | : RibManagerFixture({true, true}, false) |
| 254 | { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 255 | } |
| 256 | }; |
| 257 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 258 | BOOST_FIXTURE_TEST_CASE(AddTopPrefix, AddTopPrefixFixture) |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 259 | { |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 260 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 261 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 262 | std::vector<Name> ribEntryNames; |
| 263 | for (auto&& entry : m_rib) { |
| 264 | ribEntryNames.push_back(entry.first); |
| 265 | } |
| 266 | BOOST_CHECK_EQUAL(ribEntryNames[0], "/localhop/nfd"); |
| 267 | BOOST_CHECK_EQUAL(ribEntryNames[1], "/localhost/nfd"); |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 270 | class UnauthorizedRibManagerFixture : public RibManagerFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 271 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 272 | public: |
| 273 | UnauthorizedRibManagerFixture() |
| 274 | : RibManagerFixture({false, false}, true) |
| 275 | { |
| 276 | } |
| 277 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 278 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 279 | class LocalhostAuthorizedRibManagerFixture : public RibManagerFixture |
| 280 | { |
| 281 | public: |
| 282 | LocalhostAuthorizedRibManagerFixture() |
| 283 | : RibManagerFixture({true, false}, true) |
| 284 | { |
| 285 | } |
| 286 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 287 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 288 | class LocalhopAuthorizedRibManagerFixture : public RibManagerFixture |
| 289 | { |
| 290 | public: |
| 291 | LocalhopAuthorizedRibManagerFixture() |
| 292 | : RibManagerFixture({false, true}, true) |
| 293 | { |
| 294 | } |
| 295 | }; |
| 296 | |
| 297 | class AuthorizedRibManagerFixture : public RibManagerFixture |
| 298 | { |
| 299 | public: |
| 300 | AuthorizedRibManagerFixture() |
| 301 | : RibManagerFixture({true, true}, true) |
| 302 | { |
| 303 | } |
| 304 | }; |
| 305 | |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 306 | template<typename Fixture, auto Format> |
| 307 | struct FixtureWithFormat : public Fixture |
| 308 | { |
| 309 | static constexpr ndn::security::SignedInterestFormat signedInterestFmt = Format; |
| 310 | }; |
| 311 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 312 | using AllFixtures = boost::mpl::vector< |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 313 | FixtureWithFormat<UnauthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V02>, |
| 314 | FixtureWithFormat<UnauthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V03>, |
| 315 | FixtureWithFormat<LocalhostAuthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V02>, |
| 316 | FixtureWithFormat<LocalhostAuthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V03>, |
| 317 | FixtureWithFormat<LocalhopAuthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V02>, |
| 318 | FixtureWithFormat<LocalhopAuthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V03>, |
| 319 | FixtureWithFormat<AuthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V02>, |
| 320 | FixtureWithFormat<AuthorizedRibManagerFixture, ndn::security::SignedInterestFormat::V03> |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 321 | >; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 322 | |
| 323 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T) |
| 324 | { |
| 325 | auto parameters = this->makeRegisterParameters("/test-authorization", 9527); |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 326 | auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters, |
| 327 | T::signedInterestFmt); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 328 | auto commandHop = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters, |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 329 | T::signedInterestFmt, this->m_derivedId); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 330 | if (this->m_status.isLocalhopConfigured) { |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 331 | commandHop.setTag(std::make_shared<lp::IncomingFaceIdTag>(123)); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 332 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 333 | auto successResp = this->makeResponse(200, "Success", parameters); |
| 334 | auto failureResp = ControlResponse(403, "authorization rejected"); |
| 335 | |
| 336 | BOOST_CHECK_EQUAL(this->m_responses.size(), 0); |
| 337 | this->receiveInterest(commandHost); |
| 338 | this->receiveInterest(commandHop); |
| 339 | |
| 340 | auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1; |
| 341 | auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp; |
| 342 | auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp; |
| 343 | |
| 344 | BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 346 | ManagerCommonFixture::CheckResponseResult::OK); |
| 347 | if (nExpectedResponses == 2) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 348 | BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 349 | ManagerCommonFixture::CheckResponseResult::OK); |
| 350 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 353 | BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture) |
| 354 | |
| 355 | BOOST_AUTO_TEST_CASE(Basic) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 356 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 357 | auto paramsRegister = makeRegisterParameters("/test-register-unregister", 9527); |
| 358 | auto paramsUnregister = makeUnregisterParameters("/test-register-unregister", 9527); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 359 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 360 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 361 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
| 362 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 363 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 364 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 365 | receiveInterest(commandRegister); |
| 366 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 367 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 368 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 369 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 370 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 371 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 372 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 373 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 374 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 375 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 376 | rib::FibUpdate::createAddUpdate("/test-register-unregister", 9527, 10)); |
| 377 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 378 | rib::FibUpdate::createRemoveUpdate("/test-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 379 | } |
| 380 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 381 | BOOST_AUTO_TEST_CASE(SelfOperation) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 382 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 383 | auto paramsRegister = makeRegisterParameters("/test-self-register-unregister"); |
| 384 | auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister"); |
| 385 | BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0); |
| 386 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 387 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 388 | const uint64_t inFaceId = 9527; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 389 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 390 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
| 391 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 392 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 393 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 394 | receiveInterest(commandRegister); |
| 395 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 396 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 397 | paramsRegister.setFaceId(inFaceId); |
| 398 | paramsUnregister.setFaceId(inFaceId); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 399 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 400 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 401 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 402 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 404 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 405 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 406 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 407 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 408 | rib::FibUpdate::createAddUpdate("/test-self-register-unregister", 9527, 10)); |
| 409 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 410 | rib::FibUpdate::createRemoveUpdate("/test-self-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 411 | } |
| 412 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 413 | BOOST_AUTO_TEST_CASE(Expiration) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 414 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 415 | auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 416 | auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527); |
| 417 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 418 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 419 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 420 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); // the registered route has expired |
| 421 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 422 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
| 423 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 424 | rib::FibUpdate::createRemoveUpdate("/test-expiry", 9527)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 425 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 426 | m_fibUpdater.updates.clear(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 427 | paramsRegister.setExpirationPeriod(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 428 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 429 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 430 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 431 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 1); // the registered route is still active |
| 432 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 433 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 436 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 437 | { |
| 438 | Name prefix; |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 439 | while (prefix.size() <= Fib::getMaxDepth()) { |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 440 | prefix.append("A"); |
| 441 | } |
| 442 | auto params = makeRegisterParameters(prefix, 2899); |
| 443 | auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params); |
| 444 | receiveInterest(command); |
| 445 | |
| 446 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 447 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), |
| 448 | ControlResponse(414, "Route prefix cannot exceed " + |
| 449 | to_string(Fib::getMaxDepth()) + " components")), |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 450 | CheckResponseResult::OK); |
| 451 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 452 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 455 | BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister |
| 456 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 457 | BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 458 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 459 | uint64_t faceId = 0; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 460 | auto generateRoute = [&faceId] () -> rib::Route { |
| 461 | rib::Route route; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 462 | route.faceId = ++faceId; |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 463 | route.cost = route.faceId * 10; |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 464 | route.expires = std::nullopt; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 465 | return route; |
| 466 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 467 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 468 | const size_t nEntries = 108; |
| 469 | std::set<Name> actualPrefixes; |
| 470 | for (size_t i = 0; i < nEntries; ++i) { |
| 471 | Name prefix = Name("/test-dataset").appendNumber(i); |
| 472 | actualPrefixes.insert(prefix); |
| 473 | m_rib.insert(prefix, generateRoute()); |
| 474 | if (i & 0x1) { |
| 475 | m_rib.insert(prefix, generateRoute()); |
| 476 | m_rib.insert(prefix, generateRoute()); |
| 477 | } |
| 478 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 479 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 480 | receiveInterest(*makeInterest("/localhost/nfd/rib/list", true)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 481 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 482 | Block content = concatenateResponses(); |
| 483 | content.parse(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 484 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 485 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 486 | std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 487 | for (size_t idx = 0; idx < nEntries; ++idx) { |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 488 | ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 489 | receivedRecords.push_back(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 490 | actualPrefixes.erase(decodedEntry.getName()); |
| 491 | |
| 492 | auto matchedEntryIt = m_rib.find(decodedEntry.getName()); |
| 493 | BOOST_REQUIRE(matchedEntryIt != m_rib.end()); |
| 494 | |
| 495 | auto matchedEntry = matchedEntryIt->second; |
| 496 | BOOST_REQUIRE(matchedEntry != nullptr); |
| 497 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 498 | expectedRecords.emplace_back(); |
| 499 | expectedRecords.back().setName(matchedEntry->getName()); |
| 500 | for (const auto& route : matchedEntry->getRoutes()) { |
| 501 | expectedRecords.back().addRoute(ndn::nfd::Route() |
| 502 | .setFaceId(route.faceId) |
| 503 | .setOrigin(route.origin) |
| 504 | .setCost(route.cost) |
| 505 | .setFlags(route.flags)); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 506 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | BOOST_CHECK_EQUAL(actualPrefixes.size(), 0); |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 510 | BOOST_TEST(receivedRecords == expectedRecords, boost::test_tools::per_element()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 511 | } |
| 512 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 513 | BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture) |
| 514 | |
| 515 | BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 516 | { |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 517 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 518 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 519 | advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 520 | BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 2); |
| 521 | BOOST_CHECK_EQUAL(m_face.sentInterests[0].getName(), "/localhost/nfd/faces/events"); |
| 522 | BOOST_CHECK_EQUAL(m_face.sentInterests[1].getName(), "/localhost/nfd/faces/list"); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 525 | BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 526 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 527 | auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1"); |
| 528 | auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2"); |
| 529 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1))); |
| 530 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2))); |
| 531 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2))); |
| 532 | BOOST_REQUIRE_EQUAL(m_rib.size(), 3); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 533 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 534 | ndn::nfd::FaceStatus status; |
| 535 | status.setFaceId(1); |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 536 | std::vector<ndn::nfd::FaceStatus> activeFaces; |
| 537 | activeFaces.push_back(status); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 538 | |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 539 | m_manager.removeInvalidFaces(activeFaces); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 540 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 541 | BOOST_REQUIRE_EQUAL(m_rib.size(), 1); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 542 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 543 | auto it1 = m_rib.find("/test-remove-invalid-faces-1"); |
| 544 | auto it2 = m_rib.find("/test-remove-invalid-faces-2"); |
| 545 | BOOST_CHECK(it2 == m_rib.end()); |
| 546 | BOOST_REQUIRE(it1 != m_rib.end()); |
| 547 | BOOST_CHECK(it1->second->hasFaceId(1)); |
| 548 | BOOST_CHECK(!it1->second->hasFaceId(2)); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 549 | } |
| 550 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 551 | BOOST_AUTO_TEST_CASE(OnNotification) |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 552 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 553 | auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1); |
| 554 | auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1); |
| 555 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1)); |
| 556 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2)); |
| 557 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 558 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 559 | auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) { |
| 560 | return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 561 | }; |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 562 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 563 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 564 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 565 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 566 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 567 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 568 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 569 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 570 | } |
| 571 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 572 | BOOST_AUTO_TEST_SUITE_END() // FaceMonitor |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 573 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 574 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 575 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 576 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 577 | } // namespace nfd::tests |