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