Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [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_UNSOLICITED_DATA_POLICY_HPP |
| 27 | #define NFD_DAEMON_FW_UNSOLICITED_DATA_POLICY_HPP |
| 28 | |
| 29 | #include "face/face.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace fw { |
| 33 | |
| 34 | /** \brief a decision made by UnsolicitedDataPolicy |
| 35 | */ |
| 36 | enum class UnsolicitedDataDecision { |
| 37 | DROP, ///< the Data should be dropped |
| 38 | CACHE ///< the Data should be cached in the ContentStore |
| 39 | }; |
| 40 | |
| 41 | std::ostream& |
| 42 | operator<<(std::ostream& os, UnsolicitedDataDecision d); |
| 43 | |
| 44 | /** \brief determines how to process an unsolicited Data |
| 45 | * |
| 46 | * An incoming Data is unsolicited if it does not match any PIT entry. |
| 47 | * This class assists forwarding pipelines to decide whether to drop an unsolicited Data |
| 48 | * or admit it into the ContentStore. |
| 49 | */ |
| 50 | class UnsolicitedDataPolicy : noncopyable |
| 51 | { |
| 52 | public: |
| 53 | virtual ~UnsolicitedDataPolicy() = default; |
| 54 | |
| 55 | virtual UnsolicitedDataDecision |
| 56 | decide(const Face& inFace, const Data& data) const = 0; |
| 57 | }; |
| 58 | |
Junxiao Shi | 36b2225 | 2016-08-25 13:22:21 +0000 | [diff] [blame] | 59 | /** \brief drops all unsolicited Data |
| 60 | */ |
| 61 | class DropAllUnsolicitedDataPolicy : public UnsolicitedDataPolicy |
| 62 | { |
| 63 | public: |
| 64 | virtual UnsolicitedDataDecision |
| 65 | decide(const Face& inFace, const Data& data) const final; |
| 66 | }; |
| 67 | |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 68 | /** \brief admits unsolicited Data from local faces |
| 69 | */ |
| 70 | class AdmitLocalUnsolicitedDataPolicy : public UnsolicitedDataPolicy |
| 71 | { |
| 72 | public: |
| 73 | virtual UnsolicitedDataDecision |
| 74 | decide(const Face& inFace, const Data& data) const final; |
| 75 | }; |
| 76 | |
Junxiao Shi | 36b2225 | 2016-08-25 13:22:21 +0000 | [diff] [blame] | 77 | /** \brief admits unsolicited Data from non-local faces |
| 78 | */ |
| 79 | class AdmitNetworkUnsolicitedDataPolicy : public UnsolicitedDataPolicy |
| 80 | { |
| 81 | public: |
| 82 | virtual UnsolicitedDataDecision |
| 83 | decide(const Face& inFace, const Data& data) const final; |
| 84 | }; |
| 85 | |
| 86 | /** \brief admits all unsolicited Data |
| 87 | */ |
| 88 | class AdmitAllUnsolicitedDataPolicy : public UnsolicitedDataPolicy |
| 89 | { |
| 90 | public: |
| 91 | virtual UnsolicitedDataDecision |
| 92 | decide(const Face& inFace, const Data& data) const final; |
| 93 | }; |
| 94 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 95 | /** \return an UnsolicitedDataPolicy identified by \p key, or nullptr if \p key is unknown |
| 96 | */ |
| 97 | unique_ptr<UnsolicitedDataPolicy> |
| 98 | makeUnsolicitedDataPolicy(const std::string& key); |
| 99 | |
| 100 | /** \brief the default UnsolicitedDataPolicy |
| 101 | */ |
| 102 | typedef AdmitLocalUnsolicitedDataPolicy DefaultUnsolicitedDataPolicy; |
| 103 | |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 104 | } // namespace fw |
| 105 | } // namespace nfd |
| 106 | |
| 107 | #endif // NFD_DAEMON_FW_UNSOLICITED_DATA_POLICY_HPP |