unsolicited-data-policy.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, 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 #include <functional>
32 #include <map>
33 #include <set>
34 
35 namespace nfd::fw {
36 
41  DROP,
42  CACHE
43 };
44 
45 std::ostream&
46 operator<<(std::ostream& os, UnsolicitedDataDecision d);
47 
55 class UnsolicitedDataPolicy : noncopyable
56 {
57 public:
58  virtual
60 
62  decide(const Face& inFace, const Data& data) const = 0;
63 
64 public: // registry
65  template<typename P>
66  static void
67  registerPolicy(std::string_view policyName = P::POLICY_NAME)
68  {
69  BOOST_ASSERT(!policyName.empty());
70  auto r = getRegistry().insert_or_assign(std::string(policyName), [] { return make_unique<P>(); });
71  BOOST_VERIFY(r.second);
72  }
73 
77  static unique_ptr<UnsolicitedDataPolicy>
78  create(const std::string& policyName);
79 
82  static std::set<std::string>
84 
85 private:
86  using CreateFunc = std::function<unique_ptr<UnsolicitedDataPolicy>()>;
87  using Registry = std::map<std::string, CreateFunc>; // indexed by policy name
88 
89  static Registry&
90  getRegistry();
91 };
92 
97 {
98 public:
100  decide(const Face& inFace, const Data& data) const final;
101 
102 public:
103  static constexpr std::string_view POLICY_NAME{"drop-all"};
104 };
105 
110 {
111 public:
113  decide(const Face& inFace, const Data& data) const final;
114 
115 public:
116  static constexpr std::string_view POLICY_NAME{"admit-local"};
117 };
118 
123 {
124 public:
126  decide(const Face& inFace, const Data& data) const final;
127 
128 public:
129  static constexpr std::string_view POLICY_NAME{"admit-network"};
130 };
131 
136 {
137 public:
139  decide(const Face& inFace, const Data& data) const final;
140 
141 public:
142  static constexpr std::string_view POLICY_NAME{"admit-all"};
143 };
144 
149 
150 } // namespace nfd::fw
151 
157 #define NFD_REGISTER_UNSOLICITED_DATA_POLICY(P) \
158 static class NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass \
159 { \
160 public: \
161  NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass() \
162  { \
163  ::nfd::fw::UnsolicitedDataPolicy::registerPolicy<P>(); \
164  } \
165 } g_nfdAuto ## P ## UnsolicitedDataPolicyRegistrationVariable
166 
167 #endif // NFD_DAEMON_FW_UNSOLICITED_DATA_POLICY_HPP
Generalization of a network interface.
Definition: face.hpp:118
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
static constexpr std::string_view POLICY_NAME
Admits unsolicited Data from local faces.
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
static constexpr std::string_view POLICY_NAME
Admits unsolicited Data from non-local faces.
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
static constexpr std::string_view POLICY_NAME
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
Determines how to process an unsolicited Data packet.
virtual UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const =0
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &policyName)
static std::set< std::string > getPolicyNames()
virtual ~UnsolicitedDataPolicy()=default
static void registerPolicy(std::string_view policyName=P::POLICY_NAME)
UnsolicitedDataDecision
Decision made by UnsolicitedDataPolicy.
@ CACHE
the Data should be cached in the ContentStore
@ DROP
the Data should be dropped
std::ostream & operator<<(std::ostream &os, UnsolicitedDataDecision d)