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