blob: 0f099d60b7e4a68bab7f9607d35be6ff0efa389f [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa3148082018-04-12 18:21:54 -04002/*
Davide Pesavento2cae8ca2019-04-18 20:48:05 -04003 * Copyright (c) 2014-2019, Regents of the University of California,
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Vince12e49462014-06-09 13:29:32 -050024 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070025
26#include "rib.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060027#include "fib-updater.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040028#include "common/logger.hpp"
Vince Lehman281ded72014-08-21 12:17:08 -050029
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070030namespace nfd {
31namespace rib {
32
Davide Pesaventoa3148082018-04-12 18:21:54 -040033NFD_LOG_INIT(Rib);
34
Junxiao Shi89c0ea02017-03-06 19:52:05 +000035bool
36operator<(const RibRouteRef& lhs, const RibRouteRef& rhs)
37{
38 return std::tie(lhs.entry->getName(), lhs.route->faceId, lhs.route->origin) <
39 std::tie(rhs.entry->getName(), rhs.route->faceId, rhs.route->origin);
40}
41
Vince Lehman4387e782014-06-19 16:57:45 -050042static inline bool
Vince Lehman218be0a2015-01-15 17:25:20 -060043sortRoutes(const Route& lhs, const Route& rhs)
Vince Lehman4387e782014-06-19 16:57:45 -050044{
Vince Lehman218be0a2015-01-15 17:25:20 -060045 return lhs.faceId < rhs.faceId;
Vince Lehman4387e782014-06-19 16:57:45 -050046}
47
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070048Rib::Rib()
Vince12e49462014-06-09 13:29:32 -050049 : m_nItems(0)
Vince Lehman76c751c2014-11-18 17:36:38 -060050 , m_isUpdateInProgress(false)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070051{
52}
53
Vince Lehman76c751c2014-11-18 17:36:38 -060054void
55Rib::setFibUpdater(FibUpdater* updater)
56{
57 m_fibUpdater = updater;
58}
59
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070060Rib::const_iterator
Vince12e49462014-06-09 13:29:32 -050061Rib::find(const Name& prefix) const
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070062{
Vince12e49462014-06-09 13:29:32 -050063 return m_rib.find(prefix);
64}
65
Vince Lehman218be0a2015-01-15 17:25:20 -060066Route*
67Rib::find(const Name& prefix, const Route& route) const
Vince12e49462014-06-09 13:29:32 -050068{
Davide Pesaventoe4b22382018-06-10 14:37:24 -040069 auto ribIt = m_rib.find(prefix);
Vince12e49462014-06-09 13:29:32 -050070
71 // Name prefix exists
Vince Lehman76c751c2014-11-18 17:36:38 -060072 if (ribIt != m_rib.end()) {
73 shared_ptr<RibEntry> entry = ribIt->second;
Davide Pesaventoe4b22382018-06-10 14:37:24 -040074 auto routeIt = entry->findRoute(route);
Vince Lehman76c751c2014-11-18 17:36:38 -060075 if (routeIt != entry->end()) {
Davide Pesaventoe4b22382018-06-10 14:37:24 -040076 return &*routeIt;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070077 }
Vince Lehman76c751c2014-11-18 17:36:38 -060078 }
Vince Lehman218be0a2015-01-15 17:25:20 -060079
80 return nullptr;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070081}
82
Teng Lianga4e6ec32018-10-21 09:25:00 -070083Route*
84Rib::findLongestPrefix(const Name& prefix, const Route& route) const
85{
86 Route* existingRoute = find(prefix, route);
87 if (existingRoute == nullptr) {
88 auto parent = findParent(prefix);
89 if (parent) {
90 existingRoute = find(parent->getName(), route);
91 }
92 }
93
94 return existingRoute;
95}
96
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070097void
Vince Lehman218be0a2015-01-15 17:25:20 -060098Rib::insert(const Name& prefix, const Route& route)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070099{
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400100 auto ribIt = m_rib.find(prefix);
Vince12e49462014-06-09 13:29:32 -0500101
102 // Name prefix exists
Vince Lehman76c751c2014-11-18 17:36:38 -0600103 if (ribIt != m_rib.end()) {
104 shared_ptr<RibEntry> entry(ribIt->second);
Vince12e49462014-06-09 13:29:32 -0500105
Nick Gordon89c4cca2016-11-02 15:42:32 +0000106 RibEntry::iterator entryIt;
107 bool didInsert = false;
108 std::tie(entryIt, didInsert) = entry->insertRoute(route);
Vince12e49462014-06-09 13:29:32 -0500109
Nick Gordon89c4cca2016-11-02 15:42:32 +0000110 if (didInsert) {
111 // The route was new and we successfully inserted it.
Vince Lehman76c751c2014-11-18 17:36:38 -0600112 m_nItems++;
Vince12e49462014-06-09 13:29:32 -0500113
Nick Gordon89c4cca2016-11-02 15:42:32 +0000114 afterAddRoute(RibRouteRef{entry, entryIt});
115
Vince12e49462014-06-09 13:29:32 -0500116 // Register with face lookup table
Junxiao Shi17a70012019-06-25 10:50:32 +0000117 m_faceEntries.emplace(route.faceId, entry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700118 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600119 else {
120 // Route exists, update fields
121 // First cancel old scheduled event, if any, then set the EventId to new one
Davide Pesaventoe1bdc082018-10-11 21:20:23 -0400122 if (entryIt->getExpirationEvent()) {
123 NFD_LOG_TRACE("Cancelling expiration event for " << entry->getName() << " " << *entryIt);
124 entryIt->cancelExpirationEvent();
Vince Lehman76c751c2014-11-18 17:36:38 -0600125 }
126
Junxiao Shid47cd632018-09-11 03:10:00 +0000127 *entryIt = route;
Vince Lehman76c751c2014-11-18 17:36:38 -0600128 }
129 }
130 else {
131 // New name prefix
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400132 auto entry = make_shared<RibEntry>();
Vince Lehman76c751c2014-11-18 17:36:38 -0600133
134 m_rib[prefix] = entry;
135 m_nItems++;
136
137 entry->setName(prefix);
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400138 auto routeIt = entry->insertRoute(route).first;
Vince Lehman76c751c2014-11-18 17:36:38 -0600139
140 // Find prefix's parent
141 shared_ptr<RibEntry> parent = findParent(prefix);
142
143 // Add self to parent's children
144 if (parent != nullptr) {
145 parent->addChild(entry);
146 }
147
148 RibEntryList children = findDescendants(prefix);
149
150 for (const auto& child : children) {
151 if (child->getParent() == parent) {
152 // Remove child from parent and inherit parent's child
153 if (parent != nullptr) {
154 parent->removeChild(child);
155 }
156
157 entry->addChild(child);
158 }
159 }
160
161 // Register with face lookup table
Junxiao Shi17a70012019-06-25 10:50:32 +0000162 m_faceEntries.emplace(route.faceId, entry);
Vince Lehman76c751c2014-11-18 17:36:38 -0600163
164 // do something after inserting an entry
165 afterInsertEntry(prefix);
Nick Gordon89c4cca2016-11-02 15:42:32 +0000166 afterAddRoute(RibRouteRef{entry, routeIt});
Vince Lehman76c751c2014-11-18 17:36:38 -0600167 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700168}
169
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700170void
Vince Lehman218be0a2015-01-15 17:25:20 -0600171Rib::erase(const Name& prefix, const Route& route)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700172{
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400173 auto ribIt = m_rib.find(prefix);
Junxiao Shi17a70012019-06-25 10:50:32 +0000174 if (ribIt == m_rib.end()) {
175 // Name prefix does not exist
176 return;
177 }
Vince12e49462014-06-09 13:29:32 -0500178
Junxiao Shi17a70012019-06-25 10:50:32 +0000179 shared_ptr<RibEntry> entry = ribIt->second;
180 auto routeIt = entry->findRoute(route);
Vince Lehman4387e782014-06-19 16:57:45 -0500181
Junxiao Shi17a70012019-06-25 10:50:32 +0000182 if (routeIt != entry->end()) {
183 beforeRemoveRoute(RibRouteRef{entry, routeIt});
Nick Gordon89c4cca2016-11-02 15:42:32 +0000184
Junxiao Shi17a70012019-06-25 10:50:32 +0000185 auto faceId = route.faceId;
186 entry->eraseRoute(routeIt);
187 m_nItems--;
Vince Lehman4387e782014-06-19 16:57:45 -0500188
Junxiao Shi17a70012019-06-25 10:50:32 +0000189 // If this RibEntry no longer has this faceId, unregister from face lookup table
190 if (!entry->hasFaceId(faceId)) {
191 auto range = m_faceEntries.equal_range(faceId);
192 for (auto it = range.first; it != range.second; ++it) {
193 if (it->second == entry) {
194 m_faceEntries.erase(it);
195 break;
196 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600197 }
Junxiao Shi17a70012019-06-25 10:50:32 +0000198 }
Syed Obaid3313a372014-07-01 01:31:33 -0500199
Junxiao Shi17a70012019-06-25 10:50:32 +0000200 // If a RibEntry's route list is empty, remove it from the tree
201 if (entry->getRoutes().empty()) {
202 eraseEntry(ribIt);
Vince12e49462014-06-09 13:29:32 -0500203 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600204 }
Vince12e49462014-06-09 13:29:32 -0500205}
206
207void
Vince Lehman76c751c2014-11-18 17:36:38 -0600208Rib::onRouteExpiration(const Name& prefix, const Route& route)
Vince12e49462014-06-09 13:29:32 -0500209{
Vince Lehman76c751c2014-11-18 17:36:38 -0600210 NFD_LOG_DEBUG(route << " for " << prefix << " has expired");
Vince12e49462014-06-09 13:29:32 -0500211
Vince Lehman76c751c2014-11-18 17:36:38 -0600212 RibUpdate update;
213 update.setAction(RibUpdate::UNREGISTER)
214 .setName(prefix)
215 .setRoute(route);
Vince12e49462014-06-09 13:29:32 -0500216
Vince Lehman76c751c2014-11-18 17:36:38 -0600217 beginApplyUpdate(update, nullptr, nullptr);
Vince12e49462014-06-09 13:29:32 -0500218}
219
220shared_ptr<RibEntry>
221Rib::findParent(const Name& prefix) const
222{
Vince Lehman76c751c2014-11-18 17:36:38 -0600223 for (int i = prefix.size() - 1; i >= 0; i--) {
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400224 auto it = m_rib.find(prefix.getPrefix(i));
Vince Lehman76c751c2014-11-18 17:36:38 -0600225 if (it != m_rib.end()) {
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400226 return it->second;
Vince12e49462014-06-09 13:29:32 -0500227 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600228 }
Vince12e49462014-06-09 13:29:32 -0500229
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400230 return nullptr;
Vince12e49462014-06-09 13:29:32 -0500231}
232
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400233std::list<shared_ptr<RibEntry>>
Vince12e49462014-06-09 13:29:32 -0500234Rib::findDescendants(const Name& prefix) const
235{
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400236 std::list<shared_ptr<RibEntry>> children;
Vince12e49462014-06-09 13:29:32 -0500237
238 RibTable::const_iterator it = m_rib.find(prefix);
Vince Lehman76c751c2014-11-18 17:36:38 -0600239 if (it != m_rib.end()) {
240 ++it;
241 for (; it != m_rib.end(); ++it) {
242 if (prefix.isPrefixOf(it->first)) {
243 children.push_back((it->second));
244 }
245 else {
246 break;
247 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700248 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600249 }
250
251 return children;
252}
253
254std::list<shared_ptr<RibEntry>>
255Rib::findDescendantsForNonInsertedName(const Name& prefix) const
256{
257 std::list<shared_ptr<RibEntry>> children;
258
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400259 for (const auto& pair : m_rib) {
Vince Lehman76c751c2014-11-18 17:36:38 -0600260 if (prefix.isPrefixOf(pair.first)) {
261 children.push_back(pair.second);
262 }
263 }
Vince12e49462014-06-09 13:29:32 -0500264
265 return children;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700266}
267
Vince12e49462014-06-09 13:29:32 -0500268Rib::RibTable::iterator
269Rib::eraseEntry(RibTable::iterator it)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700270{
Vince12e49462014-06-09 13:29:32 -0500271 // Entry does not exist
Vince Lehman76c751c2014-11-18 17:36:38 -0600272 if (it == m_rib.end()) {
273 return m_rib.end();
274 }
Vince12e49462014-06-09 13:29:32 -0500275
276 shared_ptr<RibEntry> entry(it->second);
277
278 shared_ptr<RibEntry> parent = entry->getParent();
279
280 // Remove self from parent's children
Vince Lehman76c751c2014-11-18 17:36:38 -0600281 if (parent != nullptr) {
282 parent->removeChild(entry);
283 }
284
285 for (auto childIt = entry->getChildren().begin(); childIt != entry->getChildren().end(); ) {
286 shared_ptr<RibEntry> child = *childIt;
287
288 // Advance iterator so it is not invalidated by removal
289 ++childIt;
290
291 // Remove children from self
292 entry->removeChild(child);
293
294 // Update parent's children
295 if (parent != nullptr) {
296 parent->addChild(child);
Vince12e49462014-06-09 13:29:32 -0500297 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600298 }
Vince12e49462014-06-09 13:29:32 -0500299
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400300 auto nextIt = m_rib.erase(it);
Vince12e49462014-06-09 13:29:32 -0500301
Yanbiao Lic17de832014-11-21 17:51:45 -0800302 // do something after erasing an entry.
303 afterEraseEntry(entry->getName());
304
Vince12e49462014-06-09 13:29:32 -0500305 return nextIt;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700306}
307
Vince Lehman218be0a2015-01-15 17:25:20 -0600308Rib::RouteSet
309Rib::getAncestorRoutes(const RibEntry& entry) const
Vince Lehman4387e782014-06-19 16:57:45 -0500310{
Vince Lehman218be0a2015-01-15 17:25:20 -0600311 RouteSet ancestorRoutes(&sortRoutes);
Vince Lehman4387e782014-06-19 16:57:45 -0500312
313 shared_ptr<RibEntry> parent = entry.getParent();
314
Vince Lehman76c751c2014-11-18 17:36:38 -0600315 while (parent != nullptr) {
316 for (const Route& route : parent->getRoutes()) {
317 if (route.isChildInherit()) {
318 ancestorRoutes.insert(route);
Vince Lehman4387e782014-06-19 16:57:45 -0500319 }
Vince Lehman4387e782014-06-19 16:57:45 -0500320 }
321
Vince Lehman76c751c2014-11-18 17:36:38 -0600322 if (parent->hasCapture()) {
323 break;
Vince Lehman4387e782014-06-19 16:57:45 -0500324 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600325
326 parent = parent->getParent();
327 }
328
329 return ancestorRoutes;
330}
331
332Rib::RouteSet
333Rib::getAncestorRoutes(const Name& name) const
334{
335 RouteSet ancestorRoutes(&sortRoutes);
336
337 shared_ptr<RibEntry> parent = findParent(name);
338
339 while (parent != nullptr) {
340 for (const Route& route : parent->getRoutes()) {
341 if (route.isChildInherit()) {
342 ancestorRoutes.insert(route);
343 }
344 }
345
346 if (parent->hasCapture()) {
347 break;
348 }
349
350 parent = parent->getParent();
351 }
352
353 return ancestorRoutes;
354}
355
356void
357Rib::beginApplyUpdate(const RibUpdate& update,
358 const Rib::UpdateSuccessCallback& onSuccess,
359 const Rib::UpdateFailureCallback& onFailure)
360{
361 BOOST_ASSERT(m_fibUpdater != nullptr);
362
363 addUpdateToQueue(update, onSuccess, onFailure);
364
365 sendBatchFromQueue();
366}
367
368void
369Rib::beginRemoveFace(uint64_t faceId)
370{
Junxiao Shi17a70012019-06-25 10:50:32 +0000371 auto range = m_faceEntries.equal_range(faceId);
372 for (auto it = range.first; it != range.second; ++it) {
373 enqueueRemoveFace(*it->second, faceId);
374 }
375 sendBatchFromQueue();
376}
377
378void
379Rib::beginRemoveFailedFaces(const std::set<uint64_t>& activeFaceIds)
380{
381 for (auto it = m_faceEntries.begin(); it != m_faceEntries.end(); ++it) {
382 if (activeFaceIds.count(it->first) > 0) {
383 continue;
384 }
385 enqueueRemoveFace(*it->second, it->first);
386 }
387 sendBatchFromQueue();
388}
389
390void
391Rib::enqueueRemoveFace(const RibEntry& entry, uint64_t faceId)
392{
393 for (const Route& route : entry) {
394 if (route.faceId != faceId) {
395 continue;
396 }
397
Vince Lehman76c751c2014-11-18 17:36:38 -0600398 RibUpdate update;
399 update.setAction(RibUpdate::REMOVE_FACE)
Junxiao Shi17a70012019-06-25 10:50:32 +0000400 .setName(entry.getName())
401 .setRoute(route);
Vince Lehman76c751c2014-11-18 17:36:38 -0600402 addUpdateToQueue(update, nullptr, nullptr);
403 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600404}
405
406void
407Rib::addUpdateToQueue(const RibUpdate& update,
408 const Rib::UpdateSuccessCallback& onSuccess,
409 const Rib::UpdateFailureCallback& onFailure)
410{
411 RibUpdateBatch batch(update.getRoute().faceId);
412 batch.add(update);
413
414 UpdateQueueItem item{batch, onSuccess, onFailure};
415 m_updateBatches.push_back(std::move(item));
416}
417
418void
419Rib::sendBatchFromQueue()
420{
421 if (m_updateBatches.empty() || m_isUpdateInProgress) {
422 return;
423 }
424
425 m_isUpdateInProgress = true;
426
427 UpdateQueueItem item = std::move(m_updateBatches.front());
428 m_updateBatches.pop_front();
429
430 RibUpdateBatch& batch = item.batch;
431
432 // Until task #1698, each RibUpdateBatch contains exactly one RIB update
433 BOOST_ASSERT(batch.size() == 1);
434
Junxiao Shi52009042018-09-10 12:33:56 +0000435 auto fibSuccessCb = bind(&Rib::onFibUpdateSuccess, this, batch, _1, item.managerSuccessCallback);
436 auto fibFailureCb = bind(&Rib::onFibUpdateFailure, this, item.managerFailureCallback, _1, _2);
Vince Lehman76c751c2014-11-18 17:36:38 -0600437
Junxiao Shi52009042018-09-10 12:33:56 +0000438#ifdef WITH_TESTS
439 if (mockFibResponse != nullptr) {
440 m_fibUpdater->computeAndSendFibUpdates(batch, bind([]{}), bind([]{}));
441 bool shouldFibSucceed = mockFibResponse(batch);
442 if (wantMockFibResponseOnce) {
443 mockFibResponse = nullptr;
444 }
445 if (shouldFibSucceed) {
446 fibSuccessCb(m_fibUpdater->m_inheritedRoutes);
447 }
448 else {
449 fibFailureCb(504, "mocked failure");
450 }
451 return;
Vince Lehman76c751c2014-11-18 17:36:38 -0600452 }
Junxiao Shi52009042018-09-10 12:33:56 +0000453#endif
454
455 m_fibUpdater->computeAndSendFibUpdates(batch, fibSuccessCb, fibFailureCb);
Vince Lehman76c751c2014-11-18 17:36:38 -0600456}
457
458void
459Rib::onFibUpdateSuccess(const RibUpdateBatch& batch,
460 const RibUpdateList& inheritedRoutes,
461 const Rib::UpdateSuccessCallback& onSuccess)
462{
463 for (const RibUpdate& update : batch) {
464 switch (update.getAction()) {
465 case RibUpdate::REGISTER:
466 insert(update.getName(), update.getRoute());
467 break;
468 case RibUpdate::UNREGISTER:
469 case RibUpdate::REMOVE_FACE:
470 erase(update.getName(), update.getRoute());
471 break;
472 }
473 }
474
475 // Add and remove precalculated inherited routes to RibEntries
476 modifyInheritedRoutes(inheritedRoutes);
477
478 m_isUpdateInProgress = false;
479
480 if (onSuccess != nullptr) {
481 onSuccess();
482 }
483
484 // Try to advance the batch queue
485 sendBatchFromQueue();
486}
487
488void
489Rib::onFibUpdateFailure(const Rib::UpdateFailureCallback& onFailure,
490 uint32_t code, const std::string& error)
491{
492 m_isUpdateInProgress = false;
493
494 if (onFailure != nullptr) {
495 onFailure(code, error);
496 }
497
498 // Try to advance the batch queue
499 sendBatchFromQueue();
500}
501
502void
503Rib::modifyInheritedRoutes(const RibUpdateList& inheritedRoutes)
504{
505 for (const RibUpdate& update : inheritedRoutes) {
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400506 auto ribIt = m_rib.find(update.getName());
Vince Lehman76c751c2014-11-18 17:36:38 -0600507 BOOST_ASSERT(ribIt != m_rib.end());
508 shared_ptr<RibEntry> entry(ribIt->second);
509
510 switch (update.getAction()) {
511 case RibUpdate::REGISTER:
512 entry->addInheritedRoute(update.getRoute());
513 break;
514 case RibUpdate::UNREGISTER:
515 entry->removeInheritedRoute(update.getRoute());
516 break;
517 case RibUpdate::REMOVE_FACE:
518 break;
519 }
520 }
521}
522
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700523std::ostream&
Vince12e49462014-06-09 13:29:32 -0500524operator<<(std::ostream& os, const Rib& rib)
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700525{
Vince Lehman76c751c2014-11-18 17:36:38 -0600526 for (const auto& item : rib) {
Weiwei Liuaaa58a62016-11-28 23:15:15 -0700527 os << *item.second << "\n";
Vince Lehman76c751c2014-11-18 17:36:38 -0600528 }
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700529
530 return os;
531}
532
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700533} // namespace rib
534} // namespace nfd