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)
62 , m_hasConnectedHub(false)
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") {
89 m_commandOptions.
setTimeout(time::milliseconds(i.second.get_value<
size_t>()));
91 else if (i.first ==
"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;
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,
255 const CommandOptions& options,
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) {
269 if (parameters.getName().isPrefixOf(ribTableEntry.first)) {
270 afterInsertRibEntry(ribTableEntry.first);
277 const CommandOptions& options,
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),
298 const CommandOptions& options,
299 time::seconds retryWaitTime)
305 bind(&AutoPrefixPropagator::afterRevokeSucceed,
this, parameters, options, retryWaitTime),
306 bind(&AutoPrefixPropagator::afterRevokeFail,
this, _1, parameters, options),
312 const CommandOptions& options)
314 BOOST_ASSERT(m_propagatedEntries.find(parameters.getName()) == m_propagatedEntries.end());
317 auto& entry = m_propagatedEntries[parameters.getName()]
318 .setSigningIdentity(options.getSigningInfo().getSignerName());
320 if (!m_hasConnectedHub) {
321 NFD_LOG_INFO(
"no hub connected to propagate " << parameters.getName());
326 entry.startPropagation();
327 advertise(parameters, options, m_baseRetryWait);
332 const CommandOptions& options)
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) {
343 NFD_LOG_INFO(
"no hub connected to revoke propagation of " << parameters.getName());
347 if (!hasPropagationSucceeded) {
348 NFD_LOG_INFO(
"propagation has not succeeded: " << parameters.getName());
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;
372 parameters.setName(it->first),
379 AutoPrefixPropagator::afterHubDisconnect()
381 for (
auto&& entry : m_propagatedEntries) {
383 BOOST_ASSERT(!entry.second.isNew());
384 entry.second.initialize();
390 const CommandOptions& options,
393 NFD_LOG_TRACE(
"success to propagate " << parameters.getName());
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());
411 const CommandOptions& options,
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());
432 const CommandOptions& options,
433 time::seconds retryWaitTime)
435 NFD_LOG_TRACE(
"success to revoke propagation of " << parameters.getName());
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);
454 const CommandOptions& options)
456 NFD_LOG_INFO(
"fail to revoke the propagation of " << parameters.getName()
457 <<
"\n\t reason:" << response.
getText());
462 const CommandOptions& options)
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);
471 const CommandOptions& options,
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
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
ControlParameters & setFaceId(uint64_t faceId)
represents the Routing Information Base
The interface of signing key management.
const Name LOCAL_REGISTRATION_PREFIX("/localhost")
const time::seconds PREFIX_PROPAGATION_MAX_REFRESH_INTERVAL
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
#define NFD_LOG_DEBUG(expression)
const name::Component IGNORE_COMMPONENT("nrd")
void disable()
disable automatic prefix propagation
#define NFD_LOG_INFO(expression)
const IdentityContainer & getIdentities() const
Get all the identities.
const time::milliseconds PREFIX_PROPAGATION_DEFAULT_TIMEOUT
const Pib & getPib() const
CommandOptions & setTimeout(const time::milliseconds &timeout)
sets command timeout
const time::seconds PREFIX_PROPAGATION_DEFAULT_BASE_RETRY_WAIT
const Component & at(ssize_t i) const
Get the component at the given index.
#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
NFD Management protocol client.
boost::property_tree::ptree ConfigSection
a config file section
Represents an absolute 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 number of components.
void enable()
enable automatic prefix propagation
ControlParameters & setCost(uint64_t cost)
void disconnect()
disconnects the connection manually
SigningInfo signingByIdentity(const Name &identityName)
Represents a name component.
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 & setOrigin(RouteOrigin origin)
AutoPrefixPropagator(ndn::nfd::Controller &controller, ndn::KeyChain &keyChain, Rib &rib)
bool empty() const
Check if name is empty.
A frontend handle of an Identity.
const std::string & getText() const
const time::seconds PREFIX_PROPAGATION_DEFAULT_MAX_RETRY_WAIT
#define NFD_LOG_INIT(name)
CommandOptions & setPrefix(const Name &prefix)
sets command prefix