Kea  1.5.0
communication_state.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_COMMUNICATION_STATE_H
8 #define HA_COMMUNICATION_STATE_H
9 
10 #include <ha_config.h>
11 #include <ha_service_states.h>
13 #include <asiolink/io_service.h>
14 #include <dhcp/pkt.h>
15 #include <boost/date_time/posix_time/posix_time.hpp>
16 #include <boost/function.hpp>
17 #include <boost/shared_ptr.hpp>
18 #include <map>
19 #include <set>
20 #include <string>
21 
22 namespace isc {
23 namespace ha {
24 
75 public:
76 
82  const HAConfigPtr& config);
83 
87  virtual ~CommunicationState();
88 
92  int getPartnerState() const {
93  return (partner_state_);
94  }
95 
101  void setPartnerState(const std::string& state);
102 
108  void startHeartbeat(const long interval,
109  const boost::function<void()>& heartbeat_impl);
110 
111 protected:
112 
118  void startHeartbeatInternal(const long interval = 0,
119  const boost::function<void()>& heartbeat_impl = 0);
120 
121 public:
122 
124  void stopHeartbeat();
125 
129  bool isHeartbeatRunning() const {
130  return (static_cast<bool>(timer_));
131  }
132 
138  void poke();
139 
143  int64_t getDurationInMillisecs() const;
144 
153  bool isCommunicationInterrupted() const;
154 
186  virtual void analyzeMessage(const boost::shared_ptr<dhcp::Pkt>& message) = 0;
187 
202  virtual bool failureDetected() const = 0;
203 
204 protected:
205 
217  virtual void clearUnackedClients() = 0;
218 
219 public:
220 
243  bool clockSkewShouldWarn();
244 
261  bool clockSkewShouldTerminate() const;
262 
263 protected:
264 
271  bool isClockSkewGreater(const long seconds) const;
272 
273 public:
274 
284  void setPartnerTime(const std::string& time_text);
285 
287  std::string logFormatClockSkew() const;
288 
289 protected:
290 
293 
296 
299 
301  long interval_;
302 
304  boost::posix_time::ptime poke_time_;
305 
307  boost::function<void()> heartbeat_impl_;
308 
313 
315  boost::posix_time::time_duration clock_skew_;
316 
319  boost::posix_time::ptime last_clock_skew_warn_;
320 };
321 
323 typedef boost::shared_ptr<CommunicationState> CommunicationStatePtr;
324 
325 
332 public:
333 
339  const HAConfigPtr& config);
340 
355  virtual void analyzeMessage(const boost::shared_ptr<dhcp::Pkt>& message);
356 
362  virtual bool failureDetected() const;
363 
364 protected:
365 
370  virtual void clearUnackedClients();
371 
378  std::multimap<std::vector<uint8_t>, std::vector<uint8_t> > unacked_clients_;
379 };
380 
382 typedef boost::shared_ptr<CommunicationState4> CommunicationState4Ptr;
383 
390 public:
391 
397  const HAConfigPtr& config);
398 
407  virtual void analyzeMessage(const boost::shared_ptr<dhcp::Pkt>& message);
408 
414  virtual bool failureDetected() const;
415 
416 protected:
417 
422  virtual void clearUnackedClients();
423 
428  std::set<std::vector<uint8_t> > unacked_clients_;
429 };
430 
432 typedef boost::shared_ptr<CommunicationState6> CommunicationState6Ptr;
433 
434 } // end of namespace isc::ha
435 } // end of namespace isc
436 
437 #endif
isc::ha::CommunicationState6::analyzeMessage
virtual void analyzeMessage(const boost::shared_ptr< dhcp::Pkt > &message)
Checks if the DHCPv6 message appears to be unanswered.
Definition: communication_state.cc:316
isc::ha::CommunicationState::isCommunicationInterrupted
bool isCommunicationInterrupted() const
Checks if communication with the partner is interrupted.
Definition: communication_state.cc:174
isc::ha::CommunicationState::clearUnackedClients
virtual void clearUnackedClients()=0
Removes information about clients which the partner server failed to respond to.
isc::ha::CommunicationState::clockSkewShouldTerminate
bool clockSkewShouldTerminate() const
Indicates whether the HA service should enter "terminated" state as a result of the clock skew exceed...
Definition: communication_state.cc:206
isc::ha::CommunicationState4Ptr
boost::shared_ptr< CommunicationState4 > CommunicationState4Ptr
Pointer to the CommunicationState4 object.
Definition: communication_state.h:382
isc::ha::CommunicationState6::CommunicationState6
CommunicationState6(const asiolink::IOServicePtr &io_service, const HAConfigPtr &config)
Constructor.
Definition: communication_state.cc:310
isc::ha::CommunicationState::isHeartbeatRunning
bool isHeartbeatRunning() const
Checks if recurring heartbeat is running.
Definition: communication_state.h:129
isc::ha::CommunicationState::analyzeMessage
virtual void analyzeMessage(const boost::shared_ptr< dhcp::Pkt > &message)=0
Checks if the DHCP message appears to be unanswered.
isc::ha::CommunicationState::clockSkewShouldWarn
bool clockSkewShouldWarn()
Indicates whether the HA service should issue a warning about high clock skew between the active serv...
Definition: communication_state.cc:179
isc::ha::CommunicationState::setPartnerState
void setPartnerState(const std::string &state)
Sets partner state.
Definition: communication_state.cc:57
ha_config.h
isc::ha::CommunicationState::~CommunicationState
virtual ~CommunicationState()
Destructor.
Definition: communication_state.cc:52
isc::ha::CommunicationState::logFormatClockSkew
std::string logFormatClockSkew() const
Returns current clock skew value in the logger friendly format.
Definition: communication_state.cc:226
isc::ha::CommunicationState::partner_state_
int partner_state_
Last known state of the partner server.
Definition: communication_state.h:312
isc::ha::CommunicationState6::unacked_clients_
std::set< std::vector< uint8_t > > unacked_clients_
Holds information about the clients which the partner server failed to respond to.
Definition: communication_state.h:428
io_service.h
isc::ha::CommunicationState6Ptr
boost::shared_ptr< CommunicationState6 > CommunicationState6Ptr
Pointer to the CommunicationState6 object.
Definition: communication_state.h:432
isc::ha::CommunicationState::setPartnerTime
void setPartnerTime(const std::string &time_text)
Provide partner's notion of time so the new clock skew can be calculated.
Definition: communication_state.cc:218
isc::ha::CommunicationState::heartbeat_impl_
boost::function< void()> heartbeat_impl_
Pointer to the function providing heartbeat implementation.
Definition: communication_state.h:307
isc::ha::CommunicationState::clock_skew_
boost::posix_time::time_duration clock_skew_
Clock skew between the active servers.
Definition: communication_state.h:315
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::ha::CommunicationState::poke
void poke()
Pokes the communication state.
Definition: communication_state.cc:138
isc::ha::CommunicationState::startHeartbeat
void startHeartbeat(const long interval, const boost::function< void()> &heartbeat_impl)
Starts recurring heartbeat (public interface).
Definition: communication_state.cc:81
isc::ha::CommunicationState::startHeartbeatInternal
void startHeartbeatInternal(const long interval=0, const boost::function< void()> &heartbeat_impl=0)
Starts recurring heartbeat.
Definition: communication_state.cc:87
isc::ha::CommunicationState::stopHeartbeat
void stopHeartbeat()
Stops recurring heartbeat.
Definition: communication_state.cc:128
isc::ha::CommunicationState4::analyzeMessage
virtual void analyzeMessage(const boost::shared_ptr< dhcp::Pkt > &message)
Checks if the DHCPv4 message appears to be unanswered.
Definition: communication_state.cc:247
isc::ha::CommunicationState4::CommunicationState4
CommunicationState4(const asiolink::IOServicePtr &io_service, const HAConfigPtr &config)
Constructor.
Definition: communication_state.cc:241
pkt.h
isc::ha::CommunicationState::last_clock_skew_warn_
boost::posix_time::ptime last_clock_skew_warn_
Holds a time when last warning about too high clock skew was issued.
Definition: communication_state.h:319
isc::ha::CommunicationState4::clearUnackedClients
virtual void clearUnackedClients()
Removes information about clients which the partner server failed to respond to.
Definition: communication_state.cc:306
isc::ha::CommunicationState6
Holds communication state between DHCPv6 servers.
Definition: communication_state.h:389
isc::ha::CommunicationState::isClockSkewGreater
bool isClockSkewGreater(const long seconds) const
Checks if the clock skew is greater than the specified number of seconds.
Definition: communication_state.cc:212
isc::ha::CommunicationState::interval_
long interval_
Interval specified for the heartbeat.
Definition: communication_state.h:301
isc::ha::CommunicationState::timer_
asiolink::IntervalTimerPtr timer_
Interval timer triggering heartbeat commands.
Definition: communication_state.h:298
isc::ha::HAConfigPtr
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:509
isc::ha::CommunicationStatePtr
boost::shared_ptr< CommunicationState > CommunicationStatePtr
Type of the pointer to the CommunicationState object.
Definition: communication_state.h:323
isc::ha::CommunicationState6::clearUnackedClients
virtual void clearUnackedClients()
Removes information about clients which the partner server failed to respond to.
Definition: communication_state.cc:347
isc::ha::CommunicationState6::failureDetected
virtual bool failureDetected() const
Checks if the partner failure has been detected based on the DHCP traffic analysis.
Definition: communication_state.cc:341
isc::ha::CommunicationState::failureDetected
virtual bool failureDetected() const =0
Checks if the partner failure has been detected based on the DHCP traffic analysis.
isc::ha::CommunicationState::getDurationInMillisecs
int64_t getDurationInMillisecs() const
Returns duration between the poke time and current time.
Definition: communication_state.cc:167
interval_timer.h
isc::ha::CommunicationState4::unacked_clients_
std::multimap< std::vector< uint8_t >, std::vector< uint8_t > > unacked_clients_
Holds information about the clients which the partner server failed to respond to.
Definition: communication_state.h:378
isc::ha::CommunicationState4::failureDetected
virtual bool failureDetected() const
Checks if the partner failure has been detected based on the DHCP traffic analysis.
Definition: communication_state.cc:300
isc::ha::CommunicationState::CommunicationState
CommunicationState(const asiolink::IOServicePtr &io_service, const HAConfigPtr &config)
Constructor.
Definition: communication_state.cc:44
isc::ha::CommunicationState::poke_time_
boost::posix_time::ptime poke_time_
Last poke time.
Definition: communication_state.h:304
ha_service_states.h
isc::ha::CommunicationState::getPartnerState
int getPartnerState() const
Returns last known state of the partner.
Definition: communication_state.h:92
isc::ha::CommunicationState
Holds communication state between the two HA peers.
Definition: communication_state.h:74
isc::ha::CommunicationState4
Holds communication state between DHCPv4 servers.
Definition: communication_state.h:331
isc::ha::CommunicationState::config_
HAConfigPtr config_
High availability configuration.
Definition: communication_state.h:295
isc::ha::CommunicationState::io_service_
asiolink::IOServicePtr io_service_
Pointer to the common IO service instance.
Definition: communication_state.h:292