Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 84c65c0 | 2017-07-05 18:40:34 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 51cf75c | 2020-03-11 22:21:13 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [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. |
| 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 Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FW_ALGORITHM_HPP |
| 27 | #define NFD_DAEMON_FW_ALGORITHM_HPP |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 29 | #include "fw/scope-prefix.hpp" |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 30 | #include "table/fib.hpp" |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 31 | #include "table/pit-entry.hpp" |
| 32 | |
| 33 | /** \file |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 34 | * This file contains common algorithms used by forwarding strategies. |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | namespace nfd { |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 38 | namespace fw { |
| 39 | |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 40 | /** \brief determine whether forwarding the Interest in \p pitEntry to \p outFace would violate scope |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 41 | * \sa https://redmine.named-data.net/projects/nfd/wiki/ScopeControl |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 42 | */ |
| 43 | bool |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 44 | wouldViolateScope(const Face& inFace, const Interest& interest, const Face& outFace); |
| 45 | |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 46 | /** \brief decide whether Interest can be forwarded to face |
| 47 | * |
| 48 | * \return true if out-record of this face does not exist or has expired, |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 49 | * and there is an in-record not of this face |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 50 | * |
| 51 | * \note This algorithm has a weakness that it does not permit consumer retransmissions |
| 52 | * before out-record expires. Therefore, it's not recommended to use this function |
| 53 | * in new strategies. |
| 54 | * \todo find a better name for this function |
| 55 | */ |
| 56 | bool |
| 57 | canForwardToLegacy(const pit::Entry& pitEntry, const Face& face); |
| 58 | |
| 59 | /** \brief indicates where duplicate Nonces are found |
| 60 | */ |
| 61 | enum DuplicateNonceWhere { |
| 62 | DUPLICATE_NONCE_NONE = 0, ///< no duplicate Nonce is found |
| 63 | DUPLICATE_NONCE_IN_SAME = (1 << 0), ///< in-record of same face |
| 64 | DUPLICATE_NONCE_IN_OTHER = (1 << 1), ///< in-record of other face |
| 65 | DUPLICATE_NONCE_OUT_SAME = (1 << 2), ///< out-record of same face |
| 66 | DUPLICATE_NONCE_OUT_OTHER = (1 << 3) ///< out-record of other face |
| 67 | }; |
| 68 | |
| 69 | /** \brief determine whether \p pitEntry has duplicate Nonce \p nonce |
| 70 | * \return OR'ed DuplicateNonceWhere |
| 71 | */ |
| 72 | int |
Davide Pesavento | 51cf75c | 2020-03-11 22:21:13 -0400 | [diff] [blame] | 73 | findDuplicateNonce(const pit::Entry& pitEntry, Interest::Nonce nonce, const Face& face); |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 74 | |
| 75 | /** \brief determine whether \p pitEntry has any pending out-records |
Junxiao Shi | 8744c97 | 2016-04-06 10:33:46 -0700 | [diff] [blame] | 76 | * \return true if there is at least one out-record waiting for Data |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 77 | */ |
| 78 | bool |
| 79 | hasPendingOutRecords(const pit::Entry& pitEntry); |
| 80 | |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 81 | /** \return last out-record time |
| 82 | * \pre pitEntry has one or more unexpired out-records |
| 83 | */ |
| 84 | time::steady_clock::TimePoint |
| 85 | getLastOutgoing(const pit::Entry& pitEntry); |
| 86 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 87 | /** \brief pick an eligible NextHop with earliest out-record |
| 88 | * \note It is assumed that every nexthop has an out-record. |
| 89 | */ |
| 90 | fib::NextHopList::const_iterator |
| 91 | findEligibleNextHopWithEarliestOutRecord(const Face& inFace, const Interest& interest, |
| 92 | const fib::NextHopList& nexthops, |
| 93 | const shared_ptr<pit::Entry>& pitEntry); |
| 94 | |
| 95 | /** \brief determines whether a NextHop is eligible i.e. not the same inFace |
| 96 | * \param inFace incoming face of current Interest |
| 97 | * \param interest incoming Interest |
| 98 | * \param nexthop next hop |
| 99 | * \param pitEntry PIT entry |
| 100 | * \param wantUnused if true, NextHop must not have unexpired out-record |
| 101 | * \param now time::steady_clock::now(), ignored if !wantUnused |
| 102 | */ |
| 103 | bool |
| 104 | isNextHopEligible(const Face& inFace, const Interest& interest, |
| 105 | const fib::NextHop& nexthop, |
| 106 | const shared_ptr<pit::Entry>& pitEntry, |
| 107 | bool wantUnused = false, |
| 108 | time::steady_clock::TimePoint now = time::steady_clock::TimePoint::min()); |
| 109 | |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 110 | } // namespace fw |
| 111 | } // namespace nfd |
| 112 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 113 | #endif // NFD_DAEMON_FW_ALGORITHM_HPP |