Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "face-manager.hpp" |
| 8 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 9 | #include "core/logger.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 10 | #include "core/face-uri.hpp" |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 11 | #include "core/network-interface.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 12 | #include "fw/face-table.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 13 | #include "face/tcp-factory.hpp" |
| 14 | #include "face/udp-factory.hpp" |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 15 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 16 | #include <ndn-cpp-dev/management/nfd-face-event-notification.hpp> |
| 17 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 18 | #ifdef HAVE_UNIX_SOCKETS |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 19 | #include "face/unix-stream-factory.hpp" |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 20 | #endif // HAVE_UNIX_SOCKETS |
| 21 | |
| 22 | #ifdef HAVE_PCAP |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 23 | #include "face/ethernet-factory.hpp" |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 24 | #endif // HAVE_PCAP |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 25 | |
| 26 | namespace nfd { |
| 27 | |
| 28 | NFD_LOG_INIT("FaceManager"); |
| 29 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 30 | const Name FaceManager::COMMAND_PREFIX("/localhost/nfd/faces"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 31 | |
| 32 | const size_t FaceManager::COMMAND_UNSIGNED_NCOMPS = |
| 33 | FaceManager::COMMAND_PREFIX.size() + |
| 34 | 1 + // verb |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 35 | 1; // verb parameters |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 36 | |
| 37 | const size_t FaceManager::COMMAND_SIGNED_NCOMPS = |
| 38 | FaceManager::COMMAND_UNSIGNED_NCOMPS + |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 39 | 4; // (timestamp, nonce, signed info tlv, signature tlv) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 40 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 41 | const FaceManager::SignedVerbAndProcessor FaceManager::SIGNED_COMMAND_VERBS[] = |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 42 | { |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 43 | SignedVerbAndProcessor( |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 44 | Name::Component("create"), |
| 45 | &FaceManager::createFace |
| 46 | ), |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 47 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 48 | SignedVerbAndProcessor( |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 49 | Name::Component("destroy"), |
| 50 | &FaceManager::destroyFace |
| 51 | ), |
| 52 | |
| 53 | SignedVerbAndProcessor( |
| 54 | Name::Component("enable-local-control"), |
| 55 | &FaceManager::enableLocalControl |
| 56 | ), |
| 57 | |
| 58 | SignedVerbAndProcessor( |
| 59 | Name::Component("disable-local-control"), |
| 60 | &FaceManager::disableLocalControl |
| 61 | ), |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 64 | const FaceManager::UnsignedVerbAndProcessor FaceManager::UNSIGNED_COMMAND_VERBS[] = |
| 65 | { |
| 66 | UnsignedVerbAndProcessor( |
| 67 | Name::Component("list"), |
| 68 | &FaceManager::listFaces |
| 69 | ), |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 70 | |
| 71 | UnsignedVerbAndProcessor( |
| 72 | Name::Component("events"), |
| 73 | &FaceManager::ignoreUnsignedVerb |
| 74 | ), |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | const Name FaceManager::LIST_COMMAND_PREFIX("/localhost/nfd/faces/list"); |
| 78 | const size_t FaceManager::LIST_COMMAND_NCOMPS = LIST_COMMAND_PREFIX.size(); |
| 79 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 80 | const Name FaceManager::EVENTS_COMMAND_PREFIX("/localhost/nfd/faces/events"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 81 | |
| 82 | FaceManager::FaceManager(FaceTable& faceTable, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 83 | shared_ptr<InternalFace> face) |
| 84 | : ManagerBase(face, FACE_MANAGER_PRIVILEGE) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 85 | , m_faceTable(faceTable) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 86 | , m_statusPublisher(m_faceTable, m_face, LIST_COMMAND_PREFIX) |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 87 | , m_notificationStream(m_face, EVENTS_COMMAND_PREFIX) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 88 | , m_signedVerbDispatch(SIGNED_COMMAND_VERBS, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 89 | SIGNED_COMMAND_VERBS + |
| 90 | (sizeof(SIGNED_COMMAND_VERBS) / sizeof(SignedVerbAndProcessor))) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 91 | , m_unsignedVerbDispatch(UNSIGNED_COMMAND_VERBS, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 92 | UNSIGNED_COMMAND_VERBS + |
| 93 | (sizeof(UNSIGNED_COMMAND_VERBS) / sizeof(UnsignedVerbAndProcessor))) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 94 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 95 | { |
| 96 | face->setInterestFilter("/localhost/nfd/faces", |
| 97 | bind(&FaceManager::onFaceRequest, this, _2)); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 98 | |
| 99 | m_faceTable.onAdd += bind(&FaceManager::onAddFace, this, _1); |
| 100 | m_faceTable.onRemove += bind(&FaceManager::onRemoveFace, this, _1); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 103 | FaceManager::~FaceManager() |
| 104 | { |
| 105 | |
| 106 | } |
| 107 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 108 | void |
| 109 | FaceManager::setConfigFile(ConfigFile& configFile) |
| 110 | { |
| 111 | configFile.addSectionHandler("face_system", |
Steve DiBenedetto | 1a3c673 | 2014-03-13 06:44:05 -0600 | [diff] [blame] | 112 | bind(&FaceManager::onConfig, this, _1, _2, _3)); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | void |
Steve DiBenedetto | 1a3c673 | 2014-03-13 06:44:05 -0600 | [diff] [blame] | 117 | FaceManager::onConfig(const ConfigSection& configSection, |
| 118 | bool isDryRun, |
| 119 | const std::string& filename) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 120 | { |
| 121 | bool hasSeenUnix = false; |
| 122 | bool hasSeenTcp = false; |
| 123 | bool hasSeenUdp = false; |
| 124 | bool hasSeenEther = false; |
| 125 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 126 | const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces()); |
| 127 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 128 | for (ConfigSection::const_iterator item = configSection.begin(); |
| 129 | item != configSection.end(); |
| 130 | ++item) |
| 131 | { |
| 132 | if (item->first == "unix") |
| 133 | { |
| 134 | if (hasSeenUnix) |
| 135 | throw Error("Duplicate \"unix\" section"); |
| 136 | hasSeenUnix = true; |
| 137 | |
| 138 | processSectionUnix(item->second, isDryRun); |
| 139 | } |
| 140 | else if (item->first == "tcp") |
| 141 | { |
| 142 | if (hasSeenTcp) |
| 143 | throw Error("Duplicate \"tcp\" section"); |
| 144 | hasSeenTcp = true; |
| 145 | |
| 146 | processSectionTcp(item->second, isDryRun); |
| 147 | } |
| 148 | else if (item->first == "udp") |
| 149 | { |
| 150 | if (hasSeenUdp) |
| 151 | throw Error("Duplicate \"udp\" section"); |
| 152 | hasSeenUdp = true; |
| 153 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 154 | processSectionUdp(item->second, isDryRun, nicList); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 155 | } |
| 156 | else if (item->first == "ether") |
| 157 | { |
| 158 | if (hasSeenEther) |
| 159 | throw Error("Duplicate \"ether\" section"); |
| 160 | hasSeenEther = true; |
| 161 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 162 | processSectionEther(item->second, isDryRun, nicList); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 163 | } |
| 164 | else |
| 165 | { |
| 166 | throw Error("Unrecognized option \"" + item->first + "\""); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | FaceManager::processSectionUnix(const ConfigSection& configSection, bool isDryRun) |
| 173 | { |
| 174 | // ; the unix section contains settings of UNIX stream faces and channels |
| 175 | // unix |
| 176 | // { |
| 177 | // listen yes ; set to 'no' to disable UNIX stream listener, default 'yes' |
| 178 | // path /var/run/nfd.sock ; UNIX stream listener path |
| 179 | // } |
| 180 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 181 | #if defined(HAVE_UNIX_SOCKETS) |
| 182 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 183 | bool needToListen = true; |
| 184 | std::string path = "/var/run/nfd.sock"; |
| 185 | |
| 186 | for (ConfigSection::const_iterator i = configSection.begin(); |
| 187 | i != configSection.end(); |
| 188 | ++i) |
| 189 | { |
| 190 | if (i->first == "path") |
| 191 | { |
| 192 | path = i->second.get_value<std::string>(); |
| 193 | } |
| 194 | else if (i->first == "listen") |
| 195 | { |
| 196 | needToListen = parseYesNo(i, i->first, "unix"); |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"unix\" section"); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if (!isDryRun) |
| 205 | { |
| 206 | shared_ptr<UnixStreamFactory> factory = make_shared<UnixStreamFactory>(); |
| 207 | shared_ptr<UnixStreamChannel> unixChannel = factory->createChannel(path); |
| 208 | |
| 209 | if (needToListen) |
| 210 | { |
| 211 | // Should acceptFailed callback be used somehow? |
| 212 | unixChannel->listen(bind(&FaceTable::add, &m_faceTable, _1), |
| 213 | UnixStreamChannel::ConnectFailedCallback()); |
| 214 | } |
| 215 | |
| 216 | m_factories.insert(std::make_pair("unix", factory)); |
| 217 | } |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 218 | #else |
| 219 | throw ConfigFile::Error("NFD was compiled without UNIX sockets support, cannot process \"unix\" section"); |
| 220 | #endif // HAVE_UNIX_SOCKETS |
| 221 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void |
| 225 | FaceManager::processSectionTcp(const ConfigSection& configSection, bool isDryRun) |
| 226 | { |
| 227 | // ; the tcp section contains settings of TCP faces and channels |
| 228 | // tcp |
| 229 | // { |
| 230 | // listen yes ; set to 'no' to disable TCP listener, default 'yes' |
| 231 | // port 6363 ; TCP listener port number |
| 232 | // } |
| 233 | |
| 234 | std::string port = "6363"; |
| 235 | bool needToListen = true; |
| 236 | |
| 237 | for (ConfigSection::const_iterator i = configSection.begin(); |
| 238 | i != configSection.end(); |
| 239 | ++i) |
| 240 | { |
| 241 | if (i->first == "port") |
| 242 | { |
| 243 | port = i->second.get_value<std::string>(); |
| 244 | } |
| 245 | else if (i->first == "listen") |
| 246 | { |
| 247 | needToListen = parseYesNo(i, i->first, "tcp"); |
| 248 | } |
| 249 | else |
| 250 | { |
| 251 | throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"tcp\" section"); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if (!isDryRun) |
| 256 | { |
| 257 | shared_ptr<TcpFactory> factory = make_shared<TcpFactory>(boost::cref(port)); |
| 258 | |
| 259 | using namespace boost::asio::ip; |
| 260 | |
| 261 | shared_ptr<TcpChannel> ipv4Channel = factory->createChannel("0.0.0.0", port); |
| 262 | shared_ptr<TcpChannel> ipv6Channel = factory->createChannel("::", port); |
| 263 | |
| 264 | if (needToListen) |
| 265 | { |
| 266 | // Should acceptFailed callback be used somehow? |
| 267 | |
| 268 | ipv4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), |
| 269 | TcpChannel::ConnectFailedCallback()); |
| 270 | ipv6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), |
| 271 | TcpChannel::ConnectFailedCallback()); |
| 272 | } |
| 273 | |
| 274 | m_factories.insert(std::make_pair("tcp", factory)); |
| 275 | m_factories.insert(std::make_pair("tcp4", factory)); |
| 276 | m_factories.insert(std::make_pair("tcp6", factory)); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 281 | FaceManager::processSectionUdp(const ConfigSection& configSection, |
| 282 | bool isDryRun, |
| 283 | const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 284 | { |
| 285 | // ; the udp section contains settings of UDP faces and channels |
| 286 | // udp |
| 287 | // { |
| 288 | // port 6363 ; UDP unicast port number |
| 289 | // idle_timeout 30 ; idle time (seconds) before closing a UDP unicast face |
| 290 | // keep_alive_interval 25; interval (seconds) between keep-alive refreshes |
| 291 | |
| 292 | // ; NFD creates one UDP multicast face per NIC |
| 293 | // mcast yes ; set to 'no' to disable UDP multicast, default 'yes' |
| 294 | // mcast_port 56363 ; UDP multicast port number |
| 295 | // mcast_group 224.0.23.170 ; UDP multicast group (IPv4 only) |
| 296 | // } |
| 297 | |
| 298 | std::string port = "6363"; |
| 299 | size_t timeout = 30; |
| 300 | size_t keepAliveInterval = 25; |
| 301 | bool useMcast = true; |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 302 | std::string mcastGroup = "224.0.23.170"; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 303 | std::string mcastPort = "56363"; |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 304 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 305 | |
| 306 | for (ConfigSection::const_iterator i = configSection.begin(); |
| 307 | i != configSection.end(); |
| 308 | ++i) |
| 309 | { |
| 310 | if (i->first == "port") |
| 311 | { |
| 312 | port = i->second.get_value<std::string>(); |
| 313 | } |
| 314 | else if (i->first == "idle_timeout") |
| 315 | { |
| 316 | try |
| 317 | { |
| 318 | timeout = i->second.get_value<size_t>(); |
| 319 | } |
| 320 | catch (const std::exception& e) |
| 321 | { |
| 322 | throw ConfigFile::Error("Invalid value for option \"" + |
| 323 | i->first + "\" in \"udp\" section"); |
| 324 | } |
| 325 | } |
| 326 | else if (i->first == "keep_alive_interval") |
| 327 | { |
| 328 | try |
| 329 | { |
| 330 | keepAliveInterval = i->second.get_value<size_t>(); |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame] | 331 | |
| 332 | /// \todo Make use of keepAliveInterval |
| 333 | (void)(keepAliveInterval); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 334 | } |
| 335 | catch (const std::exception& e) |
| 336 | { |
| 337 | throw ConfigFile::Error("Invalid value for option \"" + |
| 338 | i->first + "\" in \"udp\" section"); |
| 339 | } |
| 340 | } |
| 341 | else if (i->first == "mcast") |
| 342 | { |
| 343 | useMcast = parseYesNo(i, i->first, "udp"); |
| 344 | } |
| 345 | else if (i->first == "mcast_port") |
| 346 | { |
| 347 | mcastPort = i->second.get_value<std::string>(); |
| 348 | } |
| 349 | else if (i->first == "mcast_group") |
| 350 | { |
| 351 | using namespace boost::asio::ip; |
| 352 | mcastGroup = i->second.get_value<std::string>(); |
| 353 | try |
| 354 | { |
| 355 | address mcastGroupTest = address::from_string(mcastGroup); |
| 356 | if (!mcastGroupTest.is_v4()) |
| 357 | { |
| 358 | throw ConfigFile::Error("Invalid value for option \"" + |
| 359 | i->first + "\" in \"udp\" section"); |
| 360 | } |
| 361 | } |
| 362 | catch(const std::runtime_error& e) |
| 363 | { |
| 364 | throw ConfigFile::Error("Invalid value for option \"" + |
| 365 | i->first + "\" in \"udp\" section"); |
| 366 | } |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"udp\" section"); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | /// \todo what is keep alive interval used for? |
| 375 | |
| 376 | if (!isDryRun) |
| 377 | { |
| 378 | shared_ptr<UdpFactory> factory = make_shared<UdpFactory>(boost::cref(port)); |
| 379 | |
Steve DiBenedetto | b9906cf | 2014-03-27 09:18:28 -0600 | [diff] [blame] | 380 | shared_ptr<UdpChannel> v4Channel = |
| 381 | factory->createChannel("0.0.0.0", port, time::seconds(timeout)); |
| 382 | |
| 383 | shared_ptr<UdpChannel> v6Channel = |
| 384 | factory->createChannel("::", port, time::seconds(timeout)); |
| 385 | |
| 386 | v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), |
| 387 | UdpChannel::ConnectFailedCallback()); |
| 388 | |
| 389 | v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), |
| 390 | UdpChannel::ConnectFailedCallback()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 391 | |
| 392 | m_factories.insert(std::make_pair("udp", factory)); |
| 393 | m_factories.insert(std::make_pair("udp4", factory)); |
| 394 | m_factories.insert(std::make_pair("udp6", factory)); |
| 395 | |
| 396 | if (useMcast) |
| 397 | { |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 398 | for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin(); |
| 399 | i != nicList.end(); |
| 400 | ++i) |
| 401 | { |
| 402 | const shared_ptr<NetworkInterfaceInfo>& nic = *i; |
| 403 | if (nic->isUp() && nic->isMulticastCapable() && !nic->ipv4Addresses.empty()) |
| 404 | { |
| 405 | shared_ptr<MulticastUdpFace> newFace = |
| 406 | factory->createMulticastFace(nic->ipv4Addresses[0].to_string(), |
| 407 | mcastGroup, mcastPort); |
| 408 | |
Alexander Afanasyev | bbe3f0c | 2014-03-23 11:44:01 -0700 | [diff] [blame] | 409 | addCreatedFaceToForwarder(newFace); |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | } |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
| 416 | void |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 417 | FaceManager::processSectionEther(const ConfigSection& configSection, |
| 418 | bool isDryRun, |
| 419 | const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 420 | { |
| 421 | // ; the ether section contains settings of Ethernet faces and channels |
| 422 | // ether |
| 423 | // { |
| 424 | // ; NFD creates one Ethernet multicast face per NIC |
| 425 | // mcast yes ; set to 'no' to disable Ethernet multicast, default 'yes' |
| 426 | // mcast_group 01:00:5E:00:17:AA ; Ethernet multicast group |
| 427 | // } |
| 428 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 429 | #if defined(HAVE_PCAP) |
| 430 | |
| 431 | using ethernet::Address; |
| 432 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 433 | bool useMcast = true; |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 434 | Address mcastGroup(ethernet::getDefaultMulticastAddress()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 435 | |
| 436 | for (ConfigSection::const_iterator i = configSection.begin(); |
| 437 | i != configSection.end(); |
| 438 | ++i) |
| 439 | { |
| 440 | if (i->first == "mcast") |
| 441 | { |
| 442 | useMcast = parseYesNo(i, i->first, "ether"); |
| 443 | } |
| 444 | |
| 445 | else if (i->first == "mcast_group") |
| 446 | { |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 447 | mcastGroup = Address::fromString(i->second.get_value<std::string>()); |
| 448 | if (mcastGroup.isNull()) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 449 | { |
| 450 | throw ConfigFile::Error("Invalid value for option \"" + |
| 451 | i->first + "\" in \"ether\" section"); |
| 452 | } |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"ether\" section"); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | if (!isDryRun) |
| 461 | { |
| 462 | shared_ptr<EthernetFactory> factory = make_shared<EthernetFactory>(); |
| 463 | m_factories.insert(std::make_pair("ether", factory)); |
| 464 | |
| 465 | if (useMcast) |
| 466 | { |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 467 | for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin(); |
| 468 | i != nicList.end(); |
| 469 | ++i) |
| 470 | { |
| 471 | const shared_ptr<NetworkInterfaceInfo>& nic = *i; |
| 472 | if (nic->isUp() && nic->isMulticastCapable()) |
| 473 | { |
| 474 | try |
| 475 | { |
| 476 | shared_ptr<EthernetFace> newFace = |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 477 | factory->createMulticastFace(nic, mcastGroup); |
Alexander Afanasyev | bbe3f0c | 2014-03-23 11:44:01 -0700 | [diff] [blame] | 478 | |
| 479 | addCreatedFaceToForwarder(newFace); |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 480 | } |
| 481 | catch (const EthernetFactory::Error& factoryError) |
| 482 | { |
| 483 | NFD_LOG_ERROR(factoryError.what() << ", continuing"); |
| 484 | } |
| 485 | catch (const EthernetFace::Error& faceError) |
| 486 | { |
| 487 | NFD_LOG_ERROR(faceError.what() << ", continuing"); |
| 488 | } |
| 489 | } |
| 490 | } |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 493 | #else |
| 494 | throw ConfigFile::Error("NFD was compiled without libpcap, cannot process \"ether\" section"); |
| 495 | #endif // HAVE_PCAP |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
| 499 | void |
| 500 | FaceManager::onFaceRequest(const Interest& request) |
| 501 | { |
| 502 | const Name& command = request.getName(); |
| 503 | const size_t commandNComps = command.size(); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 504 | const Name::Component& verb = command.get(COMMAND_PREFIX.size()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 505 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 506 | UnsignedVerbDispatchTable::const_iterator unsignedVerbProcessor = m_unsignedVerbDispatch.find(verb); |
| 507 | if (unsignedVerbProcessor != m_unsignedVerbDispatch.end()) |
| 508 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 509 | NFD_LOG_DEBUG("command result: processing verb: " << verb); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 510 | (unsignedVerbProcessor->second)(this, boost::cref(request)); |
| 511 | } |
| 512 | else if (COMMAND_UNSIGNED_NCOMPS <= commandNComps && |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 513 | commandNComps < COMMAND_SIGNED_NCOMPS) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 514 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 515 | NFD_LOG_DEBUG("command result: unsigned verb: " << command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 516 | sendResponse(command, 401, "Signature required"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 517 | } |
| 518 | else if (commandNComps < COMMAND_SIGNED_NCOMPS || |
| 519 | !COMMAND_PREFIX.isPrefixOf(command)) |
| 520 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 521 | NFD_LOG_DEBUG("command result: malformed"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 522 | sendResponse(command, 400, "Malformed command"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 523 | } |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 524 | else |
| 525 | { |
| 526 | validate(request, |
| 527 | bind(&FaceManager::onValidatedFaceRequest, this, _1), |
| 528 | bind(&ManagerBase::onCommandValidationFailed, this, _1, _2)); |
| 529 | } |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | void |
| 533 | FaceManager::onValidatedFaceRequest(const shared_ptr<const Interest>& request) |
| 534 | { |
| 535 | const Name& command = request->getName(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 536 | const Name::Component& verb = command[COMMAND_PREFIX.size()]; |
| 537 | const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1]; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 538 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 539 | SignedVerbDispatchTable::const_iterator signedVerbProcessor = m_signedVerbDispatch.find(verb); |
| 540 | if (signedVerbProcessor != m_signedVerbDispatch.end()) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 541 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 542 | ControlParameters parameters; |
| 543 | if (!extractParameters(parameterComponent, parameters)) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 544 | { |
| 545 | sendResponse(command, 400, "Malformed command"); |
| 546 | return; |
| 547 | } |
| 548 | |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 549 | NFD_LOG_DEBUG("command result: processing verb: " << verb); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 550 | (signedVerbProcessor->second)(this, *request, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 551 | } |
| 552 | else |
| 553 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 554 | NFD_LOG_DEBUG("command result: unsupported verb: " << verb); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 555 | sendResponse(command, 501, "Unsupported command"); |
| 556 | } |
| 557 | |
| 558 | } |
| 559 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 560 | void |
Alexander Afanasyev | bbe3f0c | 2014-03-23 11:44:01 -0700 | [diff] [blame] | 561 | FaceManager::addCreatedFaceToForwarder(const shared_ptr<Face>& newFace) |
| 562 | { |
| 563 | m_faceTable.add(newFace); |
| 564 | |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 565 | NFD_LOG_DEBUG("Created face " << newFace->getUri() << " ID " << newFace->getId()); |
Alexander Afanasyev | bbe3f0c | 2014-03-23 11:44:01 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | void |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 569 | FaceManager::onCreated(const Name& requestName, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 570 | ControlParameters& parameters, |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 571 | const shared_ptr<Face>& newFace) |
| 572 | { |
Alexander Afanasyev | bbe3f0c | 2014-03-23 11:44:01 -0700 | [diff] [blame] | 573 | addCreatedFaceToForwarder(newFace); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 574 | parameters.setFaceId(newFace->getId()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 575 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 576 | sendResponse(requestName, 200, "Success", parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | void |
| 580 | FaceManager::onConnectFailed(const Name& requestName, const std::string& reason) |
| 581 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 582 | NFD_LOG_DEBUG("Failed to create face: " << reason); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 583 | sendResponse(requestName, 400, "Failed to create face"); |
| 584 | } |
| 585 | |
| 586 | void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 587 | FaceManager::createFace(const Interest& request, |
| 588 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 589 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 590 | const Name& requestName = request.getName(); |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 591 | ndn::nfd::FaceCreateCommand command; |
| 592 | |
| 593 | if (!validateParameters(command, parameters)) |
| 594 | { |
| 595 | sendResponse(requestName, 400, "Malformed command"); |
| 596 | return; |
| 597 | } |
| 598 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 599 | FaceUri uri; |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 600 | if (!uri.parse(parameters.getUri())) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 601 | { |
| 602 | sendResponse(requestName, 400, "Malformed command"); |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | FactoryMap::iterator factory = m_factories.find(uri.getScheme()); |
| 607 | if (factory == m_factories.end()) |
| 608 | { |
| 609 | sendResponse(requestName, 501, "Unsupported protocol"); |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | factory->second->createFace(uri, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 614 | bind(&FaceManager::onCreated, this, requestName, parameters, _1), |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 615 | bind(&FaceManager::onConnectFailed, this, requestName, _1)); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 620 | FaceManager::destroyFace(const Interest& request, |
| 621 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 622 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 623 | const Name& requestName = request.getName(); |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 624 | ndn::nfd::FaceDestroyCommand command; |
| 625 | |
| 626 | if (!validateParameters(command, parameters)) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 627 | { |
| 628 | sendResponse(requestName, 400, "Malformed command"); |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | shared_ptr<Face> target = m_faceTable.get(parameters.getFaceId()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 633 | if (static_cast<bool>(target)) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 634 | { |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 635 | target->close(); |
| 636 | } |
Steve DiBenedetto | ba74905 | 2014-03-22 19:54:53 -0600 | [diff] [blame] | 637 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 638 | sendResponse(requestName, 200, "Success", parameters.wireEncode()); |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 639 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 642 | void |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 643 | FaceManager::onAddFace(shared_ptr<Face> face) |
| 644 | { |
| 645 | ndn::nfd::FaceEventNotification faceCreated(ndn::nfd::FACE_EVENT_CREATED, |
| 646 | face->getId(), |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 647 | face->getUri().toString(), |
| 648 | (face->isLocal() ? ndn::nfd::FACE_IS_LOCAL : 0) | |
| 649 | (face->isOnDemand() ? ndn::nfd::FACE_IS_ON_DEMAND : 0)); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 650 | |
| 651 | m_notificationStream.postNotification(faceCreated); |
| 652 | } |
| 653 | |
| 654 | void |
| 655 | FaceManager::onRemoveFace(shared_ptr<Face> face) |
| 656 | { |
| 657 | ndn::nfd::FaceEventNotification faceDestroyed(ndn::nfd::FACE_EVENT_DESTROYED, |
| 658 | face->getId(), |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 659 | face->getUri().toString(), |
| 660 | (face->isLocal() ? ndn::nfd::FACE_IS_LOCAL : 0) | |
| 661 | (face->isOnDemand() ? ndn::nfd::FACE_IS_ON_DEMAND : 0)); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 662 | |
| 663 | m_notificationStream.postNotification(faceDestroyed); |
| 664 | } |
| 665 | |
| 666 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 667 | bool |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 668 | FaceManager::extractLocalControlParameters(const Interest& request, |
| 669 | ControlParameters& parameters, |
| 670 | ControlCommand& command, |
| 671 | shared_ptr<LocalFace>& outFace, |
| 672 | LocalControlFeature& outFeature) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 673 | { |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 674 | if (!validateParameters(command, parameters)) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 675 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 676 | sendResponse(request.getName(), 400, "Malformed command"); |
| 677 | return false; |
| 678 | } |
| 679 | |
| 680 | shared_ptr<Face> face = m_faceTable.get(request.getIncomingFaceId()); |
| 681 | |
| 682 | if (!static_cast<bool>(face)) |
| 683 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 684 | NFD_LOG_DEBUG("command result: faceid " << request.getIncomingFaceId() << " not found"); |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 685 | sendResponse(request.getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 686 | return false; |
| 687 | } |
| 688 | else if (!face->isLocal()) |
| 689 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 690 | NFD_LOG_DEBUG("command result: cannot enable local control on non-local faceid " << |
| 691 | face->getId()); |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 692 | sendResponse(request.getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 693 | return false; |
| 694 | } |
| 695 | |
| 696 | outFace = dynamic_pointer_cast<LocalFace>(face); |
| 697 | outFeature = static_cast<LocalControlFeature>(parameters.getLocalControlFeature()); |
| 698 | |
| 699 | return true; |
| 700 | } |
| 701 | |
| 702 | void |
| 703 | FaceManager::enableLocalControl(const Interest& request, |
| 704 | ControlParameters& parameters) |
| 705 | { |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 706 | ndn::nfd::FaceEnableLocalControlCommand command; |
| 707 | |
| 708 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 709 | shared_ptr<LocalFace> face; |
| 710 | LocalControlFeature feature; |
| 711 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 712 | if (extractLocalControlParameters(request, parameters, command, face, feature)) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 713 | { |
| 714 | face->setLocalControlHeaderFeature(feature, true); |
| 715 | sendResponse(request.getName(), 200, "Success", parameters.wireEncode()); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | void |
| 720 | FaceManager::disableLocalControl(const Interest& request, |
| 721 | ControlParameters& parameters) |
| 722 | { |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 723 | ndn::nfd::FaceDisableLocalControlCommand command; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 724 | shared_ptr<LocalFace> face; |
| 725 | LocalControlFeature feature; |
| 726 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 727 | if (extractLocalControlParameters(request, parameters, command, face, feature)) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 728 | { |
| 729 | face->setLocalControlHeaderFeature(feature, false); |
| 730 | sendResponse(request.getName(), 200, "Success", parameters.wireEncode()); |
| 731 | } |
| 732 | } |
| 733 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 734 | void |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 735 | FaceManager::listFaces(const Interest& request) |
| 736 | { |
| 737 | const Name& command = request.getName(); |
| 738 | const size_t commandNComps = command.size(); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 739 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 740 | if (commandNComps < LIST_COMMAND_NCOMPS || |
| 741 | !LIST_COMMAND_PREFIX.isPrefixOf(command)) |
| 742 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 743 | NFD_LOG_DEBUG("command result: malformed"); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 744 | sendResponse(command, 400, "Malformed command"); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | m_statusPublisher.publish(); |
| 749 | } |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 750 | |
| 751 | } // namespace nfd |