Too numerous to mention.
statistics in deployments running multiple Kea servers that use
shared lease back end. The in-memory statistics kept by individual
servers only track lease changes made by that server. Thus in a
- deployment with multiple servers, these statistics are incomplete.
+ deployment with multiple servers (e.g. two kea-dhcp6 servers using the
+ same PostgreSQL database for lease storage), these statistics are incomplete.
In Kea 1.4, the MySQL and PostgreSQL back ends were modified to track
lease allocation changes as they occur via database triggers. Additionally,
all four lease back ends were extended to support retrieving lease
The following command would fetch lease statistcis for all known subnets from kea-dhcp4 server:
<screen>
{
- "command": "stat-lease4-get",
- "arguments": {
- }
+ "command": "stat-lease4-get"
}
</screen>
</para>
<itemizedlist>
<listitem><simpara><command>subnet-id</command> - ID of the subnet</simpara></listitem>
<listitem><simpara><command>total-addresses</command> - total number of addresses
- available for DHCPv4 management. In other words, this is the sum of all
- addresses in all configured pools. This statistic changes only during
- configuration changes. Note it does not take into account any addresses that
- may be reserved due to host reservation.
- </simpara></listitem>
- <listitem><simpara><command>assigned-addresses</command> - number of assigned
- addresses in a given subnet. It increases every time a new lease is
- allocated (as a result of receiving a DHCPREQUEST message) and is decreased
- every time a lease is released (a DHCPRELEASE message is received) or expires.
- </simpara></listitem>
- <listitem><simpara><command>declined-addresses</command> - number of IPv4 addresses
- that are currently declined in a given subnet, so is a count of the number
- of leases currently unavailable. Once a lease is recovered, this statistic
- will be decreased. Ideally, this statistic should be zero. If this statistic
- is non-zero (or worse increasing), a network administrator should investigate
- if there is a misbehaving device in his network.
+ available for DHCPv4 management in the subnet. In other words, this is the sum of all
+ addresses in all the configured pools in the subnet.</simpara></listitem>
+ <listitem><simpara><command>assigned-addresses</command> - number of addresses
+ in the subnet that are currently assigned to a client.</simpara></listitem>
+ <listitem><simpara><command>declined-addresses</command> - number of addresses
+ in the subnet that are currently declined and are thus unavailable for assignment.
</simpara></listitem>
</itemizedlist></para>
</listitem>
<itemizedlist>
<listitem><simpara><command>subnet-id</command> - ID of the subnet</simpara></listitem>
<listitem><simpara><command>total-nas</command> - number of NA addresses available
- for DHCPv6 management for a given subnet. In other words, this is the
- sum of all addresses in all configured pools. This statistic changes
- only during configuration changes. Note that it does not take into account
- any addresses that may be reserved due to host reservation.</simpara>
- </listitem>
+ for DHCPv6 management in the subnet. In other words, this is the sum of all
+ the NA addresses in the all configured NA pools in the subnet.</simpara></listitem>
<listitem><simpara><command>assigned-nas</command> - number of NA addresses in a
- the subnet that are assigned. This statistic increases every time a new
- lease is allocated (as a result of receiving a REQUEST message) and is
- decreased every time a lease is released (a RELEASE message is received)
- or expires.
- </simpara></listitem>
- <listitem><simpara><command>declined-nas</command> - number of IPv6 addresses that
- are currently declined and so counts the number of leases currently
- unavailable. Once a lease is recovered, this statistic will be decreased.
- Ideally, this statistic should be zero. If this statistic is non-zero
- (or worse, increasing), the network administrator should investigate if
- there is a misbehaving device in the network.
- </simpara></listitem>
- <listitem><simpara><command>total-pds</command> - total number of PD prefixes available
- of DHCPv6 management for a given subnet. In other words, this is the sum
- of all prefixes in all configured pools. This statistic changes only during
- configuration changes. Note it does not take into account any prefixes that
- may be reserved due to host reservation.
- </simpara></listitem>
- <listitem><simpara><command>assigned-pds</command> - number of PD prefixes in a given
- subnet that are assigned. This statistic increases every time a new lease is
- allocated (as a result of receiving a REQUEST message) and is decreased every
- time a lease is released (a RELEASE message is received) or expires.
- </simpara></listitem>
+ the subnet that are currently assigned to a client.</simpara></listitem>
+ <listitem><simpara><command>declined-nas</command> - number of NA addresses that
+ are currently declined and are thus unavailable for assignment.</simpara></listitem>
+ <listitem><simpara><command>total-pds</command> - total number of prefixes available
+ of DHCPv6 management in the subnet. In other words, this is the sum of all prefixes
+ in all the configured prefix pools in the subnet.</simpara></listitem>
+ <listitem><simpara><command>assigned-pds</command> - number of prefixes in the subnet
+ that are currently assigned to a client.</simpara></listitem>
</itemizedlist></para>
</listitem>
<listitem><para><command>rows</command> - a list of rows, one per subnet ID. Each row
"result-set": {
"columns": [ "subnet-id", "total-addresses", "assigned-addresses", "declined-addresses" ]
"rows": [
- [ 10, 256, 111, 0 ], [ 20, 4098, 2034, 4 ]
+ [ 10, 256, 111, 0 ],
+ [ 20, 4098, 2034, 4 ]
],
"timestamp": "2018-05-04 15:03:37.000000"
}
</screen>
</para>
<para>
- The response to a DHCPv6 command might look as follows:
+ The response to a DHCPv6 command might look as follows (subnet 10 has no
+ prefix pools, subnet 20 has no NA pools, and subnet 30 has both NA and PD
+ pools):
<screen>
{
"result": 0,
"result-set": {
"columns": [ "subnet-id", "total-nas", "assigned-nas", "declined-nas", "total-pds", "assigned-pds" ]
"rows": [
- [ 10, 256, 111, 0 ],
- [ 20, 4098, 2034, 4 ]
+ [ 10, 4096, 2400, 3, 0, 0],
+ [ 20, 0, 0, 0, 1048, 233 ]
+ [ 30, 256, 60, 0, 1048, 15 ]
],
"timestamp": "2018-05-04 15:03:37.000000"
}
</simpara>
</listitem>
+ <listitem>
+ <simpara>
+ <command>kea-dhcp4.stat-cmds-hooks</command> - this logger is used
+ to log messages related to operation of the Stats Cmds hooks library.
+ In general these will pertain to loading and unloading the library,
+ as well as execution of commands by the library.
+ </simpara>
+ </listitem>
+
<listitem>
<simpara>
<command>kea-dhcp6</command> - the root logger for the DHCPv6
/// @brief Denotes the query selection mode all, subnet,
/// or subnet range
LeaseStatsQuery::SelectMode select_mode_;
+
+ /// @brief Generate a string version of the contents
+ std::string toText() {
+ std::stringstream os;
+ switch (select_mode_) {
+ case LeaseStatsQuery::ALL_SUBNETS:
+ os << "[all subnets]";
+ break;
+ case LeaseStatsQuery::SINGLE_SUBNET:
+ os << "[subnet-id=" << first_subnet_id_ << "]";
+ break;
+ case LeaseStatsQuery::SUBNET_RANGE:
+ os << "[subnets " << first_subnet_id_
+ << " through " << last_subnet_id_ << "]";
+ break;
+ }
+
+ return (os.str());
+ }
};
public:
/// must fulfill: 0 < first-subnet-id < last-subnet-id
/// -# subnet-id and subnet-range are mutually exclusive
Parameters getParameters(const ConstElementPtr& cmd_args);
-
- /// @brief Executes the lease4 query and constructs the outbound result set
+/// @brief Executes the lease4 query and constructs the outbound result set
///
/// This method uses the command parameters to identify the range
/// of configured subnets. If the range contains no known subnets
int
LeaseStatCmdsImpl::statLease4GetHandler(CalloutHandle& handle) {
ElementPtr result = Element::createMap();
- int response_code;
- string txt = "malformed command";
+ Parameters params;
+ ConstElementPtr response;
+
+ // Extract the command and then the parameters
try {
- // Extract the command and then the parameters
extractCommand(handle);
- Parameters params = getParameters(cmd_args_);
+ params = getParameters(cmd_args_);
+ } catch (const std::exception& ex) {
+ LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_INVALID)
+ .arg(ex.what());
+ setErrorResponse(handle, ex.what());
+ return (1);
+ }
+ try {
// Now build the result set
- txt = "building result";
uint64_t rows = makeResultSet4(result, params);
-
- // Eureka it worked!
- response_code = CONTROL_RESULT_SUCCESS;
+ LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET)
+ .arg(params.toText())
+ .arg(rows);
std::stringstream os;
- os << "stat-lease4-get: " << rows << " rows found";
- txt = os.str();
+ os << "stat-lease4-get" << params.toText() << ": " << rows << " rows found";
+ response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result);
} catch (const NotFound& ex) {
// Criteria was valid but included no known subnets,
// so we return a not found response.
- response_code = CONTROL_RESULT_EMPTY;
+ LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET_NO_SUBNETS)
+ .arg(params.toText())
+ .arg(ex.what());
std::stringstream os;
- os << "stat-lease4-get: " << "no matching data, " << ex.what();
- txt = os.str();
+ os << "stat-lease4-get" << params.toText() << ": no matching data, " << ex.what();
+ response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result);
} catch (const std::exception& ex) {
- LOG_ERROR(stat_cmds_logger, STAT_LEASE4_GET_FAILED)
- .arg(txt)
- .arg(ex.what());
+ LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_FAILED)
+ .arg(params.toText())
+ .arg(ex.what());
setErrorResponse(handle, ex.what());
return (1);
}
- LOG_INFO(stat_cmds_logger, STAT_LEASE4_GET).arg(txt);
- ConstElementPtr response = createAnswer(response_code, txt, result);
setResponse(handle, response);
return (0);
}
int
LeaseStatCmdsImpl::statLease6GetHandler(CalloutHandle& handle) {
ElementPtr result = Element::createMap();
- int response_code;
- string txt = "malformed command";
+ Parameters params;
+ ConstElementPtr response;
+
+ // Extract the command and then the parameters
try {
- // Extract the command and then the parameters
extractCommand(handle);
- Parameters params = getParameters(cmd_args_);
+ params = getParameters(cmd_args_);
+ } catch (const std::exception& ex) {
+ LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_INVALID)
+ .arg(ex.what());
+ setErrorResponse(handle, ex.what());
+ return (1);
+ }
+ try {
// Now build the result set
- txt = "building result";
uint64_t rows = makeResultSet6(result, params);
-
- // Eureka it worked!
- response_code = CONTROL_RESULT_SUCCESS;
+ LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET)
+ .arg(params.toText())
+ .arg(rows);
std::stringstream os;
- os << "stat-lease6-get: " << rows << " rows found";
- txt = os.str();
+ os << "stat-lease6-get" << params.toText() << ": " << rows << " rows found";
+ response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result);
} catch (const NotFound& ex) {
// Criteria was valid but included no known subnets,
// so we return a not found response.
- result = Element::createMap();
- response_code = CONTROL_RESULT_EMPTY;
+ LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET_NO_SUBNETS)
+ .arg(params.toText())
+ .arg(ex.what());
std::stringstream os;
- os << "stat-lease6-get: " << "no matching data, " << ex.what();
- txt = os.str();
+ os << "stat-lease6-get" << params.toText() << ": no matching data, " << ex.what();
+ response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result);
} catch (const std::exception& ex) {
- LOG_ERROR(stat_cmds_logger, STAT_LEASE6_GET_FAILED)
- .arg(txt)
- .arg(ex.what());
+ LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_FAILED)
+ .arg(params.toText())
+ .arg(ex.what());
setErrorResponse(handle, ex.what());
return (1);
}
- LOG_INFO(stat_cmds_logger, STAT_LEASE6_GET).arg(txt);
- ConstElementPtr response = createAnswer(response_code, txt, result);
setResponse(handle, response);
return (0);
}
LeaseStatCmdsImpl::getParameters(const ConstElementPtr& cmd_args) {
Parameters params;
- if (!cmd_args || cmd_args->getType() != Element::map) {
- isc_throw(BadValue, "Parameters missing or are not a map.");
+ params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS;
+ if (!cmd_args ) {
+ // No arguments defaults to ALL_SUBNETS.
+ return (params);
+ }
+
+ if (cmd_args->getType() != Element::map) {
+ isc_throw(BadValue, "'arguments' parameter is not a map");
}
params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS;
if (cmd_args->contains("subnet-range")) {
if (params.select_mode_ == LeaseStatsQuery::SINGLE_SUBNET) {
- isc_throw(BadValue, "Cannot specify both subnet-id and subnet-range");
+ isc_throw(BadValue, "cannot specify both subnet-id and subnet-range");
}
ConstElementPtr range = cmd_args->get("subnet-range");
result_wrapper->set("result-set", result_set);
// Create the timestamp based on time now and add it to the result set.
- boost::posix_time::ptime now(boost::posix_time::second_clock::universal_time());
+ boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
+
ElementPtr timestamp = Element::create(isc::util::ptimeToText(now));
result_set->set("timestamp", timestamp);
return(impl.statLease6GetHandler(handle));
}
-StatCmds::StatCmds() {
-}
-
};
};
-// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#ifndef STAT_CMDS_H
#define STAT_CMDS_H
-#include <cc/data.h>
#include <hooks/hooks.h>
#include <boost/shared_ptr.hpp>
/// stat manipulations.
class StatCmds {
public:
- /// @brief Constructor.
- ///
- /// It creates an instance of the @c StatCmdsImpl.
- StatCmds();
+ /// @brief Default Constructor.
+ StatCmds() {};
/// @brief stat-lease4-get command handler
///
- /// This command attempts to fetch lease4 statistics for one or
+ /// This command attempts to fetch lease4 statistics for one or
/// more subnets based upon subnet selection criteria (or lack thereof).
/// It extracts the command name and arguments from the given Callouthandle,
/// attempts to process them, and then set's the handle's "response"
/// {
/// "command": "stat-lease4-get",
/// "arguments": {
- /// "subnet-id": x // optional
+ /// "subnet-id": 10 // optional
/// "subnet-range": { // optional
- /// "first-subnet-id": x, // id >= x
- /// "last-subnet-id": y // id <= x
+ /// "first-subnet-id": 10, // id >= 10
+ /// "last-subnet-id": 50 // id <= 50
/// }
/// }
/// }
/// "arguments": {
/// "result-set": {
/// "timestamp": "2018-03-22 09:43:30.815371",
- /// "columns": ["subnet_id", "total-addresses",
+ /// "columns": ["subnet_id", "total-addresses",
/// "assigned-addresses", "declined-addresses"],
/// "rows": [
/// [1, 600, 450, 3],
/// @brief stat-lease6-get command handler
///
- /// This command attempts to fetch lease6 statistics for one or
+ /// This command attempts to fetch lease6 statistics for one or
/// more subnets based upon subnet selection criteria (or lack thereof).
/// It extracts the command name and arguments from the given Callouthandle,
/// attempts to process them, and then set's the handle's "response"
/// {
/// "command": "stat-lease6-get",
/// "arguments": {
- /// "subnet-id": x // optional
+ /// "subnet-id": 10 // optional
/// "subnet-range": { // optional
- /// "first-subnet-id": x, // id >= x
- /// "last-subnet-id": y // id <= x
+ /// "first-subnet-id": 10, // id >= 10
+ /// "last-subnet-id": 50 // id <= 50
/// }
/// }
/// }
/// "arguments": {
/// "result-set": {
/// "timestamp": "2018-03-22 09:43:30.815371",
- /// "columns": ["subnet_id", "total-nas",
- /// "assigned-nas", "declined-nas",
+ /// "columns": ["subnet_id", "total-nas",
+ /// "assigned-nas", "declined-nas",
/// "total-pds", "assigned-pds"],
/// "rows": [
/// [1, 600, 450, 3, 64, 10],
/// @return result of the operation
int
statLease6GetHandler(hooks::CalloutHandle& handle);
-#if 0
-private:
- /// Pointer to the actual implementation
- boost::shared_ptr<StatCmdsImpl> impl_;
-#endif
};
};
#include <cc/command_interpreter.h>
#include <hooks/hooks.h>
-using namespace isc::config;
-using namespace isc::data;
using namespace isc::hooks;
using namespace isc::stat_cmds;
int load(LibraryHandle& handle) {
handle.registerCommandCallout("stat-lease4-get", stat_lease4_get);
handle.registerCommandCallout("stat-lease6-get", stat_lease6_get);
- LOG_INFO(stat_cmds_logger, STAT_CMDS_INIT_OK);
+ LOG_INFO(stat_cmds_logger, STAT_CMDS_CMDS_INIT_OK);
return (0);
}
///
/// @return 0 if deregistration was successful, 1 otherwise
int unload() {
- LOG_INFO(stat_cmds_logger, STAT_CMDS_DEINIT_OK);
+ LOG_INFO(stat_cmds_logger, STAT_CMDS_CMDS_DEINIT_OK);
return (0);
}
namespace isc {
namespace stat_cmds {
-isc::log::Logger stat_cmds_logger("stat_cmds_hooks");
+isc::log::Logger stat_cmds_logger("stat-cmds-hooks");
}
}
# Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
-% STAT_LEASE4_GET stat-lease4-get command successful (parameters: %1)
-The stat-lease4-get command has been successful. Parameters of the command
-are logged.
+% STAT_CMDS_LEASE4_GET stat-lease4-get command successful, parameters: %1 rows found: %2
+The stat-lease4-get command has been successful. The log will contain
+the parameters supplied and the number of rows found.
-% STAT_LEASE4_GET_FAILED stat-lease4-get command failed (parameters: %1, reason: %2)
-The stat-lease4-get command has failed. Both the reason as well as the
-parameters passed are logged.
+% STAT_CMDS_LEASE4_GET_FAILED stat-lease4-get command failed: parameters: %1, reason: %2
+The stat-lease4-get command has failed. Both the parameters supplied and
+the reason for failure are logged.
-% STAT_LEASE6_GET stat-lease4-get command successful (parameters: %1)
-The stat-lease4-get command has been successful. Parameters of the command
-are logged.
+% STAT_CMDS_LEASE4_GET_INVALID stat-lease4-get command is malformed or invalid, reason: %1
+The stat-lease4-get command was either malformed or contained invalid
+parameters. A detailed explanation should be logged.
-% STAT_LEASE6_GET_FAILED stat-lease4-get command failed (parameters: %1, reason: %2)
-The stat-lease4-get command has failed. Both the reason as well as the
-parameters passed are logged.
+% STAT_CMDS_LEASE4_GET_NO_SUBNETS stat-lease4-get, parameters: %1, %2"
+The parameters submitted with stat-lease4-get were valid but excluded all
+known subnets. The parameters supplied along with an explanation should
+be logged.
-% STAT_CMDS_DEINIT_FAILED unloading Stat Commands hooks library failed: %1
+% STAT_CMDS_LEASE6_GET stat-lease6-get command successful, parameters: %1 rows found: %2
+The stat-lease6-get command has been successful. The log will contain
+the parameters supplied and the number of rows found.
+
+% STAT_CMDS_LEASE6_GET_FAILED stat-lease4-get command failed: parameters: %1, reason: %2
+The stat-lease6-get command has failed. Both the parameters supplied and
+the reason for failure are logged.
+
+% STAT_CMDS_LEASE6_GET_INVALID stat-lease6-get command is malformed or invalid, reason: %1
+The stat-lease6-get command was either malformed or contained invalid
+parameters. A detailed explanation should be logged.
+
+% STAT_CMDS_LEASE6_GET_NO_SUBNETS stat-lease6-get, parameters: %1, %2"
+The parameters submitted with stat-lease6-get were valid but excluded all
+known subnets. The parameters supplied along with an explanation should
+be logged.
+
+% STAT_CMDS_CMDS_DEINIT_FAILED unloading Stat Commands hooks library failed: %1
This error message indicates an error during unloading the Lease Commands
hooks library. The details of the error are provided as argument of
the log message.
-% STAT_CMDS_DEINIT_OK unloading Stat Commands hooks library successful
+% STAT_CMDS_CMDS_DEINIT_OK unloading Stat Commands hooks library successful
This info message indicates that the Stat Commands hooks library has been
removed successfully.
-% STAT_CMDS_INIT_FAILED loading Stat Commands hooks library failed: %1
+% STAT_CMDS_CMDS_INIT_FAILED loading Stat Commands hooks library failed: %1
This error message indicates an error during loading the Lease Commands
hooks library. The details of the error are provided as argument of
the log message.
-% STAT_CMDS_INIT_OK loading Stat Commands hooks library successful
+% STAT_CMDS_CMDS_INIT_OK loading Stat Commands hooks library successful
This info message indicates that the Stat Commands hooks library has been
loaded successfully. Enjoy!
stat_cmds_unittests_CXXFLAGS = $(AM_CXXFLAGS)
stat_cmds_unittests_LDADD = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
-stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
-stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
+stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la
stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
stat_cmds_unittests_LDADD += $(LOG4CPLUS_LIBS)
-// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// @brief Creates an IPv6 lease
///
- /// Lease parameters: cltt = 12345678, fqdn-fwd = false, fqdn-rev = true,
- /// hostname = myhost.example.com, preferred lifetime = 1800,
- /// valid lifetime = 3600
- ///
/// @param ip_address IP address for the lease.
/// @param subnet_id subnet identifier
- /// @param state lease state
+ /// @param state lease state of the lease, defaults to STATE_DEFAULT
+ /// @param lease_type type of the lease, defaults to TYPE_NA
+ /// @param prefix_len prefix length of the lease, defaults to 128
void addLease6(const std::string& ip_address, const SubnetID& subnet_id,
const int state = Lease::STATE_DEFAULT,
const Lease::Type& lease_type = Lease::TYPE_NA,
<< "cannot add lease6: " << lease->toText();
}
- void addPrefix(const std::string& ip_address, const int prefix_len,
+ /// @brief Creates an IPv6 PD lease
+ ///
+ /// @param prefix IP address prefix for the lease.
+ /// @param prefix_len prefix length of the lease
+ /// @param subnet_id subnet identifier
+ /// @param state lease state of the lease, defaults to STATE_DEFAULT
+ void addPrefix(const std::string& prefix, const int prefix_len,
const SubnetID& subnet_id,
const int state = Lease::STATE_DEFAULT) {
- addLease6(ip_address, subnet_id, state, Lease::TYPE_PD, prefix_len);
+ addLease6(prefix, subnet_id, state, Lease::TYPE_PD, prefix_len);
}
/// @brief Pointer to the lease manager
initLeaseMgr4();
std::vector<TestScenario> tests = {
+ {
+ "arguments is not a map",
+ "{\n"
+ " \"command\": \"stat-lease4-get\",\n"
+ " \"arguments\": \"not a map\"\n"
+ "}",
+ "'arguments' parameter is not a map"
+ },
{
"subnet-id 0",
"{\n"
"}",
"'last-subnet-id' must be greater than 'first-subnet-id'"
},
+ {
+ "Subnet-Range: all in the middle",
+ "{\n"
+ " \"command\": \"stat-lease4-get\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 10,\n"
+ " \"subnet-range\": {\n"
+ " \"first-subnet-id\": 20,"
+ " \"last-subnet-id\": 40"
+ " }\n"
+ " }\n"
+ "}",
+ "cannot specify both subnet-id and subnet-range"
+ }
};
for (auto test = tests.begin(); test != tests.end(); ++test) {
" \"arguments\": {"
" }\n"
"}",
- "stat-lease4-get: 5 rows found",
+ "stat-lease4-get[all subnets]: 5 rows found",
+ "{\n"
+ "\"result-set\": {\n"
+ " \"columns\": [\n"
+ " \"subnet-id\", \"total-addreses\",\n"
+ " \"assigned-addreses\", \"declined-addreses\"\n"
+ " ],\n"
+ " \"rows\": [\n"
+ " [ 10, 256, 2, 3 ],\n"
+ " [ 20, 16, 3, 0 ],\n"
+ " [ 30, 256, 0, 0 ],\n"
+ " [ 40, 16, 4, 0 ],\n"
+ " [ 50, 256, 1, 1 ]\n"
+ " ],\n"
+ " \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
+ "}\n"
+ },
+ {
+ "ALL-Subnets - arguments omitted",
+ "{\n"
+ " \"command\": \"stat-lease4-get\"\n"
+ "}",
+ "stat-lease4-get[all subnets]: 5 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" \"subnet-id\": 20"
" }\n"
"}",
- "stat-lease4-get: 1 rows found",
+ "stat-lease4-get[subnet-id=20]: 1 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease4-get: 3 rows found",
+ "stat-lease4-get[subnets 10 through 30]: 3 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease4-get: 3 rows found",
+ "stat-lease4-get[subnets 20 through 40]: 3 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease4-get: 3 rows found",
+ "stat-lease4-get[subnets 30 through 50]: 3 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease4-get: 2 rows found",
+ "stat-lease4-get[subnets 25 through 45]: 2 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" \"subnet-id\": 88"
" }\n"
"}",
- "stat-lease4-get: no matching data, subnet-id: 88 does not exist",
+ "stat-lease4-get[subnet-id=88]: no matching data, subnet-id: 88 does not exist",
"{}"
},
{
" }\n"
" }\n"
"}",
- "stat-lease4-get: no matching data, selected ID range: 2 through 6 includes no known subnets",
+ "stat-lease4-get[subnets 2 through 6]: no matching data, selected ID range: 2 through 6 includes no known subnets",
"{}"
},
{
" }\n"
" }\n"
"}",
- "stat-lease4-get: no matching data, selected ID range: 200 through 600 includes no known subnets",
+ "stat-lease4-get[subnets 200 through 600]: no matching data, selected ID range: 200 through 600 includes no known subnets",
"{}"
}
};
initLeaseMgr6();
std::vector<TestScenario> tests = {
+ {
+ "arguments not a map",
+ "{\n"
+ " \"command\": \"stat-lease6-get\",\n"
+ " \"arguments\": \"not a map\"\n"
+ "}",
+ "'arguments' parameter is not a map"
+ },
{
"subnet-id 0",
"{\n"
"}",
"'last-subnet-id' must be greater than 'first-subnet-id'"
},
+ {
+ "both subnet and range",
+ "{\n"
+ " \"command\": \"stat-lease6-get\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 10,\n"
+ " \"subnet-range\": {\n"
+ " \"first-subnet-id\": 20,"
+ " \"last-subnet-id\": 40"
+ " }\n"
+ " }\n"
+ "}",
+ "cannot specify both subnet-id and subnet-range"
+ }
};
for (auto test = tests.begin(); test != tests.end(); ++test) {
" \"arguments\": {"
" }\n"
"}",
- "stat-lease6-get: 5 rows found",
+ "stat-lease6-get[all subnets]: 5 rows found",
+ "{\n"
+ "\"result-set\": {\n"
+ " \"columns\": [\n"
+ " \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
+ " \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+ " ],\n"
+ " \"rows\": [\n"
+ " [ 10, 65536, 2, 3, 0, 0 ],\n"
+ " [ 20, 16777216, 3, 0, 0, 0 ],\n"
+ " [ 30, 16, 1, 1, 65536, 3 ],\n"
+ " [ 40, 16777216, 0, 0, 0, 0 ],\n"
+ " [ 50, 0, 0, 0, 65536, 2 ]\n"
+ " ],\n"
+ " \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
+ "}\n"
+ },
+ {
+ "ALL-Subnets6 arugments omitted",
+ "{\n"
+ " \"command\": \"stat-lease6-get\"\n"
+ "}",
+ "stat-lease6-get[all subnets]: 5 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" \"subnet-id\": 20"
" }\n"
"}",
- "stat-lease6-get: 1 rows found",
+ "stat-lease6-get[subnet-id=20]: 1 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease6-get: 3 rows found",
+ "stat-lease6-get[subnets 10 through 30]: 3 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease6-get: 3 rows found",
+ "stat-lease6-get[subnets 20 through 40]: 3 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease6-get: 3 rows found",
+ "stat-lease6-get[subnets 30 through 50]: 3 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" }\n"
" }\n"
"}",
- "stat-lease6-get: 2 rows found",
+ "stat-lease6-get[subnets 25 through 45]: 2 rows found",
"{\n"
"\"result-set\": {\n"
" \"columns\": [\n"
" \"subnet-id\": 88"
" }\n"
"}",
- "stat-lease6-get: no matching data, subnet-id: 88 does not exist",
+ "stat-lease6-get[subnet-id=88]: no matching data, subnet-id: 88 does not exist",
"{}"
},
{
" }\n"
" }\n"
"}",
- "stat-lease6-get: no matching data, selected ID range: 2 through 6 includes no known subnets",
+ "stat-lease6-get[subnets 2 through 6]: no matching data, selected ID range: 2 through 6 includes no known subnets",
"{}"
},
{
" }\n"
" }\n"
"}",
- "stat-lease6-get: no matching data, selected ID range: 200 through 600 includes no known subnets",
+ "stat-lease6-get[subnets 200 through 600]: no matching data, selected ID range: 200 through 600 includes no known subnets",
"{}"
}
};