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 | /* |
Alexander Afanasyev | a158370 | 2020-06-03 13:55:45 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, 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 | #include <ndn-cxx/security/signing-helpers.hpp> |
| 35 | |
| 36 | #include <boost/property_tree/info_parser.hpp> |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 37 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 38 | namespace nfd { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 39 | namespace tests { |
| 40 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 41 | struct ConfigurationStatus |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 42 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 43 | bool isLocalhostConfigured; |
| 44 | bool isLocalhopConfigured; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 47 | static ConfigSection |
| 48 | getValidatorConfigSection() |
| 49 | { |
| 50 | ConfigSection section; |
| 51 | section.put("trust-anchor.type", "any"); |
| 52 | return section; |
| 53 | } |
| 54 | |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 55 | static ConfigSection |
| 56 | makeSection(const std::string& config) |
| 57 | { |
| 58 | std::istringstream inputStream(config); |
| 59 | ConfigSection section; |
| 60 | boost::property_tree::read_info(inputStream, section); |
| 61 | return section; |
| 62 | } |
| 63 | |
| 64 | static ConfigSection |
| 65 | getLocalhopValidatorConfigSection() |
| 66 | { |
| 67 | std::string config = R"CONF( |
| 68 | rule |
| 69 | { |
| 70 | id rule-id1 |
| 71 | for interest |
| 72 | filter |
| 73 | { |
| 74 | type name |
| 75 | name /localhop/nfd/rib |
| 76 | relation is-prefix-of |
| 77 | } |
| 78 | checker |
| 79 | { |
| 80 | type customized |
| 81 | sig-type ecdsa-sha256 |
| 82 | key-locator |
| 83 | { |
| 84 | type name |
| 85 | name /TrustAnchor-identity/Derived-identity |
| 86 | relation is-prefix-of |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | rule |
| 91 | { |
| 92 | id rule-id2 |
| 93 | for data |
| 94 | filter |
| 95 | { |
| 96 | type name |
| 97 | name /TrustAnchor-identity/Derived-identity/KEY |
| 98 | relation is-prefix-of |
| 99 | } |
| 100 | checker |
| 101 | { |
| 102 | type customized |
| 103 | sig-type ecdsa-sha256 |
| 104 | key-locator |
| 105 | { |
| 106 | type name |
| 107 | name /TrustAnchor-identity |
| 108 | relation is-prefix-of |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | trust-anchor |
| 113 | { |
| 114 | type file |
| 115 | file-name signer.ndncert |
| 116 | } |
| 117 | )CONF"; |
| 118 | return makeSection(config); |
| 119 | } |
| 120 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 121 | class RibManagerFixture : public ManagerCommonFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 122 | { |
| 123 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 124 | RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib) |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 125 | : m_status(status) |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 126 | , m_anchorId("/TrustAnchor-identity") |
| 127 | , m_derivedId("/TrustAnchor-identity/Derived-identity") |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 128 | , m_nfdController(m_face, m_keyChain) |
| 129 | , m_fibUpdater(m_rib, m_nfdController) |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame] | 130 | , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 131 | { |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 132 | addIdentity(m_anchorId); |
| 133 | addIdentity(m_derivedId); |
| 134 | |
| 135 | m_derivedCert = m_keyChain.getPib().getIdentity(m_derivedId).getDefaultKey().getDefaultCertificate(); |
| 136 | ndn::SignatureInfo signatureInfo; |
| 137 | signatureInfo.setValidityPeriod(m_derivedCert.getValidityPeriod()); |
| 138 | ndn::security::SigningInfo signingInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID, |
| 139 | m_anchorId, signatureInfo); |
| 140 | m_keyChain.sign(m_derivedCert, signingInfo); |
| 141 | saveIdentityCertificate(m_anchorId, "signer.ndncert", true); |
| 142 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 143 | if (m_status.isLocalhostConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 144 | m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 145 | } |
| 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 | |
| 159 | m_face.onSendInterest.connect([this] (const Interest& interest) { |
| 160 | if (interest.getName().isPrefixOf(m_derivedCert.getName())) { |
| 161 | if (m_status.isLocalhopConfigured && interest.template getTag<lp::NextHopFaceIdTag>() != nullptr) { |
| 162 | m_face.put(m_derivedCert); |
| 163 | } |
| 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 | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 176 | ControlParameters params(interest.getName().get(-5).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"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 178 | params.setFaceId(1).setCost(0); |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 179 | ControlResponse resp; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 180 | |
| 181 | resp.setCode(200).setBody(params.wireEncode()); |
| 182 | shared_ptr<Data> data = make_shared<Data>(interest.getName()); |
| 183 | data->setContent(resp.wireEncode()); |
| 184 | |
| 185 | m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); |
| 186 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 187 | m_face.getIoService().post([this, data] { m_face.receive(*data); }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | Name commandPrefix("/localhost/nfd/fib/add-nexthop"); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 191 | for (const auto& command : m_face.sentInterests) { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 192 | if (commandPrefix.isPrefixOf(command.getName())) { |
| 193 | replyFibAddCommand(command); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 194 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | // clear commands and responses |
| 199 | m_responses.clear(); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 200 | m_face.sentInterests.clear(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 203 | void |
| 204 | clearRib() |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 205 | { |
| 206 | while (!m_rib.empty()) { |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 207 | m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | public: |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 212 | static ControlParameters |
| 213 | makeRegisterParameters(const Name& name, uint64_t faceId = 0, |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 214 | time::milliseconds expiry = time::milliseconds::max()) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 215 | { |
| 216 | return ControlParameters() |
| 217 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 218 | .setFaceId(faceId) |
| 219 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 220 | .setCost(10) |
| 221 | .setFlags(0) |
| 222 | .setExpirationPeriod(expiry); |
| 223 | } |
| 224 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 225 | static ControlParameters |
| 226 | makeUnregisterParameters(const Name& name, uint64_t faceId = 0) |
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 | } |
| 233 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 234 | protected: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 235 | ConfigurationStatus m_status; |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 236 | Name m_anchorId; |
| 237 | Name m_derivedId; |
Alexander Afanasyev | a158370 | 2020-06-03 13:55:45 -0400 | [diff] [blame^] | 238 | ndn::security::Certificate m_derivedCert; |
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; |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 242 | rib::tests::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 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 260 | BOOST_CHECK_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 | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 306 | using AllFixtures = boost::mpl::vector< |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 307 | UnauthorizedRibManagerFixture, |
| 308 | LocalhostAuthorizedRibManagerFixture, |
| 309 | LocalhopAuthorizedRibManagerFixture, |
| 310 | AuthorizedRibManagerFixture |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 311 | >; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 312 | |
| 313 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T) |
| 314 | { |
| 315 | auto parameters = this->makeRegisterParameters("/test-authorization", 9527); |
| 316 | auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters); |
Zhiyi Zhang | a499aa2 | 2019-09-24 15:00:40 -0700 | [diff] [blame] | 317 | auto commandHop = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters, |
| 318 | this->m_derivedId); |
| 319 | if (this->m_status.isLocalhopConfigured) { |
| 320 | commandHop.setTag(make_shared<lp::IncomingFaceIdTag>(123)); |
| 321 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 322 | auto successResp = this->makeResponse(200, "Success", parameters); |
| 323 | auto failureResp = ControlResponse(403, "authorization rejected"); |
| 324 | |
| 325 | BOOST_CHECK_EQUAL(this->m_responses.size(), 0); |
| 326 | this->receiveInterest(commandHost); |
| 327 | this->receiveInterest(commandHop); |
| 328 | |
| 329 | auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1; |
| 330 | auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp; |
| 331 | auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp; |
| 332 | |
| 333 | BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 334 | BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 335 | ManagerCommonFixture::CheckResponseResult::OK); |
| 336 | if (nExpectedResponses == 2) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 338 | ManagerCommonFixture::CheckResponseResult::OK); |
| 339 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 340 | } |
| 341 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 342 | BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture) |
| 343 | |
| 344 | BOOST_AUTO_TEST_CASE(Basic) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 345 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 346 | auto paramsRegister = makeRegisterParameters("/test-register-unregister", 9527); |
| 347 | auto paramsUnregister = makeUnregisterParameters("/test-register-unregister", 9527); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 348 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 349 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 350 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
| 351 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 352 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 353 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 354 | receiveInterest(commandRegister); |
| 355 | receiveInterest(commandUnregister); |
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 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 358 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 359 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 360 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 361 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 362 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 363 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 364 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 365 | rib::FibUpdate::createAddUpdate("/test-register-unregister", 9527, 10)); |
| 366 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 367 | rib::FibUpdate::createRemoveUpdate("/test-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 368 | } |
| 369 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 370 | BOOST_AUTO_TEST_CASE(SelfOperation) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 371 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 372 | auto paramsRegister = makeRegisterParameters("/test-self-register-unregister"); |
| 373 | auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister"); |
| 374 | BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0); |
| 375 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 376 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 377 | const uint64_t inFaceId = 9527; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 378 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 379 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
| 380 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 381 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
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 | receiveInterest(commandRegister); |
| 384 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 385 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 386 | paramsRegister.setFaceId(inFaceId); |
| 387 | paramsUnregister.setFaceId(inFaceId); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 388 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 389 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 391 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 392 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 393 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 394 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 395 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 396 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 397 | rib::FibUpdate::createAddUpdate("/test-self-register-unregister", 9527, 10)); |
| 398 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 399 | rib::FibUpdate::createRemoveUpdate("/test-self-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 400 | } |
| 401 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 402 | BOOST_AUTO_TEST_CASE(Expiration) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 403 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 404 | auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 405 | auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527); |
| 406 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 407 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 408 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 409 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); // the registered route has expired |
| 410 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 411 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
| 412 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 413 | rib::FibUpdate::createRemoveUpdate("/test-expiry", 9527)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 414 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 415 | m_fibUpdater.updates.clear(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 416 | paramsRegister.setExpirationPeriod(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 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(), 1); // the registered route is still active |
| 421 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 422 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 425 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 426 | { |
| 427 | Name prefix; |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 428 | while (prefix.size() <= Fib::getMaxDepth()) { |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 429 | prefix.append("A"); |
| 430 | } |
| 431 | auto params = makeRegisterParameters(prefix, 2899); |
| 432 | auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params); |
| 433 | receiveInterest(command); |
| 434 | |
| 435 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 436 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), |
| 437 | ControlResponse(414, "Route prefix cannot exceed " + |
| 438 | to_string(Fib::getMaxDepth()) + " components")), |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 439 | CheckResponseResult::OK); |
| 440 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 441 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 444 | BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister |
| 445 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 446 | BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 447 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 448 | uint64_t faceId = 0; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 449 | auto generateRoute = [&faceId] () -> rib::Route { |
| 450 | rib::Route route; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 451 | route.faceId = ++faceId; |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 452 | route.cost = route.faceId * 10; |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 453 | route.expires = nullopt; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 454 | return route; |
| 455 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 456 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 457 | const size_t nEntries = 108; |
| 458 | std::set<Name> actualPrefixes; |
| 459 | for (size_t i = 0; i < nEntries; ++i) { |
| 460 | Name prefix = Name("/test-dataset").appendNumber(i); |
| 461 | actualPrefixes.insert(prefix); |
| 462 | m_rib.insert(prefix, generateRoute()); |
| 463 | if (i & 0x1) { |
| 464 | m_rib.insert(prefix, generateRoute()); |
| 465 | m_rib.insert(prefix, generateRoute()); |
| 466 | } |
| 467 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 468 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 469 | receiveInterest(*makeInterest("/localhost/nfd/rib/list", true)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 470 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 471 | Block content = concatenateResponses(); |
| 472 | content.parse(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 473 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 474 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 475 | std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 476 | for (size_t idx = 0; idx < nEntries; ++idx) { |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 477 | ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 478 | receivedRecords.push_back(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 479 | actualPrefixes.erase(decodedEntry.getName()); |
| 480 | |
| 481 | auto matchedEntryIt = m_rib.find(decodedEntry.getName()); |
| 482 | BOOST_REQUIRE(matchedEntryIt != m_rib.end()); |
| 483 | |
| 484 | auto matchedEntry = matchedEntryIt->second; |
| 485 | BOOST_REQUIRE(matchedEntry != nullptr); |
| 486 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 487 | expectedRecords.emplace_back(); |
| 488 | expectedRecords.back().setName(matchedEntry->getName()); |
| 489 | for (const auto& route : matchedEntry->getRoutes()) { |
| 490 | expectedRecords.back().addRoute(ndn::nfd::Route() |
| 491 | .setFaceId(route.faceId) |
| 492 | .setOrigin(route.origin) |
| 493 | .setCost(route.cost) |
| 494 | .setFlags(route.flags)); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 495 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | BOOST_CHECK_EQUAL(actualPrefixes.size(), 0); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 499 | BOOST_CHECK_EQUAL_COLLECTIONS(receivedRecords.begin(), receivedRecords.end(), |
| 500 | expectedRecords.begin(), expectedRecords.end()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 503 | BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture) |
| 504 | |
| 505 | BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 506 | { |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 507 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 508 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 509 | advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 510 | BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 2); |
| 511 | BOOST_CHECK_EQUAL(m_face.sentInterests[0].getName(), "/localhost/nfd/faces/events"); |
| 512 | BOOST_CHECK_EQUAL(m_face.sentInterests[1].getName(), "/localhost/nfd/faces/list"); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 515 | BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 516 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 517 | auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1"); |
| 518 | auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2"); |
| 519 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1))); |
| 520 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2))); |
| 521 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2))); |
| 522 | BOOST_REQUIRE_EQUAL(m_rib.size(), 3); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 523 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 524 | ndn::nfd::FaceStatus status; |
| 525 | status.setFaceId(1); |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 526 | std::vector<ndn::nfd::FaceStatus> activeFaces; |
| 527 | activeFaces.push_back(status); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 528 | |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 529 | m_manager.removeInvalidFaces(activeFaces); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 530 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 531 | BOOST_REQUIRE_EQUAL(m_rib.size(), 1); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 532 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 533 | auto it1 = m_rib.find("/test-remove-invalid-faces-1"); |
| 534 | auto it2 = m_rib.find("/test-remove-invalid-faces-2"); |
| 535 | BOOST_CHECK(it2 == m_rib.end()); |
| 536 | BOOST_REQUIRE(it1 != m_rib.end()); |
| 537 | BOOST_CHECK(it1->second->hasFaceId(1)); |
| 538 | BOOST_CHECK(!it1->second->hasFaceId(2)); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 539 | } |
| 540 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 541 | BOOST_AUTO_TEST_CASE(OnNotification) |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 542 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 543 | auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1); |
| 544 | auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1); |
| 545 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1)); |
| 546 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2)); |
| 547 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 548 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 549 | auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) { |
| 550 | return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 551 | }; |
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 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 554 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 555 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 556 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 557 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 558 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 559 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 560 | } |
| 561 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 562 | BOOST_AUTO_TEST_SUITE_END() // FaceMonitor |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 563 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 564 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 565 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 566 | |
| 567 | } // namespace tests |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 568 | } // namespace nfd |