12#include <boost/pointer_cast.hpp>
22 "list-commands",
"status-get",
23 "dhcp-disable",
"dhcp-enable",
24 "ha-reset",
"ha-heartbeat",
25 "lease4-update",
"lease4-del",
26 "lease4-get-all",
"lease4-get-page",
27 "ha-maintenance-notify",
"ha-sync-complete-notify"
31 "list-commands",
"status-get",
32 "dhcp-disable",
"dhcp-enable",
33 "ha-reset",
"ha-heartbeat",
35 "lease6-update",
"lease6-del",
36 "lease6-get-all",
"lease6-get-page",
37 "ha-maintenance-notify",
"ha-sync-complete-notify"
48 args->set(
"max-period",
Element::create(
static_cast<long int>(max_period)));
51 insertService(command, server_type);
61 insertService(command, server_type);
68 insertService(command, server_type);
75 insertService(command, server_type);
82 insertLeaseExpireTime(lease_as_json);
92 insertLeaseExpireTime(lease_as_json);
107 const uint32_t limit) {
121 args->set(
"from", from_element);
122 args->set(
"limit", limit_element);
134 for (
auto lease = deleted_leases->begin(); lease != deleted_leases->end();
136 ElementPtr lease_as_json = (*lease)->toElement();
137 insertLeaseExpireTime(lease_as_json);
138 deleted_leases_list->add(lease_as_json);
142 for (
auto lease = leases->begin(); lease != leases->end();
144 ElementPtr lease_as_json = (*lease)->toElement();
145 insertLeaseExpireTime(lease_as_json);
146 leases_list->add(lease_as_json);
150 args->set(
"deleted-leases", deleted_leases_list);
151 args->set(
"leases", leases_list);
165 while ((lease = boost::dynamic_pointer_cast<Lease6>(leases.
pop(op_type)))) {
166 ElementPtr lease_as_json = lease->toElement();
167 insertLeaseExpireTime(lease_as_json);
169 deleted_leases_list->add(lease_as_json);
171 leases_list->add(lease_as_json);
176 args->set(
"deleted-leases", deleted_leases_list);
177 args->set(
"leases", leases_list);
187 insertLeaseExpireTime(lease_as_json);
197 insertLeaseExpireTime(lease_as_json);
212 const uint32_t limit) {
226 args->set(
"from", from_element);
227 args->set(
"limit", limit_element);
240 insertService(command, server_type);
247 insertService(command, server_type);
252CommandCreator::insertLeaseExpireTime(
ElementPtr& lease) {
254 (!lease->contains(
"cltt") || (lease->get(
"cltt")->getType() !=
Element::integer) ||
255 (!lease->contains(
"valid-lft") ||
260 int64_t cltt = lease->get(
"cltt")->intValue();
261 int64_t valid_lifetime = lease->get(
"valid-lft")->intValue();
262 int64_t expire = cltt + valid_lifetime;
264 lease->remove(
"cltt");
279 (boost::const_pointer_cast<Element>(command))->set(
"service", service);
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 when an unexpected error condition occurs.
static ElementPtr create(const Position &pos=ZERO_POSITION())
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.
static data::ConstElementPtr createLease4Delete(const dhcp::Lease4 &lease4)
Creates lease4-del command.
static std::unordered_set< std::string > ha_commands4_
List of commands used by the High Availability in v4.
static data::ConstElementPtr createHeartbeat(const HAServerType &server_type)
Creates ha-heartbeat command for DHCP server.
static data::ConstElementPtr createLease4Update(const dhcp::Lease4 &lease4)
Creates lease4-update command.
static data::ConstElementPtr createDHCPDisable(const unsigned int max_period, const HAServerType &server_type)
Creates dhcp-disable command for DHCP server.
static data::ConstElementPtr createLease6Update(const dhcp::Lease6 &lease6)
Creates lease6-update command.
static data::ConstElementPtr createHAReset(const HAServerType &server_type)
Creates ha-reset command.
static data::ConstElementPtr createLease6Delete(const dhcp::Lease6 &lease6)
Creates lease6-del command.
static data::ConstElementPtr createLease6BulkApply(const dhcp::Lease6CollectionPtr &leases, const dhcp::Lease6CollectionPtr &deleted_leases)
Creates lease6-bulk-apply command.
static data::ConstElementPtr createSyncCompleteNotify(const HAServerType &server_type)
Creates ha-sync-complete-notify command.
static data::ConstElementPtr createLease4GetAll()
Creates lease4-get-all command.
static data::ConstElementPtr createLease6GetPage(const dhcp::Lease6Ptr &lease6, const uint32_t limit)
Creates lease6-get-page command.
static data::ConstElementPtr createMaintenanceNotify(const bool cancel, const HAServerType &server_type)
Creates ha-maintenance-notify command.
static std::unordered_set< std::string > ha_commands6_
List of commands used by the High Availability in v6.
static data::ConstElementPtr createDHCPEnable(const HAServerType &server_type)
Creates dhcp-enable command for DHCP server.
static data::ConstElementPtr createLease6GetAll()
Creates lease6-get-all command.
static data::ConstElementPtr createLease4GetPage(const dhcp::Lease4Ptr &lease4, const uint32_t limit)
Creates lease4-get-page command.
Queue holding a backlog of unsent lease updates.
dhcp::LeasePtr pop(OpType &op_type)
Returns the next lease update and removes it from the queue.
OpType
Type of the lease update (operation type).
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ConstElementPtr createCommand(const std::string &command)
Creates a standard command message with no argument (of the form { "command": "my_command" })
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
HAServerType
Lists possible server types for which HA service is created.
Defines the logger used by the top-level component of kea-lfc.
Structure that holds a lease for IPv4 address.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Structure that holds a lease for IPv6 address and/or prefix.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.