Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2016, 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 | #ifndef NFD_DAEMON_FW_PIT_ALGORITHM_HPP |
| 27 | #define NFD_DAEMON_FW_PIT_ALGORITHM_HPP |
| 28 | |
| 29 | #include "table/pit-entry.hpp" |
| 30 | |
| 31 | /** \file |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 32 | * This file contains common algorithms used by forwarding strategies. |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | namespace nfd { |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 36 | |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 37 | /** \brief contain name prefixes that affect namespace-based scope control |
| 38 | * \sa https://redmine.named-data.net/projects/nfd/wiki/ScopeControl |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 39 | */ |
| 40 | namespace scope_prefix { |
| 41 | |
| 42 | /** \brief ndn:/localhost |
| 43 | * |
| 44 | * The localhost scope limits propagation to the applications on the originating host. |
| 45 | * |
| 46 | * Interest and Data packets under prefix ndn:/localhost are restricted by these rules: |
| 47 | * \li Interest can come from and go to local faces only. |
| 48 | * \li Data can come from and go to local faces only. |
| 49 | */ |
| 50 | extern const Name LOCALHOST; |
| 51 | |
| 52 | /** \brief ndn:/localhop |
| 53 | * |
| 54 | * The localhop scope limits propagation to no further than the next node. |
| 55 | * |
| 56 | * Interest packets under prefix ndn:/localhop are restricted by these rules: |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 57 | * \li If an Interest is received from a local face, it can be forwarded to a non-local face. |
| 58 | * \li If an Interest is received from a non-local face, it cannot be forwarded to a non-local face. |
| 59 | * \li In either case the Interest can be forwarded to a local face. |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 60 | * \li PIT entry can be satisfied by Data from any source. |
| 61 | * |
| 62 | * Data packets under prefix ndn:/localhop are unrestricted. |
| 63 | */ |
| 64 | extern const Name LOCALHOP; |
| 65 | |
| 66 | } // namespace scope_prefix |
| 67 | |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 68 | namespace fw { |
| 69 | |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 70 | /** \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] | 71 | * \sa https://redmine.named-data.net/projects/nfd/wiki/ScopeControl |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 72 | */ |
| 73 | bool |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 74 | wouldViolateScope(const Face& inFace, const Interest& interest, const Face& outFace); |
| 75 | |
| 76 | /** \brief determine whether forwarding the Interest in \p pitEntry to \p outFace would violate scope |
| 77 | * \sa https://redmine.named-data.net/projects/nfd/wiki/ScopeControl |
| 78 | * \deprecated use violatesScope(inFace, interest, outFace) instead |
| 79 | */ |
| 80 | DEPRECATED( |
| 81 | bool |
| 82 | violatesScope(const pit::Entry& pitEntry, const Face& outFace)); |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 83 | |
| 84 | /** \brief decide whether Interest can be forwarded to face |
| 85 | * |
| 86 | * \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] | 87 | * and there is an in-record not of this face |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 88 | * |
| 89 | * \note This algorithm has a weakness that it does not permit consumer retransmissions |
| 90 | * before out-record expires. Therefore, it's not recommended to use this function |
| 91 | * in new strategies. |
| 92 | * \todo find a better name for this function |
| 93 | */ |
| 94 | bool |
| 95 | canForwardToLegacy(const pit::Entry& pitEntry, const Face& face); |
| 96 | |
| 97 | /** \brief indicates where duplicate Nonces are found |
| 98 | */ |
| 99 | enum DuplicateNonceWhere { |
| 100 | DUPLICATE_NONCE_NONE = 0, ///< no duplicate Nonce is found |
| 101 | DUPLICATE_NONCE_IN_SAME = (1 << 0), ///< in-record of same face |
| 102 | DUPLICATE_NONCE_IN_OTHER = (1 << 1), ///< in-record of other face |
| 103 | DUPLICATE_NONCE_OUT_SAME = (1 << 2), ///< out-record of same face |
| 104 | DUPLICATE_NONCE_OUT_OTHER = (1 << 3) ///< out-record of other face |
| 105 | }; |
| 106 | |
| 107 | /** \brief determine whether \p pitEntry has duplicate Nonce \p nonce |
| 108 | * \return OR'ed DuplicateNonceWhere |
| 109 | */ |
| 110 | int |
| 111 | findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face); |
| 112 | |
| 113 | /** \brief determine whether \p pitEntry has any pending out-records |
Junxiao Shi | 8744c97 | 2016-04-06 10:33:46 -0700 | [diff] [blame] | 114 | * \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] | 115 | */ |
| 116 | bool |
| 117 | hasPendingOutRecords(const pit::Entry& pitEntry); |
| 118 | |
| 119 | } // namespace fw |
| 120 | } // namespace nfd |
| 121 | |
| 122 | #endif // NFD_DAEMON_FW_PIT_ALGORITHM_HPP |