Kea 3.1.1
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
130 virtual bool nextToSend(asiolink::IOAddress& next);
131
147 virtual void sendCompleted(const ICMPMsgPtr& echo, bool send_failed);
148
160 virtual void replyReceived(const ICMPMsgPtr& reply);
161
165 void handleEchoReply(const ICMPMsgPtr& echo_reply);
166
170 void handleTargetUnreachable(const ICMPMsgPtr& unreachable);
171
181 void finishFree(const PingContextPtr& context);
182
189 void doNextEcho(const PingContextPtr& context);
190
195 virtual void channelShutdown();
196
208 virtual size_t processExpiredSince(const TimeStamp& since = PingContext::now());
209
214
222 virtual void setNextExpiration();
223
231 virtual void setNextExpirationInternal();
232
235
238
240 virtual void expirationTimedOut();
241
264 dhcp::Pkt4Ptr& query,
265 dhcp::Lease4Ptr& old_lease,
268
274 void checkPermissions();
275
280 void startService(dhcp::NetworkStatePtr network_state);
281
294 void stopService(bool finish_free = false);
295
302 void start();
303
308 void startSingleThreaded();
309
314 void pause();
315
320 void resume();
321
332 void flush(bool finish_free = false);
333
335 void stop();
336
342 bool isRunning();
343
349 bool isStopped();
350
355 bool isPaused();
356
362 bool checkSuspended();
363
373
378
385
392
397 io_service_ = io_service;
398 }
399
400protected:
401
404
407
410
413
416
419
422
425
427 const boost::scoped_ptr<std::mutex> mutex_;
428
431};
432
434typedef boost::shared_ptr<PingCheckMgr> PingCheckMgrPtr;
435
436} // end of namespace ping_check
437} // end of namespace isc
438
439#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.
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 bool nextToSend(asiolink::IOAddress &next)
Callback passed to PingChannel to use to retrieve the next address to check.
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.
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.