17 ClassLeaseCounter::getClassCount(
const ClientClass& client_class,
19 const ClassCountMap& leases_by_class = getConstCountMap(ltype);
20 auto it = leases_by_class.find(client_class);
21 if (it == leases_by_class.end()) {
30 ClassLeaseCounter::setClassCount(
const ClientClass& client_class,
size_t count,
33 leases_by_class[client_class] = count;
37 ClassLeaseCounter::adjustClassCount(
const ClientClass& client_class,
int offset,
40 auto it = leases_by_class.find(client_class);
41 if (it == leases_by_class.end()) {
43 leases_by_class[client_class] = offset < 0 ? 0 : offset;
45 size_t new_count = it->second + offset;
46 if (offset < 0 && (new_count > it->second)) {
50 it->second = new_count;
57 ClassLeaseCounter::getLeaseClientClasses(
LeasePtr lease) {
63 auto ctx = lease->getContext();
66 classes = ctx->find(
"ISC/client-classes");
71 }
catch (
const std::exception& ex) {
86 for (
int i = 0; i < classes->size(); ++i) {
87 std::string class_name = classes->get(i)->stringValue();
88 adjustClassCount(class_name, offset, ltype);
104 if (lease->state_ == Lease::STATE_DEFAULT) {
105 adjustClassCounts(classes, 1, lease->getType());
121 uint32_t new_state = new_lease->state_;
124 uint32_t old_state = old_lease->state_;
130 if ((old_state != new_state) || (old_classes != new_classes)) {
132 if (old_state == Lease::STATE_DEFAULT) {
133 adjustClassCounts(old_classes, -1, old_lease->getType());
137 if (new_state == Lease::STATE_DEFAULT) {
138 adjustClassCounts(new_classes, 1, new_lease->getType());
155 if (lease->state_ == Lease::STATE_DEFAULT) {
156 adjustClassCounts(classes, -1, lease->getType());
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
std::unordered_map< ClientClass, size_t > ClassCountMap
Defines ClassCountMap as an unordered map of counts.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< const Element > ConstElementPtr
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.
std::string ClientClass
Defines a single class name.