29#include <ndn-cxx/mgmt/nfd/control-command.hpp>
41RibEntry::RouteList::iterator
48RibEntry::RouteList::const_iterator
55std::pair<RibEntry::iterator, bool>
61 if (route.
flags & ndn::nfd::ROUTE_FLAG_CAPTURE) {
62 m_nRoutesWithCaptureSet++;
65 m_routes.push_back(route);
66 return {std::prev(m_routes.end()),
true};
81 return std::find_if(
begin(),
end(), [=] (
const auto& r) {
return r.faceId == faceId; }) !=
end();
87 BOOST_ASSERT(!child->getParent());
88 child->m_parent = shared_from_this();
89 m_children.push_back(std::move(child));
95 BOOST_ASSERT(child->getParent().get() ==
this);
96 child->m_parent =
nullptr;
97 m_children.remove(child);
100RibEntry::RouteList::iterator
103 if (route != m_routes.end()) {
104 if (route->flags & ndn::nfd::ROUTE_FLAG_CAPTURE) {
105 m_nRoutesWithCaptureSet--;
109 NFD_LOG_TRACE(
"Cancelling expiration event: " << route->getExpirationEvent());
110 route->cancelExpirationEvent();
112 return m_routes.erase(route);
115 return m_routes.end();
121 m_inheritedRoutes.push_back(route);
127 m_inheritedRoutes.remove_if([
id = route.
faceId] (
const auto& r) { return r.faceId == id; });
130RibEntry::RouteList::const_iterator
133 return std::find_if(m_inheritedRoutes.begin(), m_inheritedRoutes.end(),
134 [
id = route.
faceId] (
const auto& r) { return r.faceId == id; });
146 for (
const Route& route : m_routes) {
147 if (route.faceId == faceId && (route.flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)) {
158 const Route* candidate =
nullptr;
160 for (
const Route& route : m_routes) {
162 if (route.faceId == faceId) {
164 if (candidate ==
nullptr) {
167 else if (route.cost < candidate->
cost) {
180 std::vector<const Route*> matches;
183 for (
const Route& route : m_routes) {
184 if (route.faceId == faceId) {
185 matches.push_back(&route);
190 if (matches.size() < 2) {
195 std::nth_element(matches.begin(), matches.begin() + 1, matches.end(),
196 [] (
const Route* lhs,
const Route* rhs) { return lhs->cost < rhs->cost; });
198 return matches.at(1);
204 const Route* candidate =
nullptr;
206 for (
const Route& route : m_routes) {
208 if (route.faceId == faceId &&
209 (route.flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) == ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
212 if (candidate ==
nullptr) {
215 else if (route.cost < candidate->
cost) {
225ndn::PrefixAnnouncement
227 time::milliseconds maxExpiration)
const
229 const Route* bestAnnRoute =
nullptr;
230 auto entryExpiry = time::steady_clock::time_point::min();
232 for (
const Route& route : *
this) {
234 entryExpiry = std::max(entryExpiry, *route.expires);
235 if (route.announcement) {
236 if (bestAnnRoute ==
nullptr || *route.
expires > *bestAnnRoute->
expires) {
237 bestAnnRoute = &route;
242 entryExpiry = time::steady_clock::time_point::max();
246 if (bestAnnRoute !=
nullptr) {
250 ndn::PrefixAnnouncement ann;
251 ann.setAnnouncedName(m_name);
252 ann.setExpiration(std::clamp(
253 time::duration_cast<time::milliseconds>(entryExpiry - time::steady_clock::now()),
254 minExpiration, maxExpiration));
262 <<
" Name: " << entry.
getName() <<
"\n";
263 for (
const Route& route : entry) {
264 os <<
" " << route <<
"\n";
Represents a RIB entry, which contains one or more Routes with the same prefix.
RouteList::const_iterator findInheritedRoute(const Route &route) const
Finds an inherited route with a matching face ID.
const Route * getRouteWithLowestCostByFaceId(uint64_t faceId) const
Returns the route with the lowest cost that has the passed face ID.
iterator findRoute(const Route &route)
void addInheritedRoute(const Route &route)
void removeInheritedRoute(const Route &route)
std::pair< RibEntry::iterator, bool > insertRoute(const Route &route)
Inserts a new route into the entry's route list.
const_iterator end() const noexcept
void eraseRoute(const Route &route)
Erases a Route with the same FaceId and origin.
const Route * getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const
Returns the route with the lowest cost that has the passed face ID and its child inherit flag set.
void addChild(shared_ptr< RibEntry > child)
ndn::PrefixAnnouncement getPrefixAnnouncement(time::milliseconds minExpiration=15_s, time::milliseconds maxExpiration=1_h) const
Retrieve a prefix announcement suitable for readvertising this route.
void removeChild(shared_ptr< RibEntry > child)
const Route * getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const
bool hasFaceId(uint64_t faceId) const
const_iterator begin() const noexcept
bool hasChildInheritOnFaceId(uint64_t faceId) const
Determines if the entry has an inherited route with the passed face ID and its child inherit flag set...
const Name & getName() const noexcept
bool hasInheritedRoute(const Route &route) const
Determines if the entry has an inherited route with a matching face ID.
Represents a route for a name prefix.
ndn::nfd::RouteOrigin origin
std::underlying_type_t< ndn::nfd::RouteFlags > flags
std::optional< time::steady_clock::time_point > expires
std::optional< ndn::PrefixAnnouncement > announcement
The prefix announcement that caused the creation of this route.
#define NFD_LOG_INIT(name)
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
static bool compareFaceIdAndOrigin(const Route &lhs, const Route &rhs)