]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#816] Added per subnet cumulative assigned stats
authorFrancis Dupont <fdupont@isc.org>
Sat, 4 Apr 2020 16:53:50 +0000 (18:53 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 23 Apr 2020 21:23:18 +0000 (23:23 +0200)
14 files changed:
doc/sphinx/arm/dhcp4-srv.rst
doc/sphinx/arm/dhcp6-srv.rst
doc/sphinx/arm/hooks-stat-cmds.rst
src/hooks/dhcp/stat_cmds/stat_cmds.cc
src/hooks/dhcp/stat_cmds/stat_cmds.dox
src/hooks/dhcp/stat_cmds/stat_cmds.h
src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine_utils.cc
src/lib/dhcpsrv/tests/alloc_engine_utils.h

index 53d36d24175b17fdad667ac2b101340bf682ab85..132428e5b2e190db2022a5f12418fc01e9b4d0b0 100644 (file)
@@ -5372,412 +5372,430 @@ The DHCPv4 server supports the following statistics:
    :class: longtable
    :widths: 20 10 70
 
-   +--------------------------------+----------------+-----------------------------------+
-   | Statistic                      | Data Type      | Description                       |
-   +================================+================+===================================+
-   | pkt4-received                  | integer        | Number of DHCPv4 packets          |
-   |                                |                | received.  This includes all      |
-   |                                |                | packets: valid, bogus,            |
-   |                                |                | corrupted, rejected, etc. This    |
-   |                                |                | statistic is expected to grow     |
-   |                                |                | rapidly.                          |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-discover-received         | integer        | Number of                         |
-   |                                |                | DHCPDISCOVER packets              |
-   |                                |                | received. This                    |
-   |                                |                | statistic is expected             |
-   |                                |                | to grow; its increase             |
-   |                                |                | means that clients                |
-   |                                |                | that just booted                  |
-   |                                |                | started their                     |
-   |                                |                | configuration process             |
-   |                                |                | and their initial                 |
-   |                                |                | packets reached the               |
-   |                                |                | Kea server.                       |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-offer-received            | integer        | Number of DHCPOFFER               |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to remain                |
-   |                                |                | zero at all times, as             |
-   |                                |                | DHCPOFFER packets are             |
-   |                                |                | sent by the server                |
-   |                                |                | and the server is                 |
-   |                                |                | never expected to                 |
-   |                                |                | receive them. A                   |
-   |                                |                | non-zero value                    |
-   |                                |                | indicates an error.               |
-   |                                |                | One likely cause                  |
-   |                                |                | would be a                        |
-   |                                |                | misbehaving relay                 |
-   |                                |                | agent that                        |
-   |                                |                | incorrectly forwards              |
-   |                                |                | DHCPOFFER messages                |
-   |                                |                | towards the server,               |
-   |                                |                | rather than back to               |
-   |                                |                | the clients.                      |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-request-received          | integer        | Number of DHCPREQUEST             |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to grow. Its             |
-   |                                |                | increase means that               |
-   |                                |                | clients that just                 |
-   |                                |                | booted received the               |
-   |                                |                | server's response                 |
-   |                                |                | (DHCPOFFER) and                   |
-   |                                |                | accepted it, and are              |
-   |                                |                | now requesting an                 |
-   |                                |                | address                           |
-   |                                |                | (DHCPREQUEST).                    |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-ack-received              | integer        | Number of DHCPACK                 |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to remain                |
-   |                                |                | zero at all times, as             |
-   |                                |                | DHCPACK packets are               |
-   |                                |                | sent by the server                |
-   |                                |                | and the server is                 |
-   |                                |                | never expected to                 |
-   |                                |                | receive them. A                   |
-   |                                |                | non-zero value                    |
-   |                                |                | indicates an error.               |
-   |                                |                | One likely cause                  |
-   |                                |                | would be a                        |
-   |                                |                | misbehaving relay                 |
-   |                                |                | agent that                        |
-   |                                |                | incorrectly forwards              |
-   |                                |                | DHCPACK messages                  |
-   |                                |                | towards the server,               |
-   |                                |                | rather than back to               |
-   |                                |                | the clients.                      |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-nak-received              | integer        | Number of DHCPNAK                 |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to remain                |
-   |                                |                | zero at all times, as             |
-   |                                |                | DHCPNAK packets are               |
-   |                                |                | sent by the server                |
-   |                                |                | and the server is                 |
-   |                                |                | never expected to                 |
-   |                                |                | receive them. A                   |
-   |                                |                | non-zero value                    |
-   |                                |                | indicates an error.               |
-   |                                |                | One likely cause                  |
-   |                                |                | would be a                        |
-   |                                |                | misbehaving relay                 |
-   |                                |                | agent that                        |
-   |                                |                | incorrectly forwards              |
-   |                                |                | DHCPNAK messages                  |
-   |                                |                | towards the server,               |
-   |                                |                | rather than back to               |
-   |                                |                | the clients.                      |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-release-received          | integer        | Number of DHCPRELEASE             |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to grow. Its             |
-   |                                |                | increase means that               |
-   |                                |                | clients that had an               |
-   |                                |                | address are shutting              |
-   |                                |                | down or ceasing to                |
-   |                                |                | use their addresses.              |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-decline-received          | integer        | Number of DHCPDECLINE             |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to remain                |
-   |                                |                | close to zero. Its                |
-   |                                |                | increase means that a             |
-   |                                |                | client leased an                  |
-   |                                |                | address, but                      |
-   |                                |                | discovered that the               |
-   |                                |                | address is currently              |
-   |                                |                | used by an unknown                |
-   |                                |                | device in the                     |
-   |                                |                | network.                          |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-inform-received           | integer        | Number of DHCPINFORM              |
-   |                                |                | packets received.                 |
-   |                                |                | This statistic is                 |
-   |                                |                | expected to grow. Its             |
-   |                                |                | increase means that               |
-   |                                |                | there are clients                 |
-   |                                |                | that either do not                |
-   |                                |                | need an address or                |
-   |                                |                | already have an                   |
-   |                                |                | address and are                   |
-   |                                |                | interested only in                |
-   |                                |                | getting additional                |
-   |                                |                | configuration                     |
-   |                                |                | parameters.                       |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-unknown-received          | integer        | Number of packets                 |
-   |                                |                | received of an                    |
-   |                                |                | unknown type. A                   |
-   |                                |                | non-zero value of                 |
-   |                                |                | this statistic                    |
-   |                                |                | indicates that the                |
-   |                                |                | server received a                 |
-   |                                |                | packet that it wasn't             |
-   |                                |                | able to recognize,                |
-   |                                |                | either with an                    |
-   |                                |                | unsupported type or               |
-   |                                |                | possibly malformed                |
-   |                                |                | (without message type             |
-   |                                |                | option).                          |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-sent                      | integer        | Number of DHCPv4                  |
-   |                                |                | packets sent. This                |
-   |                                |                | statistic is expected             |
-   |                                |                | to grow every time                |
-   |                                |                | the server transmits              |
-   |                                |                | a packet. In general,             |
-   |                                |                | it should roughly                 |
-   |                                |                | match pkt4-received,              |
-   |                                |                | as most incoming                  |
-   |                                |                | packets cause the                 |
-   |                                |                | server to respond.                |
-   |                                |                | There are exceptions              |
-   |                                |                | (e.g. DHCPRELEASE),               |
-   |                                |                | so do not worry if it             |
-   |                                |                | is less than                      |
-   |                                |                | pkt4-received.                    |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-offer-sent                | integer        | Number of DHCPOFFER               |
-   |                                |                | packets sent. This                |
-   |                                |                | statistic is expected             |
-   |                                |                | to grow in most cases             |
-   |                                |                | after a DHCPDISCOVER              |
-   |                                |                | is processed. There               |
-   |                                |                | are certain uncommon,             |
-   |                                |                | but valid, cases                  |
-   |                                |                | where incoming                    |
-   |                                |                | DHCPDISCOVER packets              |
-   |                                |                | are dropped, but in               |
-   |                                |                | general this                      |
-   |                                |                | statistic is expected             |
-   |                                |                | to be close to                    |
-   |                                |                | pkt4-discover-received.           |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-ack-sent                  | integer        | Number of DHCPACK                 |
-   |                                |                | packets sent. This                |
-   |                                |                | statistic is expected             |
-   |                                |                | to grow in most cases             |
-   |                                |                | after a DHCPREQUEST               |
-   |                                |                | is processed. There               |
-   |                                |                | are certain cases                 |
-   |                                |                | where DHCPNAK is sent             |
-   |                                |                | instead. In general,              |
-   |                                |                | the sum of                        |
-   |                                |                | pkt4-ack-sent and                 |
-   |                                |                | pkt4-nak-sent should              |
-   |                                |                | be close to                       |
-   |                                |                | pkt4-request-received.            |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-nak-sent                  | integer        | Number of DHCPNAK                 |
-   |                                |                | packets sent. This                |
-   |                                |                | statistic is expected             |
-   |                                |                | to grow when the                  |
-   |                                |                | server chooses not to             |
-   |                                |                | honor the address                 |
-   |                                |                | requested by a                    |
-   |                                |                | client. In general,               |
-   |                                |                | the sum of                        |
-   |                                |                | pkt4-ack-sent and                 |
-   |                                |                | pkt4-nak-sent should              |
-   |                                |                | be close to                       |
-   |                                |                | pkt4-request-received.            |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-parse-failed              | integer        | Number of incoming                |
-   |                                |                | packets that could                |
-   |                                |                | not be parsed. A                  |
-   |                                |                | non-zero value of                 |
-   |                                |                | this statistic                    |
-   |                                |                | indicates that the                |
-   |                                |                | server received a                 |
-   |                                |                | malformed or                      |
-   |                                |                | truncated packet.                 |
-   |                                |                | This may indicate                 |
-   |                                |                | problems in the                   |
-   |                                |                | network, faulty                   |
-   |                                |                | clients, or a bug in              |
-   |                                |                | the server.                       |
-   +--------------------------------+----------------+-----------------------------------+
-   | pkt4-receive-drop              | integer        | Number of incoming                |
-   |                                |                | packets that were                 |
-   |                                |                | dropped. The exact                |
-   |                                |                | reason for dropping               |
-   |                                |                | packets is logged,                |
-   |                                |                | but the most common               |
-   |                                |                | reasons may be: an                |
-   |                                |                | unacceptable packet               |
-   |                                |                | type, direct                      |
-   |                                |                | responses are                     |
-   |                                |                | forbidden, or the                 |
-   |                                |                | server-id sent by the             |
-   |                                |                | client does not match             |
-   |                                |                | the server's                      |
-   |                                |                | server-id.                        |
-   +--------------------------------+----------------+-----------------------------------+
-   | subnet[id].total-addresses     | integer        | 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.              |
-   |                                |                | The *id* is the                   |
-   |                                |                | subnet-id of a given              |
-   |                                |                | subnet. This                      |
-   |                                |                | statistic is exposed              |
-   |                                |                | for each subnet                   |
-   |                                |                | separately, and is                |
-   |                                |                | reset during a                    |
-   |                                |                | reconfiguration                   |
-   |                                |                | event.                            |
-   +--------------------------------+----------------+-----------------------------------+
-   | subnet[id].assigned-addresses  | integer        | 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. The *id* is              |
-   |                                |                | the subnet-id of the              |
-   |                                |                | subnet. This                      |
-   |                                |                | statistic is exposed              |
-   |                                |                | for each subnet                   |
-   |                                |                | separately, and is                |
-   |                                |                | reset during a                    |
-   |                                |                | reconfiguration                   |
-   |                                |                | event.                            |
-   +--------------------------------+----------------+-----------------------------------+
-   | reclaimed-leases               | integer        | Number of expired                 |
-   |                                |                | leases that have been             |
-   |                                |                | reclaimed since                   |
-   |                                |                | server startup. It is             |
-   |                                |                | incremented each time             |
-   |                                |                | an expired lease is               |
-   |                                |                | reclaimed and is                  |
-   |                                |                | reset when the server             |
-   |                                |                | is reconfigured.                  |
-   +--------------------------------+----------------+-----------------------------------+
-   | subnet[id].reclaimed-leases    | integer        | Number of expired                 |
-   |                                |                | leases associated                 |
-   |                                |                | with a given subnet               |
-   |                                |                | (*id* is the                      |
-   |                                |                | subnet-id) that have              |
-   |                                |                | been reclaimed since              |
-   |                                |                | server startup. It is             |
-   |                                |                | incremented each time             |
-   |                                |                | an expired lease is               |
-   |                                |                | reclaimed and is                  |
-   |                                |                | reset when the server             |
-   |                                |                | is reconfigured.                  |
-   +--------------------------------+----------------+-----------------------------------+
-   | declined-addresses             | integer        | Number of IPv4                    |
-   |                                |                | addresses that are                |
-   |                                |                | currently declined; 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 increasing, a                  |
-   |                                |                | network administrator             |
-   |                                |                | should investigate                |
-   |                                |                | whether there is a                |
-   |                                |                | misbehaving device in             |
-   |                                |                | the network. This is              |
-   |                                |                | a global statistic                |
-   |                                |                | that covers all                   |
-   |                                |                | subnets.                          |
-   +--------------------------------+----------------+-----------------------------------+
-   | subnet[id].declined-addresses  | integer        | Number of IPv4                    |
-   |                                |                | addresses that are                |
-   |                                |                | currently declined in             |
-   |                                |                | a given subnet; 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 increasing, a                  |
-   |                                |                | network administrator             |
-   |                                |                | should investigate                |
-   |                                |                | whether there is a                |
-   |                                |                | misbehaving device in             |
-   |                                |                | the network. The *id*             |
-   |                                |                | is the subnet-id of a             |
-   |                                |                | given subnet. This                |
-   |                                |                | statistic is exposed              |
-   |                                |                | for each subnet                   |
-   |                                |                | separately.                       |
-   +--------------------------------+----------------+-----------------------------------+
-   | reclaimed-declined-addresses   | integer        | Number of IPv4                    |
-   |                                |                | addresses that were               |
-   |                                |                | declined, but have                |
-   |                                |                | now been recovered.               |
-   |                                |                | Unlike                            |
-   |                                |                | declined-addresses,               |
-   |                                |                | this statistic never              |
-   |                                |                | decreases. It can be              |
-   |                                |                | used as a long-term               |
-   |                                |                | indicator of how many             |
-   |                                |                | actual valid Declines             |
-   |                                |                | were processed and                |
-   |                                |                | recovered from. This              |
-   |                                |                | is a global statistic             |
-   |                                |                | that covers all                   |
-   |                                |                | subnets.                          |
-   +--------------------------------+----------------+-----------------------------------+
-   | subnet[id].reclaimed           | integer        | Number of IPv4                    |
-   |  -declined-addresses           |                | addresses that were               |
-   |                                |                | declined, but have                |
-   |                                |                | now been recovered.               |
-   |                                |                | Unlike                            |
-   |                                |                | declined-addresses,               |
-   |                                |                | this statistic never              |
-   |                                |                | decreases. It can be              |
-   |                                |                | used as a long-term               |
-   |                                |                | indicator of how many             |
-   |                                |                | actual valid Declines             |
-   |                                |                | were processed and                |
-   |                                |                | recovered from. The               |
-   |                                |                | *id* is the subnet-id             |
-   |                                |                | of a given subnet.                |
-   |                                |                | This statistic is                 |
-   |                                |                | exposed for each                  |
-   |                                |                | subnet separately.                |
-   +--------------------------------+----------------+-----------------------------------+
+   +------------------------------------------+----------------+-----------------------------------+
+   | Statistic                                | Data Type      | Description                       |
+   +==========================================+================+===================================+
+   | pkt4-received                            | integer        | Number of DHCPv4 packets          |
+   |                                          |                | received.  This includes all      |
+   |                                          |                | packets: valid, bogus,            |
+   |                                          |                | corrupted, rejected, etc. This    |
+   |                                          |                | statistic is expected to grow     |
+   |                                          |                | rapidly.                          |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-discover-received                   | integer        | Number of                         |
+   |                                          |                | DHCPDISCOVER packets              |
+   |                                          |                | received. This                    |
+   |                                          |                | statistic is expected             |
+   |                                          |                | to grow; its increase             |
+   |                                          |                | means that clients                |
+   |                                          |                | that just booted                  |
+   |                                          |                | started their                     |
+   |                                          |                | configuration process             |
+   |                                          |                | and their initial                 |
+   |                                          |                | packets reached the               |
+   |                                          |                | Kea server.                       |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-offer-received                      | integer        | Number of DHCPOFFER               |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to remain                |
+   |                                          |                | zero at all times, as             |
+   |                                          |                | DHCPOFFER packets are             |
+   |                                          |                | sent by the server                |
+   |                                          |                | and the server is                 |
+   |                                          |                | never expected to                 |
+   |                                          |                | receive them. A                   |
+   |                                          |                | non-zero value                    |
+   |                                          |                | indicates an error.               |
+   |                                          |                | One likely cause                  |
+   |                                          |                | would be a                        |
+   |                                          |                | misbehaving relay                 |
+   |                                          |                | agent that                        |
+   |                                          |                | incorrectly forwards              |
+   |                                          |                | DHCPOFFER messages                |
+   |                                          |                | towards the server,               |
+   |                                          |                | rather than back to               |
+   |                                          |                | the clients.                      |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-request-received                    | integer        | Number of DHCPREQUEST             |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to grow. Its             |
+   |                                          |                | increase means that               |
+   |                                          |                | clients that just                 |
+   |                                          |                | booted received the               |
+   |                                          |                | server's response                 |
+   |                                          |                | (DHCPOFFER) and                   |
+   |                                          |                | accepted it, and are              |
+   |                                          |                | now requesting an                 |
+   |                                          |                | address                           |
+   |                                          |                | (DHCPREQUEST).                    |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-ack-received                        | integer        | Number of DHCPACK                 |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to remain                |
+   |                                          |                | zero at all times, as             |
+   |                                          |                | DHCPACK packets are               |
+   |                                          |                | sent by the server                |
+   |                                          |                | and the server is                 |
+   |                                          |                | never expected to                 |
+   |                                          |                | receive them. A                   |
+   |                                          |                | non-zero value                    |
+   |                                          |                | indicates an error.               |
+   |                                          |                | One likely cause                  |
+   |                                          |                | would be a                        |
+   |                                          |                | misbehaving relay                 |
+   |                                          |                | agent that                        |
+   |                                          |                | incorrectly forwards              |
+   |                                          |                | DHCPACK messages                  |
+   |                                          |                | towards the server,               |
+   |                                          |                | rather than back to               |
+   |                                          |                | the clients.                      |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-nak-received                        | integer        | Number of DHCPNAK                 |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to remain                |
+   |                                          |                | zero at all times, as             |
+   |                                          |                | DHCPNAK packets are               |
+   |                                          |                | sent by the server                |
+   |                                          |                | and the server is                 |
+   |                                          |                | never expected to                 |
+   |                                          |                | receive them. A                   |
+   |                                          |                | non-zero value                    |
+   |                                          |                | indicates an error.               |
+   |                                          |                | One likely cause                  |
+   |                                          |                | would be a                        |
+   |                                          |                | misbehaving relay                 |
+   |                                          |                | agent that                        |
+   |                                          |                | incorrectly forwards              |
+   |                                          |                | DHCPNAK messages                  |
+   |                                          |                | towards the server,               |
+   |                                          |                | rather than back to               |
+   |                                          |                | the clients.                      |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-release-received                    | integer        | Number of DHCPRELEASE             |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to grow. Its             |
+   |                                          |                | increase means that               |
+   |                                          |                | clients that had an               |
+   |                                          |                | address are shutting              |
+   |                                          |                | down or ceasing to                |
+   |                                          |                | use their addresses.              |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-decline-received                    | integer        | Number of DHCPDECLINE             |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to remain                |
+   |                                          |                | close to zero. Its                |
+   |                                          |                | increase means that a             |
+   |                                          |                | client leased an                  |
+   |                                          |                | address, but                      |
+   |                                          |                | discovered that the               |
+   |                                          |                | address is currently              |
+   |                                          |                | used by an unknown                |
+   |                                          |                | device in the                     |
+   |                                          |                | network.                          |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-inform-received                     | integer        | Number of DHCPINFORM              |
+   |                                          |                | packets received.                 |
+   |                                          |                | This statistic is                 |
+   |                                          |                | expected to grow. Its             |
+   |                                          |                | increase means that               |
+   |                                          |                | there are clients                 |
+   |                                          |                | that either do not                |
+   |                                          |                | need an address or                |
+   |                                          |                | already have an                   |
+   |                                          |                | address and are                   |
+   |                                          |                | interested only in                |
+   |                                          |                | getting additional                |
+   |                                          |                | configuration                     |
+   |                                          |                | parameters.                       |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-unknown-received                    | integer        | Number of packets                 |
+   |                                          |                | received of an                    |
+   |                                          |                | unknown type. A                   |
+   |                                          |                | non-zero value of                 |
+   |                                          |                | this statistic                    |
+   |                                          |                | indicates that the                |
+   |                                          |                | server received a                 |
+   |                                          |                | packet that it wasn't             |
+   |                                          |                | able to recognize,                |
+   |                                          |                | either with an                    |
+   |                                          |                | unsupported type or               |
+   |                                          |                | possibly malformed                |
+   |                                          |                | (without message type             |
+   |                                          |                | option).                          |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-sent                                | integer        | Number of DHCPv4                  |
+   |                                          |                | packets sent. This                |
+   |                                          |                | statistic is expected             |
+   |                                          |                | to grow every time                |
+   |                                          |                | the server transmits              |
+   |                                          |                | a packet. In general,             |
+   |                                          |                | it should roughly                 |
+   |                                          |                | match pkt4-received,              |
+   |                                          |                | as most incoming                  |
+   |                                          |                | packets cause the                 |
+   |                                          |                | server to respond.                |
+   |                                          |                | There are exceptions              |
+   |                                          |                | (e.g. DHCPRELEASE),               |
+   |                                          |                | so do not worry if it             |
+   |                                          |                | is less than                      |
+   |                                          |                | pkt4-received.                    |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-offer-sent                          | integer        | Number of DHCPOFFER               |
+   |                                          |                | packets sent. This                |
+   |                                          |                | statistic is expected             |
+   |                                          |                | to grow in most cases             |
+   |                                          |                | after a DHCPDISCOVER              |
+   |                                          |                | is processed. There               |
+   |                                          |                | are certain uncommon,             |
+   |                                          |                | but valid, cases                  |
+   |                                          |                | where incoming                    |
+   |                                          |                | DHCPDISCOVER packets              |
+   |                                          |                | are dropped, but in               |
+   |                                          |                | general this                      |
+   |                                          |                | statistic is expected             |
+   |                                          |                | to be close to                    |
+   |                                          |                | pkt4-discover-received.           |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-ack-sent                            | integer        | Number of DHCPACK                 |
+   |                                          |                | packets sent. This                |
+   |                                          |                | statistic is expected             |
+   |                                          |                | to grow in most cases             |
+   |                                          |                | after a DHCPREQUEST               |
+   |                                          |                | is processed. There               |
+   |                                          |                | are certain cases                 |
+   |                                          |                | where DHCPNAK is sent             |
+   |                                          |                | instead. In general,              |
+   |                                          |                | the sum of                        |
+   |                                          |                | pkt4-ack-sent and                 |
+   |                                          |                | pkt4-nak-sent should              |
+   |                                          |                | be close to                       |
+   |                                          |                | pkt4-request-received.            |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-nak-sent                            | integer        | Number of DHCPNAK                 |
+   |                                          |                | packets sent. This                |
+   |                                          |                | statistic is expected             |
+   |                                          |                | to grow when the                  |
+   |                                          |                | server chooses not to             |
+   |                                          |                | honor the address                 |
+   |                                          |                | requested by a                    |
+   |                                          |                | client. In general,               |
+   |                                          |                | the sum of                        |
+   |                                          |                | pkt4-ack-sent and                 |
+   |                                          |                | pkt4-nak-sent should              |
+   |                                          |                | be close to                       |
+   |                                          |                | pkt4-request-received.            |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-parse-failed                        | integer        | Number of incoming                |
+   |                                          |                | packets that could                |
+   |                                          |                | not be parsed. A                  |
+   |                                          |                | non-zero value of                 |
+   |                                          |                | this statistic                    |
+   |                                          |                | indicates that the                |
+   |                                          |                | server received a                 |
+   |                                          |                | malformed or                      |
+   |                                          |                | truncated packet.                 |
+   |                                          |                | This may indicate                 |
+   |                                          |                | problems in the                   |
+   |                                          |                | network, faulty                   |
+   |                                          |                | clients, or a bug in              |
+   |                                          |                | the server.                       |
+   +------------------------------------------+----------------+-----------------------------------+
+   | pkt4-receive-drop                        | integer        | Number of incoming                |
+   |                                          |                | packets that were                 |
+   |                                          |                | dropped. The exact                |
+   |                                          |                | reason for dropping               |
+   |                                          |                | packets is logged,                |
+   |                                          |                | but the most common               |
+   |                                          |                | reasons may be: an                |
+   |                                          |                | unacceptable packet               |
+   |                                          |                | type, direct                      |
+   |                                          |                | responses are                     |
+   |                                          |                | forbidden, or the                 |
+   |                                          |                | server-id sent by the             |
+   |                                          |                | client does not match             |
+   |                                          |                | the server's                      |
+   |                                          |                | server-id.                        |
+   +------------------------------------------+----------------+-----------------------------------+
+   | subnet[id].total-addresses               | integer        | 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.              |
+   |                                          |                | The *id* is the                   |
+   |                                          |                | subnet-id of a given              |
+   |                                          |                | subnet. This                      |
+   |                                          |                | statistic is exposed              |
+   |                                          |                | for each subnet                   |
+   |                                          |                | separately, and is                |
+   |                                          |                | reset during a                    |
+   |                                          |                | reconfiguration                   |
+   |                                          |                | event.                            |
+   +------------------------------------------+----------------+-----------------------------------+
+   | subnet[id].cumulative-assigned-addresses | integer        | Cumulative 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 never decreased.              |
+   |                                          |                | The *id* is the subnet-id         |
+   |                                          |                | of the ubnet. This                |
+   |                                          |                | statistic is exposed              |
+   |                                          |                | for each subnet                   |
+   |                                          |                | separately, and is                |
+   |                                          |                | reset during a                    |
+   |                                          |                | reconfiguration                   |
+   |                                          |                | event.                            |
+   +------------------------------------------+----------------+-----------------------------------+
+   | subnet[id].assigned-addresses            | integer        | 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. The *id* is              |
+   |                                          |                | the subnet-id of the              |
+   |                                          |                | subnet. This                      |
+   |                                          |                | statistic is exposed              |
+   |                                          |                | for each subnet                   |
+   |                                          |                | separately, and is                |
+   |                                          |                | reset during a                    |
+   |                                          |                | reconfiguration                   |
+   |                                          |                | event.                            |
+   +------------------------------------------+----------------+-----------------------------------+
+   | reclaimed-leases                         | integer        | Number of expired                 |
+   |                                          |                | leases that have been             |
+   |                                          |                | reclaimed since                   |
+   |                                          |                | server startup. It is             |
+   |                                          |                | incremented each time             |
+   |                                          |                | an expired lease is               |
+   |                                          |                | reclaimed and is                  |
+   |                                          |                | reset when the server             |
+   |                                          |                | is reconfigured.                  |
+   +------------------------------------------+----------------+-----------------------------------+
+   | subnet[id].reclaimed-leases              | integer        | Number of expired                 |
+   |                                          |                | leases associated                 |
+   |                                          |                | with a given subnet               |
+   |                                          |                | (*id* is the                      |
+   |                                          |                | subnet-id) that have              |
+   |                                          |                | been reclaimed since              |
+   |                                          |                | server startup. It is             |
+   |                                          |                | incremented each time             |
+   |                                          |                | an expired lease is               |
+   |                                          |                | reclaimed and is                  |
+   |                                          |                | reset when the server             |
+   |                                          |                | is reconfigured.                  |
+   +------------------------------------------+----------------+-----------------------------------+
+   | declined-addresses                       | integer        | Number of IPv4                    |
+   |                                          |                | addresses that are                |
+   |                                          |                | currently declined; 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 increasing, a                  |
+   |                                          |                | network administrator             |
+   |                                          |                | should investigate                |
+   |                                          |                | whether there is a                |
+   |                                          |                | misbehaving device in             |
+   |                                          |                | the network. This is              |
+   |                                          |                | a global statistic                |
+   |                                          |                | that covers all                   |
+   |                                          |                | subnets.                          |
+   +------------------------------------------+----------------+-----------------------------------+
+   | subnet[id].declined-addresses            | integer        | Number of IPv4                    |
+   |                                          |                | addresses that are                |
+   |                                          |                | currently declined in             |
+   |                                          |                | a given subnet; 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 increasing, a                  |
+   |                                          |                | network administrator             |
+   |                                          |                | should investigate                |
+   |                                          |                | whether there is a                |
+   |                                          |                | misbehaving device in             |
+   |                                          |                | the network. The *id*             |
+   |                                          |                | is the subnet-id of a             |
+   |                                          |                | given subnet. This                |
+   |                                          |                | statistic is exposed              |
+   |                                          |                | for each subnet                   |
+   |                                          |                | separately.                       |
+   +------------------------------------------+----------------+-----------------------------------+
+   | reclaimed-declined-addresses             | integer        | Number of IPv4                    |
+   |                                          |                | addresses that were               |
+   |                                          |                | declined, but have                |
+   |                                          |                | now been recovered.               |
+   |                                          |                | Unlike                            |
+   |                                          |                | declined-addresses,               |
+   |                                          |                | this statistic never              |
+   |                                          |                | decreases. It can be              |
+   |                                          |                | used as a long-term               |
+   |                                          |                | indicator of how many             |
+   |                                          |                | actual valid Declines             |
+   |                                          |                | were processed and                |
+   |                                          |                | recovered from. This              |
+   |                                          |                | is a global statistic             |
+   |                                          |                | that covers all                   |
+   |                                          |                | subnets.                          |
+   +------------------------------------------+----------------+-----------------------------------+
+   | subnet[id].reclaimed-declined-addresses  | integer        | Number of IPv4                    |
+   |                                          |                | addresses that were               |
+   |                                          |                | declined, but have                |
+   |                                          |                | now been recovered.               |
+   |                                          |                | Unlike                            |
+   |                                          |                | declined-addresses,               |
+   |                                          |                | this statistic never              |
+   |                                          |                | decreases. It can be              |
+   |                                          |                | used as a long-term               |
+   |                                          |                | indicator of how many             |
+   |                                          |                | actual valid Declines             |
+   |                                          |                | were processed and                |
+   |                                          |                | recovered from. The               |
+   |                                          |                | *id* is the subnet-id             |
+   |                                          |                | of a given subnet.                |
+   |                                          |                | This statistic is                 |
+   |                                          |                | exposed for each                  |
+   |                                          |                | subnet separately.                |
+   +------------------------------------------+----------------+-----------------------------------+
 
 .. _dhcp4-ctrl-channel:
 
index 6bf4ca11765f8a379cb05f7774c5b9670cdb4f3d..97b49ba5eaeb2f5526eb9a3df7720cd9cbf071a7 100644 (file)
@@ -5198,14 +5198,14 @@ reclaimed-declined-addresses statistics (again in two variants, global
 and subnet-specific) are increased.
 
 A note about statistics: The server does not decrease the
-assigned-addresses statistics when a DHCPDECLINE message is received and
+assigned-nas statistics when a DHCPDECLINE message is received and
 processed successfully. While technically a declined address is no
-longer assigned, the primary usage of the assigned-addresses statistic
+longer assigned, the primary usage of the assigned-nas statistic
 is to monitor pool utilization. Most people would forget to include
 declined-addresses in the calculation, and simply use
-assigned-addresses/total-addresses. This would cause a bias towards
+assigned-nas/total-nas. This would cause a bias towards
 under-representing pool utilization. As this has a potential for major
-issues, ISC decided not to decrease assigned-addresses immediately after
+issues, ISC decided not to decrease assigned-nas immediately after
 receiving DHCPDECLINE, but to do it later when Kea recovers the address
 back to the available pool.
 
@@ -5591,6 +5591,26 @@ The DHCPv6 server supports the following statistics:
    |                                         |                       | reconfiguration        |
    |                                         |                       | event.                 |
    +-----------------------------------------+-----------------------+------------------------+
+   | subnet[id].cumulative-assigned-nas      | integer               | Cumulative number of   |
+   |                                         |                       | NA addresses in a      |
+   |                                         |                       | given subnet that      |
+   |                                         |                       | were assigned. It      |
+   |                                         |                       | increases every time   |
+   |                                         |                       | a new lease is         |
+   |                                         |                       | allocated (as a        |
+   |                                         |                       | result of receiving a  |
+   |                                         |                       | REQUEST message) and   |
+   |                                         |                       | is never decreased.    |
+   |                                         |                       | The *id* is the        |
+   |                                         |                       | subnet-id of a given   |
+   |                                         |                       | subnet. This           |
+   |                                         |                       | statistic is exposed   |
+   |                                         |                       | for each subnet        |
+   |                                         |                       | separately, and is     |
+   |                                         |                       | reset during a         |
+   |                                         |                       | reconfiguration        |
+   |                                         |                       | event.                 |
+   +-----------------------------------------+-----------------------+------------------------+
    | subnet[id].assigned-nas                 | integer               | Number of NA           |
    |                                         |                       | addresses in a given   |
    |                                         |                       | subnet that are        |
@@ -5639,6 +5659,26 @@ The DHCPv6 server supports the following statistics:
    |                                         |                       | reconfiguration        |
    |                                         |                       | event.                 |
    +-----------------------------------------+-----------------------+------------------------+
+   | subnet[id].cumulative-assigned-pds      | integer               | Cumulative number of   |
+   |                                         |                       | PD prefixes in a       |
+   |                                         |                       | given subnet that      |
+   |                                         |                       | were assigned. It      |
+   |                                         |                       | increases every time   |
+   |                                         |                       | a new lease is         |
+   |                                         |                       | allocated (as a        |
+   |                                         |                       | result of receiving a  |
+   |                                         |                       | REQUEST message) and   |
+   |                                         |                       | is never decreased.    |
+   |                                         |                       | The *id* is the        |
+   |                                         |                       | subnet-id of a given   |
+   |                                         |                       | subnet. This           |
+   |                                         |                       | statistic is exposed   |
+   |                                         |                       | for each subnet        |
+   |                                         |                       | separately, and is     |
+   |                                         |                       | reset during a         |
+   |                                         |                       | reconfiguration        |
+   |                                         |                       | event.                 |
+   +-----------------------------------------+-----------------------+------------------------+
    | subnet[id].assigned-pds                 | integer               | Number of PD prefixes  |
    |                                         |                       | in a given subnet      |
    |                                         |                       | that are assigned. It  |
index 3526f6171c9073b8f3cc7457ced921ca27fb1b9b..73228193f24d4675975dfb98f5f6a070d006153b 100644 (file)
@@ -154,6 +154,10 @@ The response to either command will contain three elements:
          DHCPv4 management in the subnet. In other words, this is the
          sum of all addresses in all the configured pools in the subnet.
 
+      - ``cumulative-assigned-addresses`` - the cumulative number of addresses
+        in the subnet that have been assigned to a client by the server
+        since it started.
+
       -  ``assigned-addresses`` - the number of addresses in the subnet that
          are currently assigned to a client.
 
@@ -169,6 +173,10 @@ The response to either command will contain three elements:
          all the NA addresses in all the configured NA pools in the
          subnet.
 
+      - ``cumulative-assigned-nas`` - the cumulative number of NA addresses
+        in the subnet that have been assigned to a client by the server
+        since it started.
+
       -  ``assigned-nas`` - the number of NA addresses in the subnet that
          are currently assigned to a client.
 
@@ -179,6 +187,10 @@ The response to either command will contain three elements:
          management in the subnet. In other words, this is the sum of
          all prefixes in all the configured prefix pools in the subnet.
 
+      - ``cumulative-assigned-pds`` - the cumulative number of prefixes
+        in the subnet that have been assigned to a client by the server
+        since it started.
+
       -  ``assigned-pds`` - the number of prefixes in the subnet that are
          currently assigned to a client.
 
@@ -198,10 +210,10 @@ The response to a DHCPv4 command might look as follows:
        "text": "stat-lease4-get: 2 rows found",
        "arguments": {
          "result-set": {
-           "columns": [ "subnet-id", "total-addresses", "assigned-addresses", "declined-addresses" ]
+           "columns": [ "subnet-id", "total-addresses", "cumulative-assigned-addresses", "assigned-addresses", "declined-addresses" ]
            "rows": [
-             [ 10, 256, 111, 0 ],
-             [ 20, 4098, 2034, 4 ]
+             [ 10, 256, 300, 111, 0 ],
+             [ 20, 4098, 2034, 2034, 4 ]
            ],
          "timestamp": "2018-05-04 15:03:37.000000"
          }
@@ -219,11 +231,11 @@ PD pools):
        "text": "stat-lease6-get: 2 rows found",
        "arguments": {
          "result-set": {
-           "columns": [ "subnet-id", "total-nas", "assigned-nas", "declined-nas", "total-pds", "assigned-pds" ]
+           "columns": [ "subnet-id", "total-nas", "cumulative-assigned-nas", "assigned-nas", "declined-nas", "total-pds", "cumulative-assigned-pds", "assigned-pds" ]
            "rows": [
-             [ 10, 4096, 2400, 3, 0, 0],
-             [ 20, 0, 0, 0, 1048, 233 ]
-             [ 30, 256, 60, 0, 1048, 15 ]
+             [ 10, 4096, 5000, 2400, 3, 0, 0, 0],
+             [ 20, 0, 0, 0, 0, 1048, 300, 233 ]
+             [ 30, 256, 60, 60, 0, 1048, 15, 15 ]
            ],
          "timestamp": "2018-05-04 15:03:37.000000"
          }
index d0057509dc11e77b633a194ba0921da61ff5dde9..b1aa18d15a26fa5723df737eeb5fc910a226a7d9 100644 (file)
@@ -438,8 +438,10 @@ LeaseStatCmdsImpl::makeResultSet4(const ElementPtr& result_wrapper,
     }
 
     // Create the empty result-set.
-    std::vector<std::string>column_labels = { "subnet-id", "total-addreses",
-                                              "assigned-addreses","declined-addreses"};
+    std::vector<std::string>column_labels = { "subnet-id", "total-addresses",
+                                              "cumulative-assigned-addresses",
+                                              "assigned-addresses",
+                                              "declined-addresses" };
     ElementPtr value_rows = createResultSet(result_wrapper, column_labels);
 
     // Get the first query row
@@ -531,8 +533,12 @@ LeaseStatCmdsImpl::makeResultSet6(const ElementPtr& result_wrapper,
 
     // Create the result-set map.
     // labels could be class statics?
-    std::vector<std::string>column_labels = { "subnet-id", "total-nas", "assigned-nas",
-                                              "declined-nas", "total-pds", "assigned-pds"};
+    std::vector<std::string>column_labels = { "subnet-id", "total-nas",
+                                              "cumulative-assigned-nas",
+                                              "assigned-nas",
+                                              "declined-nas", "total-pds",
+                                              "cumulative-assigned-pds",
+                                              "assigned-pds" };
     ElementPtr value_rows = createResultSet(result_wrapper, column_labels);
 
     // Now we can run the stats query.
@@ -634,6 +640,7 @@ LeaseStatCmdsImpl::addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id
     ElementPtr row = Element::createList();
     row->add(Element::create(static_cast<int64_t>(subnet_id)));
     row->add(Element::create(getSubnetStat(subnet_id, "total-addresses")));
+    row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-addresses")));
     row->add(Element::create(assigned));
     row->add(Element::create(declined));
     value_rows->add(row);
@@ -645,9 +652,11 @@ LeaseStatCmdsImpl::addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id
     ElementPtr row = Element::createList();
     row->add(Element::create(static_cast<int64_t>(subnet_id)));
     row->add(Element::create(getSubnetStat(subnet_id, "total-nas")));
+    row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-nas")));
     row->add(Element::create(assigned));
     row->add(Element::create(declined));
     row->add(Element::create(getSubnetStat(subnet_id, "total-pds")));
+    row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-pds")));
     row->add(Element::create(assigned_pds));
     value_rows->add(row);
 }
index 6779a79835150c6d36204ce220811dd542bdcffb..4432f4a9a3390006bb597d03ab662324776eee17 100644 (file)
@@ -167,13 +167,14 @@ A DHCPv4 response might look like this:
         {
         "result-set\": {
            "columns\": [
-                "subnet-id", "total-addreses",
-                "assigned-addreses", "declined-addreses"
+                "subnet-id", "total-addresses",
+                "cumulative-assigned-addresses",
+                "assigned-addresses", "declined-addresses"
            ],
            "rows\": [
-               [ 30, 256, 100, 2 ],
-               [ 40,  16, 0, 0 ],
-               [ 50, 256, 35, 0 ],
+               [ 30, 256, 300, 100, 2 ],
+               [ 40,  16, 5, 0, 0 ],
+               [ 50, 256, 100, 35, 0 ],
            ],
            timestamp\": \"2018-05-04 15:03:37.000000\" }
         }
@@ -185,12 +186,13 @@ and DHCPv6 response might look like this:
         {
         "result-set": {
            "columns": [
-                "subnet-id", "total-nas", "assigned-nas",
-                "declined-nas", "total-pds", "assigned-pds"
+                "subnet-id", "total-nas", "cumulative-assigned-nas"
+                "assigned-nas", "declined-nas", "total-pds",
+                "cumulative-assigned-pds", "assigned-pds"
            ],
            "rows": [
-               [ 30, 16, 6, 0, 65536, 400 ],
-               [ 40, 16777216, 989837, 0, 0, 0 ]
+               [ 30, 16, 20, 6, 0, 65536, 1000, 400 ],
+               [ 40, 16777216, 1100000, 989837, 0, 0, 0, 0 ]
            ],
            "timestamp": "2018-05-04 15:03:37.000000" }
         }
index ce63667fefa85c5c2240b6d30dd2a502fd535abb..80eb0862f683fcfd9ac6b67b6f88ee18994207e0 100644 (file)
@@ -54,9 +54,10 @@ public:
     ///         "result-set": {
     ///             "timestamp": "2018-03-22 09:43:30.815371",
     ///             "columns": ["subnet_id", "total-addresses",
+    ///                         "cumulative-assigned-addresses",
     ///                         "assigned-addresses", "declined-addresses"],
     ///             "rows": [
-    ///                 [1, 600, 450, 3],
+    ///                 [1, 600, 1000, 450, 3],
     ///                 :
     ///             ]
     ///         }
@@ -97,10 +98,12 @@ public:
     ///         "result-set": {
     ///             "timestamp": "2018-03-22 09:43:30.815371",
     ///             "columns": ["subnet_id", "total-nas",
+    ///                         "cumulative-assigned-nas",
     ///                         "assigned-nas", "declined-nas",
-    ///                         "total-pds", "assigned-pds"],
+    ///                         "total-pds", "cumulative-assigned-pds",
+    ///                         "assigned-pds"],
     ///             "rows": [
-    ///                 [1, 600, 450, 3, 64, 10],
+    ///                 [1, 600, 1000, 450, 3, 64, 20, 10],
     ///                 :
     ///             ]
     ///         }
index ae31773602b856dbc3591bcabd650f6f661d5f54..17c8b75c6853f617868e11505741879f3c67c1c5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 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
@@ -17,6 +17,7 @@
 #include <cc/command_interpreter.h>
 #include <cc/data.h>
 #include <cc/data.h>
+#include <stats/stats_mgr.h>
 
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <gtest/gtest.h>
@@ -29,6 +30,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::asiolink;
+using namespace isc::stats;
 using namespace boost::posix_time;
 
 namespace {
@@ -101,7 +103,7 @@ public:
     /// @param exp_result 0 - success, 1 - error, 2 - ...
     /// @param exp_txt expected text response (optional)
     void testCommand(string cmd_txt, int exp_result, string exp_txt,
-                                string exp_result_json = "") {
+                     string exp_result_json = "") {
         // Let's load the library first.
         loadLib();
 
@@ -389,7 +391,8 @@ public:
         cfg_mgr.commit();
 
         // Subnet 10
-        // 2 assigned, 3 declined,  1 expired
+        // 300 cumulative, 2 assigned, 3 declined,  1 expired
+        setSubnetStat(10, "cumulative-assigned-addresses", 300);
         addLease4("192.0.1.1", 10);
         addLease4("192.0.1.2", 10, Lease::STATE_DECLINED);
         addLease4("192.0.1.3", 10, Lease::STATE_DECLINED);
@@ -398,7 +401,8 @@ public:
         addLease4("192.0.1.6", 10, Lease::STATE_EXPIRED_RECLAIMED);
 
         // Subnet 20
-        // 3 assigned, 0 declined,  2 expired
+        // 10 cumulative, 3 assigned, 0 declined,  2 expired
+        setSubnetStat(20, "cumulative-assigned-addresses", 10);
         addLease4("192.0.2.1", 20);
         addLease4("192.0.2.2", 20);
         addLease4("192.0.2.3", 20);
@@ -407,13 +411,15 @@ public:
 
         // Subnet 30 no leases
 
-        // Subnet 40, 4 assigned
+        // Subnet 40, 4 cumulative, 4 assigned
+        setSubnetStat(40, "cumulative-assigned-addresses", 4);
         addLease4("192.0.4.1", 40);
         addLease4("192.0.4.2", 40);
         addLease4("192.0.4.3", 40);
         addLease4("192.0.4.4", 40);
 
-        // Subnet 50, 1 assigned, 1 declined
+        // Subnet 50, 2 cumulative, 1 assigned, 1 declined
+        setSubnetStat(50, "cumulative-assigned-addresses", 2);
         addLease4("192.0.5.1", 50);
         addLease4("192.0.5.2", 50, Lease::STATE_DECLINED);
     }
@@ -465,7 +471,8 @@ public:
 
         cfg_mgr.commit();
 
-        // Subnet 10:  2 assigned NAs, 3 declined NAs, 1 expired NAs
+        // Subnet 10: 10000 cumulative NAs, 2 assigned, 3 declined, 1 expired
+        setSubnetStat(10, "cumulative-assigned-nas", 10000);
         addLease6("2001:db8:1::1", 10);
         addLease6("2001:db8:1::2", 10);
         addLease6("2001:db8:1::3", 10, Lease::STATE_DECLINED);
@@ -473,21 +480,26 @@ public:
         addLease6("2001:db8:1::5", 10, Lease::STATE_DECLINED);
         addLease6("2001:db8:1::6", 10, Lease::STATE_EXPIRED_RECLAIMED);
 
-        // Subnet 20:  3 assigned NAs
+        // Subnet 20: 10 cumulative NAs, 3 assigned
+        setSubnetStat(20, "cumulative-assigned-nas", 10);
         addLease6("2001:db8:2::1", 20);
         addLease6("2001:db8:2::2", 20);
         addLease6("2001:db8:2::3", 20);
 
-        // Subnet 30:  1 assigned NAs, 1 declined NAs, 3 PDs
+        // Subnet 30: 2 cumulative NAs, 1 assigned, 1 declined,
+        // 4 cumulative PDs, 3 assigned
+        setSubnetStat(30, "cumulative-assigned-nas", 2);
         addLease6("2001:db8:3::1", 30);
         addLease6("2001:db8:3::2", 30, Lease::STATE_DECLINED);
+        setSubnetStat(30, "cumulative-assigned-pds", 4);
         addPrefix("3001::1:0", 112, 30);
         addPrefix("3001::2:0", 112, 30);
         addPrefix("3001::3:0", 112, 30);
 
         // Subnet 40:  no leases
 
-        // Subnet 50:  2 PDs
+        // Subnet 50:  1000 cumulative PDs, 2 assigned
+        setSubnetStat(50, "cumulative-assigned-pds", 1000);
         addPrefix("5001::1:0", 112, 50);
         addPrefix("5001::2:0", 112, 50);
     }
@@ -565,6 +577,19 @@ public:
         addLease6(prefix, subnet_id, state, Lease::TYPE_PD, prefix_len);
     }
 
+    /// @brief Creates a statistic
+    ///
+    /// @param subnet_id subnet identifier
+    /// @param name statistic name
+    /// @param value statistic value
+    void setSubnetStat(const SubnetID& subnet_id, const std::string& name,
+                       int64_t value) {
+        StatsMgr& stats_mgr = StatsMgr::instance();
+        const std::string& stats_name =
+            stats_mgr.generateName("subnet", subnet_id, name);
+        stats_mgr.setValue(stats_name, value);
+    }
+
     /// @brief Pointer to the lease manager
     LeaseMgr* lmptr_;
 
@@ -781,15 +806,16 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\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"
+        "       [ 10, 256, 300, 2, 3 ],\n"
+        "       [ 20, 16, 10, 3, 0 ],\n"
+        "       [ 30, 256, 0, 0, 0 ],\n"
+        "       [ 40, 16, 4, 4, 0 ],\n"
+        "       [ 50, 256, 2, 1, 1 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -803,15 +829,16 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\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"
+        "       [ 10, 256, 300, 2, 3 ],\n"
+        "       [ 20, 16, 10, 3, 0 ],\n"
+        "       [ 30, 256, 0, 0, 0 ],\n"
+        "       [ 40, 16, 4, 4, 0 ],\n"
+        "       [ 50, 256, 2, 1, 1 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -828,11 +855,12 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 20, 16, 3, 0 ],\n"
+        "       [ 20, 16, 10, 3, 0 ],\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -852,13 +880,14 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 10, 256, 2, 3 ],\n"
-        "       [ 20,  16, 3, 0 ],\n"
-        "       [ 30, 256, 0, 0 ],\n"
+        "       [ 10, 256, 300, 2, 3 ],\n"
+        "       [ 20, 16, 10, 3, 0 ],\n"
+        "       [ 30, 256, 0, 0, 0 ],\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -878,13 +907,14 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 20,  16, 3, 0 ],\n"
-        "       [ 30, 256, 0, 0 ],\n"
-        "       [ 40,  16, 4, 0 ],\n"
+        "       [ 20, 16, 10, 3, 0 ],\n"
+        "       [ 30, 256, 0, 0, 0 ],\n"
+        "       [ 40, 16, 4, 4, 0 ],\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -904,13 +934,14 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 30, 256, 0, 0 ],\n"
-        "       [ 40,  16, 4, 0 ],\n"
-        "       [ 50, 256, 1, 1 ],\n"
+        "       [ 30, 256, 0, 0, 0 ],\n"
+        "       [ 40, 16, 4, 4, 0 ],\n"
+        "       [ 50, 256, 2, 1, 1 ],\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -930,12 +961,13 @@ TEST_F(StatCmdsTest, statLease4GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-addreses\",\n"
-        "        \"assigned-addreses\", \"declined-addreses\"\n"
+        "        \"subnet-id\", \"total-addresses\",\n"
+        "        \"cumulative-assigned-addresses\",\n"
+        "        \"assigned-addresses\", \"declined-addresses\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 30, 256, 0, 0 ],\n"
-        "       [ 40,  16, 4, 0 ],\n"
+        "       [ 30, 256, 0, 0, 0 ],\n"
+        "       [ 40, 16, 4, 4, 0 ],\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1199,15 +1231,17 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-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"
+        "       [ 10, 65536, 10000, 2, 3, 0, 0, 0 ],\n"
+        "       [ 20, 16777216, 10, 3, 0, 0, 0, 0 ],\n"
+        "       [ 30, 16, 2, 1, 1, 65536, 4, 3 ],\n"
+        "       [ 40, 16777216, 0, 0, 0, 0, 0, 0 ],\n"
+        "       [ 50, 0, 0, 0, 0, 65536, 1000, 2 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1221,15 +1255,17 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-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"
+        "       [ 10, 65536, 10000, 2, 3, 0, 0, 0 ],\n"
+        "       [ 20, 16777216, 10, 3, 0, 0, 0, 0 ],\n"
+        "       [ 30, 16, 2, 1, 1, 65536, 4, 3 ],\n"
+        "       [ 40, 16777216, 0, 0, 0, 0, 0, 0 ],\n"
+        "       [ 50, 0, 0, 0, 0, 65536, 1000, 2 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1246,11 +1282,13 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-pds\", \"assigned-pds\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 20, 16777216, 3, 0, 0, 0 ]\n"
+        "       [ 20, 16777216, 10, 3, 0, 0, 0, 0 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1270,13 +1308,15 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-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"
+        "       [ 10, 65536, 10000, 2, 3, 0, 0, 0 ],\n"
+        "       [ 20, 16777216, 10, 3, 0, 0, 0, 0 ],\n"
+        "       [ 30, 16, 2, 1, 1, 65536, 4, 3 ],\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1296,13 +1336,15 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-pds\", \"assigned-pds\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 20, 16777216, 3, 0, 0, 0 ],\n"
-        "       [ 30, 16, 1, 1, 65536, 3 ],\n"
-        "       [ 40, 16777216, 0, 0, 0, 0 ]\n"
+        "       [ 20, 16777216, 10, 3, 0, 0, 0, 0 ],\n"
+        "       [ 30, 16, 2, 1, 1, 65536, 4, 3 ],\n"
+        "       [ 40, 16777216, 0, 0, 0, 0, 0, 0 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1322,13 +1364,15 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-pds\", \"assigned-pds\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 30, 16, 1, 1, 65536, 3 ],\n"
-        "       [ 40, 16777216, 0, 0, 0, 0 ],\n"
-        "       [ 50, 0, 0, 0, 65536, 2 ]\n"
+        "       [ 30, 16, 2, 1, 1, 65536, 4, 3 ],\n"
+        "       [ 40, 16777216, 0, 0, 0, 0, 0, 0 ],\n"
+        "       [ 50, 0, 0, 0, 0, 65536, 1000, 2 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
@@ -1348,12 +1392,14 @@ TEST_F(StatCmdsTest, statLease6GetValid) {
         "{\n"
         "\"result-set\": {\n"
         "   \"columns\": [\n"
-        "        \"subnet-id\", \"total-nas\", \"assigned-nas\",\n"
-        "        \"declined-nas\", \"total-pds\", \"assigned-pds\"\n"
+        "        \"subnet-id\", \"total-nas\",\n"
+        "        \"cumulative-assigned-nas\", \"assigned-nas\",\n"
+        "        \"declined-nas\", \"total-pds\",\n"
+        "        \"cumulative-assigned-pds\", \"assigned-pds\"\n"
         "   ],\n"
         "   \"rows\": [\n"
-        "       [ 30, 16, 1, 1, 65536, 3 ],\n"
-        "       [ 40, 16777216, 0, 0, 0, 0 ]\n"
+        "       [ 30, 16, 2, 1, 1, 65536, 4, 3 ],\n"
+        "       [ 40, 16777216, 0, 0, 0, 0, 0, 0 ]\n"
         "   ],\n"
         "   \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n"
         "}\n"
index 07004cfcac7ef2a79fddb07ea43c21ec75f35d0a..683fd09e0048b9cbef14a490ee1401f1af0dbc2e 100644 (file)
@@ -1758,6 +1758,12 @@ AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
                                        ctx.currentIA().type_ == Lease::TYPE_NA ?
                                        "assigned-nas" : "assigned-pds"),
                 static_cast<int64_t>(1));
+            StatsMgr::instance().addValue(
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       ctx.currentIA().type_ == Lease::TYPE_NA ?
+                                       "cumulative-assigned-nas" :
+                                       "cumulative-assigned-pds"),
+                static_cast<int64_t>(1));
         }
     }
 
@@ -1858,6 +1864,12 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx,
                                            ctx.currentIA().type_ == Lease::TYPE_NA ?
                                            "assigned-nas" : "assigned-pds"),
                     static_cast<int64_t>(1));
+                StatsMgr::instance().addValue(
+                    StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                           ctx.currentIA().type_ == Lease::TYPE_NA ?
+                                           "cumulative-assigned-nas" :
+                                           "cumulative-assigned-pds"),
+                    static_cast<int64_t>(1));
             }
 
             return (lease);
@@ -2139,6 +2151,12 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
                                        ctx.currentIA().type_ == Lease::TYPE_NA ?
                                        "assigned-nas" : "assigned-pds"),
                 static_cast<int64_t>(1));
+            StatsMgr::instance().addValue(
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       ctx.currentIA().type_ == Lease::TYPE_NA ?
+                                       "cumulative-assigned-nas" :
+                                       "cumulative-assigned-pds"),
+                static_cast<int64_t>(1));
         }
 
     } else {
@@ -2192,6 +2210,12 @@ AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases
                                            ctx.currentIA().type_ == Lease::TYPE_NA ?
                                            "assigned-nas" : "assigned-pds"),
                     static_cast<int64_t>(1));
+                StatsMgr::instance().addValue(
+                    StatsMgr::generateName("subnet", lease->subnet_id_,
+                                           ctx.currentIA().type_ == Lease::TYPE_NA ?
+                                           "cumulative-assigned-nas" :
+                                           "cumulative-assigned-pds"),
+                    static_cast<int64_t>(1));
             }
         }
 
@@ -3666,7 +3690,12 @@ AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr,
 
             // The lease insertion succeeded, let's bump up the statistic.
             StatsMgr::instance().addValue(
-                StatsMgr::generateName("subnet", ctx.subnet_->getID(), "assigned-addresses"),
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       "assigned-addresses"),
+                static_cast<int64_t>(1));
+            StatsMgr::instance().addValue(
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       "cumulative-assigned-addresses"),
                 static_cast<int64_t>(1));
 
             return (lease);
@@ -3776,7 +3805,12 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
         // We need to account for the re-assignment of The lease.
         if (ctx.old_lease_->expired() || ctx.old_lease_->state_ == Lease::STATE_EXPIRED_RECLAIMED) {
             StatsMgr::instance().addValue(
-                StatsMgr::generateName("subnet", ctx.subnet_->getID(), "assigned-addresses"),
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       "assigned-addresses"),
+                static_cast<int64_t>(1));
+            StatsMgr::instance().addValue(
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       "cumulative-assigned-addresses"),
                 static_cast<int64_t>(1));
         }
     }
@@ -3874,7 +3908,12 @@ AllocEngine::reuseExpiredLease4(Lease4Ptr& expired,
 
         // We need to account for the re-assignment of The lease.
         StatsMgr::instance().addValue(
-                StatsMgr::generateName("subnet", ctx.subnet_->getID(), "assigned-addresses"),
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       "assigned-addresses"),
+                static_cast<int64_t>(1));
+        StatsMgr::instance().addValue(
+                StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+                                       "cumulative-assigned-addresses"),
                 static_cast<int64_t>(1));
     }
 
index 1a936210e984e0e93f3e67952d479f2645e9382f..d2d26e285370fc07a80048f37a6d4f3d553471ac 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 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
@@ -484,6 +484,9 @@ CfgSubnets4::removeStatistics() {
         stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
                                              "assigned-addresses"));
 
+        stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+                                             "cumulative-assigned-addresses"));
+
         stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
                                              "declined-addresses"));
 
@@ -509,6 +512,11 @@ CfgSubnets4::updateStatistics() {
                                         static_cast<int64_t>
                                         ((*subnet4)->getPoolCapacity(Lease::
                                                                      TYPE_V4)));
+        const std::string& name =
+            StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-addresses");
+        if (!stats_mgr.getObservation(name)) {
+            stats_mgr.setValue(name, static_cast<int64_t>(0));
+        }
     }
 
     // Only recount the stats if we have subnets.
index 852262c18335974d23556c2a768d55cebc60f0af..91769cc654471f8f6d7539beecb5423afe358565 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 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
@@ -395,11 +395,17 @@ CfgSubnets6::removeStatistics() {
         stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
                                              "assigned-nas"));
 
+        stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+                                             "cumulative-assigned-nas"));
+
         stats_mgr.del(StatsMgr::generateName("subnet", subnet_id, "total-pds"));
 
         stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
                                              "assigned-pds"));
 
+        stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+                                             "cumulative-assigned-pds"));
+
         stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
                                              "declined-addresses"));
 
@@ -430,6 +436,18 @@ CfgSubnets6::updateStatistics() {
                                                   "total-pds"),
                             static_cast<int64_t>
                             ((*subnet6)->getPoolCapacity(Lease::TYPE_PD)));
+
+        const std::string& name_nas =
+            StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-nas");
+        if (!stats_mgr.getObservation(name_nas)) {
+            stats_mgr.setValue(name_nas, static_cast<int64_t>(0));
+        }
+
+        const std::string& name_pds =
+            StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-pds");
+        if (!stats_mgr.getObservation(name_pds)) {
+            stats_mgr.setValue(name_pds, static_cast<int64_t>(0));
+        }
     }
 
     // Only recount the stats if we have subnets.
index d717fb6e5b95366779052958d5005f5ba580d51b..9547a29b3f2328d12616addd5391201b19c3a62c 100644 (file)
@@ -71,6 +71,10 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
     // Assigned addresses should be zero.
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
+
     AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
                                     false, true, "somehost.example.com.", false);
     ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
@@ -94,6 +98,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
 
     // Assigned addresses should have incremented.
     EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
 
     // Second allocation starts here.
     uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
@@ -130,6 +137,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
 
     // Assigned addresses should have incremented.
     EXPECT_TRUE(testStatistics("assigned-addresses", 2, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
 }
 
 // This test checks that simple allocation uses the default valid lifetime.
@@ -331,6 +341,10 @@ TEST_F(AllocEngine4Test, fakeAlloc4) {
     // Assigned addresses should be zero.
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
+
     AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
                                     IOAddress("0.0.0.0"), false, true,
                                     "host.example.com.", true);
@@ -353,6 +367,8 @@ TEST_F(AllocEngine4Test, fakeAlloc4) {
 
     // Assigned addresses should still be zero.
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-addresses", subnet_->getID()));
 }
 
 
@@ -529,6 +545,8 @@ TEST_F(AllocEngine4Test, simpleRenew4) {
     ASSERT_TRUE(engine);
 
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
 
     AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
                                     false, true, "somehost.example.com.", false);
@@ -545,6 +563,9 @@ TEST_F(AllocEngine4Test, simpleRenew4) {
 
     // We should have incremented assigned-addresses
     EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
 
     // Do it again, this should amount to the renew of an existing lease
     Lease4Ptr lease2 = engine->allocateLease4(ctx);
@@ -558,6 +579,8 @@ TEST_F(AllocEngine4Test, simpleRenew4) {
 
     // Should NOT have bumped assigned-addresses
     EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
 }
 
 // This test checks simple renewal uses the default valid lifetime.
@@ -1689,6 +1712,8 @@ TEST_F(AllocEngine4Test, requestReuseExpiredLease4) {
     IOAddress addr("192.0.2.105");
 
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
 
@@ -1736,6 +1761,9 @@ TEST_F(AllocEngine4Test, requestReuseExpiredLease4) {
     // added the lease directly, assigned-leases never bumped to one, so when we
     // reclaim it gets decremented to -1, then on assignment back to 0.
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 1));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID()));
 }
@@ -1795,6 +1823,8 @@ TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4Stats) {
     subnet_->addPool(pool_);
     cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
     cfg_mgr.commit(); // so we will recalc stats
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
 
     // Now create a declined lease, decline it and rewind its cltt, so it
     // is expired.
@@ -1807,6 +1837,8 @@ TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4Stats) {
 
     // Check that the stats declined stats were not modified
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-addresses", subnet_->getID()));
     EXPECT_TRUE(testStatistics("declined-addresses", 0));
     EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0));
     EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()));
@@ -1866,6 +1898,8 @@ TEST_F(AllocEngine4Test, requestReuseDeclinedLease4Stats) {
     subnet_->addPool(pool_);
     cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
     cfg_mgr.commit();
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
 
     // Now create a declined lease, decline it and rewind its cltt, so it
     // is expired.
@@ -1882,6 +1916,9 @@ TEST_F(AllocEngine4Test, requestReuseDeclinedLease4Stats) {
     // when it is reused.  Declined address stats will be -1 since
     // lease was created as declined which does not increment the stat.
     EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
     EXPECT_TRUE(testStatistics("declined-addresses", -1));
     EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1));
     EXPECT_TRUE(testStatistics("declined-addresses", -1, subnet_->getID()));
@@ -2901,6 +2938,8 @@ TEST_F(AllocEngine4Test, simpleAlloc4Stats) {
     string name = StatsMgr::generateName("subnet", subnet_->getID(),
                                          "assigned-addresses");
     StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
 
     Lease4Ptr lease = engine->allocateLease4(ctx);
     // The new lease has been allocated, so the old lease should not exist.
@@ -2913,6 +2952,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4Stats) {
     ObservationPtr stat = StatsMgr::instance().getObservation(name);
     ASSERT_TRUE(stat);
     EXPECT_EQ(101, stat->getInteger().first);
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
 }
 
 // This test checks if the fake allocation (for DHCPDISCOVER) can succeed
@@ -2932,6 +2974,8 @@ TEST_F(AllocEngine4Test, fakeAlloc4Stat) {
     string name = StatsMgr::generateName("subnet", subnet_->getID(),
                                          "assigned-addresses");
     StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
 
     Lease4Ptr lease = engine->allocateLease4(ctx);
 
@@ -2946,6 +2990,8 @@ TEST_F(AllocEngine4Test, fakeAlloc4Stat) {
     ObservationPtr stat = StatsMgr::instance().getObservation(name);
     ASSERT_TRUE(stat);
     EXPECT_EQ(100, stat->getInteger().first);
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-addresses", subnet_->getID()));
 }
 
 // This test checks that the allocated-addresses statistic is decreased when
@@ -2974,6 +3020,8 @@ TEST_F(AllocEngine4Test, reservedAddressExistingLeaseStat) {
     string name = StatsMgr::generateName("subnet", subnet_->getID(),
                                          "assigned-addresses");
     StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
+    int64_t cumulative = getStatistics("cumulative-assigned-addresses",
+                                       subnet_->getID());
 
     // Request allocation of the reserved address.
     AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
@@ -2992,6 +3040,9 @@ TEST_F(AllocEngine4Test, reservedAddressExistingLeaseStat) {
     ObservationPtr stat = StatsMgr::instance().getObservation(name);
     ASSERT_TRUE(stat);
     EXPECT_EQ(100, stat->getInteger().first);
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",
+                               cumulative, subnet_->getID()));
 
     // Lets' double check that the actual allocation took place.
     EXPECT_FALSE(ctx.fake_allocation_);
index f68679c5bae724fa01da88568e83b5a2b67cebb7..cc1931fdfe61b40ba2a6db1d85dc9b1e53d3a8c1 100644 (file)
@@ -87,6 +87,11 @@ TEST_F(AllocEngine6Test, constructor) {
 TEST_F(AllocEngine6Test, simpleAlloc6) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     simpleAlloc6Test(pool_, IOAddress("::"), false);
 
     // We should have bumped the assigned counter by 1
@@ -104,6 +109,9 @@ TEST_F(AllocEngine6Test, simpleAlloc6) {
 
     // We should have bumped the assigned counter by 2
     EXPECT_TRUE(testStatistics("assigned-nas", 2, subnet_->getID()));
+    cumulative += 2;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 }
 
 // This test checks that simple allocation uses default lifetimes.
@@ -132,10 +140,17 @@ TEST_F(AllocEngine6Test, pdSimpleAlloc6) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-pds", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned prefixes.
+    int64_t cumulative = getStatistics("cumulative-assigned-pds",
+                                       subnet_->getID());
+
     simpleAlloc6Test(pd_pool_, IOAddress("::"), false);
 
     // We should have bumped the assigned counter by 1
     EXPECT_TRUE(testStatistics("assigned-pds", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-pds",
+                               cumulative, subnet_->getID()));
 }
 
 // This test checks if the fake allocation (for SOLICIT) can succeed
@@ -144,10 +159,16 @@ TEST_F(AllocEngine6Test, fakeAlloc6) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     simpleAlloc6Test(pool_, IOAddress("::"), true);
 
     // We should not have bumped the assigned counter.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-nas", subnet_->getID()));
 }
 
 // This test checks if the fake PD allocation (for SOLICIT) can succeed
@@ -156,10 +177,16 @@ TEST_F(AllocEngine6Test, pdFakeAlloc6) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-pds", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned prefixes.
+    int64_t cumulative = getStatistics("cumulative-assigned-pds",
+                                       subnet_->getID());
+
     simpleAlloc6Test(pd_pool_, IOAddress("::"), true);
 
     // We should not have bumped the assigned counter
     EXPECT_TRUE(testStatistics("assigned-pds", 0, subnet_->getID()));
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-pds", subnet_->getID()));
 }
 
 // This test checks if the allocation with a hint that is valid (in range,
@@ -871,6 +898,10 @@ TEST_F(AllocEngine6Test, solicitReuseExpiredLease6) {
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     // Just a different duid
     DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
     const uint32_t other_iaid = 3568;
@@ -911,6 +942,8 @@ TEST_F(AllocEngine6Test, solicitReuseExpiredLease6) {
 
     // Verify the none of relevant stats were altered.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-nas", subnet_->getID()));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
 }
@@ -1115,6 +1148,8 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
     subnet_->addPool(pool_);
     cfg_mgr.getStagingCfg()->getCfgSubnets6()->add(subnet_);
     cfg_mgr.commit();
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
 
     // Let's create an expired lease
     DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
@@ -1124,6 +1159,7 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
     Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
                                501, 502, other_subnetid, HWAddrPtr(),
                                0));
+    int64_t other_cumulative = getStatistics("cumulative-assigned-nas", other_subnetid);
 
     lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
     lease->valid_lft_ = 495; // Lease was valid for 495 seconds
@@ -1167,7 +1203,12 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) {
 
     // Verify the stats got adjusted correctly
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
     EXPECT_TRUE(testStatistics("assigned-nas", -1, other_subnetid));
+    EXPECT_EQ(other_cumulative,
+              getStatistics("cumulative-assigned-nas", other_subnetid));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 1));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 1, other_subnetid));
@@ -1795,12 +1836,19 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     // Client gets an address
     Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false);
     ASSERT_TRUE(lease1);
 
     // We should have bumped the address counter
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 
     // Just check that if the client requests again, it will get the same
     // address.
@@ -1810,6 +1858,8 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
 
     // We should not have bumped the address counter again
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 
     // Now admin creates a reservation for this client. This is in-pool
     // reservation, as the pool is 2001:db8:1::10 - 2001:db8:1::20.
@@ -1842,6 +1892,9 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) {
     // Lastly check to see that the address counter is still 1, we should have
     // have decremented it on the implied release and incremented it on the reserved
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 }
 // In the following situation:
 // - client X is assigned an address A
@@ -1855,12 +1908,19 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     // Client gets an address
     Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false);
     ASSERT_TRUE(lease1);
 
     // We should have bumped the address counter
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 
     // Just check that if the client requests again, it will get the same
     // address.
@@ -1870,6 +1930,8 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
 
     // We should not have bumped the address counter again
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 
     // Now admin creates a reservation for this client. Let's use the
     // address client X just received. Let's generate a host, but don't add it
@@ -1907,6 +1969,9 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) {
     // Lastly check to see that the address counter is still 1 we should have
     // have decremented it on the implied release and incremented it on the reserved
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
 }
 
 // Checks that a reserved address for client A is not assigned when
@@ -2533,6 +2598,9 @@ TEST_F(AllocEngine6Test, solicitReuseDeclinedLease6Stats) {
     EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()));
     EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
 
     // Now create a declined lease, decline it and rewind its cltt, so it
     // is expired.
@@ -2545,6 +2613,8 @@ TEST_F(AllocEngine6Test, solicitReuseDeclinedLease6Stats) {
 
     // Check that the stats were not modified
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+    EXPECT_EQ(cumulative,
+              getStatistics("cumulative-assigned-nas", subnet_->getID()));
     EXPECT_TRUE(testStatistics("declined-addresses", 0));
     EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0));
     EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()));
@@ -2572,6 +2642,10 @@ TEST_F(AllocEngine6Test, requestReuseDeclinedLease6Stats) {
     EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()));
     EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     // Now create a declined lease, decline it and rewind its cltt, so it
     // is expired.
     Lease6Ptr declined = generateDeclinedLease(addr_txt, 100, -10);
@@ -2588,6 +2662,9 @@ TEST_F(AllocEngine6Test, requestReuseDeclinedLease6Stats) {
     // doesn't increment it from zero.  reclaimed-declined-addresses will be 1
     // because the leases are implicitly reclaimed before they can be assigned.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
     EXPECT_TRUE(testStatistics("declined-addresses", -1));
     EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1));
     EXPECT_TRUE(testStatistics("declined-addresses", -1, subnet_->getID()));
@@ -2620,6 +2697,10 @@ TEST_F(AllocEngine6Test, reuseReclaimedExpiredViaRequest) {
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
 
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet_->getID());
+
     // Let's create an expired lease
     Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid_,
                                501, 502, subnet_->getID(), HWAddrPtr(),
@@ -2659,6 +2740,9 @@ TEST_F(AllocEngine6Test, reuseReclaimedExpiredViaRequest) {
     // Verify assigned-nas got bumped.  Reclaimed stats should still
     // be zero as we artificially marked it reclaimed.
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet_->getID()));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0));
     EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()));
 }
@@ -3048,6 +3132,10 @@ TEST_F(SharedNetworkAlloc6Test, requestSharedNetworkReservationsNoColl) {
 // the client is assigned a reserved address from a shared network which
 // replaces existing lease within this shared network.
 TEST_F(SharedNetworkAlloc6Test, requestSharedNetworkExistingLeases) {
+    // Get the cumulative count of assigned addresses.
+    int64_t cumulative = getStatistics("cumulative-assigned-nas",
+                                       subnet2_->getID());
+
     // Create a lease in subnet 2 for this client. The lease is in expired
     // reclaimed state initially to allow for checking whether the lease
     // gets renewed.
@@ -3074,6 +3162,9 @@ TEST_F(SharedNetworkAlloc6Test, requestSharedNetworkExistingLeases) {
 
     // Statistics should be bumped when the lease is re-assigned.
     EXPECT_TRUE(testStatistics("assigned-nas", 1, subnet2_->getID()));
+    cumulative += 1;
+    EXPECT_TRUE(testStatistics("cumulative-assigned-nas",
+                               cumulative, subnet2_->getID()));
 
     // Another interesting case is when there is a reservation in a different
     // subnet than the one from which the ease has been assigned.
index 2a40d25c1c012504f4d7c240a33f08d120aa225c..e459ad0389c41aaf680a010ea112671d68f5a543 100644 (file)
@@ -67,6 +67,20 @@ bool testStatistics(const std::string& stat_name, const int64_t exp_value,
     return (false);
 }
 
+int64_t getStatistics(const std::string& stat_name, const SubnetID subnet_id) {
+    try {
+        std::string name = (subnet_id == SUBNET_ID_UNUSED ? stat_name :
+                            StatsMgr::generateName("subnet", subnet_id, stat_name));
+        ObservationPtr observation = StatsMgr::instance().getObservation(name);
+        if (observation) {
+            return (observation->getInteger().first);
+        }
+    } catch (...) {
+        ;
+    }
+    return (0);
+}
+
 void
 AllocEngine4Test::testReuseLease4(const AllocEnginePtr& engine,
                                   Lease4Ptr& existing_lease,
index 4a198f39dcab8edac87e2f3c27a88024c6c4b67c..28dc70ac0689f9dd7aa71e609bf80c3d44b2c773 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2020 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
@@ -46,6 +46,17 @@ namespace test {
 bool testStatistics(const std::string& stat_name, const int64_t exp_value,
                     const SubnetID subnet_id = SUBNET_ID_UNUSED);
 
+/// @brief Get a value held by statistic manager.
+///
+/// This function may be used in some allocation tests and there's no
+/// single base class for it. @todo consider moving it src/lib/util.
+///
+/// @param stat_name Statistic name.
+/// @param subnet_id subnet_id of the desired subnet, if not zero.
+/// @return the value held by the statistic manager or zero.
+int64_t getStatistics(const std::string& stat_name,
+                      const SubnetID subnet_id = SUBNET_ID_UNUSED);
+
 /// @brief Allocation engine with some internal methods exposed
 class NakedAllocEngine : public AllocEngine {
 public: