Kea: lease_mgr.cc Source File

| Kea 3.2.0-git

lease_mgr.cc
Go to the documentation of this file.
1// Copyright (C) 2012-2026 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
9#include <cc/command_interpreter.h>
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>
15#include <dhcpsrv/sflq_allocator.h>
16#include <dhcpsrv/subnet_id.h>
17#include <exceptions/exceptions.h>
18#include <stats/stats_mgr.h>
19#include <util/encode/encode.h>
20#include <util/str.h>
21#include <util/boost_time_utils.h>
22
23#include <boost/algorithm/string.hpp>
24
25#include <algorithm>
26#include <iostream>
27#include <iterator>
28#include <limits>
29#include <map>
30#include <sstream>
31#include <string>
32
33#include <time.h>
34
35using namespace isc::asiolink;
36using namespace isc::config;
37using namespace isc::data;
38using namespace isc::db;
39using namespace isc::dhcp;
40using namespace isc::stats;
41using namespace isc::util;
42using namespace std;
43
44namespace isc {
45namespace dhcp {
46
47LeasePageSize::LeasePageSize(const size_t page_size)
48 : page_size_(page_size) {
49
50 if (page_size_ == 0) {
51 isc_throw(OutOfRange, "page size of retrieved leases must not be 0");
52 }
53
54 if (page_size_ > std::numeric_limits<uint32_t>::max()) {
55 isc_throw(OutOfRange, "page size of retrieved leases must not be greater than "
56 << std::numeric_limits<uint32_t>::max());
57 }
58}
59
60 Lease6Ptr
61 LeaseMgr::getLease6(Lease::Type type, const DUID& duid,
62 uint32_t iaid, SubnetID subnet_id) const {
63 Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);
64
65 if (col.size() > 1) {
66 isc_throw(MultipleRecords, "More than one lease found for type "
67 << static_cast<int>(type) << ", duid "
68 << duid.toText() << ", iaid " << iaid
69 << " and subnet-id " << subnet_id);
70 }
71 if (col.empty()) {
72 return (Lease6Ptr());
73 }
74 return (*col.begin());
75}
76
77void
78LeaseMgr::recountLeaseStats4() {
79 using namespace stats;
80
81 StatsMgr& stats_mgr = StatsMgr::instance();
82
83 LeaseStatsQueryPtr query = startLeaseStatsQuery4();
84 if (!query) {
86 return;
87 }
88
89 // Zero out the global stats.
90 // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases",
91 // "cumulative-assigned-addresses") never get zeroed.
92 int64_t zero = 0;
93
94 stats_mgr.setValue("assigned-addresses", zero);
95
96 stats_mgr.setValue("declined-addresses", zero);
97
98 // Create if it does not exit reclaimed declined leases global stats.
99 if (!stats_mgr.getObservation("reclaimed-declined-addresses")) {
100 stats_mgr.setValue("reclaimed-declined-addresses", zero);
101 }
102
103 // Create if it does not exit reclaimed leases global stats.
104 if (!stats_mgr.getObservation("reclaimed-leases")) {
105 stats_mgr.setValue("reclaimed-leases", zero);
106 }
107
108 // Create if it does not exit cumulative global stats.
109 if (!stats_mgr.getObservation("cumulative-assigned-addresses")) {
110 stats_mgr.setValue("cumulative-assigned-addresses", zero);
111 }
112
113 // Clear subnet level stats. This ensures we don't end up with corner
114 // cases that leave stale values in place.
115 const Subnet4Collection* subnets =
116 CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
117
118 for (auto const& subnet : *subnets) {
119 SubnetID subnet_id = subnet->getID();
120 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
121 "assigned-addresses"),
122 zero);
123
124 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
125 "declined-addresses"),
126 zero);
127
128 const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
129 "reclaimed-declined-addresses"));
130 if (!stats_mgr.getObservation(name_rec_dec)) {
131 stats_mgr.setValue(name_rec_dec, zero);
132 }
133
134 const std::string name_rec(StatsMgr::generateName("subnet", subnet_id,
135 "reclaimed-leases"));
136 if (!stats_mgr.getObservation(name_rec)) {
137 stats_mgr.setValue(name_rec, zero);
138 }
139
140 for (auto const& pool : subnet->getPools(Lease::TYPE_V4)) {
141 const std::string name_aa(StatsMgr::generateName("subnet", subnet_id,
142 StatsMgr::generateName("pool", pool->getID(),
143 "assigned-addresses")));
144 if (!stats_mgr.getObservation(name_aa)) {
145 stats_mgr.setValue(name_aa, zero);
146 }
147
148 const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
149 StatsMgr::generateName("pool", pool->getID(),
150 "declined-addresses")));
151 if (!stats_mgr.getObservation(name_da)) {
152 stats_mgr.setValue(name_da, zero);
153 }
154
155 const std::string& pname_rec_dec(StatsMgr::generateName("subnet", subnet_id,
156 StatsMgr::generateName("pool", pool->getID(),
157 "reclaimed-declined-addresses")));
158 if (!stats_mgr.getObservation(pname_rec_dec)) {
159 stats_mgr.setValue(pname_rec_dec, zero);
160 }
161
162 const std::string& pname_rec(StatsMgr::generateName("subnet", subnet_id,
163 StatsMgr::generateName("pool", pool->getID(),
164 "reclaimed-leases")));
165 if (!stats_mgr.getObservation(pname_rec)) {
166 stats_mgr.setValue(pname_rec, zero);
167 }
168 }
169 }
170
171 // Get counts per state per subnet. Iterate over the result set
172 // updating the subnet and global values.
173 LeaseStatsRow row;
174 while (query->getNextRow(row)) {
175 if (row.lease_state_ == Lease::STATE_DEFAULT) {
176 // Add to the global value.
177 stats_mgr.addValue("assigned-addresses", row.state_count_);
178
179 // Add to subnet level value.
180 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
181 "assigned-addresses"),
182 row.state_count_);
183 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
184 // Set subnet level value.
185 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
186 "declined-addresses"),
187 row.state_count_);
188
189 // Add to the global value.
190 stats_mgr.addValue("assigned-addresses", row.state_count_);
191
192 // Add to the global value.
193 stats_mgr.addValue("declined-addresses", row.state_count_);
194
195 // Add to subnet level value.
196 // Declined leases also count as assigned.
197 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
198 "assigned-addresses"),
199 row.state_count_);
200 }
201 }
202
203 query = startPoolLeaseStatsQuery4();
204 if (!query) {
206 return;
207 }
208
209 // Get counts per state per subnet and pool. Iterate over the result set
210 // updating the subnet and pool and global values.
211 while (query->getNextRow(row)) {
212 if (row.lease_state_ == Lease::STATE_DEFAULT) {
213 // Add to subnet and pool level value.
214 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
215 StatsMgr::generateName("pool", row.pool_id_,
216 "assigned-addresses")),
217 row.state_count_);
218 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
219 // Set subnet and pool level value.
220 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
221 StatsMgr::generateName("pool", row.pool_id_,
222 "declined-addresses")),
223 row.state_count_);
224
225 // Add to subnet and pool level value.
226 // Declined leases also count as assigned.
227 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
228 StatsMgr::generateName("pool", row.pool_id_,
229 "assigned-addresses")),
230 row.state_count_);
231 }
232 }
233}
234
235LeaseStatsQuery::LeaseStatsQuery(const SelectMode& select_mode)
236 : first_subnet_id_(0), last_subnet_id_(0), select_mode_(select_mode) {
237 if (select_mode != ALL_SUBNETS && select_mode != ALL_SUBNET_POOLS) {
238 isc_throw(BadValue, "LeaseStatsQuery: mode must be either ALL_SUBNETS or ALL_SUBNET_POOLS");
239 }
240}
241
242 LeaseStatsQuery::LeaseStatsQuery(const SubnetID& subnet_id)
243 : first_subnet_id_(subnet_id), last_subnet_id_(0),
244 select_mode_(SINGLE_SUBNET) {
245
246 if (first_subnet_id_ == 0) {
247 isc_throw(BadValue, "LeaseStatsQuery: subnet_id_ must be > 0");
248 }
249}
250
251 LeaseStatsQuery::LeaseStatsQuery(const SubnetID& first_subnet_id,
252 const SubnetID& last_subnet_id)
253 : first_subnet_id_(first_subnet_id), last_subnet_id_(last_subnet_id),
254 select_mode_(SUBNET_RANGE) {
255
256 if (first_subnet_id_ == 0) {
257 isc_throw(BadValue, "LeaseStatsQuery: first_subnet_id_ must be > 0");
258 }
259
260 if (last_subnet_id_ == 0) {
261 isc_throw(BadValue, "LeaseStatsQuery: last_subnet_id_ must be > 0");
262 }
263
264 if (last_subnet_id_ <= first_subnet_id_) {
265 isc_throw(BadValue,
266 "LeaseStatsQuery: last_subnet_id_must be > first_subnet_id_");
267 }
268}
269
270 LeaseStatsQueryPtr
271LeaseMgr::startLeaseStatsQuery4() {
272 return(LeaseStatsQueryPtr());
273}
274
275 LeaseStatsQueryPtr
276LeaseMgr::startPoolLeaseStatsQuery4() {
277 return(LeaseStatsQueryPtr());
278}
279
280 LeaseStatsQueryPtr
281LeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& /* subnet_id */) {
282 return(LeaseStatsQueryPtr());
283}
284
285 LeaseStatsQueryPtr
286LeaseMgr::startSubnetRangeLeaseStatsQuery4(const SubnetID& /* first_subnet_id */,
287 const SubnetID& /* last_subnet_id */) {
288 return(LeaseStatsQueryPtr());
289}
290
291bool
292LeaseStatsQuery::getNextRow(LeaseStatsRow& /*row*/) {
293 return (false);
294}
295
296void
297LeaseMgr::recountLeaseStats6() {
298 using namespace stats;
299
300 StatsMgr& stats_mgr = StatsMgr::instance();
301
302 LeaseStatsQueryPtr query = startLeaseStatsQuery6();
303 if (!query) {
305 return;
306 }
307
308 // Zero out the global stats.
309 // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases",
310 // "cumulative-assigned-nas", "cumulative-assigned-pds",
311 // "cumulative-registered-nas")) never get zeroed.
312 int64_t zero = 0;
313
314 stats_mgr.setValue("assigned-nas", zero);
315
316 stats_mgr.setValue("assigned-pds", zero);
317
318 stats_mgr.setValue("declined-addresses", zero);
319
320 if (!stats_mgr.getObservation("reclaimed-declined-addresses")) {
321 stats_mgr.setValue("reclaimed-declined-addresses", zero);
322 }
323
324 if (!stats_mgr.getObservation("reclaimed-leases")) {
325 stats_mgr.setValue("reclaimed-leases", zero);
326 }
327
328 // Create if it does not exit cumulative nas global stats.
329 if (!stats_mgr.getObservation("cumulative-assigned-nas")) {
330 stats_mgr.setValue("cumulative-assigned-nas", zero);
331 }
332
333 // Create if it does not exit cumulative pds global stats.
334 if (!stats_mgr.getObservation("cumulative-assigned-pds")) {
335 stats_mgr.setValue("cumulative-assigned-pds", zero);
336 }
337
338 // Create if it does not exit cumulative registered nas global stats.
339 if (!stats_mgr.getObservation("cumulative-registered-nas")) {
340 stats_mgr.setValue("cumulative-registered-nas", zero);
341 }
342
343 // Clear subnet level stats. This ensures we don't end up with corner
344 // cases that leave stale values in place.
345 const Subnet6Collection* subnets =
346 CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
347
348 for (auto const& subnet : *subnets) {
349 SubnetID subnet_id = subnet->getID();
350 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
351 "assigned-nas"),
352 zero);
353
354 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
355 "assigned-pds"),
356 zero);
357
358 stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
359 "declined-addresses"),
360 zero);
361
362 if (!stats_mgr.getObservation(
363 StatsMgr::generateName("subnet", subnet_id,
364 "reclaimed-declined-addresses"))) {
365 stats_mgr.setValue(
366 StatsMgr::generateName("subnet", subnet_id,
367 "reclaimed-declined-addresses"),
368 zero);
369 }
370
371 if (!stats_mgr.getObservation(
372 StatsMgr::generateName("subnet", subnet_id,
373 "reclaimed-leases"))) {
374 stats_mgr.setValue(
375 StatsMgr::generateName("subnet", subnet_id,
376 "reclaimed-leases"),
377 zero);
378 }
379
380 if (!stats_mgr.getObservation(
381 StatsMgr::generateName("subnet", subnet_id,
382 "registered-nas"))) {
383 stats_mgr.setValue(
384 StatsMgr::generateName("subnet", subnet_id,
385 "registered-nas"),
386 zero);
387 }
388
389 for (auto const& pool : subnet->getPools(Lease::TYPE_NA)) {
390 const std::string& name_anas(StatsMgr::generateName("subnet", subnet_id,
391 StatsMgr::generateName("pool", pool->getID(),
392 "assigned-nas")));
393 if (!stats_mgr.getObservation(name_anas)) {
394 stats_mgr.setValue(name_anas, zero);
395 }
396
397 const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
398 StatsMgr::generateName("pool", pool->getID(),
399 "declined-addresses")));
400 if (!stats_mgr.getObservation(name_da)) {
401 stats_mgr.setValue(name_da, zero);
402 }
403
404 const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
405 StatsMgr::generateName("pool", pool->getID(),
406 "reclaimed-declined-addresses")));
407 if (!stats_mgr.getObservation(name_rec_dec)) {
408 stats_mgr.setValue(name_rec_dec, zero);
409 }
410
411 const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
412 StatsMgr::generateName("pool", pool->getID(),
413 "reclaimed-leases")));
414 if (!stats_mgr.getObservation(name_rec)) {
415 stats_mgr.setValue(name_rec, zero);
416 }
417 }
418
419 for (auto const& pool : subnet->getPools(Lease::TYPE_PD)) {
420 const std::string& name_apds(StatsMgr::generateName("subnet", subnet_id,
421 StatsMgr::generateName("pd-pool", pool->getID(),
422 "assigned-pds")));
423 if (!stats_mgr.getObservation(name_apds)) {
424 stats_mgr.setValue(name_apds, zero);
425 }
426
427 const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
428 StatsMgr::generateName("pd-pool", pool->getID(),
429 "reclaimed-leases")));
430 if (!stats_mgr.getObservation(name_rec)) {
431 stats_mgr.setValue(name_rec, zero);
432 }
433 }
434 }
435
436 // Get counts per state per subnet. Iterate over the result set
437 // updating the subnet and global values.
438 LeaseStatsRow row;
439 while (query->getNextRow(row)) {
440 switch(row.lease_type_) {
441 case Lease::TYPE_NA:
442 if (row.lease_state_ == Lease::STATE_DEFAULT) {
443 // Add to the global value.
444 stats_mgr.addValue("assigned-nas", row.state_count_);
445
446 // Add to subnet level value.
447 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
448 "assigned-nas"),
449 row.state_count_);
450 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
451 // Set subnet level value.
452 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
453 "declined-addresses"),
454 row.state_count_);
455
456 // Add to the global value.
457 stats_mgr.addValue("assigned-nas", row.state_count_);
458
459 // Add to the global value.
460 stats_mgr.addValue("declined-addresses", row.state_count_);
461
462 // Add to subnet level value.
463 // Declined leases also count as assigned.
464 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
465 "assigned-nas"),
466 row.state_count_);
467 } else if (row.lease_state_ == Lease::STATE_REGISTERED) {
468 // Add to subnet level value
469 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
470 "registered-nas"),
471 row.state_count_);
472 }
473 break;
474
475 case Lease::TYPE_PD:
476 if (row.lease_state_ == Lease::STATE_DEFAULT) {
477 // Add to the global value.
478 stats_mgr.addValue("assigned-pds", row.state_count_);
479
480 // Set subnet level value.
481 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
482 "assigned-pds"),
483 row.state_count_);
484 }
485 break;
486
487 default:
488 break;
489 }
490 }
491
492 query = startPoolLeaseStatsQuery6();
493 if (!query) {
495 return;
496 }
497
498 // Get counts per state per subnet and pool. Iterate over the result set
499 // updating the subnet and pool and global values.
500 while (query->getNextRow(row)) {
501 switch(row.lease_type_) {
502 case Lease::TYPE_NA:
503 if (row.lease_state_ == Lease::STATE_DEFAULT) {
504 // Add to subnet and pool level value.
505 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
506 StatsMgr::generateName("pool", row.pool_id_,
507 "assigned-nas")),
508 row.state_count_);
509 } else if (row.lease_state_ == Lease::STATE_DECLINED) {
510 // Set subnet and pool level value.
511 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
512 StatsMgr::generateName("pool", row.pool_id_,
513 "declined-addresses")),
514 row.state_count_);
515
516 // Add to subnet and pool level value.
517 // Declined leases also count as assigned.
518 stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
519 StatsMgr::generateName("pool", row.pool_id_,
520 "assigned-nas")),
521 row.state_count_);
522 }
523 break;
524
525 case Lease::TYPE_PD:
526 if (row.lease_state_ == Lease::STATE_DEFAULT) {
527 // Set subnet and pool level value.
528 stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
529 StatsMgr::generateName("pd-pool", row.pool_id_,
530 "assigned-pds")),
531 row.state_count_);
532 }
533 break;
534
535 default:
536 break;
537 }
538 }
539}
540
541 LeaseStatsQueryPtr
542LeaseMgr::startLeaseStatsQuery6() {
543 return(LeaseStatsQueryPtr());
544}
545
546 LeaseStatsQueryPtr
547LeaseMgr::startPoolLeaseStatsQuery6() {
548 return(LeaseStatsQueryPtr());
549}
550
551 LeaseStatsQueryPtr
552LeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& /* subnet_id */) {
553 return(LeaseStatsQueryPtr());
554}
555
556 LeaseStatsQueryPtr
557LeaseMgr::startSubnetRangeLeaseStatsQuery6(const SubnetID& /* first_subnet_id */,
558 const SubnetID& /* last_subnet_id */) {
559 return(LeaseStatsQueryPtr());
560}
561
562std::string
563LeaseMgr::getDBVersion() {
564 isc_throw(NotImplemented, "LeaseMgr::getDBVersion() called");
565}
566
567void
568 LeaseMgr::setExtendedInfoTablesEnabled(const DatabaseConnection::ParameterMap& parameters) {
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") {
577 setExtendedInfoTablesEnabled(true);
578 }
579}
580
581bool
582LeaseMgr::upgradeLease4ExtendedInfo(const Lease4Ptr& lease,
583 CfgConsistency::ExtendedInfoSanity check) {
584 const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF();
585
586 bool changed = false;
587 if (!lease) {
588 return (changed);
589 }
590
591 if (check == CfgConsistency::EXTENDED_INFO_CHECK_NONE) {
592 return (changed);
593 }
594
595 ConstElementPtr user_context = lease->getContext();
596 if (!user_context) {
597 return (changed);
598 }
599
600 ConstElementPtr isc;
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",
677 Element::create(encode::encodeHex(bytes)));
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",
686 Element::create(encode::encodeHex(bytes)));
687 }
688 }
689
690 LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
691 DHCPSRV_LEASE4_EXTENDED_INFO_UPGRADED)
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
700 if (check == CfgConsistency::EXTENDED_INFO_CHECK_FIX) {
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
754 if (check != CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC) {
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();
775 LOG_ERROR(dhcpsrv_logger, DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL)
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
803LeaseMgr::upgradeLease6ExtendedInfo(const Lease6Ptr& lease,
804 CfgConsistency::ExtendedInfoSanity check) {
805 bool changed = false;
806 if (!lease) {
807 return (changed);
808 }
809
810 if (check == CfgConsistency::EXTENDED_INFO_CHECK_NONE) {
811 return (changed);
812 }
813
814 ConstElementPtr user_context = lease->getContext();
815 if (!user_context) {
816 return (changed);
817 }
818
819 ConstElementPtr isc;
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",
936 Element::create(encode::encodeHex(bytes)));
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",
948 Element::create(encode::encodeHex(bytes)));
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 }
1001 if (check == CfgConsistency::EXTENDED_INFO_CHECK_FIX) {
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
1060 if (check != CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC) {
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) {
1113 LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
1114 DHCPSRV_LEASE6_EXTENDED_INFO_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();
1126 LOG_ERROR(dhcpsrv_logger, DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL)
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
1155LeaseMgr::extractLease4ExtendedInfo(const Lease4Ptr& lease,
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
1241LeaseMgr::addExtendedInfo6(const Lease6Ptr& lease) {
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
1302LeaseMgr::byRelayId6size() const {
1303 return (0);
1304}
1305
1306size_t
1307LeaseMgr::byRemoteId6size() const {
1308 return (0);
1309}
1310
1311 ElementPtr
1312LeaseMgr::getStatus() const {
1313 return (ElementPtr());
1314}
1315
1316 ConstElementPtr
1317LeaseMgr::lfcStartHandler() {
1318 ostringstream msg;
1319 msg << "lease backend '" << getName() << "' is not 'memfile'";
1320 return (createAnswer(CONTROL_RESULT_COMMAND_UNSUPPORTED, msg.str()));
1321}
1322
1323void
1324LeaseMgr::updateStatsOnAdd(const Lease4Ptr& lease) {
1325 if (!lease->stateExpiredReclaimed()) {
1326 StatsMgr::instance().addValue("assigned-addresses", static_cast<int64_t>(1));
1327
1328 StatsMgr::instance().addValue(
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) {
1338 StatsMgr::instance().addValue(
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
1349 StatsMgr::instance().addValue(
1350 StatsMgr::generateName("subnet", lease->subnet_id_,
1351 "declined-addresses"),
1352 static_cast<int64_t>(1));
1353
1354 if (pool) {
1355 StatsMgr::instance().addValue(
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
1366 LeaseMgr::updateStatsOnAdd(const Lease6Ptr& lease) {
1367 if (lease->stateRegistered()) {
1368 StatsMgr::instance().addValue(
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
1376 StatsMgr::instance().addValue(
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) {
1387 StatsMgr::instance().addValue(
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
1400 StatsMgr::instance().addValue(
1401 StatsMgr::generateName("subnet", lease->subnet_id_,
1402 "declined-addresses"),
1403 static_cast<int64_t>(1));
1404
1405 if (pool) {
1406 StatsMgr::instance().addValue(
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) {
1422 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id,
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) {
1434 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", subnet_id,
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
1445 constexpr uint16_t ASSIGNED_ASSIGNED = STATE_MASK(Lease::STATE_DEFAULT,
1446 Lease::STATE_DEFAULT);
1447 constexpr uint16_t ASSIGNED_DECLINED = STATE_MASK(Lease::STATE_DEFAULT,
1448 Lease::STATE_DECLINED);
1449 constexpr uint16_t ASSIGNED_RECLAIMED = STATE_MASK(Lease::STATE_DEFAULT,
1450 Lease::STATE_EXPIRED_RECLAIMED);
1451 constexpr uint16_t ASSIGNED_RELEASED = STATE_MASK(Lease::STATE_DEFAULT,
1452 Lease::STATE_RELEASED);
1453 constexpr uint16_t ASSIGNED_REGISTERED = STATE_MASK(Lease::STATE_DEFAULT,
1454 Lease::STATE_REGISTERED);
1455// New state DECLINED
1456 constexpr uint16_t DECLINED_ASSIGNED = STATE_MASK(Lease::STATE_DECLINED,
1457 Lease::STATE_DEFAULT);
1458 constexpr uint16_t DECLINED_DECLINED = STATE_MASK(Lease::STATE_DECLINED,
1459 Lease::STATE_DECLINED);
1460 constexpr uint16_t DECLINED_RECLAIMED = STATE_MASK(Lease::STATE_DECLINED,
1461 Lease::STATE_EXPIRED_RECLAIMED);
1462 constexpr uint16_t DECLINED_RELEASED = STATE_MASK(Lease::STATE_DECLINED,
1463 Lease::STATE_RELEASED);
1464 constexpr uint16_t DECLINED_REGISTERED = STATE_MASK(Lease::STATE_DECLINED,
1465 Lease::STATE_REGISTERED);
1466// New state EXPIRED_RECLAIMED
1467 constexpr uint16_t RECLAIMED_ASSIGNED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1468 Lease::STATE_DEFAULT);
1469 constexpr uint16_t RECLAIMED_DECLINED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1470 Lease::STATE_DECLINED);
1471#if 0 // Currently unused.
1472constexpr uint16_t RECLAIMED_RECLAIMED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1473 Lease::STATE_EXPIRED_RECLAIMED);
1474constexpr uint16_t RECLAIMED_RELEASED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1475 Lease::STATE_RELEASED);
1476#endif
1477 constexpr uint16_t RECLAIMED_REGISTERED = STATE_MASK(Lease::STATE_EXPIRED_RECLAIMED,
1478 Lease::STATE_REGISTERED);
1479// New state RELEASED
1480 constexpr uint16_t RELEASED_ASSIGNED = STATE_MASK(Lease::STATE_RELEASED,
1481 Lease::STATE_DEFAULT);
1482 constexpr uint16_t RELEASED_DECLINED = STATE_MASK(Lease::STATE_RELEASED,
1483 Lease::STATE_DECLINED);
1484#if 0 // Currently unused.
1485constexpr uint16_t RELEASED_RECLAIMED = STATE_MASK(Lease::STATE_RELEASED,
1486 Lease::STATE_EXPIRED_RECLAIMED);
1487constexpr uint16_t RELEASED_RELEASED = STATE_MASK(Lease::STATE_RELEASED,
1488 Lease::STATE_RELEASED);
1489#endif
1490 constexpr uint16_t RELEASED_REGISTERED = STATE_MASK(Lease::STATE_RELEASED,
1491 Lease::STATE_REGISTERED);
1492// New state REGISTERED
1493 constexpr uint16_t REGISTERED_ASSIGNED = STATE_MASK(Lease::STATE_REGISTERED, Lease::STATE_DEFAULT);
1494 constexpr uint16_t REGISTERED_DECLINED = STATE_MASK(Lease::STATE_REGISTERED,
1495 Lease::STATE_DECLINED);
1496 constexpr uint16_t REGISTERED_RECLAIMED = STATE_MASK(Lease::STATE_REGISTERED,
1497 Lease::STATE_EXPIRED_RECLAIMED);
1498 constexpr uint16_t REGISTERED_RELEASED = STATE_MASK(Lease::STATE_REGISTERED,
1499 Lease::STATE_RELEASED);
1500 constexpr uint16_t REGISTERED_REGISTERED = STATE_MASK(Lease::STATE_REGISTERED,
1501 Lease::STATE_REGISTERED);
1502
1503void
1504LeaseMgr::updateStatsOnUpdate(const Lease4Ptr& existing,
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
1639 LeaseMgr::updateStatsOnUpdate(const Lease6Ptr& existing,
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
1684 case ASSIGNED_REGISTERED:
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
1699 case DECLINED_REGISTERED:
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
1713 case RECLAIMED_REGISTERED:
1714 case RELEASED_REGISTERED:
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
1724 case REGISTERED_ASSIGNED:
1725 bumpStat("assigned-nas", existing->subnet_id_, pool, -1);
1726 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), 1);
1727 break;
1728
1729 case REGISTERED_DECLINED:
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
1735 case REGISTERED_RECLAIMED:
1736 case REGISTERED_RELEASED:
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
1792 case ASSIGNED_REGISTERED:
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
1816 case DECLINED_REGISTERED:
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
1837 case RECLAIMED_REGISTERED:
1838 case RELEASED_REGISTERED:
1839 bumpStat("registered-nas", existing->subnet_id_, PoolPtr(), -1);
1840 break;
1841
1842 case REGISTERED_ASSIGNED:
1843 bumpStat("assigned-nas", existing->subnet_id_, existing_pool, -1);
1844 bumpStat("registered-nas", lease->subnet_id_, PoolPtr(), 1);
1845 break;
1846
1847 case REGISTERED_DECLINED:
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
1853 case REGISTERED_RECLAIMED:
1854 case REGISTERED_RELEASED:
1855 bumpStat("registered-nas", lease->subnet_id_, PoolPtr(), 1);
1856 break;
1857
1858 case REGISTERED_REGISTERED:
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
1872LeaseMgr::updateStatsOnDelete(const Lease4Ptr& lease) {
1873 if (!lease->stateExpiredReclaimed()) {
1874 StatsMgr::instance().addValue("assigned-addresses", static_cast<int64_t>(-1));
1875
1876 StatsMgr::instance().addValue(
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) {
1886 StatsMgr::instance().addValue(
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
1897 StatsMgr::instance().addValue(
1898 StatsMgr::generateName("subnet", lease->subnet_id_,
1899 "declined-addresses"),
1900 static_cast<int64_t>(-1));
1901
1902 if (pool) {
1903 StatsMgr::instance().addValue(
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
1914 LeaseMgr::updateStatsOnDelete(const Lease6Ptr& lease) {
1915 if (lease->stateRegistered()) {
1916 StatsMgr::instance().addValue(
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
1925 StatsMgr::instance().addValue(
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) {
1936 StatsMgr::instance().addValue(
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
1949 StatsMgr::instance().addValue(
1950 StatsMgr::generateName("subnet", lease->subnet_id_,
1951 "declined-addresses"),
1952 static_cast<int64_t>(-1));
1953
1954 if (pool) {
1955 StatsMgr::instance().addValue(
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
1965SflqPoolInfo::SflqPoolInfo():
1966 lease_type_(Lease::TYPE_V4),
1967 start_address_(IOAddress::IPV4_ZERO_ADDRESS()),
1968 end_address_(IOAddress::IPV4_ZERO_ADDRESS()),
1969 delegated_len_(128),
1970 subnet_id_(SUBNET_ID_UNUSED),
1971 free_leases_(0),
1972 created_ts_(),
1973 modified_ts_() {
1974}
1975
1976 data::ElementPtr
1977SflqPoolInfo::toElement() const {
1978 ElementPtr info = Element::createMap();
1979 info->set("lease-type", Element::create(Lease::typeToText(lease_type_)));
1980 info->set("start-address", Element::create(start_address_.toText()));
1981 info->set("end-address", Element::create(end_address_.toText()));
1982 info->set("delegated-len", Element::create(delegated_len_));
1983 info->set("subnet-id", Element::create(subnet_id_));
1984 info->set("free-leases", ElementPtr(new IntElement(free_leases_)));
1985 info->set("created-ts", Element::create(isc::util::ptimeToText(created_ts_)));
1986 info->set("modified-ts", Element::create(isc::util::ptimeToText(modified_ts_)));
1987 return(info);
1988}
1989
1990bool
1991LeaseMgr::sflqCreateFlqPool4(IOAddress, IOAddress, SubnetID, bool) {
1992 isc_throw(NotImplemented, "LeaseMgr::sflqCreateFlqPool4() called");
1993}
1994
1995 IOAddress
1996LeaseMgr::sflqPickFreeLease4(IOAddress, IOAddress) {
1997 isc_throw(NotImplemented, "LeaseMgr::sflqPickFreeLease4() called");
1998}
1999
2000bool
2001LeaseMgr::sflqCreateFlqPool6(IOAddress, IOAddress, Lease::Type, uint8_t, SubnetID, bool) {
2002 isc_throw(NotImplemented, "LeaseMgr::sflqCreateFlqPool6() called");
2003}
2004
2005 IOAddress
2006LeaseMgr::sflqPickFreeLease6(IOAddress, IOAddress) {
2007 isc_throw(NotImplemented, "LeaseMgr::sflqPickFreeLease6() called");
2008}
2009
2010 SflqPoolInfoCollectionPtr
2011LeaseMgr::sflqPool4GetAll() {
2012 isc_throw(NotImplemented, "LeaseMgr::sflqPool4GetAll() called");
2013}
2014
2015 SflqPoolInfoCollectionPtr
2016LeaseMgr::sflqPool4Get(SubnetID /* subnet_id */) {
2017 isc_throw(NotImplemented, "LeaseMgr::sflqPool4Get(SubnetID) called");
2018}
2019
2020 SflqPoolInfoCollectionPtr
2021 LeaseMgr::sflqPool4Get(asiolink::IOAddress, asiolink::IOAddress) {
2022 isc_throw(NotImplemented, "LeaseMgr::sflqPool4Get(IOAddress,IOAddress) called");
2023}
2024
2025bool
2026LeaseMgr::sflqPool4Del(asiolink::IOAddress, asiolink::IOAddress, bool) {
2027 isc_throw(NotImplemented, "LeaseMgr::sflqPool4Del() called");
2028}
2029
2030 SflqPoolInfoCollectionPtr
2031LeaseMgr::sflqPool6GetAll() {
2032 isc_throw(NotImplemented, "LeaseMgr::sflqPool6GetAll() called");
2033}
2034
2035 SflqPoolInfoCollectionPtr
2036LeaseMgr::sflqPool6Get(SubnetID) {
2037 isc_throw(NotImplemented, "LeaseMgr::sflqPool6Get(SubnetID) called");
2038}
2039
2040 SflqPoolInfoCollectionPtr
2041 LeaseMgr::sflqPool6Get(asiolink::IOAddress, asiolink::IOAddress) {
2042 isc_throw(NotImplemented, "LeaseMgr::sflqPool6Get(IOAddress,IOAddress) called");
2043}
2044
2045bool
2046LeaseMgr::sflqPool6Del(asiolink::IOAddress, asiolink::IOAddress, bool) {
2047 isc_throw(NotImplemented, "LeaseMgr::sflqPool6Del() called");
2048}
2049
2050bool
2051LeaseMgr::useSharedFlqStatement(Lease4Ptr lease) {
2052 // Only check the subnet if SFLQ is in-use in this config.
2053 if (SharedFlqAllocator::inUse()) {
2054 auto const& subnet = CfgMgr::instance().getCurrentCfg()->
2055 getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
2056
2057 // We should? always have a subnet.
2058 if (subnet) {
2059 return (subnet->getAllocator(Lease::TYPE_V4)->getType() == "shared-flq");
2060 }
2061 }
2062
2063 return false;
2064}
2065
2066bool
2067 LeaseMgr::useSharedFlqStatement(Lease6Ptr lease) {
2068 // Only check the subnet if SFLQ is in-use in this config.
2069 if (SharedFlqAllocator::inUse()) {
2070 auto const& subnet = CfgMgr::instance().getCurrentCfg()->
2071 getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
2072
2073 // We should? always have a subnet.
2074 if (subnet) {
2075 return (subnet->getAllocator(lease->getType())->getType() == "shared-flq");
2076 }
2077 }
2078
2079 return false;
2080}
2081
2082} // namespace isc::dhcp
2083} // namespace isc
boost_time_utils.h
cfgmgr.h
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::NotImplemented
A generic exception that is thrown when a function is not implemented.
Definition exceptions/exceptions.h:166
isc::OutOfRange
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Definition exceptions/exceptions.h:115
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::asiolink::IOAddress::isV6
bool isV6() const
Convenience function to check for an IPv6 address.
Definition io_address.h:144
isc::data::Element::create
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
Definition data.cc:299
isc::data::Element::map
@ map
Definition data.h:160
isc::data::Element::integer
@ integer
Definition data.h:153
isc::data::Element::list
@ list
Definition data.h:159
isc::data::Element::string
@ string
Definition data.h:157
isc::data::Element::createMap
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:354
isc::data::IntElement
Notes: IntElement type is changed to int64_t.
Definition data.h:776
isc::db::DatabaseConnection::ParameterMap
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Definition database_connection.h:137
isc::db::MultipleRecords
Multiple lease records found where one expected.
Definition db_exceptions.h:16
isc::dhcp::CfgConsistency::ExtendedInfoSanity
ExtendedInfoSanity
Values for extended info sanity checks done for leases.
Definition cfg_consistency.h:36
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC
@ EXTENDED_INFO_CHECK_PEDANTIC
Definition cfg_consistency.h:41
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_FIX
@ EXTENDED_INFO_CHECK_FIX
Definition cfg_consistency.h:38
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_NONE
@ EXTENDED_INFO_CHECK_NONE
Definition cfg_consistency.h:37
isc::dhcp::CfgMgr::instance
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
isc::dhcp::CfgMgr::getCurrentCfg
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition cfgmgr.cc:116
isc::dhcp::DUID
Holds DUID (DHCPv6 Unique Identifier).
Definition duid.h:142
isc::dhcp::IdentifierType::toText
std::string toText() const
Returns textual representation of the identifier (e.g.
Definition duid.h:88
isc::dhcp::LeaseMgr::sflqPool4Del
virtual bool sflqPool4Del(asiolink::IOAddress start_address, asiolink::IOAddress end_address, bool force=false)
Delete the SFLQ V4 pool that matches a start and end address.
Definition lease_mgr.cc:2026
isc::dhcp::LeaseMgr::startSubnetLeaseStatsQuery6
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
Definition lease_mgr.cc:552
isc::dhcp::LeaseMgr::startPoolLeaseStatsQuery6
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets and pools.
Definition lease_mgr.cc:547
isc::dhcp::LeaseMgr::getLeases6
virtual Lease6Collection getLeases6() const =0
Returns all IPv6 leases.
isc::dhcp::LeaseMgr::recountLeaseStats6
void recountLeaseStats6()
Recalculates per-subnet and global stats for IPv6 leases.
Definition lease_mgr.cc:297
isc::dhcp::LeaseMgr::getStatus
virtual data::ElementPtr getStatus() const
Return status information.
Definition lease_mgr.cc:1312
isc::dhcp::LeaseMgr::setExtendedInfoTablesEnabled
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
Definition lease_mgr.h:1072
isc::dhcp::LeaseMgr::sflqPool6Del
virtual bool sflqPool6Del(asiolink::IOAddress start_address, asiolink::IOAddress end_address, bool force=false)
Delete the SFLQ V6 pool that matches a start and end address.
Definition lease_mgr.cc:2046
isc::dhcp::LeaseMgr::byRelayId6size
virtual size_t byRelayId6size() const
Return the by-relay-id table size.
Definition lease_mgr.cc:1302
isc::dhcp::LeaseMgr::upgradeLease6ExtendedInfo
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
isc::dhcp::LeaseMgr::sflqPool4Get
virtual SflqPoolInfoCollectionPtr sflqPool4Get(SubnetID subnet_id)
Fetch all SFLQ V4 pools belonging to a subnet.
Definition lease_mgr.cc:2016
isc::dhcp::LeaseMgr::sflqPool4GetAll
virtual SflqPoolInfoCollectionPtr sflqPool4GetAll()
Fetch all SFLQ V4 pools.
Definition lease_mgr.cc:2011
isc::dhcp::LeaseMgr::updateStatsOnAdd
static void updateStatsOnAdd(const Lease4Ptr &lease)
Update in-memory stats when adding a v4 lease.
Definition lease_mgr.cc:1324
isc::dhcp::LeaseMgr::byRemoteId6size
virtual size_t byRemoteId6size() const
Return the by-remote-id table size.
Definition lease_mgr.cc:1307
isc::dhcp::LeaseMgr::sflqPickFreeLease4
virtual asiolink::IOAddress sflqPickFreeLease4(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V4 address within the given pool range.
Definition lease_mgr.cc:1996
isc::dhcp::LeaseMgr::updateStatsOnUpdate
static void updateStatsOnUpdate(const Lease4Ptr &existing, const Lease4Ptr &lease)
Update in-memory stats when updating a v4 lease.
Definition lease_mgr.cc:1504
isc::dhcp::LeaseMgr::useSharedFlqStatement
static bool useSharedFlqStatement(Lease4Ptr lease)
Determine if SFLQ alternate SQL statements should be used for a given v4 lease.
Definition lease_mgr.cc:2051
isc::dhcp::LeaseMgr::addRelayId6
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.
isc::dhcp::LeaseMgr::bumpStatPrefix
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.
Definition lease_mgr.cc:1429
isc::dhcp::LeaseMgr::startSubnetRangeLeaseStatsQuery4
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:286
isc::dhcp::LeaseMgr::getName
virtual std::string getName() const =0
Returns backend name.
isc::dhcp::LeaseMgr::recountLeaseStats4
void recountLeaseStats4()
Recalculates per-subnet and global stats for IPv4 leases.
Definition lease_mgr.cc:78
isc::dhcp::LeaseMgr::getDBVersion
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
isc::dhcp::LeaseMgr::startSubnetRangeLeaseStatsQuery6
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
isc::dhcp::LeaseMgr::updateStatsOnDelete
static void updateStatsOnDelete(const Lease4Ptr &lease)
Update in-memory stats when deleting a v4 lease.
Definition lease_mgr.cc:1872
isc::dhcp::LeaseMgr::startSubnetLeaseStatsQuery4
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
Definition lease_mgr.cc:281
isc::dhcp::LeaseMgr::getLease6
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
isc::dhcp::LeaseMgr::lfcStartHandler
virtual isc::data::ConstElementPtr lfcStartHandler()
Handler for kea-lfc-start command.
Definition lease_mgr.cc:1317
isc::dhcp::LeaseMgr::startLeaseStatsQuery4
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets.
Definition lease_mgr.cc:271
isc::dhcp::LeaseMgr::extractLease4ExtendedInfo
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
Definition lease_mgr.cc:1155
isc::dhcp::LeaseMgr::sflqCreateFlqPool4
virtual bool sflqCreateFlqPool4(asiolink::IOAddress start_address, asiolink::IOAddress end_address, SubnetID subnet_id, bool recreate=false)
Creates a v4 SFLQ Pool.
Definition lease_mgr.cc:1991
isc::dhcp::LeaseMgr::upgradeLease4ExtendedInfo
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
isc::dhcp::LeaseMgr::sflqPool6GetAll
virtual SflqPoolInfoCollectionPtr sflqPool6GetAll()
Fetch all SFLQ V6 pools.
Definition lease_mgr.cc:2031
isc::dhcp::LeaseMgr::addRemoteId6
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.
isc::dhcp::LeaseMgr::startPoolLeaseStatsQuery4
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets and pools.
Definition lease_mgr.cc:276
isc::dhcp::LeaseMgr::bumpStat
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.
Definition lease_mgr.cc:1417
isc::dhcp::LeaseMgr::addExtendedInfo6
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
Definition lease_mgr.cc:1241
isc::dhcp::LeaseMgr::sflqPickFreeLease6
virtual asiolink::IOAddress sflqPickFreeLease6(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V6 address/prefix within the given pool range.
Definition lease_mgr.cc:2006
isc::dhcp::LeaseMgr::sflqPool6Get
virtual SflqPoolInfoCollectionPtr sflqPool6Get(SubnetID subnet_id)
Fetch all SFLQ V6 pools belonging to a subnet.
Definition lease_mgr.cc:2036
isc::dhcp::LeaseMgr::sflqCreateFlqPool6
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.
Definition lease_mgr.cc:2001
isc::dhcp::LeaseMgr::startLeaseStatsQuery6
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets.
Definition lease_mgr.cc:542
isc::dhcp::LeasePageSize::page_size_
const size_t page_size_
Holds page size.
Definition lease_mgr.h:56
isc::dhcp::LeasePageSize::LeasePageSize
LeasePageSize(const size_t page_size)
Constructor.
Definition lease_mgr.cc:47
isc::dhcp::LeaseStatsQuery::LeaseStatsQuery
LeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor to query statistics for all subnets.
Definition lease_mgr.cc:235
isc::dhcp::LeaseStatsQuery::first_subnet_id_
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
Definition lease_mgr.h:222
isc::dhcp::LeaseStatsQuery::last_subnet_id_
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
Definition lease_mgr.h:225
isc::dhcp::LeaseStatsQuery::getNextRow
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row of data.
Definition lease_mgr.cc:292
isc::dhcp::LeaseStatsQuery::SelectMode
SelectMode
Defines the types of selection criteria supported.
Definition lease_mgr.h:152
isc::dhcp::LeaseStatsQuery::ALL_SUBNETS
@ ALL_SUBNETS
Definition lease_mgr.h:153
isc::dhcp::LeaseStatsQuery::SINGLE_SUBNET
@ SINGLE_SUBNET
Definition lease_mgr.h:154
isc::dhcp::LeaseStatsQuery::SUBNET_RANGE
@ SUBNET_RANGE
Definition lease_mgr.h:155
isc::dhcp::LeaseStatsQuery::ALL_SUBNET_POOLS
@ ALL_SUBNET_POOLS
Definition lease_mgr.h:156
isc::dhcp::LibDHCP::unpackOptions6
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, size_t rec_level=0)
Parses provided buffer as DHCPv6 options and creates Option objects.
Definition libdhcp++.cc:320
isc::dhcp::LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF
static const OptionDefinition & DHO_DHCP_AGENT_OPTIONS_DEF()
Get definition of DHO_DHCP_AGENT_OPTIONS option.
Definition libdhcp++.cc:1480
isc::dhcp::OptionCustom
Option with defined data fields represented as buffers that can be accessed using data field index.
Definition option_custom.h:31
isc::dhcp::OptionDefinition
Base class representing a DHCP option definition.
Definition option_definition.h:138
isc::dhcp::Option::V4
@ V4
Definition option.h:90
isc::dhcp::SflqPoolInfo::delegated_len_
uint8_t delegated_len_
Definition lease_mgr.h:248
isc::dhcp::SflqPoolInfo::lease_type_
Lease::Type lease_type_
Definition lease_mgr.h:245
isc::dhcp::SflqPoolInfo::SflqPoolInfo
SflqPoolInfo()
Definition lease_mgr.cc:1965
isc::dhcp::SflqPoolInfo::subnet_id_
SubnetID subnet_id_
Definition lease_mgr.h:249
isc::dhcp::SflqPoolInfo::modified_ts_
boost::posix_time::ptime modified_ts_
Definition lease_mgr.h:252
isc::dhcp::SflqPoolInfo::created_ts_
boost::posix_time::ptime created_ts_
Definition lease_mgr.h:251
isc::dhcp::SflqPoolInfo::free_leases_
uint64_t free_leases_
Definition lease_mgr.h:250
isc::dhcp::SflqPoolInfo::toElement
data::ElementPtr toElement() const
Definition lease_mgr.cc:1977
isc::dhcp::SflqPoolInfo::start_address_
asiolink::IOAddress start_address_
Definition lease_mgr.h:246
isc::dhcp::SflqPoolInfo::end_address_
asiolink::IOAddress end_address_
Definition lease_mgr.h:247
isc::dhcp::SharedFlqAllocator::inUse
static bool inUse()
Returns the global in-use flag.
Definition sflq_allocator.cc:37
isc::stats::StatsMgr
Statistics Manager class.
Definition lib/stats/stats_mgr.h:65
isc::stats::StatsMgr::getObservation
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
Definition lib/stats/stats_mgr.cc:100
isc::stats::StatsMgr::instance
static StatsMgr & instance()
Statistics Manager accessor method.
Definition lib/stats/stats_mgr.cc:30
isc::stats::StatsMgr::generateName
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
Definition lib/stats/stats_mgr.h:303
command_interpreter.h
This file contains several functions and constants that are used for handling commands and responses ...
D6O_REMOTE_ID
@ D6O_REMOTE_ID
Definition dhcp6.h:57
D6O_RELAY_ID
@ D6O_RELAY_ID
Definition dhcp6.h:73
dhcpsrv_log.h
encode.h
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::stats::StatsMgr::setValue
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
Definition lib/stats/stats_mgr.cc:40
isc::stats::StatsMgr::addValue
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
Definition lib/stats/stats_mgr.cc:70
STATE_MASK
#define STATE_MASK(new_state, old_state)
Creates a mask out of two states: new state and old state.
Definition lease_mgr.cc:1441
lease_mgr.h
An abstract API for lease database.
stats_mgr.h
libdhcp++.h
LOG_ERROR
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
LOG_DEBUG
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
isc::asiolink
Definition addr_utilities.cc:170
isc::config
Definition command_interpreter.cc:23
isc::config::createAnswer
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
Definition command_interpreter.cc:54
isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
Definition command_interpreter.h:48
isc::data
Definition base_stamped_element.cc:12
isc::data::copy
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
Definition data.cc:1522
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::db
Definition audit_entry.cc:14
isc::db::info
@ info
Definition db_log.h:126
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::dhcpsrv_logger
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Definition dhcpsrv_log.h:56
isc::dhcp::DECLINED_RECLAIMED
constexpr uint16_t DECLINED_RECLAIMED
Definition lease_mgr.cc:1460
isc::dhcp::RECLAIMED_ASSIGNED
constexpr uint16_t RECLAIMED_ASSIGNED
Definition lease_mgr.cc:1467
isc::dhcp::REGISTERED_RELEASED
constexpr uint16_t REGISTERED_RELEASED
Definition lease_mgr.cc:1498
isc::dhcp::SflqPoolInfoCollectionPtr
boost::shared_ptr< SflqPoolInfoCollection > SflqPoolInfoCollectionPtr
Definition lease_mgr.h:262
isc::dhcp::DHCPSRV_LEASE6_EXTENDED_INFO_UPGRADED
const isc::log::MessageID DHCPSRV_LEASE6_EXTENDED_INFO_UPGRADED
Definition dhcpsrv_messages.h:79
isc::dhcp::OptionCustomPtr
boost::shared_ptr< OptionCustom > OptionCustomPtr
A pointer to the OptionCustom object.
Definition option_custom.h:468
isc::dhcp::Lease6Ptr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
isc::dhcp::Lease6Collection
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
isc::dhcp::LeaseStatsQueryPtr
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
Definition lease_mgr.h:233
isc::dhcp::Subnet6Collection
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:934
isc::dhcp::OptionCollection
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
isc::dhcp::REGISTERED_ASSIGNED
constexpr uint16_t REGISTERED_ASSIGNED
Definition lease_mgr.cc:1493
isc::dhcp::RELEASED_DECLINED
constexpr uint16_t RELEASED_DECLINED
Definition lease_mgr.cc:1482
isc::dhcp::ASSIGNED_ASSIGNED
constexpr uint16_t ASSIGNED_ASSIGNED
Constant expression state masks for use in switch statements.
Definition lease_mgr.cc:1445
isc::dhcp::ASSIGNED_DECLINED
constexpr uint16_t ASSIGNED_DECLINED
Definition lease_mgr.cc:1447
isc::dhcp::RECLAIMED_REGISTERED
constexpr uint16_t RECLAIMED_REGISTERED
Definition lease_mgr.cc:1477
isc::dhcp::RELEASED_ASSIGNED
constexpr uint16_t RELEASED_ASSIGNED
Definition lease_mgr.cc:1480
isc::dhcp::RECLAIMED_DECLINED
constexpr uint16_t RECLAIMED_DECLINED
Definition lease_mgr.cc:1469
isc::dhcp::PoolPtr
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
isc::dhcp::Subnet4Collection
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:863
isc::dhcp::REGISTERED_REGISTERED
constexpr uint16_t REGISTERED_REGISTERED
Definition lease_mgr.cc:1500
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::dhcp::DECLINED_ASSIGNED
constexpr uint16_t DECLINED_ASSIGNED
Definition lease_mgr.cc:1456
isc::dhcp::RELEASED_REGISTERED
constexpr uint16_t RELEASED_REGISTERED
Definition lease_mgr.cc:1490
isc::dhcp::ASSIGNED_RECLAIMED
constexpr uint16_t ASSIGNED_RECLAIMED
Definition lease_mgr.cc:1449
isc::dhcp::DECLINED_REGISTERED
constexpr uint16_t DECLINED_REGISTERED
Definition lease_mgr.cc:1464
isc::dhcp::DECLINED_RELEASED
constexpr uint16_t DECLINED_RELEASED
Definition lease_mgr.cc:1462
isc::dhcp::ASSIGNED_RELEASED
constexpr uint16_t ASSIGNED_RELEASED
Definition lease_mgr.cc:1451
isc::dhcp::DECLINED_DECLINED
constexpr uint16_t DECLINED_DECLINED
Definition lease_mgr.cc:1458
isc::dhcp::RAI_OPTION_RELAY_ID
@ RAI_OPTION_RELAY_ID
Definition dhcp4.h:276
isc::dhcp::RAI_OPTION_REMOTE_ID
@ RAI_OPTION_REMOTE_ID
Definition dhcp4.h:266
isc::dhcp::DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL
const isc::log::MessageID DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL
Definition dhcpsrv_messages.h:76
isc::dhcp::DHCPSRV_LEASE4_EXTENDED_INFO_UPGRADED
const isc::log::MessageID DHCPSRV_LEASE4_EXTENDED_INFO_UPGRADED
Definition dhcpsrv_messages.h:77
isc::dhcp::Lease4Ptr
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
isc::dhcp::DHCPSRV_DBG_TRACE
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Definition dhcpsrv_log.h:26
isc::dhcp::OptionPtr
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
isc::dhcp::DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL
const isc::log::MessageID DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL
Definition dhcpsrv_messages.h:78
isc::dhcp::REGISTERED_DECLINED
constexpr uint16_t REGISTERED_DECLINED
Definition lease_mgr.cc:1494
isc::dhcp::ASSIGNED_REGISTERED
constexpr uint16_t ASSIGNED_REGISTERED
Definition lease_mgr.cc:1453
isc::dhcp::REGISTERED_RECLAIMED
constexpr uint16_t REGISTERED_RECLAIMED
Definition lease_mgr.cc:1496
isc::stats
Definition context.cc:18
isc::util::encode::decodeHex
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
Definition encode.cc:367
isc::util::encode::encodeHex
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
Definition encode.cc:361
isc::util::str::decodeFormattedHexString
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Definition str.cc:212
isc::util
Definition time_utils.cc:43
isc::util::ptimeToText
std::string ptimeToText(boost::posix_time::ptime t, size_t fsecs_precision=MAX_FSECS_PRECISION)
Converts ptime structure to text.
Definition boost_time_utils.cc:14
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
option_custom.h
sflq_allocator.h
DHCP6_OPTION_SPACE
#define DHCP6_OPTION_SPACE
Definition std_option_defs.h:17
str.h
isc::dhcp::LeaseStatsRow
Contains a single row of lease statistical data.
Definition lease_mgr.h:64
isc::dhcp::LeaseStatsRow::pool_id_
uint32_t pool_id_
The pool ID to which this data applies.
Definition lease_mgr.h:132
isc::dhcp::LeaseStatsRow::state_count_
int64_t state_count_
state_count The count of leases in the lease state
Definition lease_mgr.h:141
isc::dhcp::LeaseStatsRow::lease_state_
uint32_t lease_state_
The lease_state to which the count applies.
Definition lease_mgr.h:138
isc::dhcp::LeaseStatsRow::subnet_id_
SubnetID subnet_id_
The subnet ID to which this data applies.
Definition lease_mgr.h:129
isc::dhcp::LeaseStatsRow::lease_type_
Lease::Type lease_type_
The lease_type to which the count applies.
Definition lease_mgr.h:135
isc::dhcp::Lease
a common structure for IPv4 and IPv6 leases
Definition lease.h:31
isc::dhcp::Lease::STATE_DEFAULT
static constexpr uint32_t STATE_DEFAULT
A lease in the default state.
Definition lease.h:69
isc::dhcp::Lease::STATE_EXPIRED_RECLAIMED
static constexpr uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition lease.h:75
isc::dhcp::Lease::STATE_DECLINED
static constexpr uint32_t STATE_DECLINED
Declined lease.
Definition lease.h:72
isc::dhcp::Lease::STATE_REGISTERED
static constexpr uint32_t STATE_REGISTERED
Registered self-generated lease.
Definition lease.h:81
isc::dhcp::Lease::STATE_RELEASED
static constexpr uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
Definition lease.h:78
isc::dhcp::Lease::Type
Type
Type of lease or pool.
Definition lease.h:46
isc::dhcp::Lease::TYPE_PD
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
isc::dhcp::Lease::TYPE_V4
@ TYPE_V4
IPv4 lease.
Definition lease.h:50
isc::dhcp::Lease::TYPE_NA
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47
isc::dhcp::Lease::typeToText
static std::string typeToText(Type type)
returns text representation of a lease type
Definition lease.cc:56
subnet_id.h