NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2021, 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 
37  DROP,
38  CACHE
39 };
40 
41 std::ostream&
42 operator<<(std::ostream& os, UnsolicitedDataDecision d);
43 
50 class UnsolicitedDataPolicy : noncopyable
51 {
52 public:
53  virtual
54  ~UnsolicitedDataPolicy() = default;
55 
57  decide(const Face& inFace, const Data& data) const = 0;
58 
59 public: // registry
60  template<typename P>
61  static void
62  registerPolicy(const std::string& policyName = P::POLICY_NAME)
63  {
64  Registry& registry = getRegistry();
65  BOOST_ASSERT(registry.count(policyName) == 0);
66  registry[policyName] = [] { return make_unique<P>(); };
67  }
68 
72  static unique_ptr<UnsolicitedDataPolicy>
73  create(const std::string& policyName);
74 
77  static std::set<std::string>
78  getPolicyNames();
79 
80 private:
81  typedef std::function<unique_ptr<UnsolicitedDataPolicy>()> CreateFunc;
82  typedef std::map<std::string, CreateFunc> Registry; // indexed by policy name
83 
84  static Registry&
85  getRegistry();
86 };
87 
91 {
92 public:
94  decide(const Face& inFace, const Data& data) const final;
95 
96 public:
97  static const std::string POLICY_NAME;
98 };
99 
103 {
104 public:
106  decide(const Face& inFace, const Data& data) const final;
107 
108 public:
109  static const std::string POLICY_NAME;
110 };
111 
115 {
116 public:
118  decide(const Face& inFace, const Data& data) const final;
119 
120 public:
121  static const std::string POLICY_NAME;
122 };
123 
127 {
128 public:
130  decide(const Face& inFace, const Data& data) const final;
131 
132 public:
133  static const std::string POLICY_NAME;
134 };
135 
139 
140 } // namespace fw
141 } // namespace nfd
142 
147 #define NFD_REGISTER_UNSOLICITED_DATA_POLICY(P) \
148 static class NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass \
149 { \
150 public: \
151  NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass() \
152  { \
153  ::nfd::fw::UnsolicitedDataPolicy::registerPolicy<P>(); \
154  } \
155 } g_nfdAuto ## P ## UnsolicitedDataPolicyRegistrationVariable
156 
157 #endif // NFD_DAEMON_FW_UNSOLICITED_DATA_POLICY_HPP
determines how to process an unsolicited Data
admits unsolicited Data from local faces
ndn Face
Definition: face-impl.hpp:42
admits unsolicited Data from non-local faces
the Data should be dropped
static void registerPolicy(const std::string &policyName=P::POLICY_NAME)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
UnsolicitedDataDecision
a decision made by UnsolicitedDataPolicy
the Data should be cached in the ContentStore
std::ostream & operator<<(std::ostream &os, UnsolicitedDataDecision d)
Represents a Data packet.
Definition: data.hpp:37