Kea 2.5.8
ncr_udp.h File Reference

This file provides UDP socket based implementation for sending and receiving NameChangeRequests. More...

#include <asiolink/asio_wrapper.h>
#include <asiolink/io_address.h>
#include <asiolink/io_service.h>
#include <asiolink/udp_endpoint.h>
#include <asiolink/udp_socket.h>
#include <dhcp_ddns/ncr_io.h>
#include <util/buffer.h>
#include <util/watch_socket.h>
#include <boost/shared_array.hpp>
#include <boost/enable_shared_from_this.hpp>
+ Include dependency graph for ncr_udp.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  isc::dhcp_ddns::UDPCallback::Data
 Container class which stores service invocation related data. More...
 
class  isc::dhcp_ddns::NameChangeUDPListener
 Provides the ability to receive NameChangeRequests via UDP socket. More...
 
class  isc::dhcp_ddns::NameChangeUDPSender
 Provides the ability to send NameChangeRequests via UDP socket. More...
 
class  isc::dhcp_ddns::NcrUDPError
 Thrown when a UDP level exception occurs. More...
 
class  isc::dhcp_ddns::UDPCallback
 Implements the callback class passed into UDPSocket calls. More...
 

Namespaces

namespace  isc
 Defines the logger used by the top-level component of kea-lfc.
 
namespace  isc::dhcp_ddns
 

Typedefs

typedef isc::asiolink::UDPSocket< UDPCallback > isc::dhcp_ddns::NameChangeUDPSocket
 Convenience type for UDP socket based listener.
 
typedef boost::shared_array< uint8_t > isc::dhcp_ddns::RawBufferPtr
 Defines a dynamically allocated shared array.
 
typedef std::function< void(const bool, const UDPCallback *)> isc::dhcp_ddns::UDPCompletionHandler
 Defines a function pointer for NameChangeRequest completion handlers.
 
typedef boost::shared_ptr< asiolink::UDPEndpoint > isc::dhcp_ddns::UDPEndpointPtr
 

Detailed Description

This file provides UDP socket based implementation for sending and receiving NameChangeRequests.

These classes are derived from the abstract classes, NameChangeListener and NameChangeSender (see ncr_io.h).

The following discussion will refer to three layers of communications:

  • Application layer - This is the business layer which needs to transport NameChangeRequests, and is unaware of the means by which they are transported.
  • IO layer - This is the low-level layer that is directly responsible for sending and receiving data asynchronously and is supplied through other libraries. This layer is largely unaware of the nature of the data being transmitted. In other words, it doesn't know beans about NCRs.
  • NameChangeRequest layer - This is the layer which acts as the intermediary between the Application layer and the IO layer. It must be able to move NameChangeRequests to the IO layer as raw data and move raw data from the IO layer in the Application layer as NameChangeRequests.

This file defines NameChangeUDPListener class for receiving NCRs, and NameChangeUDPSender for sending NCRs.

Both the listener and sender implementations utilize the same underlying construct to move NCRs to and from a UDP socket. This construct consists of a set of classes centered around isc::asiolink::UDPSocket. UDPSocket is a templated class that supports asio asynchronous event processing; and which accepts as its parameter, the name of a callback class.

The asynchronous services provided by UDPSocket typically accept a buffer for transferring data (either in or out depending on the service direction) and an object which supplies a callback to invoke upon completion of the service.

The callback class must provide an operator() with the following signature:

void operator ()(const boost::system::error_code error_code,
const size_t bytes_transferred);

Upon completion of the service, the callback instance's operator() is invoked by the asio layer. It is given both a outcome result and the number of bytes either read or written, to or from the buffer supplied to the service.

Typically, an asiolink based implementation would simply implement the callback operator directly. However, the nature of the asiolink library is such that the callback object may be copied several times during course of a service invocation. This implies that any class being used as a callback class must be copyable. This is not always desirable. In order to separate the callback class from the NameChangeRequest, the construct defines the UDPCallback class for use as a copyable, callback object.

The UDPCallback class provides the asiolink layer callback operator(), which is invoked by the asiolink layer upon service completion. It contains:

  • a pointer to the transfer buffer
  • the capacity of the transfer buffer
  • a IO layer outcome result
  • the number of bytes transferred
  • a method pointer to a NameChangeRequest layer completion handler

This last item, is critical. It points to an instance method that will be invoked by the UDPCallback operator. This provides access to the outcome of the service call to the NameChangeRequest layer without that layer being used as the actual callback object.

The completion handler method signature is codified in the typedef, UDPCompletionHandler, and must be as follows:

void(const bool, const UDPCallback*)

Note that is accepts two parameters. The first is a boolean indicator which indicates if the service call completed successfully or not. The second is a pointer to the callback object invoked by the IOService upon completion of the service. The callback instance will contain all of the pertinent information about the invocation and outcome of the service.

Using the contents of the callback, it is the responsibility of the UDPCompletionHandler to interpret the results of the service invocation and pass the interpretation to the application layer via either NameChangeListener::invokeRecvHandler in the case of the UDP listener, or NameChangeSender::invokeSendHandler in the case of UDP sender.

Definition in file ncr_udp.h.