Kea 3.1.1
isc::ddns_tuning::DdnsTuningImpl Class Reference

DDNS Tuning implementation. More...

#include <ddns_tuning.h>

Public Member Functions

 DdnsTuningImpl (uint16_t family=AF_INET)
 Constructor.
 
 ~DdnsTuningImpl ()
 Destructor.
 
dhcp::ExpressionPtr cacheExpression (dhcp::ConstSubnetPtr subnet)
 Caches an expression entry for a given subnet.
 
std::string calculateHostname (dhcp::PktPtr query, dhcp::ConstSubnetPtr subnet)
 Calculate the hostname for a packet given a subnet.
 
void configure (isc::data::ConstElementPtr params)
 Configure the Ddns Tuning implementation.
 
dhcp::ExpressionPtr fetchScopedHostnameExpression (dhcp::ConstSubnetPtr subnet)
 Fetches the expression that is in scope for the given subnet.
 
void flushCache (bool preserve_global=true)
 Flushes the cache contents.
 
size_t getCacheSize ()
 Fetches the number of entries in the cache.
 
uint16_t getFamily ()
 Returns the protocol family of the address list.
 
dhcp::ExpressionPtr getGlobalHostnameExpression ()
 Get the global hostname expression.
 
dhcp::ExpressionPtr getHostnameExpression (const dhcp::SubnetID &subnet_id)
 Fetches the hostname for a given subnet_id.
 
boost::posix_time::ptime getLastFlushTime ()
 Fetches the time (in seconds) of when the cache was last flushed.
 
dhcp::ExpressionPtr parseExpression (const std::string &expression_str) const
 Parses an expression string into an Expression.
 
template<typename CfgSubnetPtrType>
int repopulateCache (const CfgSubnetPtrType cfg_subnets)
 Repopulates the expression cache from the given subnet configuration.
 
void setGlobalHostnameExpression (dhcp::ExpressionPtr &expression)
 Set the global hostname expression.
 
void setHostnameExpression (const dhcp::SubnetID &subnet_id, dhcp::ExpressionPtr &expression)
 Set the hostname expression for a given subnet.
 

Protected Attributes

ExpressionCache subnet_exprs_
 Per subnet expression cache.
 

Detailed Description

DDNS Tuning implementation.

The implementation can be divided into two parts:

  • the configuration parsed and stored by load()
  • logic to parse, cache, and evaluate hostname expressions

As features are adding, this class is likely to expand.

Definition at line 37 of file ddns_tuning.h.

Constructor & Destructor Documentation

◆ DdnsTuningImpl()

isc::ddns_tuning::DdnsTuningImpl::DdnsTuningImpl ( uint16_t family = AF_INET)
inline

Constructor.

Parameters
familyProtocol family of the server which owns this instance.

Definition at line 42 of file ddns_tuning.h.

◆ ~DdnsTuningImpl()

isc::ddns_tuning::DdnsTuningImpl::~DdnsTuningImpl ( )

Destructor.

Definition at line 29 of file ddns_tuning.cc.

Member Function Documentation

◆ cacheExpression()

ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::cacheExpression ( dhcp::ConstSubnetPtr subnet)

Caches an expression entry for a given subnet.

If the subnet specifies an expression string via user-context, it is parsed and if successful, the resulting expression is cached. If the parsing fails, the error is logged and an empty pointer is cached for the subnet. If the subnet does not specify an expression string an empty pointer is cached for it.

Parameters
subnetsubnet to process.
Returns
a pointer to the parsed expression.

Definition at line 124 of file ddns_tuning.cc.

References isc::log::DBGLVL_TRACE_BASIC, isc::ddns_tuning::ddns_tuning_logger, DDNS_TUNING_SUBNET_EXPRESSION_PARSE, isc_throw, LOG_DEBUG, Element::map, parseExpression(), setHostnameExpression(), and Element::string.

Referenced by fetchScopedHostnameExpression(), and repopulateCache().

+ Here is the call graph for this function:

◆ calculateHostname()

std::string isc::ddns_tuning::DdnsTuningImpl::calculateHostname ( dhcp::PktPtr query,
dhcp::ConstSubnetPtr subnet )

Calculate the hostname for a packet given a subnet.

Fetches the hostname expression that is in scope for the given subnet, and if found, uses it in conjunction with the given packet, to calculate the hostname.

Parameters
querythe inbound client packet.
subnetthe subnet selected for the packet.
Returns
string containing the calculated hostname, or an empty string if there is either no expression in scope or the expression is an empty expression.

Definition at line 183 of file ddns_tuning.cc.

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

+ Here is the call graph for this function:

◆ configure()

void isc::ddns_tuning::DdnsTuningImpl::configure ( isc::data::ConstElementPtr params)

Configure the Ddns Tuning implementation.

Parameters
paramsThe JSON element with the expression.
Exceptions
BadValueand similar exceptions on error.

Definition at line 32 of file ddns_tuning.cc.

References DDNS_TUNING_GLOBAL_EXPR_SET, isc::ddns_tuning::ddns_tuning_logger, flushCache(), isc_throw, LOG_INFO, Element::map, parseExpression(), setGlobalHostnameExpression(), and Element::string.

+ Here is the call graph for this function:

◆ fetchScopedHostnameExpression()

ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::fetchScopedHostnameExpression ( dhcp::ConstSubnetPtr subnet)

Fetches the expression that is in scope for the given subnet.

Hostname expressions are cached to avoid parsing them each time they might be needed. An entry is made in the cache for each subnet the first time after the cache has been flushed, that the subnet is presented. If subnet does not specify an expression, then an empty pointer is cached for it.

The expression to use is determined as follows:

  1. If the subnet has been modified since the cache was last flushed, (i.e. subnet state is newer than the cache) then we flush the cache and goto step 3.
  2. Subnet hasn't changed since the last flush. If the cache contains an entry for the subnet that is not an empty pointer, return it.
  3. If the subnet specifies an expression (via user-context) parse it, add it to the cache, and return it. If it does not specify an expression cache an empty pointer for the subnet.
  4. Return the global hostname expression or an empty pointer.
Parameters
subnetthe subnet for the which expression is desired.
Returns
pointer to the expression in scope for the subnet.

Definition at line 89 of file ddns_tuning.cc.

References cacheExpression(), isc::log::DBGLVL_TRACE_BASIC, isc::ddns_tuning::ddns_tuning_logger, DDNS_TUNING_SUBNET_EXPR_CACHED, flushCache(), getGlobalHostnameExpression(), isc_throw, LOG_DEBUG, and subnet_exprs_.

Referenced by calculateHostname().

+ Here is the call graph for this function:

◆ flushCache()

void isc::ddns_tuning::DdnsTuningImpl::flushCache ( bool preserve_global = true)

Flushes the cache contents.

Parameters
preserve_globalif true the global expression is saved and then restored to the cache after the flushing of the subnet content.

Definition at line 198 of file ddns_tuning.cc.

References getGlobalHostnameExpression(), setGlobalHostnameExpression(), and subnet_exprs_.

Referenced by configure(), fetchScopedHostnameExpression(), and repopulateCache().

+ Here is the call graph for this function:

◆ getCacheSize()

size_t isc::ddns_tuning::DdnsTuningImpl::getCacheSize ( )

Fetches the number of entries in the cache.

Returns
cache entry count, including the global expression.

Definition at line 211 of file ddns_tuning.cc.

References subnet_exprs_.

◆ getFamily()

uint16_t isc::ddns_tuning::DdnsTuningImpl::getFamily ( )
inline

Returns the protocol family of the address list.

Definition at line 157 of file ddns_tuning.h.

◆ getGlobalHostnameExpression()

ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::getGlobalHostnameExpression ( )

Get the global hostname expression.

Returns
the global expression or an empty pointer if no global expression has been configured.

Definition at line 80 of file ddns_tuning.cc.

References getHostnameExpression().

Referenced by fetchScopedHostnameExpression(), and flushCache().

+ Here is the call graph for this function:

◆ getHostnameExpression()

ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::getHostnameExpression ( const dhcp::SubnetID & subnet_id)

Fetches the hostname for a given subnet_id.

Parameters
subnet_idID for which the expression is desired.
Returns
the subnet expression or an empty pointer if no subnet expression has been configured.

Definition at line 73 of file ddns_tuning.cc.

References subnet_exprs_.

Referenced by getGlobalHostnameExpression().

◆ getLastFlushTime()

boost::posix_time::ptime isc::ddns_tuning::DdnsTuningImpl::getLastFlushTime ( )

Fetches the time (in seconds) of when the cache was last flushed.

The mechanism relies on the BaseStampedElement::modification_time_ which is currently the local time in seconds.

Returns
time of the last flush.

Definition at line 216 of file ddns_tuning.cc.

References subnet_exprs_.

◆ parseExpression()

ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::parseExpression ( const std::string & expression_str) const

Parses an expression string into an Expression.

Parameters
expression_strstring containing the expression.
Returns
a pointer to the parsed expression.
Exceptions
BadValueif the expression syntax is invalid.

Definition at line 162 of file ddns_tuning.cc.

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

Referenced by cacheExpression(), and configure().

+ Here is the call graph for this function:

◆ repopulateCache()

template<typename CfgSubnetPtrType>
int isc::ddns_tuning::DdnsTuningImpl::repopulateCache ( const CfgSubnetPtrType cfg_subnets)
inline

Repopulates the expression cache from the given subnet configuration.

Flushes the cache contents, while preserving the global expression, and then iterates over the configured subnets, parsing and caching the hostname expression for each.

Template Parameters
CfgSubnetPtrTypetype of the subnet configuration: CfgSubnet4Ptr or CfgSubnet6Ptr
Parameters
cfg_subnetssubnet configuration containing the subnets to process
Returns
0 if successful, 1 otherwise

Definition at line 172 of file ddns_tuning.h.

References cacheExpression(), isc::ddns_tuning::ddns_tuning_logger, DDNS_TUNING_SUBNET_EXPRESSION_PARSE_ERROR, flushCache(), and LOG_ERROR.

+ Here is the call graph for this function:

◆ setGlobalHostnameExpression()

void isc::ddns_tuning::DdnsTuningImpl::setGlobalHostnameExpression ( dhcp::ExpressionPtr & expression)

Set the global hostname expression.

Parameters
expressionexpression to store as the global expression.

Definition at line 84 of file ddns_tuning.cc.

References setHostnameExpression().

Referenced by configure(), and flushCache().

+ Here is the call graph for this function:

◆ setHostnameExpression()

void isc::ddns_tuning::DdnsTuningImpl::setHostnameExpression ( const dhcp::SubnetID & subnet_id,
dhcp::ExpressionPtr & expression )

Set the hostname expression for a given subnet.

Parameters
subnet_idID for which the expression is desired.
expressionpointer to the expression to store.

Definition at line 68 of file ddns_tuning.cc.

References subnet_exprs_.

Referenced by cacheExpression(), and setGlobalHostnameExpression().

Member Data Documentation

◆ subnet_exprs_

ExpressionCache isc::ddns_tuning::DdnsTuningImpl::subnet_exprs_
protected

Per subnet expression cache.

Note we store the global expression in here under SUBNET_ID_GLOBAL.

Definition at line 197 of file ddns_tuning.h.

Referenced by fetchScopedHostnameExpression(), flushCache(), getCacheSize(), getHostnameExpression(), getLastFlushTime(), and setHostnameExpression().


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