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