Kea 2.7.1
isc::dhcp::NetworkState Class Reference

Controls the DHCP service enabling status. More...

#include <network_state.h>

+ Inheritance diagram for isc::dhcp::NetworkState:

Public Types

typedef std::set< std::string > Networks
 Type of the container holding collection of shared network names.
 
typedef std::set< SubnetIDSubnets
 Type of the container holding collection of subnet identifiers.
 

Public Member Functions

 NetworkState ()
 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.
 
void resetForLocalCommands ()
 Reset origins for local commands.
 
void resetForRemoteCommands ()
 Reset origins for remote commands.
 
- Public Member Functions inherited from isc::data::CfgToElement
virtual ~CfgToElement ()
 Destructor.
 

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.
 
virtual isc::data::ElementPtr toElement () const
 The network state as Element.
 

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.
static const unsigned int HA_LOCAL_COMMAND
The network state is being altered by an HA internal command.
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 72 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 108 of file network_state.h.

◆ Subnets

Type of the container holding collection of subnet identifiers.

Definition at line 105 of file network_state.h.

Constructor & Destructor Documentation

◆ NetworkState()

isc::dhcp::NetworkState::NetworkState ( )

Constructor.

Definition at line 231 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 266 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 236 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 242 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 278 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 272 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 248 of file network_state.cc.

◆ resetForLocalCommands()

void isc::dhcp::NetworkState::resetForLocalCommands ( )

Reset origins for local commands.

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

Definition at line 254 of file network_state.cc.

◆ resetForRemoteCommands()

void isc::dhcp::NetworkState::resetForRemoteCommands ( )

Reset origins for remote commands.

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

Definition at line 260 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 293 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 288 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 303 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 298 of file network_state.cc.

References isc_throw.

◆ toElement()

ElementPtr isc::dhcp::NetworkState::toElement ( ) const
virtual

The network state as Element.

Returns
The network state as Element.

Implements isc::data::CfgToElement.

Definition at line 307 of file network_state.cc.

Member Data Documentation

◆ DB_CONNECTION

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

◆ 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 91 of file network_state.h.

Referenced by isc::dhcp::NetworkStateImpl::resetForLocalCommands(), and isc::dhcp::NetworkStateImpl::toElement().

◆ 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 98 of file network_state.h.

Referenced by isc::dhcp::NetworkStateImpl::resetForLocalCommands(), isc::dhcp::NetworkStateImpl::resetForRemoteCommands(), isc::ha::HAImpl::syncCompleteNotifyHandler(), and isc::dhcp::NetworkStateImpl::toElement().

◆ 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 85 of file network_state.h.

Referenced by isc::dhcp::NetworkStateImpl::toElement().


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