27 #include <boost/lexical_cast.hpp> 28 #include <ndn-cxx/encoding/tlv-nfd.hpp> 32 namespace autoconfig {
34 using nfd::ControlParameters;
35 using nfd::ControlResponse;
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 bind(&MulticastDiscovery::registerHubDiscoveryPrefix,
this, _1),
57 [
this] (uint32_t code,
const std::string& reason) {
58 this->
fail(
"Error " + to_string(code) +
" when querying multi-access faces: " + reason);
63 MulticastDiscovery::registerHubDiscoveryPrefix(
const std::vector<nfd::FaceStatus>& dataset)
65 if (dataset.empty()) {
66 this->
fail(
"No multi-access faces available");
70 m_nRegs = dataset.size();
74 for (
const auto& faceStatus : dataset) {
75 ControlParameters parameters;
77 .setFaceId(faceStatus.getFaceId())
79 .setExpirationPeriod(HUB_DISCOVERY_ROUTE_EXPIRATION);
81 m_controller.start<nfd::RibRegisterCommand>(
83 [
this] (
const ControlParameters&) {
87 [
this, faceStatus] (
const ControlResponse& 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 this->
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 bind(&MulticastDiscovery::requestHubData,
this),
121 [
this] (
const ControlResponse& resp) {
122 this->
fail(
"Error " + to_string(resp.getCode()) +
" when setting multicast strategy: " +
128 MulticastDiscovery::requestHubData()
131 interest.setInterestLifetime(HUB_DISCOVERY_INTEREST_LIFETIME);
132 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 this->
fail(
"Malformed hub Data: missing Uri element");
145 this->
provideHubFaceUri(std::string(reinterpret_cast<const char*>(i->value()), i->value_size()));
147 [
this] (
const Interest&,
const lp::Nack& nack) {
148 this->
fail(
"Nack-" + boost::lexical_cast<std::string>(nack.getReason()) +
" when retrieving hub Data");
150 [
this] (
const Interest&) {
151 this->
fail(
"Timeout when retrieving hub Data");
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...