Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014 Regents of the University of California, |
| 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 |
| 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-manager.hpp" |
Alexander Afanasyev | 03ea3eb | 2014-04-17 18:19:06 -0700 | [diff] [blame] | 27 | #include "core/global-io.hpp" |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 28 | #include "core/logger.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
| 31 | namespace rib { |
| 32 | |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 33 | NFD_LOG_INIT("RibManager"); |
| 34 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 35 | const Name RibManager::COMMAND_PREFIX = "/localhost/nfd/rib"; |
| 36 | const Name RibManager::REMOTE_COMMAND_PREFIX = "/localhop/nfd/rib"; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 37 | |
| 38 | const size_t RibManager::COMMAND_UNSIGNED_NCOMPS = |
| 39 | RibManager::COMMAND_PREFIX.size() + |
| 40 | 1 + // verb |
| 41 | 1; // verb options |
| 42 | |
| 43 | const size_t RibManager::COMMAND_SIGNED_NCOMPS = |
| 44 | RibManager::COMMAND_UNSIGNED_NCOMPS + |
| 45 | 4; // (timestamp, nonce, signed info tlv, signature tlv) |
| 46 | |
| 47 | const RibManager::VerbAndProcessor RibManager::COMMAND_VERBS[] = |
| 48 | { |
| 49 | VerbAndProcessor( |
| 50 | Name::Component("register"), |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 51 | &RibManager::registerEntry |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 52 | ), |
| 53 | |
| 54 | VerbAndProcessor( |
| 55 | Name::Component("unregister"), |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 56 | &RibManager::unregisterEntry |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 57 | ), |
| 58 | }; |
| 59 | |
Alexander Afanasyev | 03ea3eb | 2014-04-17 18:19:06 -0700 | [diff] [blame] | 60 | inline static void |
| 61 | NullDeleter(boost::asio::io_service* variable) |
| 62 | { |
| 63 | // do nothing |
| 64 | } |
| 65 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 66 | RibManager::RibManager() |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 67 | : m_face(shared_ptr<boost::asio::io_service>(&getGlobalIoService(), &NullDeleter)) |
| 68 | , m_nfdController(new ndn::nfd::Controller(m_face)) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 69 | , m_validator(m_face) |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 70 | , m_faceMonitor(m_face) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 71 | , m_verbDispatch(COMMAND_VERBS, |
| 72 | COMMAND_VERBS + (sizeof(COMMAND_VERBS) / sizeof(VerbAndProcessor))) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | RibManager::registerWithNfd() |
| 78 | { |
| 79 | //check whether the components of localhop and localhost prefixes are same |
| 80 | BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size()); |
| 81 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 82 | NFD_LOG_INFO("Setting interest filter on: " << COMMAND_PREFIX); |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 83 | m_face.setController(m_nfdController); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 84 | m_face.setInterestFilter(COMMAND_PREFIX, |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 85 | bind(&RibManager::onRibRequest, this, _2), |
| 86 | bind(&RibManager::setInterestFilterFailed, this, _1, _2)); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 88 | NFD_LOG_INFO("Setting interest filter on: " << REMOTE_COMMAND_PREFIX); |
| 89 | m_face.setInterestFilter(REMOTE_COMMAND_PREFIX, |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 90 | bind(&RibManager::onRibRequest, this, _2), |
| 91 | bind(&RibManager::setInterestFilterFailed, this, _1, _2)); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 93 | NFD_LOG_INFO("Start monitoring face create/destroy events"); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 94 | m_faceMonitor.addSubscriber(boost::bind(&RibManager::onNotification, this, _1)); |
| 95 | m_faceMonitor.startNotifications(); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | RibManager::setConfigFile(ConfigFile& configFile) |
| 100 | { |
Steve DiBenedetto | 34c95f7 | 2014-04-17 20:56:00 -0600 | [diff] [blame] | 101 | configFile.addSectionHandler("rib_security", |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 102 | bind(&RibManager::onConfig, this, _1, _2, _3)); |
| 103 | } |
| 104 | |
| 105 | void |
| 106 | RibManager::onConfig(const ConfigSection& configSection, |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 107 | bool isDryRun, |
| 108 | const std::string& filename) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 109 | { |
| 110 | /// \todo remove check after validator-conf replaces settings on each load |
| 111 | if (!isDryRun) |
| 112 | m_validator.load(configSection, filename); |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | RibManager::setInterestFilterFailed(const Name& name, const std::string& msg) |
| 117 | { |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 118 | NFD_LOG_ERROR("Error in setting interest filter (" << name << "): " << msg); |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 119 | m_face.shutdown(); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void |
| 123 | RibManager::sendResponse(const Name& name, |
| 124 | const ControlResponse& response) |
| 125 | { |
| 126 | const Block& encodedControl = response.wireEncode(); |
| 127 | |
| 128 | Data responseData(name); |
| 129 | responseData.setContent(encodedControl); |
| 130 | |
| 131 | m_keyChain.sign(responseData); |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 132 | m_face.put(responseData); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void |
| 136 | RibManager::sendResponse(const Name& name, |
| 137 | uint32_t code, |
| 138 | const std::string& text) |
| 139 | { |
| 140 | ControlResponse response(code, text); |
| 141 | sendResponse(name, response); |
| 142 | } |
| 143 | |
| 144 | void |
| 145 | RibManager::onRibRequest(const Interest& request) |
| 146 | { |
| 147 | m_validator.validate(request, |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 148 | bind(&RibManager::onCommandValidated, this, _1), |
| 149 | bind(&RibManager::onCommandValidationFailed, this, _1, _2)); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 153 | RibManager::onCommandValidated(const shared_ptr<const Interest>& request) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 154 | { |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 155 | // REMOTE_COMMAND_PREFIX number of componenets are same as |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 156 | // NRD_COMMAND_PREFIX's so no extra checks are required. |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 157 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 158 | const Name& command = request->getName(); |
| 159 | const Name::Component& verb = command[COMMAND_PREFIX.size()]; |
| 160 | const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1]; |
| 161 | |
| 162 | VerbDispatchTable::const_iterator verbProcessor = m_verbDispatch.find(verb); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 163 | if (verbProcessor != m_verbDispatch.end()) |
| 164 | { |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 165 | ControlParameters parameters; |
| 166 | if (!extractParameters(parameterComponent, parameters)) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 167 | { |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 168 | NFD_LOG_DEBUG("command result: malformed verb: " << verb); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 169 | sendResponse(command, 400, "Malformed command"); |
| 170 | return; |
| 171 | } |
| 172 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 173 | if (!parameters.hasFaceId() || parameters.getFaceId() == 0) |
| 174 | { |
| 175 | parameters.setFaceId(request->getIncomingFaceId()); |
| 176 | } |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 177 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 178 | NFD_LOG_DEBUG("command result: processing verb: " << verb); |
| 179 | (verbProcessor->second)(this, request, parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 180 | } |
| 181 | else |
| 182 | { |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 183 | NFD_LOG_DEBUG("Unsupported command: " << verb); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 184 | sendResponse(request->getName(), 501, "Unsupported command"); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 189 | RibManager::registerEntry(const shared_ptr<const Interest>& request, |
| 190 | ControlParameters& parameters) |
| 191 | { |
| 192 | ndn::nfd::RibRegisterCommand command; |
| 193 | |
| 194 | if (!validateParameters(command, parameters)) |
| 195 | { |
| 196 | NFD_LOG_DEBUG("register result: FAIL reason: malformed"); |
| 197 | sendResponse(request->getName(), 400, "Malformed command"); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | RibEntry ribEntry; |
| 202 | ribEntry.name = parameters.getName(); |
| 203 | ribEntry.faceId = parameters.getFaceId(); |
| 204 | ribEntry.origin = parameters.getOrigin(); |
| 205 | ribEntry.cost = parameters.getCost(); |
| 206 | ribEntry.flags = parameters.getFlags(); |
| 207 | ribEntry.expires = time::steady_clock::now() + parameters.getExpirationPeriod(); |
| 208 | |
| 209 | NFD_LOG_TRACE("register prefix: " << ribEntry); |
| 210 | |
| 211 | // For right now, just pass the options to fib as it is, |
| 212 | // without processing flags. Later options will be first added to |
| 213 | // Rib tree, then nrd will generate fib updates based on flags and then |
| 214 | // will add next hops one by one.. |
| 215 | m_managedRib.insert(ribEntry); |
| 216 | m_nfdController->start<ndn::nfd::FibAddNextHopCommand>( |
| 217 | ControlParameters() |
| 218 | .setName(ribEntry.name) |
| 219 | .setFaceId(ribEntry.faceId) |
| 220 | .setCost(ribEntry.cost), |
| 221 | bind(&RibManager::onRegSuccess, this, request, parameters, ribEntry), |
| 222 | bind(&RibManager::onCommandError, this, _1, _2, request, ribEntry)); |
| 223 | } |
| 224 | |
| 225 | void |
| 226 | RibManager::unregisterEntry(const shared_ptr<const Interest>& request, |
| 227 | ControlParameters& parameters) |
| 228 | { |
Alexander Afanasyev | ce7520e | 2014-04-28 09:40:06 -0700 | [diff] [blame] | 229 | ndn::nfd::RibUnregisterCommand command; |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 230 | |
| 231 | if (!validateParameters(command, parameters)) |
| 232 | { |
| 233 | NFD_LOG_DEBUG("register result: FAIL reason: malformed"); |
| 234 | sendResponse(request->getName(), 400, "Malformed command"); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | RibEntry ribEntry; |
| 239 | ribEntry.name = parameters.getName(); |
| 240 | ribEntry.faceId = parameters.getFaceId(); |
| 241 | ribEntry.origin = parameters.getOrigin(); |
| 242 | |
| 243 | NFD_LOG_TRACE("unregister prefix: " << ribEntry); |
| 244 | |
| 245 | m_nfdController->start<ndn::nfd::FibRemoveNextHopCommand>( |
| 246 | ControlParameters() |
| 247 | .setName(ribEntry.name) |
| 248 | .setFaceId(ribEntry.faceId), |
| 249 | bind(&RibManager::onUnRegSuccess, this, request, parameters, ribEntry), |
| 250 | bind(&RibManager::onCommandError, this, _1, _2, request, ribEntry)); |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | RibManager::onCommandValidationFailed(const shared_ptr<const Interest>& request, |
| 255 | const std::string& failureInfo) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 256 | { |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 257 | NFD_LOG_DEBUG("RibRequestValidationFailed: " << failureInfo); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 258 | sendResponse(request->getName(), 403, failureInfo); |
| 259 | } |
| 260 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 261 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 262 | bool |
| 263 | RibManager::extractParameters(const Name::Component& parameterComponent, |
| 264 | ControlParameters& extractedParameters) |
| 265 | { |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 266 | try |
| 267 | { |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 268 | Block rawParameters = parameterComponent.blockFromValue(); |
| 269 | extractedParameters.wireDecode(rawParameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 270 | } |
| 271 | catch (const ndn::Tlv::Error& e) |
| 272 | { |
| 273 | return false; |
| 274 | } |
| 275 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 276 | NFD_LOG_DEBUG("Parameters parsed OK"); |
| 277 | return true; |
| 278 | } |
| 279 | |
| 280 | bool |
| 281 | RibManager::validateParameters(const ControlCommand& command, |
| 282 | ControlParameters& parameters) |
| 283 | { |
| 284 | try |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 285 | { |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 286 | command.validateRequest(parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 287 | } |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 288 | catch (const ControlCommand::ArgumentError&) |
| 289 | { |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | command.applyDefaultsToRequest(parameters); |
| 294 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 295 | return true; |
| 296 | } |
| 297 | |
| 298 | void |
| 299 | RibManager::onCommandError(uint32_t code, const std::string& error, |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 300 | const shared_ptr<const Interest>& request, |
| 301 | const RibEntry& ribEntry) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 302 | { |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 303 | NFD_LOG_ERROR("NFD returned an error: " << error << " (code: " << code << ")"); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 304 | |
| 305 | ControlResponse response; |
| 306 | |
| 307 | if (code == 404) |
| 308 | { |
| 309 | response.setCode(code); |
| 310 | response.setText(error); |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | response.setCode(533); |
| 315 | std::ostringstream os; |
| 316 | os << "Failure to update NFD " << "(NFD Error: " << code << " " << error << ")"; |
| 317 | response.setText(os.str()); |
| 318 | } |
| 319 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 320 | sendResponse(request->getName(), response); |
| 321 | m_managedRib.erase(ribEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 325 | RibManager::onRegSuccess(const shared_ptr<const Interest>& request, |
| 326 | const ControlParameters& parameters, |
| 327 | const RibEntry& ribEntry) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 328 | { |
| 329 | ControlResponse response; |
| 330 | |
| 331 | response.setCode(200); |
| 332 | response.setText("Success"); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 333 | response.setBody(parameters.wireEncode()); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 334 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 335 | NFD_LOG_TRACE("onRegSuccess: registered " << ribEntry); |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 336 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 337 | sendResponse(request->getName(), response); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 340 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 341 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 342 | RibManager::onUnRegSuccess(const shared_ptr<const Interest>& request, |
| 343 | const ControlParameters& parameters, |
| 344 | const RibEntry& ribEntry) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 345 | { |
| 346 | ControlResponse response; |
| 347 | |
| 348 | response.setCode(200); |
| 349 | response.setText("Success"); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 350 | response.setBody(parameters.wireEncode()); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 351 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 352 | NFD_LOG_TRACE("onUnRegSuccess: unregistered " << ribEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 353 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 354 | sendResponse(request->getName(), response); |
| 355 | m_managedRib.erase(ribEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 358 | void |
| 359 | RibManager::onControlHeaderSuccess() |
| 360 | { |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 361 | NFD_LOG_DEBUG("Local control header enabled"); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | void |
| 365 | RibManager::onControlHeaderError(uint32_t code, const std::string& reason) |
| 366 | { |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 367 | NFD_LOG_ERROR("Error: couldn't enable local control header " |
| 368 | << "(code: " << code << ", info: " << reason << ")"); |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 369 | m_face.shutdown(); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void |
| 373 | RibManager::enableLocalControlHeader() |
| 374 | { |
| 375 | m_nfdController->start<ndn::nfd::FaceEnableLocalControlCommand>( |
| 376 | ControlParameters() |
| 377 | .setLocalControlFeature(ndn::nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID), |
| 378 | bind(&RibManager::onControlHeaderSuccess, this), |
| 379 | bind(&RibManager::onControlHeaderError, this, _1, _2)); |
| 380 | } |
| 381 | |
| 382 | void |
| 383 | RibManager::onNotification(const FaceEventNotification& notification) |
| 384 | { |
| 385 | /// \todo A notification can be missed, in this case check Facelist |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 386 | NFD_LOG_TRACE("onNotification: " << notification); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 387 | if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) { //face destroyed |
| 388 | m_managedRib.erase(notification.getFaceId()); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | } // namespace rib |
| 393 | } // namespace nfd |