NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2018, 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
#include <
ndn-cxx/util/string-helper.hpp
>
28
29
namespace
nfd
{
30
namespace
rib {
31
32
const
uint64_t
PA_ROUTE_COST
= 2048;
33
34
static
time::steady_clock::TimePoint
35
computeExpiration
(
const
ndn::PrefixAnnouncement
& ann)
36
{
37
time::steady_clock::Duration
validityEnd = time::steady_clock::Duration::max();
38
if
(ann.
getValidityPeriod
()) {
39
auto
now =
time::system_clock::now
();
40
if
(!ann.
getValidityPeriod
()->isValid(now)) {
41
validityEnd = time::steady_clock::Duration::zero();
42
}
43
else
{
44
validityEnd = ann.
getValidityPeriod
()->getPeriod().second - now;
45
}
46
}
47
return
time::steady_clock::now
() +
48
std::min(validityEnd, time::duration_cast<time::steady_clock::Duration>(ann.
getExpiration
()));
49
}
50
51
Route::Route
(
const
ndn::PrefixAnnouncement
& ann, uint64_t faceId)
52
: faceId(faceId)
53
, origin(
ndn
::
nfd
::
ROUTE_ORIGIN_PREFIXANN
)
54
, cost(
PA_ROUTE_COST
)
55
, flags(
ndn
::
nfd
::
ROUTE_FLAG_CHILD_INHERIT
)
56
, expires(
computeExpiration
(ann))
57
, announcement(ann)
58
, annExpires(*expires)
59
{
60
}
61
62
bool
63
operator==
(
const
Route
& lhs,
const
Route
& rhs)
64
{
65
return
lhs.
faceId
== rhs.
faceId
&&
66
lhs.
origin
== rhs.
origin
&&
67
lhs.
flags
== rhs.
flags
&&
68
lhs.
cost
== rhs.
cost
&&
69
lhs.
expires
== rhs.
expires
&&
70
lhs.
announcement
== rhs.
announcement
;
71
}
72
73
std::ostream&
74
operator<<
(std::ostream& os,
const
Route
& route)
75
{
76
os <<
"Route("
77
<<
"faceid: "
<< route.
faceId
78
<<
", origin: "
<< route.
origin
79
<<
", cost: "
<< route.
cost
80
<<
", flags: "
<<
ndn::AsHex
{route.
flags
};
81
if
(route.
expires
) {
82
os <<
", expires in: "
<< time::duration_cast<time::milliseconds>(*route.
expires
-
time::steady_clock::now
());
83
}
84
else
{
85
os <<
", never expires"
;
86
}
87
if
(route.
announcement
) {
88
os <<
", announcement: ("
<< *route.
announcement
<<
')'
;
89
}
90
os <<
')'
;
91
92
return
os;
93
}
94
95
}
// namespace rib
96
}
// namespace nfd
nfd::rib::Route::origin
ndn::nfd::RouteOrigin origin
Definition:
route.hpp:82
nfd::rib::operator==
bool operator==(const Route &lhs, const Route &rhs)
Definition:
route.cpp:63
string-helper.hpp
nfd::rib::Route::Route
Route()=default
default constructor
nfd::rib::Route::cost
uint64_t cost
Definition:
route.hpp:83
ndn::AsHex
Helper class to convert a number to hexadecimal format, for use with stream insertion operators.
Definition:
string-helper.hpp:49
ndn::time::steady_clock::now
static time_point now() noexcept
Definition:
time.cpp:80
ndn::time::system_clock::now
static time_point now() noexcept
Definition:
time.cpp:46
ndn::time::steady_clock::Duration
duration Duration
Definition:
time.hpp:226
ndn::PrefixAnnouncement
A prefix announcement object that represents an application's intent of registering a prefix toward i...
Definition:
prefix-announcement.hpp:34
route.hpp
nfd::rib::computeExpiration
static time::steady_clock::TimePoint computeExpiration(const ndn::PrefixAnnouncement &ann)
Definition:
route.cpp:35
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:40
ndn::PrefixAnnouncement::getValidityPeriod
optional< security::ValidityPeriod > getValidityPeriod() const
Return absolute validity period.
Definition:
prefix-announcement.hpp:108
nfd::rib::Route::faceId
uint64_t faceId
Definition:
route.hpp:81
nfd::rib::operator<<
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
Definition:
fib-update.hpp:74
ndn::time::steady_clock::TimePoint
time_point TimePoint
Definition:
time.hpp:225
nfd::rib::Route::announcement
optional< ndn::PrefixAnnouncement > announcement
The prefix announcement that caused the creation of this route.
Definition:
route.hpp:91
nfd::rib::Route::flags
std::underlying_type_t< ndn::nfd::RouteFlags > flags
Definition:
route.hpp:84
nfd::rib::Route
represents a route for a name prefix
Definition:
route.hpp:44
ndn::nfd::ROUTE_ORIGIN_PREFIXANN
@ ROUTE_ORIGIN_PREFIXANN
Definition:
nfd-constants.hpp:106
nfd::rib::Route::expires
optional< time::steady_clock::TimePoint > expires
Definition:
route.hpp:85
nfd::rib::PA_ROUTE_COST
const uint64_t PA_ROUTE_COST
cost of route created by prefix announcement
Definition:
route.cpp:32
ndn::PrefixAnnouncement::getExpiration
time::milliseconds getExpiration() const
Return relative expiration period.
Definition:
prefix-announcement.hpp:93
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::nfd::ROUTE_FLAG_CHILD_INHERIT
@ ROUTE_FLAG_CHILD_INHERIT
Definition:
nfd-constants.hpp:125
ndnSIM
NFD
daemon
rib
route.cpp
Generated on Mon Jun 1 2020 22:32:16 for ndnSIM by
1.8.18