Kea 2.7.8
isc::lease_cmds::BindingVariable Class Reference

Embodies a named expression, whose output when evaluated can be stored in a lease's user-context. More...

#include <binding_variables.h>

+ Inheritance diagram for isc::lease_cmds::BindingVariable:

Public Types

enum  Source { QUERY , RESPONSE }
 Specifies the packet that the expression should be evaluated against. More...
 

Public Member Functions

 BindingVariable (const std::string &name, const std::string &expression_str, const Source &source, uint32_t family)
 Constructor.
 
virtual ~BindingVariable ()=default
 Destructor.
 
std::string evaluate (dhcp::PktPtr packet) const
 Evaluate the variable against the given packet.
 
dhcp::ExpressionPtr getExpression () const
 Fetches the variable's parsed expression.
 
std::string getExpressionStr () const
 Fetches the variable's pre-parsed expression string.
 
uint32_t getFamily () const
 Fetches the variable's protocol family.
 
std::string getName () const
 Fetches the variable's name.
 
Source getSource () const
 Fetches the variable's packet source.
 
virtual data::ElementPtr toElement () const
 Creates an Element tree for the variable's configurable members.
 
- Public Member Functions inherited from isc::data::CfgToElement
virtual ~CfgToElement ()
 Destructor.
 

Static Public Member Functions

static BindingVariablePtr parse (data::ConstElementPtr config, uint16_t family)
 Parses configuration elements into a BindingVarable instance.
 

Static Public Attributes

static const data::SimpleKeywords CONFIG_KEYWORDS
 List of valid configurable parameters for a BindingVariable.
 

Detailed Description

Embodies a named expression, whose output when evaluated can be stored in a lease's user-context.

Definition at line 37 of file binding_variables.h.

Member Enumeration Documentation

◆ Source

Specifies the packet that the expression should be evaluated against.

Enumerator
QUERY 
RESPONSE 

Definition at line 41 of file binding_variables.h.

Constructor & Destructor Documentation

◆ BindingVariable()

isc::lease_cmds::BindingVariable::BindingVariable ( const std::string & name,
const std::string & expression_str,
const Source & source,
uint32_t family )

Constructor.

Parameters
namename of the variable, must be unique. Used both as the key and as the label for the value in the output.
expression_strEvaluation expression text.
sourceSource packet the expression should be evaluated against, either QUERY or RESPONSE.
familyProtocol family of the expression, either AF_INET or AF_INET6.

During construction the expression string is parsed for the protocol family.

Exceptions
BadValueif name if empty, or expression string fails to parse.
Todo
If we add scopes we may wish to allow higher order scopes to override lower scopes with empty expressions.

Definition at line 23 of file binding_variables.cc.

References isc::eval::EvalContext::expression_, if(), isc_throw, isc::eval::EvalContext::PARSER_STRING, isc::eval::EvalContext::parseString(), isc::dhcp::Option::V4, and isc::dhcp::Option::V6.

Referenced by parse().

+ Here is the call graph for this function:

◆ ~BindingVariable()

virtual isc::lease_cmds::BindingVariable::~BindingVariable ( )
virtualdefault

Destructor.

Member Function Documentation

◆ evaluate()

std::string isc::lease_cmds::BindingVariable::evaluate ( dhcp::PktPtr packet) const

Evaluate the variable against the given packet.

Parameters
packetPointer to the target packet.
Returns
string result of the evaluation.
Exceptions
BadValueif an evaluation error occurs.

Definition at line 92 of file binding_variables.cc.

References isc::dhcp::evaluateString(), and isc_throw.

+ Here is the call graph for this function:

◆ getExpression()

dhcp::ExpressionPtr isc::lease_cmds::BindingVariable::getExpression ( ) const
inline

Fetches the variable's parsed expression.

Returns
pointer to the expression.

Definition at line 103 of file binding_variables.h.

◆ getExpressionStr()

std::string isc::lease_cmds::BindingVariable::getExpressionStr ( ) const
inline

Fetches the variable's pre-parsed expression string.

Returns
string containing the expression.

Definition at line 96 of file binding_variables.h.

◆ getFamily()

uint32_t isc::lease_cmds::BindingVariable::getFamily ( ) const
inline

Fetches the variable's protocol family.

Returns
Family of the packet i.e AF_INET or AF_INET6.

Definition at line 117 of file binding_variables.h.

◆ getName()

std::string isc::lease_cmds::BindingVariable::getName ( ) const
inline

Fetches the variable's name.

Returns
string containing the name.

Definition at line 89 of file binding_variables.h.

◆ getSource()

Source isc::lease_cmds::BindingVariable::getSource ( ) const
inline

Fetches the variable's packet source.

Returns
Source of the packet.

Definition at line 110 of file binding_variables.h.

◆ parse()

BindingVariablePtr isc::lease_cmds::BindingVariable::parse ( data::ConstElementPtr config,
uint16_t family )
static

Parses configuration elements into a BindingVarable instance.

Parameters
configMap Element containing parameters for a single binding variable.
familyProtocol family of the variable, either AF_INET or AF_INET6.
Returns
Pointer to the newly created BindingVariable instance.
Exceptions
DhcpConfigErrorif configuration parameters are invalid.

Definition at line 64 of file binding_variables.cc.

References BindingVariable(), isc::data::SimpleParser::checkKeywords(), CONFIG_KEYWORDS, isc::data::SimpleParser::getString(), isc_throw, QUERY, and RESPONSE.

Referenced by isc::lease_cmds::BindingVariableMgr::configure().

+ Here is the call graph for this function:

◆ toElement()

ElementPtr isc::lease_cmds::BindingVariable::toElement ( ) const
virtual

Creates an Element tree for the variable's configurable members.

Returns
ElementPtr containing the configurable members.

Implements isc::data::CfgToElement.

Definition at line 102 of file binding_variables.cc.

References isc::data::Element::create(), isc::data::Element::createMap(), and QUERY.

+ Here is the call graph for this function:

Member Data Documentation

◆ CONFIG_KEYWORDS

const data::SimpleKeywords isc::lease_cmds::BindingVariable::CONFIG_KEYWORDS
static
Initial value:
=
{
{ "name", Element::string },
{ "expression", Element::string },
{ "source", Element::string }
}

List of valid configurable parameters for a BindingVariable.

Definition at line 47 of file binding_variables.h.

Referenced by parse().


The documentation for this class was generated from the following files: