29 #include <ndn-cxx/security/signing-helpers.hpp> 53 : m_nfdController(controller)
54 , m_keyChain(keyChain)
56 , m_refreshInterval(PREFIX_PROPAGATION_DEFAULT_REFRESH_INTERVAL)
57 , m_baseRetryWait(PREFIX_PROPAGATION_DEFAULT_BASE_RETRY_WAIT)
58 , m_maxRetryWait(PREFIX_PROPAGATION_DEFAULT_MAX_RETRY_WAIT)
59 , m_hasConnectedHub(false)
71 .
setCost(PREFIX_PROPAGATION_DEFAULT_COST)
77 .
setTimeout(PREFIX_PROPAGATION_DEFAULT_TIMEOUT);
79 NFD_LOG_INFO(
"Load auto_prefix_propagate section in rib section");
81 for (
auto&& i : configSection) {
82 if (i.first ==
"cost") {
83 m_controlParameters.
setCost(i.second.get_value<uint64_t>());
85 else if (i.first ==
"timeout") {
86 m_commandOptions.
setTimeout(time::milliseconds(i.second.get_value<
size_t>()));
88 else if (i.first ==
"refresh_interval") {
89 m_refreshInterval = std::min(PREFIX_PROPAGATION_MAX_REFRESH_INTERVAL,
90 time::seconds(i.second.get_value<
size_t>()));
92 else if (i.first ==
"base_retry_wait") {
93 m_baseRetryWait = time::seconds(i.second.get_value<
size_t>());
95 else if (i.first ==
"max_retry_wait") {
96 m_maxRetryWait = time::seconds(i.second.get_value<
size_t>());
100 "\" in \"auto_prefix_propagate\" section"));
108 m_afterInsertConnection =
109 m_rib.
afterInsertEntry.connect(bind(&AutoPrefixPropagator::afterInsertRibEntry,
this, _1));
110 m_afterEraseConnection =
111 m_rib.
afterEraseEntry.connect(bind(&AutoPrefixPropagator::afterEraseRibEntry,
this, _1));
121 AutoPrefixPropagator::PrefixPropagationParameters
122 AutoPrefixPropagator::getPrefixPropagationParameters(
const Name& localRibPrefix)
125 std::vector<Name> identities;
130 Name propagatedPrefix, signingIdentity;
131 bool isFound =
false;
132 for (
auto&& i : identities) {
134 if (prefix.
isPrefixOf(localRibPrefix) && (!isFound || i.size() < signingIdentity.
size())) {
136 propagatedPrefix = prefix;
141 PrefixPropagationParameters propagateParameters;
143 propagateParameters.isValid =
false;
146 propagateParameters.isValid =
true;
147 propagateParameters.parameters = m_controlParameters;
148 propagateParameters.options = m_commandOptions;
149 propagateParameters.parameters.setName(propagatedPrefix);
153 return propagateParameters;
157 AutoPrefixPropagator::afterInsertRibEntry(
const Name& prefix)
165 NFD_LOG_INFO(
"this is a prefix registered by some hub: " << prefix);
167 m_hasConnectedHub =
true;
168 return afterHubConnect();
171 auto propagateParameters = getPrefixPropagationParameters(prefix);
172 if (!propagateParameters.isValid) {
173 NFD_LOG_INFO(
"no signing identity available for: " << prefix);
177 auto entryIt = m_propagatedEntries.find(propagateParameters.parameters.getName());
178 if (entryIt != m_propagatedEntries.end()) {
182 << propagateParameters.parameters.getName());
186 afterRibInsert(propagateParameters.parameters, propagateParameters.options);
190 AutoPrefixPropagator::afterEraseRibEntry(
const Name& prefix)
193 NFD_LOG_INFO(
"local unregistration only for " << prefix);
198 NFD_LOG_INFO(
"disconnected to hub with prefix: " << prefix);
200 m_hasConnectedHub =
false;
201 return afterHubDisconnect();
204 auto propagateParameters = getPrefixPropagationParameters(prefix);
205 if (!propagateParameters.isValid) {
206 NFD_LOG_INFO(
"no signing identity available for: " << prefix);
210 auto entryIt = m_propagatedEntries.find(propagateParameters.parameters.getName());
211 if (entryIt == m_propagatedEntries.end()) {
213 << propagateParameters.parameters.getName());
217 for (
auto&& ribTableEntry : m_rib) {
218 if (propagateParameters.parameters.getName().isPrefixOf(ribTableEntry.first) &&
219 propagateParameters.options.getSigningInfo().getSignerName() ==
220 getPrefixPropagationParameters(ribTableEntry.first)
221 .options.getSigningInfo().getSignerName()) {
222 NFD_LOG_INFO(
"should be kept for another RIB entry: " << ribTableEntry.first);
227 afterRibErase(propagateParameters.parameters.unsetCost(), propagateParameters.options);
231 AutoPrefixPropagator::doesCurrentPropagatedPrefixWork(
const Name& prefix)
233 auto propagateParameters = getPrefixPropagationParameters(prefix);
234 if (!propagateParameters.isValid) {
242 return propagateParameters.parameters.getName().size() == prefix.
size();
246 AutoPrefixPropagator::redoPropagation(PropagatedEntryIt entryIt,
249 time::seconds retryWaitTime)
251 if (doesCurrentPropagatedPrefixWork(parameters.
getName())) {
253 entryIt->second.startPropagation();
254 return advertise(parameters, options, retryWaitTime);
257 NFD_LOG_INFO(
"current propagated prefix does not work any more");
258 m_propagatedEntries.erase(entryIt);
261 for (
auto&& ribTableEntry : m_rib) {
263 afterInsertRibEntry(ribTableEntry.first);
271 time::seconds retryWaitTime)
276 bind(&AutoPrefixPropagator::onRefreshTimer,
this, parameters, options);
278 bind(&AutoPrefixPropagator::onRetryTimer,
this, parameters, options,
279 std::min(m_maxRetryWait, retryWaitTime * 2));
283 bind(&AutoPrefixPropagator::afterPropagateSucceed,
this, parameters, options, refreshEvent),
284 bind(&AutoPrefixPropagator::afterPropagateFail,
285 this, _1, parameters, options, retryWaitTime, retryEvent),
292 time::seconds retryWaitTime)
298 bind(&AutoPrefixPropagator::afterRevokeSucceed,
this, parameters, options, retryWaitTime),
299 bind(&AutoPrefixPropagator::afterRevokeFail,
this, _1, parameters, options),
307 BOOST_ASSERT(m_propagatedEntries.find(parameters.
getName()) == m_propagatedEntries.end());
310 auto& entry = m_propagatedEntries[parameters.
getName()]
313 if (!m_hasConnectedHub) {
319 entry.startPropagation();
320 advertise(parameters, options, m_baseRetryWait);
327 auto entryIt = m_propagatedEntries.find(parameters.
getName());
328 BOOST_ASSERT(entryIt != m_propagatedEntries.end());
330 bool hasPropagationSucceeded = entryIt->second.isPropagated();
333 m_propagatedEntries.erase(entryIt);
335 if (!m_hasConnectedHub) {
340 if (!hasPropagationSucceeded) {
345 withdraw(parameters, options, m_baseRetryWait);
349 AutoPrefixPropagator::afterHubConnect()
352 <<
" propagations when new Hub connectivity is built.");
354 std::vector<PropagatedEntryIt> regEntryIterators;
355 for (
auto it = m_propagatedEntries.begin() ; it != m_propagatedEntries.end() ; it ++) {
356 BOOST_ASSERT(it->second.isNew());
357 regEntryIterators.push_back(it);
360 for (
auto&& it : regEntryIterators) {
361 auto parameters = m_controlParameters;
362 auto options = m_commandOptions;
372 AutoPrefixPropagator::afterHubDisconnect()
374 for (
auto&& entry : m_propagatedEntries) {
376 BOOST_ASSERT(!entry.second.isNew());
377 entry.second.initialize();
388 auto entryIt = m_propagatedEntries.find(parameters.
getName());
389 if (entryIt == m_propagatedEntries.end()) {
393 return withdraw(newParameters.
unsetCost(), options, m_baseRetryWait);
397 BOOST_ASSERT(entryIt->second.isPropagating());
405 time::seconds retryWaitTime,
409 <<
"\n\t reason:" << response.
getText()
410 <<
"\n\t retry wait time: " << retryWaitTime);
412 auto entryIt = m_propagatedEntries.find(parameters.
getName());
413 if (entryIt == m_propagatedEntries.end()) {
419 BOOST_ASSERT(entryIt->second.isPropagating());
426 time::seconds retryWaitTime)
430 auto entryIt = m_propagatedEntries.find(parameters.
getName());
431 if (m_propagatedEntries.end() != entryIt && !entryIt->second.isPropagateFail()) {
436 BOOST_ASSERT(!entryIt->second.isNew());
437 entryIt->second.startPropagation();
440 advertise(newParameters.
setCost(m_controlParameters.
getCost()), options, retryWaitTime);
450 <<
"\n\t reason:" << response.
getText());
457 auto entryIt = m_propagatedEntries.find(parameters.
getName());
458 BOOST_ASSERT(entryIt != m_propagatedEntries.end() && entryIt->second.isPropagated());
459 redoPropagation(entryIt, parameters, options, m_baseRetryWait);
465 time::seconds retryWaitTime)
467 auto entryIt = m_propagatedEntries.find(parameters.
getName());
468 BOOST_ASSERT(entryIt != m_propagatedEntries.end() && entryIt->second.isPropagateFail());
469 redoPropagation(entryIt, parameters, options, retryWaitTime);
const Name LINK_LOCAL_NFD_PREFIX("/localhop/nfd")
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
void getAllIdentities(std::vector< Name > &nameList, bool isDefault) const
represents parameters in a ControlCommand request or response
const security::SigningInfo & getSigningInfo() const
The packet signing interface.
#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 time::milliseconds PREFIX_PROPAGATION_DEFAULT_TIMEOUT
CommandOptions & setTimeout(const time::milliseconds &timeout)
sets command timeout
const Name & getSignerName() const
const time::seconds PREFIX_PROPAGATION_DEFAULT_BASE_RETRY_WAIT
#define NFD_LOG_TRACE(expression)
const Name & getName() const
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
SigningInfo signingByIdentity(const Name &identity)
NFD Management protocol client.
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
represents a rib/unregister command
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
size_t size() const
Get the number of components.
void enable()
enable automatic prefix propagation
ControlParameters & setCost(uint64_t cost)
void disconnect()
disconnects the connection manually
Component holds a read-only name component value.
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
ControlParameters & setOrigin(uint64_t origin)
ControlParameters & setName(const Name &name)
AutoPrefixPropagator(ndn::nfd::Controller &controller, ndn::KeyChain &keyChain, Rib &rib)
bool empty() const
Check if name is emtpy.
const std::string & getText() const
Name getDefaultIdentity() const
const time::seconds PREFIX_PROPAGATION_DEFAULT_MAX_RETRY_WAIT
#define NFD_LOG_INIT(name)
CommandOptions & setPrefix(const Name &prefix)
sets command prefix