20namespace ph = std::placeholders;
27 static uint32_t echo_instance_num = 0x00010000;
29 echo_instance_num = 0x00010001;
34 return (echo_instance_num);
55 "PingChannel ctor - io_service cannot be empty");
75 [](boost::system::error_code ec,
size_t ) {
82 socket_->open(&ping_to_endpoint, socket_cb);
100 }
catch (
const std::exception& ex) {
132 std::string error_string;
134 if (!error_string.empty()) {
148 }
catch (
const std::exception& ex) {
179 socket_->asyncReceive(
data, length, offset, endpoint, callback);
185 socket_->asyncSend(
data, length, endpoint, callback);
212 }
catch (
const std::exception& ex) {
231 if (ec.value() == boost::asio::error::operation_aborted) {
235 }
else if ((ec.value() == boost::asio::error::try_again) ||
236 (ec.value() == boost::asio::error::would_block)) {
261 .arg(reply->getSource())
263 .arg(reply->getSequence());
265 }
catch (
const std::exception& ex) {
295 io_service_->post(std::bind(f, shared_from_this()));
308 io_service_->post(std::bind(f, shared_from_this()));
346 next_echo->setDestination(context->getTarget());
349 next_echo->setId(
static_cast<uint16_t
>(instance_num >> 16));
350 next_echo->setSequence(
static_cast<uint16_t
>(instance_num & 0x0000FFFF));
353 ICMPPtr echo_icmp = next_echo->pack();
365 asyncSend(echo_icmp.get(),
sizeof(
struct icmp), &target_endpoint,
cb);
366 }
catch (
const std::exception& ex) {
390 }
catch (
const std::exception& ex) {
404 bool send_failed =
false;
406 auto error_value = ec.value();
407 if (error_value == boost::asio::error::operation_aborted) {
411 }
else if ((error_value == boost::asio::error::try_again) ||
412 (error_value == boost::asio::error::would_block)) {
417 }
else if ((error_value == boost::asio::error::network_unreachable) ||
418 (error_value == boost::asio::error::host_unreachable) ||
419 (error_value == boost::asio::error::network_down)) {
423 }
else if (error_value == boost::asio::error::no_buffer_space) {
426 }
else if (error_value == boost::asio::error::access_denied) {
448 .arg(echo->getDestination())
452 }
else if (length > 0) {
455 .arg(echo->getDestination())
457 .arg(echo->getSequence());
475 "PingChannel::getInputBufData() - cannot access empty buffer");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
The IOEndpoint class is an abstract base class to represent a communication endpoint.
void deleteExternalSocket(int socketfd)
Deletes external socket.
std::function< void(int fd)> SocketCallback
Defines callback used when data is received over external sockets.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
void addExternalSocket(int socketfd, SocketCallback callback)
Adds external socket and a callback.
The ICMPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a ICM...
Embodies an ICMP message.
static ICMPMsgPtr unpack(const uint8_t *wire_data, size_t length)
Unpacks an ICMP message from the given wire_data.
int registered_read_fd_
ICMPSocket fd registered with IfaceMgr.
size_t getInputBufSize() const
Returns input buffer size.
void doRead()
Initiates an asynchronous socket read.
virtual ~PingChannel()
Destructor.
PingSocketPtr socket_
Socket through which to ping.
void stopChannel()
Closes the socket channel and invokes the shutdown callback.
bool stopping_
Indicates whether or not the channel has been told to stop.
virtual void sendNext()
Initiates sending the next ECHO REQUEST.
bool sending_
Indicates whether or not the socket has a write in progress.
UpdateToSendCallback update_to_send_cb_
Callback to invoke to update selected context to SENDING state.
bool isOpen() const
Indicates whether or not the channel socket is open.
void open()
Opens the socket for communications.
static uint32_t nextEchoInstanceNum()
returns the next unique ECHO instance number.
const boost::scoped_ptr< std::mutex > send_mutex_
The mutex used to protect internal state on send events.
std::vector< uint8_t > input_buf_
Buffer to hold the contents for most recent socket read.
int registered_write_fd_
WatchSocket fd registered with IfaceMgr.
void socketWriteCallback(ICMPMsgPtr echo_sent, boost::system::error_code ec, size_t length)
Socket write completion callback.
ICMPEndpoint reply_endpoint_
Retains the endpoint from which the most recent reply was received.
EchoSentCallback echo_sent_cb_
Callback to invoke when an ECHO write has completed.
unsigned char * getInputBufData()
Returns pointer to the first byte of the input buffer.
bool canRead()
Indicates whether or not a read can be initiated.
asiolink::IOServicePtr io_service_
IOService instance the drives socket IO.
PingChannel(asiolink::IOServicePtr &io_service, NextToSendCallback next_to_send_cb, UpdateToSendCallback update_to_send_cb, EchoSentCallback echo_sent_cb, ReplyReceivedCallback reply_received_cb, ShutdownCallback shutdown_cb=ShutdownCallback())
Constructor.
void close()
Closes the channel's socket.
ReplyReceivedCallback reply_received_cb_
Callback to invoke when an ICMP reply has been received.
ShutdownCallback shutdown_cb_
Callback to invoke when the channel has shutdown.
util::WatchSocketPtr watch_socket_
Pointer to WatchSocket instance supplying the "select-fd".
bool reading_
Indicates whether or not the socket has a read in progress.
NextToSendCallback next_to_send_cb_
Callback to invoke to fetch the next context with target address to ping.
void socketReadCallback(boost::system::error_code ec, size_t length)
Socket read completion callback.
virtual void asyncSend(void *data, size_t length, asiolink::IOEndpoint *endpoint, SocketCallback &callback)
Send data on the socket asynchronously.
const boost::scoped_ptr< std::mutex > mutex_
The mutex used to protect internal state.
virtual void asyncReceive(void *data, size_t length, size_t offset, asiolink::IOEndpoint *endpoint, SocketCallback &callback)
Receive data on the socket asynchronously.
bool single_threaded_
True if channel was opened in single-threaded mode, false otherwise.
bool canSend()
Indicates whether or not a send can be initiated.
Functor associated with the socket object.
Provides an IO "ready" semaphore for use with select() or poll() WatchSocket exposes a single open fi...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
std::function< void()> ShutdownCallback
Function type for callback to invoke when the channel has shutdown.
boost::shared_ptr< ICMPMsg > ICMPMsgPtr
Shared pointer type for ICMPMsg.
isc::log::Logger ping_check_logger("ping-check-hooks")
std::function< void(ICMPMsgPtr &reply)> ReplyReceivedCallback
Function type for callback to invoke when an ICMP reply has been received.
std::function< void(ICMPMsgPtr &echo, bool send_failed)> EchoSentCallback
Function type for callback to invoke upon ECHO send completion.
std::function< void(PingContextPtr context)> UpdateToSendCallback
Function type for callback to update a context to SENDING state.
boost::shared_ptr< struct icmp > ICMPPtr
Shared pointer type for struct icmp.
boost::shared_ptr< PingContext > PingContextPtr
Defines a shared pointer to a PingContext.
boost::shared_ptr< PingChannel > PingChannelPtr
Defines a smart pointer to PingChannel.
std::function< PingContextPtr()> NextToSendCallback
Function type for callback to fetch a context with next target to ping.
ICMPSocket< SocketCallback > PingSocket
Socket type for performing ICMP socket IO.
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID PING_CHECK_CHANNEL_STOP
const isc::log::MessageID PING_CHECK_CHANNEL_WATCH_SOCKET_CLEAR_ERROR
const isc::log::MessageID PING_CHECK_CHANNEL_SOCKET_CLOSED
const isc::log::MessageID PING_CHECK_CHANNEL_MALFORMED_PACKET_RECEIVED
const isc::log::MessageID PING_CHECK_CHANNEL_SOCKET_READ_FAILED
const isc::log::MessageID PING_CHECK_CHANNEL_SOCKET_WRITE_FAILED
const isc::log::MessageID PING_CHECK_CHANNEL_ECHO_REPLY_RECEIVED
const isc::log::MessageID PING_CHECK_UNEXPECTED_WRITE_ERROR
const isc::log::MessageID PING_CHECK_CHANNEL_SOCKET_OPENED
const isc::log::MessageID PING_CHECK_UNEXPECTED_READ_ERROR
const isc::log::MessageID PING_CHECK_CHANNEL_WATCH_SOCKET_CLOSE_ERROR
const isc::log::MessageID PING_CHECK_CHANNEL_SOCKET_CLOSE_ERROR
const isc::log::MessageID PING_CHECK_CHANNEL_NETWORK_WRITE_ERROR
const isc::log::MessageID PING_CHECK_CHANNEL_ECHO_REQUEST_SENT
RAII lock object to protect the code in the same scope with a mutex.