13 #include <boost/enable_shared_from_this.hpp>
22 const std::string NETWORK_STATE_TIMER_NAME_USER_CMD =
"network-state-timer-user-cmd";
23 const std::string NETWORK_STATE_TIMER_NAME_HA_CMD =
"network-state-timer-ha-cmd";
36 : server_type_(server_type), globally_disabled_(false),
37 disabled_subnets_(), disabled_networks_(),
38 timer_mgr_(
TimerMgr::instance()), disabled_by_user_command_(false),
39 disabled_by_ha_command_(false), disabled_by_db_connection_(0) {
44 destroyTimer(NetworkState::Origin::USER_COMMAND);
45 destroyTimer(NetworkState::Origin::HA_COMMAND);
64 globally_disabled_ =
true;
66 case NetworkState::Origin::USER_COMMAND:
67 disabled_by_user_command_ =
true;
69 case NetworkState::Origin::HA_COMMAND:
70 disabled_by_ha_command_ =
true;
72 case NetworkState::Origin::DB_CONNECTION:
73 ++disabled_by_db_connection_;
77 "disabling the network state");
82 case NetworkState::Origin::USER_COMMAND:
83 disabled_by_user_command_ =
false;
85 case NetworkState::Origin::HA_COMMAND:
86 disabled_by_ha_command_ =
false;
88 case NetworkState::Origin::DB_CONNECTION:
91 if (disabled_by_db_connection_) {
92 --disabled_by_db_connection_;
97 "enabling the network state");
101 if (!disabled_by_user_command_ && !disabled_by_ha_command_ &&
102 disabled_by_db_connection_ == 0) {
103 globally_disabled_ =
false;
115 case NetworkState::Origin::USER_COMMAND:
116 disabled_by_user_command_ =
false;
118 case NetworkState::Origin::HA_COMMAND:
119 disabled_by_ha_command_ =
false;
121 case NetworkState::Origin::DB_CONNECTION:
122 disabled_by_db_connection_ = 0;
126 "resetting the network state");
130 if (!disabled_by_user_command_ && !disabled_by_ha_command_ &&
131 disabled_by_db_connection_ == 0) {
132 globally_disabled_ =
false;
142 setDisableService(
false, origin);
146 destroyTimer(origin);
160 destroyTimer(origin);
161 std::string timer_name = NETWORK_STATE_TIMER_NAME_USER_CMD;
163 case NetworkState::Origin::USER_COMMAND:
164 timer_name = NETWORK_STATE_TIMER_NAME_USER_CMD;
166 case NetworkState::Origin::HA_COMMAND:
167 timer_name = NETWORK_STATE_TIMER_NAME_HA_CMD;
169 case NetworkState::Origin::DB_CONNECTION:
174 "a timer for delayed enable");
177 timer_mgr_->registerTimer(timer_name,
178 std::bind(&NetworkStateImpl::enableAll,
179 shared_from_this(), origin),
182 timer_mgr_->setup(timer_name);
189 std::string timer_name = NETWORK_STATE_TIMER_NAME_USER_CMD;
191 case NetworkState::Origin::USER_COMMAND:
192 timer_name = NETWORK_STATE_TIMER_NAME_USER_CMD;
194 case NetworkState::Origin::HA_COMMAND:
195 timer_name = NETWORK_STATE_TIMER_NAME_HA_CMD;
197 case NetworkState::Origin::DB_CONNECTION:
201 "a timer for delayed enable");
204 if (timer_mgr_->isTimerRegistered(timer_name)) {
205 timer_mgr_->unregisterTimer(timer_name);
246 if (MultiThreadingMgr::instance().getMode()) {
247 std::lock_guard<std::mutex> lk(*mutex_);
248 impl_->setDisableService(
true, origin);
250 impl_->setDisableService(
true, origin);
256 if (MultiThreadingMgr::instance().getMode()) {
257 std::lock_guard<std::mutex> lk(*mutex_);
258 impl_->setDisableService(
false, origin);
260 impl_->setDisableService(
false, origin);
266 if (MultiThreadingMgr::instance().getMode()) {
267 std::lock_guard<std::mutex> lk(*mutex_);
268 impl_->reset(origin);
270 impl_->reset(origin);
276 if (MultiThreadingMgr::instance().getMode()) {
277 std::lock_guard<std::mutex> lk(*mutex_);
278 impl_->enableAll(origin);
280 impl_->enableAll(origin);
287 if (MultiThreadingMgr::instance().getMode()) {
288 std::lock_guard<std::mutex> lk(*mutex_);
289 impl_->createTimer(seconds, origin);
291 impl_->createTimer(seconds, origin);
297 if (MultiThreadingMgr::instance().getMode()) {
298 std::lock_guard<std::mutex> lk(*mutex_);
299 return (!impl_->globally_disabled_);
301 return (!impl_->globally_disabled_);
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
NetworkState::ServerType server_type_
Server type.
A generic exception that is thrown when a function is not implemented.
std::set< std::string > Networks
Type of the container holding collection of shared network names.
bool globally_disabled_
A flag indicating if DHCP service is globally disabled.
void setDisableService(const bool disable, const NetworkState::Origin &origin)
Sets appropriate disabled or enabled DHCP service state for the respective origin.
void enableAll(const NetworkState::Origin &origin)
Enables DHCP service globally and per scopes.
void enableService(const NetworkState::Origin &origin)
Enable the DHCP service state for respective transition origin.
ServerType
DHCP server type.
Manages a pool of asynchronous interval timers.
void delayedEnableAll(const unsigned int seconds, const NetworkState::Origin &origin)
Schedules enabling DHCP service in the future.
void reset(const NetworkState::Origin &type)
Reset internal counters.
std::set< SubnetID > Subnets
Type of the container holding collection of subnet identifiers.
void selectiveEnable(const NetworkState::Subnets &subnets)
Enable DHCP service for selected subnets.
void enableAll(const NetworkState::Origin &origin)
Enables DHCP service globally and for scopes which have been disabled as a result of control command...
bool disabled_by_ha_command_
Flag which indicates the state has been disabled by the HA command.
Origin
Origin of the network state transition.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Implementation of the NetworkState class.
NetworkState::Networks disabled_networks_
A list of networks for which the DHCP service has been disabled.
bool isDelayedEnableAll() const
Checks if delayed enabling of DHCP services is scheduled.
NetworkStateImpl(const NetworkState::ServerType &server_type)
Constructor.
void destroyTimer(const NetworkState::Origin &origin)
Destroys a timer if present.
void selectiveDisable(const NetworkState::Subnets &subnets)
Disable DHCP service for selected subnets.
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool isServiceEnabled() const
Checks if the DHCP service is globally enabled.
void disableService(const NetworkState::Origin &origin)
Disable the DHCP service state for respective transition origin.
uint32_t disabled_by_db_connection_
Flag which indicates the state has been disabled by a DB connection loss.
NetworkState::Subnets disabled_subnets_
A list of subnets for which the DHCP service has been disabled.
~NetworkStateImpl()
Destructor.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
void createTimer(const unsigned int seconds, const NetworkState::Origin &origin)
Creates a timer counting the time when enableAll should be automatically called.
void reset(const NetworkState::Origin &origin)
Reset internal counters for a specific origin.
bool disabled_by_user_command_
Flag which indicates the state has been disabled by an user command.
TimerMgrPtr timer_mgr_
A pointer to the common timer manager.