Kea  1.5.0
ha_config.h
Go to the documentation of this file.
1 // Copyright (C) 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 #ifndef HA_CONFIG_H
8 #define HA_CONFIG_H
9 
10 #include <exceptions/exceptions.h>
11 #include <http/url.h>
12 #include <util/state_model.h>
13 #include <boost/shared_ptr.hpp>
14 #include <cstdint>
15 #include <map>
16 #include <string>
17 
18 namespace isc {
19 namespace ha {
20 
23 public:
24  HAConfigValidationError(const char* file, size_t line, const char* what) :
25  isc::Exception(file, line, what) { };
26 };
27 
29 class HAConfig {
30 public:
31 
37  enum HAMode {
40  };
41 
47  class PeerConfig {
48  public:
49 
64  enum Role {
69  };
70 
72  PeerConfig();
73 
75  std::string getName() const {
76  return (name_);
77  }
78 
83  void setName(const std::string& name);
84 
86  http::Url getUrl() const {
87  return (url_);
88  }
89 
93  void setUrl(const http::Url& url) {
94  url_ = url;
95  }
96 
102  std::string getLogLabel() const;
103 
105  Role getRole() const {
106  return (role_);
107  }
108 
118  void setRole(const std::string& role);
119 
125  static Role stringToRole(const std::string& role);
126 
131  static std::string roleToString(const HAConfig::PeerConfig::Role& role);
132 
137  bool isAutoFailover() const {
138  return (auto_failover_);
139  }
140 
145  void setAutoFailover(const bool auto_failover) {
146  auto_failover_ = auto_failover;
147  }
148 
149  private:
150 
151  std::string name_;
152  http::Url url_;
153  Role role_;
154  bool auto_failover_;
155 
156  };
157 
159  typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
160 
162  typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
163 
164 
166  class StateConfig {
167  public:
168 
172  explicit StateConfig(const int state);
173 
175  int getState() const {
176  return (state_);
177  }
178 
181  return (pausing_);
182  }
183 
188  void setPausing(const std::string& pausing);
189 
194  static util::StatePausing stringToPausing(const std::string& pausing);
195 
199  static std::string pausingToString(const util::StatePausing& pausing);
200 
201  private:
202 
204  int state_;
205 
207  util::StatePausing pausing_;
208  };
209 
211  typedef boost::shared_ptr<StateConfig> StateConfigPtr;
212 
219  public:
220 
223  : states_() {
224  }
225 
234  StateConfigPtr getStateConfig(const int state);
235 
236  private:
237 
239  std::map<int, StateConfigPtr> states_;
240  };
241 
243  typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
244 
246  HAConfig();
247 
258  PeerConfigPtr selectNextPeerConfig(const std::string& name);
259 
261  std::string getThisServerName() const {
262  return (this_server_name_);
263  }
264 
269  void setThisServerName(const std::string& this_server_name);
270 
272  HAMode getHAMode() const {
273  return (ha_mode_);
274  }
275 
284  void setHAMode(const std::string& ha_mode);
285 
291  static HAMode stringToHAMode(const std::string& ha_mode);
292 
297  static std::string HAModeToString(const HAMode& ha_mode);
298 
301  bool amSendingLeaseUpdates() const {
302  return (send_lease_updates_);
303  }
304 
314  void setSendLeaseUpdates(const bool send_lease_updates) {
315  send_lease_updates_ = send_lease_updates;
316  }
317 
320  bool amSyncingLeases() const {
321  return (sync_leases_);
322  }
323 
333  void setSyncLeases(const bool sync_leases) {
334  sync_leases_ = sync_leases;
335  }
336 
340  uint32_t getSyncTimeout() const {
341  return (sync_timeout_);
342  }
343 
347  void setSyncTimeout(const uint32_t sync_timeout) {
348  sync_timeout_ = sync_timeout;
349  }
350 
355  uint32_t getSyncPageLimit() const {
356  return (sync_page_limit_);
357  }
358 
363  void setSyncPageLimit(const uint32_t sync_page_limit) {
364  sync_page_limit_ = sync_page_limit;
365  }
366 
374  uint32_t getHeartbeatDelay() const {
375  return (heartbeat_delay_);
376  }
377 
385  void setHeartbeatDelay(const uint32_t heartbeat_delay) {
386  heartbeat_delay_ = heartbeat_delay;
387  }
388 
394  uint32_t getMaxResponseDelay() const {
395  return (max_response_delay_);
396  }
397 
405  void setMaxResponseDelay(const uint32_t max_response_delay) {
406  max_response_delay_ = max_response_delay;
407  }
408 
413  uint32_t getMaxAckDelay() const {
414  return (max_ack_delay_);
415  }
416 
421  void setMaxAckDelay(const uint32_t max_ack_delay) {
422  max_ack_delay_ = max_ack_delay;
423  }
424 
429  uint32_t getMaxUnackedClients() const {
430  return (max_unacked_clients_);
431  }
432 
437  void setMaxUnackedClients(const uint32_t max_unacked_clients) {
438  max_unacked_clients_ = max_unacked_clients;
439  }
440 
447  PeerConfigPtr getPeerConfig(const std::string& name) const;
448 
460 
465 
473 
478  return (peers_);
479  }
480 
485  return (state_machine_);
486  }
487 
491  void validate() const;
492 
493  std::string this_server_name_;
497  uint32_t sync_timeout_;
498  uint32_t sync_page_limit_;
499  uint32_t heartbeat_delay_;
502  uint32_t max_ack_delay_;
506 };
507 
509 typedef boost::shared_ptr<HAConfig> HAConfigPtr;
510 
511 } // end of namespace isc::ha
512 } // end of namespace isc
513 
514 #endif
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition: ha_config.cc:208
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition: ha_config.h:333
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition: ha_config.h:503
Configuration specific to a single HA state.
Definition: ha_config.h:166
StatePausing
State machine pausing modes.
Definition: state_model.h:44
void setAutoFailover(const bool auto_failover)
Enables/disables auto-failover function for the server.
Definition: ha_config.h:145
void setMaxUnackedClients(const uint32_t max_unacked_clients)
Set maximum number of clients which may fail to communicate with the DHCP server before entering part...
Definition: ha_config.h:437
PeerConfigMap peers_
Map of peers' configurations.
Definition: ha_config.h:504
HAMode getHAMode() const
Returns mode of operation.
Definition: ha_config.h:272
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition: ha_config.cc:166
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition: ha_config.h:180
void setName(const std::string &name)
Sets server name.
Definition: ha_config.cc:23
State machine configuration information.
Definition: ha_config.h:218
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition: ha_config.cc:178
void setPausing(const std::string &pausing)
Sets pausing mode for the gievn state.
Definition: ha_config.cc:87
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition: ha_config.h:162
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
Definition: ha_config.cc:46
std::string this_server_name_
This server name.
Definition: ha_config.h:493
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition: ha_config.h:405
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition: ha_config.h:340
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
Definition: ha_config.cc:126
StateConfig(const int state)
Constructor.
Definition: ha_config.cc:82
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition: ha_config.cc:218
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition: ha_config.h:501
HAMode
Mode of operation.
Definition: ha_config.h:37
Role getRole() const
Returns server's role.
Definition: ha_config.h:105
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition: ha_config.h:394
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition: ha_config.h:477
bool sync_leases_
Synchronize databases on startup?
Definition: ha_config.h:496
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:301
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
StateMachineConfigPtr state_machine_
State machine configuration.
Definition: ha_config.h:505
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition: ha_config.h:347
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction.
Definition: ha_config.h:413
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition: ha_config.h:498
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition: ha_config.h:500
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition: ha_config.h:502
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition: ha_config.h:374
std::string getLogLabel() const
Returns a string identifying a server used in logging.
Definition: ha_config.cc:39
Exception thrown when configuration validation fails.
Definition: ha_config.h:22
Represents an URL.
Definition: url.h:20
std::string getThisServerName() const
Returns name of this server.
Definition: ha_config.h:261
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
Definition: ha_config.h:497
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition: ha_config.h:385
HAConfig()
Constructor.
Definition: ha_config.cc:140
void setSendLeaseUpdates(const bool send_lease_updates)
Sets boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:314
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition: ha_config.h:211
void setMaxAckDelay(const uint32_t max_ack_delay)
Sets maximum time for a client trying to communicate with DHCP server to completed the transaction.
Definition: ha_config.h:421
bool send_lease_updates_
Send lease updates to partner?
Definition: ha_config.h:495
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void validate() const
Validates configuration.
Definition: ha_config.cc:243
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition: ha_config.cc:236
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition: ha_config.cc:195
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition: ha_config.h:355
bool isAutoFailover() const
Checks if the auto-failover function is enabled for the server.
Definition: ha_config.h:137
void setRole(const std::string &role)
Sets servers role.
Definition: ha_config.cc:34
HAConfigValidationError(const char *file, size_t line, const char *what)
Definition: ha_config.h:24
Role
Server's role in the High Availability setup.
Definition: ha_config.h:64
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
Definition: ha_config.cc:107
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition: ha_config.h:243
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition: ha_config.h:429
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
Definition: ha_config.cc:66
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition: ha_config.cc:231
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition: ha_config.cc:148
std::string getName() const
Returns server name.
Definition: ha_config.h:75
This file defines the class StateModel.
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
Definition: ha_config.cc:92
int getState() const
Returns identifier of the state.
Definition: ha_config.h:175
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition: ha_config.h:320
void setSyncPageLimit(const uint32_t sync_page_limit)
Sets new page limit size for leases fetched from the partner during database synchronization.
Definition: ha_config.h:363
http::Url getUrl() const
Returns URL of the server's control channel.
Definition: ha_config.h:86
void setUrl(const http::Url &url)
Sets server's URL.
Definition: ha_config.h:93
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition: ha_config.h:484
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition: ha_config.cc:183
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:509
HAMode ha_mode_
Mode of operation.
Definition: ha_config.h:494
Storage for High Availability configuration.
Definition: ha_config.h:29
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition: ha_config.h:159
HA peer configuration.
Definition: ha_config.h:47