29 #include <ndn-cxx/security/pib/identity.hpp>    30 #include <ndn-cxx/security/pib/identity-container.hpp>    31 #include <ndn-cxx/security/pib/pib.hpp>    32 #include <ndn-cxx/security/signing-helpers.hpp>    56   : m_nfdController(controller)
    57   , m_keyChain(keyChain)
    59   , m_refreshInterval(PREFIX_PROPAGATION_DEFAULT_REFRESH_INTERVAL)
    60   , m_baseRetryWait(PREFIX_PROPAGATION_DEFAULT_BASE_RETRY_WAIT)
    61   , m_maxRetryWait(PREFIX_PROPAGATION_DEFAULT_MAX_RETRY_WAIT)
    62   , m_hasConnectedHub(false)
    74      .
setCost(PREFIX_PROPAGATION_DEFAULT_COST)
    80      .
setTimeout(PREFIX_PROPAGATION_DEFAULT_TIMEOUT);
    82   NFD_LOG_INFO(
"Load auto_prefix_propagate section in rib section");
    84   for (
auto&& i : configSection) {
    85     if (i.first == 
"cost") {
    86       m_controlParameters.
setCost(i.second.get_value<uint64_t>());
    88     else if (i.first == 
"timeout") {
    91     else if (i.first == 
"refresh_interval") {
    92       m_refreshInterval = std::min(PREFIX_PROPAGATION_MAX_REFRESH_INTERVAL,
    93                                    time::seconds(i.second.get_value<
size_t>()));
    95     else if (i.first == 
"base_retry_wait") {
    96       m_baseRetryWait = time::seconds(i.second.get_value<
size_t>());
    98     else if (i.first == 
"max_retry_wait") {
    99       m_maxRetryWait = time::seconds(i.second.get_value<
size_t>());
   103                                               "\" in \"auto_prefix_propagate\" section"));
   111   m_afterInsertConnection =
   112     m_rib.
afterInsertEntry.connect(bind(&AutoPrefixPropagator::afterInsertRibEntry, 
this, _1));
   113   m_afterEraseConnection =
   114     m_rib.
afterEraseEntry.connect(bind(&AutoPrefixPropagator::afterEraseRibEntry, 
this, _1));
   124 AutoPrefixPropagator::PrefixPropagationParameters
   125 AutoPrefixPropagator::getPrefixPropagationParameters(
const Name& localRibPrefix)
   128   Name propagatedPrefix;
   130   bool isFound = 
false;
   131   for (
auto&& identity : m_keyChain.getPib().getIdentities()) {
   132     Name idName = identity.getName();
   135     if (prefix.
isPrefixOf(localRibPrefix) && (!isFound || prefix.
size() < propagatedPrefix.
size())) {
   137       propagatedPrefix = prefix;
   138       signingIdentity = identity;
   142   PrefixPropagationParameters propagateParameters;
   144     propagateParameters.isValid = 
false;
   147     propagateParameters.isValid = 
true;
   148     propagateParameters.parameters = m_controlParameters;
   149     propagateParameters.options = m_commandOptions;
   150     propagateParameters.parameters.setName(propagatedPrefix);
   154   return propagateParameters;
   158 AutoPrefixPropagator::afterInsertRibEntry(
const Name& prefix)
   166     NFD_LOG_INFO(
"this is a prefix registered by some hub: " << prefix);
   168     m_hasConnectedHub = 
true;
   169     return afterHubConnect();
   172   auto propagateParameters = getPrefixPropagationParameters(prefix);
   173   if (!propagateParameters.isValid) {
   174     NFD_LOG_INFO(
"no signing identity available for: " << prefix);
   178   auto entryIt = m_propagatedEntries.find(propagateParameters.parameters.getName());
   179   if (entryIt != m_propagatedEntries.end()) {
   182     if (entryIt->second.isNew()) {
   184                    << propagateParameters.parameters.getName());
   188                    << propagateParameters.parameters.getName());
   193   afterRibInsert(propagateParameters.parameters, propagateParameters.options);
   197 AutoPrefixPropagator::afterEraseRibEntry(
const Name& prefix)
   200     NFD_LOG_INFO(
"local unregistration only for " << prefix);
   205     NFD_LOG_INFO(
"disconnected to hub with prefix: " << prefix);
   207     m_hasConnectedHub = 
false;
   208     return afterHubDisconnect();
   211   auto propagateParameters = getPrefixPropagationParameters(prefix);
   212   if (!propagateParameters.isValid) {
   213     NFD_LOG_INFO(
"no signing identity available for: " << prefix);
   217   auto entryIt = m_propagatedEntries.find(propagateParameters.parameters.getName());
   218   if (entryIt == m_propagatedEntries.end()) {
   220                  << propagateParameters.parameters.getName());
   224   for (
auto&& ribTableEntry : m_rib) {
   225     if (propagateParameters.parameters.getName().isPrefixOf(ribTableEntry.first) &&
   226         propagateParameters.options.getSigningInfo().getSignerName() ==
   227         getPrefixPropagationParameters(ribTableEntry.first)
   228           .options.getSigningInfo().getSignerName()) {
   229       NFD_LOG_INFO(
"should be kept for another RIB entry: " << ribTableEntry.first);
   234   afterRibErase(propagateParameters.parameters.unsetCost(), propagateParameters.options);
   238 AutoPrefixPropagator::doesCurrentPropagatedPrefixWork(
const Name& prefix)
   240   auto propagateParameters = getPrefixPropagationParameters(prefix);
   241   if (!propagateParameters.isValid) {
   249   return propagateParameters.parameters.getName().size() == prefix.
size();
   253 AutoPrefixPropagator::redoPropagation(PropagatedEntryIt entryIt,
   256                                       time::seconds retryWaitTime)
   258   if (doesCurrentPropagatedPrefixWork(parameters.
getName())) {
   260     entryIt->second.startPropagation();
   261     return advertise(parameters, options, retryWaitTime);
   264   NFD_LOG_INFO(
"current propagated prefix does not work any more");
   265   m_propagatedEntries.erase(entryIt);
   268   for (
auto&& ribTableEntry : m_rib) {
   270       afterInsertRibEntry(ribTableEntry.first);
   278                                 time::seconds retryWaitTime)
   283     bind(&AutoPrefixPropagator::onRefreshTimer, 
this, parameters, options);
   285     bind(&AutoPrefixPropagator::onRetryTimer, 
this, parameters, options,
   286          std::min(m_maxRetryWait, retryWaitTime * 2));
   290      bind(&AutoPrefixPropagator::afterPropagateSucceed, 
this, parameters, options, refreshEvent),
   291      bind(&AutoPrefixPropagator::afterPropagateFail,
   292           this, _1, parameters, options, retryWaitTime, retryEvent),
   299                                time::seconds retryWaitTime)
   305      bind(&AutoPrefixPropagator::afterRevokeSucceed, 
this, parameters, options, retryWaitTime),
   306      bind(&AutoPrefixPropagator::afterRevokeFail, 
this, _1, parameters, options),
   314   BOOST_ASSERT(m_propagatedEntries.find(parameters.
getName()) == m_propagatedEntries.end());
   317   auto& entry = m_propagatedEntries[parameters.
getName()]
   320   if (!m_hasConnectedHub) {
   326   entry.startPropagation();
   327   advertise(parameters, options, m_baseRetryWait);
   334   auto entryIt = m_propagatedEntries.find(parameters.
getName());
   335   BOOST_ASSERT(entryIt != m_propagatedEntries.end());
   337   bool hasPropagationSucceeded = entryIt->second.isPropagated();
   340   m_propagatedEntries.erase(entryIt);
   342   if (!m_hasConnectedHub) {
   347   if (!hasPropagationSucceeded) {
   352   withdraw(parameters, options, m_baseRetryWait);
   356 AutoPrefixPropagator::afterHubConnect()
   359                        << 
" propagations when new Hub connectivity is built.");
   361   std::vector<PropagatedEntryIt> regEntryIterators;
   362   for (
auto it = m_propagatedEntries.begin() ; it != m_propagatedEntries.end() ; it ++) {
   363     BOOST_ASSERT(it->second.isNew());
   364     regEntryIterators.push_back(it);
   367   for (
auto&& it : regEntryIterators) {
   368     auto parameters = m_controlParameters;
   369     auto options = m_commandOptions;
   379 AutoPrefixPropagator::afterHubDisconnect()
   381   for (
auto&& entry : m_propagatedEntries) {
   383     BOOST_ASSERT(!entry.second.isNew());
   384     entry.second.initialize();
   395   auto entryIt = m_propagatedEntries.find(parameters.
getName());
   396   if (entryIt == m_propagatedEntries.end()) {
   400     return withdraw(newParameters.
unsetCost(), options, m_baseRetryWait);
   404   BOOST_ASSERT(entryIt->second.isPropagating());
   412                                          time::seconds retryWaitTime,
   416                                      << 
"\n\t reason:" << response.
getText()
   417                                      << 
"\n\t retry wait time: " << retryWaitTime);
   419   auto entryIt = m_propagatedEntries.find(parameters.
getName());
   420   if (entryIt == m_propagatedEntries.end()) {
   426   BOOST_ASSERT(entryIt->second.isPropagating());
   433                                          time::seconds retryWaitTime)
   437   auto entryIt = m_propagatedEntries.find(parameters.
getName());
   438   if (m_propagatedEntries.end() != entryIt && !entryIt->second.isPropagateFail()) {
   443     BOOST_ASSERT(!entryIt->second.isNew());
   444     entryIt->second.startPropagation();
   447     advertise(newParameters.
setCost(m_controlParameters.
getCost()), options, retryWaitTime);
   457                                                      << 
"\n\t reason:" << response.
getText());
   464   auto entryIt = m_propagatedEntries.find(parameters.
getName());
   465   BOOST_ASSERT(entryIt != m_propagatedEntries.end() && entryIt->second.isPropagated());
   466   redoPropagation(entryIt, parameters, options, m_baseRetryWait);
   472                                    time::seconds retryWaitTime)
   474   auto entryIt = m_propagatedEntries.find(parameters.
getName());
   475   BOOST_ASSERT(entryIt != m_propagatedEntries.end() && entryIt->second.isPropagateFail());
   476   redoPropagation(entryIt, parameters, options, retryWaitTime);
 const Name LINK_LOCAL_NFD_PREFIX("/localhop/nfd")
 
function< void()> EventCallback
 
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution 
 
ControlParameters & setFaceId(uint64_t faceId)
 
represents the Routing Information Base 
 
const Name LOCAL_REGISTRATION_PREFIX("/localhost")
 
const time::seconds PREFIX_PROPAGATION_MAX_REFRESH_INTERVAL
 
represents parameters in a ControlCommand request or response 
 
const Name & getSignerName() const 
 
boost::posix_time::time_duration milliseconds(long duration)
 
#define NFD_LOG_DEBUG(expression)
 
ControlParameters & unsetCost()
 
const name::Component IGNORE_COMMPONENT("nrd")
 
void disable()
disable automatic prefix propagation 
 
#define NFD_LOG_INFO(expression)
 
const std::string & getText() const 
 
const time::milliseconds PREFIX_PROPAGATION_DEFAULT_TIMEOUT
 
CommandOptions & setTimeout(const time::milliseconds &timeout)
sets command timeout 
 
const time::seconds PREFIX_PROPAGATION_DEFAULT_BASE_RETRY_WAIT
 
#define NFD_LOG_TRACE(expression)
 
contains options for ControlCommand execution 
 
Copyright (c) 2011-2015 Regents of the University of California. 
 
const uint64_t PREFIX_PROPAGATION_DEFAULT_COST
 
const time::seconds PREFIX_PROPAGATION_DEFAULT_REFRESH_INTERVAL
 
void loadConfig(const ConfigSection &configSection)
load the "auto_prefix_propagate" section from config file 
 
const Name & getName() const 
 
NFD Management protocol client. 
 
size_t size() const 
Get number of components. 
 
boost::property_tree::ptree ConfigSection
a config file section 
 
Represents an absolute name. 
 
bool isPrefixOf(const Name &other) const 
Check if this name is a prefix of another name. 
 
represents a rib/unregister command 
 
const Component & at(ssize_t i) const 
Get the component at the given index. 
 
CommandOptions & setSigningInfo(const security::SigningInfo &signingInfo)
sets signing parameters 
 
represents a rib/register command 
 
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted 
 
void enable()
enable automatic prefix propagation 
 
ControlParameters & setCost(uint64_t cost)
 
void disconnect()
disconnects the connection manually 
 
SigningInfo signingByIdentity(const Name &identityName)
 
Component holds a read-only name component value. 
 
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased 
 
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event 
 
ControlParameters & setName(const Name &name)
 
ControlParameters & setOrigin(RouteOrigin origin)
 
bool empty() const 
Check if name is empty. 
 
AutoPrefixPropagator(ndn::nfd::Controller &controller, ndn::KeyChain &keyChain, Rib &rib)
 
A frontend handle of an Identity. 
 
PartialName getPrefix(ssize_t nComponents) const 
Extract a prefix of the name. 
 
const time::seconds PREFIX_PROPAGATION_DEFAULT_MAX_RETRY_WAIT
 
#define NFD_LOG_INIT(name)
 
CommandOptions & setPrefix(const Name &prefix)
sets command prefix 
 
const security::SigningInfo & getSigningInfo() const