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