24 const std::string& expression_str,
27 :
name_(name), expression_str_(expression_str), source_(source),
30 isc_throw(BadValue,
"BindingVariable - name cannot be empty");
35 if (expression_str_.empty()) {
36 isc_throw(BadValue,
"BindingVariable - '" << name_
37 <<
"' expression_str cannot be empty");
40 if (family_ != AF_INET && family_ != AF_INET6) {
42 <<
"', invalid family: " << family_);
49 }
catch (
const std::exception& ex) {
50 isc_throw(
BadValue,
"BindingVariable - '" << name_ <<
"', error parsing expression: '"
51 << expression_str_ <<
"' : " << ex.what());
75 if (source_str ==
"query") {
77 }
else if (source_str ==
"response") {
81 <<
"', must be either 'query' or 'response'");
86 }
catch (
const std::exception& ex) {
95 }
catch (
const std::exception& ex) {
96 isc_throw(
BadValue,
"BindingVariable - " << name_ <<
", error evaluating expression: ["
97 << expression_str_ <<
"] : " << ex.what());
111 : variables_(), mutex_(new std::mutex) {
117 auto retpair = variables_.push_back(variable);
118 return(retpair.second);
133 return (variables_.size());
136boost::posix_time::ptime
148 for (
auto const& variable : index) {
152 var_list->push_back(variable);
163 auto var_iter = index.find(name);
173 auto lower_limit = index.lower_bound(source);
174 auto upper_limit = index.upper_bound(source);
175 for (
auto var_iter = lower_limit; var_iter != upper_limit; ++var_iter) {
176 var_list->push_back(*var_iter);
184 if (family_ != AF_INET && family_ != AF_INET6) {
208 for (
auto const& var_elem : elem->listValue()) {
211 cache_->add(variable);
212 }
catch (
const std::exception& ex) {
220 if (!query || !response || !lease) {
221 isc_throw(
BadValue,
"evaluateVariables - missing query, response, and/or lease");
224 if (!cache_->size()) {
231 auto const variables = cache_->getAll();
233 for (
auto const& variable : *variables) {
237 *query : *response));
239 }
catch (
const std::exception& ex) {
244 return (lease->updateUserContextISC(
"binding-variables", values));
21namespace lease_cmds {
…}
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an unexpected error condition occurs.
boost::posix_time::ptime getModificationTime() const
Returns timestamp.
void updateModificationTime()
Sets timestamp to the current time.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
To be removed. Please use ConfigError instead.
Evaluation context, an interface to the expression evaluation.
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
@ PARSER_STRING
expression is expected to evaluate to string
isc::dhcp::Expression expression_
Parsed expression (output tokens are stored here)
BindingVariableCache stores binding variables.
BindingVariableListPtr getBySource(const BindingVariable::Source &source)
Fetches all of the binding variables in the order they were added to the cache that use a specific so...
size_t size()
Returns number of entries in the cache.
void clear()
Delete all the entries in the cache.
BindingVariablePtr getByName(const std::string &name)
Fetches a binding variable by name.
BindingVariableListPtr getAll()
Fetches all of the binding variables in the order they were added to the cache.
boost::posix_time::ptime getLastFlushTime()
Returns the last time the cache was flushed (or the time it was created if it has never been flushed)...
BindingVariableCache()
Constructor.
bool add(BindingVariablePtr variable)
Adds (or replaces) the variable in the cache.
bool evaluateVariables(dhcp::PktPtr query, dhcp::PktPtr response, dhcp::LeasePtr lease)
Evaluates the binding variables for a given lease and packet pair.
BindingVariableMgr(uint32_t family)
Constructor.
void configure(data::ConstElementPtr config)
Configures the manager based on the given configuration.
static const data::SimpleKeywords CONFIG_KEYWORDS
List of valid configurable parameters for a BindingVariable.
Source
Specifies the packet that the expression should be evaluated against.
std::string evaluate(dhcp::PktPtr packet) const
Evaluate the variable against the given packet.
virtual data::ElementPtr toElement() const
Creates an Element tree for the variable's configurable members.
BindingVariable(const std::string &name, const std::string &expression_str, const Source &source, uint32_t family)
Constructor.
static BindingVariablePtr parse(data::ConstElementPtr config, uint16_t family)
Parses configuration elements into a BindingVarable instance.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
std::string evaluateString(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a string value.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
boost::shared_ptr< BindingVariable > BindingVariablePtr
Defines a shared pointer to a BindingVariable.
std::list< BindingVariablePtr > BindingVariableList
Defines a list of BindingVariablePtr instances.
boost::shared_ptr< BindingVariableList > BindingVariableListPtr
Defines a pointer to a list of BindingVariablePtrs.
Defines the logger used by the top-level component of kea-lfc.
Tag for the sequence index.
Tag for the source index.
RAII lock object to protect the code in the same scope with a mutex.