13#include <boost/enable_shared_from_this.hpp>
17#include <unordered_set>
96 for (
auto const& origin : disabled_by_origin) {
112 for (
auto const& origin : disabled_by_origin) {
142 void createTimer(
const unsigned int seconds,
unsigned int origin) {
150 shared_from_this(), origin),
164 if (
timer_mgr_->isTimerRegistered(timer_name)) {
174 std::ostringstream timer_name;
175 timer_name <<
"network-state-timer-" << origin;
176 return (timer_name.str());
186 bool disabled_by_user =
false;
190 for (
auto const& origin : ordered) {
192 disabled_by_user =
true;
202 result->set(
"disabled-by-local-command", local_origin);
203 result->set(
"disabled-by-remote-command", remote_origin);
238 impl_->setDisableService(
true, origin);
244 impl_->delayedEnable(origin);
250 impl_->resetForDbConnection();
256 impl_->resetForLocalCommands();
262 impl_->resetForRemoteCommands();
268 impl_->createTimer(seconds, origin);
274 return (!impl_->globally_disabled_);
279 for (
auto const& origin : impl_->disabled_by_origin_) {
309 return (impl_->toElement());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when a function is not implemented.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Implementation of the NetworkState class.
void resetForDbConnection()
Reset internal counters for a database connection origin.
std::string getTimerName(unsigned int origin) const
Creates a unique timer name from the origin.
void setDisableService(const bool disable, unsigned int origin)
Sets appropriate disabled or enabled DHCP service state for the respective origin.
NetworkState::Subnets disabled_subnets_
A list of subnets for which the DHCP service has been disabled.
virtual ElementPtr toElement() const
The network state as Element.
void resetForRemoteCommands()
Reset origin for remote commands.
bool globally_disabled_
A flag indicating if DHCP service is globally disabled.
TimerMgrPtr timer_mgr_
A pointer to the common timer manager.
void delayedEnable(unsigned int origin)
Enables DHCP service for an origin.
uint32_t disabled_by_db_connection_
Flag which indicates the state has been disabled by a DB connection loss.
NetworkStateImpl()
Constructor.
std::unordered_set< unsigned int > disabled_by_origin_
A set of requests to disable the service by origin.
NetworkState::Networks disabled_networks_
A list of networks for which the DHCP service has been disabled.
void createTimer(const unsigned int seconds, unsigned int origin)
Creates a timer counting the time when delayedEnable should be automatically called.
~NetworkStateImpl()
Destructor.
void destroyTimer(unsigned int origin)
Destroys a timer if present.
void resetForLocalCommands()
Reset origin for local commands.
static const unsigned int DB_CONNECTION
The network state is being altered by the DB connection recovery mechanics.
void selectiveDisable(const NetworkState::Subnets &subnets)
Disable DHCP service for selected subnets.
std::set< SubnetID > Subnets
Type of the container holding collection of subnet identifiers.
NetworkState()
Constructor.
virtual isc::data::ElementPtr toElement() const
The network state as Element.
static const unsigned int USER_COMMAND
Origin of the network state transition.
std::set< std::string > Networks
Type of the container holding collection of shared network names.
static const unsigned int HA_LOCAL_COMMAND
The network state is being altered by an HA internal command.
bool isDelayedEnableService() const
Checks if delayed enabling of DHCP services is scheduled.
static const unsigned int HA_REMOTE_COMMAND
The network state is being altered by a "dhcp-disable" or "dhcp-enable" command sent by a HA partner.
void resetForDbConnection()
Reset internal counters for database connection.
void resetForLocalCommands()
Reset origins for local commands.
void selectiveEnable(const NetworkState::Subnets &subnets)
Enable DHCP service for selected subnets.
void enableService(unsigned int origin)
Enable the DHCP service state for respective transition origin.
void disableService(unsigned int origin)
Disable the DHCP service state for respective transition origin.
bool isServiceEnabled() const
Checks if the DHCP service is globally enabled.
void delayedEnableService(const unsigned int seconds, unsigned int origin)
Schedules enabling DHCP service in the future.
void resetForRemoteCommands()
Reset origins for remote commands.
Manages a pool of asynchronous interval timers.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
RAII lock object to protect the code in the same scope with a mutex.