rib: turn RibUpdate into an aggregate
And move it together with RibUpdateList and RibUpdateBatch.
Also remove a few unused functions from RibEntry.
Change-Id: Id4f79fda27d3bffb8411e2a95c24154e2cb80c4f
diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp
index d9331e5..41f9925 100644
--- a/daemon/mgmt/rib-manager.cpp
+++ b/daemon/mgmt/rib-manager.cpp
@@ -40,7 +40,6 @@
namespace nfd {
-using rib::RibUpdate;
using rib::Route;
NFD_LOG_INIT(RibManager);
@@ -156,11 +155,7 @@
NFD_LOG_TRACE("Scheduled unregistration at: " << *route.expires);
}
- RibUpdate update;
- update.setAction(RibUpdate::REGISTER)
- .setName(name)
- .setRoute(route);
- beginRibUpdate(update, done);
+ beginRibUpdate({rib::RibUpdate::REGISTER, name, route}, done);
}
void
@@ -170,15 +165,11 @@
NFD_LOG_INFO("Removing route " << name << " nexthop=" << route.faceId <<
" origin=" << route.origin);
- RibUpdate update;
- update.setAction(RibUpdate::UNREGISTER)
- .setName(name)
- .setRoute(route);
- beginRibUpdate(update, done);
+ beginRibUpdate({rib::RibUpdate::UNREGISTER, name, route}, done);
}
void
-RibManager::beginRibUpdate(const RibUpdate& update,
+RibManager::beginRibUpdate(const rib::RibUpdate& update,
const std::function<void(RibUpdateResult)>& done)
{
m_rib.beginApplyUpdate(update,
diff --git a/daemon/mgmt/rib-manager.hpp b/daemon/mgmt/rib-manager.hpp
index 87de627..d6b6ebe 100644
--- a/daemon/mgmt/rib-manager.hpp
+++ b/daemon/mgmt/rib-manager.hpp
@@ -27,7 +27,6 @@
#define NFD_DAEMON_MGMT_RIB_MANAGER_HPP
#include "manager-base.hpp"
-#include "rib/route.hpp"
#include <ndn-cxx/mgmt/nfd/controller.hpp>
#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
@@ -39,8 +38,9 @@
namespace nfd {
namespace rib {
+class Route;
class Rib;
-class RibUpdate;
+struct RibUpdate;
} // namespace rib
/**
diff --git a/daemon/rib/fib-updater.cpp b/daemon/rib/fib-updater.cpp
index 0b8fc0e..8d3b818 100644
--- a/daemon/rib/fib-updater.cpp
+++ b/daemon/rib/fib-updater.cpp
@@ -68,7 +68,7 @@
// Compute updates and add to m_fibUpdates
for (const RibUpdate& update : batch) {
- switch (update.getAction()) {
+ switch (update.action) {
case RibUpdate::REGISTER:
computeUpdatesForRegistration(update);
break;
@@ -88,42 +88,38 @@
void
FibUpdater::computeUpdatesForRegistration(const RibUpdate& update)
{
- const Name& prefix = update.getName();
- const Route& route = update.getRoute();
-
- auto it = m_rib.find(prefix);
+ auto it = m_rib.find(update.name);
// Name prefix exists
if (it != m_rib.end()) {
shared_ptr<const RibEntry> entry(it->second);
-
- auto existingRoute = entry->findRoute(route);
+ auto existingRoute = entry->findRoute(update.route);
// Route will be new
if (existingRoute == entry->end()) {
// Will the new route change the namespace's capture flag?
- bool willCaptureBeTurnedOn = (entry->hasCapture() == false && route.isRibCapture());
+ bool willCaptureBeTurnedOn = (!entry->hasCapture() && update.route.isRibCapture());
- createFibUpdatesForNewRoute(*entry, route, willCaptureBeTurnedOn);
+ createFibUpdatesForNewRoute(*entry, update.route, willCaptureBeTurnedOn);
}
else {
// Route already exists
RibEntry entryCopy = *entry;
- Route& routeToUpdate = *entryCopy.findRoute(route);
- routeToUpdate.flags = route.flags;
- routeToUpdate.cost = route.cost;
- routeToUpdate.expires = route.expires;
+ Route& routeToUpdate = *entryCopy.findRoute(update.route);
+ routeToUpdate.flags = update.route.flags;
+ routeToUpdate.cost = update.route.cost;
+ routeToUpdate.expires = update.route.expires;
- createFibUpdatesForUpdatedRoute(entryCopy, route, *existingRoute);
+ createFibUpdatesForUpdatedRoute(entryCopy, update.route, *existingRoute);
}
}
else {
// New name in RIB
// Find prefix's parent
- shared_ptr<RibEntry> parent = m_rib.findParent(prefix);
+ shared_ptr<RibEntry> parent = m_rib.findParent(update.name);
- Rib::RibEntryList descendants = m_rib.findDescendantsForNonInsertedName(prefix);
+ Rib::RibEntryList descendants = m_rib.findDescendantsForNonInsertedName(update.name);
Rib::RibEntryList children;
for (const auto& descendant : descendants) {
@@ -134,44 +130,40 @@
}
}
- createFibUpdatesForNewRibEntry(prefix, route, children);
+ createFibUpdatesForNewRibEntry(update.name, update.route, children);
}
}
void
FibUpdater::computeUpdatesForUnregistration(const RibUpdate& update)
{
- const Name& prefix = update.getName();
- const Route& route = update.getRoute();
-
- auto ribIt = m_rib.find(prefix);
+ auto ribIt = m_rib.find(update.name);
// Name prefix exists
if (ribIt != m_rib.end()) {
shared_ptr<const RibEntry> entry(ribIt->second);
const bool hadCapture = entry->hasCapture();
- auto existing = entry->findRoute(route);
+ auto existing = entry->findRoute(update.route);
if (existing != entry->end()) {
RibEntry temp = *entry;
// Erase route in temp entry
- temp.eraseRoute(route);
+ temp.eraseRoute(update.route);
- const bool captureWasTurnedOff = (hadCapture && !temp.hasCapture());
-
+ bool captureWasTurnedOff = (hadCapture && !temp.hasCapture());
createFibUpdatesForErasedRoute(temp, *existing, captureWasTurnedOff);
// The RibEntry still has the face ID; need to update FIB
// with lowest cost for the same face instead of removing the face from the FIB
- const Route* next = entry->getRouteWithSecondLowestCostByFaceId(route.faceId);
+ const Route* next = entry->getRouteWithSecondLowestCostByFaceId(update.route.faceId);
if (next != nullptr) {
createFibUpdatesForNewRoute(temp, *next, false);
}
// The RibEntry will be empty after this removal
- if (entry->getNRoutes() == 1) {
+ if (entry->getRoutes().size() == 1) {
createFibUpdatesForErasedRibEntry(*entry);
}
}
@@ -562,7 +554,7 @@
// If capture is turned off for the route and another route is installed in the RibEntry,
// add ancestors to self
Rib::RouteSet routesToAdd;
- if (captureWasTurnedOff && entry.getNRoutes() != 0) {
+ if (captureWasTurnedOff && !entry.empty()) {
// Look for an ancestors that were blocked previously
routesToAdd = m_rib.getAncestorRoutes(entry);
@@ -589,7 +581,7 @@
// If capture is turned off for the route and another route is installed in the RibEntry,
// add ancestors to self
Rib::RouteSet routesToAdd;
- if (captureWasTurnedOff && entry.getNRoutes() != 0) {
+ if (captureWasTurnedOff && !entry.empty()) {
// Look for an ancestors that were blocked previously
routesToAdd = m_rib.getAncestorRoutes(entry);
@@ -604,11 +596,10 @@
Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
// If the current entry has capture set or is pending removal, don't add inherited route
- if (!entry.hasCapture() && entry.getNRoutes() != 0) {
+ if (!entry.hasCapture() && !entry.empty()) {
// If there is an ancestor route which is the same as the erased route, add that route
// to the current entry
auto it = ancestorRoutes.find(route);
-
if (it != ancestorRoutes.end()) {
addInheritedRoute(entry.getName(), *it);
addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), it->faceId, it->cost));
@@ -684,23 +675,13 @@
void
FibUpdater::addInheritedRoute(const Name& name, const Route& route)
{
- RibUpdate update;
- update.setAction(RibUpdate::REGISTER)
- .setName(name)
- .setRoute(route);
-
- m_inheritedRoutes.push_back(update);
+ m_inheritedRoutes.push_back({RibUpdate::REGISTER, name, route});
}
void
FibUpdater::removeInheritedRoute(const Name& name, const Route& route)
{
- RibUpdate update;
- update.setAction(RibUpdate::UNREGISTER)
- .setName(name)
- .setRoute(route);
-
- m_inheritedRoutes.push_back(update);
+ m_inheritedRoutes.push_back({RibUpdate::UNREGISTER, name, route});
}
} // namespace nfd::rib
diff --git a/daemon/rib/rib-entry.cpp b/daemon/rib/rib-entry.cpp
index 1df227e..29c9eb7 100644
--- a/daemon/rib/rib-entry.cpp
+++ b/daemon/rib/rib-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -72,35 +72,20 @@
void
RibEntry::eraseRoute(const Route& route)
{
- auto it = findRoute(route);
- eraseRoute(it);
-}
-
-bool
-RibEntry::hasRoute(const Route& route)
-{
- auto it = findRoute(route);
- return it != end();
+ eraseRoute(findRoute(route));
}
bool
RibEntry::hasFaceId(uint64_t faceId) const
{
- auto it = std::find_if(begin(), end(), [faceId] (const auto& r) { return r.faceId == faceId; });
- return it != end();
-}
-
-size_t
-RibEntry::getNRoutes() const
-{
- return m_routes.size();
+ return std::find_if(begin(), end(), [=] (const auto& r) { return r.faceId == faceId; }) != end();
}
void
RibEntry::addChild(shared_ptr<RibEntry> child)
{
BOOST_ASSERT(!child->getParent());
- child->setParent(this->shared_from_this());
+ child->m_parent = shared_from_this();
m_children.push_back(std::move(child));
}
@@ -108,7 +93,7 @@
RibEntry::removeChild(shared_ptr<RibEntry> child)
{
BOOST_ASSERT(child->getParent().get() == this);
- child->setParent(nullptr);
+ child->m_parent = nullptr;
m_children.remove(child);
}
@@ -156,12 +141,6 @@
}
bool
-RibEntry::hasCapture() const
-{
- return m_nRoutesWithCaptureSet > 0;
-}
-
-bool
RibEntry::hasChildInheritOnFaceId(uint64_t faceId) const
{
for (const Route& route : m_routes) {
diff --git a/daemon/rib/rib-entry.hpp b/daemon/rib/rib-entry.hpp
index 6fbd198..6ec8b65 100644
--- a/daemon/rib/rib-entry.hpp
+++ b/daemon/rib/rib-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -42,17 +42,29 @@
using iterator = RouteList::iterator;
using const_iterator = RouteList::const_iterator;
- void
- setName(const Name& prefix);
-
const Name&
- getName() const;
+ getName() const noexcept
+ {
+ return m_name;
+ }
+
+ void
+ setName(const Name& prefix)
+ {
+ m_name = prefix;
+ }
shared_ptr<RibEntry>
- getParent() const;
+ getParent() const
+ {
+ return m_parent;
+ }
- bool
- hasParent() const;
+ const std::list<shared_ptr<RibEntry>>&
+ getChildren() const noexcept
+ {
+ return m_children;
+ }
void
addChild(shared_ptr<RibEntry> child);
@@ -60,12 +72,6 @@
void
removeChild(shared_ptr<RibEntry> child);
- const std::list<shared_ptr<RibEntry>>&
- getChildren() const;
-
- bool
- hasChildren() const;
-
/** \brief Inserts a new route into the entry's route list.
*
* If another route already exists with the same faceId and origin,
@@ -95,21 +101,12 @@
bool
hasFaceId(uint64_t faceId) const;
- const RouteList&
- getRoutes() const;
-
- size_t
- getNRoutes() const;
-
iterator
findRoute(const Route& route);
const_iterator
findRoute(const Route& route) const;
- bool
- hasRoute(const Route& route);
-
void
addInheritedRoute(const Route& route);
@@ -122,7 +119,10 @@
* The inherited routes returned represent inherited routes this namespace has in the FIB.
*/
const RouteList&
- getInheritedRoutes() const;
+ getInheritedRoutes() const noexcept
+ {
+ return m_inheritedRoutes;
+ }
/**
* \brief Finds an inherited route with a matching face ID.
@@ -140,7 +140,10 @@
hasInheritedRoute(const Route& route) const;
bool
- hasCapture() const;
+ hasCapture() const noexcept
+ {
+ return m_nRoutesWithCaptureSet > 0;
+ }
/** \brief Determines if the entry has an inherited route with the passed
* face ID and its child inherit flag set.
@@ -180,21 +183,41 @@
getPrefixAnnouncement(time::milliseconds minExpiration = 15_s,
time::milliseconds maxExpiration = 1_h) const;
- const_iterator
- begin() const;
+ const RouteList&
+ getRoutes() const noexcept
+ {
+ return m_routes;
+ }
+
+ bool
+ empty() const noexcept
+ {
+ return m_routes.empty();
+ }
const_iterator
- end() const;
+ begin() const noexcept
+ {
+ return m_routes.begin();
+ }
+
+ const_iterator
+ end() const noexcept
+ {
+ return m_routes.end();
+ }
iterator
- begin();
+ begin() noexcept
+ {
+ return m_routes.begin();
+ }
iterator
- end();
-
-private:
- void
- setParent(shared_ptr<RibEntry> parent);
+ end() noexcept
+ {
+ return m_routes.end();
+ }
private:
Name m_name;
@@ -212,72 +235,6 @@
uint64_t m_nRoutesWithCaptureSet = 0;
};
-inline void
-RibEntry::setName(const Name& prefix)
-{
- m_name = prefix;
-}
-
-inline const Name&
-RibEntry::getName() const
-{
- return m_name;
-}
-
-inline void
-RibEntry::setParent(shared_ptr<RibEntry> parent)
-{
- m_parent = std::move(parent);
-}
-
-inline shared_ptr<RibEntry>
-RibEntry::getParent() const
-{
- return m_parent;
-}
-
-inline const std::list<shared_ptr<RibEntry>>&
-RibEntry::getChildren() const
-{
- return m_children;
-}
-
-inline const RibEntry::RouteList&
-RibEntry::getRoutes() const
-{
- return m_routes;
-}
-
-inline const RibEntry::RouteList&
-RibEntry::getInheritedRoutes() const
-{
- return m_inheritedRoutes;
-}
-
-inline RibEntry::const_iterator
-RibEntry::begin() const
-{
- return m_routes.begin();
-}
-
-inline RibEntry::const_iterator
-RibEntry::end() const
-{
- return m_routes.end();
-}
-
-inline RibEntry::iterator
-RibEntry::begin()
-{
- return m_routes.begin();
-}
-
-inline RibEntry::iterator
-RibEntry::end()
-{
- return m_routes.end();
-}
-
std::ostream&
operator<<(std::ostream& os, const RibEntry& entry);
diff --git a/daemon/rib/rib-update-batch.cpp b/daemon/rib/rib-update-batch.cpp
index 12284f7..0444d8e 100644
--- a/daemon/rib/rib-update-batch.cpp
+++ b/daemon/rib/rib-update-batch.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,6 +27,26 @@
namespace nfd::rib {
+std::ostream&
+operator<<(std::ostream& os, RibUpdate::Action action)
+{
+ switch (action) {
+ case RibUpdate::REGISTER:
+ return os << "REGISTER";
+ case RibUpdate::UNREGISTER:
+ return os << "UNREGISTER";
+ case RibUpdate::REMOVE_FACE:
+ return os << "REMOVE_FACE";
+ }
+ return os;
+}
+
+std::ostream&
+operator<<(std::ostream& os, const RibUpdate& update)
+{
+ return os << "RibUpdate{" << update.action << ", " << update.name << ", " << update.route << "}";
+}
+
RibUpdateBatch::RibUpdateBatch(uint64_t faceId)
: m_faceId(faceId)
{
@@ -35,27 +55,8 @@
void
RibUpdateBatch::add(const RibUpdate& update)
{
- BOOST_ASSERT(m_faceId == update.getRoute().faceId);
-
+ BOOST_ASSERT(m_faceId == update.route.faceId);
m_updates.push_back(update);
}
-RibUpdateBatch::const_iterator
-RibUpdateBatch::begin() const
-{
- return m_updates.begin();
-}
-
-RibUpdateBatch::const_iterator
-RibUpdateBatch::end() const
-{
- return m_updates.end();
-}
-
-size_t
-RibUpdateBatch::size() const
-{
- return m_updates.size();
-}
-
} // namespace nfd::rib
diff --git a/daemon/rib/rib-update-batch.hpp b/daemon/rib/rib-update-batch.hpp
index a91cad3..4906387 100644
--- a/daemon/rib/rib-update-batch.hpp
+++ b/daemon/rib/rib-update-batch.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,12 +26,38 @@
#ifndef NFD_DAEMON_RIB_RIB_UPDATE_BATCH_HPP
#define NFD_DAEMON_RIB_RIB_UPDATE_BATCH_HPP
-#include "rib-update.hpp"
+#include "route.hpp"
#include <list>
namespace nfd::rib {
+/**
+ * \brief Represents a route that will be added to or removed from a namespace.
+ */
+struct RibUpdate
+{
+ enum Action {
+ REGISTER = 0,
+ UNREGISTER = 1,
+ /**
+ * \brief An update triggered by a face destruction notification
+ * \note indicates a Route needs to be removed after a face is destroyed
+ */
+ REMOVE_FACE = 2,
+ };
+
+ Action action;
+ Name name;
+ Route route;
+};
+
+std::ostream&
+operator<<(std::ostream& os, RibUpdate::Action action);
+
+std::ostream&
+operator<<(std::ostream& os, const RibUpdate& update);
+
using RibUpdateList = std::list<RibUpdate>;
/**
@@ -46,7 +72,7 @@
RibUpdateBatch(uint64_t faceId);
uint64_t
- getFaceId() const
+ getFaceId() const noexcept
{
return m_faceId;
}
@@ -55,13 +81,22 @@
add(const RibUpdate& update);
const_iterator
- begin() const;
+ begin() const noexcept
+ {
+ return m_updates.begin();
+ }
const_iterator
- end() const;
+ end() const noexcept
+ {
+ return m_updates.end();
+ }
size_t
- size() const;
+ size() const noexcept
+ {
+ return m_updates.size();
+ }
private:
uint64_t m_faceId;
diff --git a/daemon/rib/rib-update.cpp b/daemon/rib/rib-update.cpp
deleted file mode 100644
index 8fc5000..0000000
--- a/daemon/rib/rib-update.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2025, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "rib-update.hpp"
-
-namespace nfd::rib {
-
-std::ostream&
-operator<<(std::ostream& os, RibUpdate::Action action)
-{
- switch (action) {
- case RibUpdate::REGISTER:
- return os << "REGISTER";
- case RibUpdate::UNREGISTER:
- return os << "UNREGISTER";
- case RibUpdate::REMOVE_FACE:
- return os << "REMOVE_FACE";
- }
- return os;
-}
-
-std::ostream&
-operator<<(std::ostream& os, const RibUpdate& update)
-{
- return os << "RibUpdate{" << update.getAction()
- << ", " << update.getName()
- << ", " << update.getRoute()
- << "}";
-}
-
-} // namespace nfd::rib
diff --git a/daemon/rib/rib-update.hpp b/daemon/rib/rib-update.hpp
deleted file mode 100644
index 70bbe1e..0000000
--- a/daemon/rib/rib-update.hpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_DAEMON_RIB_RIB_UPDATE_HPP
-#define NFD_DAEMON_RIB_RIB_UPDATE_HPP
-
-#include "core/common.hpp"
-#include "route.hpp"
-
-namespace nfd::rib {
-
-/**
- * \brief Represents a route that will be added to or removed from a namespace
- * \note This type is copyable so that it can be stored in STL containers.
- */
-class RibUpdate
-{
-public:
- enum Action {
- REGISTER = 0,
- UNREGISTER = 1,
- /**
- * \brief An update triggered by a face destruction notification
- * \note indicates a Route needs to be removed after a face is destroyed
- */
- REMOVE_FACE = 2,
- };
-
- RibUpdate&
- setAction(Action action);
-
- Action
- getAction() const;
-
- RibUpdate&
- setName(const Name& name);
-
- const Name&
- getName() const;
-
- RibUpdate&
- setRoute(const Route& route);
-
- const Route&
- getRoute() const;
-
-private:
- Action m_action;
- Name m_name;
- Route m_route;
-};
-
-inline RibUpdate&
-RibUpdate::setAction(Action action)
-{
- m_action = action;
- return *this;
-}
-
-inline RibUpdate::Action
-RibUpdate::getAction() const
-{
- return m_action;
-}
-
-inline RibUpdate&
-RibUpdate::setName(const Name& name)
-{
- m_name = name;
- return *this;
-}
-
-inline const Name&
-RibUpdate::getName() const
-{
- return m_name;
-}
-
-inline RibUpdate&
-RibUpdate::setRoute(const Route& route)
-{
- m_route = route;
- return *this;
-}
-
-inline const Route&
-RibUpdate::getRoute() const
-{
- return m_route;
-}
-
-std::ostream&
-operator<<(std::ostream& os, RibUpdate::Action action);
-
-std::ostream&
-operator<<(std::ostream& os, const RibUpdate& update);
-
-} // namespace nfd::rib
-
-#endif // NFD_DAEMON_RIB_RIB_UPDATE_HPP
diff --git a/daemon/rib/rib.cpp b/daemon/rib/rib.cpp
index 7288c9a..c67d172 100644
--- a/daemon/rib/rib.cpp
+++ b/daemon/rib/rib.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -179,7 +179,7 @@
}
// If a RibEntry's route list is empty, remove it from the tree
- if (entry->getRoutes().empty()) {
+ if (entry->empty()) {
eraseEntry(ribIt);
}
}
@@ -189,13 +189,7 @@
Rib::onRouteExpiration(const Name& prefix, const Route& route)
{
NFD_LOG_DEBUG(route << " for " << prefix << " has expired");
-
- RibUpdate update;
- update.setAction(RibUpdate::UNREGISTER)
- .setName(prefix)
- .setRoute(route);
-
- beginApplyUpdate(update, nullptr, nullptr);
+ beginApplyUpdate({RibUpdate::UNREGISTER, prefix, route}, nullptr, nullptr);
}
shared_ptr<RibEntry>
@@ -370,12 +364,7 @@
if (route.faceId != faceId) {
continue;
}
-
- RibUpdate update;
- update.setAction(RibUpdate::REMOVE_FACE)
- .setName(entry.getName())
- .setRoute(route);
- addUpdateToQueue(update, nullptr, nullptr);
+ addUpdateToQueue({RibUpdate::REMOVE_FACE, entry.getName(), route}, nullptr, nullptr);
}
}
@@ -384,7 +373,7 @@
const Rib::UpdateSuccessCallback& onSuccess,
const Rib::UpdateFailureCallback& onFailure)
{
- RibUpdateBatch batch(update.getRoute().faceId);
+ RibUpdateBatch batch(update.route.faceId);
batch.add(update);
UpdateQueueItem item{batch, onSuccess, onFailure};
@@ -421,13 +410,13 @@
const Rib::UpdateSuccessCallback& onSuccess)
{
for (const RibUpdate& update : batch) {
- switch (update.getAction()) {
+ switch (update.action) {
case RibUpdate::REGISTER:
- insert(update.getName(), update.getRoute());
+ insert(update.name, update.route);
break;
case RibUpdate::UNREGISTER:
case RibUpdate::REMOVE_FACE:
- erase(update.getName(), update.getRoute());
+ erase(update.name, update.route);
break;
}
}
@@ -463,16 +452,16 @@
Rib::modifyInheritedRoutes(const RibUpdateList& inheritedRoutes)
{
for (const RibUpdate& update : inheritedRoutes) {
- auto ribIt = m_rib.find(update.getName());
+ auto ribIt = m_rib.find(update.name);
BOOST_ASSERT(ribIt != m_rib.end());
shared_ptr<RibEntry> entry(ribIt->second);
- switch (update.getAction()) {
+ switch (update.action) {
case RibUpdate::REGISTER:
- entry->addInheritedRoute(update.getRoute());
+ entry->addInheritedRoute(update.route);
break;
case RibUpdate::UNREGISTER:
- entry->removeInheritedRoute(update.getRoute());
+ entry->removeInheritedRoute(update.route);
break;
case RibUpdate::REMOVE_FACE:
break;
@@ -486,7 +475,6 @@
for (const auto& item : rib) {
os << *item.second << "\n";
}
-
return os;
}
diff --git a/tests/daemon/rib/fib-updates-common.hpp b/tests/daemon/rib/fib-updates-common.hpp
index 15e623f..4230114 100644
--- a/tests/daemon/rib/fib-updates-common.hpp
+++ b/tests/daemon/rib/fib-updates-common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -101,13 +101,6 @@
class FibUpdatesFixture : public GlobalIoFixture, public KeyChainFixture
{
public:
- FibUpdatesFixture()
- : face(g_io, m_keyChain)
- , controller(face, m_keyChain)
- , fibUpdater(rib, controller)
- {
- }
-
void
insertRoute(const Name& name, uint64_t faceId,
std::underlying_type_t<ndn::nfd::RouteOrigin> origin,
@@ -115,13 +108,7 @@
std::underlying_type_t<ndn::nfd::RouteFlags> flags)
{
auto route = createRoute(faceId, origin, cost, flags);
-
- rib::RibUpdate update;
- update.setAction(rib::RibUpdate::REGISTER)
- .setName(name)
- .setRoute(route);
-
- rib.beginApplyUpdate(update, nullptr, nullptr);
+ rib.beginApplyUpdate({rib::RibUpdate::REGISTER, name, route}, nullptr, nullptr);
pollIo();
}
@@ -130,13 +117,7 @@
std::underlying_type_t<ndn::nfd::RouteOrigin> origin)
{
auto route = createRoute(faceId, origin, 0, 0);
-
- rib::RibUpdate update;
- update.setAction(rib::RibUpdate::UNREGISTER)
- .setName(name)
- .setRoute(route);
-
- rib.beginApplyUpdate(update, nullptr, nullptr);
+ rib.beginApplyUpdate({rib::RibUpdate::UNREGISTER, name, route}, nullptr, nullptr);
pollIo();
}
@@ -167,11 +148,10 @@
}
public:
- ndn::DummyClientFace face;
- ndn::nfd::Controller controller;
-
+ ndn::DummyClientFace face{g_io, m_keyChain};
+ ndn::nfd::Controller controller{face, m_keyChain};
rib::Rib rib;
- MockFibUpdater fibUpdater;
+ MockFibUpdater fibUpdater{rib, controller};
};
} // namespace nfd::tests
diff --git a/tests/daemon/rib/rib-update.t.cpp b/tests/daemon/rib/rib-update-batch.t.cpp
similarity index 70%
rename from tests/daemon/rib/rib-update.t.cpp
rename to tests/daemon/rib/rib-update-batch.t.cpp
index 0941693..b2c8431 100644
--- a/tests/daemon/rib/rib-update.t.cpp
+++ b/tests/daemon/rib/rib-update-batch.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2024, Regents of the University of California,
+ * Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,7 +23,6 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "rib/rib-update.hpp"
#include "rib/rib-update-batch.hpp"
#include "tests/test-common.hpp"
@@ -34,48 +33,40 @@
using namespace nfd::rib;
BOOST_AUTO_TEST_SUITE(Rib)
-BOOST_AUTO_TEST_SUITE(TestRibUpdate)
+BOOST_AUTO_TEST_SUITE(TestRibUpdateBatch)
-BOOST_AUTO_TEST_CASE(Batch)
+BOOST_AUTO_TEST_CASE(AddAndIterate)
{
const uint64_t faceId = 1;
RibUpdateBatch batch(faceId);
Route routeRegister = createRoute(faceId, 128, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
- RibUpdate registerUpdate;
- registerUpdate.setAction(RibUpdate::REGISTER)
- .setName("/a")
- .setRoute(routeRegister);
-
+ RibUpdate registerUpdate{RibUpdate::REGISTER, "/a", routeRegister};
batch.add(registerUpdate);
BOOST_CHECK_EQUAL(batch.getFaceId(), faceId);
Route routeUnregister = createRoute(faceId, 0, 0, ndn::nfd::ROUTE_FLAG_CAPTURE);
- RibUpdate unregisterUpdate;
- unregisterUpdate.setAction(RibUpdate::UNREGISTER)
- .setName("/a/b")
- .setRoute(routeUnregister);
-
+ RibUpdate unregisterUpdate{RibUpdate::UNREGISTER, "/a/b", routeUnregister};
batch.add(unregisterUpdate);
BOOST_REQUIRE_EQUAL(batch.size(), 2);
auto it = batch.begin();
- BOOST_CHECK_EQUAL(it->getAction(), RibUpdate::REGISTER);
- BOOST_CHECK_EQUAL(it->getName(), "/a");
- BOOST_CHECK_EQUAL(it->getRoute(), routeRegister);
+ BOOST_CHECK_EQUAL(it->action, RibUpdate::REGISTER);
+ BOOST_CHECK_EQUAL(it->name, "/a");
+ BOOST_CHECK_EQUAL(it->route, routeRegister);
++it;
- BOOST_CHECK_EQUAL(it->getAction(), RibUpdate::UNREGISTER);
- BOOST_CHECK_EQUAL(it->getName(), "/a/b");
- BOOST_CHECK_EQUAL(it->getRoute(), routeUnregister);
+ BOOST_CHECK_EQUAL(it->action, RibUpdate::UNREGISTER);
+ BOOST_CHECK_EQUAL(it->name, "/a/b");
+ BOOST_CHECK_EQUAL(it->route, routeUnregister);
++it;
BOOST_CHECK(it == batch.end());
}
-BOOST_AUTO_TEST_SUITE_END() // TestRibUpdate
+BOOST_AUTO_TEST_SUITE_END() // TestRibUpdateBatch
BOOST_AUTO_TEST_SUITE_END() // Rib
} // namespace nfd::tests