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-2022, 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::fw {
32 
37  DROP,
38  CACHE
39 };
40 
41 std::ostream&
42 operator<<(std::ostream& os, UnsolicitedDataDecision d);
43 
51 class UnsolicitedDataPolicy : noncopyable
52 {
53 public:
54  virtual
56 
58  decide(const Face& inFace, const Data& data) const = 0;
59 
60 public: // registry
61  template<typename P>
62  static void
63  registerPolicy(const std::string& policyName = P::POLICY_NAME)
64  {
65  BOOST_ASSERT(!policyName.empty());
66  auto r = getRegistry().insert_or_assign(policyName, [] { return make_unique<P>(); });
67  BOOST_VERIFY(r.second);
68  }
69 
73  static unique_ptr<UnsolicitedDataPolicy>
74  create(const std::string& policyName);
75 
78  static std::set<std::string>
80 
81 private:
82  using CreateFunc = std::function<unique_ptr<UnsolicitedDataPolicy>()>;
83  using Registry = std::map<std::string, CreateFunc>; // indexed by policy name
84 
85  static Registry&
86  getRegistry();
87 };
88 
93 {
94 public:
96  decide(const Face& inFace, const Data& data) const final;
97 
98 public:
99  static const std::string POLICY_NAME;
100 };
101 
106 {
107 public:
109  decide(const Face& inFace, const Data& data) const final;
110 
111 public:
112  static const std::string POLICY_NAME;
113 };
114 
119 {
120 public:
122  decide(const Face& inFace, const Data& data) const final;
123 
124 public:
125  static const std::string POLICY_NAME;
126 };
127 
132 {
133 public:
135  decide(const Face& inFace, const Data& data) const final;
136 
137 public:
138  static const std::string POLICY_NAME;
139 };
140 
145 
146 } // namespace nfd::fw
147 
153 #define NFD_REGISTER_UNSOLICITED_DATA_POLICY(P) \
154 static class NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass \
155 { \
156 public: \
157  NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass() \
158  { \
159  ::nfd::fw::UnsolicitedDataPolicy::registerPolicy<P>(); \
160  } \
161 } g_nfdAuto ## P ## UnsolicitedDataPolicyRegistrationVariable
162 
163 #endif // NFD_DAEMON_FW_UNSOLICITED_DATA_POLICY_HPP
Generalization of a network interface.
Definition: face.hpp:56
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
Admits unsolicited Data from local faces.
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
Admits unsolicited Data from non-local faces.
UnsolicitedDataDecision decide(const Face &inFace, const Data &data) const final
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 void registerPolicy(const std::string &policyName=P::POLICY_NAME)
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &policyName)
static std::set< std::string > getPolicyNames()
virtual ~UnsolicitedDataPolicy()=default
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)