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 | /* |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, 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 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 35 | #include <boost/mp11/algorithm.hpp> |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 36 | #include <boost/property_tree/info_parser.hpp> |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 37 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 38 | namespace nfd::tests { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 39 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 40 | struct ConfigurationStatus |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 41 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 42 | bool isLocalhostConfigured; |
| 43 | bool isLocalhopConfigured; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 44 | }; |
| 45 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 46 | static ConfigSection |
| 47 | getValidatorConfigSection() |
| 48 | { |
| 49 | ConfigSection section; |
| 50 | section.put("trust-anchor.type", "any"); |
| 51 | return section; |
| 52 | } |
| 53 | |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 54 | static ConfigSection |
| 55 | makeSection(const std::string& config) |
| 56 | { |
| 57 | std::istringstream inputStream(config); |
| 58 | ConfigSection section; |
| 59 | boost::property_tree::read_info(inputStream, section); |
| 60 | return section; |
| 61 | } |
| 62 | |
| 63 | static ConfigSection |
| 64 | getLocalhopValidatorConfigSection() |
| 65 | { |
| 66 | std::string config = R"CONF( |
| 67 | rule |
| 68 | { |
| 69 | id rule-id1 |
| 70 | for interest |
| 71 | filter |
| 72 | { |
| 73 | type name |
| 74 | name /localhop/nfd/rib |
| 75 | relation is-prefix-of |
| 76 | } |
| 77 | checker |
| 78 | { |
| 79 | type customized |
| 80 | sig-type ecdsa-sha256 |
| 81 | key-locator |
| 82 | { |
| 83 | type name |
| 84 | name /TrustAnchor-identity/Derived-identity |
| 85 | relation is-prefix-of |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | rule |
| 90 | { |
| 91 | id rule-id2 |
| 92 | for data |
| 93 | filter |
| 94 | { |
| 95 | type name |
| 96 | name /TrustAnchor-identity/Derived-identity/KEY |
| 97 | relation is-prefix-of |
| 98 | } |
| 99 | checker |
| 100 | { |
| 101 | type customized |
| 102 | sig-type ecdsa-sha256 |
| 103 | key-locator |
| 104 | { |
| 105 | type name |
| 106 | name /TrustAnchor-identity |
| 107 | relation is-prefix-of |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | trust-anchor |
| 112 | { |
| 113 | type file |
| 114 | file-name signer.ndncert |
| 115 | } |
| 116 | )CONF"; |
| 117 | return makeSection(config); |
| 118 | } |
| 119 | |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 120 | static ConfigSection |
| 121 | getPaValidatorConfigSection() |
| 122 | { |
| 123 | ConfigSection section; |
| 124 | section.put("trust-anchor.type", "any"); |
| 125 | return section; |
| 126 | } |
| 127 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 128 | class RibManagerFixture : public ManagerCommonFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 129 | { |
| 130 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 131 | RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib) |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 132 | : m_status(status) |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 133 | , m_anchorId("/TrustAnchor-identity") |
| 134 | , m_derivedId("/TrustAnchor-identity/Derived-identity") |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 135 | , m_nfdController(m_face, m_keyChain) |
| 136 | , m_fibUpdater(m_rib, m_nfdController) |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame] | 137 | , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 138 | { |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 139 | auto anchorIdentity = m_keyChain.createIdentity(m_anchorId); |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 140 | saveIdentityCert(m_anchorId, "signer.ndncert", true); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 141 | |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 142 | auto derivedKey = m_keyChain.createIdentity(m_derivedId).getDefaultKey(); |
| 143 | auto derivedSelfSigned = derivedKey.getDefaultCertificate(); |
| 144 | ndn::security::MakeCertificateOptions opts; |
| 145 | opts.validity = derivedSelfSigned.getValidityPeriod(); |
| 146 | auto derivedCert = m_keyChain.makeCertificate(derivedSelfSigned, |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 147 | ndn::security::signingByIdentity(anchorIdentity), |
| 148 | opts); |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 149 | m_keyChain.setDefaultCertificate(derivedKey, derivedCert); |
| 150 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 151 | if (m_status.isLocalhostConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 152 | m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 153 | } |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 154 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 155 | if (m_status.isLocalhopConfigured) { |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 156 | m_manager.enableLocalhop(getLocalhopValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 157 | } |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 158 | else { |
| 159 | m_manager.disableLocalhop(); |
| 160 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 161 | |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 162 | m_manager.applyPaConfig(getPaValidatorConfigSection(), "testPa"); |
| 163 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 164 | registerWithNfd(); |
| 165 | |
| 166 | if (shouldClearRib) { |
| 167 | clearRib(); |
| 168 | } |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 169 | |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 170 | m_face.onSendInterest.connect([=] (const Interest& interest) { |
| 171 | if (interest.matchesData(derivedCert) && |
| 172 | m_status.isLocalhopConfigured && |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 173 | interest.getTag<lp::NextHopFaceIdTag>() != nullptr) { |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 174 | m_face.put(derivedCert); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 175 | } |
| 176 | }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | private: |
| 180 | void |
| 181 | registerWithNfd() |
| 182 | { |
| 183 | m_manager.registerWithNfd(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 184 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 185 | |
| 186 | auto replyFibAddCommand = [this] (const Interest& interest) { |
Davide Pesavento | 6d6f207 | 2022-09-12 23:08:34 -0400 | [diff] [blame] | 187 | ControlParameters params(interest.getName().at(4).blockFromValue()); |
Junxiao Shi | fde3f54 | 2016-07-10 19:54:53 +0000 | [diff] [blame] | 188 | BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib"); |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 189 | params.setFaceId(1) |
| 190 | .setCost(0); |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 191 | ControlResponse resp; |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 192 | resp.setCode(200) |
| 193 | .setBody(params.wireEncode()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 194 | |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 195 | auto data = make_shared<Data>(interest.getName()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 196 | data->setContent(resp.wireEncode()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 197 | m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); |
| 198 | |
Davide Pesavento | e277f8b | 2023-11-11 17:14:02 -0500 | [diff] [blame] | 199 | boost::asio::post(m_face.getIoContext(), [this, data] { m_face.receive(*data); }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 200 | }; |
| 201 | |
Davide Pesavento | 20cafa8 | 2022-07-25 01:15:03 -0400 | [diff] [blame] | 202 | const Name commandPrefix("/localhost/nfd/fib/add-nexthop"); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 203 | for (const auto& command : m_face.sentInterests) { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 204 | if (commandPrefix.isPrefixOf(command.getName())) { |
| 205 | replyFibAddCommand(command); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 206 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | // clear commands and responses |
| 211 | m_responses.clear(); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 212 | m_face.sentInterests.clear(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 215 | void |
| 216 | clearRib() |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 217 | { |
| 218 | while (!m_rib.empty()) { |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 219 | m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | public: |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 224 | static ControlParameters |
| 225 | makeRegisterParameters(const Name& name, uint64_t faceId = 0, |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 226 | time::milliseconds expiry = time::milliseconds::max()) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 227 | { |
| 228 | return ControlParameters() |
| 229 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 230 | .setFaceId(faceId) |
| 231 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 232 | .setCost(10) |
| 233 | .setFlags(0) |
| 234 | .setExpirationPeriod(expiry); |
| 235 | } |
| 236 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 237 | static ControlParameters |
| 238 | makeUnregisterParameters(const Name& name, uint64_t faceId = 0) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 239 | { |
| 240 | return ControlParameters() |
| 241 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 242 | .setFaceId(faceId) |
| 243 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 246 | protected: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 247 | ConfigurationStatus m_status; |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 248 | Name m_anchorId; |
| 249 | Name m_derivedId; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 250 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 251 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 252 | rib::Rib m_rib; |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 253 | MockFibUpdater m_fibUpdater; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 254 | RibManager m_manager; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 255 | }; |
| 256 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 257 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 258 | BOOST_AUTO_TEST_SUITE(TestRibManager) |
| 259 | |
| 260 | class AddTopPrefixFixture : public RibManagerFixture |
| 261 | { |
| 262 | public: |
| 263 | AddTopPrefixFixture() |
| 264 | : RibManagerFixture({true, true}, false) |
| 265 | { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 266 | } |
| 267 | }; |
| 268 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 269 | BOOST_FIXTURE_TEST_CASE(AddTopPrefix, AddTopPrefixFixture) |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 270 | { |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 271 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 272 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 273 | std::vector<Name> ribEntryNames; |
| 274 | for (auto&& entry : m_rib) { |
| 275 | ribEntryNames.push_back(entry.first); |
| 276 | } |
| 277 | BOOST_CHECK_EQUAL(ribEntryNames[0], "/localhop/nfd"); |
| 278 | BOOST_CHECK_EQUAL(ribEntryNames[1], "/localhost/nfd"); |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 281 | class UnauthorizedRibManagerFixture : public RibManagerFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 282 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 283 | public: |
| 284 | UnauthorizedRibManagerFixture() |
| 285 | : RibManagerFixture({false, false}, true) |
| 286 | { |
| 287 | } |
| 288 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 289 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 290 | class LocalhostAuthorizedRibManagerFixture : public RibManagerFixture |
| 291 | { |
| 292 | public: |
| 293 | LocalhostAuthorizedRibManagerFixture() |
| 294 | : RibManagerFixture({true, false}, true) |
| 295 | { |
| 296 | } |
| 297 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 298 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 299 | class LocalhopAuthorizedRibManagerFixture : public RibManagerFixture |
| 300 | { |
| 301 | public: |
| 302 | LocalhopAuthorizedRibManagerFixture() |
| 303 | : RibManagerFixture({false, true}, true) |
| 304 | { |
| 305 | } |
| 306 | }; |
| 307 | |
| 308 | class AuthorizedRibManagerFixture : public RibManagerFixture |
| 309 | { |
| 310 | public: |
| 311 | AuthorizedRibManagerFixture() |
| 312 | : RibManagerFixture({true, true}, true) |
| 313 | { |
| 314 | } |
| 315 | }; |
| 316 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 317 | template<typename Fixture, typename Format> |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 318 | struct FixtureWithFormat : public Fixture |
| 319 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 320 | static constexpr ndn::security::SignedInterestFormat signedInterestFmt = Format::value; |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 321 | }; |
| 322 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 323 | using AllFixtures = boost::mp11::mp_product< |
| 324 | FixtureWithFormat, |
| 325 | boost::mp11::mp_list<UnauthorizedRibManagerFixture, |
| 326 | LocalhostAuthorizedRibManagerFixture, |
| 327 | LocalhopAuthorizedRibManagerFixture, |
| 328 | AuthorizedRibManagerFixture>, |
| 329 | boost::mp11::mp_list_c<ndn::security::SignedInterestFormat, |
| 330 | ndn::security::SignedInterestFormat::V02, |
| 331 | ndn::security::SignedInterestFormat::V03> |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 332 | >; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 333 | |
| 334 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T) |
| 335 | { |
| 336 | auto parameters = this->makeRegisterParameters("/test-authorization", 9527); |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 337 | auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters, |
| 338 | T::signedInterestFmt); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 339 | auto commandHop = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters, |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 340 | T::signedInterestFmt, this->m_derivedId); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 341 | if (this->m_status.isLocalhopConfigured) { |
Davide Pesavento | b83d3df | 2022-09-13 14:04:34 -0400 | [diff] [blame] | 342 | commandHop.setTag(std::make_shared<lp::IncomingFaceIdTag>(123)); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 343 | } |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 344 | auto successResp = this->makeResponse(200, "OK", parameters); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 345 | auto failureResp = ControlResponse(403, "authorization rejected"); |
| 346 | |
| 347 | BOOST_CHECK_EQUAL(this->m_responses.size(), 0); |
| 348 | this->receiveInterest(commandHost); |
| 349 | this->receiveInterest(commandHop); |
| 350 | |
| 351 | auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1; |
| 352 | auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp; |
| 353 | auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp; |
| 354 | |
| 355 | BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 356 | BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 357 | ManagerCommonFixture::CheckResponseResult::OK); |
| 358 | if (nExpectedResponses == 2) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 359 | BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 360 | ManagerCommonFixture::CheckResponseResult::OK); |
| 361 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 362 | } |
| 363 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 364 | BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture) |
| 365 | |
| 366 | BOOST_AUTO_TEST_CASE(Basic) |
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 | auto paramsRegister = makeRegisterParameters("/test-register-unregister", 9527); |
| 369 | auto paramsUnregister = makeUnregisterParameters("/test-register-unregister", 9527); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 370 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 371 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 372 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
| 373 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 374 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 375 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 376 | receiveInterest(commandRegister); |
| 377 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 378 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 379 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 380 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "OK", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 381 | CheckResponseResult::OK); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 382 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "OK", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 383 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 384 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 385 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 386 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 387 | rib::FibUpdate::createAddUpdate("/test-register-unregister", 9527, 10)); |
| 388 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 389 | rib::FibUpdate::createRemoveUpdate("/test-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 390 | } |
| 391 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 392 | BOOST_AUTO_TEST_CASE(SelfOperation) |
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 | auto paramsRegister = makeRegisterParameters("/test-self-register-unregister"); |
| 395 | auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister"); |
| 396 | BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0); |
| 397 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 398 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 399 | const uint64_t inFaceId = 9527; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 400 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 401 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
| 402 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 403 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 404 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 405 | receiveInterest(commandRegister); |
| 406 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 407 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 408 | paramsRegister.setFaceId(inFaceId); |
| 409 | paramsUnregister.setFaceId(inFaceId); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 410 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 411 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "OK", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 413 | CheckResponseResult::OK); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 414 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "OK", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 415 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 416 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 417 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 418 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 419 | rib::FibUpdate::createAddUpdate("/test-self-register-unregister", 9527, 10)); |
| 420 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 421 | rib::FibUpdate::createRemoveUpdate("/test-self-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 422 | } |
| 423 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 424 | BOOST_AUTO_TEST_CASE(Expiration) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 425 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 426 | auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 427 | auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527); |
| 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(), 2); // the registered route has expired |
| 432 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 433 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
| 434 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 435 | rib::FibUpdate::createRemoveUpdate("/test-expiry", 9527)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 436 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 437 | m_fibUpdater.updates.clear(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 438 | paramsRegister.setExpirationPeriod(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 439 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 440 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 441 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 442 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 1); // the registered route is still active |
| 443 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 444 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 447 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 448 | { |
| 449 | Name prefix; |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 450 | while (prefix.size() <= Fib::getMaxDepth()) { |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 451 | prefix.append("A"); |
| 452 | } |
| 453 | auto params = makeRegisterParameters(prefix, 2899); |
| 454 | auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params); |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 455 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 456 | receiveInterest(command); |
| 457 | |
| 458 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 459 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), |
| 460 | ControlResponse(414, "Route prefix cannot exceed " + |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 461 | std::to_string(Fib::getMaxDepth()) + " components")), |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 462 | CheckResponseResult::OK); |
| 463 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 464 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 467 | BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister |
| 468 | |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 469 | BOOST_FIXTURE_TEST_SUITE(PrefixAnnounce, LocalhostAuthorizedRibManagerFixture) |
| 470 | |
| 471 | BOOST_AUTO_TEST_CASE(Basic) |
| 472 | { |
| 473 | const uint64_t announceFaceId = 1234; |
| 474 | |
| 475 | ndn::PrefixAnnouncement pa = signPrefixAnn(makePrefixAnn("/test-prefix-announce", 10_s), m_keyChain); |
| 476 | auto commandAnnounce = makeControlCommandRequest("/localhost/nfd/rib/announce", pa); |
| 477 | commandAnnounce.setTag(make_shared<lp::IncomingFaceIdTag>(announceFaceId)); |
| 478 | |
| 479 | auto paramsUnregister = makeUnregisterParameters("/test-prefix-announce"); |
| 480 | paramsUnregister.setOrigin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN); |
| 481 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
| 482 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 483 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(announceFaceId)); // same incoming face |
| 484 | |
| 485 | receiveInterest(commandAnnounce); |
| 486 | receiveInterest(commandUnregister); |
| 487 | |
| 488 | ControlParameters paramsAnnounceResponse; |
| 489 | paramsAnnounceResponse.setName("/test-prefix-announce") |
| 490 | .setFaceId(announceFaceId) |
| 491 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN) |
| 492 | .setCost(rib::Route::PA_ROUTE_COST) |
| 493 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) |
| 494 | .setExpirationPeriod(10_s); |
| 495 | paramsUnregister.setFaceId(announceFaceId); |
| 496 | |
| 497 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 498 | BOOST_CHECK_EQUAL(checkResponse(0, commandAnnounce.getName(), makeResponse(200, "OK", paramsAnnounceResponse)), |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 499 | CheckResponseResult::OK); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 500 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "OK", paramsUnregister)), |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 501 | CheckResponseResult::OK); |
| 502 | |
| 503 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 504 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 505 | rib::FibUpdate::createAddUpdate("/test-prefix-announce", announceFaceId, |
| 506 | rib::Route::PA_ROUTE_COST)); |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 507 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 508 | rib::FibUpdate::createRemoveUpdate("/test-prefix-announce", announceFaceId)); |
| 509 | } |
| 510 | |
| 511 | BOOST_AUTO_TEST_CASE(UnregisterFromDifferentFace) |
| 512 | { |
| 513 | const uint64_t announceFaceId = 1234; |
| 514 | |
| 515 | ndn::PrefixAnnouncement pa = signPrefixAnn(makePrefixAnn("/test-prefix-announce", 10_s), m_keyChain); |
| 516 | auto commandAnnounce = makeControlCommandRequest("/localhost/nfd/rib/announce", pa); |
| 517 | commandAnnounce.setTag(make_shared<lp::IncomingFaceIdTag>(announceFaceId)); |
| 518 | |
| 519 | auto paramsUnregister = makeUnregisterParameters("/test-prefix-announce", announceFaceId); |
| 520 | paramsUnregister.setOrigin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN); |
| 521 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 522 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(999)); // unregister from different face |
| 523 | |
| 524 | receiveInterest(commandAnnounce); |
| 525 | receiveInterest(commandUnregister); |
| 526 | |
| 527 | ControlParameters paramsAnnounceResponse; |
| 528 | paramsAnnounceResponse.setName("/test-prefix-announce") |
| 529 | .setFaceId(announceFaceId) |
| 530 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN) |
| 531 | .setCost(rib::Route::PA_ROUTE_COST) |
| 532 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) |
| 533 | .setExpirationPeriod(10_s); |
| 534 | |
| 535 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 536 | BOOST_CHECK_EQUAL(checkResponse(0, commandAnnounce.getName(), makeResponse(200, "OK", paramsAnnounceResponse)), |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 537 | CheckResponseResult::OK); |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 538 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "OK", paramsUnregister)), |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 539 | CheckResponseResult::OK); |
| 540 | |
| 541 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 542 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
Davide Pesavento | 21e24f9 | 2025-01-10 22:22:43 -0500 | [diff] [blame] | 543 | rib::FibUpdate::createAddUpdate("/test-prefix-announce", announceFaceId, |
| 544 | rib::Route::PA_ROUTE_COST)); |
jaczhi | b065768 | 2025-01-08 23:01:45 -0800 | [diff] [blame] | 545 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 546 | rib::FibUpdate::createRemoveUpdate("/test-prefix-announce", announceFaceId)); |
| 547 | } |
| 548 | |
| 549 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 550 | { |
| 551 | Name prefix; |
| 552 | while (prefix.size() <= Fib::getMaxDepth()) { |
| 553 | prefix.append("A"); |
| 554 | } |
| 555 | ndn::PrefixAnnouncement pa = signPrefixAnn(makePrefixAnn(prefix, 10_s), m_keyChain); |
| 556 | auto command = makeControlCommandRequest("/localhost/nfd/rib/announce", pa); |
| 557 | command.setTag(make_shared<lp::IncomingFaceIdTag>(333)); |
| 558 | |
| 559 | receiveInterest(command); |
| 560 | |
| 561 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 562 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), |
| 563 | ControlResponse(414, "Route prefix cannot exceed " + |
| 564 | std::to_string(Fib::getMaxDepth()) + " components")), |
| 565 | CheckResponseResult::OK); |
| 566 | |
| 567 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
| 568 | } |
| 569 | |
| 570 | BOOST_AUTO_TEST_SUITE_END() // PrefixAnnounce |
| 571 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 572 | BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 573 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 574 | uint64_t faceId = 0; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 575 | auto generateRoute = [&faceId] () -> rib::Route { |
| 576 | rib::Route route; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 577 | route.faceId = ++faceId; |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 578 | route.cost = route.faceId * 10; |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 579 | route.expires = std::nullopt; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 580 | return route; |
| 581 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 582 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 583 | const size_t nEntries = 108; |
| 584 | std::set<Name> actualPrefixes; |
| 585 | for (size_t i = 0; i < nEntries; ++i) { |
| 586 | Name prefix = Name("/test-dataset").appendNumber(i); |
| 587 | actualPrefixes.insert(prefix); |
| 588 | m_rib.insert(prefix, generateRoute()); |
| 589 | if (i & 0x1) { |
| 590 | m_rib.insert(prefix, generateRoute()); |
| 591 | m_rib.insert(prefix, generateRoute()); |
| 592 | } |
| 593 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 594 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 595 | receiveInterest(*makeInterest("/localhost/nfd/rib/list", true)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 596 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 597 | Block content = concatenateResponses(); |
| 598 | content.parse(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 599 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 600 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 601 | std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 602 | for (size_t idx = 0; idx < nEntries; ++idx) { |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 603 | ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); |
Davide Pesavento | d7083a5 | 2023-10-19 17:51:16 -0400 | [diff] [blame] | 604 | BOOST_TEST_INFO_SCOPE(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 605 | receivedRecords.push_back(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 606 | actualPrefixes.erase(decodedEntry.getName()); |
| 607 | |
| 608 | auto matchedEntryIt = m_rib.find(decodedEntry.getName()); |
| 609 | BOOST_REQUIRE(matchedEntryIt != m_rib.end()); |
| 610 | |
| 611 | auto matchedEntry = matchedEntryIt->second; |
| 612 | BOOST_REQUIRE(matchedEntry != nullptr); |
| 613 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 614 | expectedRecords.emplace_back(); |
| 615 | expectedRecords.back().setName(matchedEntry->getName()); |
| 616 | for (const auto& route : matchedEntry->getRoutes()) { |
| 617 | expectedRecords.back().addRoute(ndn::nfd::Route() |
| 618 | .setFaceId(route.faceId) |
| 619 | .setOrigin(route.origin) |
| 620 | .setCost(route.cost) |
| 621 | .setFlags(route.flags)); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 622 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | BOOST_CHECK_EQUAL(actualPrefixes.size(), 0); |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 626 | BOOST_TEST(receivedRecords == expectedRecords, boost::test_tools::per_element()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 627 | } |
| 628 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 629 | BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture) |
| 630 | |
| 631 | BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 632 | { |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 633 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 634 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 635 | advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 636 | BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 2); |
| 637 | BOOST_CHECK_EQUAL(m_face.sentInterests[0].getName(), "/localhost/nfd/faces/events"); |
| 638 | BOOST_CHECK_EQUAL(m_face.sentInterests[1].getName(), "/localhost/nfd/faces/list"); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 641 | BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 642 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 643 | auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1"); |
| 644 | auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2"); |
| 645 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1))); |
| 646 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2))); |
| 647 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2))); |
| 648 | BOOST_REQUIRE_EQUAL(m_rib.size(), 3); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 649 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 650 | ndn::nfd::FaceStatus status; |
| 651 | status.setFaceId(1); |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 652 | std::vector<ndn::nfd::FaceStatus> activeFaces; |
| 653 | activeFaces.push_back(status); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 654 | |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 655 | m_manager.removeInvalidFaces(activeFaces); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 656 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 657 | BOOST_REQUIRE_EQUAL(m_rib.size(), 1); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 658 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 659 | auto it1 = m_rib.find("/test-remove-invalid-faces-1"); |
| 660 | auto it2 = m_rib.find("/test-remove-invalid-faces-2"); |
| 661 | BOOST_CHECK(it2 == m_rib.end()); |
| 662 | BOOST_REQUIRE(it1 != m_rib.end()); |
| 663 | BOOST_CHECK(it1->second->hasFaceId(1)); |
| 664 | BOOST_CHECK(!it1->second->hasFaceId(2)); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 665 | } |
| 666 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 667 | BOOST_AUTO_TEST_CASE(OnNotification) |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 668 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 669 | auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1); |
| 670 | auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1); |
| 671 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1)); |
| 672 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2)); |
| 673 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 674 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 675 | auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) { |
| 676 | return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 677 | }; |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 678 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 679 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 680 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 681 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 682 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 683 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 684 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 685 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 686 | } |
| 687 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 688 | BOOST_AUTO_TEST_SUITE_END() // FaceMonitor |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 689 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 690 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 691 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 692 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 693 | } // namespace nfd::tests |