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);
90 CommandCreator::createLease4Delete(
const Lease4& lease4) {
92 insertLeaseExpireTime(lease_as_json);
99 CommandCreator::createLease4GetAll() {
106 CommandCreator::createLease4GetPage(
const Lease4Ptr& last_lease4,
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);
168 if (op_type == LeaseUpdateBacklog::DELETE) {
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);
185 CommandCreator::createLease6Update(
const Lease6& lease6) {
187 insertLeaseExpireTime(lease_as_json);
195 CommandCreator::createLease6Delete(
const Lease6& lease6) {
197 insertLeaseExpireTime(lease_as_json);
204 CommandCreator::createLease6GetAll() {
211 CommandCreator::createLease6GetPage(
const Lease6Ptr& last_lease6,
212 const uint32_t limit) {
226 args->set(
"from", from_element);
227 args->set(
"limit", limit_element);
236 CommandCreator::createMaintenanceNotify(
const bool cancel,
const HAServerType& server_type) {
240 insertService(command, server_type);
245 CommandCreator::createSyncCompleteNotify(
const HAServerType& server_type) {
247 insertService(command, server_type);
252 CommandCreator::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);
Structure that holds a lease for IPv4 address.
OpType
Type of the lease update (operation type).
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
boost::shared_ptr< Element > ElementPtr
HAServerType
Lists possible server types for which HA service is created.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
ConstElementPtr createCommand(const std::string &command)
Creates a standard command message with no argument (of the form { "command": "my_command" }) ...
A generic exception that is thrown when an unexpected error condition occurs.
boost::shared_ptr< const Element > ConstElementPtr
Structure that holds a lease for IPv6 address and/or prefix.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Defines the logger used by the top-level component of kea-lfc.
This file contains several functions and constants that are used for handling commands and responses ...
static ElementPtr create(const Position &pos=ZERO_POSITION())
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
The Element class represents a piece of data, used by the command channel and configuration parts...
dhcp::LeasePtr pop(OpType &op_type)
Returns the next lease update and removes it from the queue.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Queue holding a backlog of unsent lease updates.