Skip to content

Commit fc0b45a

Browse files
committed
No longer set capture flag on advertised prefixes
Previously, all registered routes from NLSR would have the capture flag set. This is desirable for some application prefixes but does not necessarily make sense for advertised prefixes as a whole. Refs: #5360 Change-Id: If7e0f8e7d03aada18db9db4408f8d4167970e659
1 parent 879afac commit fc0b45a

8 files changed

Lines changed: 92 additions & 68 deletions

src/route/fib.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Fib::remove(const ndn::Name& name)
6060
}
6161

6262
void
63-
Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd)
63+
Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd, uint64_t routeFlags)
6464
{
6565
const ndn::Name& name = entry.name;
6666

@@ -77,13 +77,13 @@ Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& ho
7777
registerPrefix(name, ndn::FaceUri(hop.getConnectingFaceUri()),
7878
hop.getRouteCostAsAdjustedInteger(),
7979
ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
80-
ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
80+
routeFlags, 0);
8181
}
8282
}
8383
}
8484

8585
void
86-
Fib::update(const ndn::Name& name, const NexthopList& allHops)
86+
Fib::update(const ndn::Name& name, const NexthopList& allHops, uint64_t routeFlags)
8787
{
8888
NLSR_LOG_DEBUG("Fib::update called");
8989

@@ -107,7 +107,7 @@ Fib::update(const ndn::Name& name, const NexthopList& allHops)
107107

108108
FibEntry entry;
109109
entry.name = name;
110-
addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
110+
addNextHopsToFibEntryAndNfd(entry, hopsToAdd, routeFlags);
111111

112112
entryIt = m_table.try_emplace(name, std::move(entry)).first;
113113
}
@@ -123,7 +123,7 @@ Fib::update(const ndn::Name& name, const NexthopList& allHops)
123123
}
124124

125125
FibEntry& entry = entryIt->second;
126-
addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
126+
addNextHopsToFibEntryAndNfd(entry, hopsToAdd, routeFlags);
127127

128128
std::set<NextHop, NextHopUriSortedComparator> hopsToRemove;
129129
std::set_difference(entry.nexthopSet.begin(), entry.nexthopSet.end(),
@@ -149,7 +149,8 @@ Fib::update(const ndn::Name& name, const NexthopList& allHops)
149149
if (entryIt != m_table.end() &&
150150
!entryIt->second.refreshEventId &&
151151
isNotNeighbor(entryIt->second.name)) {
152-
scheduleEntryRefresh(entryIt->second, [this] (FibEntry& entry) { scheduleLoop(entry); });
152+
scheduleEntryRefresh(entryIt->second, routeFlags,
153+
[this] (FibEntry& entry, uint64_t routeFlags) { scheduleLoop(entry, routeFlags); });
153154
}
154155
}
155156

@@ -293,31 +294,30 @@ Fib::onSetStrategyFailure(const ndn::nfd::ControlResponse&,
293294
}
294295

295296
void
296-
Fib::scheduleEntryRefresh(FibEntry& entry, const AfterRefreshCallback& refreshCallback)
297+
Fib::scheduleEntryRefresh(FibEntry& entry, uint64_t routeFlags, const AfterRefreshCallback& refreshCallback)
297298
{
298299
NLSR_LOG_DEBUG("Scheduling refresh for " << entry.name <<
299300
" Seq Num: " << entry.seqNo <<
300301
" in " << m_refreshTime << " seconds");
301302

302303
entry.refreshEventId = m_scheduler.schedule(ndn::time::seconds(m_refreshTime),
303304
std::bind(&Fib::refreshEntry, this,
304-
entry.name, refreshCallback));
305+
entry.name, routeFlags, refreshCallback));
305306
}
306307

307308
void
308-
Fib::scheduleLoop(FibEntry& entry)
309+
Fib::scheduleLoop(FibEntry& entry, uint64_t routeFlags)
309310
{
310-
scheduleEntryRefresh(entry, std::bind(&Fib::scheduleLoop, this, _1));
311+
scheduleEntryRefresh(entry, routeFlags, std::bind(&Fib::scheduleLoop, this, _1, _2));
311312
}
312313

313314
void
314-
Fib::refreshEntry(const ndn::Name& name, AfterRefreshCallback refreshCb)
315+
Fib::refreshEntry(const ndn::Name& name, uint64_t routeFlags, AfterRefreshCallback refreshCb)
315316
{
316317
auto it = m_table.find(name);
317318
if (it == m_table.end()) {
318319
return;
319320
}
320-
321321
FibEntry& entry = it->second;
322322
NLSR_LOG_DEBUG("Refreshing " << entry.name << " Seq Num: " << entry.seqNo);
323323

@@ -328,10 +328,10 @@ Fib::refreshEntry(const ndn::Name& name, AfterRefreshCallback refreshCb)
328328
ndn::FaceUri(hop.getConnectingFaceUri()),
329329
hop.getRouteCostAsAdjustedInteger(),
330330
ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
331-
ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
331+
routeFlags, 0);
332332
}
333333

334-
refreshCb(entry);
334+
refreshCb(entry, routeFlags);
335335
}
336336

337337
void

src/route/fib.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct FibEntry
4141
NextHopsUriSortedSet nexthopSet;
4242
};
4343

44-
using AfterRefreshCallback = std::function<void(FibEntry&)>;
44+
using AfterRefreshCallback = std::function<void(FibEntry&, uint64_t)>;
4545

4646
class AdjacencyList;
4747
class ConfParameter;
@@ -86,9 +86,10 @@ class Fib
8686
*
8787
* \param name The name prefix that the next-hops apply to
8888
* \param allHops A complete list of next-hops to associate with name.
89+
* \param routeFlags Route inheritance flags
8990
*/
9091
void
91-
update(const ndn::Name& name, const NexthopList& allHops);
92+
update(const ndn::Name& name, const NexthopList& allHops, uint64_t routeFlags);
9293

9394
void
9495
setEntryRefreshTime(int32_t fert)
@@ -145,7 +146,7 @@ class Fib
145146
* \sa Fib::removeOldNextHopsFromFibEntryAndNfd
146147
*/
147148
void
148-
addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd);
149+
addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd, uint64_t routeFlags);
149150

150151
unsigned int
151152
getNumberOfFacesForName(const NexthopList& nextHopList);
@@ -194,18 +195,18 @@ class Fib
194195
* \sa Fib::scheduleLoop
195196
*/
196197
void
197-
scheduleEntryRefresh(FibEntry& entry, const AfterRefreshCallback& refreshCb);
198+
scheduleEntryRefresh(FibEntry& entry, uint64_t routeFlags, const AfterRefreshCallback& refreshCb);
198199

199200
private:
200201
/*! \brief Continue the entry refresh cycle.
201202
*/
202203
void
203-
scheduleLoop(FibEntry& entry);
204+
scheduleLoop(FibEntry& entry, uint64_t routeFlags);
204205

205206
/*! \brief Refreshes an entry in NFD.
206207
*/
207208
void
208-
refreshEntry(const ndn::Name& name, AfterRefreshCallback refreshCb);
209+
refreshEntry(const ndn::Name& name, uint64_t routeFlags, AfterRefreshCallback refreshCb);
209210

210211
public:
211212
static inline const ndn::Name MULTICAST_STRATEGY{"/localhost/nfd/strategy/multicast"};

src/route/name-prefix-table-entry.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class NamePrefixTableEntry
3838
{
3939
}
4040

41-
NamePrefixTableEntry(const ndn::Name& namePrefix)
41+
NamePrefixTableEntry(const ndn::Name& namePrefix, uint64_t routeFlags)
4242
: m_namePrefix(namePrefix)
43+
, m_flags(routeFlags)
4344
, m_nexthopList()
4445
{
4546
}
@@ -87,6 +88,18 @@ class NamePrefixTableEntry
8788
return m_nexthopList;
8889
}
8990

91+
void
92+
setFlags(uint64_t flags)
93+
{
94+
m_flags = flags;
95+
}
96+
97+
uint64_t
98+
getFlags() const
99+
{
100+
return m_flags;
101+
}
102+
90103
/*! \brief Collect all next-hops that are advertised by this entry's
91104
* routing entries.
92105
*/
@@ -114,6 +127,7 @@ class NamePrefixTableEntry
114127

115128
private:
116129
ndn::Name m_namePrefix;
130+
uint64_t m_flags;
117131

118132
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
119133
std::list<std::shared_ptr<RoutingTablePoolEntry>> m_rteList;

src/route/name-prefix-table.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ NamePrefixTable::updateFromLsdb(std::shared_ptr<Lsa> lsa, LsdbUpdate updateType,
7878
for (const auto &prefix : nlsa->getNpl().getPrefixInfo()) {
7979
if (prefix.getName() != m_ownRouterName) {
8080
m_nexthopCost[DestNameKey(lsa->getOriginRouter(), prefix.getName())] = prefix.getCost();
81-
addEntry(prefix.getName(), lsa->getOriginRouter());
81+
// Don't use capture flag on advertised prefixes...
82+
addEntry(prefix.getName(), lsa->getOriginRouter(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
8283
}
8384
}
8485
}
@@ -91,7 +92,8 @@ NamePrefixTable::updateFromLsdb(std::shared_ptr<Lsa> lsa, LsdbUpdate updateType,
9192
for (const auto &prefix : namesToAdd) {
9293
if (prefix.getName() != m_ownRouterName) {
9394
m_nexthopCost[DestNameKey(lsa->getOriginRouter(), prefix.getName())] = prefix.getCost();
94-
addEntry(prefix.getName(), lsa->getOriginRouter());
95+
// Don't use capture flag on advertised prefixes...
96+
addEntry(prefix.getName(), lsa->getOriginRouter(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
9597
}
9698
}
9799

@@ -129,7 +131,7 @@ NamePrefixTable::adjustNexthopCosts(const NexthopList& nhlist, const ndn::Name&
129131
}
130132

131133
void
132-
NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
134+
NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter, uint64_t routeFlags)
133135
{
134136
// Check if the advertised name prefix is in the table already.
135137
auto nameItr = std::find_if(m_table.begin(), m_table.end(),
@@ -169,15 +171,16 @@ NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
169171
if (nameItr == m_table.end()) {
170172
NLSR_LOG_DEBUG("Adding origin: " << rtpePtr->getDestination()
171173
<< " to a new name prefix: " << name);
172-
npte = std::make_shared<NamePrefixTableEntry>(name);
174+
175+
npte = std::make_shared<NamePrefixTableEntry>(name, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
173176
npte->addRoutingTableEntry(rtpePtr);
174177
npte->generateNhlfromRteList();
175178
m_table.push_back(npte);
176179

177180
// If this entry has next hops, we need to inform the FIB
178181
if (npte->getNexthopList().size() > 0) {
179182
NLSR_LOG_TRACE("Updating FIB with next hops for " << npte->getNamePrefix());
180-
m_fib.update(name, adjustNexthopCosts(npte->getNexthopList(), name, destRouter));
183+
m_fib.update(name, adjustNexthopCosts(npte->getNexthopList(), name, destRouter), npte->getFlags());
181184
}
182185
// The routing table may recalculate and add a routing table entry
183186
// with no next hops to replace an existing routing table entry. In
@@ -193,13 +196,16 @@ NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
193196
else {
194197
npte = *nameItr;
195198
NLSR_LOG_TRACE("Adding origin: " << rtpePtr->getDestination() <<
196-
" to existing prefix: " << **nameItr);
197-
(*nameItr)->addRoutingTableEntry(rtpePtr);
198-
(*nameItr)->generateNhlfromRteList();
199-
200-
if ((*nameItr)->getNexthopList().size() > 0) {
201-
NLSR_LOG_TRACE("Updating FIB with next hops for " << (**nameItr));
202-
m_fib.update(name, adjustNexthopCosts((*nameItr)->getNexthopList(), name, destRouter));
199+
" to existing prefix: " << *npte);
200+
// We should not downgrade the capture flag to child-inherit unless there are no nexthops
201+
if (npte->getFlags() != routeFlags && npte->getNexthopList().size() == 0) {
202+
npte->setFlags(routeFlags);
203+
}
204+
npte->addRoutingTableEntry(rtpePtr);
205+
npte->generateNhlfromRteList();
206+
if (npte->getNexthopList().size() > 0) {
207+
NLSR_LOG_TRACE("Updating FIB with next hops for " << *npte);
208+
m_fib.update(name, adjustNexthopCosts(npte->getNexthopList(), name, destRouter), npte->getFlags());
203209
}
204210
else {
205211
NLSR_LOG_TRACE(npte->getNamePrefix() << " has no next hops; removing from FIB");
@@ -233,12 +239,13 @@ NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter)
233239
auto nameItr = std::find_if(m_table.begin(), m_table.end(),
234240
[&] (const auto& entry) { return entry->getNamePrefix() == name; });
235241
if (nameItr != m_table.end()) {
242+
std::shared_ptr<NamePrefixTableEntry> npte = *nameItr;
236243
NLSR_LOG_TRACE("Removing origin: " << rtpePtr->getDestination()
237244
<< " from prefix: " << **nameItr);
238245

239246
// Rather than iterating through the whole list periodically, just
240247
// delete them here if they have no references.
241-
if ((*nameItr)->removeRoutingTableEntry(rtpePtr) == 0) {
248+
if (npte->removeRoutingTableEntry(rtpePtr) == 0) {
242249
deleteRtpeFromPool(rtpePtr);
243250
}
244251

@@ -257,17 +264,17 @@ NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter)
257264
// Prefix Table. Once a new Name LSA advertises this prefix, a
258265
// new entry for the prefix will be created.
259266
//
260-
if ((*nameItr)->getRteListSize() == 0) {
261-
NLSR_LOG_TRACE(**nameItr << " has no routing table entries;"
267+
if (npte->getRteListSize() == 0) {
268+
NLSR_LOG_TRACE(*npte << " has no routing table entries;"
262269
<< " removing from table and FIB");
263270
m_table.erase(nameItr);
264271
m_fib.remove(name);
265272
}
266273
else {
267-
NLSR_LOG_TRACE(**nameItr << " has other routing table entries;"
274+
NLSR_LOG_TRACE(*npte << " has other routing table entries;"
268275
<< " updating FIB with next hops");
269276
(*nameItr)->generateNhlfromRteList();
270-
m_fib.update(name, adjustNexthopCosts((*nameItr)->getNexthopList(), name, destRouter));
277+
m_fib.update(name, adjustNexthopCosts(npte->getNexthopList(), name, destRouter), npte->getFlags());
271278
}
272279
}
273280
else {
@@ -295,15 +302,15 @@ NamePrefixTable::updateWithNewRoute(const std::list<RoutingTableEntry>& entries)
295302
poolEntry->setNexthopList(sourceEntry->getNexthopList());
296303
for (const auto& nameEntry : poolEntry->namePrefixTableEntries) {
297304
auto nameEntryFullPtr = nameEntry.second.lock();
298-
addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
305+
addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination(), nameEntryFullPtr->getFlags());
299306
}
300307
}
301308
else if (sourceEntry == entries.end()) {
302309
NLSR_LOG_DEBUG("Routing entry: " << poolEntry->getDestination() << " now has no next-hops.");
303310
poolEntry->getNexthopList().clear();
304311
for (const auto& nameEntry : poolEntry->namePrefixTableEntries) {
305312
auto nameEntryFullPtr = nameEntry.second.lock();
306-
addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
313+
addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination(), nameEntryFullPtr->getFlags());
307314
}
308315
}
309316
else {

src/route/name-prefix-table.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class NamePrefixTable
6666
/*! \brief Adds a destination to the specified name prefix.
6767
\param name The name prefix
6868
\param destRouter The destination router prefix
69+
\param routeFlags Route inheritance flags from NFD
6970
7071
This method adds a router to a name prefix table entry. If the
7172
name prefix table entry does not exist, it is created. The method
@@ -77,7 +78,7 @@ class NamePrefixTable
7778
notified of the change to the NPT entry, too.
7879
*/
7980
void
80-
addEntry(const ndn::Name& name, const ndn::Name& destRouter);
81+
addEntry(const ndn::Name& name, const ndn::Name& destRouter, uint64_t routeFlags = ndn::nfd::ROUTE_FLAG_CAPTURE);
8182

8283
/*! \brief Removes a destination from a name prefix table entry.
8384
\param name The name prefix

0 commit comments

Comments
 (0)