41 std::uniform_int_distribution<uint64_t> dist(-5, 5);
43 return std::max(newTime, time::milliseconds(0));
47 unique_ptr<ReadvertiseDestination> destination)
48 : m_policy(
std::move(policy))
49 , m_destination(
std::move(destination))
51 m_addRouteConn = rib.
afterAddRoute.connect(bind(&Readvertise::afterAddRoute,
this, _1));
52 m_removeRouteConn = rib.
beforeRemoveRoute.connect(bind(&Readvertise::beforeRemoveRoute,
this, _1));
54 m_destination->afterAvailabilityChange.connect([
this] (
bool isAvailable) {
56 this->afterDestinationAvailable();
59 this->afterDestinationUnavailable();
65 Readvertise::afterAddRoute(
const RibRouteRef& ribRoute)
70 ',' << ribRoute.
route->origin <<
") not-readvertising");
76 std::tie(rrIt, isNew) = m_rrs.emplace(action->prefix);
78 if (!isNew && rrIt->signer != action->signer) {
80 ',' << ribRoute.
route->origin <<
") readvertising-as " << action->prefix <<
81 " old-signer " << rrIt->signer <<
" new-signer " << action->signer);
83 rrIt->signer = action->signer;
86 std::tie(indexIt, isNew) = m_routeToRr.emplace(ribRoute, rrIt);
89 if (rrIt->nRibRoutes++ > 0) {
91 ',' << ribRoute.
route->origin <<
") already-readvertised-as " << action->prefix);
96 ',' << ribRoute.
route->origin <<
") readvertising-as " << action->prefix <<
97 " signer " << action->signer);
98 rrIt->retryDelay = RETRY_DELAY_MIN;
99 this->advertise(rrIt);
103 Readvertise::beforeRemoveRoute(
const RibRouteRef& ribRoute)
105 auto indexIt = m_routeToRr.find(ribRoute);
106 if (indexIt == m_routeToRr.end()) {
108 ',' << ribRoute.
route->origin <<
") not-readvertised");
112 auto rrIt = indexIt->second;
113 m_routeToRr.erase(indexIt);
115 if (--rrIt->nRibRoutes > 0) {
117 ',' << ribRoute.
route->origin <<
") needed-by " << rrIt->nRibRoutes);
121 rrIt->retryDelay = RETRY_DELAY_MIN;
122 this->withdraw(rrIt);
126 Readvertise::afterDestinationAvailable()
128 for (
auto rrIt = m_rrs.begin(); rrIt != m_rrs.end(); ++rrIt) {
129 rrIt->retryDelay = RETRY_DELAY_MIN;
130 this->advertise(rrIt);
135 Readvertise::afterDestinationUnavailable()
137 for (
auto rrIt = m_rrs.begin(); rrIt != m_rrs.end();) {
138 if (rrIt->nRibRoutes > 0) {
139 rrIt->retryEvt.cancel();
143 rrIt = m_rrs.erase(rrIt);
151 BOOST_ASSERT(rrIt->nRibRoutes > 0);
153 if (!m_destination->isAvailable()) {
154 NFD_LOG_DEBUG(
"advertise " << rrIt->prefix <<
" destination-unavailable");
158 m_destination->advertise(*rrIt,
161 rrIt->retryDelay = RETRY_DELAY_MIN;
163 bind(&Readvertise::advertise,
this, rrIt));
165 [
this, rrIt] (
const std::string& msg) {
166 NFD_LOG_DEBUG(
"advertise " << rrIt->prefix <<
" failure " << msg);
167 rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
169 bind(&Readvertise::advertise,
this, rrIt));
176 BOOST_ASSERT(rrIt->nRibRoutes == 0);
178 if (!m_destination->isAvailable()) {
179 NFD_LOG_DEBUG(
"withdraw " << rrIt->prefix <<
" destination-unavailable");
184 m_destination->withdraw(*rrIt,
189 [
this, rrIt] (
const std::string& msg) {
190 NFD_LOG_DEBUG(
"withdraw " << rrIt->prefix <<
" failure " << msg);
191 rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
193 bind(&Readvertise::withdraw,
this, rrIt));
Declares the global pseudorandom number generator (PRNG) for NFD.
represents the Routing Information Base
boost::posix_time::time_duration milliseconds(long duration)
ndn::util::signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
Readvertise(Rib &rib, unique_ptr< ReadvertisePolicy > policy, unique_ptr< ReadvertiseDestination > destination)
#define NFD_LOG_DEBUG(expression)
RibEntry::const_iterator route
Table::const_iterator iterator
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< RibEntry > entry
static time::milliseconds randomizeTimer(time::milliseconds baseTimer)
std::mt19937 & getGlobalRng()
#define NFD_LOG_WARN(expression)
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event
#define NFD_LOG_INIT(name)
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed