![]() |
Kea 3.1.1
|
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. | |
DDNS Tuning implementation.
The implementation can be divided into two parts:
As features are adding, this class is likely to expand.
Definition at line 37 of file ddns_tuning.h.
|
inline |
Constructor.
family | Protocol family of the server which owns this instance. |
Definition at line 42 of file ddns_tuning.h.
isc::ddns_tuning::DdnsTuningImpl::~DdnsTuningImpl | ( | ) |
Destructor.
Definition at line 29 of file ddns_tuning.cc.
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.
subnet | subnet to process. |
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().
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.
query | the inbound client packet. |
subnet | the subnet selected for the packet. |
Definition at line 183 of file ddns_tuning.cc.
References isc::dhcp::evaluateString(), and fetchScopedHostnameExpression().
void isc::ddns_tuning::DdnsTuningImpl::configure | ( | isc::data::ConstElementPtr | params | ) |
Configure the Ddns Tuning implementation.
params | The JSON element with the expression. |
BadValue | and 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.
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:
subnet | the subnet for the which expression is desired. |
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().
void isc::ddns_tuning::DdnsTuningImpl::flushCache | ( | bool | preserve_global = true | ) |
Flushes the cache contents.
preserve_global | if 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().
size_t isc::ddns_tuning::DdnsTuningImpl::getCacheSize | ( | ) |
Fetches the number of entries in the cache.
Definition at line 211 of file ddns_tuning.cc.
References subnet_exprs_.
|
inline |
Returns the protocol family of the address list.
Definition at line 157 of file ddns_tuning.h.
ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::getGlobalHostnameExpression | ( | ) |
Get the global hostname expression.
Definition at line 80 of file ddns_tuning.cc.
References getHostnameExpression().
Referenced by fetchScopedHostnameExpression(), and flushCache().
ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::getHostnameExpression | ( | const dhcp::SubnetID & | subnet_id | ) |
Fetches the hostname for a given subnet_id.
subnet_id | ID for which the expression is desired. |
Definition at line 73 of file ddns_tuning.cc.
References subnet_exprs_.
Referenced by getGlobalHostnameExpression().
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.
Definition at line 216 of file ddns_tuning.cc.
References subnet_exprs_.
ExpressionPtr isc::ddns_tuning::DdnsTuningImpl::parseExpression | ( | const std::string & | expression_str | ) | const |
Parses an expression string into an Expression.
expression_str | string containing the expression. |
BadValue | if 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().
|
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.
CfgSubnetPtrType | type of the subnet configuration: CfgSubnet4Ptr or CfgSubnet6Ptr |
cfg_subnets | subnet configuration containing the subnets to process |
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.
void isc::ddns_tuning::DdnsTuningImpl::setGlobalHostnameExpression | ( | dhcp::ExpressionPtr & | expression | ) |
Set the global hostname expression.
expression | expression to store as the global expression. |
Definition at line 84 of file ddns_tuning.cc.
References setHostnameExpression().
Referenced by configure(), and flushCache().
void isc::ddns_tuning::DdnsTuningImpl::setHostnameExpression | ( | const dhcp::SubnetID & | subnet_id, |
dhcp::ExpressionPtr & | expression ) |
Set the hostname expression for a given subnet.
subnet_id | ID for which the expression is desired. |
expression | pointer to the expression to store. |
Definition at line 68 of file ddns_tuning.cc.
References subnet_exprs_.
Referenced by cacheExpression(), and setGlobalHostnameExpression().
|
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().