Kea  2.1.7-git
isc::dhcp::TokenOption Class Reference

Token that represents a value of an option. More...

#include <token.h>

+ Inheritance diagram for isc::dhcp::TokenOption:

Public Types

enum  RepresentationType { TEXTUAL, HEXADECIMAL, EXISTS }
 Token representation type. More...
 

Public Member Functions

 TokenOption (const uint16_t option_code, const RepresentationType &rep_type)
 Constructor that takes an option code as a parameter. More...
 
void evaluate (Pkt &pkt, ValueStack &values)
 Evaluates the values of the option. More...
 
uint16_t getCode () const
 Returns option-code. More...
 
RepresentationType getRepresentation () const
 Returns representation-type. More...
 
- Public Member Functions inherited from isc::dhcp::Token
virtual ~Token ()
 Virtual destructor. More...
 

Protected Member Functions

virtual OptionPtr getOption (Pkt &pkt)
 Attempts to retrieve an option. More...
 
virtual std::string pushFailure (ValueStack &values)
 Auxiliary method that puts string representing a failure. More...
 

Protected Attributes

uint16_t option_code_
 Code of the option to be extracted. More...
 
RepresentationType representation_type_
 Representation type. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from isc::dhcp::Token
static bool toBool (std::string value)
 Coverts a (string) value to a boolean. More...
 

Detailed Description

Token that represents a value of an option.

This represents a reference to a given option, e.g. in the expression option[vendor-class].text == "MSFT", it represents option[vendor-class].text

During the evaluation it tries to extract the value of the specified option. If the option is not found, an empty string ("") is returned (or "false" when the representation is EXISTS).

Definition at line 344 of file token.h.

Member Enumeration Documentation

◆ RepresentationType

Token representation type.

There are many possible ways in which option can be presented. Currently the textual, hexadecimal and exists representations are supported. The type of representation is specified in the constructor and it affects the value generated by the TokenOption::evaluate function.

Enumerator
TEXTUAL 
HEXADECIMAL 
EXISTS 

Definition at line 354 of file token.h.

Constructor & Destructor Documentation

◆ TokenOption()

isc::dhcp::TokenOption::TokenOption ( const uint16_t  option_code,
const RepresentationType rep_type 
)
inline

Constructor that takes an option code as a parameter.

Note: There is no constructor that takes option_name, as it would introduce complex dependency of the libkea-eval on libdhcpsrv.

Parameters
option_codecode of the option to be represented.
rep_typeToken representation type.

Definition at line 367 of file token.h.

Member Function Documentation

◆ evaluate()

void TokenOption::evaluate ( Pkt pkt,
ValueStack values 
)
virtual

Evaluates the values of the option.

This token represents a value of the option, so this method attempts to extract the option from the packet and put its value on the stack. If the option is not there, an empty string ("") is put on the stack.

Parameters
pktspecified option will be extracted from this packet (if present)
valuesvalue of the option will be pushed here (or "")

Implements isc::dhcp::Token.

Reimplemented in isc::dhcp::TokenSubOption, isc::dhcp::TokenVendorClass, and isc::dhcp::TokenVendor.

Definition at line 333 of file token.cc.

References isc::dhcp::EVAL_DBG_STACK, isc::dhcp::EVAL_DEBUG_OPTION, isc::dhcp::eval_logger, LOG_DEBUG, and isc::util::encode::toHex().

Referenced by isc::dhcp::TokenVendor::evaluate().

+ Here is the call graph for this function:

◆ getCode()

uint16_t isc::dhcp::TokenOption::getCode ( ) const
inline

Returns option-code.

This method is used in testing to determine if the parser had instantiated TokenOption with correct parameters.

Returns
option-code of the option this token expects to extract.

Definition at line 386 of file token.h.

◆ getOption()

OptionPtr TokenOption::getOption ( Pkt pkt)
protectedvirtual

Attempts to retrieve an option.

For this class it simply attempts to retrieve the option from the packet, but there may be derived classes that would attempt to extract it from other places (e.g. relay option, or as a suboption of other specific option).

Parameters
pktthe option will be retrieved from here
Returns
option instance (or NULL if not found)

Reimplemented in isc::dhcp::TokenVendor, isc::dhcp::TokenRelay6Option, and isc::dhcp::TokenRelay4Option.

Definition at line 328 of file token.cc.

References isc::dhcp::Pkt::getOption().

+ Here is the call graph for this function:

◆ getRepresentation()

RepresentationType isc::dhcp::TokenOption::getRepresentation ( ) const
inline

Returns representation-type.

This method is used in testing to determine if the parser had instantiated TokenOption with correct parameters.

Returns
representation-type of the option this token expects to use.

Definition at line 396 of file token.h.

◆ pushFailure()

std::string TokenOption::pushFailure ( ValueStack values)
protectedvirtual

Auxiliary method that puts string representing a failure.

Depending on the representation type, this is either "" or "false".

Parameters
valuesa string representing failure will be pushed here.
Returns
value pushed

Definition at line 371 of file token.cc.

Referenced by isc::dhcp::TokenVendor::evaluate(), and isc::dhcp::TokenVendorClass::evaluate().

Member Data Documentation

◆ option_code_

uint16_t isc::dhcp::TokenOption::option_code_
protected

Code of the option to be extracted.

Definition at line 420 of file token.h.

Referenced by isc::dhcp::TokenRelay4Option::getOption(), isc::dhcp::TokenRelay6Option::getOption(), and isc::dhcp::TokenVendor::getOption().

◆ representation_type_

RepresentationType isc::dhcp::TokenOption::representation_type_
protected

Representation type.

Definition at line 421 of file token.h.

Referenced by isc::dhcp::TokenVendor::TokenVendor().


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