29 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
41 RibEntry::RouteList::iterator
48 RibEntry::RouteList::const_iterator
55 std::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};
89 auto it = std::find_if(
begin(),
end(), [faceId] (
const auto& r) {
return r.faceId == faceId; });
96 return m_routes.size();
102 BOOST_ASSERT(!child->getParent());
103 child->setParent(this->shared_from_this());
104 m_children.push_back(std::move(child));
110 BOOST_ASSERT(child->getParent().get() ==
this);
111 child->setParent(
nullptr);
112 m_children.remove(child);
115 RibEntry::RouteList::iterator
118 if (route != m_routes.end()) {
119 if (route->flags & ndn::nfd::ROUTE_FLAG_CAPTURE) {
120 m_nRoutesWithCaptureSet--;
124 NFD_LOG_TRACE(
"Cancelling expiration event: " << route->getExpirationEvent());
125 route->cancelExpirationEvent();
127 return m_routes.erase(route);
130 return m_routes.end();
136 m_inheritedRoutes.push_back(route);
142 m_inheritedRoutes.remove_if([
id = route.
faceId] (
const auto& r) { return r.faceId == id; });
145 RibEntry::RouteList::const_iterator
148 return std::find_if(m_inheritedRoutes.begin(), m_inheritedRoutes.end(),
149 [
id = route.
faceId] (
const auto& r) { return r.faceId == id; });
161 return m_nRoutesWithCaptureSet > 0;
167 for (
const Route& route : m_routes) {
168 if (route.faceId == faceId && (route.flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)) {
179 const Route* candidate =
nullptr;
181 for (
const Route& route : m_routes) {
183 if (route.faceId == faceId) {
185 if (candidate ==
nullptr) {
188 else if (route.cost < candidate->
cost) {
201 std::vector<const Route*> matches;
204 for (
const Route& route : m_routes) {
205 if (route.faceId == faceId) {
206 matches.push_back(&route);
211 if (matches.size() < 2) {
216 std::nth_element(matches.begin(), matches.begin() + 1, matches.end(),
217 [] (
const Route* lhs,
const Route* rhs) { return lhs->cost < rhs->cost; });
219 return matches.at(1);
225 const Route* candidate =
nullptr;
227 for (
const Route& route : m_routes) {
229 if (route.faceId == faceId &&
230 (route.flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) == ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
233 if (candidate ==
nullptr) {
236 else if (route.cost < candidate->
cost) {
246 ndn::PrefixAnnouncement
248 time::milliseconds maxExpiration)
const
250 const Route* bestAnnRoute =
nullptr;
251 auto entryExpiry = time::steady_clock::time_point::min();
253 for (
const Route& route : *
this) {
255 entryExpiry = std::max(entryExpiry, *route.
expires);
257 if (bestAnnRoute ==
nullptr || *route.
expires > *bestAnnRoute->
expires) {
258 bestAnnRoute = &route;
263 entryExpiry = time::steady_clock::time_point::max();
267 if (bestAnnRoute !=
nullptr) {
271 ndn::PrefixAnnouncement ann;
272 ann.setAnnouncedName(m_name);
273 ann.setExpiration(std::clamp(
274 time::duration_cast<time::milliseconds>(entryExpiry - time::steady_clock::now()),
275 minExpiration, maxExpiration));
283 <<
" Name: " << entry.
getName() <<
"\n";
284 for (
const Route& route : entry) {
285 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)
const_iterator end() const
std::pair< RibEntry::iterator, bool > insertRoute(const Route &route)
Inserts a new route into the entry's route list.
size_t getNRoutes() const
const_iterator begin() const
void eraseRoute(const Route &route)
Erases a Route with the same FaceId and origin.
const Name & getName() const
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
bool hasRoute(const Route &route)
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...
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)