Kea 3.1.3
ping_check_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2023-2025 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 PING_CHECK_MGR_H
8#define PING_CHECK_MGR_H
9
11#include <asiolink/io_address.h>
12#include <asiolink/io_service.h>
14#include <cc/data.h>
15#include <cc/simple_parser.h>
16#include <dhcpsrv/host.h>
17#include <dhcpsrv/srv_config.h>
19#include <dhcp/pkt4.h>
20#include <dhcpsrv/lease.h>
22#include <ping_context_store.h>
23#include <ping_channel.h>
24#include <config_cache.h>
25
26#include <boost/enable_shared_from_this.hpp>
27
28#include <mutex>
29
30namespace isc {
31namespace ping_check {
32
34typedef boost::shared_ptr<PingContextStore> PingContextStorePtr;
35
47class PingCheckMgr : public boost::enable_shared_from_this<PingCheckMgr> {
48public:
50 explicit PingCheckMgr();
51
64 PingCheckMgr(uint32_t num_threads,
65 uint32_t min_echos = 1,
66 uint32_t reply_timeout = 100);
67
69 virtual ~PingCheckMgr();
70
76
84 void updateSubnetConfig(dhcp::SrvConfigPtr server_config);
85
92
103 void startPing(dhcp::Lease4Ptr& lease, dhcp::Pkt4Ptr& query,
104 hooks::ParkingLotHandlePtr& parking_lot,
106
117 void startPing(dhcp::Lease4Ptr& lease, dhcp::Pkt4Ptr& query,
118 hooks::ParkingLotHandlePtr& parking_lot);
119
127 virtual PingContextPtr nextToSend();
128
137 virtual void updateContextToSend(PingContextPtr context);
138
154 virtual void sendCompleted(const ICMPMsgPtr& echo, bool send_failed);
155
167 virtual void replyReceived(const ICMPMsgPtr& reply);
168
172 void handleEchoReply(const ICMPMsgPtr& echo_reply);
173
177 void handleTargetUnreachable(const ICMPMsgPtr& unreachable);
178
188 void finishFree(const PingContextPtr& context);
189
196 void doNextEcho(const PingContextPtr& context);
197
202 virtual void channelShutdown();
203
215 virtual size_t processExpiredSince(const TimeStamp& since = PingContext::now());
216
221
229 virtual void setNextExpiration();
230
238 virtual void setNextExpirationInternal();
239
242
245
247 virtual void expirationTimedOut();
248
271 dhcp::Pkt4Ptr& query,
272 dhcp::Lease4Ptr& old_lease,
275
281 void checkPermissions();
282
287 void startService(dhcp::NetworkStatePtr network_state);
288
301 void stopService(bool finish_free = false);
302
309 void start();
310
315 void startSingleThreaded();
316
321 void pause();
322
327 void resume();
328
339 void flush(bool finish_free = false);
340
342 void stop();
343
349 bool isRunning();
350
356 bool isStopped();
357
362 bool isPaused();
363
369 bool checkSuspended();
370
380
385
392
399
404 io_service_ = io_service;
405 }
406
407protected:
408
411
414
417
420
423
426
429
432
434 const boost::scoped_ptr<std::mutex> mutex_;
435
438};
439
441typedef boost::shared_ptr<PingCheckMgr> PingCheckMgrPtr;
442
443} // end of namespace ping_check
444} // end of namespace isc
445
446#endif
CalloutNextStep
Specifies allowed next steps.
virtual void channelShutdown()
Callback passed to PingChannel to invoke when it shuts down.
virtual void expirationTimedOut()
Callback passed to expiration timer to invoke on timeout.
virtual void updateContextToSend(PingContextPtr context)
Callback passed to PingChannel to update a context to SENDING state just before sending.
asiolink::IntervalTimerPtr expiration_timer_
Timer which tracks the next expiration event.
bool isRunning()
Indicates if the thread pool is running.
void checkPermissions()
Check if the current thread can perform thread pool state transition.
void configure(data::ConstElementPtr params)
Configure the PingCheckMgr.
asiolink::IoServiceThreadPoolPtr thread_pool_
Thread pool used when running multi-threaded.
void cancelExpirationTimerInternal()
Cancels the expiration timer.
TimeStamp next_expiry_
TimeStamp of the next expiration event.
virtual void setNextExpirationInternal()
Updates the expiration timer.
void stopService(bool finish_free=false)
Shuts down the manager's channel, flushes the store.
void resume()
Resume PingChannel operations.
void startService(dhcp::NetworkStatePtr network_state)
Performs a deferred start by posting an invocation of start() to the given IOService.
const PingCheckConfigPtr getScopedConfig(dhcp::Lease4Ptr &lease)
Fetches the current, scoped configuration parameters.
bool isStopped()
Indicates if the thread pool is stopped.
virtual PingChannelPtr createChannel(asiolink::IOServicePtr io_service)
Creates a ping channel instance.
const PingCheckConfigPtr getGlobalConfig() const
Fetches the current, global configuration parameters.
TimeStamp getNextExpiry()
Fetches the time at which expiration timer will next expire.
void handleTargetUnreachable(const ICMPMsgPtr &unreachable)
Process an UNREACHABLE message.
void startPing(dhcp::Lease4Ptr &lease, dhcp::Pkt4Ptr &query, hooks::ParkingLotHandlePtr &parking_lot, const PingCheckConfigPtr &config)
Initiates a ping check for a given lease and its associated DHCPDISCOVER packet.
void finishFree(const PingContextPtr &context)
Processes a context whose address has been deemed free to use.
void setIOService(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
const boost::scoped_ptr< std::mutex > mutex_
The mutex used to protect internal state.
virtual size_t processExpiredSince(const TimeStamp &since=PingContext::now())
Performs expiration processing for contexts whose WAITING_FOR_REPLY states expired prior to a given p...
bool checkSuspendedInternal()
Checks if operations are currently suspended due to NetworkState.
void pause()
Pause PingChannel operations.
virtual ~PingCheckMgr()
Destructor.
bool checkSuspended()
Checks if operations are currently suspended due to NetworkState.
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
void flush(bool finish_free=false)
Flushes the ping context store.
PingChannelPtr channel_
Channel that conducts ICMP messaging.
bool suspended_
Indicates whether or not operations have been suspended.
void cancelExpirationTimer()
Cancels the expiration timer (thread safe).
void start()
Start PingChannel operations.
void updateSubnetConfig(dhcp::SrvConfigPtr server_config)
Update the cache of subnet ping check configurations.
virtual void replyReceived(const ICMPMsgPtr &reply)
Callback passed to PingChannel to invoke when an ICMP reply has been received.
PingContextStorePtr store_
In-memory store of PingContexts.
virtual hooks::CalloutHandle::CalloutNextStep shouldPing(dhcp::Lease4Ptr &lease, dhcp::Pkt4Ptr &query, dhcp::Lease4Ptr &old_lease, dhcp::ConstHostPtr host, const PingCheckConfigPtr &config)
Determines whether or not a lease should be ping checked.
virtual PingContextPtr nextToSend()
Callback passed to PingChannel to use to retrieve the next context with address to check.
void startSingleThreaded()
Start single-threaded PingChannel operations.
void stop()
Stop PingChannel operations.
ConfigCachePtr config_cache_
Warehouses parsed global and subnet configuration.
isc::asiolink::IOServicePtr io_service_
The hook I/O service.
dhcp::NetworkStatePtr network_state_
Tracks whether or not the server is processing DHCP packets.
void handleEchoReply(const ICMPMsgPtr &echo_reply)
Process an ECHO REPLY message.
virtual void setNextExpiration()
Updates the expiration timer (thread safe).
void doNextEcho(const PingContextPtr &context)
Position a context to do another ping test.
virtual void sendCompleted(const ICMPMsgPtr &echo, bool send_failed)
Callback passed to PingChannel to invoke when an ECHO REQUEST send has completed.
bool isPaused()
Indicates if the thread pool is paused.
static TimeStamp now()
Fetches the current timestamp (UTC/milliseconds precision)
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:556
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
boost::shared_ptr< PingCheckConfig > PingCheckConfigPtr
Defines a shared pointer to a PingCheckConfig.
boost::shared_ptr< ICMPMsg > ICMPMsgPtr
Shared pointer type for ICMPMsg.
Definition icmp_msg.h:26
boost::shared_ptr< PingCheckMgr > PingCheckMgrPtr
Defines a shared pointer to a PingCheckMgr.
std::chrono::time_point< std::chrono::system_clock > TimeStamp
Specifies the type for time stamps.
boost::shared_ptr< ConfigCache > ConfigCachePtr
Defines a shared pointer to a ConfigCache.
boost::shared_ptr< PingContext > PingContextPtr
Defines a shared pointer to a PingContext.
boost::shared_ptr< PingContextStore > PingContextStorePtr
Defines a pointer to a PingContextStore.
boost::shared_ptr< PingChannel > PingChannelPtr
Defines a smart pointer to PingChannel.
Defines the logger used by the top-level component of kea-lfc.