NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
rule.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25 #ifndef NDN_SECURITY_CONF_RULE_HPP
26 #define NDN_SECURITY_CONF_RULE_HPP
27 
28 #include "filter.hpp"
29 #include "checker.hpp"
30 
31 
32 namespace ndn {
33 namespace security {
34 namespace conf {
35 
36 template<class Packet>
37 class Rule
38 {
39 public:
40  explicit
41  Rule(const std::string& id)
42  : m_id(id)
43  {
44  }
45 
46  virtual
48  {
49  }
50 
51  const std::string&
53  {
54  return m_id;
55  }
56 
57  void
58  addFilter(const shared_ptr<Filter>& filter)
59  {
60  m_filters.push_back(filter);
61  }
62 
63  void
64  addChecker(const shared_ptr<Checker>& checker)
65  {
66  m_checkers.push_back(checker);
67  }
68 
69  bool
70  match(const Packet& packet)
71  {
72  if (m_filters.empty())
73  return true;
74 
75  for (FilterList::iterator it = m_filters.begin();
76  it != m_filters.end(); it++)
77  {
78  if (!(*it)->match(packet))
79  return false;
80  }
81 
82  return true;
83  }
84 
95  template<class ValidatedCallback, class ValidationFailureCallback>
96  int8_t
97  check(const Packet& packet,
98  const ValidatedCallback& onValidated,
99  const ValidationFailureCallback& onValidationFailed)
100  {
101  bool hasPendingResult = false;
102  for (CheckerList::iterator it = m_checkers.begin(); it != m_checkers.end(); it++) {
103  int8_t result = (*it)->check(packet);
104  if (result > 0) {
105  onValidated(packet.shared_from_this());
106  return result;
107  }
108  else if (result == 0)
109  hasPendingResult = true;
110  }
111  if (hasPendingResult) {
112  return 0;
113  }
114  else {
115  onValidationFailed(packet.shared_from_this(), "Packet cannot pass any checkers.");
116  return -1;
117  }
118  }
119 
121  typedef std::vector<shared_ptr<Filter>> FilterList;
122  typedef std::vector<shared_ptr<Checker>> CheckerList;
123 
124  std::string m_id;
125  FilterList m_filters;
126  CheckerList m_checkers;
127 };
128 
129 } // namespace conf
130 } // namespace security
131 } // namespace ndn
132 
133 #endif // NDN_SECURITY_CONF_RULE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
FilterList m_filters
Definition: rule.hpp:125
const std::string & getId()
Definition: rule.hpp:52
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
std::vector< shared_ptr< Checker > > CheckerList
Definition: rule.hpp:122
Table::const_iterator iterator
Definition: cs-internal.hpp:41
bool match(const Packet &packet)
Definition: rule.hpp:70
void addFilter(const shared_ptr< Filter > &filter)
Definition: rule.hpp:58
Rule(const std::string &id)
Definition: rule.hpp:41
void addChecker(const shared_ptr< Checker > &checker)
Definition: rule.hpp:64
int8_t check(const Packet &packet, const ValidatedCallback &onValidated, const ValidationFailureCallback &onValidationFailed)
check if packet satisfies certain condition
Definition: rule.hpp:97
CheckerList m_checkers
Definition: rule.hpp:126