NFD: Named Data Networking Forwarding Daemon 24.07-28-gdcc0e6e0
Loading...
Searching...
No Matches
route.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2025, Regents of the University of California,
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.
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 "route.hpp"
27
28#include <ndn-cxx/util/string-helper.hpp>
29
30namespace nfd::rib {
31
32Route::Route() = default;
33
34static time::steady_clock::time_point
35computeExpiration(const ndn::PrefixAnnouncement& ann)
36{
37 auto validityEnd = time::steady_clock::duration::max();
38 const auto& validityPeriod = ann.getValidityPeriod();
39 if (validityPeriod) {
40 auto now = time::system_clock::now();
41 if (!validityPeriod->isValid(now)) {
42 validityEnd = time::steady_clock::duration::zero();
43 }
44 else {
45 validityEnd = validityPeriod->getPeriod().second - now;
46 }
47 }
48 return time::steady_clock::now() +
49 std::min(validityEnd, time::duration_cast<time::steady_clock::duration>(ann.getExpiration()));
50}
51
52Route::Route(const ndn::PrefixAnnouncement& ann, uint64_t faceId)
53 : faceId(faceId)
54 , origin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN)
55 , cost(PA_ROUTE_COST)
56 , flags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
57 , expires(computeExpiration(ann))
58 , announcement(ann)
59 , annExpires(*expires)
60{
61}
62
63std::ostream&
64operator<<(std::ostream& os, const Route& route)
65{
66 os << "Route{"
67 << "face: " << route.faceId
68 << ", origin: " << route.origin
69 << ", cost: " << route.cost
70 << ", flags: " << ndn::AsHex{route.flags};
71
72 if (route.expires) {
73 os << ", expires in: " << time::duration_cast<time::milliseconds>(*route.expires - time::steady_clock::now());
74 }
75 else {
76 os << ", expires: never";
77 }
78
79 if (route.announcement) {
80 os << ", announcement: (" << *route.announcement << ')';
81 }
82
83 return os << '}';
84}
85
86} // namespace nfd::rib
Represents a route for a name prefix.
Definition route.hpp:44
ndn::nfd::RouteOrigin origin
Definition route.hpp:97
uint64_t cost
Definition route.hpp:98
Route()
Default constructor.
std::underlying_type_t< ndn::nfd::RouteFlags > flags
Definition route.hpp:99
std::optional< time::steady_clock::time_point > expires
Definition route.hpp:100
std::optional< ndn::PrefixAnnouncement > announcement
The prefix announcement that caused the creation of this route.
Definition route.hpp:106
uint64_t faceId
Definition route.hpp:96
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
static time::steady_clock::time_point computeExpiration(const ndn::PrefixAnnouncement &ann)
Definition route.cpp:35
Definition common.hpp:71