blob: 3ae38808ea8c8d385f2ce72cf23d386d6bba1399 [file] [log] [blame]
Junxiao Shifef73e42016-03-29 14:15:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento84c65c02017-07-05 18:40:34 +00002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shifef73e42016-03-29 14:15:05 -07004 * 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
Eric Newberry2377ada2020-09-28 22:40:14 -070026#ifndef NFD_DAEMON_FW_ALGORITHM_HPP
27#define NFD_DAEMON_FW_ALGORITHM_HPP
Junxiao Shifef73e42016-03-29 14:15:05 -070028
Davide Pesavento58091582021-03-05 19:02:48 -050029#include "table/fib-entry.hpp"
Junxiao Shifef73e42016-03-29 14:15:05 -070030#include "table/pit-entry.hpp"
31
32/** \file
Junxiao Shi00dc9142016-11-21 14:23:12 +000033 * This file contains common algorithms used by forwarding strategies.
Junxiao Shifef73e42016-03-29 14:15:05 -070034 */
35
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036namespace nfd::fw {
Junxiao Shif3410d82016-04-05 13:49:44 -070037
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040038/** \brief Determine whether forwarding the Interest in \p pitEntry to \p outFace would violate scope.
Junxiao Shi00dc9142016-11-21 14:23:12 +000039 * \sa https://redmine.named-data.net/projects/nfd/wiki/ScopeControl
Junxiao Shifef73e42016-03-29 14:15:05 -070040 */
41bool
Junxiao Shi00dc9142016-11-21 14:23:12 +000042wouldViolateScope(const Face& inFace, const Interest& interest, const Face& outFace);
43
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040044/** \brief Indicates where duplicate Nonces are found.
Junxiao Shifef73e42016-03-29 14:15:05 -070045 */
46enum DuplicateNonceWhere {
47 DUPLICATE_NONCE_NONE = 0, ///< no duplicate Nonce is found
48 DUPLICATE_NONCE_IN_SAME = (1 << 0), ///< in-record of same face
49 DUPLICATE_NONCE_IN_OTHER = (1 << 1), ///< in-record of other face
50 DUPLICATE_NONCE_OUT_SAME = (1 << 2), ///< out-record of same face
Davide Pesavento58091582021-03-05 19:02:48 -050051 DUPLICATE_NONCE_OUT_OTHER = (1 << 3), ///< out-record of other face
Junxiao Shifef73e42016-03-29 14:15:05 -070052};
53
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040054/** \brief Determine whether \p pitEntry has duplicate Nonce \p nonce.
Junxiao Shifef73e42016-03-29 14:15:05 -070055 * \return OR'ed DuplicateNonceWhere
56 */
57int
Davide Pesavento51cf75c2020-03-11 22:21:13 -040058findDuplicateNonce(const pit::Entry& pitEntry, Interest::Nonce nonce, const Face& face);
Junxiao Shifef73e42016-03-29 14:15:05 -070059
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040060/** \brief Determine whether \p pitEntry has any pending out-records.
Junxiao Shi8744c972016-04-06 10:33:46 -070061 * \return true if there is at least one out-record waiting for Data
Junxiao Shifef73e42016-03-29 14:15:05 -070062 */
63bool
64hasPendingOutRecords(const pit::Entry& pitEntry);
65
Ashlesh Gawande90015992017-07-11 17:25:48 -050066/** \return last out-record time
67 * \pre pitEntry has one or more unexpired out-records
68 */
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040069time::steady_clock::time_point
Ashlesh Gawande90015992017-07-11 17:25:48 -050070getLastOutgoing(const pit::Entry& pitEntry);
71
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040072/** \brief Pick an eligible NextHop with earliest out-record.
Saurab Dulala6dec222019-04-01 00:15:10 -050073 * \note It is assumed that every nexthop has an out-record.
74 */
75fib::NextHopList::const_iterator
76findEligibleNextHopWithEarliestOutRecord(const Face& inFace, const Interest& interest,
77 const fib::NextHopList& nexthops,
78 const shared_ptr<pit::Entry>& pitEntry);
79
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040080/** \brief Determines whether a NextHop is eligible, i.e., not the same \p inFace.
Saurab Dulala6dec222019-04-01 00:15:10 -050081 * \param inFace incoming face of current Interest
82 * \param interest incoming Interest
83 * \param nexthop next hop
84 * \param pitEntry PIT entry
85 * \param wantUnused if true, NextHop must not have unexpired out-record
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040086 * \param now the current time, ignored if `wantUnused == false`
Saurab Dulala6dec222019-04-01 00:15:10 -050087 */
88bool
89isNextHopEligible(const Face& inFace, const Interest& interest,
90 const fib::NextHop& nexthop,
91 const shared_ptr<pit::Entry>& pitEntry,
92 bool wantUnused = false,
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040093 time::steady_clock::time_point now = time::steady_clock::time_point::min());
Saurab Dulala6dec222019-04-01 00:15:10 -050094
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040095} // namespace nfd::fw
Junxiao Shifef73e42016-03-29 14:15:05 -070096
Eric Newberry2377ada2020-09-28 22:40:14 -070097#endif // NFD_DAEMON_FW_ALGORITHM_HPP