25 #include <boost/algorithm/string/predicate.hpp> 32 namespace validator_config {
43 m_filters.push_back(std::move(filter));
49 m_checkers.push_back(std::move(checker));
53 Rule::match(uint32_t pktType,
const Name& pktName,
const shared_ptr<ValidationState>& state)
const 56 if (pktType != m_pktType) {
61 if (m_filters.empty()) {
66 for (
const auto& filter : m_filters) {
67 retval |= filter->match(pktType, pktName, state);
77 const shared_ptr<ValidationState>& state)
const 79 NDN_LOG_TRACE(
"Trying to check " << pktName <<
" with keyLocator " << klName);
81 if (pktType != m_pktType) {
86 bool hasPendingResult =
false;
87 for (
const auto& checker : m_checkers) {
88 bool result = checker->check(pktType, pktName, klName, state);
92 hasPendingResult =
true;
95 return hasPendingResult;
101 auto propertyIt = configSection.begin();
104 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"id")) {
108 std::string ruleId = propertyIt->second.data();
112 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"for")) {
116 std::string usage = propertyIt->second.data();
119 bool isForData =
false;
120 if (boost::iequals(usage,
"data")) {
123 else if (boost::iequals(usage,
"interest")) {
127 NDN_THROW(
Error(
"Unrecognized <rule.for>: " + usage +
" in rule: " + ruleId));
133 for (; propertyIt != configSection.end(); propertyIt++) {
134 if (!boost::iequals(propertyIt->first,
"filter")) {
135 if (boost::iequals(propertyIt->first,
"checker")) {
141 rule->addFilter(
Filter::create(propertyIt->second, configFilename));
145 bool hasCheckers =
false;
146 for (; propertyIt != configSection.end(); propertyIt++) {
147 if (!boost::iequals(propertyIt->first,
"checker")) {
155 if (propertyIt != configSection.end()) {
160 NDN_THROW(
Error(
"No <rule.checker> is specified in rule: " + ruleId));
Rule(const std::string &id, uint32_t pktType)
std::string to_string(const T &val)
bool match(uint32_t pktType, const Name &pktName, const shared_ptr< ValidationState > &state) const
check if the packet name matches rule's filter
static unique_ptr< Rule > create(const ConfigSection &configSection, const std::string &configFilename)
create a rule from configuration section
#define NDN_LOG_INIT(name)
Define a non-member log module.
bool check(uint32_t pktType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) const
check if packet satisfies rule's condition
void addFilter(unique_ptr< Filter > filter)
Represents an absolute name.
static unique_ptr< Filter > create(const ConfigSection &configSection, const std::string &configFilename)
Create a filter from the configuration section.
boost::property_tree::ptree ConfigSection
void addChecker(unique_ptr< Checker > checker)
#define NDN_LOG_TRACE(expression)
Log at TRACE level.
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
create a checker from configuration section