25 #include <boost/algorithm/string/predicate.hpp> 32 namespace validator_config {
57 BOOST_THROW_EXCEPTION(
Error(
"Invalid packet type supplied (" +
67 retval |= filter->match(pktType, pktName);
76 Rule::check(uint32_t pktType,
const Name& pktName,
const Name& klName,
const shared_ptr<ValidationState>& state)
const 78 NDN_LOG_TRACE(
"Trying to check " << pktName <<
" with keyLocator " << klName);
81 BOOST_THROW_EXCEPTION(
Error(
"Invalid packet type supplied (" +
85 bool hasPendingResult =
false;
87 bool result = checker->check(pktType, pktName, klName, state);
91 hasPendingResult =
true;
94 return hasPendingResult;
100 auto propertyIt = configSection.begin();
103 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"id")) {
104 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.id>"));
107 std::string ruleId = propertyIt->second.data();
111 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"for")) {
112 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.for> in rule: " + ruleId));
115 std::string usage = propertyIt->second.data();
118 bool isForData =
false;
119 if (boost::iequals(usage,
"data")) {
122 else if (boost::iequals(usage,
"interest")) {
126 BOOST_THROW_EXCEPTION(
Error(
"Unrecognized <rule.for>: " + usage +
" in rule: " + ruleId));
132 for (; propertyIt != configSection.end(); propertyIt++) {
133 if (!boost::iequals(propertyIt->first,
"filter")) {
134 if (boost::iequals(propertyIt->first,
"checker")) {
137 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.filter> in rule: " + ruleId));
140 rule->addFilter(
Filter::create(propertyIt->second, configFilename));
144 bool hasCheckers =
false;
145 for (; propertyIt != configSection.end(); propertyIt++) {
146 if (!boost::iequals(propertyIt->first,
"checker")) {
147 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.checker> in rule: " + ruleId));
155 if (propertyIt != configSection.end()) {
156 BOOST_THROW_EXCEPTION(
Error(
"Expecting the end of rule: " + ruleId));
160 BOOST_THROW_EXCEPTION(
Error(
"No <rule.checker> is specified in rule: " + ruleId));
Rule(const std::string &id, uint32_t pktType)
Copyright (c) 2011-2015 Regents of the University of California.
static unique_ptr< Rule > create(const ConfigSection &configSection, const std::string &configFilename)
create a rule from configuration section
bool check(uint32_t pktType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) const
check if packet satisfies rule's condition
#define NDN_LOG_INIT(name)
declare a log module
std::vector< unique_ptr< Checker > > m_checkers
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)
std::string to_string(const V &v)
#define NDN_LOG_TRACE(expression)
std::vector< unique_ptr< Filter > > m_filters
bool match(uint32_t pktType, const Name &pktName) const
check if the packet name matches rule's filter
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
create a checker from configuration section