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"
42 const unsigned int max_period,
51 args->set(
"max-period",
Element::create(
static_cast<long int>(max_period)));
54 insertService(command, server_type);
67 insertService(command, server_type);
77 insertService(command, server_type);
87 insertService(command, server_type);
94 insertLeaseExpireTime(lease_as_json);
105 insertLeaseExpireTime(lease_as_json);
121 const uint32_t limit) {
135 args->set(
"from", from_element);
136 args->set(
"limit", limit_element);
148 for (
auto const& lease : *deleted_leases) {
149 ElementPtr lease_as_json = lease->toElement();
150 insertLeaseExpireTime(lease_as_json);
151 deleted_leases_list->add(lease_as_json);
155 for (
auto const& lease : *leases) {
156 ElementPtr lease_as_json = lease->toElement();
157 insertLeaseExpireTime(lease_as_json);
158 leases_list->add(lease_as_json);
162 args->set(
"deleted-leases", deleted_leases_list);
163 args->set(
"leases", leases_list);
178 while ((lease = boost::dynamic_pointer_cast<Lease6>(leases.
pop(op_type)))) {
179 ElementPtr lease_as_json = lease->toElement();
180 insertLeaseExpireTime(lease_as_json);
182 deleted_leases_list->add(lease_as_json);
184 leases_list->add(lease_as_json);
189 args->set(
"deleted-leases", deleted_leases_list);
190 args->set(
"leases", leases_list);
201 insertLeaseExpireTime(lease_as_json);
212 insertLeaseExpireTime(lease_as_json);
228 const uint32_t limit) {
242 args->set(
"from", from_element);
243 args->set(
"limit", limit_element);
259 insertService(command, server_type);
265 const std::string& server_name,
276 insertService(command, server_type);
281CommandCreator::insertLeaseExpireTime(
ElementPtr& lease) {
283 (!lease->contains(
"cltt") || (lease->get(
"cltt")->getType() !=
Element::integer) ||
284 (!lease->contains(
"valid-lft") ||
289 int64_t cltt = lease->get(
"cltt")->intValue();
290 int64_t valid_lifetime = lease->get(
"valid-lft")->intValue();
291 int64_t expire = cltt + valid_lifetime;
293 lease->remove(
"cltt");
308 (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 data::ConstElementPtr createHeartbeat(const std::string &server_name, const HAServerType &server_type)
Creates ha-heartbeat command for DHCP server.
static std::unordered_set< std::string > ha_commands4_
List of commands used by the High Availability in v4.
static data::ConstElementPtr createLease4Update(const dhcp::Lease4 &lease4)
Creates lease4-update command.
static data::ConstElementPtr createLease6Update(const dhcp::Lease6 &lease6)
Creates lease6-update command.
static data::ConstElementPtr createSyncCompleteNotify(const unsigned int origin_id, const std::string &server_name, const HAServerType &server_type)
Creates ha-sync-complete-notify 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 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 createDHCPDisable(const unsigned int origin_id, const unsigned int max_period, const HAServerType &server_type)
Creates dhcp-disable command for DHCP server.
static data::ConstElementPtr createDHCPEnable(const unsigned int origin_id, const HAServerType &server_type)
Creates dhcp-enable command for DHCP server.
static std::unordered_set< std::string > ha_commands6_
List of commands used by the High Availability in v6.
static data::ConstElementPtr createHAReset(const std::string &server_name, const HAServerType &server_type)
Creates ha-reset command.
static data::ConstElementPtr createLease6GetAll()
Creates lease6-get-all command.
static data::ConstElementPtr createMaintenanceNotify(const std::string &server_name, const bool cancel, const HAServerType &server_type)
Creates ha-maintenance-notify 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.