blob: c5732b867bc13cd881df4382d5aa33b8f15fa4cb [file] [log] [blame]
Junxiao Shifef73e42016-03-29 14:15:05 -07001/* -*- 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
32 * This file contains algorithms that operate on a PIT entry.
33 */
34
35namespace nfd {
36namespace fw {
37
38/** \brief contain Name prefix that affects namespace-based scope control
39 * \sa http://redmine.named-data.net/projects/nfd/wiki/ScopeControl
40 */
41namespace scope_prefix {
42
43/** \brief ndn:/localhost
44 *
45 * The localhost scope limits propagation to the applications on the originating host.
46 *
47 * Interest and Data packets under prefix ndn:/localhost are restricted by these rules:
48 * \li Interest can come from and go to local faces only.
49 * \li Data can come from and go to local faces only.
50 */
51extern const Name LOCALHOST;
52
53/** \brief ndn:/localhop
54 *
55 * The localhop scope limits propagation to no further than the next node.
56 *
57 * Interest packets under prefix ndn:/localhop are restricted by these rules:
58 * \li Interest can come from a local face or a non-local face.
59 * \li If PIT entry has at least one in-record from a local face,
60 * it can be forwarded to local faces and non-local faces.
61 * \li If PIT entry has all in-records from non-local faces,
62 * it can only be forwarded to local faces.
63 * \li PIT entry can be satisfied by Data from any source.
64 *
65 * Data packets under prefix ndn:/localhop are unrestricted.
66 */
67extern const Name LOCALHOP;
68
69} // namespace scope_prefix
70
71/** \brief determine whether forwarding the Interest in \p pitEntry to \p outFace would violate scope
72 * \sa http://redmine.named-data.net/projects/nfd/wiki/ScopeControl
73 */
74bool
75violatesScope(const pit::Entry& pitEntry, const Face& outFace);
76
77/** \brief decide whether Interest can be forwarded to face
78 *
79 * \return true if out-record of this face does not exist or has expired,
80 * and there is an in-record not of this face,
81 * and scope is not violated
82 *
83 * \note This algorithm has a weakness that it does not permit consumer retransmissions
84 * before out-record expires. Therefore, it's not recommended to use this function
85 * in new strategies.
86 * \todo find a better name for this function
87 */
88bool
89canForwardToLegacy(const pit::Entry& pitEntry, const Face& face);
90
91/** \brief indicates where duplicate Nonces are found
92 */
93enum DuplicateNonceWhere {
94 DUPLICATE_NONCE_NONE = 0, ///< no duplicate Nonce is found
95 DUPLICATE_NONCE_IN_SAME = (1 << 0), ///< in-record of same face
96 DUPLICATE_NONCE_IN_OTHER = (1 << 1), ///< in-record of other face
97 DUPLICATE_NONCE_OUT_SAME = (1 << 2), ///< out-record of same face
98 DUPLICATE_NONCE_OUT_OTHER = (1 << 3) ///< out-record of other face
99};
100
101/** \brief determine whether \p pitEntry has duplicate Nonce \p nonce
102 * \return OR'ed DuplicateNonceWhere
103 */
104int
105findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face);
106
107/** \brief determine whether \p pitEntry has any pending out-records
108 * \return true if there is one or more unexpired OutRecords
109 * \todo #3545 take Nack into consideration
110 */
111bool
112hasPendingOutRecords(const pit::Entry& pitEntry);
113
114} // namespace fw
115} // namespace nfd
116
117#endif // NFD_DAEMON_FW_PIT_ALGORITHM_HPP