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);
104 ElementPtr lease_as_json = lease4.toElement();
105 insertLeaseExpireTime(lease_as_json);
121 const uint32_t limit) {
135 args->set(
"from", from_element);
136 args->set(
"limit", limit_element);
149 for (
auto const& lease : *deleted_leases) {
150 ElementPtr lease_as_json = lease->toElement();
151 insertLeaseExpireTime(lease_as_json);
156 if (lease->state_ == Lease6::STATE_RELEASED) {
157 leases_list->add(lease_as_json);
159 deleted_leases_list->add(lease_as_json);
163 for (
auto const& lease : *leases) {
164 ElementPtr lease_as_json = lease->toElement();
165 insertLeaseExpireTime(lease_as_json);
166 leases_list->add(lease_as_json);
170 args->set(
"deleted-leases", deleted_leases_list);
171 args->set(
"leases", leases_list);
186 while ((lease = boost::dynamic_pointer_cast<Lease6>(leases.pop(op_type)))) {
187 ElementPtr lease_as_json = lease->toElement();
188 insertLeaseExpireTime(lease_as_json);
190 deleted_leases_list->add(lease_as_json);
192 leases_list->add(lease_as_json);
197 args->set(
"deleted-leases", deleted_leases_list);
198 args->set(
"leases", leases_list);
208 ElementPtr lease_as_json = lease6.toElement();
209 insertLeaseExpireTime(lease_as_json);
219 ElementPtr lease_as_json = lease6.toElement();
220 insertLeaseExpireTime(lease_as_json);
236 const uint32_t limit) {
250 args->set(
"from", from_element);
251 args->set(
"limit", limit_element);
267 insertService(command, server_type);
273 const std::string& server_name,
284 insertService(command, server_type);
289CommandCreator::insertLeaseExpireTime(
ElementPtr& lease) {
291 (!lease->contains(
"cltt") || (lease->get(
"cltt")->getType() !=
Element::integer) ||
292 (!lease->contains(
"valid-lft") ||
297 int64_t cltt = lease->get(
"cltt")->intValue();
298 int64_t valid_lifetime = lease->get(
"valid-lft")->intValue();
299 int64_t expire = cltt + valid_lifetime;
301 lease->remove(
"cltt");
316 (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.
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.
Structure that holds a lease for IPv6 address and/or prefix.