Kea  1.9.9-git
ha_config.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2021 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 <asiolink/crypto_tls.h>
11 #include <exceptions/exceptions.h>
12 #include <http/basic_auth.h>
13 #include <http/post_request_json.h>
14 #include <http/url.h>
15 #include <util/optional.h>
16 #include <util/state_model.h>
17 #include <boost/shared_ptr.hpp>
18 #include <cstdint>
19 #include <map>
20 #include <string>
21 
22 namespace isc {
23 namespace ha {
24 
27 public:
28  HAConfigValidationError(const char* file, size_t line, const char* what) :
29  isc::Exception(file, line, what) { };
30 };
31 
33 class HAConfig {
34 public:
35 
42  enum HAMode {
46  };
47 
53  class PeerConfig {
54  public:
55 
70  enum Role {
75  };
76 
78  PeerConfig();
79 
81  std::string getName() const {
82  return (name_);
83  }
84 
89  void setName(const std::string& name);
90 
92  http::Url getUrl() const {
93  return (url_);
94  }
95 
99  void setUrl(const http::Url& url) {
100  url_ = url;
101  }
102 
105  return (trust_anchor_);
106  }
107 
112  trust_anchor_ = ca;
113  }
114 
117  return (cert_file_);
118  }
119 
124  cert_file_ = cert;
125  }
126 
129  return (key_file_);
130  }
131 
136  key_file_ = key;
137  }
138 
141  return (tls_context_);
142  }
143 
149  std::string getLogLabel() const;
150 
152  Role getRole() const {
153  return (role_);
154  }
155 
165  void setRole(const std::string& role);
166 
172  static Role stringToRole(const std::string& role);
173 
178  static std::string roleToString(const HAConfig::PeerConfig::Role& role);
179 
184  bool isAutoFailover() const {
185  return (auto_failover_);
186  }
187 
192  void setAutoFailover(const bool auto_failover) {
193  auto_failover_ = auto_failover;
194  }
195 
198  return (basic_auth_);
199  }
200 
203  return (basic_auth_);
204  }
205 
209 
215 
216  private:
217 
218  std::string name_;
219  http::Url url_;
220  util::Optional<std::string> trust_anchor_;
221  util::Optional<std::string> cert_file_;
222  util::Optional<std::string> key_file_;
223  Role role_;
224  bool auto_failover_;
225  http::BasicHttpAuthPtr basic_auth_;
226  };
227 
229  typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
230 
232  typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
233 
235  class StateConfig {
236  public:
237 
241  explicit StateConfig(const int state);
242 
244  int getState() const {
245  return (state_);
246  }
247 
250  return (pausing_);
251  }
252 
257  void setPausing(const std::string& pausing);
258 
263  static util::StatePausing stringToPausing(const std::string& pausing);
264 
268  static std::string pausingToString(const util::StatePausing& pausing);
269 
270  private:
271 
273  int state_;
274 
276  util::StatePausing pausing_;
277  };
278 
280  typedef boost::shared_ptr<StateConfig> StateConfigPtr;
281 
288  public:
289 
292  : states_() {
293  }
294 
303  StateConfigPtr getStateConfig(const int state);
304 
305  private:
306 
308  std::map<int, StateConfigPtr> states_;
309  };
310 
312  typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
313 
315  HAConfig();
316 
327  PeerConfigPtr selectNextPeerConfig(const std::string& name);
328 
330  std::string getThisServerName() const {
331  return (this_server_name_);
332  }
333 
338  void setThisServerName(const std::string& this_server_name);
339 
341  HAMode getHAMode() const {
342  return (ha_mode_);
343  }
344 
353  void setHAMode(const std::string& ha_mode);
354 
360  static HAMode stringToHAMode(const std::string& ha_mode);
361 
366  static std::string HAModeToString(const HAMode& ha_mode);
367 
370  bool amSendingLeaseUpdates() const {
371  return (send_lease_updates_);
372  }
373 
383  void setSendLeaseUpdates(const bool send_lease_updates) {
384  send_lease_updates_ = send_lease_updates;
385  }
386 
389  bool amSyncingLeases() const {
390  return (sync_leases_);
391  }
392 
402  void setSyncLeases(const bool sync_leases) {
403  sync_leases_ = sync_leases;
404  }
405 
409  uint32_t getSyncTimeout() const {
410  return (sync_timeout_);
411  }
412 
416  void setSyncTimeout(const uint32_t sync_timeout) {
417  sync_timeout_ = sync_timeout;
418  }
419 
424  uint32_t getSyncPageLimit() const {
425  return (sync_page_limit_);
426  }
427 
432  void setSyncPageLimit(const uint32_t sync_page_limit) {
433  sync_page_limit_ = sync_page_limit;
434  }
435 
448  uint32_t getDelayedUpdatesLimit() const {
449  return (delayed_updates_limit_);
450  }
451 
464  void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
465  delayed_updates_limit_ = delayed_updates_limit;
466  }
467 
475  bool amAllowingCommRecovery() const {
476  return (delayed_updates_limit_ > 0);
477  }
478 
486  uint32_t getHeartbeatDelay() const {
487  return (heartbeat_delay_);
488  }
489 
497  void setHeartbeatDelay(const uint32_t heartbeat_delay) {
498  heartbeat_delay_ = heartbeat_delay;
499  }
500 
506  uint32_t getMaxResponseDelay() const {
507  return (max_response_delay_);
508  }
509 
517  void setMaxResponseDelay(const uint32_t max_response_delay) {
518  max_response_delay_ = max_response_delay;
519  }
520 
525  uint32_t getMaxAckDelay() const {
526  return (max_ack_delay_);
527  }
528 
533  void setMaxAckDelay(const uint32_t max_ack_delay) {
534  max_ack_delay_ = max_ack_delay;
535  }
536 
541  uint32_t getMaxUnackedClients() const {
542  return (max_unacked_clients_);
543  }
544 
549  void setMaxUnackedClients(const uint32_t max_unacked_clients) {
550  max_unacked_clients_ = max_unacked_clients;
551  }
552 
559  void setWaitBackupAck(const bool wait_backup_ack) {
560  wait_backup_ack_ = wait_backup_ack;
561  }
562 
568  bool amWaitingBackupAck() const {
569  return (wait_backup_ack_);
570  }
571 
576  return (enable_multi_threading_);
577  }
578 
583  void setEnableMultiThreading(bool enable_multi_threading) {
584  enable_multi_threading_ = enable_multi_threading;
585  }
586 
595  return (http_dedicated_listener_);
596  }
597 
603  void setHttpDedicatedListener(bool http_dedicated_listener) {
604  http_dedicated_listener_ = http_dedicated_listener;
605  }
606 
611  return (http_listener_threads_);
612  }
613 
617  void setHttpListenerThreads(uint32_t http_listener_threads) {
618  http_listener_threads_ = http_listener_threads;
619  }
620 
624  uint32_t getHttpClientThreads() {
625  return (http_client_threads_);
626  }
627 
631  void setHttpClientThreads(uint32_t http_client_threads) {
632  http_client_threads_ = http_client_threads;
633  }
634 
637  return (trust_anchor_);
638  }
639 
644  trust_anchor_ = ca;
645  }
646 
649  return (cert_file_);
650  }
651 
656  cert_file_ = cert;
657  }
658 
661  return (key_file_);
662  }
663 
668  key_file_ = key;
669  }
670 
677  PeerConfigPtr getPeerConfig(const std::string& name) const;
678 
689  PeerConfigPtr getFailoverPeerConfig() const;
690 
694  PeerConfigPtr getThisServerConfig() const;
695 
702  PeerConfigMap getOtherServersConfig() const;
703 
707  PeerConfigMap getAllServersConfig() const {
708  return (peers_);
709  }
710 
714  StateMachineConfigPtr getStateMachineConfig() const {
715  return (state_machine_);
716  }
717 
732  void validate();
733 
734  std::string this_server_name_;
738  uint32_t sync_timeout_;
739  uint32_t sync_page_limit_;
740  uint32_t delayed_updates_limit_;
742  uint32_t heartbeat_delay_;
745  uint32_t max_ack_delay_;
755  PeerConfigMap peers_;
756  StateMachineConfigPtr state_machine_;
757 };
758 
760 typedef boost::shared_ptr<HAConfig> HAConfigPtr;
761 
762 } // end of namespace isc::ha
763 } // end of namespace isc
764 
765 #endif
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition: ha_config.h:714
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition: ha_config.h:249
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition: ha_config.h:402
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition: ha_config.h:631
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition: ha_config.h:746
const http::BasicHttpAuthPtr & getBasicAuth() const
Returns const basic HTTP authentication.
Definition: ha_config.h:202
Configuration specific to a single HA state.
Definition: ha_config.h:235
util::Optional< std::string > getTrustAnchor() const
Returns server's trust-anchor.
Definition: ha_config.h:104
StatePausing
State machine pausing modes.
Definition: state_model.h:45
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition: ha_config.h:583
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets server's trust-anchor.
Definition: ha_config.h:111
void setAutoFailover(const bool auto_failover)
Enables/disables auto-failover function for the server.
Definition: ha_config.h:192
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition: ha_config.cc:249
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:549
std::string getThisServerName() const
Returns name of this server.
Definition: ha_config.h:330
PeerConfigMap peers_
Map of peers' configurations.
Definition: ha_config.h:755
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition: ha_config.cc:192
void setName(const std::string &name)
Sets server name.
Definition: ha_config.cc:36
State machine configuration information.
Definition: ha_config.h:287
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition: ha_config.cc:204
bool enable_multi_threading_
Enable multi-threading.
Definition: ha_config.h:748
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
Definition: ha_config.cc:109
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition: ha_config.h:232
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
Definition: ha_config.cc:59
void setCertFile(const util::Optional< std::string > &cert)
Sets server's cert-file.
Definition: ha_config.h:123
std::string this_server_name_
This server name.
Definition: ha_config.h:734
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction...
Definition: ha_config.h:525
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition: ha_config.h:517
util::Optional< std::string > getCertFile() const
Returns server's cert-file.
Definition: ha_config.h:116
void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit)
Sets new limit for the number of lease updates to be held unsent in the communication-recovery state...
Definition: ha_config.h:464
util::Optional< std::string > key_file_
Private key file.
Definition: ha_config.h:754
void setWaitBackupAck(const bool wait_backup_ack)
Configures the server to wait/not wait for the lease update acknowledgments from the backup servers...
Definition: ha_config.h:559
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
Definition: ha_config.cc:148
StateConfig(const int state)
Constructor.
Definition: ha_config.cc:104
util::Optional< std::string > cert_file_
Certificate file.
Definition: ha_config.h:753
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition: ha_config.h:744
HAMode
Mode of operation.
Definition: ha_config.h:42
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition: ha_config.h:409
bool getEnableMultiThreading()
Checks if the server is configured for multi-threaded operation.
Definition: ha_config.h:575
bool sync_leases_
Synchronize databases on startup?
Definition: ha_config.h:737
bool http_dedicated_listener_
Enable use of own HTTP listener.
Definition: ha_config.h:749
bool amWaitingBackupAck() const
Checks if the server is configured to wait for the acknowledgments to the lease updates from the back...
Definition: ha_config.h:568
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition: ha_config.h:541
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition: ha_config.h:747
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition: ha_config.h:752
StateMachineConfigPtr state_machine_
State machine configuration.
Definition: ha_config.h:756
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition: ha_config.h:416
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
Definition: ha_config.h:197
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition: ha_config.h:739
uint32_t getDelayedUpdatesLimit() const
Returns the maximum number of lease updates which can be held unsent in the communication-recovery st...
Definition: ha_config.h:448
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition: ha_config.cc:239
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition: ha_config.h:743
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition: ha_config.h:486
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition: ha_config.h:745
void setKeyFile(const util::Optional< std::string > &key)
Sets server's key-file.
Definition: ha_config.h:135
Exception thrown when configuration validation fails.
Definition: ha_config.h:26
Represents an URL.
Definition: url.h:20
bool isAutoFailover() const
Checks if the auto-failover function is enabled for the server.
Definition: ha_config.h:184
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition: ha_config.h:707
boost::shared_ptr< PostHttpRequestJson > PostHttpRequestJsonPtr
Pointer to PostHttpRequestJson.
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
Definition: ha_config.h:738
asiolink::TlsContextPtr tls_context_
Server TLS context.
Definition: ha_config.h:214
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition: ha_config.h:497
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition: ha_config.cc:267
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition: ha_config.h:506
int getState() const
Returns identifier of the state.
Definition: ha_config.h:244
HAConfig()
Constructor.
Definition: ha_config.cc:162
std::string getName() const
Returns server name.
Definition: ha_config.h:81
asiolink::TlsContextPtr getTlsContext() const
Returns a pointer to the server's TLS context.
Definition: ha_config.h: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:383
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
Definition: ha_config.cc:96
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition: ha_config.h:280
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition: ha_config.h:636
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:370
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition: ha_config.h:389
void setHttpDedicatedListener(bool http_dedicated_listener)
Sets whether or not the server is configured to use its own HTTP listener.
Definition: ha_config.h:603
http::Url getUrl() const
Returns URL of the server's control channel.
Definition: ha_config.h:92
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition: ha_config.h:624
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:533
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
bool send_lease_updates_
Send lease updates to partner?
Definition: ha_config.h:736
This is a base class for exceptions thrown from the DNS library module.
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition: ha_config.h:617
Defines the logger used by the top-level component of kea-dhcp-ddns.
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition: ha_config.h:424
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition: ha_config.h:667
std::string getLogLabel() const
Returns a string identifying a server used in logging.
Definition: ha_config.cc:52
TLS API.
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets global trust-anchor.
Definition: ha_config.h:643
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition: ha_config.h:594
void setCertFile(const util::Optional< std::string > &cert)
Sets global cert-file.
Definition: ha_config.h:655
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition: ha_config.cc:224
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition: ha_config.h:648
void setRole(const std::string &role)
Sets servers role.
Definition: ha_config.cc:47
HAMode getHAMode() const
Returns mode of operation.
Definition: ha_config.h:341
bool amAllowingCommRecovery() const
Convenience function checking if communication recovery is allowed.
Definition: ha_config.h:475
boost::shared_ptr< BasicHttpAuth > BasicHttpAuthPtr
Type of pointers to basic HTTP authentication objects.
Definition: basic_auth.h:70
HAConfigValidationError(const char *file, size_t line, const char *what)
Definition: ha_config.h:28
Role
Server's role in the High Availability setup.
Definition: ha_config.h:70
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition: ha_config.h:660
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
Definition: ha_config.cc:129
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition: ha_config.h:312
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition: ha_config.h:741
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
Definition: ha_config.cc:79
Role getRole() const
Returns server's role.
Definition: ha_config.h:152
uint32_t getHttpListenerThreads()
Fetches the number of threads the HTTP listener should use.
Definition: ha_config.h:610
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition: ha_config.cc:174
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:114
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition: ha_config.h:750
void validate()
Validates configuration.
Definition: ha_config.cc:274
uint32_t http_client_threads_
Number of HTTP client threads.
Definition: ha_config.h:751
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:432
void setUrl(const http::Url &url)
Sets server's URL.
Definition: ha_config.h:99
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition: ha_config.cc:209
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:760
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition: ha_config.cc:262
HAMode ha_mode_
Mode of operation.
Definition: ha_config.h:735
Storage for High Availability configuration.
Definition: ha_config.h:33
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition: ha_config.h:229
HA peer configuration.
Definition: ha_config.h:53
util::Optional< std::string > getKeyFile() const
Returns server's key-file.
Definition: ha_config.h:128