23 const std::string& expression_str,
26 : name_(name), expression_str_(expression_str), source_(source),
29 isc_throw(BadValue,
"BindingVariable - name cannot be empty");
34 if (expression_str_.empty()) {
35 isc_throw(BadValue,
"BindingVariable - '" << name_
36 <<
"' expression_str cannot be empty");
39 if (family_ != AF_INET && family_ != AF_INET6) {
41 <<
"', invalid family: " << family_);
48 }
catch (
const std::exception& ex) {
49 isc_throw(
BadValue,
"BindingVariable - '" << name_ <<
"', error parsing expression: '"
50 << expression_str_ <<
"' : " << ex.what());
74 if (source_str ==
"query") {
76 }
else if (source_str ==
"response") {
80 <<
"', must be either 'query' or 'response'");
85 }
catch (
const std::exception& ex) {
94 }
catch (
const std::exception& ex) {
95 isc_throw(
BadValue,
"BindingVariable - " << name_ <<
", error evaluating expression: ["
96 << expression_str_ <<
"] : " << ex.what());
110 : variables_(), mutex_(new std::mutex) {
116 auto retpair = variables_.push_back(variable);
117 return(retpair.second);
132 return (variables_.size());
135boost::posix_time::ptime
147 for (
auto const& variable : index) {
151 var_list->push_back(variable);
162 auto var_iter = index.find(name);
172 auto lower_limit = index.lower_bound(source);
173 auto upper_limit = index.upper_bound(source);
174 for (
auto var_iter = lower_limit; var_iter != upper_limit; ++var_iter) {
175 var_list->push_back(*var_iter);
183 if (family_ != AF_INET && family_ != AF_INET6) {
207 for (
auto const& var_elem : elem->listValue()) {
210 cache_->add(variable);
211 }
catch (
const std::exception& ex) {
219 if (!query || !response || !lease) {
220 isc_throw(
BadValue,
"evaluateVariables - missing query, response, and/or lease");
223 if (!cache_->size()) {
230 auto const variables = cache_->getAll();
232 for (
auto const& variable : *variables) {
236 *query : *response));
238 }
catch (
const std::exception& ex) {
243 return (lease->updateUserContextISC(
"binding-variables", values));
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
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 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.
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.
Source
Specifies the packet that the expression should be evaluated against.
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.