28 #include <boost/lexical_cast.hpp> 30 #include <ndn-cxx/encoding/tlv-nfd.hpp> 34 namespace autoconfig {
36 using nfd::ControlParameters;
37 using nfd::ControlResponse;
46 , m_controller(controller)
51 MulticastDiscovery::doStart()
53 nfd::FaceQueryFilter filter;
54 filter.setLinkType(nfd::LINK_TYPE_MULTI_ACCESS);
56 m_controller.fetch<nfd::FaceQueryDataset>(
58 bind(&MulticastDiscovery::registerHubDiscoveryPrefix,
this, _1),
59 [
this] (uint32_t code,
const std::string& reason) {
60 this->
fail(
"Error " + to_string(code) +
" when querying multi-access faces: " + reason);
65 MulticastDiscovery::registerHubDiscoveryPrefix(
const std::vector<nfd::FaceStatus>& dataset)
67 if (dataset.empty()) {
68 this->
fail(
"No multi-access faces available");
72 m_nRegs = dataset.size();
76 for (
const auto& faceStatus : dataset) {
77 ControlParameters parameters;
79 .setFaceId(faceStatus.getFaceId())
81 .setExpirationPeriod(HUB_DISCOVERY_ROUTE_EXPIRATION);
83 m_controller.start<nfd::RibRegisterCommand>(
85 [
this] (
const ControlParameters&) {
89 [
this, faceStatus] (
const ControlResponse& resp) {
90 std::cerr <<
"Error " << resp.getCode() <<
" when registering hub discovery prefix " 91 <<
"for face " << faceStatus.getFaceId() <<
" (" << faceStatus.getRemoteUri()
92 <<
"): " << resp.getText() << std::endl;
100 MulticastDiscovery::afterReg()
102 if (m_nRegSuccess + m_nRegFailure < m_nRegs) {
105 if (m_nRegSuccess > 0) {
109 this->
fail(
"Cannot register hub discovery prefix for any face");
114 MulticastDiscovery::setStrategy()
116 ControlParameters parameters;
118 .setStrategy(
"/localhost/nfd/strategy/multicast"),
120 m_controller.start<nfd::StrategyChoiceSetCommand>(
122 bind(&MulticastDiscovery::requestHubData,
this),
123 [
this] (
const ControlResponse& resp) {
124 this->
fail(
"Error " + to_string(resp.getCode()) +
" when setting multicast strategy: " +
130 MulticastDiscovery::requestHubData()
133 interest.setCanBePrefix(
true);
134 interest.setMustBeFresh(
true);
135 interest.setInterestLifetime(HUB_DISCOVERY_INTEREST_LIFETIME);
137 m_face.expressInterest(interest,
138 [
this] (
const Interest&,
const Data& data) {
139 const Block& content = data.getContent();
142 auto i = content.find(tlv::nfd::Uri);
143 if (i == content.elements_end()) {
144 this->
fail(
"Malformed hub Data: missing Uri element");
148 this->
provideHubFaceUri(std::string(reinterpret_cast<const char*>(i->value()), i->value_size()));
150 [
this] (
const Interest&,
const lp::Nack& nack) {
151 this->
fail(
"Nack-" + boost::lexical_cast<std::string>(nack.getReason()) +
" when retrieving hub Data");
153 [
this] (
const Interest&) {
154 this->
fail(
"Timeout when retrieving hub Data");
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...