blob: 7ee0f38c4400c215f435387fe8659088a5dc7103 [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/*
Yanbiao Lif48d0802018-06-01 03:00:02 -07003 * Copyright (c) 2014-2018, 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
26#ifndef NFD_DAEMON_FW_PIT_ALGORITHM_HPP
27#define NFD_DAEMON_FW_PIT_ALGORITHM_HPP
28
Yanbiao Lif48d0802018-06-01 03:00:02 -070029#include "core/scope-prefix.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
36namespace nfd {
Junxiao Shif3410d82016-04-05 13:49:44 -070037namespace fw {
38
Junxiao Shifef73e42016-03-29 14:15:05 -070039/** \brief determine whether forwarding the Interest in \p pitEntry to \p outFace would violate scope
Junxiao Shi00dc9142016-11-21 14:23:12 +000040 * \sa https://redmine.named-data.net/projects/nfd/wiki/ScopeControl
Junxiao Shifef73e42016-03-29 14:15:05 -070041 */
42bool
Junxiao Shi00dc9142016-11-21 14:23:12 +000043wouldViolateScope(const Face& inFace, const Interest& interest, const Face& outFace);
44
Junxiao Shifef73e42016-03-29 14:15:05 -070045/** \brief decide whether Interest can be forwarded to face
46 *
47 * \return true if out-record of this face does not exist or has expired,
Junxiao Shie21b3f32016-11-24 14:13:46 +000048 * and there is an in-record not of this face
Junxiao Shifef73e42016-03-29 14:15:05 -070049 *
50 * \note This algorithm has a weakness that it does not permit consumer retransmissions
51 * before out-record expires. Therefore, it's not recommended to use this function
52 * in new strategies.
53 * \todo find a better name for this function
54 */
55bool
56canForwardToLegacy(const pit::Entry& pitEntry, const Face& face);
57
58/** \brief indicates where duplicate Nonces are found
59 */
60enum DuplicateNonceWhere {
61 DUPLICATE_NONCE_NONE = 0, ///< no duplicate Nonce is found
62 DUPLICATE_NONCE_IN_SAME = (1 << 0), ///< in-record of same face
63 DUPLICATE_NONCE_IN_OTHER = (1 << 1), ///< in-record of other face
64 DUPLICATE_NONCE_OUT_SAME = (1 << 2), ///< out-record of same face
65 DUPLICATE_NONCE_OUT_OTHER = (1 << 3) ///< out-record of other face
66};
67
68/** \brief determine whether \p pitEntry has duplicate Nonce \p nonce
69 * \return OR'ed DuplicateNonceWhere
70 */
71int
72findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face);
73
74/** \brief determine whether \p pitEntry has any pending out-records
Junxiao Shi8744c972016-04-06 10:33:46 -070075 * \return true if there is at least one out-record waiting for Data
Junxiao Shifef73e42016-03-29 14:15:05 -070076 */
77bool
78hasPendingOutRecords(const pit::Entry& pitEntry);
79
Ashlesh Gawande90015992017-07-11 17:25:48 -050080/** \return last out-record time
81 * \pre pitEntry has one or more unexpired out-records
82 */
83time::steady_clock::TimePoint
84getLastOutgoing(const pit::Entry& pitEntry);
85
Junxiao Shifef73e42016-03-29 14:15:05 -070086} // namespace fw
87} // namespace nfd
88
89#endif // NFD_DAEMON_FW_PIT_ALGORITHM_HPP