12 #include <boost/pointer_cast.hpp>
21 CommandCreator::createDHCPDisable(
const unsigned int max_period,
28 args->set(
"max-period",
Element::create(static_cast<long int>(max_period)));
31 insertService(command, server_type);
36 CommandCreator::createDHCPEnable(
const HAServerType& server_type) {
41 insertService(command, server_type);
48 insertService(command, server_type);
55 insertService(command, server_type);
60 CommandCreator::createLease4Update(
const Lease4& lease4) {
62 insertLeaseExpireTime(lease_as_json);
65 insertService(command, HAServerType::DHCPv4);
70 CommandCreator::createLease4Delete(
const Lease4& lease4) {
72 insertLeaseExpireTime(lease_as_json);
74 insertService(command, HAServerType::DHCPv4);
79 CommandCreator::createLease4GetAll() {
81 insertService(command, HAServerType::DHCPv4);
86 CommandCreator::createLease4GetPage(
const Lease4Ptr& last_lease4,
87 const uint32_t limit) {
101 args->set(
"from", from_element);
102 args->set(
"limit", limit_element);
106 insertService(command, HAServerType::DHCPv4);
114 for (
auto lease = deleted_leases->begin(); lease != deleted_leases->end();
116 ElementPtr lease_as_json = (*lease)->toElement();
117 insertLeaseExpireTime(lease_as_json);
118 deleted_leases_list->add(lease_as_json);
122 for (
auto lease = leases->begin(); lease != leases->end();
124 ElementPtr lease_as_json = (*lease)->toElement();
125 insertLeaseExpireTime(lease_as_json);
126 leases_list->add(lease_as_json);
130 args->set(
"deleted-leases", deleted_leases_list);
131 args->set(
"leases", leases_list);
134 insertService(command, HAServerType::DHCPv6);
145 while ((lease = boost::dynamic_pointer_cast<Lease6>(leases.
pop(op_type)))) {
146 ElementPtr lease_as_json = lease->toElement();
147 insertLeaseExpireTime(lease_as_json);
148 if (op_type == LeaseUpdateBacklog::DELETE) {
149 deleted_leases_list->add(lease_as_json);
151 leases_list->add(lease_as_json);
156 args->set(
"deleted-leases", deleted_leases_list);
157 args->set(
"leases", leases_list);
160 insertService(command, HAServerType::DHCPv6);
165 CommandCreator::createLease6Update(
const Lease6& lease6) {
167 insertLeaseExpireTime(lease_as_json);
170 insertService(command, HAServerType::DHCPv6);
175 CommandCreator::createLease6Delete(
const Lease6& lease6) {
177 insertLeaseExpireTime(lease_as_json);
179 insertService(command, HAServerType::DHCPv6);
184 CommandCreator::createLease6GetAll() {
186 insertService(command, HAServerType::DHCPv6);
191 CommandCreator::createLease6GetPage(
const Lease6Ptr& last_lease6,
192 const uint32_t limit) {
206 args->set(
"from", from_element);
207 args->set(
"limit", limit_element);
211 insertService(command, HAServerType::DHCPv6);
216 CommandCreator::createMaintenanceNotify(
const bool cancel,
const HAServerType& server_type) {
220 insertService(command, server_type);
225 CommandCreator::insertLeaseExpireTime(
ElementPtr& lease) {
227 (!lease->contains(
"cltt") || (lease->get(
"cltt")->getType() !=
Element::integer) ||
228 (!lease->contains(
"valid-lft") ||
233 int64_t cltt = lease->get(
"cltt")->intValue();
234 int64_t valid_lifetime = lease->get(
"valid-lft")->intValue();
235 int64_t expire = cltt + valid_lifetime;
237 lease->remove(
"cltt");
244 const std::string service_name = (server_type == HAServerType::DHCPv4 ?
"dhcp4" :
"dhcp6");
252 (boost::const_pointer_cast<
Element>(command))->set(
"service", service);
Structure that holds a lease for IPv4 address.
OpType
Type of the lease update (operation type).
boost::shared_ptr< Element > ElementPtr
HAServerType
Lists possible server types for which HA service is created.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
ConstElementPtr createCommand(const std::string &command)
Creates a standard command message with no argument (of the form { "command": "my_command" }) ...
A generic exception that is thrown when an unexpected error condition occurs.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
boost::shared_ptr< const Element > ConstElementPtr
Structure that holds a lease for IPv6 address and/or prefix.
Defines the logger used by the top-level component of kea-dhcp-ddns.
This file contains several functions and constants that are used for handling commands and responses ...
static ElementPtr create(const Position &pos=ZERO_POSITION())
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
The Element class represents a piece of data, used by the command channel and configuration parts...
dhcp::LeasePtr pop(OpType &op_type)
Returns the next lease update and removes it from the queue.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Queue holding a backlog of unsent lease updates.