Kea 2.5.9
isc::dhcp::NetworkState Class Reference

Controls the DHCP service enabling status. More...

#include <network_state.h>

Public Types

typedef std::set< std::string > Networks
 Type of the container holding collection of shared network names.
 
enum  ServerType { DHCPv4 , DHCPv6 }
 DHCP server type. More...
 
typedef std::set< SubnetIDSubnets
 Type of the container holding collection of subnet identifiers.
 

Public Member Functions

 NetworkState (const ServerType &server_type)
 Constructor.
 
void delayedEnableService (const unsigned int seconds, unsigned int origin)
 Schedules enabling DHCP service in the future.
 
void disableService (unsigned int origin)
 Disable the DHCP service state for respective transition origin.
 
void enableService (unsigned int origin)
 Enable the DHCP service state for respective transition origin.
 
bool isDelayedEnableService () const
 Checks if delayed enabling of DHCP services is scheduled.
 
bool isServiceEnabled () const
 Checks if the DHCP service is globally enabled.
 
void resetForDbConnection ()
 Reset internal counters for database connection.
 

Static Public Attributes

static const unsigned int DB_CONNECTION = 3000
 The network state is being altered by the DB connection recovery mechanics.
 
static const unsigned int HA_LOCAL_COMMAND = 1000
 The network state is being altered by an HA internal command.
 
static const unsigned int HA_REMOTE_COMMAND = 2000
 The network state is being altered by a "dhcp-disable" or "dhcp-enable" command sent by a HA partner.
 
static const unsigned int USER_COMMAND = 1
 Origin of the network state transition.
 

Selective disabling/enabling DHCP service per scopes

void selectiveDisable (const NetworkState::Subnets &subnets)
 Disable DHCP service for selected subnets.
 
void selectiveDisable (const NetworkState::Networks &networks)
 Disable DHCP service for selected networks.
 
void selectiveEnable (const NetworkState::Subnets &subnets)
 Enable DHCP service for selected subnets.
 
void selectiveEnable (const NetworkState::Networks &networks)
 Enable DHCP service for selected networks.
 

Detailed Description

Controls the DHCP service enabling status.

Sometimes, a DHCP server must pause responding to the DHCP queries. Typical cases include a database connection loss when the server tries to reconnect and various cases related to the High Availability operation. It is also possible to explicitly turn the DHCP service on and off via the control channel. This class receives calls from different origins to disable and re-enable the DHCP service.

The general rule is that the DHCP service must be disabled when the class receives at least one request to disable the service from any origin. The service must be re-enabled when all requestors previously disabling the service re-enabled it. This class also allows for specifying a timeout value for each request, after which the service gets re-enabled automatically. It is particularly useful in HA when there is no guarantee that the HA partner will be able to re-enable the service because it may experience an unexpected outage. In that case, the "max-period" parameter must accompany the "dhcp-disable" command to ensure that the service will eventually be re-enabled. The HA hook library may include several independent relationships. Each relationship is treated as a separate origin by this class. If one relationship disables the DHCP service, the service must remain disabled even when any other relationship requests enabling it. The service is re-enabled after all relationships requested re-enabling it (e.g., they all finished synchronizing the lease database).

The HA service instances must have unique identifiers they use to specify the origin. For example, an HAService with the identifier of 1 should request disabling the local service like this:

Controls the DHCP service enabling status.
Definition: network_state.h:71
static const unsigned int HA_LOCAL_COMMAND
The network state is being altered by an HA internal command.
Definition: network_state.h:96
void disableService(unsigned int origin)
Disable the DHCP service state for respective transition origin.

The DHCP state can also be altered by the database recovery mechanism, which disables the service on connection loss and re-enables it after the connection is restored. Unlike in HA, this is implemented using an internal counter. In this case, there is one origin for all database connections. The requests for the NetworkState::DB_CONNECTION are counted, and the DHCP service is re-enabled when the counter reaches 0.

Todo:
We should consider migrating the database recovery to the same mechanism we use for the HA. The reference counting works because the database connection classes ensure that for each request to disable the DHCP service, there is a corresponding request to enable the service. It prevents the situation that the service remains disabled because there were more requests to disable than to enable the service. It is hard to ensure the same consistency for the HA.

Definition at line 71 of file network_state.h.

Member Typedef Documentation

◆ Networks

typedef std::set<std::string> isc::dhcp::NetworkState::Networks

Type of the container holding collection of shared network names.

Definition at line 113 of file network_state.h.

◆ Subnets

Type of the container holding collection of subnet identifiers.

Definition at line 110 of file network_state.h.

Member Enumeration Documentation

◆ ServerType

DHCP server type.

Enumerator
DHCPv4 
DHCPv6 

Definition at line 75 of file network_state.h.

Constructor & Destructor Documentation

◆ NetworkState()

isc::dhcp::NetworkState::NetworkState ( const ServerType server_type)

Constructor.

Definition at line 173 of file network_state.cc.

Member Function Documentation

◆ delayedEnableService()

void isc::dhcp::NetworkState::delayedEnableService ( const unsigned int  seconds,
unsigned int  origin 
)

Schedules enabling DHCP service in the future.

Parameters
secondsNumber of seconds after which the service should be enabled unless enableAll is enabled before that time.
originThe origin of the state transition.

Definition at line 196 of file network_state.cc.

◆ disableService()

void isc::dhcp::NetworkState::disableService ( unsigned int  origin)

Disable the DHCP service state for respective transition origin.

Note
If any of the user commands, HA internal commands or connection recovery processes disable the dhcp service, the service will remain disabled until all flags are cleared.
Parameters
originThe origin of the state transition.

Definition at line 178 of file network_state.cc.

◆ enableService()

void isc::dhcp::NetworkState::enableService ( unsigned int  origin)

Enable the DHCP service state for respective transition origin.

Note
If any of the user commands, HA internal commands or connection recovery processes disable the dhcp service, the service will remain disabled until all flags are cleared.
Parameters
originThe origin of the state transition.

Definition at line 184 of file network_state.cc.

◆ isDelayedEnableService()

bool isc::dhcp::NetworkState::isDelayedEnableService ( ) const

Checks if delayed enabling of DHCP services is scheduled.

It indicates that the timer is present which counts the time until delayedEnable function will be called automatically.

Returns
true if delayed enabling of the DHCP service is scheduled, false otherwise.

Definition at line 208 of file network_state.cc.

References isc::dhcp::TimerMgr::instance().

+ Here is the call graph for this function:

◆ isServiceEnabled()

bool isc::dhcp::NetworkState::isServiceEnabled ( ) const

Checks if the DHCP service is globally enabled.

Returns
true if the service is globally enabled, false otherwise.

Definition at line 202 of file network_state.cc.

◆ resetForDbConnection()

void isc::dhcp::NetworkState::resetForDbConnection ( )

Reset internal counters for database connection.

It results in enabling the network service if network service for all other origins is enabled.

Definition at line 190 of file network_state.cc.

◆ selectiveDisable() [1/2]

void isc::dhcp::NetworkState::selectiveDisable ( const NetworkState::Networks networks)

Disable DHCP service for selected networks.

Parameters
networksCollection of shared network names for which the service should be disabled.
Exceptions
isc::NotImplemented

Definition at line 223 of file network_state.cc.

References isc_throw.

◆ selectiveDisable() [2/2]

void isc::dhcp::NetworkState::selectiveDisable ( const NetworkState::Subnets subnets)

Disable DHCP service for selected subnets.

Parameters
subnetsCollection of subnet identifiers for which the service should be disabled.
Exceptions
isc::NotImplemented

Definition at line 218 of file network_state.cc.

References isc_throw.

◆ selectiveEnable() [1/2]

void isc::dhcp::NetworkState::selectiveEnable ( const NetworkState::Networks networks)

Enable DHCP service for selected networks.

Parameters
networksCollection of shared network names for which the service should be enabled.
Exceptions
isc::NotImplemented

Definition at line 233 of file network_state.cc.

References isc_throw.

◆ selectiveEnable() [2/2]

void isc::dhcp::NetworkState::selectiveEnable ( const NetworkState::Subnets subnets)

Enable DHCP service for selected subnets.

Parameters
subnetsCollection of subnet identifiers for which the service should be disabled.
Exceptions
isc::NotImplemented

Definition at line 228 of file network_state.cc.

References isc_throw.

Member Data Documentation

◆ DB_CONNECTION

const unsigned int isc::dhcp::NetworkState::DB_CONNECTION = 3000
static

The network state is being altered by the DB connection recovery mechanics.

Definition at line 107 of file network_state.h.

Referenced by isc::dhcp::NetworkStateImpl::createTimer(), isc::dhcp::NetworkStateImpl::destroyTimer(), and isc::dhcp::NetworkStateImpl::setDisableService().

◆ HA_LOCAL_COMMAND

const unsigned int isc::dhcp::NetworkState::HA_LOCAL_COMMAND = 1000
static

The network state is being altered by an HA internal command.

Specify HA service-specific origins by adding a unique local service identifier to this constant.

Definition at line 96 of file network_state.h.

◆ HA_REMOTE_COMMAND

const unsigned int isc::dhcp::NetworkState::HA_REMOTE_COMMAND = 2000
static

The network state is being altered by a "dhcp-disable" or "dhcp-enable" command sent by a HA partner.

Specify HA service-specific origins by adding a unique remote service identifier to this constant.

Definition at line 103 of file network_state.h.

Referenced by isc::ha::HAImpl::syncCompleteNotifyHandler().

◆ USER_COMMAND

const unsigned int isc::dhcp::NetworkState::USER_COMMAND = 1
static

Origin of the network state transition.

The enumeration indicates the originator of the state transition of the network state: either user command, HA internal command or DB connection recovery mechanism.

The network state is being altered by a user command.

Specify unique origins for different commands by adding a number to this constant.

Definition at line 90 of file network_state.h.


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