13#include <boost/pointer_cast.hpp>
23 "list-commands",
"status-get",
24 "dhcp-disable",
"dhcp-enable",
25 "ha-reset",
"ha-heartbeat",
26 "lease4-update",
"lease4-del",
27 "lease4-get-all",
"lease4-get-page",
28 "ha-maintenance-notify",
"ha-sync-complete-notify"
32 "list-commands",
"status-get",
33 "dhcp-disable",
"dhcp-enable",
34 "ha-reset",
"ha-heartbeat",
36 "lease6-update",
"lease6-del",
37 "lease6-get-all",
"lease6-get-page",
38 "ha-maintenance-notify",
"ha-sync-complete-notify"
43 const unsigned int max_period,
52 args->set(
"max-period",
Element::create(
static_cast<long int>(max_period)));
55 insertService(command, server_type);
68 insertService(command, server_type);
78 insertService(command, server_type);
88 insertService(command, server_type);
95 insertLeaseExpireTime(lease_as_json);
106 insertLeaseExpireTime(lease_as_json);
122 const uint32_t limit) {
136 args->set(
"from", from_element);
137 args->set(
"limit", limit_element);
150 for (
auto const& lease : *deleted_leases) {
151 ElementPtr lease_as_json = lease->toElement();
152 insertLeaseExpireTime(lease_as_json);
157 if (lease->state_ == Lease6::STATE_RELEASED) {
158 leases_list->add(lease_as_json);
160 deleted_leases_list->add(lease_as_json);
164 for (
auto const& lease : *leases) {
165 ElementPtr lease_as_json = lease->toElement();
166 insertLeaseExpireTime(lease_as_json);
167 leases_list->add(lease_as_json);
171 args->set(
"deleted-leases", deleted_leases_list);
172 args->set(
"leases", leases_list);
187 while ((lease = boost::dynamic_pointer_cast<Lease6>(leases.
pop(op_type)))) {
188 ElementPtr lease_as_json = lease->toElement();
189 insertLeaseExpireTime(lease_as_json);
191 deleted_leases_list->add(lease_as_json);
193 leases_list->add(lease_as_json);
198 args->set(
"deleted-leases", deleted_leases_list);
199 args->set(
"leases", leases_list);
210 insertLeaseExpireTime(lease_as_json);
221 insertLeaseExpireTime(lease_as_json);
237 const uint32_t limit) {
251 args->set(
"from", from_element);
252 args->set(
"limit", limit_element);
270 insertService(command, server_type);
276 const std::string& server_name,
287 insertService(command, server_type);
292CommandCreator::insertLeaseExpireTime(
ElementPtr& lease) {
294 (!lease->contains(
"cltt") || (lease->get(
"cltt")->getType() !=
Element::integer) ||
295 (!lease->contains(
"valid-lft") ||
300 int64_t cltt = lease->get(
"cltt")->intValue();
301 int64_t valid_lifetime = lease->get(
"valid-lft")->intValue();
302 int64_t expire = cltt + valid_lifetime;
304 lease->remove(
"cltt");
319 (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 data::ConstElementPtr createMaintenanceNotify(const std::string &server_name, const bool cancel, const int state, 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 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 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.
std::string stateToString(int state)
Returns state name.
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.