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