34 #include <ndn-cxx/lp/tags.hpp>
35 #include <ndn-cxx/mgmt/nfd/channel-status.hpp>
36 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
37 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
39 #ifdef HAVE_UNIX_SOCKETS
41 #endif // HAVE_UNIX_SOCKETS
46 #endif // HAVE_LIBPCAP
50 #endif // HAVE_WEBSOCKET
58 , m_faceTable(faceTable)
60 registerCommandHandler<ndn::nfd::FaceCreateCommand>(
"create",
61 bind(&FaceManager::createFace,
this, _2, _3, _4, _5));
63 registerCommandHandler<ndn::nfd::FaceUpdateCommand>(
"update",
64 bind(&FaceManager::updateFace,
this, _2, _3, _4, _5));
66 registerCommandHandler<ndn::nfd::FaceDestroyCommand>(
"destroy",
67 bind(&FaceManager::destroyFace,
this, _2, _3, _4, _5));
69 registerCommandHandler<ndn::nfd::FaceEnableLocalControlCommand>(
"enable-local-control",
70 bind(&FaceManager::enableLocalControl,
this, _2, _3, _4, _5));
72 registerCommandHandler<ndn::nfd::FaceDisableLocalControlCommand>(
"disable-local-control",
73 bind(&FaceManager::disableLocalControl,
this, _2, _3, _4, _5));
80 m_faceAddConn = m_faceTable.
afterAdd.connect(bind(&FaceManager::notifyAddFace,
this, _1));
81 m_faceRemoveConn = m_faceTable.
beforeRemove.connect(bind(&FaceManager::notifyRemoveFace,
this, _1));
87 configFile.
addSectionHandler(
"face_system", bind(&FaceManager::processConfig,
this, _1, _2, _3));
91 FaceManager::createFace(
const Name& topPrefix,
const Interest& interest,
92 const ControlParameters& parameters,
93 const ndn::mgmt::CommandContinuation& done)
96 if (!uri.parse(parameters.getUri())) {
98 done(ControlResponse(400,
"Malformed command"));
102 if (!uri.isCanonical()) {
104 done(ControlResponse(400,
"Non-canonical URI"));
108 auto factory = m_factories.find(uri.getScheme());
109 if (factory == m_factories.end()) {
110 NFD_LOG_TRACE(
"received create request for unsupported protocol");
111 done(ControlResponse(406,
"Unsupported protocol"));
116 factory->second->createFace(uri,
117 parameters.getFacePersistency(),
118 parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) ?
119 parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) :
false,
120 bind(&FaceManager::afterCreateFaceSuccess,
121 this, parameters, _1, done),
122 bind(&FaceManager::afterCreateFaceFailure,
123 this, _1, _2, done));
125 catch (
const std::runtime_error& error) {
127 done(ControlResponse(500,
"Face creation failed due to internal error"));
130 catch (
const std::logic_error& error) {
132 done(ControlResponse(500,
"Face creation failed due to internal error"));
144 FaceManager::afterCreateFaceSuccess(
const ControlParameters& parameters,
145 const shared_ptr<Face>& face,
146 const ndn::mgmt::CommandContinuation& done)
167 BOOST_ASSERT(face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL ||
168 !parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) ||
169 (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
170 !parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)));
172 m_faceTable.
add(face);
174 ControlParameters response;
175 response.setFaceId(face->getId());
176 response.setFacePersistency(face->getPersistency());
177 response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED,
178 parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) ?
179 parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) :
false,
182 done(ControlResponse(200,
"OK").setBody(response.wireEncode()));
187 FaceManager::afterCreateFaceFailure(uint32_t status,
188 const std::string& reason,
189 const ndn::mgmt::CommandContinuation& done)
193 done(ControlResponse(status, reason));
197 FaceManager::updateFace(
const Name& topPrefix,
const Interest& interest,
198 const ControlParameters& parameters,
199 const ndn::mgmt::CommandContinuation& done)
201 FaceId faceId = parameters.getFaceId();
204 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = interest.getTag<lp::IncomingFaceIdTag>();
205 if (incomingFaceIdTag ==
nullptr) {
207 done(ControlResponse(404,
"No FaceId specified and IncomingFaceId not available"));
210 faceId = *incomingFaceIdTag;
213 Face* face = m_faceTable.
get(faceId);
215 if (face ==
nullptr) {
217 done(ControlResponse(404,
"Specified face does not exist"));
222 ControlParameters response;
223 bool areParamsValid =
true;
225 if (parameters.hasFacePersistency()) {
227 NFD_LOG_TRACE(
"received unsupported face persistency change");
228 areParamsValid =
false;
229 response.setFacePersistency(parameters.getFacePersistency());
232 if (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
233 parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
234 face->getScope() != ndn::nfd::FACE_SCOPE_LOCAL) {
235 NFD_LOG_TRACE(
"received request to enable local fields on non-local face");
236 areParamsValid =
false;
237 response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED,
238 parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
241 if (!areParamsValid) {
242 done(ControlResponse(409,
"Invalid properties specified").setBody(response.wireEncode()));
250 setLinkServiceOptions(*face, parameters, response);
253 response.setFaceId(faceId);
254 response.setFacePersistency(face->getPersistency());
255 response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED,
256 parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) ?
257 parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) :
false,
260 done(ControlResponse(200,
"OK").setBody(response.wireEncode()));
264 FaceManager::destroyFace(
const Name& topPrefix,
const Interest& interest,
265 const ControlParameters& parameters,
266 const ndn::mgmt::CommandContinuation& done)
268 Face* face = m_faceTable.
get(parameters.getFaceId());
269 if (face !=
nullptr) {
273 done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
277 FaceManager::enableLocalControl(
const Name& topPrefix,
const Interest& interest,
278 const ControlParameters& parameters,
279 const ndn::mgmt::CommandContinuation& done)
281 Face* face = findFaceForLocalControl(interest, parameters, done);
287 auto service =
dynamic_cast<face::GenericLinkService*
>(face->getLinkService());
288 if (service ==
nullptr) {
289 return done(ControlResponse(503,
"LinkService type not supported"));
292 face::GenericLinkService::Options options = service->getOptions();
293 options.allowLocalFields =
true;
294 service->setOptions(options);
296 return done(ControlResponse(200,
"OK: enable all local fields on GenericLinkService")
297 .setBody(parameters.wireEncode()));
301 FaceManager::disableLocalControl(
const Name& topPrefix,
const Interest& interest,
302 const ControlParameters& parameters,
303 const ndn::mgmt::CommandContinuation& done)
305 Face* face = findFaceForLocalControl(interest, parameters, done);
311 auto service =
dynamic_cast<face::GenericLinkService*
>(face->getLinkService());
312 if (service ==
nullptr) {
313 return done(ControlResponse(503,
"LinkService type not supported"));
316 face::GenericLinkService::Options options = service->getOptions();
317 options.allowLocalFields =
false;
318 service->setOptions(options);
320 return done(ControlResponse(200,
"OK: disable all local fields on GenericLinkService")
321 .setBody(parameters.wireEncode()));
325 FaceManager::findFaceForLocalControl(
const Interest& request,
326 const ControlParameters& parameters,
327 const ndn::mgmt::CommandContinuation& done)
329 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
333 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
335 Face* face = m_faceTable.
get(*incomingFaceIdTag);
336 if (face ==
nullptr) {
337 NFD_LOG_DEBUG(
"FaceId " << *incomingFaceIdTag <<
" not found");
338 done(ControlResponse(410,
"Face not found"));
342 if (face->getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
343 NFD_LOG_DEBUG(
"Cannot enable local control on non-local FaceId " << face->getId());
344 done(ControlResponse(412,
"Face is non-local"));
352 FaceManager::setLinkServiceOptions(Face& face,
353 const ControlParameters& parameters,
354 ControlParameters& response)
356 auto linkService =
dynamic_cast<face::GenericLinkService*
>(face.getLinkService());
357 BOOST_ASSERT(linkService !=
nullptr);
359 auto options = linkService->getOptions();
360 if (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
361 face.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
362 options.allowLocalFields = parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
364 linkService->setOptions(options);
367 response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields,
false);
371 FaceManager::listFaces(
const Name& topPrefix,
const Interest& interest,
372 ndn::mgmt::StatusDatasetContext& context)
374 auto now = time::steady_clock::now();
375 for (
const Face& face : m_faceTable) {
376 ndn::nfd::FaceStatus status = collectFaceStatus(face, now);
377 context.append(status.wireEncode());
383 FaceManager::listChannels(
const Name& topPrefix,
const Interest& interest,
384 ndn::mgmt::StatusDatasetContext& context)
386 std::set<const ProtocolFactory*> seenFactories;
388 for (
const auto& kv : m_factories) {
389 const ProtocolFactory* factory = kv.second.get();
391 std::tie(std::ignore, inserted) = seenFactories.insert(factory);
394 for (
const auto& channel : factory->getChannels()) {
395 ndn::nfd::ChannelStatus entry;
396 entry.setLocalUri(channel->getUri().toString());
397 context.append(entry.wireEncode());
406 FaceManager::queryFaces(
const Name& topPrefix,
const Interest& interest,
407 ndn::mgmt::StatusDatasetContext& context)
409 ndn::nfd::FaceQueryFilter faceFilter;
410 const Name& query = interest.getName();
412 faceFilter.wireDecode(query[-1].blockFromValue());
414 catch (
const tlv::Error& e) {
416 return context.reject(ControlResponse(400,
"Malformed filter"));
419 auto now = time::steady_clock::now();
420 for (
const Face& face : m_faceTable) {
421 if (!matchFilter(faceFilter, face)) {
424 ndn::nfd::FaceStatus status = collectFaceStatus(face, now);
425 context.append(status.wireEncode());
432 FaceManager::matchFilter(
const ndn::nfd::FaceQueryFilter& filter,
const Face& face)
434 if (filter.hasFaceId() &&
435 filter.getFaceId() !=
static_cast<uint64_t
>(face.getId())) {
439 if (filter.hasUriScheme() &&
440 filter.getUriScheme() != face.getRemoteUri().getScheme() &&
441 filter.getUriScheme() != face.getLocalUri().getScheme()) {
445 if (filter.hasRemoteUri() &&
446 filter.getRemoteUri() != face.getRemoteUri().toString()) {
450 if (filter.hasLocalUri() &&
451 filter.getLocalUri() != face.getLocalUri().toString()) {
455 if (filter.hasFaceScope() &&
456 filter.getFaceScope() != face.getScope()) {
460 if (filter.hasFacePersistency() &&
461 filter.getFacePersistency() != face.getPersistency()) {
465 if (filter.hasLinkType() &&
466 filter.getLinkType() != face.getLinkType()) {
474 FaceManager::collectFaceStatus(
const Face& face,
const time::steady_clock::TimePoint& now)
476 ndn::nfd::FaceStatus status;
478 collectFaceProperties(face, status);
480 time::steady_clock::TimePoint expirationTime = face.getExpirationTime();
481 if (expirationTime != time::steady_clock::TimePoint::max()) {
482 status.setExpirationPeriod(std::max(time::milliseconds(0),
483 time::duration_cast<time::milliseconds>(expirationTime - now)));
486 const face::FaceCounters& counters = face.getCounters();
487 status.setNInInterests(counters.nInInterests)
488 .setNOutInterests(counters.nOutInterests)
489 .setNInDatas(counters.nInData)
490 .setNOutDatas(counters.nOutData)
491 .setNInNacks(counters.nInNacks)
492 .setNOutNacks(counters.nOutNacks)
493 .setNInBytes(counters.nInBytes)
494 .setNOutBytes(counters.nOutBytes);
497 auto linkService =
dynamic_cast<face::GenericLinkService*
>(face.getLinkService());
498 if (linkService !=
nullptr) {
499 auto linkServiceOptions = linkService->getOptions();
500 status.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, linkServiceOptions.allowLocalFields);
506 template<
typename FaceTraits>
508 FaceManager::collectFaceProperties(
const Face& face, FaceTraits& traits)
510 traits.setFaceId(face.getId())
511 .setRemoteUri(face.getRemoteUri().toString())
512 .setLocalUri(face.getLocalUri().toString())
513 .setFaceScope(face.getScope())
514 .setFacePersistency(face.getPersistency())
515 .setLinkType(face.getLinkType());
519 FaceManager::notifyAddFace(
const Face& face)
521 ndn::nfd::FaceEventNotification notification;
522 notification.setKind(ndn::nfd::FACE_EVENT_CREATED);
523 collectFaceProperties(face, notification);
525 m_postNotification(notification.wireEncode());
529 FaceManager::notifyRemoveFace(
const Face& face)
531 ndn::nfd::FaceEventNotification notification;
532 notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED);
533 collectFaceProperties(face, notification);
535 m_postNotification(notification.wireEncode());
539 FaceManager::processConfig(
const ConfigSection& configSection,
541 const std::string& filename)
543 bool hasSeenUnix =
false;
544 bool hasSeenTcp =
false;
545 bool hasSeenUdp =
false;
546 bool hasSeenEther =
false;
547 bool hasSeenWebSocket =
false;
550 for (
const auto& item : configSection) {
551 if (item.first ==
"unix") {
553 BOOST_THROW_EXCEPTION(Error(
"Duplicate \"unix\" section"));
557 processSectionUnix(item.second, isDryRun);
559 else if (item.first ==
"tcp") {
561 BOOST_THROW_EXCEPTION(Error(
"Duplicate \"tcp\" section"));
565 processSectionTcp(item.second, isDryRun);
567 else if (item.first ==
"udp") {
569 BOOST_THROW_EXCEPTION(Error(
"Duplicate \"udp\" section"));
573 processSectionUdp(item.second, isDryRun, nicList);
575 else if (item.first ==
"ether") {
577 BOOST_THROW_EXCEPTION(Error(
"Duplicate \"ether\" section"));
581 processSectionEther(item.second, isDryRun, nicList);
583 else if (item.first ==
"websocket") {
584 if (hasSeenWebSocket) {
585 BOOST_THROW_EXCEPTION(Error(
"Duplicate \"websocket\" section"));
587 hasSeenWebSocket =
true;
589 processSectionWebSocket(item.second, isDryRun);
592 BOOST_THROW_EXCEPTION(Error(
"Unrecognized option \"" + item.first +
"\""));
598 FaceManager::processSectionUnix(
const ConfigSection& configSection,
bool isDryRun)
606 #if defined(HAVE_UNIX_SOCKETS)
607 std::string path =
"/var/run/nfd.sock";
609 for (
const auto& i : configSection) {
610 if (i.first ==
"path") {
611 path = i.second.get_value<std::string>();
614 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unrecognized option \"" +
615 i.first +
"\" in \"unix\" section"));
620 if (m_factories.count(
"unix") > 0) {
624 auto factory = make_shared<UnixStreamFactory>();
625 m_factories.insert(std::make_pair(
"unix", factory));
627 auto channel = factory->createChannel(path);
628 channel->listen(bind(&
FaceTable::add, &m_faceTable, _1),
nullptr);
631 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"NFD was compiled without Unix sockets support, "
632 "cannot process \"unix\" section"));
633 #endif // HAVE_UNIX_SOCKETS
637 FaceManager::processSectionTcp(
const ConfigSection& configSection,
bool isDryRun)
646 uint16_t port = 6363;
647 bool needToListen =
true;
648 bool enableV4 =
true;
649 bool enableV6 =
true;
651 for (
const auto& i : configSection) {
652 if (i.first ==
"port") {
653 port = ConfigFile::parseNumber<uint16_t>(i,
"tcp");
656 else if (i.first ==
"listen") {
659 else if (i.first ==
"enable_v4") {
662 else if (i.first ==
"enable_v6") {
666 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unrecognized option \"" +
667 i.first +
"\" in \"tcp\" section"));
671 if (!enableV4 && !enableV6) {
672 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"IPv4 and IPv6 TCP channels have been disabled."
673 " Remove \"tcp\" section to disable TCP channels or"
674 " re-enable at least one channel type."));
678 if (m_factories.count(
"tcp") > 0) {
682 auto factory = make_shared<TcpFactory>();
683 m_factories.insert(std::make_pair(
"tcp", factory));
687 shared_ptr<TcpChannel> v4Channel = factory->createChannel(endpoint);
689 v4Channel->listen(bind(&
FaceTable::add, &m_faceTable, _1),
nullptr);
692 m_factories.insert(std::make_pair(
"tcp4", factory));
697 shared_ptr<TcpChannel> v6Channel = factory->createChannel(endpoint);
699 v6Channel->listen(bind(&
FaceTable::add, &m_faceTable, _1),
nullptr);
702 m_factories.insert(std::make_pair(
"tcp6", factory));
708 FaceManager::processSectionUdp(
const ConfigSection& configSection,
bool isDryRun,
709 const std::vector<NetworkInterfaceInfo>& nicList)
724 uint16_t port = 6363;
725 bool enableV4 =
true;
726 bool enableV6 =
true;
727 size_t timeout = 600;
728 size_t keepAliveInterval = 25;
729 bool useMcast =
true;
730 auto mcastGroup = boost::asio::ip::address_v4::from_string(
"224.0.23.170");
731 uint16_t mcastPort = 56363;
733 for (
const auto& i : configSection) {
734 if (i.first ==
"port") {
735 port = ConfigFile::parseNumber<uint16_t>(i,
"udp");
738 else if (i.first ==
"enable_v4") {
741 else if (i.first ==
"enable_v6") {
744 else if (i.first ==
"idle_timeout") {
746 timeout = i.second.get_value<
size_t>();
748 catch (
const boost::property_tree::ptree_bad_data&) {
749 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Invalid value for option \"" +
750 i.first +
"\" in \"udp\" section"));
753 else if (i.first ==
"keep_alive_interval") {
755 keepAliveInterval = i.second.get_value<
size_t>();
757 (void)(keepAliveInterval);
759 catch (
const boost::property_tree::ptree_bad_data&) {
760 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Invalid value for option \"" +
761 i.first +
"\" in \"udp\" section"));
764 else if (i.first ==
"mcast") {
767 else if (i.first ==
"mcast_port") {
768 mcastPort = ConfigFile::parseNumber<uint16_t>(i,
"udp");
771 else if (i.first ==
"mcast_group") {
772 boost::system::error_code ec;
773 mcastGroup = boost::asio::ip::address_v4::from_string(i.second.get_value<std::string>(), ec);
775 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Invalid value for option \"" +
776 i.first +
"\" in \"udp\" section"));
781 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unrecognized option \"" +
782 i.first +
"\" in \"udp\" section"));
786 if (!enableV4 && !enableV6) {
787 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"IPv4 and IPv6 UDP channels have been disabled."
788 " Remove \"udp\" section to disable UDP channels or"
789 " re-enable at least one channel type."));
791 else if (useMcast && !enableV4) {
792 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"IPv4 multicast requested, but IPv4 channels"
793 " have been disabled (conflicting configuration options set)"));
797 shared_ptr<UdpFactory> factory;
798 bool isReload =
false;
799 if (m_factories.count(
"udp") > 0) {
801 factory = static_pointer_cast<UdpFactory>(m_factories[
"udp"]);
804 factory = make_shared<UdpFactory>();
805 m_factories.insert(std::make_pair(
"udp", factory));
808 if (!isReload && enableV4) {
810 shared_ptr<UdpChannel> v4Channel = factory->createChannel(endpoint, time::seconds(timeout));
811 v4Channel->listen(bind(&
FaceTable::add, &m_faceTable, _1),
nullptr);
813 m_factories.insert(std::make_pair(
"udp4", factory));
816 if (!isReload && enableV6) {
818 shared_ptr<UdpChannel> v6Channel = factory->createChannel(endpoint, time::seconds(timeout));
819 v6Channel->listen(bind(&
FaceTable::add, &m_faceTable, _1),
nullptr);
821 m_factories.insert(std::make_pair(
"udp6", factory));
824 std::set<shared_ptr<Face>> multicastFacesToRemove;
825 for (
const auto& i : factory->getMulticastFaces()) {
826 multicastFacesToRemove.insert(i.second);
829 if (useMcast && enableV4) {
830 std::vector<NetworkInterfaceInfo> ipv4MulticastInterfaces;
831 for (
const auto& nic : nicList) {
832 if (nic.isUp() && nic.isMulticastCapable() && !nic.ipv4Addresses.empty()) {
833 ipv4MulticastInterfaces.push_back(nic);
837 bool isNicNameNecessary =
false;
838 #if defined(__linux__)
839 if (ipv4MulticastInterfaces.size() > 1) {
842 isNicNameNecessary =
true;
847 for (
const auto& nic : ipv4MulticastInterfaces) {
848 udp::Endpoint localEndpoint(nic.ipv4Addresses[0], mcastPort);
849 auto newFace = factory->createMulticastFace(localEndpoint, mcastEndpoint,
850 isNicNameNecessary ? nic.name :
"");
851 m_faceTable.add(newFace);
852 multicastFacesToRemove.erase(newFace);
856 for (
const auto& face : multicastFacesToRemove) {
863 FaceManager::processSectionEther(
const ConfigSection& configSection,
bool isDryRun,
864 const std::vector<NetworkInterfaceInfo>& nicList)
874 #if defined(HAVE_LIBPCAP)
875 bool useMcast =
true;
876 ethernet::Address mcastGroup(ethernet::getDefaultMulticastAddress());
878 for (
const auto& i : configSection) {
879 if (i.first ==
"mcast") {
882 else if (i.first ==
"mcast_group") {
883 mcastGroup = ethernet::Address::fromString(i.second.get_value<std::string>());
884 if (mcastGroup.isNull()) {
885 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Invalid value for option \"" +
886 i.first +
"\" in \"ether\" section"));
888 NFD_LOG_TRACE(
"Ethernet multicast group set to " << mcastGroup);
891 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unrecognized option \"" +
892 i.first +
"\" in \"ether\" section"));
897 shared_ptr<EthernetFactory> factory;
898 if (m_factories.count(
"ether") > 0) {
899 factory = static_pointer_cast<EthernetFactory>(m_factories[
"ether"]);
902 factory = make_shared<EthernetFactory>();
903 m_factories.insert(std::make_pair(
"ether", factory));
906 std::set<shared_ptr<Face>> multicastFacesToRemove;
907 for (
const auto& i : factory->getMulticastFaces()) {
908 multicastFacesToRemove.insert(i.second);
912 for (
const auto& nic : nicList) {
913 if (nic.isUp() && nic.isMulticastCapable()) {
915 auto newFace = factory->createMulticastFace(nic, mcastGroup);
916 m_faceTable.add(newFace);
917 multicastFacesToRemove.erase(newFace);
919 catch (
const EthernetFactory::Error& factoryError) {
922 catch (
const face::EthernetTransport::Error& faceError) {
929 for (
const auto& face : multicastFacesToRemove) {
934 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"NFD was compiled without libpcap, cannot process \"ether\" section"));
935 #endif // HAVE_LIBPCAP
939 FaceManager::processSectionWebSocket(
const ConfigSection& configSection,
bool isDryRun)
950 #if defined(HAVE_WEBSOCKET)
951 uint16_t port = 9696;
952 bool needToListen =
true;
953 bool enableV4 =
true;
954 bool enableV6 =
true;
956 for (
const auto& i : configSection) {
957 if (i.first ==
"port") {
958 port = ConfigFile::parseNumber<uint16_t>(i,
"websocket");
961 else if (i.first ==
"listen") {
964 else if (i.first ==
"enable_v4") {
967 else if (i.first ==
"enable_v6") {
971 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unrecognized option \"" +
972 i.first +
"\" in \"websocket\" section"));
976 if (!enableV4 && !enableV6) {
977 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"IPv4 and IPv6 WebSocket channels have been disabled."
978 " Remove \"websocket\" section to disable WebSocket channels or"
979 " re-enable at least one channel type."));
982 if (!enableV4 && enableV6) {
983 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"NFD does not allow pure IPv6 WebSocket channel."));
987 if (m_factories.count(
"websocket") > 0) {
991 auto factory = make_shared<WebSocketFactory>();
992 m_factories.insert(std::make_pair(
"websocket", factory));
994 shared_ptr<WebSocketChannel> channel;
996 if (enableV6 && enableV4) {
998 channel = factory->createChannel(endpoint);
1000 m_factories.insert(std::make_pair(
"websocket46", factory));
1002 else if (enableV4) {
1004 channel = factory->createChannel(endpoint);
1006 m_factories.insert(std::make_pair(
"websocket4", factory));
1009 if (channel && needToListen) {
1014 BOOST_THROW_EXCEPTION(ConfigFile::Error(
"NFD was compiled without WebSocket, "
1015 "cannot process \"websocket\" section"));
1016 #endif // HAVE_WEBSOCKET
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
#define NFD_LOG_DEBUG(expression)
configuration file parsing utility
Face * get(FaceId id) const
get face by FaceId
#define NFD_LOG_ERROR(expression)
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
std::vector< NetworkInterfaceInfo > listNetworkInterfaces()
List configured network interfaces on the system and their info.
provides ControlCommand authorization according to NFD configuration file
void add(shared_ptr< Face > face)
add a face
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
boost::asio::ip::tcp::endpoint Endpoint
signal::Signal< FaceTable, Face & > beforeRemove
fires before a face is removed
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
signal::Signal< FaceTable, Face & > afterAdd
fires after a face is added
boost::property_tree::ptree ConfigSection
void setConfigFile(ConfigFile &configFile)
Subscribe to face_system section for the config file.
boost::asio::ip::udp::endpoint Endpoint
#define NFD_LOG_INIT(name)
#define NFD_LOG_TRACE(expression)
boost::asio::ip::tcp::endpoint Endpoint
uint64_t FaceId
identifies a face
FaceManager(FaceTable &faceTable, Dispatcher &dispatcher, CommandAuthenticator &authenticator)