Kea  1.5.0
network_state.cc
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
10 #include <dhcpsrv/network_state.h>
11 #include <dhcpsrv/timer_mgr.h>
12 #include <boost/bind.hpp>
13 #include <boost/enable_shared_from_this.hpp>
14 #include <string>
15 
16 namespace {
17 
19 const std::string NETWORK_STATE_TIMER_NAME = "network-state-timer";
20 
21 } // end of anonymous namespace
22 
23 namespace isc {
24 namespace dhcp {
25 
27 class NetworkStateImpl : public boost::enable_shared_from_this<NetworkStateImpl> {
28 public:
29 
32  : server_type_(server_type), globally_disabled_(false), disabled_subnets_(),
33  disabled_networks_(), timer_mgr_(TimerMgr::instance()) {
34  }
35 
38  destroyTimer();
39  }
40 
42  void setDisableService(const bool disable) {
43  globally_disabled_ = disable;
44  }
45 
49  void enableAll() {
50  setDisableService(false);
51 
53 
54  destroyTimer();
55  }
56 
65  void createTimer(const unsigned int seconds) {
66  destroyTimer();
67  timer_mgr_->registerTimer(NETWORK_STATE_TIMER_NAME,
68  boost::bind(&NetworkStateImpl::enableAll,
69  shared_from_this()),
70  seconds * 1000,
72  timer_mgr_->setup(NETWORK_STATE_TIMER_NAME);
73  }
74 
76  void destroyTimer() {
77  if (timer_mgr_->isTimerRegistered(NETWORK_STATE_TIMER_NAME)) {
78  timer_mgr_->unregisterTimer(NETWORK_STATE_TIMER_NAME);
79  }
80  }
81 
84 
87 
90 
93 
99 };
100 
102  : impl_(new NetworkStateImpl(server_type)) {
103 }
104 
105 void
107  impl_->setDisableService(true);
108 }
109 
110 void
112  impl_->setDisableService(false);
113 }
114 
115 void
117  impl_->enableAll();
118 }
119 
120 void
121 NetworkState::delayedEnableAll(const unsigned int seconds) {
122  impl_->createTimer(seconds);
123 }
124 
125 bool
127  return (!impl_->globally_disabled_);
128 }
129 
130 bool
132  return (TimerMgr::instance()->isTimerRegistered(NETWORK_STATE_TIMER_NAME));
133 }
134 
135 void
137  isc_throw(NotImplemented, "selectiveDisableService is not implemented");
138 }
139 
140 void
142  isc_throw(NotImplemented, "selectiveDisableService is not implemented");
143 }
144 
145 void
147  isc_throw(NotImplemented, "selectiveEnableService is not implemented");
148 }
149 
150 void
152  isc_throw(NotImplemented, "selectiveEnableService is not implemented");
153 }
154 
155 
156 } // end of namespace isc::dhcp
157 } // end of namespace isc
isc::dhcp::NetworkState::Networks
std::set< std::string > Networks
Type of the container holding collection of shared network names.
Definition: network_state.h:70
isc::dhcp::NetworkStateImpl::globally_disabled_
bool globally_disabled_
A flag indicating if DHCP service is globally disabled.
Definition: network_state.cc:86
isc::dhcp::NetworkState::isServiceEnabled
bool isServiceEnabled() const
Checks if the DHCP service is globally enabled.
Definition: network_state.cc:126
isc::dhcp::NetworkStateImpl::disabled_networks_
NetworkState::Networks disabled_networks_
A list of networks for which the DHCP service has been disabled.
Definition: network_state.cc:92
isc::dhcp::NetworkStateImpl::server_type_
NetworkState::ServerType server_type_
Server type.
Definition: network_state.cc:83
isc::dhcp::NetworkStateImpl::~NetworkStateImpl
~NetworkStateImpl()
Destructor.
Definition: network_state.cc:37
timer_mgr.h
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::TimerMgr
Manages a pool of asynchronous interval timers.
Definition: timer_mgr.h:54
isc::dhcp::NetworkState::Subnets
std::set< SubnetID > Subnets
Type of the container holding collection of subnet identifiers.
Definition: network_state.h:67
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:192
isc::dhcp::NetworkState::selectiveDisable
void selectiveDisable(const NetworkState::Subnets &subnets)
Disable DHCP service for selected subnets.
Definition: network_state.cc:136
isc::dhcp::NetworkState::isDelayedEnableAll
bool isDelayedEnableAll() const
Checks if delayed enabling of DHCP services is scheduled.
Definition: network_state.cc:131
isc::dhcp::TimerMgr::instance
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
Definition: timer_mgr.cc:319
isc::dhcp::NetworkStateImpl::disabled_subnets_
NetworkState::Subnets disabled_subnets_
A list of subnets for which the DHCP service has been disabled.
Definition: network_state.cc:89
isc::dhcp::NetworkState::NetworkState
NetworkState(const ServerType &server_type)
Constructor.
Definition: network_state.cc:101
isc::dhcp::NetworkStateImpl::NetworkStateImpl
NetworkStateImpl(const NetworkState::ServerType &server_type)
Constructor.
Definition: network_state.cc:31
isc::dhcp::NetworkState::ServerType
ServerType
DHCP server type.
Definition: network_state.h:61
isc::dhcp::TimerMgrPtr
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
Definition: timer_mgr.h:22
isc::dhcp::NetworkStateImpl::createTimer
void createTimer(const unsigned int seconds)
Creates a timer counting the time when enableAll should be automatically called.
Definition: network_state.cc:65
network_state.h
exceptions.h
isc::dhcp::NetworkStateImpl::enableAll
void enableAll()
Enables DHCP service globally and per scopes.
Definition: network_state.cc:49
isc::dhcp::NetworkState::selectiveEnable
void selectiveEnable(const NetworkState::Subnets &subnets)
Enable DHCP service for selected subnets.
Definition: network_state.cc:146
isc::dhcp::NetworkStateImpl::destroyTimer
void destroyTimer()
Destroys a timer if present.
Definition: network_state.cc:76
isc::dhcp::NetworkState::enableService
void enableService()
Globally enables DHCP service.
Definition: network_state.cc:111
isc::NotImplemented
A generic exception that is thrown when a function is not implemented.
Definition: exceptions/exceptions.h:165
isc::dhcp::NetworkState::delayedEnableAll
void delayedEnableAll(const unsigned int seconds)
Schedules enabling DHCP service in the future.
Definition: network_state.cc:121
isc::dhcp::NetworkState::enableAll
void enableAll()
Enables DHCP service globally and for scopes which have been disabled as a result of control command.
Definition: network_state.cc:116
isc::dhcp::NetworkStateImpl::setDisableService
void setDisableService(const bool disable)
Globally disables or enables DHCP service.
Definition: network_state.cc:42
isc::dhcp::NetworkStateImpl::timer_mgr_
TimerMgrPtr timer_mgr_
A pointer to the common timer manager.
Definition: network_state.cc:98
isc::dhcp::NetworkStateImpl
Implementation of the NetworkState class.
Definition: network_state.cc:27
isc::dhcp::NetworkState::disableService
void disableService()
Globally disables DHCP service.
Definition: network_state.cc:106