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