28 #include <boost/lexical_cast.hpp>
30 #include <ndn-cxx/encoding/tlv-nfd.hpp>
31 #include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
35 using nfd::ControlParameters;
44 , m_controller(controller)
49 MulticastDiscovery::doStart()
51 nfd::FaceQueryFilter filter;
52 filter.setLinkType(nfd::LINK_TYPE_MULTI_ACCESS);
54 m_controller.fetch<nfd::FaceQueryDataset>(
56 [
this] (
const auto& dataset) { registerHubDiscoveryPrefix(dataset); },
57 [
this] (uint32_t code,
const std::string& reason) {
58 fail(
"Error " + std::to_string(code) +
" when querying multi-access faces: " + reason);
63 MulticastDiscovery::registerHubDiscoveryPrefix(
const std::vector<nfd::FaceStatus>& dataset)
65 if (dataset.empty()) {
66 fail(
"No multi-access faces available");
70 m_nRegs = dataset.size();
74 for (
const auto& faceStatus : dataset) {
75 ControlParameters parameters;
77 .setFaceId(faceStatus.getFaceId())
81 m_controller.start<nfd::RibRegisterCommand>(
83 [
this] (
const auto&) {
87 [
this, faceStatus] (
const auto& resp) {
88 std::cerr <<
"Error " << resp.getCode() <<
" when registering hub discovery prefix "
89 <<
"for face " << faceStatus.getFaceId() <<
" (" << faceStatus.getRemoteUri()
90 <<
"): " << resp.getText() << std::endl;
98 MulticastDiscovery::afterReg()
100 if (m_nRegSuccess + m_nRegFailure < m_nRegs) {
103 if (m_nRegSuccess > 0) {
107 fail(
"Cannot register hub discovery prefix for any face");
112 MulticastDiscovery::setStrategy()
114 ControlParameters parameters;
116 .setStrategy(
"/localhost/nfd/strategy/multicast");
118 m_controller.start<nfd::StrategyChoiceSetCommand>(
120 [
this] (
const auto&) { requestHubData(); },
121 [
this] (
const auto& resp) {
122 fail(
"Error " + std::to_string(resp.getCode()) +
" when setting multicast strategy: " + resp.getText());
127 MulticastDiscovery::requestHubData()
130 interest.setCanBePrefix(
true);
131 interest.setMustBeFresh(
true);
134 m_face.expressInterest(interest,
135 [
this] (
const Interest&,
const Data& data) {
136 const Block& content = data.getContent();
139 auto i = content.find(tlv::nfd::Uri);
140 if (i == content.elements_end()) {
141 fail(
"Malformed hub Data: missing Uri element");
145 provideHubFaceUri(std::string(
reinterpret_cast<const char*
>(i->value()), i->value_size()));
147 [
this] (
const Interest&,
const lp::Nack& nack) {
148 fail(
"Nack-" + boost::lexical_cast<std::string>(nack.getReason()) +
" when retrieving hub Data");
150 [
this] (
const Interest&) {
151 fail(
"Timeout when retrieving hub Data");
MulticastDiscovery(Face &face, nfd::Controller &controller)
void provideHubFaceUri(const std::string &s)
Parse HUB FaceUri from string and declare success.
void fail(const std::string &msg)
constexpr uint64_t HUB_DISCOVERY_ROUTE_COST
const Name HUB_DISCOVERY_PREFIX
constexpr time::milliseconds HUB_DISCOVERY_INTEREST_LIFETIME
constexpr time::milliseconds HUB_DISCOVERY_ROUTE_EXPIRATION