Kea 3.1.8
lease_mgr.cc
Go to the documentation of this file.
1// Copyright (C) 2012-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
10#include <dhcp/libdhcp++.h>
11#include <dhcp/option_custom.h>
12#include <dhcpsrv/cfgmgr.h>
13#include <dhcpsrv/dhcpsrv_log.h>
14#include <dhcpsrv/lease_mgr.h>
17#include <stats/stats_mgr.h>
18#include <util/encode/encode.h>
19#include <util/str.h>
20
21#include <boost/algorithm/string.hpp>
22
23#include <algorithm>
24#include <iostream>
25#include <iterator>
26#include <limits>
27#include <map>
28#include <sstream>
29#include <string>
30
31#include <time.h>
32
33using namespace isc::asiolink;
34using namespace isc::config;
35using namespace isc::data;
36using namespace isc::db;
37using namespace isc::dhcp;
38using namespace isc::stats;
39using namespace isc::util;
40using namespace std;
41
42namespace isc {
43namespace dhcp {
44
45LeasePageSize::LeasePageSize(const size_t page_size)
46 : page_size_(page_size) {
47
48 if (page_size_ == 0) {
49 isc_throw(OutOfRange, "page size of retrieved leases must not be 0");
50 }
51
52 if (page_size_ > std::numeric_limits<uint32_t>::max()) {
53 isc_throw(OutOfRange, "page size of retrieved leases must not be greater than "
54 << std::numeric_limits<uint32_t>::max());
55 }
56}
57
60 uint32_t iaid, SubnetID subnet_id) const {
61 Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);
62
63 if (col.size() > 1) {
64 isc_throw(MultipleRecords, "More than one lease found for type "
65 << static_cast<int>(type) << ", duid "
66 << duid.toText() << ", iaid " << iaid
67 << " and subnet-id " << subnet_id);
68 }
69 if (col.empty()) {
70 return (Lease6Ptr());
71 }
72 return (*col.begin());
73}
74
75void
77 using namespace stats;
78
79 StatsMgr& stats_mgr = StatsMgr::instance();
80
82 if (!query) {
84 return;
85 }
86
87 // Zero out the global stats.
88 // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases",
89 // "cumulative-assigned-addresses") never get zeroed.
90 int64_t zero = 0;
91
92 stats_mgr.setValue("assigned-addresses", zero);
93
94 stats_mgr.setValue("declined-addresses", zero);
95
96 // Create if it does not exit reclaimed declined leases global stats.
97 if (!stats_mgr.getObservation("reclaimed-declined-addresses")) {
98 stats_mgr.setValue("reclaimed-declined-addresses", zero);
99 }
100
101 // Create if it does not exit reclaimed leases global stats.
102 if (!stats_mgr.getObservation("reclaimed-leases")) {
103 stats_mgr.setValue("reclaimed-leases", zero);
104 }
105
106 // Create if it does not exit cumulative global stats.
107 if (!stats_mgr.getObservation("cumulative-assigned-addresses")) {
108 stats_mgr.setValue("cumulative-assigned-addresses", zero);
109 }
110
111 // Clear subnet level stats. This ensures we don't end up with corner
112 // cases that leave stale values in place.
113 const Subnet4Collection* subnets =
114 CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
115
116 for (auto const& subnet : *subnets) {
117 SubnetID subnet_id = subnet->getID();
118 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
119 "assigned-addresses"),
120 zero);
121
122 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
123 "declined-addresses"),
124 zero);
125
126 const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
127 "reclaimed-declined-addresses"));
128 if (!stats_mgr.getObservation(name_rec_dec)) {
129 stats_mgr.setValue(name_rec_dec, zero);
130 }
131
132 const std::string name_rec(StatsMgr::generateName("subnet", subnet_id,
133 "reclaimed-leases"));
134 if (!stats_mgr.getObservation(name_rec)) {
135 stats_mgr.setValue(name_rec, zero);
136 }
137
138 for (auto const& pool : subnet->getPools(Lease::TYPE_V4)) {
139 const std::string name_aa(StatsMgr::generateName("subnet", subnet_id,
140 StatsMgr::generateName("pool", pool->getID(),
141 "assigned-addresses")));
142 if (!stats_mgr.getObservation(name_aa)) {
143 stats_mgr.setValue(name_aa, zero);
144 }
145
146 const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
147 StatsMgr::generateName("pool", pool->getID(),
148 "declined-addresses")));
149 if (!stats_mgr.getObservation(name_da)) {
150 stats_mgr.setValue(name_da, zero);
151 }
152
153 const std::string& pname_rec_dec(StatsMgr::generateName("subnet", subnet_id,
154 StatsMgr::generateName("pool", pool->getID(),
155 "reclaimed-declined-addresses")));
156 if (!stats_mgr.getObservation(pname_rec_dec)) {
157 stats_mgr.setValue(pname_rec_dec, zero);
158 }
159
160 const std::string& pname_rec(StatsMgr::generateName("subnet", subnet_id,
161 StatsMgr::generateName("pool", pool->getID(),
162 "reclaimed-leases")));
163 if (!stats_mgr.getObservation(pname_rec)) {
164 stats_mgr.setValue(pname_rec, zero);
165 }
166 }
167 }
168
169 // Get counts per state per subnet. Iterate over the result set
170 // updating the subnet and global values.
171 LeaseStatsRow row;
172 while (query->getNextRow(row)) {
174 // Add to the global value.
175 stats_mgr.addValue("assigned-addresses", row.state_count_);
176
177 // Add to subnet level value.
178 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
179 "assigned-addresses"),
180 row.state_count_);
181 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
182 // Set subnet level value.
183 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
184 "declined-addresses"),
185 row.state_count_);
186
187 // Add to the global value.
188 stats_mgr.addValue("assigned-addresses", row.state_count_);
189
190 // Add to the global value.
191 stats_mgr.addValue("declined-addresses", row.state_count_);
192
193 // Add to subnet level value.
194 // Declined leases also count as assigned.
195 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
196 "assigned-addresses"),
197 row.state_count_);
198 }
199 }
200
202 if (!query) {
204 return;
205 }
206
207 // Get counts per state per subnet and pool. Iterate over the result set
208 // updating the subnet and pool and global values.
209 while (query->getNextRow(row)) {
211 // Add to subnet and pool level value.
212 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
214 "assigned-addresses")),
215 row.state_count_);
216 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
217 // Set subnet and pool level value.
218 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
220 "declined-addresses")),
221 row.state_count_);
222
223 // Add to subnet and pool level value.
224 // Declined leases also count as assigned.
225 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
227 "assigned-addresses")),
228 row.state_count_);
229 }
230 }
231}
232
234 : first_subnet_id_(0), last_subnet_id_(0), select_mode_(select_mode) {
235 if (select_mode != ALL_SUBNETS && select_mode != ALL_SUBNET_POOLS) {
236 isc_throw(BadValue, "LeaseStatsQuery: mode must be either ALL_SUBNETS or ALL_SUBNET_POOLS");
237 }
238}
239
241 : first_subnet_id_(subnet_id), last_subnet_id_(0),
242 select_mode_(SINGLE_SUBNET) {
243
244 if (first_subnet_id_ == 0) {
245 isc_throw(BadValue, "LeaseStatsQuery: subnet_id_ must be > 0");
246 }
247}
248
250 const SubnetID& last_subnet_id)
251 : first_subnet_id_(first_subnet_id), last_subnet_id_(last_subnet_id),
252 select_mode_(SUBNET_RANGE) {
253
254 if (first_subnet_id_ == 0) {
255 isc_throw(BadValue, "LeaseStatsQuery: first_subnet_id_ must be > 0");
256 }
257
258 if (last_subnet_id_ == 0) {
259 isc_throw(BadValue, "LeaseStatsQuery: last_subnet_id_ must be > 0");
260 }
261
264 "LeaseStatsQuery: last_subnet_id_must be > first_subnet_id_");
265 }
266}
267
272
277
280 return(LeaseStatsQueryPtr());
281}
282
285 const SubnetID& /* last_subnet_id */) {
286 return(LeaseStatsQueryPtr());
287}
288
289bool
291 return (false);
292}
293
294void
296 using namespace stats;
297
298 StatsMgr& stats_mgr = StatsMgr::instance();
299
301 if (!query) {
303 return;
304 }
305
306 // Zero out the global stats.
307 // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases",
308 // "cumulative-assigned-nas", "cumulative-assigned-pds",
309 // "cumulative-registered-nas")) never get zeroed.
310 int64_t zero = 0;
311
312 stats_mgr.setValue("assigned-nas", zero);
313
314 stats_mgr.setValue("assigned-pds", zero);
315
316 stats_mgr.setValue("declined-addresses", zero);
317
318 if (!stats_mgr.getObservation("reclaimed-declined-addresses")) {
319 stats_mgr.setValue("reclaimed-declined-addresses", zero);
320 }
321
322 if (!stats_mgr.getObservation("reclaimed-leases")) {
323 stats_mgr.setValue("reclaimed-leases", zero);
324 }
325
326 // Create if it does not exit cumulative nas global stats.
327 if (!stats_mgr.getObservation("cumulative-assigned-nas")) {
328 stats_mgr.setValue("cumulative-assigned-nas", zero);
329 }
330
331 // Create if it does not exit cumulative pds global stats.
332 if (!stats_mgr.getObservation("cumulative-assigned-pds")) {
333 stats_mgr.setValue("cumulative-assigned-pds", zero);
334 }
335
336 // Create if it does not exit cumulative registered nas global stats.
337 if (!stats_mgr.getObservation("cumulative-registered-nas")) {
338 stats_mgr.setValue("cumulative-registered-nas", zero);
339 }
340
341 // Clear subnet level stats. This ensures we don't end up with corner
342 // cases that leave stale values in place.
343 const Subnet6Collection* subnets =
344 CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
345
346 for (auto const& subnet : *subnets) {
347 SubnetID subnet_id = subnet->getID();
348 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
349 "assigned-nas"),
350 zero);
351
352 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
353 "assigned-pds"),
354 zero);
355
356 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
357 "declined-addresses"),
358 zero);
359
360 if (!stats_mgr.getObservation(
361 StatsMgr::generateName("subnet", subnet_id,
362 "reclaimed-declined-addresses"))) {
363 stats_mgr.setValue(
364 StatsMgr::generateName("subnet", subnet_id,
365 "reclaimed-declined-addresses"),
366 zero);
367 }
368
369 if (!stats_mgr.getObservation(
370 StatsMgr::generateName("subnet", subnet_id,
371 "reclaimed-leases"))) {
372 stats_mgr.setValue(
373 StatsMgr::generateName("subnet", subnet_id,
374 "reclaimed-leases"),
375 zero);
376 }
377
378 if (!stats_mgr.getObservation(
379 StatsMgr::generateName("subnet", subnet_id,
380 "registered-nas"))) {
381 stats_mgr.setValue(
382 StatsMgr::generateName("subnet", subnet_id,
383 "registered-nas"),
384 zero);
385 }
386
387 for (auto const& pool : subnet->getPools(Lease::TYPE_NA)) {
388 const std::string& name_anas(StatsMgr::generateName("subnet", subnet_id,
389 StatsMgr::generateName("pool", pool->getID(),
390 "assigned-nas")));
391 if (!stats_mgr.getObservation(name_anas)) {
392 stats_mgr.setValue(name_anas, zero);
393 }
394
395 const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
396 StatsMgr::generateName("pool", pool->getID(),
397 "declined-addresses")));
398 if (!stats_mgr.getObservation(name_da)) {
399 stats_mgr.setValue(name_da, zero);
400 }
401
402 const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
403 StatsMgr::generateName("pool", pool->getID(),
404 "reclaimed-declined-addresses")));
405 if (!stats_mgr.getObservation(name_rec_dec)) {
406 stats_mgr.setValue(name_rec_dec, zero);
407 }
408
409 const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
410 StatsMgr::generateName("pool", pool->getID(),
411 "reclaimed-leases")));
412 if (!stats_mgr.getObservation(name_rec)) {
413 stats_mgr.setValue(name_rec, zero);
414 }
415 }
416
417 for (auto const& pool : subnet->getPools(Lease::TYPE_PD)) {
418 const std::string& name_apds(StatsMgr::generateName("subnet", subnet_id,
419 StatsMgr::generateName("pd-pool", pool->getID(),
420 "assigned-pds")));
421 if (!stats_mgr.getObservation(name_apds)) {
422 stats_mgr.setValue(name_apds, zero);
423 }
424
425 const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
426 StatsMgr::generateName("pd-pool", pool->getID(),
427 "reclaimed-leases")));
428 if (!stats_mgr.getObservation(name_rec)) {
429 stats_mgr.setValue(name_rec, zero);
430 }
431 }
432 }
433
434 // Get counts per state per subnet. Iterate over the result set
435 // updating the subnet and global values.
436 LeaseStatsRow row;
437 while (query->getNextRow(row)) {
438 switch(row.lease_type_) {
439 case Lease::TYPE_NA:
441 // Add to the global value.
442 stats_mgr.addValue("assigned-nas", row.state_count_);
443
444 // Add to subnet level value.
445 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
446 "assigned-nas"),
447 row.state_count_);
448 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
449 // Set subnet level value.
450 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
451 "declined-addresses"),
452 row.state_count_);
453
454 // Add to the global value.
455 stats_mgr.addValue("assigned-nas", row.state_count_);
456
457 // Add to the global value.
458 stats_mgr.addValue("declined-addresses", row.state_count_);
459
460 // Add to subnet level value.
461 // Declined leases also count as assigned.
462 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
463 "assigned-nas"),
464 row.state_count_);
465 } else if (row.lease_state_ == Lease::STATE_REGISTERED) {
466 // Add to subnet level value
467 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
468 "registered-nas"),
469 row.state_count_);
470 }
471 break;
472
473 case Lease::TYPE_PD:
475 // Add to the global value.
476 stats_mgr.addValue("assigned-pds", row.state_count_);
477
478 // Set subnet level value.
479 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
480 "assigned-pds"),
481 row.state_count_);
482 }
483 break;
484
485 default:
486 // We don't support TYPE_TAs yet
487 break;
488 }
489 }
490
492 if (!query) {
494 return;
495 }
496
497 // Get counts per state per subnet and pool. Iterate over the result set
498 // updating the subnet and pool and global values.
499 while (query->getNextRow(row)) {
500 switch(row.lease_type_) {
501 case Lease::TYPE_NA:
503 // Add to subnet and pool level value.
504 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
506 "assigned-nas")),
507 row.state_count_);
508 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
509 // Set subnet and pool level value.
510 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
512 "declined-addresses")),
513 row.state_count_);
514
515 // Add to subnet and pool level value.
516 // Declined leases also count as assigned.
517 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
519 "assigned-nas")),
520 row.state_count_);
521 }
522 break;
523
524 case Lease::TYPE_PD:
526 // Set subnet and pool level value.
527 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
528 StatsMgr::generateName("pd-pool", row.pool_id_,
529 "assigned-pds")),
530 row.state_count_);
531 }
532 break;
533
534 default:
535 // We don't support TYPE_TAs yet
536 break;
537 }
538 }
539}
540
545
550
553 return(LeaseStatsQueryPtr());
554}
555
558 const SubnetID& /* last_subnet_id */) {
559 return(LeaseStatsQueryPtr());
560}
561
562std::string
564 isc_throw(NotImplemented, "LeaseMgr::getDBVersion() called");
565}
566
567void
569 std::string extended_info_tables;
570 try {
571 extended_info_tables = parameters.at("extended-info-tables");
572 } catch (const exception&) {
573 extended_info_tables = "false";
574 }
575 // If extended_info_tables is 'true' we will enable them.
576 if (extended_info_tables == "true") {
578 }
579}
580
581bool
585
586 bool changed = false;
587 if (!lease) {
588 return (changed);
589 }
590
592 return (changed);
593 }
594
595 ConstElementPtr user_context = lease->getContext();
596 if (!user_context) {
597 return (changed);
598 }
599
601 ConstElementPtr extended_info;
602 ElementPtr mutable_user_context;
603 ElementPtr mutable_isc;
604 string verifying = "";
605 bool removed_extended_info = false;
606
607 try {
608 verifying = "user context";
609 if (user_context->getType() != Element::map) {
610 isc_throw(BadValue, "user context is not a map");
611 }
612 if (user_context->empty()) {
613 changed = true;
614 lease->setContext(ConstElementPtr());
615 return (changed);
616 }
617
618 verifying = "isc";
619 isc = user_context->get("ISC");
620 if (!isc) {
621 return (changed);
622 }
623 mutable_user_context =
624 boost::const_pointer_cast<Element>(user_context);
625 if (!mutable_user_context) {
626 // Should not happen...
627 mutable_user_context = copy(user_context, 0);
628 lease->setContext(mutable_user_context);
629 }
630
631 if (isc->getType() != Element::map) {
632 isc_throw(BadValue, "ISC entry is not a map");
633 }
634 if (isc->empty()) {
635 changed = true;
636 mutable_user_context->remove("ISC");
637 if (mutable_user_context->empty()) {
638 lease->setContext(ConstElementPtr());
639 }
640 return (changed);
641 }
642
643 verifying = "relay-agent-info";
644 extended_info = isc->get("relay-agent-info");
645 if (!extended_info) {
646 return (changed);
647 }
648 mutable_isc = boost::const_pointer_cast<Element>(isc);
649 if (!mutable_isc) {
650 // Should not happen...
651 mutable_isc = copy(isc, 0);
652 mutable_user_context->set("ISC", mutable_isc);
653 }
654
655 if (extended_info->getType() == Element::string) {
656 // Upgrade
657 changed = true;
658 ElementPtr upgraded = Element::createMap();
659 upgraded->set("sub-options", extended_info);
660 mutable_isc->set("relay-agent-info", upgraded);
661
662 // Try to decode sub-options.
663 verifying = "rai";
664 string rai_hex = extended_info->stringValue();
665 vector<uint8_t> rai_data;
666 str::decodeFormattedHexString(rai_hex, rai_data);
667 OptionCustomPtr rai(new OptionCustom(rai_def, Option::V4, rai_data));
668 if (!rai) {
669 isc_throw(BadValue, "can't create RAI option");
670 }
671
672 OptionPtr remote_id = rai->getOption(RAI_OPTION_REMOTE_ID);
673 if (remote_id) {
674 vector<uint8_t> bytes = remote_id->toBinary();
675 if (bytes.size() > 0) {
676 upgraded->set("remote-id",
678 }
679 }
680
681 OptionPtr relay_id = rai->getOption(RAI_OPTION_RELAY_ID);
682 if (relay_id) {
683 vector<uint8_t> bytes = relay_id->toBinary(false);
684 if (bytes.size() > 0) {
685 upgraded->set("relay-id",
687 }
688 }
689
692 .arg(lease->addr_.toText());
693 return (changed);
694 } else if (extended_info->getType() != Element::map) {
695 mutable_isc->remove("relay-agent-info");
696 removed_extended_info = true;
697 isc_throw(BadValue, "relay-agent-info is not a map or a string");
698 }
699
701 return (changed);
702 }
703
704 // Try to decode sub-options.
705 ConstElementPtr sub_options = extended_info->get("sub-options");
706 if (sub_options) {
707 verifying = "sub-options";
708 if (sub_options->getType() != Element::string) {
709 mutable_isc->remove("relay-agent-info");
710 removed_extended_info = true;
711 isc_throw(BadValue, "sub-options is not a string");
712 }
713 string rai_hex = sub_options->stringValue();
714 vector<uint8_t> rai_data;
715 str::decodeFormattedHexString(rai_hex, rai_data);
716 }
717
718 ConstElementPtr remote_id = extended_info->get("remote-id");
719 if (remote_id) {
720 verifying = "remote-id";
721 if (remote_id->getType() != Element::string) {
722 mutable_isc->remove("relay-agent-info");
723 removed_extended_info = true;
724 isc_throw(BadValue, "remote-id is not a string");
725 }
726 string remote_id_hex = remote_id->stringValue();
727 vector<uint8_t> remote_id_data;
728 encode::decodeHex(remote_id_hex, remote_id_data);
729 if (remote_id_data.empty()) {
730 mutable_isc->remove("relay-agent-info");
731 removed_extended_info = true;
732 isc_throw(BadValue, "remote-id is empty");
733 }
734 }
735
736 ConstElementPtr relay_id = extended_info->get("relay-id");
737 if (relay_id) {
738 verifying = "relay-id";
739 if (relay_id->getType() != Element::string) {
740 mutable_isc->remove("relay-agent-info");
741 removed_extended_info = true;
742 isc_throw(BadValue, "relay-id is not a string");
743 }
744 string relay_id_hex = relay_id->stringValue();
745 vector<uint8_t> relay_id_data;
746 encode::decodeHex(relay_id_hex, relay_id_data);
747 if (relay_id_data.empty()) {
748 mutable_isc->remove("relay-agent-info");
749 removed_extended_info = true;
750 isc_throw(BadValue, "relay-id is empty");
751 }
752 }
753
755 return (changed);
756 }
757
758 verifying = "relay-agent-info";
759 for (auto const& elem : extended_info->mapValue()) {
760 if ((elem.first != "sub-options") &&
761 (elem.first != "remote-id") &&
762 (elem.first != "relay-id") &&
763 (elem.first != "comment")) {
764 mutable_isc->remove("relay-agent-info");
765 removed_extended_info = true;
766 isc_throw(BadValue, "spurious '" << elem.first <<
767 "' entry in relay-agent-info");
768 }
769 }
770
771 return (changed);
772 } catch (const exception& ex) {
773 ostringstream err;
774 err << "in " << verifying << " a problem was found: " << ex.what();
776 .arg(lease->addr_.toText())
777 .arg(err.str());
778
779 changed = true;
780 if (verifying == "user context") {
781 lease->setContext(ConstElementPtr());
782 } else if (verifying == "isc") {
783 mutable_user_context->remove("ISC");
784 if (mutable_user_context->empty()) {
785 lease->setContext(ConstElementPtr());
786 }
787 } else {
788 if (!removed_extended_info) {
789 mutable_isc->remove("relay-agent-info");
790 }
791 if (mutable_isc->empty()) {
792 mutable_user_context->remove("ISC");
793 if (mutable_user_context->empty()) {
794 lease->setContext(ConstElementPtr());
795 }
796 }
797 }
798 return (changed);
799 }
800}
801
802bool
805 bool changed = false;
806 if (!lease) {
807 return (changed);
808 }
809
811 return (changed);
812 }
813
814 ConstElementPtr user_context = lease->getContext();
815 if (!user_context) {
816 return (changed);
817 }
818
820 ConstElementPtr relay_info;
821 ElementPtr mutable_user_context;
822 ElementPtr mutable_isc;
823 string verifying = "";
824 bool removed_relay_info = false;
825 bool upgraded = false;
826 bool have_both = false;
827 int i = -1;
828
829 try {
830 verifying = "user context";
831 if (user_context->getType() != Element::map) {
832 isc_throw(BadValue, "user context is not a map");
833 }
834 if (user_context->empty()) {
835 changed = true;
836 lease->setContext(ConstElementPtr());
837 return (changed);
838 }
839
840 verifying = "isc";
841 isc = user_context->get("ISC");
842 if (!isc) {
843 return (changed);
844 }
845 mutable_user_context =
846 boost::const_pointer_cast<Element>(user_context);
847 if (!mutable_user_context) {
848 // Should not happen...
849 mutable_user_context = copy(user_context, 0);
850 lease->setContext(mutable_user_context);
851 }
852
853 if (isc->getType() != Element::map) {
854 isc_throw(BadValue, "ISC entry is not a map");
855 }
856 if (isc->empty()) {
857 changed = true;
858 mutable_user_context->remove("ISC");
859 if (mutable_user_context->empty()) {
860 lease->setContext(ConstElementPtr());
861 }
862 return (changed);
863 }
864 mutable_isc = boost::const_pointer_cast<Element>(isc);
865 if (!mutable_isc) {
866 // Should not happen...
867 mutable_isc = copy(isc, 0);
868 mutable_user_context->set("ISC", mutable_isc);
869 }
870
871 relay_info = mutable_isc->get("relays");
872 if (relay_info && isc->contains("relay-info")) {
873 changed = true;
874 mutable_isc->remove("relays");
875 have_both = true;
876 relay_info.reset();
877 }
878 if (relay_info) {
879 // Upgrade
880 changed = true;
881 upgraded = true;
882 verifying = "relays";
883 mutable_isc->set("relay-info", relay_info);
884 mutable_isc->remove("relays");
885
886 if (relay_info->getType() != Element::list) {
887 mutable_isc->remove("relay-info");
888 removed_relay_info = true;
889 isc_throw(BadValue, "relays is not a list");
890 }
891 if (relay_info->empty()) {
892 mutable_isc->remove("relay-info");
893 removed_relay_info = true;
894 isc_throw(BadValue, "relays is empty");
895 }
896
897 verifying = "relay";
898 for (i = 0; static_cast<size_t>(i) < relay_info->size(); ++i) {
899 ElementPtr relay = relay_info->getNonConst(i);
900 if (!relay) {
901 mutable_isc->remove("relay-info");
902 removed_relay_info = true;
903 isc_throw(BadValue, "null relay#" << i);
904 }
905 if (relay->getType() != Element::map) {
906 mutable_isc->remove("relay-info");
907 removed_relay_info = true;
908 isc_throw(BadValue, "relay#" << i << " is not a map");
909 }
910
911 // Try to decode options.
912 ConstElementPtr options = relay->get("options");
913 if (!options) {
914 continue;
915 }
916
917 verifying = "options";
918 if (options->getType() != Element::string) {
919 mutable_isc->remove("relay-info");
920 removed_relay_info = true;
921 isc_throw(BadValue, "options is not a string");
922 }
923 string options_hex = options->stringValue();
924 vector<uint8_t> options_data;
925 str::decodeFormattedHexString(options_hex, options_data);
926 OptionCollection opts;
927 LibDHCP::unpackOptions6(options_data, DHCP6_OPTION_SPACE, opts);
928
929 auto remote_id_it = opts.find(D6O_REMOTE_ID);
930 if (remote_id_it != opts.end()) {
931 OptionPtr remote_id = remote_id_it->second;
932 if (remote_id) {
933 vector<uint8_t> bytes = remote_id->toBinary();
934 if (bytes.size() > 0) {
935 relay->set("remote-id",
937 }
938 }
939 }
940
941 auto relay_id_it = opts.find(D6O_RELAY_ID);
942 if (relay_id_it != opts.end()) {
943 OptionPtr relay_id = relay_id_it->second;
944 if (relay_id) {
945 vector<uint8_t> bytes = relay_id->toBinary(false);
946 if (bytes.size() > 0) {
947 relay->set("relay-id",
949 }
950 }
951 }
952 }
953 }
954
955 verifying = (upgraded ? "relays" : "relay-info");
956 i = -1;
957 relay_info = mutable_isc->get("relay-info");
958 if (!relay_info) {
959 return (changed);
960 }
961 if (!upgraded && (relay_info->getType() != Element::list)) {
962 mutable_isc->remove("relay-info");
963 removed_relay_info = true;
964 isc_throw(BadValue, "relay-info is not a list");
965 }
966 if (!upgraded && relay_info->empty()) {
967 mutable_isc->remove("relay-info");
968 removed_relay_info = true;
969 isc_throw(BadValue, "relay-info is empty");
970 }
971
972 verifying = "relay";
973 for (i = 0; static_cast<size_t>(i) < relay_info->size(); ++i) {
974 ElementPtr relay = relay_info->getNonConst(i);
975 if (!upgraded && !relay) {
976 mutable_isc->remove("relay-info");
977 removed_relay_info = true;
978 isc_throw(BadValue, "null relay#" << i);
979 }
980 if (!upgraded && (relay->getType() != Element::map)) {
981 mutable_isc->remove("relay-info");
982 removed_relay_info = true;
983 isc_throw(BadValue, "relay#" << i << " is not a map");
984 }
985
986 ConstElementPtr options = relay->get("options");
987 if (!upgraded && options) {
988 // Try to decode options.
989 verifying = "options";
990 if (options->getType() != Element::string) {
991 mutable_isc->remove("relay-info");
992 removed_relay_info = true;
993 isc_throw(BadValue, "options is not a string");
994 }
995 string options_hex = options->stringValue();
996 vector<uint8_t> options_data;
997 str::decodeFormattedHexString(options_hex, options_data);
998 OptionCollection opts;
999 LibDHCP::unpackOptions6(options_data, DHCP6_OPTION_SPACE, opts);
1000 }
1002 continue;
1003 }
1004
1005 verifying = "link";
1006 ConstElementPtr link_addr = relay->get("link");
1007 if (!link_addr) {
1008 mutable_isc->remove("relay-info");
1009 removed_relay_info = true;
1010 isc_throw(BadValue, "no link");
1011 }
1012 if (link_addr->getType() != Element::string) {
1013 mutable_isc->remove("relay-info");
1014 removed_relay_info = true;
1015 isc_throw(BadValue, "link is not a string");
1016 }
1017 IOAddress laddr(link_addr->stringValue());
1018 if (!laddr.isV6()) {
1019 mutable_isc->remove("relay-info");
1020 removed_relay_info = true;
1021 isc_throw(BadValue, "link is not an IPv6 address");
1022 }
1023
1024 ConstElementPtr remote_id = relay->get("remote-id");
1025 if (!upgraded && remote_id) {
1026 verifying = "remote-id";
1027 if (remote_id->getType() != Element::string) {
1028 mutable_isc->remove("relay-info");
1029 removed_relay_info = true;
1030 isc_throw(BadValue, "remote-id is not a string");
1031 }
1032 string remote_id_hex = remote_id->stringValue();
1033 vector<uint8_t> remote_id_data;
1034 encode::decodeHex(remote_id_hex, remote_id_data);
1035 if (remote_id_data.empty()) {
1036 mutable_isc->remove("relay-info");
1037 removed_relay_info = true;
1038 isc_throw(BadValue, "remote-id is empty");
1039 }
1040 }
1041
1042 ConstElementPtr relay_id = relay->get("relay-id");
1043 if (!upgraded && relay_id) {
1044 verifying = "relay-id";
1045 if (relay_id->getType() != Element::string) {
1046 mutable_isc->remove("relay-info");
1047 removed_relay_info = true;
1048 isc_throw(BadValue, "relay-id is not a string");
1049 }
1050 string relay_id_hex = relay_id->stringValue();
1051 vector<uint8_t> relay_id_data;
1052 encode::decodeHex(relay_id_hex, relay_id_data);
1053 if (relay_id_data.empty()) {
1054 mutable_isc->remove("relay-info");
1055 removed_relay_info = true;
1056 isc_throw(BadValue, "relay-id is empty");
1057 }
1058 }
1059
1061 continue;
1062 }
1063
1064 verifying = "peer";
1065 ConstElementPtr peer_addr = relay->get("peer");
1066 if (!peer_addr) {
1067 mutable_isc->remove("relay-info");
1068 removed_relay_info = true;
1069 isc_throw(BadValue, "no peer");
1070 }
1071 if (peer_addr->getType() != Element::string) {
1072 mutable_isc->remove("relay-info");
1073 removed_relay_info = true;
1074 isc_throw(BadValue, "peer is not a string");
1075 }
1076 IOAddress paddr(peer_addr->stringValue());
1077 if (!paddr.isV6()) {
1078 mutable_isc->remove("relay-info");
1079 removed_relay_info = true;
1080 isc_throw(BadValue, "peer is not an IPv6 address");
1081 }
1082
1083 verifying = "hop";
1084 ConstElementPtr hop = relay->get("hop");
1085 if (!hop) {
1086 mutable_isc->remove("relay-info");
1087 removed_relay_info = true;
1088 isc_throw(BadValue, "no hop");
1089 }
1090 if (hop->getType() != Element::integer) {
1091 mutable_isc->remove("relay-info");
1092 removed_relay_info = true;
1093 isc_throw(BadValue, "hop is not an integer");
1094 }
1095
1096 verifying = (upgraded ? "relays" : "relay-info");
1097 for (auto const& elem : relay->mapValue()) {
1098 if ((elem.first != "hop") &&
1099 (elem.first != "link") &&
1100 (elem.first != "peer") &&
1101 (elem.first != "options") &&
1102 (elem.first != "remote-id") &&
1103 (elem.first != "relay-id") &&
1104 (elem.first != "comment")) {
1105 mutable_isc->remove("relay-info");
1106 removed_relay_info = true;
1107 isc_throw(BadValue, "spurious '" << elem.first << "' entry");
1108 }
1109 }
1110 }
1111
1112 if (upgraded) {
1115 .arg(lease->addr_.toText());
1116 }
1117
1118 return (changed);
1119 } catch (const exception& ex) {
1120 ostringstream err;
1121 err << "in " << verifying;
1122 if (i >= 0) {
1123 err << " [relay#" << i << "]";
1124 }
1125 err << " a problem was found: " << ex.what();
1127 .arg(lease->addr_.toText())
1128 .arg(err.str());
1129
1130 changed = true;
1131 have_both = !have_both;
1132 if (verifying == "user context") {
1133 lease->setContext(ConstElementPtr());
1134 } else if (verifying == "isc") {
1135 mutable_user_context->remove("ISC");
1136 if (mutable_user_context->empty()) {
1137 lease->setContext(ConstElementPtr());
1138 }
1139 } else {
1140 if (!removed_relay_info) {
1141 mutable_isc->remove("relay-info");
1142 }
1143 if (mutable_isc->empty()) {
1144 mutable_user_context->remove("ISC");
1145 if (mutable_user_context->empty()) {
1146 lease->setContext(ConstElementPtr());
1147 }
1148 }
1149 }
1150 return (changed);
1151 }
1152}
1153
1154void
1156 bool ignore_errors) {
1157 if (!lease) {
1158 return;
1159 }
1160
1161 ConstElementPtr user_context = lease->getContext();
1162 if (!user_context) {
1163 return;
1164 }
1165 if (user_context->getType() != Element::map) {
1166 if (ignore_errors) {
1167 return;
1168 }
1169 isc_throw(BadValue, "user context is not a map");
1170 }
1171 if (user_context->empty()) {
1172 return;
1173 }
1174
1175 ConstElementPtr isc = user_context->get("ISC");
1176 if (!isc) {
1177 return;
1178 }
1179 if (isc->getType() != Element::map) {
1180 if (ignore_errors) {
1181 return;
1182 }
1183 isc_throw(BadValue, "ISC entry is not a map");
1184 }
1185 if (isc->empty()) {
1186 return;
1187 }
1188
1189 ConstElementPtr extended_info = isc->get("relay-agent-info");
1190 if (!extended_info) {
1191 return;
1192 }
1193 if (extended_info->getType() != Element::map) {
1194 if (ignore_errors) {
1195 return;
1196 }
1197 isc_throw(BadValue, "relay-agent-info is not a map");
1198 }
1199 if (extended_info->empty()) {
1200 return;
1201 }
1202
1203 ConstElementPtr relay_id = extended_info->get("relay-id");
1204 if (relay_id) {
1205 if (relay_id->getType() == Element::string) {
1206 vector<uint8_t> bytes;
1207 try {
1208 encode::decodeHex(relay_id->stringValue(), bytes);
1209 } catch (...) {
1210 // Decode failed
1211 if (!ignore_errors) {
1212 throw;
1213 }
1214 }
1215 lease->relay_id_ = bytes;
1216 } else if (!ignore_errors) {
1217 isc_throw(BadValue, "relay-id entry is not a string");
1218 }
1219 }
1220
1221 ConstElementPtr remote_id = extended_info->get("remote-id");
1222 if (remote_id) {
1223 if (remote_id->getType() == Element::string) {
1224 vector<uint8_t> bytes;
1225 try {
1226 encode::decodeHex(remote_id->stringValue(), bytes);
1227 } catch (...) {
1228 // Decode failed
1229 if (!ignore_errors) {
1230 throw;
1231 }
1232 }
1233 lease->remote_id_ = bytes;
1234 } else if (!ignore_errors) {
1235 isc_throw(BadValue, "remote-id entry is not a string");
1236 }
1237 }
1238}
1239
1240bool
1242
1243 bool added = false;
1244 if (!lease) {
1245 return (added);
1246 }
1247
1248 ConstElementPtr user_context = lease->getContext();
1249 if (!user_context || (user_context->getType() != Element::map) ||
1250 user_context->empty()) {
1251 return (added);
1252 }
1253
1254 ConstElementPtr isc = user_context->get("ISC");
1255 if (!isc || (isc->getType() != Element::map) || isc->empty()) {
1256 return (added);
1257 }
1258
1259 ConstElementPtr relay_info = isc->get("relay-info");
1260 if (!relay_info || (relay_info->getType() != Element::list) ||
1261 relay_info->empty()) {
1262 return (added);
1263 }
1264
1265 for (unsigned i = 0; i < relay_info->size(); ++i) {
1266 ConstElementPtr relay = relay_info->get(i);
1267 if (!relay || (relay->getType() != Element::map) || relay->empty()) {
1268 continue;
1269 }
1270 try {
1271 ConstElementPtr relay_id = relay->get("relay-id");
1272 if (relay_id) {
1273 string relay_id_hex = relay_id->stringValue();
1274 vector<uint8_t> relay_id_data;
1275 encode::decodeHex(relay_id_hex, relay_id_data);
1276 if (relay_id_data.empty()) {
1277 continue;
1278 }
1279 addRelayId6(lease->addr_, relay_id_data);
1280 added = true;
1281 }
1282
1283 ConstElementPtr remote_id = relay->get("remote-id");
1284 if (remote_id) {
1285 string remote_id_hex = remote_id->stringValue();
1286 vector<uint8_t> remote_id_data;
1287 encode::decodeHex(remote_id_hex, remote_id_data);
1288 if (remote_id_data.empty()) {
1289 continue;
1290 }
1291 addRemoteId6(lease->addr_, remote_id_data);
1292 added = true;
1293 }
1294 } catch (const exception&) {
1295 continue;
1296 }
1297 }
1298 return (added);
1299}
1300
1301size_t
1303 return (0);
1304}
1305
1306size_t
1308 return (0);
1309}
1310
1313 return (ElementPtr());
1314}
1315
1318 ostringstream msg;
1319 msg << "lease backend '" << getName() << "' is not 'memfile'";
1321}
1322
1323void
1325 if (!lease->stateExpiredReclaimed()) {
1326 StatsMgr::instance().addValue("assigned-addresses", static_cast<int64_t>(1));
1327
1329 StatsMgr::generateName("subnet", lease->subnet_id_,
1330 "assigned-addresses"),
1331 static_cast<int64_t>(1));
1332
1333 PoolPtr pool;
1334 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
1335 if (subnet) {
1336 pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
1337 if (pool) {
1339 StatsMgr::generateName("subnet", subnet->getID(),
1340 StatsMgr::generateName("pool", pool->getID(),
1341 "assigned-addresses")),
1342 static_cast<int64_t>(1));
1343 }
1344 }
1345
1346 if (lease->stateDeclined()) {
1347 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
1348
1350 StatsMgr::generateName("subnet", lease->subnet_id_,
1351 "declined-addresses"),
1352 static_cast<int64_t>(1));
1353
1354 if (pool) {
1356 StatsMgr::generateName("subnet", subnet->getID(),
1357 StatsMgr::generateName("pool", pool->getID(),
1358 "declined-addresses")),
1359 static_cast<int64_t>(1));
1360 }
1361 }
1362 }
1363}
1364
1365void
1367 if (lease->stateRegistered()) {
1369 StatsMgr::generateName("subnet", lease->subnet_id_, "registered-nas"),
1370 static_cast<int64_t>(1));
1371 } else if (!lease->stateExpiredReclaimed()) {
1372 StatsMgr::instance().addValue(lease->type_ == Lease::TYPE_NA ?
1373 "assigned-nas" : "assigned-pds",
1374 static_cast<int64_t>(1));
1375
1377 StatsMgr::generateName("subnet", lease->subnet_id_,
1378 lease->type_ == Lease::TYPE_NA ?
1379 "assigned-nas" : "assigned-pds"),
1380 static_cast<int64_t>(1));
1381
1382 PoolPtr pool;
1383 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
1384 if (subnet) {
1385 pool = subnet->getPool(lease->type_, lease->addr_, false);
1386 if (pool) {
1388 StatsMgr::generateName("subnet", subnet->getID(),
1389 StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
1390 "pool" : "pd-pool", pool->getID(),
1391 lease->type_ == Lease::TYPE_NA ?
1392 "assigned-nas" : "assigned-pds")),
1393 static_cast<int64_t>(1));
1394 }
1395 }
1396
1397 if (lease->stateDeclined()) {
1398 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
1399
1401 StatsMgr::generateName("subnet", lease->subnet_id_,
1402 "declined-addresses"),
1403 static_cast<int64_t>(1));
1404
1405 if (pool) {
1407 StatsMgr::generateName("subnet", subnet->getID(),
1408 StatsMgr::generateName("pool", pool->getID(),
1409 "declined-addresses")),
1410 static_cast<int64_t>(1));
1411 }
1412 }
1413 }
1414}
1415
1416void
1417LeaseMgr::bumpStat(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) {
1418 StatsMgr::instance().addValue(stat, static_cast<int64_t>(value));
1419 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id, stat),
1420 static_cast<int64_t>(value));
1421 if (pool) {
1423 StatsMgr::generateName("pool", pool->getID(), stat)),
1424 static_cast<int64_t>(value));
1425 }
1426}
1427
1428void
1429LeaseMgr::bumpStatPrefix(const std::string& stat, SubnetID& subnet_id, PoolPtr pool, int value) {
1430 StatsMgr::instance().addValue(stat, static_cast<int64_t>(value));
1431 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id, stat),
1432 static_cast<int64_t>(value));
1433 if (pool) {
1435 StatsMgr::generateName("pd-pool", pool->getID(), stat)),
1436 static_cast<int64_t>(value));
1437 }
1438}
1439
1441#define STATE_MASK(new_state, old_state) ((new_state << 4) | old_state)
1442
1444// New state ASSIGNED
1455// New state DECLINED
1466// New state EXPIRED_RECLAIMED
1471#if 0 // Currently unused.
1472constexpr uint16_t RECLAIMED_RECLAIMED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1474constexpr uint16_t RECLAIMED_RELEASED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1476#endif
1479// New state RELEASED
1484#if 0 // Currently unused.
1485constexpr uint16_t RELEASED_RECLAIMED = STATE_MASK(Lease::STATE_RELEASED,
1487constexpr uint16_t RELEASED_RELEASED = STATE_MASK(Lease::STATE_RELEASED,
1489#endif
1492// New state REGISTERED
1502
1503void
1505 const Lease4Ptr& lease) {
1506 if (existing->state_ == Lease::STATE_REGISTERED ||
1507 lease->state_ == Lease::STATE_REGISTERED) {
1508 // Registered is not valid for v4.
1509 return;
1510 }
1511
1512 if (existing->subnet_id_ == lease->subnet_id_) {
1513 if (existing->state_ == lease->state_) {
1514 // Same subnet, same state, nothing to do.
1515 return;
1516 }
1517
1518 // State is different so we know we're updating at least one stat.
1519 PoolPtr pool;
1520 auto const& subnet = CfgMgr::instance().getCurrentCfg()->
1521 getCfgSubnets4()->getBySubnetId(existing->subnet_id_);
1522 if (subnet) {
1523 pool = subnet->getPool(Lease::TYPE_V4, existing->addr_, false);
1524 }
1525
1526 // Switch on new-state:old-state mask.
1527 switch (STATE_MASK(lease->state_ , existing->state_)) {
1528 case ASSIGNED_DECLINED:
1529 bumpStat("declined-addresses", existing->subnet_id_, pool, -1);
1530 break;
1531
1532 case ASSIGNED_RECLAIMED:
1533 case ASSIGNED_RELEASED:
1534 bumpStat("assigned-addresses", existing->subnet_id_, pool, 1);
1535 break;
1536
1537 case DECLINED_ASSIGNED:
1538 bumpStat("declined-addresses", existing->subnet_id_, pool, 1);
1539 break;
1540
1541 case DECLINED_RECLAIMED:
1542 case DECLINED_RELEASED:
1543 bumpStat("assigned-addresses", existing->subnet_id_, pool, 1);
1544 bumpStat("declined-addresses", existing->subnet_id_, pool, 1);
1545 break;
1546
1547 case RECLAIMED_ASSIGNED:
1548 case RELEASED_ASSIGNED:
1549 bumpStat("assigned-addresses", existing->subnet_id_, pool, -1);
1550 break;
1551
1552 case RECLAIMED_DECLINED:
1553 case RELEASED_DECLINED:
1554 bumpStat("assigned-addresses", existing->subnet_id_, pool, -1);
1555 bumpStat("declined-addresses", existing->subnet_id_, pool, -1);
1556 break;
1557 default:
1558 // nothing to do.
1559 break;
1560 };
1561
1562 return;
1563 }
1564
1565 // Lease moved to a different subnet.
1566 // Fetch the new subnet and pool.
1567 auto const& new_subnet = CfgMgr::instance().getCurrentCfg()->
1568 getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
1569 PoolPtr new_pool;
1570 if (new_subnet) {
1571 new_pool = new_subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
1572 }
1573
1574 // Fetch the existing subnet and pool.
1575 auto const& existing_subnet = CfgMgr::instance().getCurrentCfg()->
1576 getCfgSubnets4()->getBySubnetId(existing->subnet_id_);
1577 PoolPtr existing_pool;
1578 if (existing_subnet) {
1579 existing_pool = existing_subnet->getPool(Lease::TYPE_V4, existing->addr_, false);
1580 }
1581
1582 // Switch on new-state:old-state mask.
1583 switch (STATE_MASK(lease->state_ , existing->state_)) {
1584 case ASSIGNED_ASSIGNED:
1585 bumpStat("assigned-addresses", existing->subnet_id_, existing_pool, -1);
1586 bumpStat("assigned-addresses", lease->subnet_id_, new_pool, 1);
1587 break;
1588
1589 case ASSIGNED_DECLINED:
1590 bumpStat("assigned-addresses", existing->subnet_id_, existing_pool, -1);
1591 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1592 bumpStat("assigned-addresses", lease->subnet_id_, new_pool, 1);
1593 break;
1594
1595 case ASSIGNED_RECLAIMED:
1596 case ASSIGNED_RELEASED:
1597 bumpStat("assigned-addresses", lease->subnet_id_, new_pool, 1);
1598 break;
1599
1600 case DECLINED_ASSIGNED:
1601 bumpStat("assigned-addresses", existing->subnet_id_, existing_pool, -1);
1602 bumpStat("assigned-addresses", lease->subnet_id_, new_pool, 1);
1603 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1604 break;
1605
1606 case DECLINED_DECLINED:
1607 bumpStat("assigned-addresses", existing->subnet_id_, existing_pool, -1);
1608 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1609 bumpStat("assigned-addresses", lease->subnet_id_, new_pool, 1);
1610 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1611 break;
1612
1613 case DECLINED_RECLAIMED:
1614 case DECLINED_RELEASED:
1615 bumpStat("assigned-addresses", lease->subnet_id_, new_pool, 1);
1616 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1617 break;
1618
1619 case RECLAIMED_ASSIGNED:
1620 case RELEASED_ASSIGNED:
1621 bumpStat("assigned-addresses", existing->subnet_id_, existing_pool, -1);
1622 break;
1623
1624 case RECLAIMED_DECLINED:
1625 case RELEASED_DECLINED:
1626 bumpStat("assigned-addresses", existing->subnet_id_, existing_pool, -1);
1627 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1628 break;
1629
1630 default:
1631 // nothing to do.
1632 break;
1633 };
1634
1635 return;
1636}
1637
1638void
1640 const Lease6Ptr& lease) {
1641 if (existing->type_ != lease->type_) {
1642 // Something is fishy, mismatched types.
1643 return;
1644 }
1645
1646 if (existing->type_ == Lease::TYPE_PD &&
1647 (existing->state_ == Lease::STATE_DECLINED ||
1648 lease->state_ == Lease::STATE_DECLINED ||
1649 existing->state_ == Lease::STATE_REGISTERED ||
1650 lease->state_ == Lease::STATE_REGISTERED)) {
1651 // Something is fishy. Invalid states for PDs.
1652 return;
1653 }
1654
1655 if (existing->subnet_id_ == lease->subnet_id_) {
1656 if (existing->state_ == lease->state_) {
1657 // Same subnet, same state, nothing to do.
1658 return;
1659 }
1660
1661 // State is different so we know we're updating at least one stat.
1662 PoolPtr pool;
1663 auto const& subnet = CfgMgr::instance().getCurrentCfg()->
1664 getCfgSubnets6()->getBySubnetId(existing->subnet_id_);
1665 if (subnet) {
1666 pool = subnet->getPool(existing->type_, existing->addr_, false);
1667 }
1668
1669 // Switch on new-state:old-state mask.
1670 switch (STATE_MASK(lease->state_, existing->state_)) {
1671 case ASSIGNED_DECLINED:
1672 bumpStat("declined-addresses", existing->subnet_id_, pool, -1);
1673 break;
1674
1675 case ASSIGNED_RECLAIMED:
1676 case ASSIGNED_RELEASED:
1677 if (existing->type_ == Lease::TYPE_NA) {
1678 bumpStat("assigned-nas", existing->subnet_id_, pool, 1);
1679 } else {
1680 bumpStatPrefix("assigned-pds", existing->subnet_id_, pool, 1);
1681 }
1682 break;
1683
1685 bumpStat("assigned-nas", existing->subnet_id_, pool, 1);
1686 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1687 break;
1688
1689 case DECLINED_ASSIGNED:
1690 bumpStat("declined-addresses", existing->subnet_id_, pool, 1);
1691 break;
1692
1693 case DECLINED_RECLAIMED:
1694 case DECLINED_RELEASED:
1695 bumpStat("assigned-nas", existing->subnet_id_, pool, 1);
1696 bumpStat("declined-addresses", existing->subnet_id_, pool, 1);
1697 break;
1698
1700 bumpStat("declined-addresses", existing->subnet_id_, pool, 1);
1701 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1702 break;
1703
1704 case RECLAIMED_ASSIGNED:
1705 case RELEASED_ASSIGNED:
1706 if (existing->type_ == Lease::TYPE_NA) {
1707 bumpStat("assigned-nas", existing->subnet_id_, pool, -1);
1708 } else {
1709 bumpStatPrefix("assigned-pds", existing->subnet_id_, pool, -1);
1710 }
1711 break;
1712
1715 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1716 break;
1717
1718 case RECLAIMED_DECLINED:
1719 case RELEASED_DECLINED:
1720 bumpStat("assigned-nas", existing->subnet_id_, pool, -1);
1721 bumpStat("declined-addresses", existing->subnet_id_, pool, -1);
1722 break;
1723
1725 bumpStat("assigned-nas", existing->subnet_id_, pool, -1);
1726 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), 1);
1727 break;
1728
1730 bumpStat("assigned-nas", existing->subnet_id_, pool, -1);
1731 bumpStat("declined-addresses", existing->subnet_id_, pool, -1);
1732 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), 1);
1733 break;
1734
1737 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), 1);
1738 break;
1739
1740 default:
1741 // nothing to do.
1742 break;
1743 };
1744
1745 return;
1746 }
1747
1748 // Lease moved to a different subnet.
1749 // Fetch the new subnet and pool.
1750 auto const& new_subnet = CfgMgr::instance().getCurrentCfg()->
1751 getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
1752 PoolPtr new_pool;
1753 if (new_subnet) {
1754 new_pool = new_subnet->getPool(lease->type_, lease->addr_, false);
1755 }
1756
1757 // Fetch the existing subnet and pool.
1758 auto const& existing_subnet = CfgMgr::instance().getCurrentCfg()->
1759 getCfgSubnets6()->getBySubnetId(existing->subnet_id_);
1760 PoolPtr existing_pool;
1761 if (existing_subnet) {
1762 existing_pool = existing_subnet->getPool(existing->type_, existing->addr_, false);
1763 }
1764
1765 // Switch on new-state:old-state mask.
1766 switch (STATE_MASK(lease->state_, existing->state_)) {
1767 case ASSIGNED_ASSIGNED:
1768 if (lease->type_ == Lease::TYPE_NA) {
1769 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1770 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1771 } else {
1772 bumpStatPrefix("assigned-pds", existing->subnet_id_, existing_pool, -1);
1773 bumpStatPrefix("assigned-pds", lease->subnet_id_, new_pool, 1);
1774 }
1775 break;
1776
1777 case ASSIGNED_DECLINED:
1778 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1779 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1780 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1781 break;
1782
1783 case ASSIGNED_RECLAIMED:
1784 case ASSIGNED_RELEASED:
1785 if (lease->type_ == Lease::TYPE_NA) {
1786 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1787 } else {
1788 bumpStatPrefix("assigned-pds", lease->subnet_id_, new_pool, 1);
1789 }
1790 break;
1791
1793 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1794 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1795 break;
1796
1797 case DECLINED_ASSIGNED:
1798 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1799 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1800 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1801 break;
1802
1803 case DECLINED_DECLINED:
1804 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1805 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1806 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1807 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1808 break;
1809
1810 case DECLINED_RECLAIMED:
1811 case DECLINED_RELEASED:
1812 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1813 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1814 break;
1815
1817 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1818 bumpStat("assigned-nas", lease->subnet_id_, new_pool, 1);
1819 bumpStat("declined-addresses", lease->subnet_id_, new_pool, 1);
1820 break;
1821
1822 case RECLAIMED_ASSIGNED:
1823 case RELEASED_ASSIGNED:
1824 if (lease->type_ == Lease::TYPE_NA) {
1825 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1826 } else {
1827 bumpStatPrefix("assigned-pds", existing->subnet_id_, existing_pool, -1);
1828 }
1829 break;
1830
1831 case RECLAIMED_DECLINED:
1832 case RELEASED_DECLINED:
1833 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1834 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1835 break;
1836
1839 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1840 break;
1841
1843 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1844 bumpStat("registered-nas", lease->subnet_id_, PoolPtr(), 1);
1845 break;
1846
1848 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1849 bumpStat("declined-addresses", existing->subnet_id_, existing_pool, -1);
1850 bumpStat("registered-nas", lease->subnet_id_, PoolPtr(), 1);
1851 break;
1852
1855 bumpStat("registered-nas", lease->subnet_id_, PoolPtr(), 1);
1856 break;
1857
1859 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1860 bumpStat("registered-nas", lease->subnet_id_, PoolPtr(), 1);
1861 break;
1862
1863 default:
1864 // nothing to do.
1865 break;
1866 };
1867
1868 return;
1869}
1870
1871void
1873 if (!lease->stateExpiredReclaimed()) {
1874 StatsMgr::instance().addValue("assigned-addresses", static_cast<int64_t>(-1));
1875
1877 StatsMgr::generateName("subnet", lease->subnet_id_,
1878 "assigned-addresses"),
1879 static_cast<int64_t>(-1));
1880
1881 PoolPtr pool;
1882 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
1883 if (subnet) {
1884 pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
1885 if (pool) {
1887 StatsMgr::generateName("subnet", subnet->getID(),
1888 StatsMgr::generateName("pool", pool->getID(),
1889 "assigned-addresses")),
1890 static_cast<int64_t>(-1));
1891 }
1892 }
1893
1894 if (lease->stateDeclined()) {
1895 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
1896
1898 StatsMgr::generateName("subnet", lease->subnet_id_,
1899 "declined-addresses"),
1900 static_cast<int64_t>(-1));
1901
1902 if (pool) {
1904 StatsMgr::generateName("subnet", subnet->getID(),
1905 StatsMgr::generateName("pool", pool->getID(),
1906 "declined-addresses")),
1907 static_cast<int64_t>(-1));
1908 }
1909 }
1910 }
1911}
1912
1913void
1915 if (lease->stateRegistered()) {
1917 StatsMgr::generateName("subnet", lease->subnet_id_,
1918 "registered-nas"),
1919 static_cast<int64_t>(-1));
1920 } else if (!lease->stateExpiredReclaimed()) {
1921 StatsMgr::instance().addValue(lease->type_ == Lease::TYPE_NA ?
1922 "assigned-nas" : "assigned-pds",
1923 static_cast<int64_t>(-1));
1924
1926 StatsMgr::generateName("subnet", lease->subnet_id_,
1927 lease->type_ == Lease::TYPE_NA ?
1928 "assigned-nas" : "assigned-pds"),
1929 static_cast<int64_t>(-1));
1930
1931 PoolPtr pool;
1932 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
1933 if (subnet) {
1934 pool = subnet->getPool(lease->type_, lease->addr_, false);
1935 if (pool) {
1937 StatsMgr::generateName("subnet", subnet->getID(),
1938 StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
1939 "pool" : "pd-pool", pool->getID(),
1940 lease->type_ == Lease::TYPE_NA ?
1941 "assigned-nas" : "assigned-pds")),
1942 static_cast<int64_t>(-1));
1943 }
1944 }
1945
1946 if (lease->stateDeclined()) {
1947 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
1948
1950 StatsMgr::generateName("subnet", lease->subnet_id_,
1951 "declined-addresses"),
1952 static_cast<int64_t>(-1));
1953
1954 if (pool) {
1956 StatsMgr::generateName("subnet", subnet->getID(),
1957 StatsMgr::generateName("pool", pool->getID(),
1958 "declined-addresses")),
1959 static_cast<int64_t>(-1));
1960 }
1961 }
1962 }
1963}
1964
1965
1966bool
1968 isc_throw(NotImplemented, "LeaseMgr::sflqCreateFlqPool4() called");
1969}
1970
1973 isc_throw(NotImplemented, "LeaseMgr::sflqPickFreeLease4() called");
1974}
1975
1976bool
1978 isc_throw(NotImplemented, "LeaseMgr::sflqCreateFlqPool6() called");
1979}
1980
1983 isc_throw(NotImplemented, "LeaseMgr::sflqPickFreeLease6() called");
1984}
1985
1986bool
1988 // Only check the subnet if SFLQ is in-use in this config.
1990 auto const& subnet = CfgMgr::instance().getCurrentCfg()->
1991 getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
1992
1993 // We should? always have a subnet.
1994 if (subnet) {
1995 return (subnet->getAllocator(Lease::TYPE_V4)->getType() == "shared-flq");
1996 }
1997 }
1998
1999 return false;
2000}
2001
2002bool
2004 // Only check the subnet if SFLQ is in-use in this config.
2006 auto const& subnet = CfgMgr::instance().getCurrentCfg()->
2007 getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
2008
2009 // We should? always have a subnet.
2010 if (subnet) {
2011 return (subnet->getAllocator(lease->getType())->getType() == "shared-flq");
2012 }
2013 }
2014
2015 return false;
2016}
2017
2018} // namespace isc::dhcp
2019} // namespace isc
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 a function is not implemented.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
Definition data.cc:299
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:354
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Multiple lease records found where one expected.
ExtendedInfoSanity
Values for extended info sanity checks done for leases.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition cfgmgr.cc:116
Holds DUID (DHCPv6 Unique Identifier)
Definition duid.h:142
std::string toText() const
Returns textual representation of the identifier (e.g.
Definition duid.h:88
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
Definition lease_mgr.cc:552
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets and pools.
Definition lease_mgr.cc:547
virtual Lease6Collection getLeases6() const =0
Returns all IPv6 leases.
void recountLeaseStats6()
Recalculates per-subnet and global stats for IPv6 leases.
Definition lease_mgr.cc:295
virtual data::ElementPtr getStatus() const
Return status information.
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
Definition lease_mgr.h:1045
virtual size_t byRelayId6size() const
Return the by-relay-id table size.
static bool upgradeLease6ExtendedInfo(const Lease6Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
Upgrade a V6 lease user context to the new extended info entry.
Definition lease_mgr.cc:803
static void updateStatsOnAdd(const Lease4Ptr &lease)
Update in-memory stats when adding a v4 lease.
virtual size_t byRemoteId6size() const
Return the by-remote-id table size.
virtual asiolink::IOAddress sflqPickFreeLease4(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V4 address within the given pool range.
static void updateStatsOnUpdate(const Lease4Ptr &existing, const Lease4Ptr &lease)
Update in-memory stats when updating a v4 lease.
static bool useSharedFlqStatement(Lease4Ptr lease)
Determine if SFLQ alternate SQL statements should be used for a given v4 lease.
virtual void addRelayId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &relay_id)=0
Add lease6 extended info into by-relay-id table.
static void bumpStatPrefix(const std::string &stat, SubnetID &subnet_id, PoolPtr pool, int value)
Helper function that adds a value to a prefix stat's global, subnet, and pool level values.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
Definition lease_mgr.cc:284
virtual std::string getName() const =0
Returns backend name.
void recountLeaseStats4()
Recalculates per-subnet and global stats for IPv4 leases.
Definition lease_mgr.cc:76
static std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
Definition lease_mgr.cc:563
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
Definition lease_mgr.cc:557
static void updateStatsOnDelete(const Lease4Ptr &lease)
Update in-memory stats when deleting a v4 lease.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
Definition lease_mgr.cc:279
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
virtual isc::data::ConstElementPtr lfcStartHandler()
Handler for kea-lfc-start command.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets.
Definition lease_mgr.cc:269
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
virtual bool sflqCreateFlqPool4(asiolink::IOAddress start_address, asiolink::IOAddress end_address, SubnetID subnet_id, bool recreate=false)
Creates a v4 SFLQ Pool.
static bool upgradeLease4ExtendedInfo(const Lease4Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
The following queries are used to fulfill Bulk Lease Query queries.
Definition lease_mgr.cc:582
virtual void addRemoteId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &remote_id)=0
Add lease6 extended info into by-remote-id table.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets and pools.
Definition lease_mgr.cc:274
static void bumpStat(const std::string &stat, SubnetID &subnet_id, PoolPtr pool, int value)
Helper function that adds a value to an address stat's global, subnet, and pool level values.
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
virtual asiolink::IOAddress sflqPickFreeLease6(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V6 address/prefix within the given pool range.
virtual bool sflqCreateFlqPool6(asiolink::IOAddress start_address, asiolink::IOAddress end_address, Lease::Type lease_type, uint8_t delegated_len, SubnetID subnet_id, bool recreate=false)
Calls stored procedure to create an SFLQ pool for v6.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets.
Definition lease_mgr.cc:542
const size_t page_size_
Holds page size.
Definition lease_mgr.h:56
LeasePageSize(const size_t page_size)
Constructor.
Definition lease_mgr.cc:45
LeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor to query statistics for all subnets.
Definition lease_mgr.cc:233
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
Definition lease_mgr.h:222
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
Definition lease_mgr.h:225
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row of data.
Definition lease_mgr.cc:290
SelectMode
Defines the types of selection criteria supported.
Definition lease_mgr.h:152
static const OptionDefinition & DHO_DHCP_AGENT_OPTIONS_DEF()
Get definition of DHO_DHCP_AGENT_OPTIONS option.
static size_t unpackOptions6(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, size_t *relay_msg_offset=0, size_t *relay_msg_len=0)
Parses provided buffer as DHCPv6 options and creates Option objects.
Definition libdhcp++.cc:317
Option with defined data fields represented as buffers that can be accessed using data field index.
Base class representing a DHCP option definition.
static bool inUse()
Returns the global in-use flag.
Statistics Manager class.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
This file contains several functions and constants that are used for handling commands and responses ...
@ D6O_REMOTE_ID
Definition dhcp6.h:57
@ D6O_RELAY_ID
Definition dhcp6.h:73
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
#define STATE_MASK(new_state, old_state)
Creates a mask out of two states: new state and old state.
An abstract API for lease database.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
Definition data.cc:1516
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Definition dhcpsrv_log.h:56
constexpr uint16_t DECLINED_RECLAIMED
constexpr uint16_t RECLAIMED_ASSIGNED
constexpr uint16_t REGISTERED_RELEASED
const isc::log::MessageID DHCPSRV_LEASE6_EXTENDED_INFO_UPGRADED
boost::shared_ptr< OptionCustom > OptionCustomPtr
A pointer to the OptionCustom object.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
Definition lease_mgr.h:233
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet6Collection
A collection of Subnet6 objects.
Definition subnet.h:937
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
constexpr uint16_t REGISTERED_ASSIGNED
constexpr uint16_t RELEASED_DECLINED
constexpr uint16_t ASSIGNED_ASSIGNED
Constant expression state masks for use in switch statements.
constexpr uint16_t ASSIGNED_DECLINED
constexpr uint16_t RECLAIMED_REGISTERED
constexpr uint16_t RELEASED_ASSIGNED
constexpr uint16_t RECLAIMED_DECLINED
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet4Collection
A collection of Subnet4 objects.
Definition subnet.h:866
constexpr uint16_t REGISTERED_REGISTERED
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
constexpr uint16_t DECLINED_ASSIGNED
constexpr uint16_t RELEASED_REGISTERED
constexpr uint16_t ASSIGNED_RECLAIMED
constexpr uint16_t DECLINED_REGISTERED
constexpr uint16_t DECLINED_RELEASED
constexpr uint16_t ASSIGNED_RELEASED
constexpr uint16_t DECLINED_DECLINED
@ RAI_OPTION_RELAY_ID
Definition dhcp4.h:276
@ RAI_OPTION_REMOTE_ID
Definition dhcp4.h:266
const isc::log::MessageID DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL
const isc::log::MessageID DHCPSRV_LEASE4_EXTENDED_INFO_UPGRADED
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Definition dhcpsrv_log.h:26
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
const isc::log::MessageID DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL
constexpr uint16_t REGISTERED_DECLINED
constexpr uint16_t ASSIGNED_REGISTERED
constexpr uint16_t REGISTERED_RECLAIMED
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
Definition encode.cc:367
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
Definition encode.cc:361
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Definition str.cc:212
Defines the logger used by the top-level component of kea-lfc.
#define DHCP6_OPTION_SPACE
Contains a single row of lease statistical data.
Definition lease_mgr.h:64
uint32_t pool_id_
The pool ID to which this data applies.
Definition lease_mgr.h:132
int64_t state_count_
state_count The count of leases in the lease state
Definition lease_mgr.h:141
uint32_t lease_state_
The lease_state to which the count applies.
Definition lease_mgr.h:138
SubnetID subnet_id_
The subnet ID to which this data applies.
Definition lease_mgr.h:129
Lease::Type lease_type_
The lease_type to which the count applies.
Definition lease_mgr.h:135
static constexpr uint32_t STATE_DEFAULT
A lease in the default state.
Definition lease.h:69
static constexpr uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition lease.h:75
static constexpr uint32_t STATE_DECLINED
Declined lease.
Definition lease.h:72
static constexpr uint32_t STATE_REGISTERED
Registered self-generated lease.
Definition lease.h:81
static constexpr uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
Definition lease.h:78
Type
Type of lease or pool.
Definition lease.h:46
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
@ TYPE_V4
IPv4 lease.
Definition lease.h:50
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47