12 #include <boost/pointer_cast.hpp>
21 unordered_set<string> CommandCreator::ha_commands4_ = {
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"
30 unordered_set<string> CommandCreator::ha_commands6_ = {
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"
41 CommandCreator::createDHCPDisable(
const unsigned int max_period,
48 args->set(
"max-period",
Element::create(
static_cast<long int>(max_period)));
51 insertService(command, server_type);
56 CommandCreator::createDHCPEnable(
const HAServerType& server_type) {
61 insertService(command, server_type);
68 insertService(command, server_type);
75 insertService(command, server_type);
80 CommandCreator::createLease4Update(
const Lease4& lease4) {
82 insertLeaseExpireTime(lease_as_json);
91 CommandCreator::createLease4Delete(
const Lease4& lease4) {
93 insertLeaseExpireTime(lease_as_json);
101 CommandCreator::createLease4GetAll() {
108 CommandCreator::createLease4GetPage(
const Lease4Ptr& last_lease4,
109 const uint32_t limit) {
123 args->set(
"from", from_element);
124 args->set(
"limit", limit_element);
136 for (
auto lease = deleted_leases->begin(); lease != deleted_leases->end();
138 ElementPtr lease_as_json = (*lease)->toElement();
139 insertLeaseExpireTime(lease_as_json);
140 deleted_leases_list->add(lease_as_json);
144 for (
auto lease = leases->begin(); lease != leases->end();
146 ElementPtr lease_as_json = (*lease)->toElement();
147 insertLeaseExpireTime(lease_as_json);
148 leases_list->add(lease_as_json);
152 args->set(
"deleted-leases", deleted_leases_list);
153 args->set(
"leases", leases_list);
168 while ((lease = boost::dynamic_pointer_cast<Lease6>(leases.
pop(op_type)))) {
169 ElementPtr lease_as_json = lease->toElement();
170 insertLeaseExpireTime(lease_as_json);
171 if (op_type == LeaseUpdateBacklog::DELETE) {
172 deleted_leases_list->add(lease_as_json);
174 leases_list->add(lease_as_json);
179 args->set(
"deleted-leases", deleted_leases_list);
180 args->set(
"leases", leases_list);
189 CommandCreator::createLease6Update(
const Lease6& lease6) {
191 insertLeaseExpireTime(lease_as_json);
200 CommandCreator::createLease6Delete(
const Lease6& lease6) {
202 insertLeaseExpireTime(lease_as_json);
210 CommandCreator::createLease6GetAll() {
217 CommandCreator::createLease6GetPage(
const Lease6Ptr& last_lease6,
218 const uint32_t limit) {
232 args->set(
"from", from_element);
233 args->set(
"limit", limit_element);
242 CommandCreator::createMaintenanceNotify(
const bool cancel,
const HAServerType& server_type) {
246 insertService(command, server_type);
251 CommandCreator::createSyncCompleteNotify(
const HAServerType& server_type) {
253 insertService(command, server_type);
258 CommandCreator::insertLeaseExpireTime(
ElementPtr& lease) {
260 (!lease->contains(
"cltt") || (lease->get(
"cltt")->getType() !=
Element::integer) ||
261 (!lease->contains(
"valid-lft") ||
266 int64_t cltt = lease->get(
"cltt")->intValue();
267 int64_t valid_lifetime = lease->get(
"valid-lft")->intValue();
268 int64_t expire = cltt + valid_lifetime;
270 lease->remove(
"cltt");
285 (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.
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.