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 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 37 | namespace nfd { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 38 | namespace tests { |
| 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 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 120 | class RibManagerFixture : public ManagerCommonFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 121 | { |
| 122 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 123 | RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib) |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 124 | : m_status(status) |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 125 | , m_anchorId("/TrustAnchor-identity") |
| 126 | , m_derivedId("/TrustAnchor-identity/Derived-identity") |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 127 | , m_nfdController(m_face, m_keyChain) |
| 128 | , m_fibUpdater(m_rib, m_nfdController) |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame] | 129 | , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 130 | { |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 131 | auto anchorIdentity = m_keyChain.createIdentity(m_anchorId); |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 132 | saveIdentityCert(m_anchorId, "signer.ndncert", true); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 133 | |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 134 | auto derivedKey = m_keyChain.createIdentity(m_derivedId).getDefaultKey(); |
| 135 | auto derivedSelfSigned = derivedKey.getDefaultCertificate(); |
| 136 | ndn::security::MakeCertificateOptions opts; |
| 137 | opts.validity = derivedSelfSigned.getValidityPeriod(); |
| 138 | auto derivedCert = m_keyChain.makeCertificate(derivedSelfSigned, |
| 139 | ndn::security::signingByIdentity(anchorIdentity), opts); |
| 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 | } |
| 145 | if (m_status.isLocalhopConfigured) { |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 146 | m_manager.enableLocalhop(getLocalhopValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 147 | } |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 148 | else { |
| 149 | m_manager.disableLocalhop(); |
| 150 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 151 | |
| 152 | registerWithNfd(); |
| 153 | |
| 154 | if (shouldClearRib) { |
| 155 | clearRib(); |
| 156 | } |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 157 | |
Junxiao Shi | 4b84a2c | 2022-04-28 03:17:05 +0000 | [diff] [blame] | 158 | m_face.onSendInterest.connect([=] (const Interest& interest) { |
| 159 | if (interest.matchesData(derivedCert) && |
| 160 | m_status.isLocalhopConfigured && |
| 161 | interest.template getTag<lp::NextHopFaceIdTag>() != nullptr) { |
| 162 | m_face.put(derivedCert); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 163 | } |
| 164 | }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | private: |
| 168 | void |
| 169 | registerWithNfd() |
| 170 | { |
| 171 | m_manager.registerWithNfd(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 172 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 173 | |
| 174 | auto replyFibAddCommand = [this] (const Interest& interest) { |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 175 | ControlParameters params(interest.getName().get(-5).blockFromValue()); |
Junxiao Shi | fde3f54 | 2016-07-10 19:54:53 +0000 | [diff] [blame] | 176 | BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 177 | params.setFaceId(1).setCost(0); |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 178 | ControlResponse resp; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 179 | |
| 180 | resp.setCode(200).setBody(params.wireEncode()); |
| 181 | shared_ptr<Data> data = make_shared<Data>(interest.getName()); |
| 182 | data->setContent(resp.wireEncode()); |
| 183 | |
| 184 | m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); |
| 185 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 186 | m_face.getIoService().post([this, data] { m_face.receive(*data); }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | Name commandPrefix("/localhost/nfd/fib/add-nexthop"); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 190 | for (const auto& command : m_face.sentInterests) { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 191 | if (commandPrefix.isPrefixOf(command.getName())) { |
| 192 | replyFibAddCommand(command); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 193 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
| 197 | // clear commands and responses |
| 198 | m_responses.clear(); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 199 | m_face.sentInterests.clear(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 202 | void |
| 203 | clearRib() |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 204 | { |
| 205 | while (!m_rib.empty()) { |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 206 | m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | public: |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 211 | static ControlParameters |
| 212 | makeRegisterParameters(const Name& name, uint64_t faceId = 0, |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 213 | time::milliseconds expiry = time::milliseconds::max()) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 214 | { |
| 215 | return ControlParameters() |
| 216 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 217 | .setFaceId(faceId) |
| 218 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 219 | .setCost(10) |
| 220 | .setFlags(0) |
| 221 | .setExpirationPeriod(expiry); |
| 222 | } |
| 223 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 224 | static ControlParameters |
| 225 | makeUnregisterParameters(const Name& name, uint64_t faceId = 0) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 226 | { |
| 227 | return ControlParameters() |
| 228 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 229 | .setFaceId(faceId) |
| 230 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 233 | protected: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 234 | ConfigurationStatus m_status; |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 235 | Name m_anchorId; |
| 236 | Name m_derivedId; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 237 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 238 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 239 | rib::Rib m_rib; |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 240 | rib::tests::MockFibUpdater m_fibUpdater; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 241 | RibManager m_manager; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 242 | }; |
| 243 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 244 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 245 | BOOST_AUTO_TEST_SUITE(TestRibManager) |
| 246 | |
| 247 | class AddTopPrefixFixture : public RibManagerFixture |
| 248 | { |
| 249 | public: |
| 250 | AddTopPrefixFixture() |
| 251 | : RibManagerFixture({true, true}, false) |
| 252 | { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 253 | } |
| 254 | }; |
| 255 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 256 | BOOST_FIXTURE_TEST_CASE(AddTopPrefix, AddTopPrefixFixture) |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 257 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 258 | BOOST_CHECK_EQUAL(m_rib.size(), 2); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 259 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 260 | std::vector<Name> ribEntryNames; |
| 261 | for (auto&& entry : m_rib) { |
| 262 | ribEntryNames.push_back(entry.first); |
| 263 | } |
| 264 | BOOST_CHECK_EQUAL(ribEntryNames[0], "/localhop/nfd"); |
| 265 | BOOST_CHECK_EQUAL(ribEntryNames[1], "/localhost/nfd"); |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 268 | class UnauthorizedRibManagerFixture : public RibManagerFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 269 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 270 | public: |
| 271 | UnauthorizedRibManagerFixture() |
| 272 | : RibManagerFixture({false, false}, true) |
| 273 | { |
| 274 | } |
| 275 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 276 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 277 | class LocalhostAuthorizedRibManagerFixture : public RibManagerFixture |
| 278 | { |
| 279 | public: |
| 280 | LocalhostAuthorizedRibManagerFixture() |
| 281 | : RibManagerFixture({true, false}, true) |
| 282 | { |
| 283 | } |
| 284 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 285 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 286 | class LocalhopAuthorizedRibManagerFixture : public RibManagerFixture |
| 287 | { |
| 288 | public: |
| 289 | LocalhopAuthorizedRibManagerFixture() |
| 290 | : RibManagerFixture({false, true}, true) |
| 291 | { |
| 292 | } |
| 293 | }; |
| 294 | |
| 295 | class AuthorizedRibManagerFixture : public RibManagerFixture |
| 296 | { |
| 297 | public: |
| 298 | AuthorizedRibManagerFixture() |
| 299 | : RibManagerFixture({true, true}, true) |
| 300 | { |
| 301 | } |
| 302 | }; |
| 303 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 304 | using AllFixtures = boost::mpl::vector< |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 305 | UnauthorizedRibManagerFixture, |
| 306 | LocalhostAuthorizedRibManagerFixture, |
| 307 | LocalhopAuthorizedRibManagerFixture, |
| 308 | AuthorizedRibManagerFixture |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 309 | >; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 310 | |
| 311 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T) |
| 312 | { |
| 313 | auto parameters = this->makeRegisterParameters("/test-authorization", 9527); |
| 314 | auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 315 | auto commandHop = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters, |
| 316 | this->m_derivedId); |
| 317 | if (this->m_status.isLocalhopConfigured) { |
| 318 | commandHop.setTag(make_shared<lp::IncomingFaceIdTag>(123)); |
| 319 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 320 | auto successResp = this->makeResponse(200, "Success", parameters); |
| 321 | auto failureResp = ControlResponse(403, "authorization rejected"); |
| 322 | |
| 323 | BOOST_CHECK_EQUAL(this->m_responses.size(), 0); |
| 324 | this->receiveInterest(commandHost); |
| 325 | this->receiveInterest(commandHop); |
| 326 | |
| 327 | auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1; |
| 328 | auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp; |
| 329 | auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp; |
| 330 | |
| 331 | BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 332 | BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 333 | ManagerCommonFixture::CheckResponseResult::OK); |
| 334 | if (nExpectedResponses == 2) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 335 | BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 336 | ManagerCommonFixture::CheckResponseResult::OK); |
| 337 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 338 | } |
| 339 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 340 | BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture) |
| 341 | |
| 342 | BOOST_AUTO_TEST_CASE(Basic) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 343 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 344 | auto paramsRegister = makeRegisterParameters("/test-register-unregister", 9527); |
| 345 | auto paramsUnregister = makeUnregisterParameters("/test-register-unregister", 9527); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 346 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 347 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 348 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
| 349 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 350 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 351 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 352 | receiveInterest(commandRegister); |
| 353 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 354 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 355 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 356 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 357 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 358 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 359 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 360 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 361 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 362 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 363 | rib::FibUpdate::createAddUpdate("/test-register-unregister", 9527, 10)); |
| 364 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 365 | rib::FibUpdate::createRemoveUpdate("/test-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 366 | } |
| 367 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 368 | BOOST_AUTO_TEST_CASE(SelfOperation) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 369 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 370 | auto paramsRegister = makeRegisterParameters("/test-self-register-unregister"); |
| 371 | auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister"); |
| 372 | BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0); |
| 373 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 374 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 375 | const uint64_t inFaceId = 9527; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 376 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 377 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
| 378 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 379 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 380 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 381 | receiveInterest(commandRegister); |
| 382 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 383 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 384 | paramsRegister.setFaceId(inFaceId); |
| 385 | paramsUnregister.setFaceId(inFaceId); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 386 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 387 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 388 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 389 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 391 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 392 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 393 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 394 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 395 | rib::FibUpdate::createAddUpdate("/test-self-register-unregister", 9527, 10)); |
| 396 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 397 | rib::FibUpdate::createRemoveUpdate("/test-self-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 398 | } |
| 399 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 400 | BOOST_AUTO_TEST_CASE(Expiration) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 401 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 402 | auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 403 | auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527); |
| 404 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 405 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 406 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 407 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); // the registered route has expired |
| 408 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 409 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
| 410 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 411 | rib::FibUpdate::createRemoveUpdate("/test-expiry", 9527)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 412 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 413 | m_fibUpdater.updates.clear(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 414 | paramsRegister.setExpirationPeriod(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 415 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 416 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 417 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 418 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 1); // the registered route is still active |
| 419 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 420 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 423 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 424 | { |
| 425 | Name prefix; |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 426 | while (prefix.size() <= Fib::getMaxDepth()) { |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 427 | prefix.append("A"); |
| 428 | } |
| 429 | auto params = makeRegisterParameters(prefix, 2899); |
| 430 | auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params); |
| 431 | receiveInterest(command); |
| 432 | |
| 433 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 434 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), |
| 435 | ControlResponse(414, "Route prefix cannot exceed " + |
| 436 | to_string(Fib::getMaxDepth()) + " components")), |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 437 | CheckResponseResult::OK); |
| 438 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 439 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 442 | BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister |
| 443 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 444 | BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 445 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 446 | uint64_t faceId = 0; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 447 | auto generateRoute = [&faceId] () -> rib::Route { |
| 448 | rib::Route route; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 449 | route.faceId = ++faceId; |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 450 | route.cost = route.faceId * 10; |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame^] | 451 | route.expires = std::nullopt; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 452 | return route; |
| 453 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 454 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 455 | const size_t nEntries = 108; |
| 456 | std::set<Name> actualPrefixes; |
| 457 | for (size_t i = 0; i < nEntries; ++i) { |
| 458 | Name prefix = Name("/test-dataset").appendNumber(i); |
| 459 | actualPrefixes.insert(prefix); |
| 460 | m_rib.insert(prefix, generateRoute()); |
| 461 | if (i & 0x1) { |
| 462 | m_rib.insert(prefix, generateRoute()); |
| 463 | m_rib.insert(prefix, generateRoute()); |
| 464 | } |
| 465 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 466 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 467 | receiveInterest(*makeInterest("/localhost/nfd/rib/list", true)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 468 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 469 | Block content = concatenateResponses(); |
| 470 | content.parse(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 471 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 472 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 473 | std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 474 | for (size_t idx = 0; idx < nEntries; ++idx) { |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 475 | ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 476 | receivedRecords.push_back(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 477 | actualPrefixes.erase(decodedEntry.getName()); |
| 478 | |
| 479 | auto matchedEntryIt = m_rib.find(decodedEntry.getName()); |
| 480 | BOOST_REQUIRE(matchedEntryIt != m_rib.end()); |
| 481 | |
| 482 | auto matchedEntry = matchedEntryIt->second; |
| 483 | BOOST_REQUIRE(matchedEntry != nullptr); |
| 484 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 485 | expectedRecords.emplace_back(); |
| 486 | expectedRecords.back().setName(matchedEntry->getName()); |
| 487 | for (const auto& route : matchedEntry->getRoutes()) { |
| 488 | expectedRecords.back().addRoute(ndn::nfd::Route() |
| 489 | .setFaceId(route.faceId) |
| 490 | .setOrigin(route.origin) |
| 491 | .setCost(route.cost) |
| 492 | .setFlags(route.flags)); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 493 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | BOOST_CHECK_EQUAL(actualPrefixes.size(), 0); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 497 | BOOST_CHECK_EQUAL_COLLECTIONS(receivedRecords.begin(), receivedRecords.end(), |
| 498 | expectedRecords.begin(), expectedRecords.end()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 499 | } |
| 500 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 501 | BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture) |
| 502 | |
| 503 | BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 504 | { |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 505 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 506 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 507 | advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 508 | BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 2); |
| 509 | BOOST_CHECK_EQUAL(m_face.sentInterests[0].getName(), "/localhost/nfd/faces/events"); |
| 510 | BOOST_CHECK_EQUAL(m_face.sentInterests[1].getName(), "/localhost/nfd/faces/list"); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 513 | BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 514 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 515 | auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1"); |
| 516 | auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2"); |
| 517 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1))); |
| 518 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2))); |
| 519 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2))); |
| 520 | BOOST_REQUIRE_EQUAL(m_rib.size(), 3); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 521 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 522 | ndn::nfd::FaceStatus status; |
| 523 | status.setFaceId(1); |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 524 | std::vector<ndn::nfd::FaceStatus> activeFaces; |
| 525 | activeFaces.push_back(status); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 526 | |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 527 | m_manager.removeInvalidFaces(activeFaces); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 528 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 529 | BOOST_REQUIRE_EQUAL(m_rib.size(), 1); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 530 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 531 | auto it1 = m_rib.find("/test-remove-invalid-faces-1"); |
| 532 | auto it2 = m_rib.find("/test-remove-invalid-faces-2"); |
| 533 | BOOST_CHECK(it2 == m_rib.end()); |
| 534 | BOOST_REQUIRE(it1 != m_rib.end()); |
| 535 | BOOST_CHECK(it1->second->hasFaceId(1)); |
| 536 | BOOST_CHECK(!it1->second->hasFaceId(2)); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 537 | } |
| 538 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 539 | BOOST_AUTO_TEST_CASE(OnNotification) |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 540 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 541 | auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1); |
| 542 | auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1); |
| 543 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1)); |
| 544 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2)); |
| 545 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 546 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 547 | auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) { |
| 548 | return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 549 | }; |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 550 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 551 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 552 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 553 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 554 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 555 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 556 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 557 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 558 | } |
| 559 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 560 | BOOST_AUTO_TEST_SUITE_END() // FaceMonitor |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 561 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 562 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 563 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 564 | |
| 565 | } // namespace tests |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 566 | } // namespace nfd |