Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 4 | * 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. |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 10 | * |
| 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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "rib-entry.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/logger.hpp" |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 28 | |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 29 | #include <ndn-cxx/mgmt/nfd/control-command.hpp> |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::rib { |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 32 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 33 | NFD_LOG_INIT(RibEntry); |
| 34 | |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 35 | static bool |
| 36 | compareFaceIdAndOrigin(const Route& lhs, const Route& rhs) |
| 37 | { |
| 38 | return lhs.faceId == rhs.faceId && lhs.origin == rhs.origin; |
| 39 | } |
| 40 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 41 | RibEntry::RouteList::iterator |
| 42 | RibEntry::findRoute(const Route& route) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 43 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 44 | return std::find_if(begin(), end(), |
| 45 | [&] (const auto& r) { return compareFaceIdAndOrigin(r, route); }); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 48 | RibEntry::RouteList::const_iterator |
| 49 | RibEntry::findRoute(const Route& route) const |
| 50 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 51 | return std::find_if(begin(), end(), |
| 52 | [&] (const auto& r) { return compareFaceIdAndOrigin(r, route); }); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 53 | } |
| 54 | |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 55 | std::pair<RibEntry::iterator, bool> |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 56 | RibEntry::insertRoute(const Route& route) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 57 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 58 | auto it = findRoute(route); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 59 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 60 | if (it == end()) { |
| 61 | if (route.flags & ndn::nfd::ROUTE_FLAG_CAPTURE) { |
| 62 | m_nRoutesWithCaptureSet++; |
| 63 | } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 64 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 65 | m_routes.push_back(route); |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 66 | return {std::prev(m_routes.end()), true}; |
| 67 | } |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 68 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 69 | return {it, false}; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 72 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 73 | RibEntry::eraseRoute(const Route& route) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 74 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 75 | auto it = findRoute(route); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 76 | eraseRoute(it); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | bool |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 80 | RibEntry::hasRoute(const Route& route) |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 81 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 82 | auto it = findRoute(route); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 83 | return it != end(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | bool |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 87 | RibEntry::hasFaceId(uint64_t faceId) const |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 88 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 89 | auto it = std::find_if(begin(), end(), [faceId] (const auto& r) { return r.faceId == faceId; }); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 90 | return it != end(); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 93 | size_t |
| 94 | RibEntry::getNRoutes() const |
| 95 | { |
| 96 | return m_routes.size(); |
| 97 | } |
| 98 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 99 | void |
| 100 | RibEntry::addChild(shared_ptr<RibEntry> child) |
| 101 | { |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 102 | BOOST_ASSERT(!child->getParent()); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 103 | child->setParent(this->shared_from_this()); |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 104 | m_children.push_back(std::move(child)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void |
| 108 | RibEntry::removeChild(shared_ptr<RibEntry> child) |
| 109 | { |
| 110 | BOOST_ASSERT(child->getParent().get() == this); |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 111 | child->setParent(nullptr); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 112 | m_children.remove(child); |
| 113 | } |
| 114 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 115 | RibEntry::RouteList::iterator |
| 116 | RibEntry::eraseRoute(RouteList::iterator route) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 117 | { |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 118 | if (route != m_routes.end()) { |
| 119 | if (route->flags & ndn::nfd::ROUTE_FLAG_CAPTURE) { |
| 120 | m_nRoutesWithCaptureSet--; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 123 | // Cancel any scheduled event |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 124 | NFD_LOG_TRACE("Cancelling expiration event: " << route->getExpirationEvent()); |
| 125 | route->cancelExpirationEvent(); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 126 | |
| 127 | return m_routes.erase(route); |
| 128 | } |
| 129 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 130 | return m_routes.end(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 134 | RibEntry::addInheritedRoute(const Route& route) |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 135 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 136 | m_inheritedRoutes.push_back(route); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 140 | RibEntry::removeInheritedRoute(const Route& route) |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 141 | { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 142 | m_inheritedRoutes.remove_if([id = route.faceId] (const auto& r) { return r.faceId == id; }); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 145 | RibEntry::RouteList::const_iterator |
| 146 | RibEntry::findInheritedRoute(const Route& route) const |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 147 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 148 | return std::find_if(m_inheritedRoutes.begin(), m_inheritedRoutes.end(), |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 149 | [id = route.faceId] (const auto& r) { return r.faceId == id; }); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | bool |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 153 | RibEntry::hasInheritedRoute(const Route& route) const |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 154 | { |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 155 | return findInheritedRoute(route) != m_inheritedRoutes.end(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | bool |
| 159 | RibEntry::hasCapture() const |
| 160 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 161 | return m_nRoutesWithCaptureSet > 0; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | bool |
| 165 | RibEntry::hasChildInheritOnFaceId(uint64_t faceId) const |
| 166 | { |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 167 | for (const Route& route : m_routes) { |
| 168 | if (route.faceId == faceId && (route.flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)) { |
| 169 | return true; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 170 | } |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 171 | } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 172 | |
| 173 | return false; |
| 174 | } |
| 175 | |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 176 | const Route* |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 177 | RibEntry::getRouteWithLowestCostByFaceId(uint64_t faceId) const |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 178 | { |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 179 | const Route* candidate = nullptr; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 180 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 181 | for (const Route& route : m_routes) { |
| 182 | // Matching face ID |
| 183 | if (route.faceId == faceId) { |
| 184 | // If this is the first route with this Face ID found |
| 185 | if (candidate == nullptr) { |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 186 | candidate = &route; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 187 | } |
| 188 | else if (route.cost < candidate->cost) { |
| 189 | // Found a route with a lower cost |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 190 | candidate = &route; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 191 | } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 192 | } |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 193 | } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 194 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 195 | return candidate; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 198 | const Route* |
| 199 | RibEntry::getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const |
| 200 | { |
Vince Lehman | 4310d50 | 2016-03-04 11:58:59 -0600 | [diff] [blame] | 201 | std::vector<const Route*> matches; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 202 | |
| 203 | // Copy routes which have faceId |
Vince Lehman | 4310d50 | 2016-03-04 11:58:59 -0600 | [diff] [blame] | 204 | for (const Route& route : m_routes) { |
| 205 | if (route.faceId == faceId) { |
| 206 | matches.push_back(&route); |
| 207 | } |
| 208 | } |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 209 | |
Vince Lehman | 4310d50 | 2016-03-04 11:58:59 -0600 | [diff] [blame] | 210 | // If there are less than 2 routes, there is no second lowest |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 211 | if (matches.size() < 2) { |
| 212 | return nullptr; |
| 213 | } |
| 214 | |
| 215 | // Get second lowest cost |
| 216 | std::nth_element(matches.begin(), matches.begin() + 1, matches.end(), |
Vince Lehman | 4310d50 | 2016-03-04 11:58:59 -0600 | [diff] [blame] | 217 | [] (const Route* lhs, const Route* rhs) { return lhs->cost < rhs->cost; }); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 218 | |
Vince Lehman | 4310d50 | 2016-03-04 11:58:59 -0600 | [diff] [blame] | 219 | return matches.at(1); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 220 | } |
| 221 | |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 222 | const Route* |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 223 | RibEntry::getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 224 | { |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 225 | const Route* candidate = nullptr; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 226 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 227 | for (const Route& route : m_routes) { |
| 228 | // Correct face ID and Child Inherit flag set |
| 229 | if (route.faceId == faceId && |
| 230 | (route.flags & ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) == ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 231 | { |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 232 | // If this is the first route with this Face ID found |
| 233 | if (candidate == nullptr) { |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 234 | candidate = &route; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 235 | } |
| 236 | else if (route.cost < candidate->cost) { |
| 237 | // Found a route with a lower cost |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 238 | candidate = &route; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 239 | } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 240 | } |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 241 | } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 242 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 243 | return candidate; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 244 | } |
| 245 | |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 246 | ndn::PrefixAnnouncement |
| 247 | RibEntry::getPrefixAnnouncement(time::milliseconds minExpiration, |
| 248 | time::milliseconds maxExpiration) const |
| 249 | { |
| 250 | const Route* bestAnnRoute = nullptr; |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 251 | auto entryExpiry = time::steady_clock::time_point::min(); |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 252 | |
| 253 | for (const Route& route : *this) { |
| 254 | if (route.expires) { |
| 255 | entryExpiry = std::max(entryExpiry, *route.expires); |
| 256 | if (route.announcement) { |
| 257 | if (bestAnnRoute == nullptr || *route.expires > *bestAnnRoute->expires) { |
| 258 | bestAnnRoute = &route; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | else { |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 263 | entryExpiry = time::steady_clock::time_point::max(); |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | if (bestAnnRoute != nullptr) { |
| 268 | return *bestAnnRoute->announcement; |
| 269 | } |
| 270 | |
| 271 | ndn::PrefixAnnouncement ann; |
| 272 | ann.setAnnouncedName(m_name); |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 273 | ann.setExpiration(std::clamp( |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 274 | time::duration_cast<time::milliseconds>(entryExpiry - time::steady_clock::now()), |
| 275 | minExpiration, maxExpiration)); |
| 276 | return ann; |
| 277 | } |
| 278 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 279 | std::ostream& |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 280 | operator<<(std::ostream& os, const RibEntry& entry) |
| 281 | { |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 282 | os << "RibEntry {\n" |
| 283 | << " Name: " << entry.getName() << "\n"; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 284 | for (const Route& route : entry) { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 285 | os << " " << route << "\n"; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 286 | } |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 287 | return os << "}"; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 290 | } // namespace nfd::rib |