NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
24 #ifndef NDN_SECURITY_CONF_RULE_HPP
25 #define NDN_SECURITY_CONF_RULE_HPP
26 
27 #include "filter.hpp"
28 #include "checker.hpp"
29 
30 
31 namespace ndn {
32 namespace security {
33 namespace conf {
34 
35 template<class Packet>
36 class Rule
37 {
38 public:
39  explicit
40  Rule(const std::string& id)
41  : m_id(id)
42  {
43  }
44 
45  virtual
47  {
48  }
49 
50  const std::string&
52  {
53  return m_id;
54  }
55 
56  void
57  addFilter(const shared_ptr<Filter>& filter)
58  {
59  m_filters.push_back(filter);
60  }
61 
62  void
63  addChecker(const shared_ptr<Checker>& checker)
64  {
65  m_checkers.push_back(checker);
66  }
67 
68  bool
69  match(const Packet& packet)
70  {
71  if (m_filters.empty())
72  return true;
73 
74  for (FilterList::iterator it = m_filters.begin();
75  it != m_filters.end(); it++)
76  {
77  if (!(*it)->match(packet))
78  return false;
79  }
80 
81  return true;
82  }
83 
94  template<class ValidatedCallback, class ValidationFailureCallback>
95  int8_t
96  check(const Packet& packet,
97  const ValidatedCallback& onValidated,
98  const ValidationFailureCallback& onValidationFailed)
99  {
100  for (CheckerList::iterator it = m_checkers.begin();
101  it != m_checkers.end(); it++)
102  {
103  int8_t result = (*it)->check(packet, onValidated, onValidationFailed);
104  if (result >= 0)
105  return result;
106  }
107  return -1;
108  }
109 
110 private:
111  typedef std::vector<shared_ptr<Filter> > FilterList;
112  typedef std::vector<shared_ptr<Checker> > CheckerList;
113 
114  std::string m_id;
115  FilterList m_filters;
116  CheckerList m_checkers;
117 };
118 
119 } // namespace conf
120 } // namespace security
121 } // namespace ndn
122 
123 #endif // NDN_SECURITY_CONF_RULE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const std::string & getId()
Definition: rule.hpp:51
Table::const_iterator iterator
Definition: cs-internal.hpp:41
bool match(const Packet &packet)
Definition: rule.hpp:69
void addFilter(const shared_ptr< Filter > &filter)
Definition: rule.hpp:57
Rule(const std::string &id)
Definition: rule.hpp:40
void addChecker(const shared_ptr< Checker > &checker)
Definition: rule.hpp:63
int8_t check(const Packet &packet, const ValidatedCallback &onValidated, const ValidationFailureCallback &onValidationFailed)
check if packet satisfies certain condition
Definition: rule.hpp:96