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 | /* |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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" |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 27 | #include "core/fib-max-depth.hpp" |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 28 | #include "rib/fib-updater.hpp" |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 29 | |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 30 | #include "manager-common-fixture.hpp" |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 31 | |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 32 | #include <ndn-cxx/lp/tags.hpp> |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 33 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
| 34 | #include <ndn-cxx/mgmt/nfd/rib-entry.hpp> |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 35 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 36 | namespace nfd { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 37 | namespace tests { |
| 38 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 39 | struct ConfigurationStatus |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 40 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 41 | bool isLocalhostConfigured; |
| 42 | bool isLocalhopConfigured; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 45 | static ConfigSection |
| 46 | getValidatorConfigSection() |
| 47 | { |
| 48 | ConfigSection section; |
| 49 | section.put("trust-anchor.type", "any"); |
| 50 | return section; |
| 51 | } |
| 52 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 53 | class RibManagerFixture : public ManagerCommonFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 54 | { |
| 55 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 56 | RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib) |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 57 | : m_commands(m_face.sentInterests) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 58 | , m_status(status) |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 59 | , m_nfdController(m_face, m_keyChain) |
| 60 | , m_fibUpdater(m_rib, m_nfdController) |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame^] | 61 | , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 62 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 63 | m_rib.mockFibResponse = [] (const rib::RibUpdateBatch& batch) { |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 64 | BOOST_CHECK(batch.begin() != batch.end()); |
| 65 | return true; |
| 66 | }; |
| 67 | m_rib.wantMockFibResponseOnce = false; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 68 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 69 | if (m_status.isLocalhostConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 70 | m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 71 | } |
| 72 | if (m_status.isLocalhopConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 73 | m_manager.enableLocalhop(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 74 | } |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 75 | else { |
| 76 | m_manager.disableLocalhop(); |
| 77 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 78 | |
| 79 | registerWithNfd(); |
| 80 | |
| 81 | if (shouldClearRib) { |
| 82 | clearRib(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | private: |
| 87 | void |
| 88 | registerWithNfd() |
| 89 | { |
| 90 | m_manager.registerWithNfd(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 91 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 92 | |
| 93 | auto replyFibAddCommand = [this] (const Interest& interest) { |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 94 | ControlParameters params(interest.getName().get(-5).blockFromValue()); |
Junxiao Shi | fde3f54 | 2016-07-10 19:54:53 +0000 | [diff] [blame] | 95 | BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 96 | params.setFaceId(1).setCost(0); |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 97 | ControlResponse resp; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 98 | |
| 99 | resp.setCode(200).setBody(params.wireEncode()); |
| 100 | shared_ptr<Data> data = make_shared<Data>(interest.getName()); |
| 101 | data->setContent(resp.wireEncode()); |
| 102 | |
| 103 | m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); |
| 104 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 105 | m_face.getIoService().post([this, data] { m_face.receive(*data); }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | Name commandPrefix("/localhost/nfd/fib/add-nexthop"); |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 109 | for (const auto& command : m_commands) { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 110 | if (commandPrefix.isPrefixOf(command.getName())) { |
| 111 | replyFibAddCommand(command); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 112 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | // clear commands and responses |
| 117 | m_responses.clear(); |
| 118 | m_commands.clear(); |
| 119 | } |
| 120 | |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 121 | void |
| 122 | clearRib() |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 123 | { |
| 124 | while (!m_rib.empty()) { |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 125 | m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | public: |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 130 | static ControlParameters |
| 131 | makeRegisterParameters(const Name& name, uint64_t faceId = 0, |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 132 | time::milliseconds expiry = time::milliseconds::max()) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 133 | { |
| 134 | return ControlParameters() |
| 135 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 136 | .setFaceId(faceId) |
| 137 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 138 | .setCost(10) |
| 139 | .setFlags(0) |
| 140 | .setExpirationPeriod(expiry); |
| 141 | } |
| 142 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 143 | static ControlParameters |
| 144 | makeUnregisterParameters(const Name& name, uint64_t faceId = 0) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 145 | { |
| 146 | return ControlParameters() |
| 147 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 148 | .setFaceId(faceId) |
| 149 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 152 | public: |
| 153 | enum class CheckCommandResult { |
| 154 | OK, |
| 155 | OUT_OF_BOUNDARY, |
| 156 | WRONG_FORMAT, |
| 157 | WRONG_VERB, |
| 158 | WRONG_PARAMS_FORMAT, |
| 159 | WRONG_PARAMS_NAME, |
| 160 | WRONG_PARAMS_FACE |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 161 | }; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 162 | |
| 163 | CheckCommandResult |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 164 | checkCommand(size_t idx, const char* verbStr, const ControlParameters& expectedParams) const |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 165 | { |
| 166 | if (idx > m_commands.size()) { |
| 167 | return CheckCommandResult::OUT_OF_BOUNDARY; |
| 168 | } |
| 169 | const auto& name = m_commands[idx].getName(); |
| 170 | |
| 171 | if (!FIB_COMMAND_PREFIX.isPrefixOf(name) || FIB_COMMAND_PREFIX.size() >= name.size()) { |
| 172 | return CheckCommandResult::WRONG_FORMAT; |
| 173 | } |
| 174 | const auto& verb = name[FIB_COMMAND_PREFIX.size()]; |
| 175 | |
| 176 | Name::Component expectedVerb(verbStr); |
| 177 | if (verb != expectedVerb) { |
| 178 | return CheckCommandResult::WRONG_VERB; |
| 179 | } |
| 180 | |
| 181 | ControlParameters parameters; |
| 182 | try { |
| 183 | Block rawParameters = name[FIB_COMMAND_PREFIX.size() + 1].blockFromValue(); |
| 184 | parameters.wireDecode(rawParameters); |
| 185 | } |
| 186 | catch (...) { |
| 187 | return CheckCommandResult::WRONG_PARAMS_FORMAT; |
| 188 | } |
| 189 | |
| 190 | if (parameters.getName() != expectedParams.getName()) { |
| 191 | return CheckCommandResult::WRONG_PARAMS_NAME; |
| 192 | } |
| 193 | |
| 194 | if (parameters.getFaceId() != expectedParams.getFaceId()) { |
| 195 | return CheckCommandResult::WRONG_PARAMS_FACE; |
| 196 | } |
| 197 | |
| 198 | return CheckCommandResult::OK; |
| 199 | } |
| 200 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 201 | protected: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 202 | static const Name FIB_COMMAND_PREFIX; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 203 | std::vector<Interest>& m_commands; |
| 204 | ConfigurationStatus m_status; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 205 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 206 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 207 | rib::Rib m_rib; |
| 208 | rib::FibUpdater m_fibUpdater; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 209 | RibManager m_manager; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | const Name RibManagerFixture::FIB_COMMAND_PREFIX("/localhost/nfd/fib"); |
| 213 | |
| 214 | std::ostream& |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 215 | operator<<(std::ostream& os, RibManagerFixture::CheckCommandResult result) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 216 | { |
| 217 | switch (result) { |
| 218 | case RibManagerFixture::CheckCommandResult::OK: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 219 | return os << "OK"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 220 | case RibManagerFixture::CheckCommandResult::OUT_OF_BOUNDARY: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 221 | return os << "OUT_OF_BOUNDARY"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 222 | case RibManagerFixture::CheckCommandResult::WRONG_FORMAT: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 223 | return os << "WRONG_FORMAT"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 224 | case RibManagerFixture::CheckCommandResult::WRONG_VERB: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 225 | return os << "WRONG_VERB"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 226 | case RibManagerFixture::CheckCommandResult::WRONG_PARAMS_FORMAT: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 227 | return os << "WRONG_PARAMS_FORMAT"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 228 | case RibManagerFixture::CheckCommandResult::WRONG_PARAMS_NAME: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 229 | return os << "WRONG_PARAMS_NAME"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 230 | case RibManagerFixture::CheckCommandResult::WRONG_PARAMS_FACE: |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 231 | return os << "WRONG_PARAMS_FACE"; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 232 | }; |
| 233 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 234 | return os << static_cast<int>(result); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 237 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 238 | BOOST_AUTO_TEST_SUITE(TestRibManager) |
| 239 | |
| 240 | class AddTopPrefixFixture : public RibManagerFixture |
| 241 | { |
| 242 | public: |
| 243 | AddTopPrefixFixture() |
| 244 | : RibManagerFixture({true, true}, false) |
| 245 | { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 246 | } |
| 247 | }; |
| 248 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 249 | BOOST_FIXTURE_TEST_CASE(AddTopPrefix, AddTopPrefixFixture) |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 250 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 251 | BOOST_CHECK_EQUAL(m_rib.size(), 2); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 252 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 253 | std::vector<Name> ribEntryNames; |
| 254 | for (auto&& entry : m_rib) { |
| 255 | ribEntryNames.push_back(entry.first); |
| 256 | } |
| 257 | BOOST_CHECK_EQUAL(ribEntryNames[0], "/localhop/nfd"); |
| 258 | BOOST_CHECK_EQUAL(ribEntryNames[1], "/localhost/nfd"); |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 261 | class UnauthorizedRibManagerFixture : public RibManagerFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 262 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 263 | public: |
| 264 | UnauthorizedRibManagerFixture() |
| 265 | : RibManagerFixture({false, false}, true) |
| 266 | { |
| 267 | } |
| 268 | }; |
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 | class LocalhostAuthorizedRibManagerFixture : public RibManagerFixture |
| 271 | { |
| 272 | public: |
| 273 | LocalhostAuthorizedRibManagerFixture() |
| 274 | : RibManagerFixture({true, 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 LocalhopAuthorizedRibManagerFixture : public RibManagerFixture |
| 280 | { |
| 281 | public: |
| 282 | LocalhopAuthorizedRibManagerFixture() |
| 283 | : RibManagerFixture({false, true}, true) |
| 284 | { |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | class AuthorizedRibManagerFixture : public RibManagerFixture |
| 289 | { |
| 290 | public: |
| 291 | AuthorizedRibManagerFixture() |
| 292 | : RibManagerFixture({true, true}, true) |
| 293 | { |
| 294 | } |
| 295 | }; |
| 296 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 297 | using AllFixtures = boost::mpl::vector< |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 298 | UnauthorizedRibManagerFixture, |
| 299 | LocalhostAuthorizedRibManagerFixture, |
| 300 | LocalhopAuthorizedRibManagerFixture, |
| 301 | AuthorizedRibManagerFixture |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 302 | >; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 303 | |
| 304 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T) |
| 305 | { |
| 306 | auto parameters = this->makeRegisterParameters("/test-authorization", 9527); |
| 307 | auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters); |
| 308 | auto commandHop = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters); |
| 309 | auto successResp = this->makeResponse(200, "Success", parameters); |
| 310 | auto failureResp = ControlResponse(403, "authorization rejected"); |
| 311 | |
| 312 | BOOST_CHECK_EQUAL(this->m_responses.size(), 0); |
| 313 | this->receiveInterest(commandHost); |
| 314 | this->receiveInterest(commandHop); |
| 315 | |
| 316 | auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1; |
| 317 | auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp; |
| 318 | auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp; |
| 319 | |
| 320 | BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 321 | BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 322 | ManagerCommonFixture::CheckResponseResult::OK); |
| 323 | if (nExpectedResponses == 2) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 325 | ManagerCommonFixture::CheckResponseResult::OK); |
| 326 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 329 | BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture) |
| 330 | |
| 331 | BOOST_AUTO_TEST_CASE(Basic) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 332 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 333 | auto paramsRegister = makeRegisterParameters("/test-register-unregister", 9527); |
| 334 | auto paramsUnregister = makeUnregisterParameters("/test-register-unregister", 9527); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 335 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 336 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 337 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
| 338 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 339 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 340 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 341 | receiveInterest(commandRegister); |
| 342 | receiveInterest(commandUnregister); |
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 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 346 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 347 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 348 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 349 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 350 | BOOST_REQUIRE_EQUAL(m_commands.size(), 2); |
| 351 | BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK); |
| 352 | BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 353 | } |
| 354 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 355 | BOOST_AUTO_TEST_CASE(SelfOperation) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 356 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 357 | auto paramsRegister = makeRegisterParameters("/test-self-register-unregister"); |
| 358 | auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister"); |
| 359 | BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0); |
| 360 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 361 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 362 | const uint64_t inFaceId = 9527; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 363 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 364 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
| 365 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 366 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
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 | receiveInterest(commandRegister); |
| 369 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 370 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 371 | paramsRegister.setFaceId(inFaceId); |
| 372 | paramsUnregister.setFaceId(inFaceId); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 373 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 374 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 375 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 376 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 377 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 378 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 379 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 380 | BOOST_REQUIRE_EQUAL(m_commands.size(), 2); |
| 381 | BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK); |
| 382 | BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 383 | } |
| 384 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 385 | BOOST_AUTO_TEST_CASE(Expiration) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 386 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 387 | auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 388 | auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527); |
| 389 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 390 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 391 | advanceClocks(55_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 392 | BOOST_REQUIRE_EQUAL(m_commands.size(), 2); // the registered route has expired |
| 393 | BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK); |
| 394 | BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 395 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 396 | m_commands.clear(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 397 | paramsRegister.setExpirationPeriod(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 398 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 399 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 400 | advanceClocks(55_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 401 | BOOST_REQUIRE_EQUAL(m_commands.size(), 1); // the registered route is still active |
| 402 | BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 405 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 406 | { |
| 407 | Name prefix; |
| 408 | while (prefix.size() <= FIB_MAX_DEPTH) { |
| 409 | prefix.append("A"); |
| 410 | } |
| 411 | auto params = makeRegisterParameters(prefix, 2899); |
| 412 | auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params); |
| 413 | receiveInterest(command); |
| 414 | |
| 415 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 416 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), ControlResponse(414, |
| 417 | "Route prefix cannot exceed " + ndn::to_string(FIB_MAX_DEPTH) + |
| 418 | " components")), |
| 419 | CheckResponseResult::OK); |
| 420 | |
| 421 | BOOST_CHECK_EQUAL(m_commands.size(), 0); |
| 422 | } |
| 423 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 424 | BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister |
| 425 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 426 | BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 427 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 428 | uint64_t faceId = 0; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 429 | auto generateRoute = [&faceId] () -> rib::Route { |
| 430 | rib::Route route; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 431 | route.faceId = ++faceId; |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 432 | route.cost = route.faceId * 10; |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 433 | route.expires = nullopt; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 434 | return route; |
| 435 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 436 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 437 | const size_t nEntries = 108; |
| 438 | std::set<Name> actualPrefixes; |
| 439 | for (size_t i = 0; i < nEntries; ++i) { |
| 440 | Name prefix = Name("/test-dataset").appendNumber(i); |
| 441 | actualPrefixes.insert(prefix); |
| 442 | m_rib.insert(prefix, generateRoute()); |
| 443 | if (i & 0x1) { |
| 444 | m_rib.insert(prefix, generateRoute()); |
| 445 | m_rib.insert(prefix, generateRoute()); |
| 446 | } |
| 447 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 448 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 449 | receiveInterest(Interest("/localhost/nfd/rib/list")); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 450 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 451 | Block content = concatenateResponses(); |
| 452 | content.parse(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 453 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 454 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 455 | std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 456 | for (size_t idx = 0; idx < nEntries; ++idx) { |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 457 | ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 458 | receivedRecords.push_back(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 459 | actualPrefixes.erase(decodedEntry.getName()); |
| 460 | |
| 461 | auto matchedEntryIt = m_rib.find(decodedEntry.getName()); |
| 462 | BOOST_REQUIRE(matchedEntryIt != m_rib.end()); |
| 463 | |
| 464 | auto matchedEntry = matchedEntryIt->second; |
| 465 | BOOST_REQUIRE(matchedEntry != nullptr); |
| 466 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 467 | expectedRecords.emplace_back(); |
| 468 | expectedRecords.back().setName(matchedEntry->getName()); |
| 469 | for (const auto& route : matchedEntry->getRoutes()) { |
| 470 | expectedRecords.back().addRoute(ndn::nfd::Route() |
| 471 | .setFaceId(route.faceId) |
| 472 | .setOrigin(route.origin) |
| 473 | .setCost(route.cost) |
| 474 | .setFlags(route.flags)); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 475 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | BOOST_CHECK_EQUAL(actualPrefixes.size(), 0); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 479 | BOOST_CHECK_EQUAL_COLLECTIONS(receivedRecords.begin(), receivedRecords.end(), |
| 480 | expectedRecords.begin(), expectedRecords.end()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 481 | } |
| 482 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 483 | BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture) |
| 484 | |
| 485 | BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 486 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 487 | BOOST_CHECK_EQUAL(m_commands.size(), 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 488 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 489 | advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 490 | BOOST_REQUIRE_EQUAL(m_commands.size(), 2); |
| 491 | BOOST_CHECK_EQUAL(m_commands[0].getName(), "/localhost/nfd/faces/events"); |
| 492 | BOOST_CHECK_EQUAL(m_commands[1].getName(), "/localhost/nfd/faces/list"); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 495 | BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 496 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 497 | auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1"); |
| 498 | auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2"); |
| 499 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1))); |
| 500 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2))); |
| 501 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2))); |
| 502 | BOOST_REQUIRE_EQUAL(m_rib.size(), 3); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 503 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 504 | ndn::nfd::FaceStatus status; |
| 505 | status.setFaceId(1); |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 506 | std::vector<ndn::nfd::FaceStatus> activeFaces; |
| 507 | activeFaces.push_back(status); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 508 | |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 509 | m_manager.removeInvalidFaces(activeFaces); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 510 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 511 | BOOST_REQUIRE_EQUAL(m_rib.size(), 1); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 512 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 513 | auto it1 = m_rib.find("/test-remove-invalid-faces-1"); |
| 514 | auto it2 = m_rib.find("/test-remove-invalid-faces-2"); |
| 515 | BOOST_CHECK(it2 == m_rib.end()); |
| 516 | BOOST_REQUIRE(it1 != m_rib.end()); |
| 517 | BOOST_CHECK(it1->second->hasFaceId(1)); |
| 518 | BOOST_CHECK(!it1->second->hasFaceId(2)); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 519 | } |
| 520 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 521 | BOOST_AUTO_TEST_CASE(OnNotification) |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 522 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 523 | auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1); |
| 524 | auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1); |
| 525 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1)); |
| 526 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2)); |
| 527 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 528 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 529 | auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) { |
| 530 | return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 531 | }; |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 532 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 533 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 534 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 535 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 536 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 537 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 538 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 539 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 540 | } |
| 541 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 542 | BOOST_AUTO_TEST_SUITE_END() // FaceMonitor |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 543 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 544 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 545 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 546 | |
| 547 | } // namespace tests |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 548 | } // namespace nfd |