summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bin/admin/tests/data/lease4_dump_test.reference.csv8
-rw-r--r--src/bin/admin/tests/data/lease6_dump_test.reference.csv8
-rw-r--r--src/bin/admin/tests/memfile_tests.sh.in8
-rw-r--r--src/bin/admin/tests/mysql_tests.sh.in30
-rw-r--r--src/bin/admin/tests/pgsql_tests.sh.in12
-rw-r--r--src/bin/dhcp4/dhcp4_srv.cc22
-rw-r--r--src/bin/dhcp6/dhcp6_srv.cc33
-rw-r--r--src/bin/dhcp6/tests/fqdn_unittest.cc14
-rw-r--r--src/bin/lfc/tests/lfc_controller_unittests.cc42
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc10
-rw-r--r--src/hooks/dhcp/lease_cmds/lease_cmds.cc409
-rw-r--r--src/lib/dhcp/tests/option6_pdexclude_unittest.cc1
-rw-r--r--src/lib/dhcpsrv/alloc_engine.cc377
-rw-r--r--src/lib/dhcpsrv/cfg_option.cc2
-rw-r--r--src/lib/dhcpsrv/cfg_subnets4.cc42
-rw-r--r--src/lib/dhcpsrv/cfg_subnets6.cc90
-rw-r--r--src/lib/dhcpsrv/csv_lease_file4.cc13
-rw-r--r--src/lib/dhcpsrv/csv_lease_file4.h7
-rw-r--r--src/lib/dhcpsrv/csv_lease_file6.cc15
-rw-r--r--src/lib/dhcpsrv/csv_lease_file6.h6
-rw-r--r--src/lib/dhcpsrv/flq_allocator.cc14
-rw-r--r--src/lib/dhcpsrv/iterative_allocator.cc4
-rw-r--r--src/lib/dhcpsrv/lease.cc34
-rw-r--r--src/lib/dhcpsrv/lease.h5
-rw-r--r--src/lib/dhcpsrv/lease_mgr.cc118
-rw-r--r--src/lib/dhcpsrv/memfile_lease_mgr.h8
-rw-r--r--src/lib/dhcpsrv/memfile_lease_storage.h67
-rw-r--r--src/lib/dhcpsrv/mysql_lease_mgr.cc130
-rw-r--r--src/lib/dhcpsrv/parsers/dhcp_parsers.cc7
-rw-r--r--src/lib/dhcpsrv/pgsql_lease_mgr.cc171
-rw-r--r--src/lib/dhcpsrv/pool.cc5
-rw-r--r--src/lib/dhcpsrv/pool.h36
-rw-r--r--src/lib/dhcpsrv/random_allocator.cc8
-rw-r--r--src/lib/dhcpsrv/subnet.cc48
-rw-r--r--src/lib/dhcpsrv/subnet.h7
-rw-r--r--src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc19
-rw-r--r--src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc42
-rw-r--r--src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc62
-rw-r--r--src/lib/dhcpsrv/tests/lease_unittest.cc31
-rw-r--r--src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc323
-rw-r--r--src/lib/dhcpsrv/tests/pool_unittest.cc49
-rw-r--r--src/share/database/scripts/mysql/dhcpdb_create.mysql460
-rw-r--r--src/share/database/scripts/mysql/dhcpdb_drop.mysql8
-rw-r--r--src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_012_to_013.sh.in2
-rw-r--r--src/share/database/scripts/mysql/upgrade_017_to_018.sh.in450
-rw-r--r--src/share/database/scripts/mysql/wipe_data.sh.in2
-rw-r--r--src/share/database/scripts/pgsql/dhcpdb_create.pgsql464
-rw-r--r--src/share/database/scripts/pgsql/dhcpdb_drop.pgsql17
-rw-r--r--src/share/database/scripts/pgsql/upgrade_016_to_017.sh.in464
-rw-r--r--src/share/database/scripts/pgsql/wipe_data.sh.in2
52 files changed, 3552 insertions, 662 deletions
diff --git a/src/bin/admin/tests/data/lease4_dump_test.reference.csv b/src/bin/admin/tests/data/lease4_dump_test.reference.csv
index 265b81b10b..05eb50cce9 100644
--- a/src/bin/admin/tests/data/lease4_dump_test.reference.csv
+++ b/src/bin/admin/tests/data/lease4_dump_test.reference.csv
@@ -1,4 +1,4 @@
-address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
-0.0.0.10,32:30,33:30,40,1642000000,50,1,1,one.example.com,0,
-0.0.0.11,,31:32:33,40,1643210000,50,1,1,,1,{ }
-0.0.0.12,32:32,,40,1643212345,50,1,1,three&#x2cexample&#x2ccom,2,{ "a": 1&#x2c "b": "c" }
+address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id
+0.0.0.10,32:30,33:30,40,1642000000,50,1,1,one.example.com,0,,0
+0.0.0.11,,31:32:33,40,1643210000,50,1,1,,1,{ },0
+0.0.0.12,32:32,,40,1643212345,50,1,1,three&#x2cexample&#x2ccom,2,{ "a": 1&#x2c "b": "c" },0
diff --git a/src/bin/admin/tests/data/lease6_dump_test.reference.csv b/src/bin/admin/tests/data/lease6_dump_test.reference.csv
index 39c443bdb1..74fe733abf 100644
--- a/src/bin/admin/tests/data/lease6_dump_test.reference.csv
+++ b/src/bin/admin/tests/data/lease6_dump_test.reference.csv
@@ -1,4 +1,4 @@
-address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source
-::10,32:30:33,30,1642000000,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16
-::11,32:31:33,30,1643210000,40,50,1,60,70,1,1,,38:30,1,{ },90,1
-::12,32:32:33,30,1643212345,40,50,1,60,70,1,1,three&#x2cexample&#x2ccom,38:30,2,{ "a": 1&#x2c "b": "c" },90,4
+address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id
+::10,32:30:33,30,1642000000,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16,0
+::11,32:31:33,30,1643210000,40,50,1,60,70,1,1,,38:30,1,{ },90,1,0
+::12,32:32:33,30,1643212345,40,50,1,60,70,1,1,three&#x2cexample&#x2ccom,38:30,2,{ "a": 1&#x2c "b": "c" },90,4,0
diff --git a/src/bin/admin/tests/memfile_tests.sh.in b/src/bin/admin/tests/memfile_tests.sh.in
index 24483bf9e9..ce090ee734 100644
--- a/src/bin/admin/tests/memfile_tests.sh.in
+++ b/src/bin/admin/tests/memfile_tests.sh.in
@@ -57,21 +57,21 @@ incomplete_memfile_header_v6() {
# Print the entire header for v4.
memfile_header_v4() {
- printf '%s,state,user_context' "$(incomplete_memfile_header_v4)"
+ printf '%s,state,user_context,pool_id' "$(incomplete_memfile_header_v4)"
}
# Print the entire header for v6.
memfile_header_v6() {
- printf '%s,hwaddr,state,user_context,hwtype,hwaddr_source' "$(incomplete_memfile_header_v6)"
+ printf '%s,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id' "$(incomplete_memfile_header_v6)"
}
# Print data copied from mysql_upgrade_12_to_13_test and pgsql_upgrade_7_0_to_8_0.
# @{
memfile_data_v4() {
- printf '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{"a":1&#x2c"b":2}'
+ printf '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{"a":1&#x2c"b":2},0'
}
memfile_data_v6() {
- printf '::10,32:30:33,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{"a":1&#x2c"b":2},90,16'
+ printf '::10,32:30:33,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{"a":1&#x2c"b":2},90,16,0'
}
# @}
diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in
index a3ac113275..08a029f107 100644
--- a/src/bin/admin/tests/mysql_tests.sh.in
+++ b/src/bin/admin/tests/mysql_tests.sh.in
@@ -344,47 +344,47 @@ mysql_upgrade_12_to_13_test() {
# Check lease4Dump*().
run_command \
- mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,(SELECT FROM_UNIXTIME(1678900000)),50,1,1,'one,example,com',0,'{ \"a\": 1, \"b\": 2 }',NULL,NULL);"
+ mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,(SELECT FROM_UNIXTIME(1678900000)),50,1,1,'one,example,com',0,'{ \"a\": 1, \"b\": 2 }',NULL,NULL,0);"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease4 failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
run_command \
mysql_execute "CALL lease4DumpHeader();"
assert_eq 0 "${EXIT_CODE}" 'lease4DumpHeader() failed, expected exit code %d, actual %d'
- assert_str_eq 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context' "${OUTPUT}"
+ assert_str_eq 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id' "${OUTPUT}"
run_command \
mysql_execute "CALL lease4DumpData();"
assert_eq 0 "${EXIT_CODE}" 'lease4DumpData() failed, expected exit code %d, actual %d'
output=$(printf '%s' "${OUTPUT}" | sed 's/\t/,/g') # turn tabs into commas
- assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{ "a": 1&#x2c "b": 2 }' "${output}"
+ assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{ "a": 1&#x2c "b": 2 },0' "${output}"
# Check lease6Dump*().
run_command \
- mysql_execute "INSERT INTO lease6 VALUES('::10',20,30,(SELECT FROM_UNIXTIME(1678900000)),40,50,1,60,70,1,1,'one,example,com',80,90,16,0,'{ \"a\": 1, \"b\": 2 }',NULL);"
+ mysql_execute "INSERT INTO lease6 VALUES('::10',20,30,(SELECT FROM_UNIXTIME(1678900000)),40,50,1,60,70,1,1,'one,example,com',80,90,16,0,'{ \"a\": 1, \"b\": 2 }',NULL,0);"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease6 failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
run_command \
mysql_execute "CALL lease6DumpHeader();"
assert_eq 0 "${EXIT_CODE}" 'lease6DumpHeader() failed, expected exit code %d, actual %d'
- assert_str_eq 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source' "${OUTPUT}"
+ assert_str_eq 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id' "${OUTPUT}"
run_command \
mysql_execute "CALL lease6DumpData();"
assert_eq 0 "${EXIT_CODE}" 'lease6DumpData() failed, expected exit code %d, actual %d'
output=$(printf '%s' "${OUTPUT}" | sed 's/\t/,/g') # turn tabs into commas
- assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{ "a": 1&#x2c "b": 2 },90,16' "${output}"
+ assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{ "a": 1&#x2c "b": 2 },90,16,0' "${output}"
# Check lease4Upload().
run_command \
- mysql_execute "CALL lease4Upload('192.0.0.0','ff0102030405','01ff0102030405',7200,1234567890,1,0,0,'',0,'');"
+ mysql_execute "CALL lease4Upload('192.0.0.0','ff0102030405','01ff0102030405',7200,1234567890,1,0,0,'',0,'',0);"
assert_eq 0 "${EXIT_CODE}" 'lease4Upload() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
# Check lease6Upload().
run_command \
- mysql_execute "CALL lease6Upload('2001:db8::','000100012955cb80ff0102030407',7200,1234567890,1,3600,0,1,128,0,0,'','ff0102030407',0,'',90,16);"
+ mysql_execute "CALL lease6Upload('2001:db8::','000100012955cb80ff0102030407',7200,1234567890,1,3600,0,1,128,0,0,'','ff0102030407',0,'',90,16,0);"
assert_eq 0 "${EXIT_CODE}" 'lease6Upload() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
}
@@ -771,7 +771,7 @@ mysql_upgrade_17_to_18_test() {
run_statement "hosts_255_long_dhcp_identifier" "$qry"
#lease6 duid should support 130 long strings.
- qry="insert into lease6 values('::10',12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,NULL);"
+ qry="insert into lease6 values('::10',12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,NULL,0);"
run_statement "lease6_130_long_duid" "$qry"
#lease6 new binaddr column.
@@ -1520,9 +1520,9 @@ mysql_lease4_dump_test() {
# Insert the reference record
insert_sql="\
-insert into lease4 values(10,20,30,40,(SELECT FROM_UNIXTIME(1642000000)),50,1,1,'one.example.com',0,NULL,NULL,NULL);
-insert into lease4 values(11,NULL,123,40,(SELECT FROM_UNIXTIME(1643210000)),50,1,1,'',1,'{ }',NULL,NULL);\
-insert into lease4 values(12,22,NULL,40,(SELECT FROM_UNIXTIME(1643212345)),50,1,1,'three,example,com',2,'{ \"a\": 1, \"b\": \"c\" }',NULL,NULL);"
+insert into lease4 values(10,20,30,40,(SELECT FROM_UNIXTIME(1642000000)),50,1,1,'one.example.com',0,NULL,NULL,NULL,0);
+insert into lease4 values(11,NULL,123,40,(SELECT FROM_UNIXTIME(1643210000)),50,1,1,'',1,'{ }',NULL,NULL,0);\
+insert into lease4 values(12,22,NULL,40,(SELECT FROM_UNIXTIME(1643212345)),50,1,1,'three,example,com',2,'{ \"a\": 1, \"b\": \"c\" }',NULL,NULL,0);"
run_command \
mysql_execute "$insert_sql"
@@ -1583,9 +1583,9 @@ mysql_lease6_dump_test() {
# Insert the reference record
insert_sql="\
-insert into lease6 values('::10',203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,NULL);\
-insert into lease6 values('::11',213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }',NULL);\
-insert into lease6 values('::12',223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',NULL);"
+insert into lease6 values('::10',203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,NULL,0);\
+insert into lease6 values('::11',213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }',NULL,0);\
+insert into lease6 values('::12',223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',NULL,0);"
run_command \
mysql_execute "$insert_sql"
diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in
index 5ae313fc8f..8087ef57ca 100644
--- a/src/bin/admin/tests/pgsql_tests.sh.in
+++ b/src/bin/admin/tests/pgsql_tests.sh.in
@@ -381,12 +381,12 @@ pgsql_upgrade_7_0_to_8_0_test() {
run_command \
pgsql_execute "SELECT * FROM lease4DumpHeader();"
assert_eq 0 "${EXIT_CODE}" 'lease4DumpHeader() failed, expected exit code %d, actual %d'
- assert_str_eq 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context' "${OUTPUT}"
+ assert_str_eq 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id' "${OUTPUT}"
run_command \
pgsql_execute "SELECT * FROM lease4DumpData();" --field-separator=','
assert_eq 0 "${EXIT_CODE}" 'lease4DumpData() failed, expected exit code %d, actual %d'
- assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{ "a": 1&#x2c "b": 2 }' "${OUTPUT}"
+ assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{ "a": 1&#x2c "b": 2 },0' "${OUTPUT}"
# Check lease6Dump*().
run_command \
@@ -397,22 +397,22 @@ pgsql_upgrade_7_0_to_8_0_test() {
run_command \
pgsql_execute "SELECT * FROM lease6DumpHeader();"
assert_eq 0 "${EXIT_CODE}" 'lease6DumpHeader() failed, expected exit code %d, actual %d'
- assert_str_eq 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source' "${OUTPUT}"
+ assert_str_eq 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id' "${OUTPUT}"
run_command \
pgsql_execute "SELECT * FROM lease6DumpData();" --field-separator=','
assert_eq 0 "${EXIT_CODE}" 'lease6DumpData() failed, expected exit code %d, actual %d'
- assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{ "a": 1&#x2c "b": 2 },16,0' "${OUTPUT}"
+ assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{ "a": 1&#x2c "b": 2 },16,0,0' "${OUTPUT}"
# Check lease4Upload().
run_command \
- pgsql_execute "SELECT lease4Upload('192.0.0.0','ff0102030405','01ff0102030405',7200,1234567890,1,0,0,'',0,'');"
+ pgsql_execute "SELECT lease4Upload('192.0.0.0','ff0102030405','01ff0102030405',7200,1234567890,1,0,0,'',0,'',0);"
assert_eq 0 "${EXIT_CODE}" 'lease4Upload() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
# Check lease6Upload().
run_command \
- pgsql_execute "SELECT lease6Upload('2001:db8::','000100012955cb80ff0102030407',7200,1234567890,1,3600,0,1,128,0,0,'','ff0102030407',0,'',90,16);"
+ pgsql_execute "SELECT lease6Upload('2001:db8::','000100012955cb80ff0102030407',7200,1234567890,1,3600,0,1,128,0,0,'','ff0102030407',0,'',90,16,0);"
assert_eq 0 "${EXIT_CODE}" 'lease6Upload() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
}
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index cc8606dcc3..a771d0563c 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -3658,6 +3658,17 @@ Dhcpv4Srv::processRelease(Pkt4Ptr& release, AllocEngine::ClientContext4Ptr& cont
StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-addresses"),
static_cast<int64_t>(-1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(), "assigned-addresses")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
// Remove existing DNS entries for the lease, if any.
queueNCR(CHG_REMOVE, lease);
}
@@ -3819,6 +3830,17 @@ Dhcpv4Srv::declineLease(const Lease4Ptr& lease, const Pkt4Ptr& decline,
StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
static_cast<int64_t>(1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(), "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
// Global declined addresses counter.
StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 63efc5d866..4ccd2e36b0 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -3266,6 +3266,17 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-nas"),
static_cast<int64_t>(-1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_NA, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(), "assigned-nas")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
// Check if a lease has flags indicating that the FQDN update has
// been performed. If so, create NameChangeRequest which removes
// the entries.
@@ -3462,6 +3473,17 @@ Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-pds"),
static_cast<int64_t>(-1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_PD, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pd-pool", pool->getID(), "assigned-pds")),
+ static_cast<int64_t>(-1));
+ }
+ }
}
}
@@ -4045,6 +4067,17 @@ Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
static_cast<int64_t>(1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_NA, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(), "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
// Global declined addresses counter.
StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
diff --git a/src/bin/dhcp6/tests/fqdn_unittest.cc b/src/bin/dhcp6/tests/fqdn_unittest.cc
index 2e88fb5247..95f683b384 100644
--- a/src/bin/dhcp6/tests/fqdn_unittest.cc
+++ b/src/bin/dhcp6/tests/fqdn_unittest.cc
@@ -384,7 +384,7 @@ public:
// Context flags are normally set during lease allocation. Since that
// hasn't occurred we'll set them here to match the expected values.
// Call createNameChangeRequests
- ctx.fwd_dns_update_ = exp_fwd.value_;
+ ctx.fwd_dns_update_ = exp_fwd.value_;
ctx.rev_dns_update_ = exp_rev.value_;
ASSERT_NO_THROW(srv_->createNameChangeRequests(answer, ctx));
if (exp_fwd.value_ || exp_rev.value_) {
@@ -422,13 +422,13 @@ public:
"{ \"interfaces-config\": { \n"
" \"interfaces\": [ \"eth0\" ] \n"
"}, \n"
- "\"valid-lifetime\": 4000, \n"
+ "\"valid-lifetime\": 4000, \n"
"\"preferred-lifetime\": 3000, \n"
- "\"rebind-timer\": 2000, \n"
- "\"renew-timer\": 1000, \n"
- "\"subnet6\": [ { \n"
+ "\"rebind-timer\": 2000, \n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { \n"
" \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ], \n"
- " \"subnet\": \"2001:db8:1::/48\", \n"
+ " \"subnet\": \"2001:db8:1::/48\", \n"
" \"interface\": \"eth0\" \n"
" } ], \n"
"\"dhcp-ddns\": { \n"
@@ -665,7 +665,7 @@ public:
const PoolCollection& pool_col = subnet_->getPools(type);
ASSERT_EQ(pool_idx + 1, pool_col.size());
- PoolPtr pool = (subnet_->getPools(type)).at(pool_idx);
+ PoolPtr pool = (subnet_->getPools(type)).at(pool_idx);
ASSERT_TRUE(pool);
pool_ = boost::dynamic_pointer_cast<Pool6>(pool);
ASSERT_TRUE(pool);
diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc
index b5439b00c6..a2a42d99b3 100644
--- a/src/bin/lfc/tests/lfc_controller_unittests.cc
+++ b/src/bin/lfc/tests/lfc_controller_unittests.cc
@@ -84,12 +84,12 @@ protected:
cstr_ = base_dir + "/" + "config_file"; // config
v4_hdr_ = "address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
v6_hdr_ = "address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n";
+ "hwtype,hwaddr_source,pool_id\n";
// and remove any outstanding test files
removeTestFile();
@@ -399,28 +399,28 @@ TEST_F(LFCControllerTest, launch4) {
// We have several entries for different leases, the naming is:
// <lease letter>_<version#>
string a_1 = "192.0.2.1,06:07:08:09:0a:bc,,"
- "200,200,8,1,1,host.example.com,1,\n";
+ "200,200,8,1,1,host.example.com,1,,0\n";
string a_2 = "192.0.2.1,06:07:08:09:0a:bc,,"
- "200,500,8,1,1,host.example.com,1,\n";
+ "200,500,8,1,1,host.example.com,1,,0\n";
string a_3 = "192.0.2.1,06:07:08:09:0a:bc,,"
- "200,800,8,1,1,host.example.com,1,{ \"foo\": true }\n";
+ "200,800,8,1,1,host.example.com,1,{ \"foo\": true },0\n";
string b_1 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,100,7,0,0,,1,{ \"bar\": false }\n";
+ "100,100,7,0,0,,1,{ \"bar\": false },0\n";
string b_2 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,135,7,0,0,,1,\n";
+ "100,135,7,0,0,,1,,0\n";
string b_3 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,150,7,0,0,,1,\n";
+ "100,150,7,0,0,,1,,0\n";
// This one should be invalid, no hardware address or client id
// and state is not declined
string c_1 = "192.0.2.3,,,"
- "200,200,8,1,1,host.example.com,0,\n";
+ "200,200,8,1,1,host.example.com,0,,0\n";
string d_1 = "192.0.2.5,16:17:18:19:1a:bc,,"
- "200,200,8,1,1,host.example.com,1,\n";
+ "200,200,8,1,1,host.example.com,1,,0\n";
string d_2 = "192.0.2.5,16:17:18:19:1a:bc,,"
- "0,200,8,1,1,host.example.com,1,\n";
+ "0,200,8,1,1,host.example.com,1,,0\n";
// Subtest 1: both previous and copy available.
// Create the test previous file
@@ -555,29 +555,29 @@ TEST_F(LFCControllerTest, launch6) {
// We have several entries for different leases, the naming is:
// <lease letter>_<version#>.
string a_1 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,\n";
+ "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n";
string a_2 = "2001:db8:1::1,,200,200,8,100,0,7,0,1,1,"
- "host.example.com,,1,,,\n";
+ "host.example.com,,1,,,,0\n";
string a_3 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "200,400,8,100,0,7,0,1,1,host.example.com,,1,,,\n";
+ "200,400,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n";
string a_4 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"0,200,8,100,0,7,0,1,1,host.example.com,,1,"
- "{ \"foo\": true },,\n";
+ "{ \"foo\": true },,,0\n";
string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,300,6,150,0,8,0,0,0,,,1,{ \"bar\": false },,\n";
+ "300,300,6,150,0,8,0,0,0,,,1,{ \"bar\": false },,,0\n";
string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,800,6,150,0,8,0,0,0,,,1,,,\n";
+ "300,800,6,150,0,8,0,0,0,,,1,,,,0\n";
string b_3 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,1000,6,150,0,8,0,0,0,,,1,,,\n";
+ "300,1000,6,150,0,8,0,0,0,,,1,,,,0\n";
string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "100,200,8,0,2,16,64,0,0,,,1,,,\n";
+ "100,200,8,0,2,16,64,0,0,,,1,,,,0\n";
string c_2 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "100,400,8,0,2,16,64,0,0,,,1,,,\n";
+ "100,400,8,0,2,16,64,0,0,,,1,,,,0\n";
string d_1 = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "200,600,8,100,0,7,0,1,1,host.example.com,,1,,,\n";
+ "200,600,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n";
// Subtest 1: bot previous and copy available
// Create the test previous file
diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
index d017906b4c..f0c286ea83 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
@@ -2928,7 +2928,7 @@ TEST_F(HAServiceTest, recurringHeartbeatControlResultUnauthorized) {
// This test verifies that IPv4 leases can be fetched from the peer and inserted
// or updated in the local lease database.
-TEST_F(HAServiceTest, asyncSyncLeases) {
+TEST_F(HAServiceTest, asyncSyncLeases4) {
// Create lease manager.
ASSERT_NO_THROW(LeaseMgrFactory::create("universe=4 type=memfile persist=false"));
@@ -3047,7 +3047,7 @@ TEST_F(HAServiceTest, asyncSyncLeases) {
// This test verifies that IPv4 leases can be fetched from the peer and inserted
// or updated in the local lease database.
-TEST_F(HAServiceTest, asyncSyncLeasesAuthorized) {
+TEST_F(HAServiceTest, asyncSyncLeases4Authorized) {
// Update config to provide authentication.
user2_ = "foo";
password2_ = "bar";
@@ -3176,7 +3176,7 @@ TEST_F(HAServiceTest, asyncSyncLeasesAuthorized) {
// Test that there is no exception thrown during leases synchronization
// when server returns a wrong answer.
-TEST_F(HAServiceTest, asyncSyncLeasesWrongAnswer) {
+TEST_F(HAServiceTest, asyncSyncLeases4WrongAnswer) {
// Create lease manager.
ASSERT_NO_THROW(LeaseMgrFactory::create("universe=4 type=memfile persist=false"));
@@ -3214,7 +3214,7 @@ TEST_F(HAServiceTest, asyncSyncLeasesWrongAnswer) {
// Test that there is no exception thrown during leases synchronization
// when servers are offline.
-TEST_F(HAServiceTest, asyncSyncLeasesServerOffline) {
+TEST_F(HAServiceTest, asyncSyncLeases4ServerOffline) {
// Create HA configuration.
HAConfigPtr config_storage = createValidConfiguration();
// Setting the heartbeat delay to 0 disables the recurring heartbeat.
@@ -3232,7 +3232,7 @@ TEST_F(HAServiceTest, asyncSyncLeasesServerOffline) {
// Test that there is no exception thrown during leases synchronization
// when servers require not provided authentication.
-TEST_F(HAServiceTest, asyncSyncLeasesServerUnauthorized) {
+TEST_F(HAServiceTest, asyncSyncLeases4ServerUnauthorized) {
// Instruct servers to require authentication.
factory2_->getResponseCreator()->addBasicAuth("foo", "bar");
factory3_->getResponseCreator()->addBasicAuth("test", "1234");
diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc
index 38540fe784..c488c85569 100644
--- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc
+++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc
@@ -480,14 +480,36 @@ LeaseCmdsImpl::updateStatsOnAdd(const Lease4Ptr& lease) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ PoolPtr pool;
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
if (lease->stateDeclined()) {
- StatsMgr::instance().addValue("declined-addresses", int64_t(1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
}
}
}
@@ -499,14 +521,38 @@ LeaseCmdsImpl::updateStatsOnAdd(const Lease6Ptr& lease) {
StatsMgr::generateName("subnet", lease->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ PoolPtr pool;
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ lease->type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+ }
+
if (lease->stateDeclined()) {
- StatsMgr::instance().addValue("declined-addresses", int64_t(1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
}
}
}
@@ -515,38 +561,86 @@ void
LeaseCmdsImpl::updateStatsOnUpdate(const Lease4Ptr& existing,
const Lease4Ptr& lease) {
if (!existing->stateExpiredReclaimed()) {
+ ConstSubnet4Ptr subnet;
+ PoolPtr pool;
+
// old lease is non expired-reclaimed
if (existing->subnet_id_ != lease->subnet_id_) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", existing->subnet_id_,
"assigned-addresses"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(existing->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(Lease::TYPE_V4, existing->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(-1));
+ }
+ }
}
+
if (existing->stateDeclined()) {
// old lease is declined
- StatsMgr::instance().addValue("declined-addresses", int64_t(-1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", existing->subnet_id_,
"declined-addresses"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(-1));
+ }
}
+
+ pool.reset();
+
if (!lease->stateExpiredReclaimed()) {
// new lease is non expired-reclaimed
if (existing->subnet_id_ != lease->subnet_id_) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
}
+
if (lease->stateDeclined()) {
// new lease is declined
- StatsMgr::instance().addValue("declined-addresses", int64_t(1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
}
}
} else {
@@ -556,15 +650,37 @@ LeaseCmdsImpl::updateStatsOnUpdate(const Lease4Ptr& existing,
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ PoolPtr pool;
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
if (lease->stateDeclined()) {
// new lease is declined
- StatsMgr::instance().addValue("declined-addresses", int64_t(1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
}
}
}
@@ -574,23 +690,52 @@ void
LeaseCmdsImpl::updateStatsOnUpdate(const Lease6Ptr& existing,
const Lease6Ptr& lease) {
if (!existing->stateExpiredReclaimed()) {
+ ConstSubnet6Ptr subnet;
+ PoolPtr pool;
+
// old lease is non expired-reclaimed
if (existing->subnet_id_ != lease->subnet_id_) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", existing->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(existing->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(existing->type_, existing->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(existing->type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ existing->type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(-1));
+ }
+ }
}
+
if (existing->stateDeclined()) {
// old lease is declined
- StatsMgr::instance().addValue("declined-addresses", int64_t(-1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", existing->subnet_id_,
"declined-addresses"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(-1));
+ }
}
+
+ pool.reset();
+
if (!lease->stateExpiredReclaimed()) {
// new lease is non expired-reclaimed
if (existing->subnet_id_ != lease->subnet_id_) {
@@ -598,16 +743,39 @@ LeaseCmdsImpl::updateStatsOnUpdate(const Lease6Ptr& existing,
StatsMgr::generateName("subnet", lease->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ lease->type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+ }
}
+
if (lease->stateDeclined()) {
// new lease is declined
- StatsMgr::instance().addValue("declined-addresses", int64_t(1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
}
}
} else {
@@ -618,15 +786,39 @@ LeaseCmdsImpl::updateStatsOnUpdate(const Lease6Ptr& existing,
StatsMgr::generateName("subnet", lease->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ PoolPtr pool;
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ lease->type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+ }
+
if (lease->stateDeclined()) {
// new lease is declined
- StatsMgr::instance().addValue("declined-addresses", int64_t(1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(1));
+ }
}
}
}
@@ -638,14 +830,36 @@ LeaseCmdsImpl::updateStatsOnDelete(const Lease4Ptr& lease) {
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-addresses"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ PoolPtr pool;
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
if (lease->stateDeclined()) {
- StatsMgr::instance().addValue("declined-addresses", int64_t(-1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(-1));
+ }
}
}
}
@@ -657,14 +871,38 @@ LeaseCmdsImpl::updateStatsOnDelete(const Lease6Ptr& lease) {
StatsMgr::generateName("subnet", lease->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ PoolPtr pool;
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ lease->type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
if (lease->stateDeclined()) {
- StatsMgr::instance().addValue("declined-addresses", int64_t(-1));
+ StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"declined-addresses"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(-1));
+ }
}
}
}
@@ -1998,18 +2236,35 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "assigned-addresses"),
- int64_t(0));
+ static_cast<int64_t>(0));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "declined-addresses"),
- int64_t(0));
+ static_cast<int64_t>(0));
+
+ auto const& sub = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(id);
+ if (sub) {
+ for (const auto& pool : sub->getPools(Lease::TYPE_V4)) {
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(0));
+
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(0));
+ }
+ }
StatsMgr::instance().addValue("declined-addresses", -previous_declined);
} else {
// Wipe them all!
ConstSrvConfigPtr config = CfgMgr::instance().getCurrentCfg();
ConstCfgSubnets4Ptr subnets = config->getCfgSubnets4();
- const Subnet4Collection * subs = subnets->getAll();
+ const Subnet4Collection* subs = subnets->getAll();
// Go over all subnets and wipe leases in each of them.
for (auto sub : *subs) {
@@ -2017,14 +2272,28 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
ids << " " << sub->getID();
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(), "assigned-addresses"),
- int64_t(0));
+ static_cast<int64_t>(0));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(), "declined-addresses"),
- int64_t(0));
+ static_cast<int64_t>(0));
+
+ for (const auto& pool : sub->getPools(Lease::TYPE_V4)) {
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(0));
+
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(0));
+ }
}
- StatsMgr::instance().setValue("declined-addresses", int64_t(0));
+ StatsMgr::instance().setValue("declined-addresses", static_cast<int64_t>(0));
}
stringstream tmp;
@@ -2083,22 +2352,47 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "assigned-nas" ),
- int64_t(0));
+ static_cast<int64_t>(0));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "assigned-pds"),
- int64_t(0));
+ static_cast<int64_t>(0));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "declined-addresses"),
- int64_t(0));
+ static_cast<int64_t>(0));
+
+ auto const& sub = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(id);
+ if (sub) {
+ for (const auto& pool : sub->getPools(Lease::TYPE_NA)) {
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-nas")),
+ static_cast<int64_t>(0));
+
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(0));
+ }
+
+ for (const auto& pool : sub->getPools(Lease::TYPE_PD)) {
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "assigned-pds")),
+ static_cast<int64_t>(0));
+ }
+ }
StatsMgr::instance().addValue("declined-addresses", -previous_declined);
- } else {
+ } else {
// Wipe them all!
ConstSrvConfigPtr config = CfgMgr::instance().getCurrentCfg();
ConstCfgSubnets6Ptr subnets = config->getCfgSubnets6();
- const Subnet6Collection * subs = subnets->getAll();
+ const Subnet6Collection* subs = subnets->getAll();
// Go over all subnets and wipe leases in each of them.
for (auto sub : *subs) {
@@ -2106,18 +2400,40 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
ids << " " << sub->getID();
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(), "assigned-nas" ),
- int64_t(0));
+ static_cast<int64_t>(0));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(), "assigned-pds"),
- int64_t(0));
+ static_cast<int64_t>(0));
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", sub->getID(), "declined-addresses"),
- int64_t(0));
+ static_cast<int64_t>(0));
+
+ for (const auto& pool : sub->getPools(Lease::TYPE_NA)) {
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-nas")),
+ static_cast<int64_t>(0));
+
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(0));
+ }
+
+ for (const auto& pool : sub->getPools(Lease::TYPE_PD)) {
+ StatsMgr::instance().setValue(
+ StatsMgr::generateName("subnet", sub->getID(),
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "assigned-pds")),
+ static_cast<int64_t>(0));
+ }
}
- StatsMgr::instance().setValue("declined-addresses", int64_t(0));
+ StatsMgr::instance().setValue("declined-addresses", static_cast<int64_t>(0));
}
stringstream tmp;
@@ -2462,8 +2778,7 @@ LeaseCmds::leaseWriteHandler(CalloutHandle& handle) {
return (impl_->leaseWriteHandler(handle));
}
-LeaseCmds::LeaseCmds()
- :impl_(new LeaseCmdsImpl()) {
+LeaseCmds::LeaseCmds() : impl_(new LeaseCmdsImpl()) {
}
} // end of namespace lease_cmds
diff --git a/src/lib/dhcp/tests/option6_pdexclude_unittest.cc b/src/lib/dhcp/tests/option6_pdexclude_unittest.cc
index edc2293d37..cfafe8b413 100644
--- a/src/lib/dhcp/tests/option6_pdexclude_unittest.cc
+++ b/src/lib/dhcp/tests/option6_pdexclude_unittest.cc
@@ -11,7 +11,6 @@
#include <asiolink/io_address.h>
#include <exceptions/exceptions.h>
#include <dhcp/option6_pdexclude.h>
-#include <dhcpsrv/pool.h>
#include <util/buffer.h>
#include <util/encode/hex.h>
#include <gtest/gtest.h>
diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc
index f2e87015d9..ef2e7c06f9 100644
--- a/src/lib/dhcpsrv/alloc_engine.cc
+++ b/src/lib/dhcpsrv/alloc_engine.cc
@@ -1525,6 +1525,18 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx,
"assigned-nas" : "assigned-pds"),
static_cast<int64_t>(-1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(candidate->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(ctx.currentIA().type_, candidate->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ? ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ? "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
// In principle, we could trigger a hook here, but we will do this
// only if we get serious complaints from actual users. We want the
// conflict resolution procedure to really work and user libraries
@@ -1572,6 +1584,18 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx,
"assigned-nas" : "assigned-pds"),
static_cast<int64_t>(-1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(candidate->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(candidate->type_, candidate->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(candidate->type_ == Lease::TYPE_NA ? ".pool" : ".pd-pool", pool->getID(),
+ candidate->type_ == Lease::TYPE_NA ? "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
// Add this to the list of removed leases.
ctx.currentIA().old_leases_.push_back(candidate);
@@ -1643,6 +1667,18 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx,
"assigned-nas" : "assigned-pds"),
static_cast<int64_t>(-1));
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId((*lease)->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(ctx.currentIA().type_, (*lease)->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ? ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ? "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(-1));
+ }
+ }
+
/// @todo: Probably trigger a hook here
// Add this to the list of removed leases.
@@ -1771,15 +1807,34 @@ 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"),
+ "cumulative-assigned-nas" : "cumulative-assigned-pds"),
static_cast<int64_t>(1));
+
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_,expired->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "cumulative-assigned-nas" : "cumulative-assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+
StatsMgr::instance().addValue(ctx.currentIA().type_ == Lease::TYPE_NA ?
- "cumulative-assigned-nas" :
- "cumulative-assigned-pds",
+ "cumulative-assigned-nas" : "cumulative-assigned-pds",
static_cast<int64_t>(1));
}
}
@@ -1942,15 +1997,34 @@ 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"),
+ "cumulative-assigned-nas" : "cumulative-assigned-pds"),
static_cast<int64_t>(1));
+
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "cumulative-assigned-nas" : "cumulative-assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+
StatsMgr::instance().addValue(ctx.currentIA().type_ == Lease::TYPE_NA ?
- "cumulative-assigned-nas" :
- "cumulative-assigned-pds",
+ "cumulative-assigned-nas" : "cumulative-assigned-pds",
static_cast<int64_t>(1));
}
@@ -2117,9 +2191,22 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
// Need to decrease statistic for assigned addresses.
StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", ctx.subnet_->getID(), "assigned-nas"),
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds"),
static_cast<int64_t>(-1));
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+
// Add it to the removed leases list.
ctx.currentIA().old_leases_.push_back(lease);
@@ -2254,15 +2341,34 @@ 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"),
+ "cumulative-assigned-nas" : "cumulative-assigned-pds"),
static_cast<int64_t>(1));
+
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "cumulative-assigned-nas" : "cumulative-assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+
StatsMgr::instance().addValue(ctx.currentIA().type_ == Lease::TYPE_NA ?
- "cumulative-assigned-nas" :
- "cumulative-assigned-pds",
+ "cumulative-assigned-nas" : "cumulative-assigned-pds",
static_cast<int64_t>(1));
}
@@ -2333,15 +2439,34 @@ 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"),
+ "cumulative-assigned-nas" : "cumulative-assigned-pds"),
static_cast<int64_t>(1));
+
+ const auto& pool = ctx.subnet_->getPool(ctx.currentIA().type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "assigned-nas" : "assigned-pds")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ StatsMgr::generateName(ctx.currentIA().type_ == Lease::TYPE_NA ?
+ ".pool" : ".pd-pool", pool->getID(),
+ ctx.currentIA().type_ == Lease::TYPE_NA ?
+ "cumulative-assigned-nas" : "cumulative-assigned-pds")),
+ static_cast<int64_t>(1));
+ }
+
StatsMgr::instance().addValue(ctx.currentIA().type_ == Lease::TYPE_NA ?
- "cumulative-assigned-nas" :
- "cumulative-assigned-pds",
+ "cumulative-assigned-nas" : "cumulative-assigned-pds",
static_cast<int64_t>(1));
}
}
@@ -2753,25 +2878,60 @@ AllocEngine::reclaimExpiredLease(const Lease6Ptr& lease,
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"assigned-nas"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "assigned-nas")),
+ static_cast<int64_t>(-1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "reclaimed-leases")),
+ static_cast<int64_t>(1));
+ }
+ }
} else if (lease->type_ == Lease::TYPE_PD) {
// IA_PD
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"assigned-pds"),
- int64_t(-1));
+ static_cast<int64_t>(-1));
- }
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pd-pool" , pool->getID(),
+ "assigned-pds")),
+ static_cast<int64_t>(-1));
- // Increase total number of reclaimed leases.
- StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pd-pool" , pool->getID(),
+ "reclaimed-leases")),
+ static_cast<int64_t>(1));
+ }
+ }
+ }
// Increase number of reclaimed leases for a subnet.
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ // Increase total number of reclaimed leases.
+ StatsMgr::instance().addValue("reclaimed-leases", static_cast<int64_t>(1));
}
void
@@ -2851,16 +3011,34 @@ AllocEngine::reclaimExpiredLease(const Lease4Ptr& lease,
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"assigned-addresses"),
- int64_t(-1));
-
- // Increase total number of reclaimed leases.
- StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
+ static_cast<int64_t>(-1));
// Increase number of reclaimed leases for a subnet.
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
- int64_t(1));
+ static_cast<int64_t>(1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(-1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "reclaimed-leases")),
+ static_cast<int64_t>(1));
+ }
+ }
+
+ // Increase total number of reclaimed leases.
+ StatsMgr::instance().addValue("reclaimed-leases", static_cast<int64_t>(1));
}
void
@@ -2924,16 +3102,34 @@ AllocEngine::reclaimDeclined(const Lease4Ptr& lease) {
// Decrease subnet specific counter for currently declined addresses
stats_mgr.addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
- "declined-addresses"), static_cast<int64_t>(-1));
+ "declined-addresses"),
+ static_cast<int64_t>(-1));
+
+ stats_mgr.addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
+ "reclaimed-declined-addresses"),
+ static_cast<int64_t>(1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ stats_mgr.addValue(StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(-1));
+
+ stats_mgr.addValue(StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "reclaimed-declined-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
// Decrease global counter for declined addresses
stats_mgr.addValue("declined-addresses", static_cast<int64_t>(-1));
stats_mgr.addValue("reclaimed-declined-addresses", static_cast<int64_t>(1));
- stats_mgr.addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
- "reclaimed-declined-addresses"), static_cast<int64_t>(1));
-
// Note that we do not touch assigned-addresses counters. Those are
// modified in whatever code calls this method.
return (true);
@@ -2978,16 +3174,34 @@ AllocEngine::reclaimDeclined(const Lease6Ptr& lease) {
// Decrease subnet specific counter for currently declined addresses
stats_mgr.addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
- "declined-addresses"), static_cast<int64_t>(-1));
+ "declined-addresses"),
+ static_cast<int64_t>(-1));
+
+ stats_mgr.addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
+ "reclaimed-declined-addresses"),
+ static_cast<int64_t>(1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(lease->type_, lease->addr_, false);
+ if (pool) {
+ stats_mgr.addValue(StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "declined-addresses")),
+ static_cast<int64_t>(-1));
+
+ stats_mgr.addValue(StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool" , pool->getID(),
+ "reclaimed-declined-addresses")),
+ static_cast<int64_t>(-1));
+ }
+ }
// Decrease global counter for declined addresses
stats_mgr.addValue("declined-addresses", static_cast<int64_t>(-1));
stats_mgr.addValue("reclaimed-declined-addresses", static_cast<int64_t>(1));
- stats_mgr.addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
- "reclaimed-declined-addresses"), static_cast<int64_t>(1));
-
// Note that we do not touch assigned-nas counters. Those are
// modified in whatever code calls this method.
@@ -3615,8 +3829,7 @@ AllocEngine::discoverLease4(AllocEngine::ClientContext4& ctx) {
.arg(ctx.currentHost()->getIPv4Reservation().toText())
.arg(ctx.conflicting_lease_ ? ctx.conflicting_lease_->toText() :
"(no lease info)");
- StatsMgr::instance().addValue(StatsMgr::generateName(
- "subnet",
+ StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
ctx.conflicting_lease_->subnet_id_,
"v4-reservation-conflicts"),
static_cast<int64_t>(1));
@@ -3877,6 +4090,18 @@ AllocEngine::requestLease4(AllocEngine::ClientContext4& ctx) {
StatsMgr::generateName("subnet", client_lease->subnet_id_,
"assigned-addresses"),
static_cast<int64_t>(-1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(client_lease->subnet_id_);
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, client_lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(-1));
+ }
+ }
}
}
@@ -4074,10 +4299,30 @@ AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr,
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));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(ctx.subnet_->getID());
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
StatsMgr::instance().addValue("cumulative-assigned-addresses",
static_cast<int64_t>(1));
@@ -4182,16 +4427,36 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease4(lease);
- // We need to account for the re-assignment of The 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"),
static_cast<int64_t>(1));
+
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", ctx.subnet_->getID(),
"cumulative-assigned-addresses"),
static_cast<int64_t>(1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(ctx.subnet_->getID());
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
StatsMgr::instance().addValue("cumulative-assigned-addresses",
static_cast<int64_t>(1));
}
@@ -4289,15 +4554,35 @@ AllocEngine::reuseExpiredLease4(Lease4Ptr& expired,
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease4(expired);
- // We need to account for the re-assignment of The lease.
+ // We need to account for the re-assignment of the lease.
StatsMgr::instance().addValue(
- StatsMgr::generateName("subnet", ctx.subnet_->getID(),
- "assigned-addresses"),
- static_cast<int64_t>(1));
+ 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));
+ StatsMgr::generateName("subnet", ctx.subnet_->getID(),
+ "cumulative-assigned-addresses"),
+ static_cast<int64_t>(1));
+
+ const auto& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(ctx.subnet_->getID());
+ if (subnet) {
+ const auto& pool = subnet->getPool(Lease::TYPE_V4, expired->addr_, false);
+ if (pool) {
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ static_cast<int64_t>(1));
+
+ StatsMgr::instance().addValue(
+ StatsMgr::generateName("subnet", subnet->getID(),
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")),
+ static_cast<int64_t>(1));
+ }
+ }
+
StatsMgr::instance().addValue("cumulative-assigned-addresses",
static_cast<int64_t>(1));
}
diff --git a/src/lib/dhcpsrv/cfg_option.cc b/src/lib/dhcpsrv/cfg_option.cc
index a1d9e64589..e3c3e8b668 100644
--- a/src/lib/dhcpsrv/cfg_option.cc
+++ b/src/lib/dhcpsrv/cfg_option.cc
@@ -159,7 +159,7 @@ CfgOption::createOptions(CfgOptionDefPtr cfg_def) {
for (auto opt_desc : *(getAll(space))) {
if (createDescriptorOption(cfg_def, space, opt_desc)) {
// Option was recreated, let's replace the descriptor.
- replace(opt_desc,space);
+ replace(opt_desc, space);
}
}
}
diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc
index a621c4d4a6..1947c2fe40 100644
--- a/src/lib/dhcpsrv/cfg_subnets4.cc
+++ b/src/lib/dhcpsrv/cfg_subnets4.cc
@@ -155,7 +155,7 @@ CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks,
other_subnet->getCfgOption()->createOptions(cfg_def);
// Create the options for pool based on the given definitions.
- for (auto const& pool : other_subnet->getPoolsWritable(Lease::TYPE_V4)) {
+ for (const auto& pool : other_subnet->getPoolsWritable(Lease::TYPE_V4)) {
pool->getCfgOption()->createOptions(cfg_def);
}
@@ -540,6 +540,32 @@ CfgSubnets4::removeStatistics() {
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"));
+
+ for (const auto& pool : subnet4->getPools(Lease::TYPE_V4)) {
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "total-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-declined-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-leases")));
+ }
}
}
@@ -569,6 +595,20 @@ CfgSubnets4::updateStatistics() {
if (!stats_mgr.getObservation(name)) {
stats_mgr.setValue(name, static_cast<int64_t>(0));
}
+
+ for (const auto& pool : subnet4->getPools(Lease::TYPE_V4)) {
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "total-addresses")),
+ static_cast<int64_t>(pool->getCapacity()));
+
+ name = StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "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.
diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc
index ef22436626..a06505294d 100644
--- a/src/lib/dhcpsrv/cfg_subnets6.cc
+++ b/src/lib/dhcpsrv/cfg_subnets6.cc
@@ -152,12 +152,12 @@ CfgSubnets6::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks6Ptr networks,
other_subnet->getCfgOption()->createOptions(cfg_def);
// Create the options for pool based on the given definitions.
- for (auto const& pool : other_subnet->getPoolsWritable(Lease::TYPE_NA)) {
+ for (const auto& pool : other_subnet->getPoolsWritable(Lease::TYPE_NA)) {
pool->getCfgOption()->createOptions(cfg_def);
}
// Create the options for pd pool based on the given definitions.
- for (auto const& pool : other_subnet->getPoolsWritable(Lease::TYPE_PD)) {
+ for (const auto& pool : other_subnet->getPoolsWritable(Lease::TYPE_PD)) {
pool->getCfgOption()->createOptions(cfg_def);
}
@@ -412,7 +412,8 @@ CfgSubnets6::removeStatistics() {
// For each v6 subnet currently configured, remove the statistics.
for (auto const& subnet6 : subnets_) {
SubnetID subnet_id = subnet6->getID();
- stats_mgr.del(StatsMgr::generateName("subnet", subnet_id, "total-nas"));
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ "total-nas"));
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"assigned-nas"));
@@ -420,7 +421,8 @@ CfgSubnets6::removeStatistics() {
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,
+ "total-pds"));
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"assigned-pds"));
@@ -436,6 +438,50 @@ CfgSubnets6::removeStatistics() {
stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"));
+
+ for (const auto& pool : subnet6->getPools(Lease::TYPE_NA)) {
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "total-nas")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-nas")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-nas")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-declined-addresses")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-leases")));
+ }
+
+ for (const auto& pool : subnet6->getPools(Lease::TYPE_PD)) {
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "total-pds")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "assigned-pds")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "cumulative-assigned-pds")));
+
+ stats_mgr.del(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "reclaimed-leases")));
+ }
}
}
@@ -456,14 +502,12 @@ CfgSubnets6::updateStatistics() {
"total-pds"),
subnet6->getPoolCapacity(Lease::TYPE_PD));
- const std::string& name_nas =
- StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-nas");
+ 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");
+ 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));
}
@@ -479,6 +523,36 @@ CfgSubnets6::updateStatistics() {
if (!stats_mgr.getObservation(name_ia_pd_reuses)) {
stats_mgr.setValue(name_ia_pd_reuses, int64_t(0));
}
+
+ for (const auto& pool : subnet6->getPools(Lease::TYPE_NA)) {
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "total-nas")),
+ static_cast<int64_t>(pool->getCapacity()));
+
+ const std::string& name_nas =
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "cumulative-assigned-nas"));
+ if (!stats_mgr.getObservation(name_nas)) {
+ stats_mgr.setValue(name_nas, static_cast<int64_t>(0));
+ }
+ }
+
+ for (const auto& pool : subnet6->getPools(Lease::TYPE_PD)) {
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "total-pds")),
+ static_cast<int64_t>(pool->getCapacity()));
+
+ const std::string& name_nas =
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "cumulative-assigned-pds"));
+ if (!stats_mgr.getObservation(name_nas)) {
+ stats_mgr.setValue(name_nas, static_cast<int64_t>(0));
+ }
+ }
}
// Only recount the stats if we have subnets.
diff --git a/src/lib/dhcpsrv/csv_lease_file4.cc b/src/lib/dhcpsrv/csv_lease_file4.cc
index 71bfd22440..d8ca8c5dc2 100644
--- a/src/lib/dhcpsrv/csv_lease_file4.cc
+++ b/src/lib/dhcpsrv/csv_lease_file4.cc
@@ -70,7 +70,7 @@ CSVLeaseFile4::append(const Lease4& lease) {
if (lease.getContext()) {
row.writeAtEscaped(getColumnIndex("user_context"), lease.getContext()->str());
}
-
+ row.writeAt(getColumnIndex("pool_id"), lease.pool_id_);
try {
VersionedCSVFile::append(row);
} catch (const std::exception&) {
@@ -140,12 +140,14 @@ CSVLeaseFile4::next(Lease4Ptr& lease) {
readFqdnFwd(row),
readFqdnRev(row),
readHostname(row)));
+
lease->state_ = state;
if (ctx) {
lease->setContext(ctx);
}
+ lease->pool_id_ = readPoolID(row);
} catch (const std::exception& ex) {
// bump the read error count
++read_errs_;
@@ -176,6 +178,8 @@ CSVLeaseFile4::initColumns() {
addColumn("hostname", "1.0");
addColumn("state", "2.0", "0");
addColumn("user_context", "2.1");
+ addColumn("pool_id", "3.0", "0");
+
// Any file with less than hostname is invalid
setMinimumValidColumns("hostname");
}
@@ -225,6 +229,13 @@ CSVLeaseFile4::readSubnetID(const CSVRow& row) {
return (subnet_id);
}
+uint32_t
+CSVLeaseFile4::readPoolID(const CSVRow& row) {
+ uint32_t pool_id =
+ row.readAndConvertAt<SubnetID>(getColumnIndex("pool_id"));
+ return (pool_id);
+}
+
bool
CSVLeaseFile4::readFqdnFwd(const CSVRow& row) {
bool fqdn_fwd = row.readAndConvertAt<bool>(getColumnIndex("fqdn_fwd"));
diff --git a/src/lib/dhcpsrv/csv_lease_file4.h b/src/lib/dhcpsrv/csv_lease_file4.h
index c5f88f2f0d..11afe6cb40 100644
--- a/src/lib/dhcpsrv/csv_lease_file4.h
+++ b/src/lib/dhcpsrv/csv_lease_file4.h
@@ -101,6 +101,7 @@ private:
/// - hostname
/// - state
/// - user_context
+ /// - pool_id
void initColumns();
///
@@ -138,6 +139,11 @@ private:
/// @param row CSV file row holding lease information.
SubnetID readSubnetID(const util::CSVRow& row);
+ /// @brief Reads pool id from the CSV file row.
+ ///
+ /// @param row CSV file row holding lease information.
+ uint32_t readPoolID(const util::CSVRow& row);
+
/// @brief Reads the FQDN forward flag from the CSV file row.
///
/// @param row CSV file row holding lease information.
@@ -163,7 +169,6 @@ private:
/// @param row CSV file row holding lease information.
data::ConstElementPtr readContext(const util::CSVRow& row);
//@}
-
};
} // namespace isc::dhcp
diff --git a/src/lib/dhcpsrv/csv_lease_file6.cc b/src/lib/dhcpsrv/csv_lease_file6.cc
index 50306d6aba..2933ffc3c9 100644
--- a/src/lib/dhcpsrv/csv_lease_file6.cc
+++ b/src/lib/dhcpsrv/csv_lease_file6.cc
@@ -69,6 +69,7 @@ CSVLeaseFile6::append(const Lease6& lease) {
if (lease.getContext()) {
row.writeAtEscaped(getColumnIndex("user_context"), lease.getContext()->str());
}
+ row.writeAt(getColumnIndex("pool_id"), lease.pool_id_);
try {
VersionedCSVFile::append(row);
} catch (const std::exception&) {
@@ -106,20 +107,25 @@ CSVLeaseFile6::next(Lease6Ptr& lease) {
readSubnetID(row),
readHWAddr(row),
readPrefixLen(row)));
+
lease->cltt_ = readCltt(row);
lease->fqdn_fwd_ = readFqdnFwd(row);
lease->fqdn_rev_ = readFqdnRev(row);
lease->hostname_ = readHostname(row);
lease->state_ = readState(row);
+
if ((*lease->duid_ == DUID::EMPTY())
&& lease->state_ != Lease::STATE_DECLINED) {
isc_throw(isc::BadValue,
"The Empty DUID is only valid for declined leases");
}
+
ConstElementPtr ctx = readContext(row);
if (ctx) {
lease->setContext(ctx);
}
+
+ lease->pool_id_ = readPoolID(row);
} catch (const std::exception& ex) {
// bump the read error count
++read_errs_;
@@ -154,13 +160,13 @@ CSVLeaseFile6::initColumns() {
addColumn("hwaddr", "2.0");
addColumn("state", "3.0", "0" /* == STATE_DEFAULT */);
addColumn("user_context", "3.1");
-
// Default not added for hwtype and hwaddr_source, because they depend on
// hwaddr having value. When a CSV lease having a hwaddr is upgraded to 4.0,
// hwtype will have value "1" meaning HTYPE_ETHER and
// hwaddr_source will have value "0" meaning HWADDR_SOURCE_UNKNOWN.
addColumn("hwtype", "4.0");
addColumn("hwaddr_source", "4.0");
+ addColumn("pool_id", "5.0", "0");
// Any file with less than hostname is invalid
setMinimumValidColumns("hostname");
@@ -219,6 +225,13 @@ CSVLeaseFile6::readSubnetID(const CSVRow& row) {
return (subnet_id);
}
+uint32_t
+CSVLeaseFile6::readPoolID(const CSVRow& row) {
+ uint32_t pool_id =
+ row.readAndConvertAt<uint32_t>(getColumnIndex("pool_id"));
+ return (pool_id);
+}
+
uint8_t
CSVLeaseFile6::readPrefixLen(const CSVRow& row) {
int prefixlen = row.readAndConvertAt<int>(getColumnIndex("prefix_len"));
diff --git a/src/lib/dhcpsrv/csv_lease_file6.h b/src/lib/dhcpsrv/csv_lease_file6.h
index 4dfe7c671e..51e0177886 100644
--- a/src/lib/dhcpsrv/csv_lease_file6.h
+++ b/src/lib/dhcpsrv/csv_lease_file6.h
@@ -106,6 +106,7 @@ private:
/// - user_context
/// - hwtype
/// - hwaddr_source
+ /// - pool_id
void initColumns();
///
@@ -153,6 +154,11 @@ private:
/// @param row CSV file row holding lease information.
SubnetID readSubnetID(const util::CSVRow& row);
+ /// @brief Reads pool id from the CSV file row.
+ ///
+ /// @param row CSV file row holding lease information.
+ uint32_t readPoolID(const util::CSVRow& row);
+
/// @brief Reads prefix length from the CSV file row.
///
/// @param row CSV file row holding lease information.
diff --git a/src/lib/dhcpsrv/flq_allocator.cc b/src/lib/dhcpsrv/flq_allocator.cc
index 7f5181052e..e5eb03255e 100644
--- a/src/lib/dhcpsrv/flq_allocator.cc
+++ b/src/lib/dhcpsrv/flq_allocator.cc
@@ -63,7 +63,7 @@ FreeLeaseQueueAllocator::pickAddressInternal(const ClientClasses& client_classes
return (pool_type_ == Lease::TYPE_V4 ? IOAddress::IPV4_ZERO_ADDRESS() : IOAddress::IPV6_ZERO_ADDRESS());
}
// Get a random pool from the available ones.
- auto pool = pools[available[getRandomNumber(available.size()-1)]];
+ auto pool = pools[available[getRandomNumber(available.size() - 1)]];
// Get or create the pool state.
auto pool_state = getPoolState(pool);
@@ -114,7 +114,7 @@ FreeLeaseQueueAllocator::pickPrefixInternal(const ClientClasses& client_classes,
return (IOAddress::IPV6_ZERO_ADDRESS());
}
// Get a random pool from the available ones.
- auto pool = pools[available[getRandomNumber(available.size()-1)]];
+ auto pool = pools[available[getRandomNumber(available.size() - 1)]];
pool6 = boost::dynamic_pointer_cast<Pool6>(pool);
if (!pool6) {
// Something is gravely wrong here
@@ -180,7 +180,8 @@ FreeLeaseQueueAllocator::initAfterConfigureInternal() {
template<typename LeaseCollectionType>
void
-FreeLeaseQueueAllocator::populateFreeAddressLeases(const LeaseCollectionType& leases, const PoolCollection& pools) {
+FreeLeaseQueueAllocator::populateFreeAddressLeases(const LeaseCollectionType& leases,
+ const PoolCollection& pools) {
auto subnet = subnet_.lock();
LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_ADDRESS_LEASES)
.arg(subnet->toText());
@@ -226,7 +227,8 @@ FreeLeaseQueueAllocator::populateFreeAddressLeases(const LeaseCollectionType& le
}
void
-FreeLeaseQueueAllocator::populateFreePrefixDelegationLeases(const Lease6Collection& leases, const PoolCollection& pools) {
+FreeLeaseQueueAllocator::populateFreePrefixDelegationLeases(const Lease6Collection& leases,
+ const PoolCollection& pools) {
auto subnet = subnet_.lock();
LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES)
.arg(subnet->toText());
@@ -251,7 +253,9 @@ FreeLeaseQueueAllocator::populateFreePrefixDelegationLeases(const Lease6Collecti
}
// Create the pool permutation so the resulting lease queue is no
// particular order.
- IPRangePermutation perm(PrefixRange(pool->getFirstAddress(), pool->getLastAddress(), pool6->getLength()));
+ IPRangePermutation perm(PrefixRange(pool->getFirstAddress(),
+ pool->getLastAddress(),
+ pool6->getLength()));
auto pool_state = getPoolState(pool);
auto done = false;
while (!done) {
diff --git a/src/lib/dhcpsrv/iterative_allocator.cc b/src/lib/dhcpsrv/iterative_allocator.cc
index 8a66cb7430..751c1485a0 100644
--- a/src/lib/dhcpsrv/iterative_allocator.cc
+++ b/src/lib/dhcpsrv/iterative_allocator.cc
@@ -97,7 +97,7 @@ IterativeAllocator::pickAddressInternal(const ClientClasses& client_classes,
bool valid = true;
bool retrying = false;
- const PoolCollection& pools = subnet_.lock()->getPools(pool_type_);
+ const auto& pools = subnet_.lock()->getPools(pool_type_);
if (pools.empty()) {
isc_throw(AllocFailed, "No pools defined in selected subnet");
@@ -211,7 +211,7 @@ IterativeAllocator::pickPrefixInternal(const ClientClasses& client_classes,
bool valid = true;
bool retrying = false;
- const PoolCollection& pools = subnet_.lock()->getPools(pool_type_);
+ const auto& pools = subnet_.lock()->getPools(pool_type_);
if (pools.empty()) {
isc_throw(AllocFailed, "No pools defined in selected subnet");
diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc
index 1d74b72a15..debc08a81b 100644
--- a/src/lib/dhcpsrv/lease.cc
+++ b/src/lib/dhcpsrv/lease.cc
@@ -14,7 +14,6 @@
#include <sstream>
#include <iostream>
-
using namespace isc::util;
using namespace isc::data;
using namespace std;
@@ -43,12 +42,11 @@ Lease::Lease(const isc::asiolink::IOAddress& addr,
const std::string& hostname, const HWAddrPtr& hwaddr)
: addr_(addr), valid_lft_(valid_lft), current_valid_lft_(valid_lft),
reuseable_valid_lft_(0),
- cltt_(cltt), current_cltt_(cltt), subnet_id_(subnet_id),
+ cltt_(cltt), current_cltt_(cltt), subnet_id_(subnet_id), pool_id_(0),
hostname_(boost::algorithm::to_lower_copy(hostname)), fqdn_fwd_(fqdn_fwd),
fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT) {
}
-
std::string
Lease::typeToText(Lease::Type type) {
switch (type) {
@@ -142,7 +140,6 @@ Lease::fromElementCommon(const LeasePtr& lease, const data::ConstElementPtr& ele
isc_throw(BadValue, "parsed lease data is not a JSON map");
}
-
if (!lease) {
isc_throw(Unexpected, "pointer to parsed lease is null");
}
@@ -182,6 +179,24 @@ Lease::fromElementCommon(const LeasePtr& lease, const data::ConstElementPtr& ele
lease->subnet_id_ = SubnetID(subnet_id->intValue());
+ // Pool identifier.
+ ConstElementPtr pool_id = element->get("pool-id");
+ if (pool_id) {
+ if (pool_id->getType() != Element::integer) {
+ isc_throw(BadValue, "pool-id is not a number");
+ }
+
+ if (pool_id->intValue() < 0) {
+ isc_throw(BadValue, "pool-id " << pool_id->intValue() << " is not"
+ << " a positive integer");
+ } else if (pool_id->intValue() > numeric_limits<uint32_t>::max()) {
+ isc_throw(BadValue, "pool-id " << pool_id->intValue() << " is not"
+ << " a 32 bit unsigned integer");
+ }
+
+ lease->pool_id_ = pool_id->intValue();
+ }
+
// Hardware address.
ConstElementPtr hw_address = element->get("hw-address");
if (hw_address) {
@@ -311,10 +326,8 @@ Lease4::Lease4(const Lease4& other)
if (other.client_id_) {
client_id_.reset(new ClientId(other.client_id_->getClientId()));
-
} else {
client_id_.reset();
-
}
if (other.getContext()) {
@@ -402,6 +415,7 @@ Lease4::operator=(const Lease4& other) {
cltt_ = other.cltt_;
current_cltt_ = other.current_cltt_;
subnet_id_ = other.subnet_id_;
+ pool_id_ = other.pool_id_;
hostname_ = other.hostname_;
fqdn_fwd_ = other.fqdn_fwd_;
fqdn_rev_ = other.fqdn_rev_;
@@ -436,6 +450,7 @@ Lease4::toElement() const {
contextToElement(map);
map->set("ip-address", Element::create(addr_.toText()));
map->set("subnet-id", Element::create(static_cast<long int>(subnet_id_)));
+ map->set("pool-id", Element::create(static_cast<long int>(pool_id_)));
map->set("hw-address", Element::create(hwaddr_->toText(false)));
if (client_id_) {
@@ -471,7 +486,6 @@ Lease4::fromElement(const ConstElementPtr& element) {
isc_throw(BadValue, "hw-address not present in the parsed lease");
}
-
// Client identifier is IPv4 specific.
ConstElementPtr client_id = element->get("client-id");
if (client_id) {
@@ -577,6 +591,7 @@ Lease6::toText() const {
<< "DUID: " << (duid_?duid_->toText():"(none)") << "\n"
<< "Hardware addr: " << (hwaddr_?hwaddr_->toText(false):"(none)") << "\n"
<< "Subnet ID: " << subnet_id_ << "\n"
+ << "Pool ID: " << pool_id_ << "\n"
<< "State: " << statesToText(state_) << "\n";
if (getContext()) {
@@ -596,6 +611,7 @@ Lease4::toText() const {
<< "Hardware addr: " << (hwaddr_ ? hwaddr_->toText(false) : "(none)") << "\n"
<< "Client id: " << (client_id_ ? client_id_->toText() : "(none)") << "\n"
<< "Subnet ID: " << subnet_id_ << "\n"
+ << "Pool ID: " << pool_id_ << "\n"
<< "State: " << statesToText(state_) << "\n"
<< "Relay ID: " << (relay_id_.empty() ? "(none)" :
str::dumpAsHex(&relay_id_[0], relay_id_.size())) << "\n"
@@ -609,13 +625,13 @@ Lease4::toText() const {
return (stream.str());
}
-
bool
Lease4::operator==(const Lease4& other) const {
return (nullOrEqualValues(hwaddr_, other.hwaddr_) &&
nullOrEqualValues(client_id_, other.client_id_) &&
addr_ == other.addr_ &&
subnet_id_ == other.subnet_id_ &&
+ pool_id_ == other.pool_id_ &&
valid_lft_ == other.valid_lft_ &&
current_valid_lft_ == other.current_valid_lft_ &&
reuseable_valid_lft_ == other.reuseable_valid_lft_ &&
@@ -644,6 +660,7 @@ Lease6::operator==(const Lease6& other) const {
cltt_ == other.cltt_ &&
current_cltt_ == other.current_cltt_ &&
subnet_id_ == other.subnet_id_ &&
+ pool_id_ == other.pool_id_ &&
hostname_ == other.hostname_ &&
fqdn_fwd_ == other.fqdn_fwd_ &&
fqdn_rev_ == other.fqdn_rev_ &&
@@ -664,6 +681,7 @@ Lease6::toElement() const {
map->set("iaid", Element::create(static_cast<long int>(iaid_)));
map->set("duid", Element::create(duid_->toText()));
map->set("subnet-id", Element::create(static_cast<long int>(subnet_id_)));
+ map->set("pool-id", Element::create(static_cast<long int>(pool_id_)));
map->set("cltt", Element::create(cltt_));
map->set("preferred-lft", Element::create(static_cast<long int>(preferred_lft_)));
diff --git a/src/lib/dhcpsrv/lease.h b/src/lib/dhcpsrv/lease.h
index 3fa764f9c9..733d1974a6 100644
--- a/src/lib/dhcpsrv/lease.h
+++ b/src/lib/dhcpsrv/lease.h
@@ -153,6 +153,11 @@ struct Lease : public isc::data::UserContext, public isc::data::CfgToElement {
/// Specifies the identification of the subnet to which the lease belongs.
SubnetID subnet_id_;
+ /// @brief The pool id
+ ///
+ /// Specifies the identification of the pool from a subnet to which the lease belongs.
+ uint32_t pool_id_;
+
/// @brief Client hostname
///
/// This field is in lower case and may be empty.
diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc
index ded2577f7f..b3109f7f5a 100644
--- a/src/lib/dhcpsrv/lease_mgr.cc
+++ b/src/lib/dhcpsrv/lease_mgr.cc
@@ -136,6 +136,40 @@ LeaseMgr::recountLeaseStats4() {
"reclaimed-leases"),
zero);
}
+
+ for (const auto & pool : (*subnet)->getPools(Lease::TYPE_V4)) {
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-addresses")),
+ zero);
+
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ zero);
+
+ if (!stats_mgr.getObservation(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-declined-addresses")))) {
+ stats_mgr.setValue(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-declined-addresses")),
+ zero);
+ }
+
+ if (!stats_mgr.getObservation(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-leases")))) {
+ stats_mgr.setValue(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-leases")),
+ zero);
+ }
+ }
}
// Get counts per state per subnet. Iterate over the result set
@@ -163,6 +197,8 @@ LeaseMgr::recountLeaseStats4() {
row.state_count_);
}
}
+ // Can not update counters at pool level. This would require retrieving all
+ // leases and matching them one by one to one possible pool.
}
LeaseStatsQuery::LeaseStatsQuery()
@@ -267,6 +303,10 @@ LeaseMgr::recountLeaseStats6() {
zero);
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ "assigned-pds"),
+ zero);
+
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"declined-addresses"),
zero);
@@ -279,10 +319,6 @@ LeaseMgr::recountLeaseStats6() {
zero);
}
- stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
- "assigned-pds"),
- zero);
-
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"))) {
@@ -291,6 +327,58 @@ LeaseMgr::recountLeaseStats6() {
"reclaimed-leases"),
zero);
}
+
+ for (const auto& pool : (*subnet)->getPools(Lease::TYPE_NA)) {
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "assigned-nas")),
+ zero);
+
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "declined-addresses")),
+ zero);
+
+ if (!stats_mgr.getObservation(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-declined-addresses")))) {
+ stats_mgr.setValue(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-declined-addresses")),
+ zero);
+ }
+
+ if (!stats_mgr.getObservation(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-leases")))) {
+ stats_mgr.setValue(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pool", pool->getID(),
+ "reclaimed-leases")),
+ zero);
+ }
+ }
+
+ for (const auto& pool : (*subnet)->getPools(Lease::TYPE_PD)) {
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "assigned-pds")),
+ zero);
+
+ if (!stats_mgr.getObservation(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "reclaimed-leases")))) {
+ stats_mgr.setValue(
+ StatsMgr::generateName("subnet", subnet_id,
+ StatsMgr::generateName(".pd-pool", pool->getID(),
+ "reclaimed-leases")),
+ zero);
+ }
+ }
}
// Get counts per state per subnet. Iterate over the result set
@@ -301,15 +389,13 @@ LeaseMgr::recountLeaseStats6() {
case Lease::TYPE_NA:
if (row.lease_state_ == Lease::STATE_DEFAULT) {
// Add to subnet level value.
- stats_mgr.addValue(StatsMgr::
- generateName("subnet", row.subnet_id_,
- "assigned-nas"),
+ stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ "assigned-nas"),
row.state_count_);
} else if (row.lease_state_ == Lease::STATE_DECLINED) {
// Set subnet level value.
- stats_mgr.setValue(StatsMgr::
- generateName("subnet", row.subnet_id_,
- "declined-addresses"),
+ stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ "declined-addresses"),
row.state_count_);
// Add to the global value.
@@ -317,9 +403,8 @@ LeaseMgr::recountLeaseStats6() {
// Add to subnet level value.
// Declined leases also count as assigned.
- stats_mgr.addValue(StatsMgr::
- generateName("subnet", row.subnet_id_,
- "assigned-nas"),
+ stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ "assigned-nas"),
row.state_count_);
}
break;
@@ -327,9 +412,8 @@ LeaseMgr::recountLeaseStats6() {
case Lease::TYPE_PD:
if (row.lease_state_ == Lease::STATE_DEFAULT) {
// Set subnet level value.
- stats_mgr.setValue(StatsMgr::
- generateName("subnet", row.subnet_id_,
- "assigned-pds"),
+ stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
+ "assigned-pds"),
row.state_count_);
}
break;
@@ -339,6 +423,8 @@ LeaseMgr::recountLeaseStats6() {
break;
}
}
+ // Can not update counters at pool level. This would require retrieving all
+ // leases and matching them one by one to one possible pool.
}
LeaseStatsQueryPtr
diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h
index ac4a858f52..2afdb7aa2b 100644
--- a/src/lib/dhcpsrv/memfile_lease_mgr.h
+++ b/src/lib/dhcpsrv/memfile_lease_mgr.h
@@ -86,13 +86,14 @@ public:
/// 1.0 - initial version (released in Kea 0.9)
/// 2.0 - hwaddr column added (released in Kea 0.9.1)
/// 2.1 - user context column added (released in Kea 1.4.0)
+ /// 3.0 - pool_id column added (released in Kea 2.3.8)
///
/// @{
/// @brief the major version of the v4 memfile backend
- static const int MAJOR_VERSION_V4 = 2;
+ static const int MAJOR_VERSION_V4 = 3;
/// @brief the minor version of the v4 memfile backend
- static const int MINOR_VERSION_V4 = 1;
+ static const int MINOR_VERSION_V4 = 0;
/// @}
/// @defgroup v6 memfile backend versions
@@ -103,10 +104,11 @@ public:
/// 3.0 - state column added (released in Kea 0.9.2)
/// 3.1 - user context column added (released in Kea 1.4.0)
/// 4.0 - hwtype,hwaddr_source columns added (released in Kea 2.1.2)
+ /// 5.0 - pool_id column added (released in Kea 2.3.8)
///
/// @{
/// @brief the major version of the v6 memfile backend
- static const int MAJOR_VERSION_V6 = 4;
+ static const int MAJOR_VERSION_V6 = 5;
/// @brief the minor version of the v6 memfile backend
static const int MINOR_VERSION_V6 = 0;
diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h
index 285be092c6..174dff49d6 100644
--- a/src/lib/dhcpsrv/memfile_lease_storage.h
+++ b/src/lib/dhcpsrv/memfile_lease_storage.h
@@ -34,15 +34,18 @@ struct DuidIaidTypeIndexTag { };
/// @brief Tag for indexes by expiration time.
struct ExpirationIndexTag { };
-/// @brief Tag for indexes by HW address, subnet identifier tuple.
+/// @brief Tag for indexes by HW address, subnet-id tuple.
struct HWAddressSubnetIdIndexTag { };
-/// @brief Tag for indexes by client and subnet identifiers.
+/// @brief Tag for indexes by client-id, subnet-id tuple.
struct ClientIdSubnetIdIndexTag { };
/// @brief Tag for indexes by subnet-id.
struct SubnetIdIndexTag { };
+/// @brief Tag for indexes by subnet-id and pool-id.
+struct SubnetIdPoolIdIndexTag { };
+
/// @brief Tag for index using DUID.
struct DuidIndexTag { };
@@ -142,6 +145,26 @@ typedef boost::multi_index_container<
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<HostnameIndexTag>,
boost::multi_index::member<Lease, std::string, &Lease::hostname_>
+ >,
+
+ // Specification of the seventh index starts here.
+ boost::multi_index::ordered_non_unique<
+ boost::multi_index::tag<SubnetIdPoolIdIndexTag>,
+ // This is a composite index that combines two attributes of the
+ // Lease6 object: subnet id and pool id.
+ boost::multi_index::composite_key<
+ Lease6,
+ // The subnet id is held in the subnet_id_ member of Lease6
+ // class. Note that the subnet_id_ is defined in the base
+ // class (Lease) so we have to point to this class rather
+ // than derived class: Lease6.
+ boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>,
+ // The pool id is held in the pool_id_ member of Lease6
+ // class. Note that the pool_id_ is defined in the base
+ // class (Lease) so we have to point to this class rather
+ // than derived class: Lease6.
+ boost::multi_index::member<Lease, uint32_t, &Lease::pool_id_>
+ >
>
>
> Lease6Storage; // Specify the type name of this container.
@@ -272,6 +295,26 @@ typedef boost::multi_index_container<
isc::asiolink::IOAddress,
&Lease::addr_>
>
+ >,
+
+ // Specification of the ninth index starts here.
+ boost::multi_index::ordered_non_unique<
+ boost::multi_index::tag<SubnetIdPoolIdIndexTag>,
+ // This is a composite index that combines two attributes of the
+ // Lease4 object: subnet id and pool id.
+ boost::multi_index::composite_key<
+ Lease4,
+ // The subnet id is held in the subnet_id_ member of Lease4
+ // class. Note that the subnet_id_ is defined in the base
+ // class (Lease) so we have to point to this class rather
+ // than derived class: Lease4.
+ boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>,
+ // The pool id is held in the pool_id_ member of Lease4
+ // class. Note that the pool_id_ is defined in the base
+ // class (Lease) so we have to point to this class rather
+ // than derived class: Lease4.
+ boost::multi_index::member<Lease, uint32_t, &Lease::pool_id_>
+ >
>
>
> Lease4Storage; // Specify the type name for this container.
@@ -291,9 +334,12 @@ typedef Lease6Storage::index<DuidIaidTypeIndexTag>::type Lease6StorageDuidIaidTy
/// @brief DHCPv6 lease storage index by expiration time.
typedef Lease6Storage::index<ExpirationIndexTag>::type Lease6StorageExpirationIndex;
-/// @brief DHCPv6 lease storage index by Subnet-id.
+/// @brief DHCPv6 lease storage index by subnet-id.
typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;
+/// @brief DHCPv6 lease storage index subnet-id and pool-id.
+typedef Lease6Storage::index<SubnetIdPoolIdIndexTag>::type Lease6StorageSubnetIdPoolIdIndex;
+
/// @brief DHCPv6 lease storage index by DUID.
typedef Lease6Storage::index<DuidIndexTag>::type Lease6StorageDuidIndex;
@@ -306,28 +352,31 @@ typedef Lease4Storage::index<AddressIndexTag>::type Lease4StorageAddressIndex;
/// @brief DHCPv4 lease storage index by expiration time.
typedef Lease4Storage::index<ExpirationIndexTag>::type Lease4StorageExpirationIndex;
-/// @brief DHCPv4 lease storage index by HW address and subnet identifier.
+/// @brief DHCPv4 lease storage index by HW address and subnet-id.
typedef Lease4Storage::index<HWAddressSubnetIdIndexTag>::type
Lease4StorageHWAddressSubnetIdIndex;
-/// @brief DHCPv4 lease storage index by client and subnet identifier.
+/// @brief DHCPv4 lease storage index by client-id and subnet-id.
typedef Lease4Storage::index<ClientIdSubnetIdIndexTag>::type
Lease4StorageClientIdSubnetIdIndex;
-/// @brief DHCPv4 lease storage index subnet identifier.
+/// @brief DHCPv4 lease storage index subnet-id.
typedef Lease4Storage::index<SubnetIdIndexTag>::type Lease4StorageSubnetIdIndex;
+/// @brief DHCPv4 lease storage index subnet-id and pool-id.
+typedef Lease4Storage::index<SubnetIdPoolIdIndexTag>::type Lease4StorageSubnetIdPoolIdIndex;
+
/// @brief DHCPv4 lease storage index by hostname.
typedef Lease4Storage::index<HostnameIndexTag>::type Lease4StorageHostnameIndex;
-/// @brief DHCPv4 lease storage index by remote identifier.
+/// @brief DHCPv4 lease storage index by remote-id.
typedef Lease4Storage::index<RemoteIdIndexTag>::type Lease4StorageRemoteIdIndex;
-/// @brief DHCPv4 lease storage range by remote identifier.
+/// @brief DHCPv4 lease storage range by remote-id.
typedef std::pair<Lease4StorageRemoteIdIndex::const_iterator,
Lease4StorageRemoteIdIndex::const_iterator> Lease4StorageRemoteIdRange;
-/// @brief DHCPv4 lease storage index by relay identifier.
+/// @brief DHCPv4 lease storage index by relay-id.
typedef Lease4Storage::index<RelayIdIndexTag>::type Lease4StorageRelayIdIndex;
//@}
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc
index 1e5cede00a..6506b28c06 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc
@@ -116,48 +116,48 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4"},
{MySqlLeaseMgr::GET_LEASE4_ADDR,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE address = ?"},
{MySqlLeaseMgr::GET_LEASE4_CLIENTID,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE client_id = ?"},
{MySqlLeaseMgr::GET_LEASE4_CLIENTID_SUBID,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE client_id = ? AND subnet_id = ?"},
{MySqlLeaseMgr::GET_LEASE4_HWADDR,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE hwaddr = ?"},
{MySqlLeaseMgr::GET_LEASE4_HWADDR_SUBID,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE hwaddr = ? AND subnet_id = ?"},
{MySqlLeaseMgr::GET_LEASE4_PAGE,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE address > ? "
"ORDER BY address "
@@ -175,21 +175,21 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE subnet_id = ?"},
{MySqlLeaseMgr::GET_LEASE4_HOSTNAME,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE hostname = ?"},
{MySqlLeaseMgr::GET_LEASE4_EXPIRE,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE state != ? "
"AND valid_lifetime != 4294967295 "
@@ -200,7 +200,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = ? and address > ? "
"ORDER BY address "
@@ -209,7 +209,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = ? and address > ? "
" and UNIX_TIMESTAMP(expire) - IF"
@@ -221,7 +221,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = ? and address > ? "
" and UNIX_TIMESTAMP(expire) - IF"
@@ -236,7 +236,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = ? and address > ? "
" and UNIX_TIMESTAMP(expire) - IF"
@@ -248,7 +248,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = ? and address > ? "
"ORDER BY address "
@@ -257,7 +257,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = ? and address > ? "
" and UNIX_TIMESTAMP(expire) - IF"
@@ -269,7 +269,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = ? and address > ? "
" and UNIX_TIMESTAMP(expire) - IF"
@@ -284,7 +284,7 @@ tagged_statements = { {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = ? and address > ? "
" and UNIX_TIMESTAMP(expire) - IF"
@@ -298,7 +298,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6"},
{MySqlLeaseMgr::GET_LEASE6_ADDR,
"SELECT address, duid, valid_lifetime, "
@@ -306,7 +306,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE address = ? AND lease_type = ?"},
{MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
@@ -315,7 +315,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE duid = ? AND iaid = ? AND lease_type = ?"},
{MySqlLeaseMgr::GET_LEASE6_DUID_IAID_SUBID,
@@ -324,7 +324,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE duid = ? AND iaid = ? AND subnet_id = ? "
"AND lease_type = ?"},
@@ -334,7 +334,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE address > ? "
"ORDER BY address "
@@ -367,7 +367,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE subnet_id = ?"},
{MySqlLeaseMgr::GET_LEASE6_DUID,
@@ -376,7 +376,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE duid = ?"},
{MySqlLeaseMgr::GET_LEASE6_HOSTNAME,
@@ -385,7 +385,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE hostname = ?"},
{MySqlLeaseMgr::GET_LEASE6_EXPIRE,
@@ -394,7 +394,7 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE state != ? "
"AND valid_lifetime != 4294967295 "
@@ -417,15 +417,15 @@ tagged_statements = { {
"INSERT INTO lease4(address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
+ "state, user_context, relay_id, remote_id, pool_id) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
{MySqlLeaseMgr::INSERT_LEASE6,
"INSERT INTO lease6(address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context, binaddr) "
+ "state, user_context, binaddr, pool_id) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
{MySqlLeaseMgr::UPDATE_LEASE4,
"UPDATE lease4 SET address = ?, hwaddr = ?, "
@@ -433,7 +433,7 @@ tagged_statements = { {
"subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, "
"hostname = ?, "
"state = ?, user_context = ?, "
- "relay_id = ?, remote_id = ? "
+ "relay_id = ?, remote_id = ?, pool_id = ? "
"WHERE address = ? AND expire = ?"},
{MySqlLeaseMgr::UPDATE_LEASE6,
"UPDATE lease6 SET address = ?, duid = ?, "
@@ -441,7 +441,7 @@ tagged_statements = { {
"pref_lifetime = ?, lease_type = ?, iaid = ?, "
"prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, "
"hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
- "state = ?, user_context = ?, binaddr = ? "
+ "state = ?, user_context = ?, binaddr = ?, pool_id = ? "
"WHERE address = ? AND expire = ?"},
{MySqlLeaseMgr::ALL_LEASE4_STATS,
"SELECT subnet_id, state, leases as state_count "
@@ -566,7 +566,7 @@ public:
class MySqlLease4Exchange : public MySqlLeaseExchange {
/// @brief Set number of database columns for this lease structure
- static const size_t LEASE_COLUMNS = 13;
+ static const size_t LEASE_COLUMNS = 14;
public:
@@ -576,11 +576,11 @@ public:
/// all variables are initialized/set in the methods before they are used.
MySqlLease4Exchange() : addr4_(0), hwaddr_length_(0), hwaddr_null_(MLM_FALSE),
client_id_length_(0), client_id_null_(MLM_FALSE),
- subnet_id_(0), valid_lifetime_(0),
+ subnet_id_(0), pool_id_(0), valid_lifetime_(0),
fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
state_(0), user_context_length_(0),
- user_context_null_(MLM_FALSE),
- relay_id_null_(MLM_FALSE),
+ user_context_null_(MLM_FALSE), relay_id_length_(0),
+ relay_id_null_(MLM_FALSE), remote_id_length_(0),
remote_id_null_(MLM_FALSE) {
memset(hwaddr_buffer_, 0, sizeof(hwaddr_buffer_));
memset(client_id_buffer_, 0, sizeof(client_id_buffer_));
@@ -604,7 +604,8 @@ public:
columns_[10] = "user_context";
columns_[11] = "relay_id";
columns_[12] = "remote_id";
- BOOST_STATIC_ASSERT(12 < LEASE_COLUMNS);
+ columns_[13] = "pool_id";
+ BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
}
/// @brief Create MYSQL_BIND objects for Lease4 Pointer
@@ -815,11 +816,19 @@ public:
bind_[12].is_null = &remote_id_null_;
}
+ // pool_id: unsigned int
+ // Can use lease_->pool_id_ directly as it is of type uint32_t.
+ bind_[13].buffer_type = MYSQL_TYPE_LONG;
+ bind_[13].buffer = reinterpret_cast<char*>(&lease_->pool_id_);
+ bind_[13].is_unsigned = MLM_TRUE;
+ // bind_[13].is_null = &MLM_FALSE; // commented out for performance
+ // reasons, see memset() above
+
// Add the error flags
setErrorIndicators(bind_, error_, LEASE_COLUMNS);
// .. and check that we have the numbers correct at compile time.
- BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
+ BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
@@ -951,11 +960,18 @@ public:
bind_[12].length = &remote_id_length_;
bind_[12].is_null = &remote_id_null_;
+ // pool_id: unsigned int
+ bind_[13].buffer_type = MYSQL_TYPE_LONG;
+ bind_[13].buffer = reinterpret_cast<char*>(&pool_id_);
+ bind_[13].is_unsigned = MLM_TRUE;
+ // bind_[13].is_null = &MLM_FALSE; // commented out for performance
+ // reasons, see memset() above
+
// Add the error flags
setErrorIndicators(bind_, error_, LEASE_COLUMNS);
// .. and check that we have the numbers correct at compile time.
- BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
+ BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
// Add the data to the vector. Note the end element is one after the
// end of the array.
@@ -1041,6 +1057,9 @@ public:
remote_id_buffer_ + remote_id_length_);
}
+ // Set pool ID
+ lease->pool_id_ = pool_id_;
+
return (lease);
}
@@ -1078,6 +1097,7 @@ private:
my_bool client_id_null_; ///< Used when Client ID is null
MYSQL_TIME expire_; ///< Lease expire time
uint32_t subnet_id_; ///< Subnet identification
+ uint32_t pool_id_; ///< Pool identification
uint32_t valid_lifetime_; ///< Lease time
my_bool fqdn_fwd_; ///< Has forward DNS update been performed
my_bool fqdn_rev_; ///< Has reverse DNS update been performed
@@ -1112,7 +1132,7 @@ private:
class MySqlLease6Exchange : public MySqlLeaseExchange {
/// @brief Set number of database columns for this lease structure
- static const size_t LEASE_COLUMNS = 18;
+ static const size_t LEASE_COLUMNS = 19;
public:
@@ -1123,8 +1143,8 @@ public:
MySqlLease6Exchange() : addr6_length_(0), hwaddr_length_(0),
hwaddr_null_(MLM_FALSE), duid_length_(0),
iaid_(0), lease_type_(0), prefix_len_(0),
- pref_lifetime_(0), subnet_id_(0), valid_lifetime_(0),
- fqdn_fwd_(false), fqdn_rev_(false),
+ pref_lifetime_(0), subnet_id_(0), pool_id_(0),
+ valid_lifetime_(0), fqdn_fwd_(false), fqdn_rev_(false),
hostname_length_(0), hwtype_(0), hwaddr_source_(0),
state_(0), user_context_length_(0),
user_context_null_(MLM_FALSE), binaddr_length_(16) {
@@ -1154,7 +1174,8 @@ public:
columns_[15] = "state";
columns_[16] = "user_context";
columns_[17] = "binaddr";
- BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
+ columns_[18] = "pool_id";
+ BOOST_STATIC_ASSERT(18 < LEASE_COLUMNS);
}
/// @brief Create MYSQL_BIND objects for Lease6 Pointer
@@ -1411,11 +1432,19 @@ public:
// bind_[17].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
+ // pool_id: unsigned int
+ // Can use lease_->pool_id_ directly as it is of type uint32_t.
+ bind_[18].buffer_type = MYSQL_TYPE_LONG;
+ bind_[18].buffer = reinterpret_cast<char*>(&lease_->pool_id_);
+ bind_[18].is_unsigned = MLM_TRUE;
+ // bind_[18].is_null = &MLM_FALSE; // commented out for performance
+ // reasons, see memset() above
+
// Add the error flags
setErrorIndicators(bind_, error_, LEASE_COLUMNS);
// .. and check that we have the numbers correct at compile time.
- BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
+ BOOST_STATIC_ASSERT(18 < LEASE_COLUMNS);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
@@ -1573,11 +1602,18 @@ public:
bind_[16].length = &user_context_length_;
bind_[16].is_null = &user_context_null_;
+ // pool_id: unsigned int
+ bind_[17].buffer_type = MYSQL_TYPE_LONG;
+ bind_[17].buffer = reinterpret_cast<char*>(&pool_id_);
+ bind_[17].is_unsigned = MLM_TRUE;
+ // bind_[17].is_null = &MLM_FALSE; // commented out for performance
+ // reasons, see memset() above
+
// Add the error flags
setErrorIndicators(bind_, error_, LEASE_COLUMNS - 1);
// .. and check that we have the numbers correct at compile time.
- BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS - 1);
+ BOOST_STATIC_ASSERT(18 < LEASE_COLUMNS);
// Add the data to the vector. Note the end element is one after the
// end of the array.
@@ -1683,6 +1719,9 @@ public:
result->setContext(ctx);
}
+ // Set pool ID.
+ result->pool_id_ = pool_id_;
+
return (result);
}
@@ -1725,6 +1764,7 @@ private:
uint8_t prefix_len_; ///< Prefix length
uint32_t pref_lifetime_; ///< Preferred lifetime
uint32_t subnet_id_; ///< Subnet identification
+ uint32_t pool_id_; ///< Pool identification
uint32_t valid_lifetime_; ///< Lease time
my_bool fqdn_fwd_; ///< Has forward DNS update been performed
my_bool fqdn_rev_; ///< Has reverse DNS update been performed
diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc
index eed5493f58..5a7b08485e 100644
--- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc
+++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc
@@ -187,7 +187,7 @@ OptionDefParser::parse(ConstElementPtr option_def) {
} else {
def.reset(new OptionDefinition(name, code, space, type,
- encapsulates.c_str()));
+ encapsulates.c_str()));
}
} else {
@@ -630,10 +630,9 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) {
initSubnet(params, addr, len);
// Add pools to it.
- for (PoolStorage::iterator it = pools_->begin(); it != pools_->end();
- ++it) {
+ for (const auto& it : *pools_) {
try {
- subnet_->addPool(*it);
+ subnet_->addPool(it);
} catch (const BadValue& ex) {
// addPool() can throw BadValue if the pool is overlapping or
// is out of bounds for the subnet.
diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc
index 6462e96377..4646ecf629 100644
--- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc
@@ -69,7 +69,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4"},
// GET_LEASE4_ADDR
@@ -78,7 +78,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE address = $1"},
@@ -88,7 +88,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE client_id = $1"},
@@ -98,7 +98,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE client_id = $1 AND subnet_id = $2"},
@@ -108,7 +108,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE hwaddr = $1"},
@@ -118,7 +118,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE hwaddr = $1 AND subnet_id = $2"},
@@ -128,7 +128,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE address > $1 "
"ORDER BY address "
@@ -152,7 +152,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE subnet_id = $1"},
@@ -162,7 +162,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE lower(hostname) = $1"},
@@ -172,7 +172,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
"ORDER BY expire "
@@ -184,7 +184,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = $1 and address > $2 "
"ORDER BY address "
@@ -196,7 +196,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = $1 and address > $2 "
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
@@ -210,7 +210,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = $1 and address > $2 "
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
@@ -226,7 +226,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE relay_id = $1 and address > $2 "
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
@@ -240,7 +240,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = $1 and address > $2 "
"ORDER BY address "
@@ -252,7 +252,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = $1 and address > $2 "
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
@@ -266,7 +266,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = $1 and address > $2 "
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
@@ -282,7 +282,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id "
+ "state, user_context, relay_id, remote_id, pool_id "
"FROM lease4 "
"WHERE remote_id = $1 and address > $2 "
"and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
@@ -297,7 +297,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6"},
// GET_LEASE6_ADDR
@@ -307,7 +307,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE address = $1 AND lease_type = $2"},
@@ -318,7 +318,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE duid = $1 AND iaid = $2 AND lease_type = $3"},
@@ -329,7 +329,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE lease_type = $1 "
"AND duid = $2 AND iaid = $3 AND subnet_id = $4"},
@@ -341,7 +341,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE address > $1 "
"ORDER BY address "
@@ -380,7 +380,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE subnet_id = $1"},
@@ -391,7 +391,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE duid = $1"},
@@ -402,7 +402,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE lower(hostname) = $1"},
@@ -414,7 +414,7 @@ PgSqlTaggedStatement tagged_statements[] = {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context "
+ "state, user_context, pool_id "
"FROM lease6 "
"WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
"ORDER BY expire "
@@ -435,52 +435,52 @@ PgSqlTaggedStatement tagged_statements[] = {
"LIMIT $3"},
// INSERT_LEASE4
- { 13, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
+ { 14, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_BOOL, OID_BOOL, OID_VARCHAR, OID_INT8, OID_TEXT, OID_BYTEA,
- OID_BYTEA },
+ OID_BYTEA, OID_INT8 },
"insert_lease4",
"INSERT INTO lease4(address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context, relay_id, remote_id) "
- "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"},
+ "state, user_context, relay_id, remote_id, pool_id) "
+ "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)"},
// INSERT_LEASE6
- { 18, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
+ { 19, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_INT8, OID_INT2, OID_INT8, OID_INT2, OID_BOOL, OID_BOOL,
OID_VARCHAR, OID_BYTEA, OID_INT2, OID_INT2, OID_INT8, OID_TEXT,
- OID_BYTEA },
+ OID_BYTEA, OID_INT8},
"insert_lease6",
"INSERT INTO lease6(address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
- "state, user_context, binaddr) "
- "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)"},
+ "state, user_context, binaddr, pool_id) "
+ "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)"},
// UPDATE_LEASE4
- { 15, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
+ { 16, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_BOOL, OID_BOOL, OID_VARCHAR, OID_INT8, OID_TEXT, OID_BYTEA,
- OID_BYTEA, OID_INT8, OID_TIMESTAMP },
+ OID_BYTEA, OID_INT8, OID_INT8, OID_TIMESTAMP },
"update_lease4",
"UPDATE lease4 SET address = $1, hwaddr = $2, "
"client_id = $3, valid_lifetime = $4, expire = $5, "
"subnet_id = $6, fqdn_fwd = $7, fqdn_rev = $8, hostname = $9, "
- "state = $10, user_context = $11, relay_id = $12, remote_id = $13 "
- "WHERE address = $14 AND expire = $15"},
+ "state = $10, user_context = $11, relay_id = $12, remote_id = $13, pool_id = $14 "
+ "WHERE address = $15 AND expire = $16"},
// UPDATE_LEASE6
- { 20, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8, OID_INT8,
+ { 21, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8, OID_INT8,
OID_INT2, OID_INT8, OID_INT2, OID_BOOL, OID_BOOL, OID_VARCHAR,
OID_BYTEA, OID_INT2, OID_INT2,
- OID_INT8, OID_TEXT, OID_BYTEA, OID_VARCHAR, OID_TIMESTAMP },
+ OID_INT8, OID_TEXT, OID_BYTEA, OID_INT8, OID_VARCHAR, OID_TIMESTAMP },
"update_lease6",
"UPDATE lease6 SET address = $1, duid = $2, "
"valid_lifetime = $3, expire = $4, subnet_id = $5, "
"pref_lifetime = $6, lease_type = $7, iaid = $8, "
"prefix_len = $9, fqdn_fwd = $10, fqdn_rev = $11, hostname = $12, "
"hwaddr = $13, hwtype = $14, hwaddr_source = $15, "
- "state = $16, user_context = $17, binaddr = $18 "
- "WHERE address = $19 AND expire = $20"},
+ "state = $16, user_context = $17, binaddr = $18, pool_id = $19 "
+ "WHERE address = $20 AND expire = $21"},
// ALL_LEASE4_STATS
{ 0, { OID_NONE },
@@ -575,9 +575,9 @@ public:
PgSqlLeaseExchange()
: addr_str_(""), hwaddr_length_(0), hwaddr_(hwaddr_length_),
valid_lifetime_(0), valid_lifetime_str_(""), expire_(0),
- expire_str_(""), subnet_id_(0), subnet_id_str_(""), cltt_(0),
- fqdn_fwd_(false), fqdn_rev_(false), hostname_(""), state_str_(""),
- user_context_(""), addr_bin_(16) {
+ expire_str_(""), subnet_id_(0), subnet_id_str_(""), pool_id_(0),
+ pool_id_str_(""), cltt_(0), fqdn_fwd_(false), fqdn_rev_(false),
+ hostname_(""), state_str_(""), user_context_(""), addr_bin_(16) {
}
virtual ~PgSqlLeaseExchange(){}
@@ -596,6 +596,8 @@ protected:
std::string expire_str_;
uint32_t subnet_id_;
std::string subnet_id_str_;
+ uint32_t pool_id_;
+ std::string pool_id_str_;
time_t cltt_;
bool fqdn_fwd_;
bool fqdn_rev_;
@@ -627,8 +629,9 @@ private:
static const size_t USER_CONTEXT_COL = 10;
static const size_t RELAY_ID_COL = 11;
static const size_t REMOTE_ID_COL = 12;
+ static const size_t POOL_ID_COL = 13;
/// @brief Number of columns in the table holding DHCPv4 leases.
- static const size_t LEASE_COLUMNS = 13;
+ static const size_t LEASE_COLUMNS = 14;
public:
@@ -637,7 +640,7 @@ public:
: lease_(), addr4_(0), client_id_length_(0),
relay_id_length_(0), remote_id_length_(0) {
- BOOST_STATIC_ASSERT(12 < LEASE_COLUMNS);
+ BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
memset(hwaddr_buffer_, 0, sizeof(hwaddr_buffer_));
memset(client_id_buffer_, 0, sizeof(client_id_buffer_));
@@ -753,6 +756,8 @@ public:
bind_array.addNull();
}
+ pool_id_str_ = boost::lexical_cast<std::string>(lease->pool_id_);
+ bind_array.add(pool_id_str_);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
"Could not create bind array from Lease4: "
@@ -820,6 +825,8 @@ public:
convertFromBytea(r, row, REMOTE_ID_COL, remote_id_buffer_,
sizeof(remote_id_buffer_), remote_id_length_);
+ getColumnValue(r, row , POOL_ID_COL, pool_id_);
+
Lease4Ptr result(boost::make_shared<Lease4>(addr4_, hwaddr,
client_id_buffer_,
client_id_length_,
@@ -843,6 +850,8 @@ public:
remote_id_buffer_ + remote_id_length_);
}
+ result->pool_id_ = pool_id_;
+
return (result);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
@@ -856,16 +865,16 @@ private:
/// @brief Lease4 object currently being sent to the database.
/// Storing this value ensures that it remains in scope while any bindings
/// that refer to its contents are in use.
- Lease4Ptr lease_;
+ Lease4Ptr lease_;
/// @brief Lease4 specific members for binding and conversion.
- uint32_t addr4_;
- size_t client_id_length_;
- uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
- size_t relay_id_length_;
- uint8_t relay_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
- size_t remote_id_length_;
- uint8_t remote_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
+ uint32_t addr4_;
+ size_t client_id_length_;
+ uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
+ size_t relay_id_length_;
+ uint8_t relay_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
+ size_t remote_id_length_;
+ uint8_t remote_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
};
/// @brief Supports exchanging IPv6 leases with PostgreSQL.
@@ -877,27 +886,28 @@ private:
/// column labels for logging. Note that their numeric order
/// MUST match that of the column order in the Lease6 table.
//@{
- static const int ADDRESS_COL = 0;
- static const int DUID_COL = 1;
- static const int VALID_LIFETIME_COL = 2;
- static const int EXPIRE_COL = 3;
- static const int SUBNET_ID_COL = 4;
- static const int PREF_LIFETIME_COL = 5;
- static const int LEASE_TYPE_COL = 6;
- static const int IAID_COL = 7;
- static const int PREFIX_LEN_COL = 8;
- static const int FQDN_FWD_COL = 9;
- static const int FQDN_REV_COL = 10;
- static const int HOSTNAME_COL = 11;
- static const int HWADDR_COL = 12;
- static const int HWTYPE_COL = 13;
- static const int HWADDR_SOURCE_COL = 14;
- static const int STATE_COL = 15;
- static const int USER_CONTEXT_COL = 16;
- static const int BINADDR_COL = 17;
+ static const size_t ADDRESS_COL = 0;
+ static const size_t DUID_COL = 1;
+ static const size_t VALID_LIFETIME_COL = 2;
+ static const size_t EXPIRE_COL = 3;
+ static const size_t SUBNET_ID_COL = 4;
+ static const size_t PREF_LIFETIME_COL = 5;
+ static const size_t LEASE_TYPE_COL = 6;
+ static const size_t IAID_COL = 7;
+ static const size_t PREFIX_LEN_COL = 8;
+ static const size_t FQDN_FWD_COL = 9;
+ static const size_t FQDN_REV_COL = 10;
+ static const size_t HOSTNAME_COL = 11;
+ static const size_t HWADDR_COL = 12;
+ static const size_t HWTYPE_COL = 13;
+ static const size_t HWADDR_SOURCE_COL = 14;
+ static const size_t STATE_COL = 15;
+ static const size_t USER_CONTEXT_COL = 16;
+ static const size_t BINADDR_COL = 17;
+ static const size_t POOL_ID_COL = 18;
//@}
/// @brief Number of columns in the table holding DHCPv6 leases.
- static const size_t LEASE_COLUMNS = 18;
+ static const size_t LEASE_COLUMNS = 19;
public:
@@ -932,7 +942,7 @@ public:
preferred_lifetime_str_(""), hwtype_(0), hwtype_str_(""),
hwaddr_source_(0), hwaddr_source_str_("") {
- BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
+ BOOST_STATIC_ASSERT(18 < LEASE_COLUMNS);
memset(duid_buffer_, 0, sizeof(duid_buffer_));
@@ -1072,6 +1082,9 @@ public:
addr_bin_ = lease_->addr_.toBytes();
bind_array.add(addr_bin_);
+
+ pool_id_str_ = boost::lexical_cast<std::string>(lease->pool_id_);
+ bind_array.add(pool_id_str_);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
"Could not create bind array from Lease6: "
@@ -1160,6 +1173,8 @@ public:
}
}
+ getColumnValue(r, row , POOL_ID_COL, pool_id_);
+
Lease6Ptr result(boost::make_shared<Lease6>(lease_type_, addr,
duid_ptr,
iaid_u_.uval_,
@@ -1178,6 +1193,8 @@ public:
result->setContext(ctx);
}
+ result->pool_id_ = pool_id_;
+
return (result);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
@@ -1219,7 +1236,7 @@ private:
/// @brief Lease6 object currently being sent to the database.
/// Storing this value ensures that it remains in scope while any bindings
/// that refer to its contents are in use.
- Lease6Ptr lease_;
+ Lease6Ptr lease_;
/// @brief Lease6 specific members for binding and conversion.
//@{
diff --git a/src/lib/dhcpsrv/pool.cc b/src/lib/dhcpsrv/pool.cc
index a3eceb96cf..177513e7e3 100644
--- a/src/lib/dhcpsrv/pool.cc
+++ b/src/lib/dhcpsrv/pool.cc
@@ -20,9 +20,8 @@ namespace dhcp {
Pool::Pool(Lease::Type type, const isc::asiolink::IOAddress& first,
const isc::asiolink::IOAddress& last)
- : id_(getNextID()), first_(first), last_(last), type_(type),
- capacity_(0), cfg_option_(new CfgOption()), client_class_(""),
- permutation_() {
+ : id_(0), first_(first), last_(last), type_(type), capacity_(0),
+ cfg_option_(new CfgOption()), client_class_(""), permutation_() {
}
bool Pool::inRange(const isc::asiolink::IOAddress& addr) const {
diff --git a/src/lib/dhcpsrv/pool.h b/src/lib/dhcpsrv/pool.h
index 368cc6e0b6..f004dc5524 100644
--- a/src/lib/dhcpsrv/pool.h
+++ b/src/lib/dhcpsrv/pool.h
@@ -35,14 +35,26 @@ public:
/// @note:
/// PoolType enum was removed. Please use Lease::Type instead
- /// @brief returns Pool-id
+ /// @brief Returns Pool-id
+ ///
+ /// Pool-id is an unique value that can be used to identify a pool within a
+ /// subnet or shared network.
///
/// @return pool-id value
- /// Pool-id is an unique value that can be used to identify a pool.
- uint32_t getId() const {
+ uint64_t getID() const {
return (id_);
}
+ /// @brief Sets Pool-id
+ ///
+ /// Pool-id is an unique value that can be used to identify a pool within a
+ /// subnet or shared network.
+ ///
+ /// @param id value to be set
+ void setID(const uint64_t id) {
+ id_ = id;
+ }
+
/// @brief Returns the first address in a pool.
///
/// @return first address in a pool
@@ -77,8 +89,7 @@ public:
/// We need Pool to be a polymorphic class, so we could dynamic cast
/// from PoolPtr to Pool6Ptr if we need to. A class becomes polymorphic,
/// when there is at least one virtual method.
- virtual ~Pool() {
- }
+ virtual ~Pool() = default;
/// @brief Returns the number of all leases in this pool.
///
@@ -181,18 +192,11 @@ protected:
const isc::asiolink::IOAddress& first,
const isc::asiolink::IOAddress& last);
- /// @brief returns the next unique Pool-ID
- ///
- /// @return the next unique Pool-ID
- static uint32_t getNextID() {
- static uint32_t id = 0;
- return (id++);
- }
-
/// @brief pool-id
///
- /// This ID is used to identify this specific pool.
- uint32_t id_;
+ /// This id is an unique value that can be used to identify a pool within a
+ /// subnet or shared network.
+ uint64_t id_;
/// @brief The first address in a pool
isc::asiolink::IOAddress first_;
@@ -494,9 +498,7 @@ typedef boost::shared_ptr<Pool> PoolPtr;
/// @brief a container for either IPv4 or IPv6 Pools
typedef std::vector<PoolPtr> PoolCollection;
-
} // end of isc::dhcp namespace
} // end of isc namespace
-
#endif // POOL_H
diff --git a/src/lib/dhcpsrv/random_allocator.cc b/src/lib/dhcpsrv/random_allocator.cc
index e06cc54575..4d4643b94d 100644
--- a/src/lib/dhcpsrv/random_allocator.cc
+++ b/src/lib/dhcpsrv/random_allocator.cc
@@ -28,7 +28,7 @@ RandomAllocator::pickAddressInternal(const ClientClasses& client_classes,
const IdentifierBaseTypePtr&,
const IOAddress&) {
auto subnet = subnet_.lock();
- auto pools = subnet->getPools(pool_type_);
+ const auto& pools = subnet->getPools(pool_type_);
// Let's first iterate over the pools and identify the ones that
// meet client class criteria. Then, segregate these pools into
@@ -59,7 +59,7 @@ RandomAllocator::pickAddressInternal(const ClientClasses& client_classes,
if (!available.empty()) {
// There are pools with available addresses. Let's randomly
// pick one of these pools and get next available address.
- pool = pools[available[getRandomNumber(available.size()-1)]];
+ pool = pools[available[getRandomNumber(available.size() - 1)]];
} else if (!exhausted.empty()) {
// All pools have been exhausted. We will start offering the same
@@ -69,7 +69,7 @@ RandomAllocator::pickAddressInternal(const ClientClasses& client_classes,
getPoolState(pools[e])->getPermutation()->reset();
}
// Get random pool from those we just reset.
- pool = pools[exhausted[getRandomNumber(exhausted.size()-1)]];
+ pool = pools[exhausted[getRandomNumber(exhausted.size() - 1)]];
}
// If pool has been found, let's get next address.
@@ -91,7 +91,7 @@ RandomAllocator::pickPrefixInternal(const ClientClasses& client_classes,
const IOAddress&,
uint8_t hint_prefix_length) {
auto subnet = subnet_.lock();
- auto pools = subnet->getPools(pool_type_);
+ const auto& pools = subnet->getPools(pool_type_);
// Let's first iterate over the pools and identify the ones that
// meet client class criteria. Then, segragate these pools into
diff --git a/src/lib/dhcpsrv/subnet.cc b/src/lib/dhcpsrv/subnet.cc
index fca60a5829..1f7f75105e 100644
--- a/src/lib/dhcpsrv/subnet.cc
+++ b/src/lib/dhcpsrv/subnet.cc
@@ -40,7 +40,8 @@ namespace {
///
/// @return true if prefix is lower than the first address in the pool.
bool
-prefixLessThanFirstAddress(const IOAddress& prefix, const PoolPtr& pool) {
+prefixLessThanFirstAddress(const IOAddress& prefix,
+ const PoolPtr& pool) {
return (prefix < pool->getFirstAddress());
}
@@ -53,9 +54,10 @@ prefixLessThanFirstAddress(const IOAddress& prefix, const PoolPtr& pool) {
/// @return true if first prefix of the first pool is smaller than
/// the first address of the second pool.
bool
-comparePoolFirstAddress(const PoolPtr& pool1, const PoolPtr& pool2) {
+comparePoolFirstAddress(const PoolPtr& pool1,
+ const PoolPtr& pool2) {
return (pool1->getFirstAddress() < pool2->getFirstAddress());
-};
+}
}
@@ -398,7 +400,7 @@ const PoolPtr Subnet::getPool(Lease::Type type, const isc::asiolink::IOAddress&
// check if the type is valid (and throw if it isn't)
checkType(type);
- const PoolCollection& pools = getPools(type);
+ const auto& pools = getPools(type);
PoolPtr candidate;
@@ -411,7 +413,7 @@ const PoolPtr Subnet::getPool(Lease::Type type, const isc::asiolink::IOAddress&
// matching prefix we use decrement operator to go back by one item.
// If returned iterator points to begin it means that prefixes in all
// pools are greater than out prefix, and thus there is no match.
- PoolCollection::const_iterator ub =
+ auto ub =
std::upper_bound(pools.begin(), pools.end(), hint,
prefixLessThanFirstAddress);
@@ -445,12 +447,12 @@ const PoolPtr Subnet::getPool(Lease::Type type,
// check if the type is valid (and throw if it isn't)
checkType(type);
- const PoolCollection& pools = getPools(type);
+ const auto& pools = getPools(type);
PoolPtr candidate;
if (!pools.empty()) {
- PoolCollection::const_iterator ub =
+ auto ub =
std::upper_bound(pools.begin(), pools.end(), hint,
prefixLessThanFirstAddress);
@@ -520,6 +522,12 @@ Subnet::addPool(const PoolPtr& pool) {
// Sort pools by first address.
std::sort(pools_writable.begin(), pools_writable.end(),
comparePoolFirstAddress);
+
+ uint64_t index = 0;
+ for (const auto& pool : pools_writable) {
+ pool->setID(index);
+ index++;
+ }
}
void
@@ -535,9 +543,8 @@ Subnet::inPool(Lease::Type type, const isc::asiolink::IOAddress& addr) const {
return (false);
}
- const PoolCollection& pools = getPools(type);
-
- for (auto const& pool : pools) {
+ const auto& pools = getPools(type);
+ for (const auto& pool : pools) {
if (pool->inRange(addr)) {
return (true);
}
@@ -556,9 +563,8 @@ Subnet::inPool(Lease::Type type,
return (false);
}
- const PoolCollection& pools = getPools(type);
-
- for (auto const& pool : pools) {
+ const auto& pools = getPools(type);
+ for (const auto& pool : pools) {
if (!pool->clientSupported(client_classes)) {
continue;
}
@@ -572,7 +578,7 @@ Subnet::inPool(Lease::Type type,
bool
Subnet::poolOverlaps(const Lease::Type& pool_type, const PoolPtr& pool) const {
- const PoolCollection& pools = getPools(pool_type);
+ const auto& pools = getPools(pool_type);
// If no pools, we don't overlap. Nothing to do.
if (pools.empty()) {
@@ -593,7 +599,7 @@ Subnet::poolOverlaps(const Lease::Type& pool_type, const PoolPtr& pool) const {
// greater than F2). prefixLessThanPoolAddress with the first argument
// set to "true" is the custom comparison function for upper_bound, which
// compares F2 with the first addresses of the existing pools.
- PoolCollection::const_iterator pool3_it =
+ const auto pool3_it =
std::upper_bound(pools.begin(), pools.end(), pool->getFirstAddress(),
prefixLessThanFirstAddress);
@@ -804,9 +810,9 @@ Subnet4::toElement() const {
isc::data::merge(map, d4o6.toElement());
// Set pools
- const PoolCollection& pools = getPools(Lease::TYPE_V4);
+ const auto& pools = getPools(Lease::TYPE_V4);
ElementPtr pool_list = Element::createList();
- for (auto const& pool : pools) {
+ for (const auto& pool : pools) {
// Add the formated pool to the list
pool_list->add(pool->toElement());
}
@@ -912,18 +918,18 @@ Subnet6::toElement() const {
merge(map, network_map);
// Set pools
- const PoolCollection& pools = getPools(Lease::TYPE_NA);
+ const auto& pools = getPools(Lease::TYPE_NA);
ElementPtr pool_list = Element::createList();
- for (auto const& pool : pools) {
+ for (const auto& pool : pools) {
// Add the formated pool to the list
pool_list->add(pool->toElement());
}
map->set("pools", pool_list);
// Set pd-pools
- const PoolCollection& pdpools = getPools(Lease::TYPE_PD);
+ const auto& pdpools = getPools(Lease::TYPE_PD);
ElementPtr pdpool_list = Element::createList();
- for (auto const& pool : pdpools) {
+ for (const auto& pool : pdpools) {
// Add the formated pool to the list
pdpool_list->add(pool->toElement());
}
diff --git a/src/lib/dhcpsrv/subnet.h b/src/lib/dhcpsrv/subnet.h
index a875bbeac8..723111d08e 100644
--- a/src/lib/dhcpsrv/subnet.h
+++ b/src/lib/dhcpsrv/subnet.h
@@ -80,7 +80,9 @@ public:
/// @brief Returns unique ID for that subnet.
///
/// @return unique ID for that subnet
- SubnetID getID() const { return (id_); }
+ SubnetID getID() const {
+ return (id_);
+ }
/// @brief Returns subnet parameters (prefix and prefix length).
///
@@ -128,7 +130,7 @@ public:
/// If there is no pool that the address belongs to (hint is invalid), other
/// pool of specified type will be returned.
///
- /// With anypool set to true, this is means give me a pool, preferably
+ /// With anypool set to true, this means give me a pool, preferably
/// the one that addr belongs to. With anypool set to false, it means
/// give me a pool that addr belongs to (or NULL if here is no such pool)
///
@@ -791,6 +793,7 @@ private:
Subnet6& operator=(const Subnet6&) = delete;
/// @brief Returns default address for pool selection
+ ///
/// @return ANY IPv6 address
virtual isc::asiolink::IOAddress default_pool() const {
return (isc::asiolink::IOAddress("::"));
diff --git a/src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc b/src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc
index cbb423da9c..a35cb264e3 100644
--- a/src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc
+++ b/src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc
@@ -268,11 +268,11 @@ TEST_F(CSVLeaseFile4Test, recreate) {
lf.close();
// Check that the contents of the csv file are correct.
EXPECT_EQ("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
"192.0.3.2,00:01:02:03:04:05,,200,200,8,1,1,host.example.com,"
- "2,\n"
+ "2,,0\n"
"192.0.3.10,0d:0e:0a:0d:0b:0e:0e:0f,01:02:03:04,100,100,7,0,"
- "0,,0,{ \"foobar\": true }\n",
+ "0,,0,{ \"foobar\": true },0\n",
io_.readFile());
}
@@ -365,7 +365,6 @@ TEST_F(CSVLeaseFile4Test, mixedSchemaload) {
}
}
-
// Verifies that a lease file with fewer header columns than the
// minimum allowed will not open.
TEST_F(CSVLeaseFile4Test, tooFewHeaderColumns) {
@@ -393,12 +392,12 @@ TEST_F(CSVLeaseFile4Test, invalidHeaderColumn) {
// Verifies that a lease file with more header columns than defined
// columns will downgrade.
TEST_F(CSVLeaseFile4Test, downGrade) {
- // Create 2.0 PLUS a column file
+ // Create 3.0 PLUS a column file
io_.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context,FUTURE_COL\n"
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id,FUTURE_COL\n"
"192.0.2.3,06:07:08:09:3a:bc,,200,200,8,1,1,"
- "three.example.com,2,,BOGUS\n");
+ "three.example.com,2,,0,FUTURE_VALUE\n");
// Lease file should open and report as needing downgrade.
CSVLeaseFile4 lf(filename_);
@@ -433,9 +432,9 @@ TEST_F(CSVLeaseFile4Test, downGrade) {
// if they are in the declined state.
TEST_F(CSVLeaseFile4Test, declinedLeaseTest) {
io_.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.1,,,200,200,8,1,1,host.example.com,0,\n"
- "192.0.2.1,,,200,200,8,1,1,host.example.com,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.1,,,200,200,8,1,1,host.example.com,0,,0\n"
+ "192.0.2.1,,,200,200,8,1,1,host.example.com,1,,0\n");
CSVLeaseFile4 lf(filename_);
ASSERT_NO_THROW(lf.open());
diff --git a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc
index dcba91f489..9ab904324f 100644
--- a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc
+++ b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc
@@ -103,22 +103,22 @@ CSVLeaseFile6Test::writeSampleFile() const {
io_.writeFile("address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n"
+ "hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,200,8,100,0,7,0,1,1,host.example.com,,1,,"
- "1,0\n"
+ "1,0,0\n"
"2001:db8:1::1,,200,200,8,100,0,7,0,1,1,host.example.com,,1,,"
- "1,0\n"
+ "1,0,0\n"
"2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,300,300,6,150,"
"0,8,0,0,0,,,1,,"
- "1,0\n"
+ "1,0,0\n"
"3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,0,200,8,0,2,"
"16,64,0,0,,,1,{ \"foobar\": true },,"
- "1,0\n"
+ "1,0,0\n"
"2001:db8:1::2,00:00:00,200,200,8,100,0,7,0,1,1,host.example.com,,0,,"
- "1,0\n"
+ "1,0,0\n"
"2001:db8:1::3,00:00:00,200,200,8,100,0,7,0,1,1,host.example.com,,1,,"
- "1,0\n");
+ "1,0,0\n");
}
// This test checks the capability to read and parse leases from the file.
@@ -221,7 +221,6 @@ TEST_F(CSVLeaseFile6Test, parse) {
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
-
// Fifth lease is invalid - DUID is empty, state is not DECLINED
{
SCOPED_TRACE("Fifth lease invalid");
@@ -327,14 +326,14 @@ TEST_F(CSVLeaseFile6Test, recreate) {
EXPECT_EQ("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
- "state,user_context,hwtype,hwaddr_source\n"
+ "state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "200,200,8,100,0,7,128,1,1,host.example.com,,0,,,\n"
+ "200,200,8,100,0,7,128,1,1,host.example.com,,0,,,,0\n"
"2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05"
- ",300,300,6,150,0,8,128,0,0,,,0,,,\n"
+ ",300,300,6,150,0,8,128,0,0,,,0,,,,0\n"
"3000:1:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "300,300,10,150,2,7,64,0,0,,,0,{ \"foobar\": true },,\n"
- "2001:db8:2::10,00:00:00,300,300,6,150,0,8,128,0,0,,,1,,,\n",
+ "300,300,10,150,2,7,64,0,0,,,0,{ \"foobar\": true },,,0\n"
+ "2001:db8:2::10,00:00:00,300,300,6,150,0,8,128,0,0,,,1,,,,0\n",
io_.readFile());
}
@@ -501,15 +500,15 @@ TEST_F(CSVLeaseFile6Test, invalidHeaderColumn) {
TEST_F(CSVLeaseFile6Test, downGrade) {
// Create a mixed schema file
io_.writeFile(
- // schema 4.0 header
+ // schema 5.0 header
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source,FUTURE_COLUMN\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id,FUTURE_COLUMN\n"
- // schema 4.0 record
+ // schema 5.0 record
"2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:03,"
"200,200,8,100,0,7,0,1,1,three.example.com,0a:0b:0c:0d:0e,1,"
- "{ \"foobar\": true },1,0,FUTURE_VALUE\n");
+ "{ \"foobar\": true },1,0,0,FUTURE_VALUE\n");
// Open should succeed in the event someone is downgrading.
CSVLeaseFile6 lf(filename_);
@@ -555,13 +554,13 @@ TEST_F(CSVLeaseFile6Test, declinedLeaseTest) {
io_.writeFile("address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n"
+ "hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,00:00:00,"
- "200,200,8,100,0,7,0,1,1,host.example.com,,0,,,\n"
+ "200,200,8,100,0,7,0,1,1,host.example.com,,0,,,,0\n"
"2001:db8:1::1,,"
- "200,200,8,100,0,7,0,1,1,host.example.com,,0,,,\n"
+ "200,200,8,100,0,7,0,1,1,host.example.com,,0,,,,0\n"
"2001:db8:1::1,00:00:00,"
- "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n");
CSVLeaseFile6 lf(filename_);
ASSERT_NO_THROW(lf.open());
@@ -595,7 +594,6 @@ TEST_F(CSVLeaseFile6Test, declinedLeaseTest) {
}
}
-
// Verifies that it is possible to output a lease with very high valid
// lifetime (infinite in RFC2131 terms) and current time, and then read
// back this lease.
diff --git a/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc b/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc
index ee25e16b9b..38a0e01a9d 100644
--- a/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc
@@ -204,7 +204,7 @@ public:
std::stringstream file_content;
file_content << v4_hdr_ << lease << ",dd:de:ba:0d:1b:2e,"
<< "0a:00:01:04,100,100," << static_cast<int>(lease_id)
- << ",0,0,,1,\n";
+ << ",0,0,,1,,0\n";
ASSERT_NO_THROW(CfgMgr::instance().getStagingCfg()->getConsistency()
->setLeaseSanityCheck(sanity));
@@ -223,7 +223,7 @@ public:
}
// Check how many leases were actually loaded.
- ASSERT_EQ( (exp_present ? 1 : 0), storage4_.size());
+ ASSERT_EQ((exp_present ? 1 : 0), storage4_.size());
Lease4Ptr l = getLease<Lease4Ptr>(lease, storage4_);
@@ -268,7 +268,7 @@ public:
file_content << v6_hdr_ << lease << ",dd:de:ba:0d:1b:2e,"
<< "300,300," << static_cast<int>(lease_id) << ",150,"
<< (prefix_len > 0 ? Lease::TYPE_PD : Lease::TYPE_NA)
- << ",8," << prefix_len << ",0,0,,,1,\n";
+ << ",8," << prefix_len << ",0,0,,,1,,,,0\n";
ASSERT_NO_THROW(CfgMgr::instance().getStagingCfg()->getConsistency()
->setLeaseSanityCheck(sanity));
@@ -287,7 +287,7 @@ public:
}
// Check how many leases were actually loaded.
- ASSERT_EQ( (exp_present ? 1 : 0), storage6_.size());
+ ASSERT_EQ((exp_present ? 1 : 0), storage6_.size());
Lease6Ptr l = getLease<Lease6Ptr>(lease, storage6_);
@@ -303,12 +303,12 @@ protected:
/// @brief Sets up the header strings
virtual void SetUp() {
v4_hdr_ = "address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
v6_hdr_ = "address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n";
+ "hwtype,hwaddr_source,pool_id\n";
}
};
@@ -338,18 +338,18 @@ TEST_F(LeaseFileLoaderTest, loadWrite4) {
std::string test_str;
std::string a_1 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,200,8,1,1,host.example.com,1,"
- "{ \"foobar\": true }\n";
+ "{ \"foobar\": true },0\n";
std::string a_2 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,500,8,1,1,host.example.com,1,"
- "{ \"foobar\": true }\n";
+ "{ \"foobar\": true },0\n";
std::string b_1 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,100,7,0,0,,1,\n";
+ "100,100,7,0,0,,1,,0\n";
std::string b_2 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,135,7,0,0,,1,\n";
+ "100,135,7,0,0,,1,,0\n";
std::string c_1 = "192.0.2.3,,,"
- "200,200,8,1,1,host.example.com,0,\n";
+ "200,200,8,1,1,host.example.com,0,,0\n";
// Create lease file with leases for 192.0.2.1, 192.0.3.15. The lease
// entry for the 192.0.2.3 is invalid (lacks HW address and client id)
@@ -415,14 +415,14 @@ TEST_F(LeaseFileLoaderTest, loadWrite4) {
TEST_F(LeaseFileLoaderTest, loadWrite4LeaseRemove) {
std::string test_str;
std::string a_1 = "192.0.2.1,06:07:08:09:0a:bc,,"
- "200,200,8,1,1,host.example.com,1,\n";
+ "200,200,8,1,1,host.example.com,1,,0\n";
std::string a_2 = "192.0.2.1,06:07:08:09:0a:bc,,"
- "0,500,8,1,1,host.example.com,1,\n";
+ "0,500,8,1,1,host.example.com,1,,0\n";
std::string b_1 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,100,7,0,0,,1,\n";
+ "100,100,7,0,0,,1,,0\n";
std::string b_2 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
- "100,135,7,0,0,,1,\n";
+ "100,135,7,0,0,,1,,0\n";
// Create lease file in which one of the entries for 192.0.2.1
@@ -466,7 +466,7 @@ TEST_F(LeaseFileLoaderTest, loadWrite4LeaseRemove) {
TEST_F(LeaseFileLoaderTest, maxRowErrors4) {
// We have 9 rows: 2 that are good, 7 that are flawed (too few fields).
std::vector<std::string> rows = {
- "192.0.2.100,08:00:27:25:d3:f4,31:31:31:31,3600,1565356064,1,0,0,,0,\n",
+ "192.0.2.100,08:00:27:25:d3:f4,31:31:31:31,3600,1565356064,1,0,0,,0,,0\n",
"192.0.2.101,FF:FF:FF:FF:FF:01,32:32:32:31,3600,1565356073,1,0,0\n",
"192.0.2.102,FF:FF:FF:FF:FF:02,32:32:32:32,3600,1565356073,1,0,0\n",
"192.0.2.103,FF:FF:FF:FF:FF:03,32:32:32:33,3600,1565356073,1,0,0\n",
@@ -474,7 +474,7 @@ TEST_F(LeaseFileLoaderTest, maxRowErrors4) {
"192.0.2.105,FF:FF:FF:FF:FF:05,32:32:32:35,3600,1565356073,1,0,0\n",
"192.0.2.106,FF:FF:FF:FF:FF:06,32:32:32:36,3600,1565356073,1,0,0\n",
"192.0.2.107,FF:FF:FF:FF:FF:07,32:32:32:37,3600,1565356073,1,0,0\n",
- "192.0.2.108,08:00:27:25:d3:f4,32:32:32:32,3600,1565356073,1,0,0,,0,\n"
+ "192.0.2.108,08:00:27:25:d3:f4,32:32:32:32,3600,1565356073,1,0,0,,0,,0\n"
};
std::ostringstream os;
@@ -524,20 +524,20 @@ TEST_F(LeaseFileLoaderTest, loadWrite6) {
std::string test_str;
std::string a_1 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,200,8,100,0,7,0,1,1,host.example.com,,1,"
- "{ \"foobar\": true },,\n";
+ "{ \"foobar\": true },,,0\n";
std::string a_2 = "2001:db8:1::1,,"
"200,200,8,100,0,7,0,1,1,host.example.com,,1,"
- "{ \"foobar\": true },,\n";
+ "{ \"foobar\": true },,,0\n";
std::string a_3 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,400,8,100,0,7,0,1,1,host.example.com,,1,"
- "{ \"foobar\": true },,\n";
+ "{ \"foobar\": true },,,0\n";
std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,300,6,150,0,8,0,0,0,,,1,,,\n";
+ "300,300,6,150,0,8,0,0,0,,,1,,,,0\n";
std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,800,6,150,0,8,0,0,0,,,1,,,\n";
+ "300,800,6,150,0,8,0,0,0,,,1,,,,0\n";
std::string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "100,200,8,0,2,16,64,0,0,,,1,,,\n";
+ "100,200,8,0,2,16,64,0,0,,,1,,,,0\n";
// Create a lease file with three valid leases: 2001:db8:1::1,
@@ -604,14 +604,14 @@ TEST_F(LeaseFileLoaderTest, loadWrite6) {
TEST_F(LeaseFileLoaderTest, loadWrite6LeaseRemove) {
std::string test_str;
std::string a_1 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,\n";
+ "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n";
std::string a_2 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
- "0,400,8,100,0,7,0,1,1,host.example.com,,1,,,\n";
+ "0,400,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n";
std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,300,6,150,0,8,0,0,0,,,1,,,\n";
+ "300,300,6,150,0,8,0,0,0,,,1,,,,0\n";
std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
- "300,800,6,150,0,8,0,0,0,,,1,,,\n";
+ "300,800,6,150,0,8,0,0,0,,,1,,,,0\n";
// Create lease file in which one of the entries for the 2001:db8:1::1
// has valid lifetime set to 0, in which case the lease should be
@@ -656,7 +656,7 @@ TEST_F(LeaseFileLoaderTest, maxRowErrors6) {
// We have 9 rows: 2 that are good, 7 that are flawed (too few fields).
std::vector<std::string> rows = {
"3002::01,00:03:00:01:08:00:27:25:d3:01,30,1565361388,2,20,0,"
- "11189196,128,0,0,,08:00:27:25:d3:f4,0,\n",
+ "11189196,128,0,0,,08:00:27:25:d3:f4,0,,,,0\n",
"3002::02,00:03:00:01:08:00:27:25:d3:02,30,1565361388,2,20,0\n",
"3002::03,00:03:00:01:08:00:27:25:d3:03,30,1565361388,2,20,0\n",
"3002::04,00:03:00:01:08:00:27:25:d3:04,30,1565361388,2,20,0\n",
@@ -665,7 +665,7 @@ TEST_F(LeaseFileLoaderTest, maxRowErrors6) {
"3002::07,00:03:00:01:08:00:27:25:d3:07,30,1565361388,2,20,0\n",
"3002::08,00:03:00:01:08:00:27:25:d3:08,30,1565361388,2,20,0\n",
"3002::09,00:03:00:01:08:00:27:25:d3:09,30,1565361388,2,20,0,"
- "11189196,128,0,0,,08:00:27:25:d3:f4,0,\n"
+ "11189196,128,0,0,,08:00:27:25:d3:f4,0,,,,0\n"
};
std::ostringstream os;
@@ -713,8 +713,8 @@ TEST_F(LeaseFileLoaderTest, maxRowErrors6) {
// and comparing that with the expected value.
TEST_F(LeaseFileLoaderTest, loadWriteLeaseWithZeroLifetime) {
std::string test_str;
- std::string a_1 = "192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,,1,\n";
- std::string b_2 = "192.0.2.3,06:07:08:09:0a:bd,,0,200,8,1,1,,1,\n";
+ std::string a_1 = "192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,,1,,0\n";
+ std::string b_2 = "192.0.2.3,06:07:08:09:0a:bd,,0,200,8,1,1,,1,,0\n";
// Create lease file. The second lease has a valid lifetime of 0.
test_str = v4_hdr_ + a_1 + b_2;
diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc
index 2321d8ecc5..35cdb52394 100644
--- a/src/lib/dhcpsrv/tests/lease_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_unittest.cc
@@ -488,6 +488,7 @@ TEST_F(Lease4Test, toText) {
<< "Hardware addr: " << hwaddr_->toText(false) << "\n"
<< "Client id: " << clientid_->toText() << "\n"
<< "Subnet ID: 789\n"
+ << "Pool ID: 0\n"
<< "State: default\n"
<< "Relay ID: (none)\n"
<< "Remote ID: (none)\n"
@@ -507,6 +508,7 @@ TEST_F(Lease4Test, toText) {
<< "Hardware addr: (none)\n"
<< "Client id: (none)\n"
<< "Subnet ID: 789\n"
+ << "Pool ID: 0\n"
<< "State: default\n"
<< "Relay ID: (none)\n"
<< "Remote ID: (none)\n";
@@ -532,6 +534,7 @@ TEST_F(Lease4Test, toElement) {
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 0,"
"\"user-context\": { \"foobar\": 1234 },"
"\"valid-lft\": 3600 "
"}";
@@ -551,6 +554,7 @@ TEST_F(Lease4Test, toElement) {
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 0,"
"\"valid-lft\": 3600 "
"}";
@@ -569,6 +573,7 @@ TEST_F(Lease4Test, toElement) {
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 0,"
"\"valid-lft\": 3600 "
"}";
@@ -587,6 +592,7 @@ TEST_F(Lease4Test, fromElement) {
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 5,"
"\"user-context\": { \"foo\": \"bar\" },"
"\"valid-lft\": 3600 "
"}";
@@ -598,6 +604,7 @@ TEST_F(Lease4Test, fromElement) {
EXPECT_EQ("192.0.2.3", lease->addr_.toText());
EXPECT_EQ(789, static_cast<uint32_t>(lease->subnet_id_));
+ EXPECT_EQ(5, static_cast<uint32_t>(lease->pool_id_));
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ("hwtype=1 08:00:2b:02:3f:4e", lease->hwaddr_->toText());
ASSERT_TRUE(lease->client_id_);
@@ -649,6 +656,9 @@ TEST_F(Lease4Test, fromElementInvalidValues) {
testInvalidElement<Lease4>(json, "subnet-id", std::string("xyz"));
testInvalidElement<Lease4>(json, "subnet-id", -5, false);
testInvalidElement<Lease4>(json, "subnet-id", 0x100000000, false);
+ testInvalidElement<Lease4>(json, "pool-id", std::string("xyz"), false);
+ testInvalidElement<Lease4>(json, "pool-id", -5, false);
+ testInvalidElement<Lease4>(json, "pool-id", 0x100000000, false);
testInvalidElement<Lease4>(json, "valid-lft", std::string("xyz"));
testInvalidElement<Lease4>(json, "valid-lft", -3, false);
testInvalidElement<Lease4>(json, "user-context", "[ ]", false);
@@ -710,7 +720,7 @@ Lease6 createLease6(const std::string& hostname, const bool fqdn_fwd,
// Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
// This test checks if the Lease6 structure can be instantiated correctly
-TEST(Lease6Test, Lease6ConstructorDefault) {
+TEST(Lease6Test, constructorDefault) {
// check a variety of addresses with different bits set.
const char* ADDRESS[] = {
@@ -755,7 +765,7 @@ TEST(Lease6Test, Lease6ConstructorDefault) {
// This test verifies that the Lease6 constructor which accepts FQDN data,
// sets the data correctly for the lease.
-TEST(Lease6Test, Lease6ConstructorWithFQDN) {
+TEST(Lease6Test, constructorWithFQDN) {
// check a variety of addresses with different bits set.
const char* ADDRESS[] = {
@@ -935,7 +945,7 @@ TEST(Lease6Test, operatorEquals) {
}
// Checks if lease expiration is calculated properly
-TEST(Lease6Test, Lease6Expired) {
+TEST(Lease6Test, lease6Expired) {
const IOAddress addr("2001:db8:1::456");
const uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
const DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
@@ -1064,6 +1074,7 @@ TEST(Lease6Test, toText) {
<< "DUID: 00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f\n"
<< "Hardware addr: " << hwaddr->toText(false) << "\n"
<< "Subnet ID: 5678\n"
+ << "Pool ID: 0\n"
<< "State: declined\n"
<< "User context: { \"foobar\": 1234 }\n";
@@ -1083,6 +1094,7 @@ TEST(Lease6Test, toText) {
<< "DUID: 00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f\n"
<< "Hardware addr: (none)\n"
<< "Subnet ID: 5678\n"
+ << "Pool ID: 0\n"
<< "State: declined\n";
EXPECT_EQ(expected.str(), lease.toText());
}
@@ -1115,6 +1127,7 @@ TEST(Lease6Test, toElementAddress) {
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 0,"
"\"type\": \"IA_NA\","
"\"user-context\": { \"foobar\": 1234 },"
"\"valid-lft\": 800"
@@ -1137,6 +1150,7 @@ TEST(Lease6Test, toElementAddress) {
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 0,"
"\"type\": \"IA_NA\","
"\"valid-lft\": 800"
"}";
@@ -1158,6 +1172,7 @@ TEST(Lease6Test, toElementAddress) {
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 0,"
"\"type\": \"IA_NA\","
"\"valid-lft\": 800"
"}";
@@ -1214,6 +1229,9 @@ TEST(Lease6Test, toElementPrefix) {
ASSERT_TRUE(l->contains("subnet-id"));
EXPECT_EQ(5678, l->get("subnet-id")->intValue());
+ ASSERT_TRUE(l->contains("pool-id"));
+ EXPECT_EQ(0, l->get("pool-id")->intValue());
+
ASSERT_TRUE(l->contains("state"));
EXPECT_EQ(static_cast<int>(Lease::STATE_DEFAULT),
l->get("state")->intValue());
@@ -1263,6 +1281,7 @@ TEST(Lease6Test, fromElementNA) {
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 5,"
"\"type\": \"IA_NA\","
"\"user-context\": { \"foobar\": 1234 },"
"\"valid-lft\": 800"
@@ -1275,6 +1294,7 @@ TEST(Lease6Test, fromElementNA) {
EXPECT_EQ("2001:db8::1", lease->addr_.toText());
EXPECT_EQ(5678, static_cast<uint32_t>(lease->subnet_id_));
+ EXPECT_EQ(5, static_cast<uint32_t>(lease->pool_id_));
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ("hwtype=1 08:00:2b:02:3f:4e", lease->hwaddr_->toText());
EXPECT_EQ(12345678, lease->cltt_);
@@ -1312,6 +1332,7 @@ TEST(Lease6Test, fromElementPD) {
"\"prefix-len\": 32,"
"\"state\": 0,"
"\"subnet-id\": 1234,"
+ "\"pool-id\": 5,"
"\"type\": \"IA_PD\","
"\"valid-lft\": 600"
"}";
@@ -1323,6 +1344,7 @@ TEST(Lease6Test, fromElementPD) {
EXPECT_EQ("3000::", lease->addr_.toText());
EXPECT_EQ(1234, static_cast<uint32_t>(lease->subnet_id_));
+ EXPECT_EQ(5, static_cast<uint32_t>(lease->pool_id_));
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ("hwtype=1 08:00:2b:02:3f:4e", lease->hwaddr_->toText());
EXPECT_EQ(12345678, lease->cltt_);
@@ -1390,6 +1412,9 @@ TEST(Lease6Test, fromElementInvalidValues) {
testInvalidElement<Lease6>(json, "subnet-id", std::string("xyz"));
testInvalidElement<Lease6>(json, "subnet-id", -5, false);
testInvalidElement<Lease6>(json, "subnet-id", 0x100000000, false);
+ testInvalidElement<Lease6>(json, "pool-id", std::string("xyz"), false);
+ testInvalidElement<Lease6>(json, "pool-id", -5, false);
+ testInvalidElement<Lease6>(json, "pool-id", 0x100000000, false);
testInvalidElement<Lease6>(json, "type", std::string("IA_XY"));
testInvalidElement<Lease6>(json, "type", -3, false);
testInvalidElement<Lease6>(json, "valid-lft", std::string("xyz"));
diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
index 8a8daadf8d..53e8b22caf 100644
--- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
@@ -557,20 +557,20 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup4) {
// stored.
std::string new_file_contents =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
// This string contains the contents of the lease file with exactly
// one lease, but two entries. One of the entries should be removed
// as a result of lease file cleanup.
std::string current_file_contents = new_file_contents +
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{ \"foo\": true }\n"
- "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,1,\n";
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{ \"foo\": true },0\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,1,,0\n";
LeaseFileIO current_file(getLeaseFilePath("leasefile4_0.csv"));
current_file.writeFile(current_file_contents);
std::string previous_file_contents = new_file_contents +
- "192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1,\n"
- "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,1,{ \"bar\": true }\n";
+ "192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,1,{ \"bar\": true },0\n";
LeaseFileIO previous_file(getLeaseFilePath("leasefile4_0.csv.2"));
previous_file.writeFile(previous_file_contents);
@@ -607,15 +607,15 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup4) {
ASSERT_NO_THROW(lease_mgr->addLease(new_lease));
std::string updated_file_contents = new_file_contents +
- "192.0.2.45,00:00:00:00:00:00,,100,100,1,0,0,,0,\n";
+ "192.0.2.45,00:00:00:00:00:00,,100,100,1,0,0,,0,,0\n";
EXPECT_EQ(updated_file_contents, current_file.readFile());
// This string contains the contents of the lease file we
// expect after the LFC run. It has two leases with one
// entry each.
std::string result_file_contents = new_file_contents +
- "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,1,\n"
- "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,1,{ \"bar\": true }\n";
+ "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,1,,0\n"
+ "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,1,{ \"bar\": true },0\n";
// The LFC should have created a file with the two leases and moved it
// to leasefile4_0.csv.2
@@ -635,24 +635,24 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) {
"address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n";
+ "hwtype,hwaddr_source,pool_id\n";
// This string contains the contents of the lease file with exactly
// one lease, but two entries. One of the entries should be removed
// as a result of lease file cleanup.
std::string current_file_contents = new_file_contents +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
- "8,100,0,7,0,1,1,,,1,,,\n"
+ "8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,\n";
+ "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n";
LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
current_file.writeFile(current_file_contents);
std::string previous_file_contents = new_file_contents +
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,200,"
- "8,100,0,7,0,1,1,,,1,{ \"bar\": true },,\n"
+ "8,100,0,7,0,1,1,,,1,{ \"bar\": true },,,0\n"
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,,1,,\n";
+ "8,100,0,7,0,1,1,,,1,,,,0\n";
LeaseFileIO previous_file(getLeaseFilePath("leasefile6_0.csv.2"));
previous_file.writeFile(previous_file_contents);
@@ -690,7 +690,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) {
std::string update_file_contents = new_file_contents +
"3000::1,00:00:00:00:00:00:00:00:00:00:00:00:00,400,"
- "400,2,300,0,123,128,0,0,,,0,,,\n";
+ "400,2,300,0,123,128,0,0,,,0,,,,0\n";
EXPECT_EQ(update_file_contents, current_file.readFile());
// This string contains the contents of the lease file we
@@ -698,9 +698,9 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) {
// entry each.
std::string result_file_contents = new_file_contents +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,\n"
+ "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n"
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,,1,,,\n";
+ "8,100,0,7,0,1,1,,,1,,,,0\n";
// The LFC should have created a file with the two leases and moved it
// to leasefile6_0.csv.2
@@ -718,11 +718,11 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanupStartFail) {
// stored.
std::string new_file_contents =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
// Create the lease file to be used by the backend.
std::string current_file_contents = new_file_contents +
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,\n";
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,,0\n";
LeaseFileIO current_file(getLeaseFilePath("leasefile4_0.csv"));
current_file.writeFile(current_file_contents);
@@ -750,15 +750,15 @@ TEST_F(MemfileLeaseMgrTest, leaseFileFinish) {
"address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n";
+ "hwtype,hwaddr_source,pool_id\n";
// This string contains the contents of the current lease file.
// It should not be moved.
std::string current_file_contents = new_file_contents +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
- "8,100,0,7,0,1,1,,,1,,,\n"
+ "8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,1,,,\n";
+ "8,100,0,7,0,1,1,,,1,,,,0\n";
LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
current_file.writeFile(current_file_contents);
@@ -766,7 +766,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileFinish) {
// be moved to the previous file.
std::string finish_file_contents = new_file_contents +
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,,1,\n";
+ "8,100,0,7,0,1,1,,,1,,0\n";
LeaseFileIO finish_file(getLeaseFilePath("leasefile6_0.csv.completed"));
finish_file.writeFile(finish_file_contents);
@@ -814,15 +814,15 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCopy) {
"address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
- "hwtype,hwaddr_source\n";
+ "hwtype,hwaddr_source,pool_id\n";
// This string contains the contents of the current lease file.
// It should not be moved.
std::string current_file_contents = new_file_contents +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
- "8,100,0,7,0,1,1,,,1,,,\n"
+ "8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,\n";
+ "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n";
LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
current_file.writeFile(current_file_contents);
@@ -832,7 +832,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCopy) {
// the same.
std::string input_file_contents = new_file_contents +
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,\n";
+ "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n";
LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.1"));
input_file.writeFile(input_file_contents);
@@ -1474,22 +1474,22 @@ TEST_F(MemfileLeaseMgrTest, getDeclined6MultiThread) {
TEST_F(MemfileLeaseMgrTest, load4MultipleLeaseFiles) {
LeaseFileIO io2(getLeaseFilePath("leasefile4_0.csv.2"));
io2.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,\n"
- "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,1,,0\n");
LeaseFileIO io1(getLeaseFilePath("leasefile4_0.csv.1"));
io1.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,1,\n"
- "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,1,\n"
- "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,1,,0\n"
+ "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,1,,0\n");
LeaseFileIO io(getLeaseFilePath("leasefile4_0.csv"));
io.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,1,\n"
- "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,1,,0\n");
startBackend(V4);
@@ -1532,27 +1532,27 @@ TEST_F(MemfileLeaseMgrTest, load4MultipleLeaseFiles) {
TEST_F(MemfileLeaseMgrTest, load4CompletedFile) {
LeaseFileIO io2(getLeaseFilePath("leasefile4_0.csv.2"));
io2.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,\n"
- "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,1,,0\n");
LeaseFileIO io1(getLeaseFilePath("leasefile4_0.csv.1"));
io1.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,1,\n"
- "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,1,\n"
- "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,1,,0\n"
+ "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,1,,0\n");
LeaseFileIO io(getLeaseFilePath("leasefile4_0.csv"));
io.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,1,\n"
- "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,1,,0\n"
+ "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,1,,0\n");
LeaseFileIO ioc(getLeaseFilePath("leasefile4_0.csv.completed"));
ioc.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
- "192.0.2.13,ff:ff:ff:ff:ff:ff,,200,200,8,1,1,,1,\n");
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
+ "192.0.2.13,ff:ff:ff:ff:ff:ff,,200,200,8,1,1,,1,,0\n");
startBackend(V4);
@@ -1609,31 +1609,31 @@ TEST_F(MemfileLeaseMgrTest, load6MultipleLeaseFiles) {
LeaseFileIO io2(getLeaseFilePath("leasefile6_0.csv.2"));
io2.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n"
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO io1(getLeaseFilePath("leasefile6_0.csv.1"));
io1.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::3,03:03:03:03:03:03:03:03:03:03:03:03:03,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n"
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "300,800,8,100,0,7,0,1,1,,,1,,,\n"
+ "300,800,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,\n"
+ "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
startBackend(V6);
@@ -1675,22 +1675,22 @@ TEST_F(MemfileLeaseMgrTest, load6MultipleNoSecondFile) {
LeaseFileIO io1(getLeaseFilePath("leasefile6_0.csv.1"));
io1.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::3,03:03:03:03:03:03:03:03:03:03:03:03:03,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n"
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "300,800,8,100,0,7,0,1,1,,,1,,,\n"
+ "300,800,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,\n"
+ "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
startBackend(V6);
@@ -1723,20 +1723,20 @@ TEST_F(MemfileLeaseMgrTest, load6MultipleNoFirstFile) {
LeaseFileIO io2(getLeaseFilePath("leasefile6_0.csv.2"));
io2.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n"
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,\n"
+ "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
startBackend(V6);
@@ -1770,38 +1770,38 @@ TEST_F(MemfileLeaseMgrTest, load6CompletedFile) {
LeaseFileIO io2(getLeaseFilePath("leasefile6_0.csv.2"));
io2.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n"
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO io1(getLeaseFilePath("leasefile6_0.csv.1"));
io1.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::3,03:03:03:03:03:03:03:03:03:03:03:03:03,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n"
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "300,800,8,100,0,7,0,1,1,,,1,,,\n"
+ "300,800,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,\n"
+ "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
- "200,200,8,100,0,7,0,1,1,,,1,,,\n");
+ "200,200,8,100,0,7,0,1,1,,,1,,,,0\n");
LeaseFileIO ioc(getLeaseFilePath("leasefile6_0.csv.completed"));
ioc.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::125,ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,\n");
+ "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n");
startBackend(V6);
@@ -1864,6 +1864,10 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade4) {
"address,hwaddr,client_id,valid_lifetime,expire,"
"subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ std::string header_3_0 =
+ "address,hwaddr,client_id,valid_lifetime,expire,"
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
+
// Create 1.0 Schema current lease file with two entries for
// the same lease
std::string current_file_contents = header_1_0 +
@@ -1890,9 +1894,9 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade4) {
// Since lease files are loaded during lease manager
// constructor, LFC should get launched automatically.
- // The new lease file should be 2.0 schema and have no entries
+ // The new lease file should be 3.0 schema and have no entries
ASSERT_TRUE(current_file.exists());
- EXPECT_EQ(header_2_0, current_file.readFile());
+ EXPECT_EQ(header_3_0, current_file.readFile());
// Wait for the LFC process to complete and
// make sure it has returned an exit status of 0.
@@ -1902,15 +1906,15 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade4) {
<< "Executing the LFC process failed: make sure that"
" the kea-lfc program has been compiled.";
- // The LFC should have created a 2.0 schema completion file with the
+ // The LFC should have created a 3.0 schema completion file with the
// one entry for each lease and moved it to leasefile4_0.csv.2
LeaseFileIO input_file(getLeaseFilePath("leasefile4_0.csv.2"), false);
ASSERT_TRUE(input_file.exists());
// Verify cleaned, converted contents
- std::string result_file_contents = header_2_0 +
- "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,0,\n"
- "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,0,\n";
+ std::string result_file_contents = header_3_0 +
+ "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,0,,0\n"
+ "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,0,,0\n";
EXPECT_EQ(result_file_contents, input_file.readFile());
}
@@ -1939,6 +1943,12 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade6) {
"fqdn_rev,hostname,hwaddr,state,user_context,"
"hwtype,hwaddr_source\n";
+ std::string header_5_0 =
+ "address,duid,valid_lifetime,expire,subnet_id,"
+ "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
+ "fqdn_rev,hostname,hwaddr,state,user_context,"
+ "hwtype,hwaddr_source,pool_id\n";
+
// The current lease file is schema 1.0 and has two entries for
// the same lease
std::string current_file_contents = header_1_0 +
@@ -1969,9 +1979,9 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade6) {
// Since lease files are loaded during lease manager
// constructor, LFC should get launched automatically.
- // The new lease file should been 4.0 and contain no leases.
+ // The new lease file should been 5.0 and contain no leases.
ASSERT_TRUE(current_file.exists());
- EXPECT_EQ(header_4_0, current_file.readFile());
+ EXPECT_EQ(header_5_0, current_file.readFile());
// Wait for the LFC process to complete and
// make sure it has returned an exit status of 0.
@@ -1981,17 +1991,17 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade6) {
<< "Executing the LFC process failed: make sure that"
" the kea-lfc program has been compiled.";
- // The LFC should have created a 4.0 schema cleaned file with one entry
+ // The LFC should have created a 5.0 schema cleaned file with one entry
// for each lease as leasefile6_0.csv.2
LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.2"), false);
ASSERT_TRUE(input_file.exists());
// Verify cleaned, converted contents
- std::string result_file_contents = header_4_0 +
+ std::string result_file_contents = header_5_0 +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,0,,,\n"
+ "8,100,0,7,0,1,1,,,0,,,,0\n"
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,11:22:33:44:55,0,,1,0\n";
+ "8,100,0,7,0,1,1,,11:22:33:44:55,0,,1,0,0\n";
EXPECT_EQ(result_file_contents, input_file.readFile());
}
@@ -2356,22 +2366,22 @@ TEST_F(MemfileLeaseMgrTest, v4UserContext) {
LeaseFileIO io(getLeaseFilePath("leasefile4_0.csv"));
io.writeFile(
"address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
- "fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
+ "fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
"192.0.0.1,01:01:01:01:01:01,,100,100,1,1,1,,1,"
- "{}\n"
+ "{},0\n"
"192.0.0.2,02:02:02:02:02:02,,200,400,1,1,1,,0,"
- "{ \"comment\": \"this lease is for the kitchen computer\"}\n"
+ "{ \"comment\": \"this lease is for the kitchen computer\"},0\n"
// The next lines have escaped commas in user context.
"192.0.0.4,04:04:04:04:04:04,,400,1600,1,1,1,,0,"
"{ \"comment\": \"this lease is for the mainframe computer\"&#x2c"
- " \"comment2\": \"don't release it\" }\n"
+ " \"comment2\": \"don't release it\" },0\n"
"192.0.0.8,08:08:08:08:08:08,,800,6400,1,1,1,,0,"
- "{ \"a\": \"b\"&#x2c \"c\": { \"d\": 1&#x2c\"e\": 2 } }\n"
+ "{ \"a\": \"b\"&#x2c \"c\": { \"d\": 1&#x2c\"e\": 2 } },0\n"
);
// Not sanitize user contexts.
@@ -2391,6 +2401,7 @@ TEST_F(MemfileLeaseMgrTest, v4UserContext) {
"Hardware addr: 01:01:01:01:01:01\n"
"Client id: (none)\n"
"Subnet ID: 1\n"
+ "Pool ID: 0\n"
"State: declined\n"
"Relay ID: (none)\n"
"Remote ID: (none)\n"
@@ -2408,6 +2419,7 @@ TEST_F(MemfileLeaseMgrTest, v4UserContext) {
"Hardware addr: 02:02:02:02:02:02\n"
"Client id: (none)\n"
"Subnet ID: 1\n"
+ "Pool ID: 0\n"
"State: default\n"
"Relay ID: (none)\n"
"Remote ID: (none)\n"
@@ -2425,6 +2437,7 @@ TEST_F(MemfileLeaseMgrTest, v4UserContext) {
"Hardware addr: 04:04:04:04:04:04\n"
"Client id: (none)\n"
"Subnet ID: 1\n"
+ "Pool ID: 0\n"
"State: default\n"
"Relay ID: (none)\n"
"Remote ID: (none)\n"
@@ -2444,6 +2457,7 @@ TEST_F(MemfileLeaseMgrTest, v4UserContext) {
"Hardware addr: 08:08:08:08:08:08\n"
"Client id: (none)\n"
"Subnet ID: 1\n"
+ "Pool ID: 0\n"
"State: default\n"
"Relay ID: (none)\n"
"Remote ID: (none)\n"
@@ -2458,26 +2472,26 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) {
io.writeFile(
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
- "{ \"comment\": \"this lease is for the kitchen computer\"},,\n"
+ "{ \"comment\": \"this lease is for the kitchen computer\"},,,0\n"
// The next lines have escaped commas in user context.
"2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
"200,200,8,100,0,7,0,1,1,,,1,"
"{ \"comment\": \"this lease is for the mainframe computer\"&#x2c"
- " \"comment2\": \"don't release it\" },,\n"
+ " \"comment2\": \"don't release it\" },,,0\n"
"2001:db8:1::8,08:08:08:08:08:08:08:08:08:08:08:08:08,"
"200,200,8,100,0,7,0,1,1,,,1,"
- "{ \"a\": \"b\"&#x2c \"c\": { \"d\": 1&#x2c\"e\": 2 } }\n"
+ "{ \"a\": \"b\"&#x2c \"c\": { \"d\": 1&#x2c\"e\": 2 } },,,0\n"
);
// Not sanitize user contexts.
@@ -2502,6 +2516,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) {
"DUID: 01:01:01:01:01:01:01:01:01:01:01:01:01\n"
"Hardware addr: (none)\n"
"Subnet ID: 8\n"
+ "Pool ID: 0\n"
"State: declined\n"
"User context: { }\n"
);
@@ -2521,13 +2536,14 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) {
"DUID: 02:02:02:02:02:02:02:02:02:02:02:02:02\n"
"Hardware addr: (none)\n"
"Subnet ID: 8\n"
+ "Pool ID: 0\n"
"State: declined\n"
"User context: { \"comment\": \"this lease is for the kitchen computer\" }\n"
);
// Check the lease with two key-value pairs in the user context.
lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::4"));
- EXPECT_TRUE(lease);
+ ASSERT_TRUE(lease);
EXPECT_EQ(
lease->toText(),
"Type: IA_NA(0)\n"
@@ -2540,6 +2556,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) {
"DUID: 04:04:04:04:04:04:04:04:04:04:04:04:04\n"
"Hardware addr: (none)\n"
"Subnet ID: 8\n"
+ "Pool ID: 0\n"
"State: declined\n"
"User context: { \"comment\": \"this lease is for the mainframe computer\","
" \"comment2\": \"don't release it\" }\n"
@@ -2547,7 +2564,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) {
// Check the lease with nested key-value pairs in the user context.
lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::8"));
- EXPECT_TRUE(lease);
+ ASSERT_TRUE(lease);
EXPECT_EQ(
lease->toText(),
"Type: IA_NA(0)\n"
@@ -2560,6 +2577,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) {
"DUID: 08:08:08:08:08:08:08:08:08:08:08:08:08\n"
"Hardware addr: (none)\n"
"Subnet ID: 8\n"
+ "Pool ID: 0\n"
"State: declined\n"
"User context: { \"a\": \"b\", \"c\": { \"d\": 1, \"e\": 2 } }\n"
);
@@ -2573,7 +2591,7 @@ TEST_F(MemfileLeaseMgrTest, testHWAddr) {
std::stringstream contents;
contents << "address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
// Create combinations with all valid values except for 255 which is an
// unused value for both hwtype and hwaddr_source, but lease construction
@@ -2590,7 +2608,7 @@ TEST_F(MemfileLeaseMgrTest, testHWAddr) {
contents << "2001:db8:1::" << hex.str()
<< ",00:00:00:00:00:" << hex.str()
<< std::dec << ",7200,8000,1,3600,0,1,128,0,0,,ff:ff:ff:ff:ff:"
- << hex.str() << ",1,," << hwtype << "," << hwsource << "\n";
+ << hex.str() << ",1,," << hwtype << "," << hwsource << ",0\n";
++i;
}
}
@@ -2619,6 +2637,7 @@ TEST_F(MemfileLeaseMgrTest, testHWAddr) {
"DUID: 00:00:00:00:00:" + hex.str() + "\n"
"Hardware addr: ff:ff:ff:ff:ff:" + hex.str() + "\n"
"Subnet ID: 1\n"
+ "Pool ID: 0\n"
"State: declined\n");
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ(lease->hwaddr_->htype_, hwtype);
@@ -2903,7 +2922,7 @@ TEST_F(MemfileLeaseMgrTest, basicWriteLease4) {
// Empty database should give a header only file.
string header =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
string filename = getLeaseFilePath("backup.csv");
LeaseFileIO file(filename);
@@ -2952,7 +2971,7 @@ TEST_F(MemfileLeaseMgrTest, basicWriteLease4MultiThread) {
// Empty database should give a header only file.
string header =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
string filename = getLeaseFilePath("backup.csv");
LeaseFileIO file(filename);
@@ -3001,7 +3020,7 @@ TEST_F(MemfileLeaseMgrTest, basicWriteLease6) {
string header =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
string filename = getLeaseFilePath("backup.csv");
LeaseFileIO file(filename);
@@ -3051,7 +3070,7 @@ TEST_F(MemfileLeaseMgrTest, basicWriteLease6MultiThread) {
string header =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
string filename = getLeaseFilePath("backup.csv");
LeaseFileIO file(filename);
@@ -3106,7 +3125,7 @@ TEST_F(MemfileLeaseMgrTest, overWriteLease4) {
// Empty database should give a header only file.
string header =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
ASSERT_TRUE(lease_mgr->lease_file4_);
string filename = lease_mgr->lease_file4_->getFilename();
@@ -3166,7 +3185,7 @@ TEST_F(MemfileLeaseMgrTest, overWriteLease4MultiThread) {
// Empty database should give a header only file.
string header =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
ASSERT_TRUE(lease_mgr->lease_file4_);
string filename = lease_mgr->lease_file4_->getFilename();
@@ -3225,7 +3244,7 @@ TEST_F(MemfileLeaseMgrTest, overWriteLease6) {
string header =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
ASSERT_TRUE(lease_mgr->lease_file6_);
string filename = lease_mgr->lease_file6_->getFilename();
@@ -3286,7 +3305,7 @@ TEST_F(MemfileLeaseMgrTest, overWriteLease6MultiThread) {
string header =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
ASSERT_TRUE(lease_mgr->lease_file6_);
string filename = lease_mgr->lease_file6_->getFilename();
@@ -3344,7 +3363,7 @@ TEST_F(MemfileLeaseMgrTest, notPersistWriteLease4) {
// Empty database should give a header only file.
string header =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
ASSERT_FALSE(lease_mgr->lease_file4_);
string filename = getLeaseFilePath("backup.csv");
@@ -3401,7 +3420,7 @@ TEST_F(MemfileLeaseMgrTest, notPersistWriteLease4MultiThread) {
// Empty database should give a header only file.
string header =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n";
ASSERT_FALSE(lease_mgr->lease_file4_);
string filename = getLeaseFilePath("backup.csv");
@@ -3457,7 +3476,7 @@ TEST_F(MemfileLeaseMgrTest, notPersistWriteLease6) {
string header =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
ASSERT_FALSE(lease_mgr->lease_file6_);
string filename = getLeaseFilePath("backup.csv");
@@ -3515,7 +3534,7 @@ TEST_F(MemfileLeaseMgrTest, notPersistWriteLease6MultiThread) {
string header =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n";
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n";
ASSERT_FALSE(lease_mgr->lease_file6_);
string filename = getLeaseFilePath("backup.csv");
@@ -3565,12 +3584,12 @@ TEST_F(MemfileLeaseMgrTest, extractExtendedInfo4) {
LeaseFileIO io(lease_file);
io.writeFile(
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{}\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{},0\n"
"192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1,"
- "{ \"ISC\": { \"relay-agent-info\": \"0x02030102030C03AABBCC\" } }\n"
+ "{ \"ISC\": { \"relay-agent-info\": \"0x02030102030C03AABBCC\" } },0\n"
);
// Start the lease manager.
@@ -3640,12 +3659,12 @@ TEST_F(MemfileLeaseMgrTest, extractExtendedInfo4noSanitize) {
LeaseFileIO io(lease_file);
io.writeFile(
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{}\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{},0\n"
"192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1,"
- "{ \"ISC\": { \"relay-agent-info\": \"0x02030102030C03AABBCC\" } }\n"
+ "{ \"ISC\": { \"relay-agent-info\": \"0x02030102030C03AABBCC\" } },0\n"
);
// Disable sanitizing.
@@ -3695,12 +3714,12 @@ TEST_F(MemfileLeaseMgrTest, extractExtendedInfo4ExplicitSanitize) {
LeaseFileIO io(lease_file);
string content =
"address,hwaddr,client_id,valid_lifetime,expire,"
- "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context\n"
+ "subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id\n"
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{}\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,{},0\n"
"192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1,"
- "{ \"ISC\": { \"relay-agent-info\": \"0x02030102030C03AABBCC\" } }\n";
+ "{ \"ISC\": { \"relay-agent-info\": \"0x02030102030C03AABBCC\" } },0\n";
io.writeFile(content);
// Disable sanitizing.
@@ -3799,13 +3818,13 @@ TEST_F(MemfileLeaseMgrTest, extractExtendedInfo4ExplicitSanitize) {
EXPECT_EQ(*lease, *leases[0]);
// Check the lease file was updated.
string new_content =
- "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,\n"
+ "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1,,0\n"
"192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1,"
"{ \"ISC\": { \"relay-agent-info\": { "
"\"relay-id\": \"AABBCC\"&#x2c "
"\"remote-id\": \"010203\"&#x2c "
- "\"sub-options\": \"0x02030102030C03AABBCC\" } } }\n";
+ "\"sub-options\": \"0x02030102030C03AABBCC\" } } },0\n";
string expected = content + new_content;
EXPECT_EQ(expected, io.readFile());
}
@@ -3820,18 +3839,18 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6) {
io.writeFile(
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
"{ \"ISC\": { \"relays\": [ { \"hop\": 44&#x2c"
" \"link\": \"2001:db8::4\"&#x2c \"peer\": \"2001:db8::5\"&#x2c"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Start the lease manager.
@@ -3890,18 +3909,18 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6noSanitize) {
io.writeFile(
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
"{ \"ISC\": { \"relays\": [ { \"hop\": 44&#x2c"
" \"link\": \"2001:db8::4\"&#x2c \"peer\": \"2001:db8::5\"&#x2c"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Disable sanitizing.
@@ -3952,11 +3971,11 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6enabled) {
io.writeFile(
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
@@ -3965,7 +3984,7 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6enabled) {
" \"remote-id\": \"010203040506\"&#x2c"
" \"relay-id\": \"6464646464646464\"&#x2c"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Disable sanitizing.
@@ -4021,11 +4040,11 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6disabled) {
io.writeFile(
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
@@ -4034,7 +4053,7 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6disabled) {
" \"remote-id\": \"010203040506\"&#x2c"
" \"relay-id\": \"6464646464646464\"&#x2c"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Start the lease manager.
@@ -4067,18 +4086,18 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6ExplicitSanitize) {
string content =
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
"{ \"ISC\": { \"relays\": [ { \"hop\": 44&#x2c"
" \"link\": \"2001:db8::4\"&#x2c \"peer\": \"2001:db8::5\"&#x2c"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n";
+ " } ] } },,,0\n";
io.writeFile(content);
// Disable sanitizing.
@@ -4140,7 +4159,7 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6ExplicitSanitize) {
// Check the lease file was updated.
string new_content =
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,\n"
+ "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
@@ -4149,7 +4168,7 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6ExplicitSanitize) {
" \"options\": \"0x00250006010203040506003500086464646464646464\""
"&#x2c \"peer\": \"2001:db8::5\"&#x2c"
" \"relay-id\": \"6464646464646464\"&#x2c"
- " \"remote-id\": \"010203040506\" } ] } },,\n";
+ " \"remote-id\": \"010203040506\" } ] } },,,0\n";
string expected = content + new_content;
EXPECT_EQ(expected, io.readFile());
}
@@ -4163,11 +4182,11 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6rebuild) {
io.writeFile(
"address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
- "hwaddr,state,user_context,hwtype,hwaddr_source\n"
+ "hwaddr,state,user_context,hwtype,hwaddr_source,pool_id\n"
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
"400,1000,8,100,0,7,0,1,1,,,1,"
- "{},,\n"
+ "{},,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
"200,200,8,100,0,7,0,1,1,,,1,"
@@ -4176,7 +4195,7 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6rebuild) {
" \"remote-id\": \"010203040506\"&#x2c"
" \"relay-id\": \"6464646464646464\"&#x2c"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Disable sanitizing.
diff --git a/src/lib/dhcpsrv/tests/pool_unittest.cc b/src/lib/dhcpsrv/tests/pool_unittest.cc
index 8ee26e75aa..6131ae4e8c 100644
--- a/src/lib/dhcpsrv/tests/pool_unittest.cc
+++ b/src/lib/dhcpsrv/tests/pool_unittest.cc
@@ -25,7 +25,7 @@ using namespace isc::asiolink;
namespace {
-TEST(Pool4Test, constructor_first_last) {
+TEST(Pool4Test, constructorFirstLast) {
// let's construct 192.0.2.1-192.0.2.255 pool
Pool4 pool1(IOAddress("192.0.2.1"), IOAddress("192.0.2.255"));
@@ -45,7 +45,7 @@ TEST(Pool4Test, constructor_first_last) {
BadValue);
}
-TEST(Pool4Test, constructor_prefix_len) {
+TEST(Pool4Test, constructorPrefixLen) {
// let's construct 2001:db8:1::/96 pool
Pool4 pool1(IOAddress("192.0.2.0"), 25);
@@ -91,26 +91,6 @@ TEST(Pool4Test, leasesCount) {
EXPECT_EQ(16777216, pool4.getCapacity());
}
-// This test creates 100 pools and verifies that their IDs are unique.
-TEST(Pool4Test, unique_id) {
-
- const int num_pools = 100;
- std::vector<Pool4Ptr> pools;
-
- for (int i = 0; i < num_pools; ++i) {
- pools.push_back(Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
- IOAddress("192.0.2.255"))));
- }
-
- for (int i = 0; i < num_pools; ++i) {
- for (int j = i + 1; j < num_pools; ++j) {
- if (pools[i]->getId() == pools[j]->getId()) {
- FAIL() << "Pool-ids must be unique";
- }
- }
- }
-}
-
// Simple check if toText returns reasonable values
TEST(Pool4Test, toText) {
Pool4 pool1(IOAddress("192.0.2.7"), IOAddress("192.0.2.17"));
@@ -334,7 +314,7 @@ TEST(Pool6Test, constructorPrefixLen) {
BadValue);
}
-TEST(Pool6Test, in_range) {
+TEST(Pool6Test, inRange) {
Pool6 pool1(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
IOAddress("2001:db8:1::f"));
@@ -479,27 +459,6 @@ TEST(Pool6Test, TA) {
EXPECT_EQ("2001:db8:1::f", pool2->getLastAddress().toText());
}
-// This test creates 100 pools and verifies that their IDs are unique.
-TEST(Pool6Test, uniqueID) {
-
- const int num_pools = 100;
- std::vector<Pool6Ptr> pools;
-
- for (int i = 0; i < num_pools; ++i) {
- pools.push_back(Pool6Ptr(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::"),
- IOAddress("2001:db8:1::ffff:ffff:ffff:ffff"))));
- }
-
- for (int i = 0; i < num_pools; ++i) {
- for (int j = i + 1; j < num_pools; ++j) {
- if (pools[i]->getId() == pools[j]->getId()) {
- FAIL() << "Pool-ids must be unique";
- }
- }
- }
-
-}
-
// Simple check if toText returns reasonable values
TEST(Pool6Test, toText) {
Pool6 pool1(Lease::TYPE_NA, IOAddress("2001:db8::1"),
@@ -710,4 +669,4 @@ TEST(Pool6Test, requiredClasses) {
EXPECT_TRUE(pool.getRequiredClasses().contains("foo"));
}
-}; // end of anonymous namespace
+} // end of anonymous namespace
diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql
index d64bff6a5d..73963c1136 100644
--- a/src/share/database/scripts/mysql/dhcpdb_create.mysql
+++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql
@@ -314,7 +314,7 @@ DELIMITER $$
CREATE PROCEDURE lease4DumpHeader()
BEGIN
SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state';
-END $$
+END $$
DELIMITER ;
# Procedure that returns a result set containing the data for lease4 dumps
@@ -346,7 +346,7 @@ DELIMITER $$
CREATE PROCEDURE lease6DumpHeader()
BEGIN
SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state';
-END $$
+END $$
DELIMITER ;
# Procedure that returns a result set containing the data for lease6 dumps
@@ -705,7 +705,7 @@ DELIMITER $$
CREATE PROCEDURE lease4DumpHeader()
BEGIN
SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context';
-END $$
+END $$
DELIMITER ;
# Procedure that returns a result set containing the data for lease4 dumps
@@ -737,7 +737,7 @@ DELIMITER $$
CREATE PROCEDURE lease6DumpHeader()
BEGIN
SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state,user_context';
-END $$
+END $$
DELIMITER ;
# Procedure that returns a result set containing the data for lease6 dumps
@@ -4184,7 +4184,7 @@ DELIMITER $$
CREATE PROCEDURE lease6DumpHeader()
BEGIN
SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source';
-END $$
+END $$
DELIMITER ;
-- Modify the procedure to output a memfile-ready CSV file.
@@ -5325,6 +5325,456 @@ CREATE TABLE lease6_remote_id (
INDEX key_lease6_remote_id_by_address (lease_addr)
) ENGINE = INNODB;
+# Add pool_id column to the lease4 table.
+ALTER TABLE lease4
+ ADD COLUMN pool_id INT UNSIGNED NOT NULL DEFAULT 0;
+
+# Add pool_id column to the lease6 table.
+ALTER TABLE lease6
+ ADD COLUMN pool_id INT UNSIGNED NOT NULL DEFAULT 0;
+
+# Create lease4_pool_stat table
+CREATE TABLE lease4_pool_stat (
+ subnet_id INT UNSIGNED NOT NULL,
+ pool_id INT UNSIGNED NOT NULL,
+ state INT UNSIGNED NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, state)
+) ENGINE = INNODB;
+
+# Create lease6_pool_stat table
+CREATE TABLE lease6_pool_stat (
+ subnet_id INT UNSIGNED NOT NULL,
+ pool_id INT UNSIGNED NOT NULL,
+ lease_type INT UNSIGNED NOT NULL,
+ state INT UNSIGNED NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, lease_type, state)
+) ENGINE = INNODB;
+
+DROP PROCEDURE IF EXISTS lease4_AINS_lease4_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease4_AINS_lease4_pool_stat(IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED)
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease4_AUPD_lease4_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease4_AUPD_lease4_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED,
+ IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED)
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert new state record if it does not exist.
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease4_ADEL_lease4_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease4_ADEL_lease4_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED)
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND old_state = state;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6_AINS_lease6_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease6_AINS_lease6_pool_stat(IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED,
+ IN new_lease_type TINYINT)
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6_AUPD_lease6_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease6_AUPD_lease6_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED,
+ IN old_lease_type TINYINT,
+ IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED,
+ IN new_lease_type TINYINT)
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_lease_type != new_lease_type OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease6_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert new state record if it does not exist
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6_ADEL_lease6_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease6_ADEL_lease6_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED,
+ IN old_lease_type TINYINT)
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease6_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease4_AINS;
+DELIMITER $$
+CREATE TRIGGER lease4_AINS AFTER INSERT ON lease4 FOR EACH ROW
+BEGIN
+ CALL lease4_AINS_lease4_stat(NEW.state, NEW.subnet_id);
+ CALL lease4_AINS_lease4_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease4_AINS_lease4_stat_by_client_class(NEW.state, NEW.user_context);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease4_AUPD;
+DELIMITER $$
+CREATE TRIGGER lease4_AUPD AFTER UPDATE ON lease4 FOR EACH ROW
+BEGIN
+ CALL lease4_AUPD_lease4_stat(OLD.state, OLD.subnet_id, NEW.state, NEW.subnet_id);
+ CALL lease4_AUPD_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, NEW.state, NEW.subnet_id, NEW.pool_id);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease4_AUPD_lease4_stat_by_client_class(OLD.state, OLD.user_context, NEW.state, NEW.user_context);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease4_ADEL;
+DELIMITER $$
+CREATE TRIGGER lease4_ADEL AFTER DELETE ON lease4 FOR EACH ROW
+BEGIN
+ CALL lease4_ADEL_lease4_stat(OLD.state, OLD.subnet_id);
+ CALL lease4_ADEL_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease4_ADEL_lease4_stat_by_client_class(OLD.state, OLD.user_context);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease6_AINS;
+DELIMITER $$
+CREATE TRIGGER lease6_AINS AFTER INSERT ON lease6 FOR EACH ROW
+BEGIN
+ CALL lease6_AINS_lease6_stat(NEW.state, NEW.subnet_id, NEW.lease_type);
+ CALL lease6_AINS_lease6_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease6_AINS_lease6_stat_by_client_class(NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease6_AUPD;
+DELIMITER $$
+CREATE TRIGGER lease6_AUPD AFTER UPDATE ON lease6 FOR EACH ROW
+BEGIN
+ CALL lease6_AUPD_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.lease_type);
+ CALL lease6_AUPD_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease6_AUPD_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type, NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease6_ADEL;
+DELIMITER $$
+CREATE TRIGGER lease6_ADEL AFTER DELETE ON lease6 FOR EACH ROW
+BEGIN
+ CALL lease6_ADEL_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type);
+ CALL lease6_ADEL_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease6_ADEL_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease4DumpHeader;
+DELIMITER $$
+CREATE PROCEDURE lease4DumpHeader()
+BEGIN
+SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id';
+END $$
+DELIMITER ;
+
+-- Modify the procedure to output a memfile-ready CSV file.
+DROP PROCEDURE IF EXISTS lease4DumpData;
+DELIMITER $$
+CREATE PROCEDURE lease4DumpData()
+BEGIN
+ SELECT
+ INET_NTOA(address),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ IFNULL(colonSeparatedHex(HEX(client_id)), ''),
+ valid_lifetime,
+ UNIX_TIMESTAMP(expire),
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, ',', '&#x2c'),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
+ pool_id
+ FROM lease4
+ ORDER BY address;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6DumpHeader;
+DELIMITER $$
+CREATE PROCEDURE lease6DumpHeader()
+BEGIN
+ SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id';
+END $$
+DELIMITER ;
+
+-- Modify the procedure to output a memfile-ready CSV file.
+DROP PROCEDURE IF EXISTS lease6DumpData;
+DELIMITER $$
+CREATE PROCEDURE lease6DumpData()
+BEGIN
+ SELECT
+ address,
+ IFNULL(colonSeparatedHex(HEX(duid)), ''),
+ valid_lifetime,
+ UNIX_TIMESTAMP(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, ',', '&#x2c'),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ FROM lease6
+ ORDER BY address;
+END $$
+DELIMITER ;
+
+-- Create a procedure that inserts a v4 lease from memfile data.
+DROP PROCEDURE IF EXISTS lease4Upload;
+DELIMITER $$
+CREATE PROCEDURE lease4Upload(
+ IN address VARCHAR(15),
+ IN hwaddr VARCHAR(20),
+ IN client_id VARCHAR(128),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN pool_id INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease4 (
+ address,
+ hwaddr,
+ client_id,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ state,
+ user_context,
+ pool_id
+ ) VALUES (
+ INET_ATON(address),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ UNHEX(REPLACE(client_id, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ pool_id
+ );
+END $$
+DELIMITER ;
+
+-- Create a procedure that inserts a v6 lease from memfile data.
+DROP PROCEDURE IF EXISTS lease6Upload;
+DELIMITER $$
+CREATE PROCEDURE lease6Upload(
+ IN address VARCHAR(39),
+ IN duid VARCHAR(128),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN pref_lifetime INT UNSIGNED,
+ IN lease_type TINYINT,
+ IN iaid INT UNSIGNED,
+ IN prefix_len TINYINT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN hwaddr VARCHAR(64),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN hwtype SMALLINT,
+ IN hwaddr_source INT UNSIGNED,
+ IN pool_id INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source,
+ pool_id
+ ) VALUES (
+ address,
+ UNHEX(REPLACE(duid, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END $$
+DELIMITER ;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '18', minor = '0';
diff --git a/src/share/database/scripts/mysql/dhcpdb_drop.mysql b/src/share/database/scripts/mysql/dhcpdb_drop.mysql
index fefb44988a..7bbe6af08d 100644
--- a/src/share/database/scripts/mysql/dhcpdb_drop.mysql
+++ b/src/share/database/scripts/mysql/dhcpdb_drop.mysql
@@ -27,10 +27,12 @@ DROP TRIGGER IF EXISTS stat_lease4_insert;
DROP TRIGGER IF EXISTS stat_lease4_update;
DROP TRIGGER IF EXISTS stat_lease4_delete;
DROP TABLE IF EXISTS lease4_stat;
+DROP TABLE IF EXISTS lease4_pool_stat;
DROP TRIGGER IF EXISTS stat_lease6_insert;
DROP TRIGGER IF EXISTS stat_lease6_update;
DROP TRIGGER IF EXISTS stat_lease6_delete;
DROP TABLE IF EXISTS lease6_stat;
+DROP TABLE IF EXISTS lease6_pool_stat;
DROP TABLE IF EXISTS logs;
DROP TABLE IF EXISTS dhcp4_audit;
DROP TABLE IF EXISTS dhcp4_audit_revision;
@@ -134,6 +136,12 @@ DROP PROCEDURE IF EXISTS lease4_ADEL_lease4_stat;
DROP PROCEDURE IF EXISTS lease6_AINS_lease6_stat;
DROP PROCEDURE IF EXISTS lease6_AUPD_lease6_stat;
DROP PROCEDURE IF EXISTS lease6_ADEL_lease6_stat;
+DROP PROCEDURE IF EXISTS lease4_AINS_lease4_pool_stat;
+DROP PROCEDURE IF EXISTS lease4_AUPD_lease4_pool_stat;
+DROP PROCEDURE IF EXISTS lease4_ADEL_lease4_pool_stat;
+DROP PROCEDURE IF EXISTS lease6_AINS_lease6_pool_stat;
+DROP PROCEDURE IF EXISTS lease6_AUPD_lease6_pool_stat;
+DROP PROCEDURE IF EXISTS lease6_ADEL_lease6_pool_stat;
DROP TABLE IF EXISTS lease4_stat_by_client_class;
DROP TABLE IF EXISTS lease6_stat_by_client_class;
DROP PROCEDURE IF EXISTS lease4_AINS_lease4_stat_by_client_class;
diff --git a/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in b/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in
index e7181c2bf1..7269e91edf 100644
--- a/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in
@@ -105,7 +105,7 @@ DELIMITER $$
CREATE PROCEDURE lease4DumpHeader()
BEGIN
SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state';
-END $$
+END $$
DELIMITER ;
# FUNCTION that returns a result set containing the data for lease4 dumps
@@ -136,7 +136,7 @@ DELIMITER $$
CREATE PROCEDURE lease6DumpHeader()
BEGIN
SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state';
-END $$
+END $$
DELIMITER ;
# FUNCTION that returns a result set containing the data for lease6 dumps
diff --git a/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in b/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in
index e3c695c2ba..d73c8a44a1 100644
--- a/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in
@@ -45,7 +45,7 @@ DELIMITER $$
CREATE PROCEDURE lease4DumpHeader()
BEGIN
SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context';
-END $$
+END $$
DELIMITER ;
# FUNCTION that returns a result set containing the data for lease4 dumps
@@ -77,7 +77,7 @@ DELIMITER $$
CREATE PROCEDURE lease6DumpHeader()
BEGIN
SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state,user_context';
-END $$
+END $$
DELIMITER ;
# FUNCTION that returns a result set containing the data for lease6 dumps
diff --git a/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in b/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in
index b1913a00ce..f5f8b6f449 100644
--- a/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in
@@ -121,7 +121,7 @@ DELIMITER $$
CREATE PROCEDURE lease6DumpHeader()
BEGIN
SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source';
-END $$
+END $$
DELIMITER ;
-- Modify the procedure to output a memfile-ready CSV file.
diff --git a/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in b/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in
index 95924119d2..94cbe8c7e9 100644
--- a/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in
@@ -213,6 +213,456 @@ CREATE TABLE lease6_remote_id (
INDEX key_lease6_remote_id_by_address (lease_addr)
) ENGINE = INNODB;
+# Add pool_id column to the lease4 table.
+ALTER TABLE lease4
+ ADD COLUMN pool_id INT UNSIGNED NOT NULL DEFAULT 0;
+
+# Add pool_id column to the lease6 table.
+ALTER TABLE lease6
+ ADD COLUMN pool_id INT UNSIGNED NOT NULL DEFAULT 0;
+
+# Create lease4_pool_stat table
+CREATE TABLE lease4_pool_stat (
+ subnet_id INT UNSIGNED NOT NULL,
+ pool_id INT UNSIGNED NOT NULL,
+ state INT UNSIGNED NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, state)
+) ENGINE = INNODB;
+
+# Create lease6_pool_stat table
+CREATE TABLE lease6_pool_stat (
+ subnet_id INT UNSIGNED NOT NULL,
+ pool_id INT UNSIGNED NOT NULL,
+ lease_type INT UNSIGNED NOT NULL,
+ state INT UNSIGNED NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, lease_type, state)
+) ENGINE = INNODB;
+
+DROP PROCEDURE IF EXISTS lease4_AINS_lease4_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease4_AINS_lease4_pool_stat(IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED)
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease4_AUPD_lease4_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease4_AUPD_lease4_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED,
+ IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED)
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert new state record if it does not exist.
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease4_ADEL_lease4_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease4_ADEL_lease4_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED)
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND old_state = state;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6_AINS_lease6_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease6_AINS_lease6_pool_stat(IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED,
+ IN new_lease_type TINYINT)
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6_AUPD_lease6_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease6_AUPD_lease6_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED,
+ IN old_lease_type TINYINT,
+ IN new_state TINYINT,
+ IN new_subnet_id INT UNSIGNED,
+ IN new_pool_id INT UNSIGNED,
+ IN new_lease_type TINYINT)
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_lease_type != new_lease_type OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease6_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert new state record if it does not exist
+ IF ROW_COUNT() <= 0 THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6_ADEL_lease6_pool_stat;
+DELIMITER $$
+CREATE PROCEDURE lease6_ADEL_lease6_pool_stat(IN old_state TINYINT,
+ IN old_subnet_id INT UNSIGNED,
+ IN old_pool_id INT UNSIGNED,
+ IN old_lease_type TINYINT)
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease6_pool_stat
+ SET leases = IF(leases > 0, leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease4_AINS;
+DELIMITER $$
+CREATE TRIGGER lease4_AINS AFTER INSERT ON lease4 FOR EACH ROW
+BEGIN
+ CALL lease4_AINS_lease4_stat(NEW.state, NEW.subnet_id);
+ CALL lease4_AINS_lease4_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease4_AINS_lease4_stat_by_client_class(NEW.state, NEW.user_context);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease4_AUPD;
+DELIMITER $$
+CREATE TRIGGER lease4_AUPD AFTER UPDATE ON lease4 FOR EACH ROW
+BEGIN
+ CALL lease4_AUPD_lease4_stat(OLD.state, OLD.subnet_id, NEW.state, NEW.subnet_id);
+ CALL lease4_AUPD_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, NEW.state, NEW.subnet_id, NEW.pool_id);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease4_AUPD_lease4_stat_by_client_class(OLD.state, OLD.user_context, NEW.state, NEW.user_context);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease4_ADEL;
+DELIMITER $$
+CREATE TRIGGER lease4_ADEL AFTER DELETE ON lease4 FOR EACH ROW
+BEGIN
+ CALL lease4_ADEL_lease4_stat(OLD.state, OLD.subnet_id);
+ CALL lease4_ADEL_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease4_ADEL_lease4_stat_by_client_class(OLD.state, OLD.user_context);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease6_AINS;
+DELIMITER $$
+CREATE TRIGGER lease6_AINS AFTER INSERT ON lease6 FOR EACH ROW
+BEGIN
+ CALL lease6_AINS_lease6_stat(NEW.state, NEW.subnet_id, NEW.lease_type);
+ CALL lease6_AINS_lease6_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease6_AINS_lease6_stat_by_client_class(NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease6_AUPD;
+DELIMITER $$
+CREATE TRIGGER lease6_AUPD AFTER UPDATE ON lease6 FOR EACH ROW
+BEGIN
+ CALL lease6_AUPD_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.lease_type);
+ CALL lease6_AUPD_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease6_AUPD_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type, NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP TRIGGER IF EXISTS lease6_ADEL;
+DELIMITER $$
+CREATE TRIGGER lease6_ADEL AFTER DELETE ON lease6 FOR EACH ROW
+BEGIN
+ CALL lease6_ADEL_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type);
+ CALL lease6_ADEL_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type);
+ IF @json_supported IS NULL THEN
+ SELECT isJsonSupported() INTO @json_supported;
+ END IF;
+ IF @json_supported = 1 THEN
+ CALL lease6_ADEL_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type);
+ END IF;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease4DumpHeader;
+DELIMITER $$
+CREATE PROCEDURE lease4DumpHeader()
+BEGIN
+SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id';
+END $$
+DELIMITER ;
+
+-- Modify the procedure to output a memfile-ready CSV file.
+DROP PROCEDURE IF EXISTS lease4DumpData;
+DELIMITER $$
+CREATE PROCEDURE lease4DumpData()
+BEGIN
+ SELECT
+ INET_NTOA(address),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ IFNULL(colonSeparatedHex(HEX(client_id)), ''),
+ valid_lifetime,
+ UNIX_TIMESTAMP(expire),
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, ',', '&#x2c'),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
+ pool_id
+ FROM lease4
+ ORDER BY address;
+END $$
+DELIMITER ;
+
+DROP PROCEDURE IF EXISTS lease6DumpHeader;
+DELIMITER $$
+CREATE PROCEDURE lease6DumpHeader()
+BEGIN
+ SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id';
+END $$
+DELIMITER ;
+
+-- Modify the procedure to output a memfile-ready CSV file.
+DROP PROCEDURE IF EXISTS lease6DumpData;
+DELIMITER $$
+CREATE PROCEDURE lease6DumpData()
+BEGIN
+ SELECT
+ address,
+ IFNULL(colonSeparatedHex(HEX(duid)), ''),
+ valid_lifetime,
+ UNIX_TIMESTAMP(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, ',', '&#x2c'),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ FROM lease6
+ ORDER BY address;
+END $$
+DELIMITER ;
+
+-- Create a procedure that inserts a v4 lease from memfile data.
+DROP PROCEDURE IF EXISTS lease4Upload;
+DELIMITER $$
+CREATE PROCEDURE lease4Upload(
+ IN address VARCHAR(15),
+ IN hwaddr VARCHAR(20),
+ IN client_id VARCHAR(128),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN pool_id INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease4 (
+ address,
+ hwaddr,
+ client_id,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ state,
+ user_context,
+ pool_id
+ ) VALUES (
+ INET_ATON(address),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ UNHEX(REPLACE(client_id, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ pool_id
+ );
+END $$
+DELIMITER ;
+
+-- Create a procedure that inserts a v6 lease from memfile data.
+DROP PROCEDURE IF EXISTS lease6Upload;
+DELIMITER $$
+CREATE PROCEDURE lease6Upload(
+ IN address VARCHAR(39),
+ IN duid VARCHAR(128),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN pref_lifetime INT UNSIGNED,
+ IN lease_type TINYINT,
+ IN iaid INT UNSIGNED,
+ IN prefix_len TINYINT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN hwaddr VARCHAR(64),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN hwtype SMALLINT,
+ IN hwaddr_source INT UNSIGNED,
+ IN pool_id INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source,
+ pool_id
+ ) VALUES (
+ address,
+ UNHEX(REPLACE(duid, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END $$
+DELIMITER ;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '18', minor = '0';
diff --git a/src/share/database/scripts/mysql/wipe_data.sh.in b/src/share/database/scripts/mysql/wipe_data.sh.in
index 411818bdc6..303e75150a 100644
--- a/src/share/database/scripts/mysql/wipe_data.sh.in
+++ b/src/share/database/scripts/mysql/wipe_data.sh.in
@@ -109,8 +109,10 @@ DELETE FROM hosts;
DELETE FROM ipv6_reservations;
DELETE FROM lease4;
DELETE FROM lease4_stat;
+DELETE FROM lease4_pool_stat;
DELETE FROM lease6;
DELETE FROM lease6_stat;
+DELETE FROM lease6_pool_stat;
DELETE FROM logs;
DELETE FROM lease4_stat_by_client_class;
DELETE FROM lease6_stat_by_client_class;
diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
index 0b20665a9b..1a1ec74a3f 100644
--- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
+++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
@@ -5658,6 +5658,470 @@ CREATE TABLE lease6_remote_id (
CREATE INDEX lease6_remote_id_by_id ON lease6_remote_id (remote_id, lease_addr ASC);
CREATE INDEX lease6_remote_id_by_address ON lease6_remote_id (lease_addr);
+-- Add pool_id column to the lease4 table.
+ALTER TABLE lease4
+ ADD COLUMN pool_id BIGINT NOT NULL DEFAULT 0;
+
+-- Add pool_id column to the lease6 table.
+ALTER TABLE lease6
+ ADD COLUMN pool_id BIGINT NOT NULL DEFAULT 0;
+
+-- Create v4 lease statistics table
+CREATE TABLE lease4_pool_stat (
+ subnet_id BIGINT NOT NULL,
+ pool_id BIGINT NOT NULL,
+ state INT8 NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, state)
+);
+
+-- Create v6 lease statistics table
+CREATE TABLE lease6_pool_stat (
+ subnet_id BIGINT NOT NULL,
+ pool_id BIGINT NOT NULL,
+ lease_type SMALLINT NOT NULL,
+ state INT8 NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, lease_type, state)
+);
+
+CREATE OR REPLACE FUNCTION lease4_AINS_lease4_pool_stat(IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT)
+RETURNS VOID
+AS $$
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF NOT FOUND THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease4_AUPD_lease4_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT,
+ IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT)
+RETURNS VOID
+AS $$
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert new state record if it does not exist.
+ IF NOT FOUND THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease4_ADEL_lease4_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT)
+RETURNS VOID
+AS $$
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND old_state = state;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease6_AINS_lease6_pool_stat(IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT,
+ IN new_lease_type SMALLINT)
+RETURNS VOID
+AS $$
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF NOT FOUND THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease6_AUPD_lease6_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT,
+ IN old_lease_type SMALLINT,
+ IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT,
+ IN new_lease_type SMALLINT)
+RETURNS VOID
+AS $$
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_lease_type != new_lease_type OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease6_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert new state record if it does not exist
+ IF NOT FOUND THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease6_ADEL_lease6_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT,
+ IN old_lease_type SMALLINT)
+RETURNS VOID
+AS $$
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease6_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease4_AINS()
+RETURNS trigger AS $lease4_AINS$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease4_AINS_lease4_stat_by_client_class(NEW.state, NEW.user_context);
+ END IF;
+ PERFORM lease4_AINS_lease4_stat(NEW.state, NEW.subnet_id);
+ PERFORM lease4_AINS_lease4_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id);
+ RETURN NULL;
+END;
+$lease4_AINS$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease4_AUPD()
+RETURNS trigger AS $lease4_AUPD$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease4_AUPD_lease4_stat_by_client_class(OLD.state, OLD.user_context, NEW.state, NEW.user_context);
+ END IF;
+ PERFORM lease4_AUPD_lease4_stat(OLD.state, OLD.subnet_id, NEW.state, NEW.subnet_id);
+ PERFORM lease4_AUPD_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, NEW.state, NEW.subnet_id, NEW.pool_id);
+ RETURN NULL;
+END;
+$lease4_AUPD$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease4_ADEL()
+RETURNS trigger AS $lease4_ADEL$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease4_ADEL_lease4_stat_by_client_class(OLD.state, OLD.user_context);
+ END IF;
+ PERFORM lease4_ADEL_lease4_stat(OLD.state, OLD.subnet_id);
+ PERFORM lease4_ADEL_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id);
+ RETURN NULL;
+END;
+$lease4_ADEL$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease6_AINS()
+RETURNS trigger AS $lease6_AINS$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease6_AINS_lease6_stat_by_client_class(NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+ PERFORM lease6_AINS_lease6_stat(NEW.state, NEW.subnet_id, NEW.lease_type);
+ PERFORM lease6_AINS_lease6_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ RETURN NULL;
+END;
+$lease6_AINS$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease6_AUPD()
+RETURNS trigger AS $lease6_AUPD$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease6_AUPD_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type, NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+ PERFORM lease6_AUPD_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.lease_type);
+ PERFORM lease6_AUPD_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ RETURN NULL;
+END;
+$lease6_AUPD$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease6_ADEL()
+RETURNS trigger AS $lease6_ADEL$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease6_ADEL_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type);
+ END IF;
+ PERFORM lease6_ADEL_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type);
+ PERFORM lease6_ADEL_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type);
+ RETURN NULL;
+END;
+$lease6_ADEL$ LANGUAGE plpgsql;
+
+DROP FUNCTION IF EXISTS lease4DumpHeader();
+CREATE OR REPLACE FUNCTION lease4DumpHeader()
+RETURNS text AS $$
+ select cast('address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id' as text) as result;
+$$ LANGUAGE SQL;
+
+-- Modify the function to output a memfile-ready CSV file.
+-- Some columns that are SMALLINT in the lease4 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+DROP FUNCTION IF EXISTS lease4DumpData();
+CREATE OR REPLACE FUNCTION lease4DumpData()
+RETURNS TABLE (
+ address INET,
+ hwaddr VARCHAR,
+ client_id VARCHAR,
+ valid_lifetime BIGINT,
+ expire BIGINT,
+ subnet_id BIGINT,
+ fqdn_fwd INT,
+ fqdn_rev INT,
+ hostname VARCHAR,
+ state INT8,
+ user_context VARCHAR,
+ pool_id BIGINT
+) AS $$
+ SELECT
+ ('0.0.0.0'::inet + address),
+ colonSeparatedHex(encode(hwaddr, 'hex')),
+ colonSeparatedHex(encode(client_id, 'hex')),
+ valid_lifetime,
+ extract(epoch from expire)::bigint,
+ subnet_id,
+ fqdn_fwd::int,
+ fqdn_rev::int,
+ replace(hostname, ',', '&#x2c'),
+ state,
+ replace(user_context, ',', '&#x2c'),
+ pool_id
+ FROM lease4
+ ORDER BY address;
+$$ LANGUAGE SQL;
+
+DROP FUNCTION IF EXISTS lease6DumpHeader();
+CREATE OR REPLACE FUNCTION lease6DumpHeader()
+RETURNS TEXT AS $$
+ SELECT CAST('address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id' AS TEXT) AS result;
+$$ LANGUAGE SQL;
+
+-- Modify the function to output a memfile-ready CSV file.
+-- Some columns that are SMALLINT in the lease6 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+DROP FUNCTION IF EXISTS lease6DumpData();
+CREATE OR REPLACE FUNCTION lease6DumpData()
+RETURNS TABLE (
+ address VARCHAR,
+ duid VARCHAR,
+ valid_lifetime BIGINT,
+ expire BIGINT,
+ subnet_id BIGINT,
+ pref_lifetime BIGINT,
+ lease_type SMALLINT,
+ iaid INT,
+ prefix_len SMALLINT,
+ fqdn_fwd INT,
+ fqdn_rev INT,
+ hostname VARCHAR,
+ hwaddr VARCHAR,
+ state INT8,
+ user_context VARCHAR,
+ hwtype SMALLINT,
+ hwaddr_source SMALLINT,
+ pool_id BIGINT
+) AS $$
+ SELECT
+ address,
+ colonSeparatedHex(encode(duid, 'hex')),
+ valid_lifetime,
+ extract(epoch from expire)::bigint,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd::int,
+ fqdn_rev::int,
+ replace(hostname, ',', '&#x2c'),
+ colonSeparatedHex(encode(hwaddr, 'hex')),
+ state,
+ replace(user_context, ',', '&#x2c'),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ FROM lease6
+ ORDER BY address;
+$$ LANGUAGE SQL;
+
+-- Create a procedure that inserts a v4 lease from memfile data.
+-- Some columns that are SMALLINT in the lease4 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+CREATE OR REPLACE FUNCTION lease4Upload(
+ IN address VARCHAR,
+ IN hwaddr VARCHAR,
+ IN client_id VARCHAR,
+ IN valid_lifetime BIGINT,
+ IN expire BIGINT,
+ IN subnet_id BIGINT,
+ IN fqdn_fwd INT,
+ IN fqdn_rev INT,
+ IN hostname VARCHAR,
+ IN state INT8,
+ IN user_context VARCHAR,
+ IN pool_id BIGINT
+) RETURNS VOID AS $$
+BEGIN
+ INSERT INTO lease4 (
+ address,
+ hwaddr,
+ client_id,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ state,
+ user_context,
+ pool_id
+ ) VALUES (
+ address::inet - '0.0.0.0'::inet,
+ decode(replace(hwaddr, ':', ''), 'hex'),
+ decode(replace(client_id, ':', ''), 'hex'),
+ valid_lifetime,
+ to_timestamp(expire),
+ subnet_id,
+ fqdn_fwd::int::boolean,
+ fqdn_rev::int::boolean,
+ replace(hostname, '&#x2c', ','),
+ state,
+ replace(user_context, '&#x2c', ','),
+ pool_id
+ );
+END
+$$ LANGUAGE plpgsql;
+
+-- Create a procedure that inserts a v6 lease from memfile data.
+-- Some columns that are SMALLINT in the lease6 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+CREATE OR REPLACE FUNCTION lease6Upload(
+ IN address VARCHAR,
+ IN duid VARCHAR,
+ IN valid_lifetime BIGINT,
+ IN expire BIGINT,
+ IN subnet_id BIGINT,
+ IN pref_lifetime BIGINT,
+ IN lease_type INT,
+ IN iaid INT,
+ IN prefix_len INT,
+ IN fqdn_fwd INT,
+ IN fqdn_rev INT,
+ IN hostname VARCHAR,
+ IN hwaddr VARCHAR,
+ IN state INT8,
+ IN user_context VARCHAR,
+ IN hwtype INT,
+ IN hwaddr_source INT,
+ IN pool_id BIGINT
+) RETURNS VOID AS $$
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source,
+ pool_id
+ ) VALUES (
+ address,
+ decode(replace(duid, ':', ''), 'hex'),
+ valid_lifetime,
+ to_timestamp(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd::int::boolean,
+ fqdn_rev::int::boolean,
+ replace(hostname, '&#x2c', ','),
+ decode(replace(hwaddr, ':', ''), 'hex'),
+ state,
+ replace(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END
+$$ LANGUAGE plpgsql;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '17', minor = '0';
diff --git a/src/share/database/scripts/pgsql/dhcpdb_drop.pgsql b/src/share/database/scripts/pgsql/dhcpdb_drop.pgsql
index 7709bf622c..044d9aa234 100644
--- a/src/share/database/scripts/pgsql/dhcpdb_drop.pgsql
+++ b/src/share/database/scripts/pgsql/dhcpdb_drop.pgsql
@@ -21,10 +21,12 @@ DROP FUNCTION IF EXISTS lease4DumpData();
DROP FUNCTION IF EXISTS lease6DumpHeader();
DROP FUNCTION IF EXISTS lease6DumpData();
DROP TABLE IF EXISTS lease4_stat CASCADE;
+DROP TABLE IF EXISTS lease4_pool_stat CASCADE;
DROP FUNCTION IF EXISTS proc_stat_lease4_insert ();
DROP FUNCTION IF EXISTS proc_stat_lease4_update ();
DROP FUNCTION IF EXISTS proc_stat_lease4_delete ();
DROP TABLE IF EXISTS lease6_stat CASCADE;
+DROP TABLE IF EXISTS lease6_pool_stat CASCADE;
DROP FUNCTION IF EXISTS proc_stat_lease6_insert ();
DROP FUNCTION IF EXISTS proc_stat_lease6_update ();
DROP FUNCTION IF EXISTS proc_stat_lease6_delete ();
@@ -202,6 +204,21 @@ DROP FUNCTION IF EXISTS lease6_AUPD_lease6_stat(old_state BIGINT,
new_subnet_id BIGINT, new_lease_type SMALLINT);
DROP FUNCTION IF EXISTS lease6_ADEL_lease6_stat(old_state BIGINT,
old_subnet_id BIGINT, old_lease_type SMALLINT);
+DROP FUNCTION IF EXISTS lease4_AINS_lease4_pool_stat(new_state BIGINT,
+ new_subnet_id BIGINT, new_pool_id BIGINT);
+DROP FUNCTION IF EXISTS lease4_AUPD_lease4_pool_stat(old_state BIGINT,
+ old_subnet_id BIGINT, old_pool_id BIGINT, new_state BIGINT,
+ new_subnet_id BIGINT, new_pool_id BIGINT);
+DROP FUNCTION IF EXISTS lease4_ADEL_lease4_pool_stat(old_state BIGINT,
+ old_subnet_id BIGINT, old_pool_id BIGINT);
+DROP FUNCTION IF EXISTS lease6_AINS_lease6_pool_stat(new_state BIGINT,
+ new_subnet_id BIGINT, new_pool_id BIGINT, new_lease_type SMALLINT);
+DROP FUNCTION IF EXISTS lease6_AUPD_lease6_pool_stat(old_state BIGINT,
+ old_subnet_id BIGINT, old_pool_id BIGINT, old_lease_type SMALLINT,
+ new_state BIGINT, new_subnet_id BIGINT, new_pool_id BIGINT,
+ new_lease_type SMALLINT);
+DROP FUNCTION IF EXISTS lease6_ADEL_lease6_pool_stat(old_state BIGINT,
+ old_subnet_id BIGINT, old_pool_id BIGINT, old_lease_type SMALLINT);
DROP FUNCTION IF EXISTS lease4_AINS_lease4_stat_by_client_class(
new_state BIGINT, new_user_context TEXT);
DROP FUNCTION IF EXISTS lease4_AUPD_lease4_stat_by_client_class(
diff --git a/src/share/database/scripts/pgsql/upgrade_016_to_017.sh.in b/src/share/database/scripts/pgsql/upgrade_016_to_017.sh.in
index e84b5cf5f2..4300285390 100644
--- a/src/share/database/scripts/pgsql/upgrade_016_to_017.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_016_to_017.sh.in
@@ -61,6 +61,470 @@ CREATE TABLE lease6_remote_id (
CREATE INDEX lease6_remote_id_by_id ON lease6_remote_id (remote_id, lease_addr ASC);
CREATE INDEX lease6_remote_id_by_address ON lease6_remote_id (lease_addr);
+-- Add pool_id column to the lease4 table.
+ALTER TABLE lease4
+ ADD COLUMN pool_id BIGINT NOT NULL DEFAULT 0;
+
+-- Add pool_id column to the lease6 table.
+ALTER TABLE lease6
+ ADD COLUMN pool_id BIGINT NOT NULL DEFAULT 0;
+
+-- Create v4 lease statistics table
+CREATE TABLE lease4_pool_stat (
+ subnet_id BIGINT NOT NULL,
+ pool_id BIGINT NOT NULL,
+ state INT8 NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, state)
+);
+
+-- Create v6 lease statistics table
+CREATE TABLE lease6_pool_stat (
+ subnet_id BIGINT NOT NULL,
+ pool_id BIGINT NOT NULL,
+ lease_type SMALLINT NOT NULL,
+ state INT8 NOT NULL,
+ leases BIGINT,
+ PRIMARY KEY (subnet_id, pool_id, lease_type, state)
+);
+
+CREATE OR REPLACE FUNCTION lease4_AINS_lease4_pool_stat(IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT)
+RETURNS VOID
+AS \$\$
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF NOT FOUND THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+END;
+\$\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease4_AUPD_lease4_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT,
+ IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT)
+RETURNS VOID
+AS \$\$
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists.
+ UPDATE lease4_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND state = new_state;
+
+ -- Insert new state record if it does not exist.
+ IF NOT FOUND THEN
+ INSERT INTO lease4_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END;
+\$\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease4_ADEL_lease4_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT)
+RETURNS VOID
+AS \$\$
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists.
+ UPDATE lease4_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND old_state = state;
+ END IF;
+END;
+\$\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease6_AINS_lease6_pool_stat(IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT,
+ IN new_lease_type SMALLINT)
+RETURNS VOID
+AS \$\$
+BEGIN
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Update the state count if it exists.
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert the state count record if it does not exist.
+ IF NOT FOUND THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+END;
+\$\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease6_AUPD_lease6_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT,
+ IN old_lease_type SMALLINT,
+ IN new_state BIGINT,
+ IN new_subnet_id BIGINT,
+ IN new_pool_id BIGINT,
+ IN new_lease_type SMALLINT)
+RETURNS VOID
+AS \$\$
+BEGIN
+ IF old_subnet_id != new_subnet_id OR
+ old_pool_id != new_pool_id OR
+ old_lease_type != new_lease_type OR
+ old_state != new_state THEN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the old state count if record exists.
+ UPDATE lease6_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+
+ IF new_state = 0 OR new_state = 1 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease6_pool_stat SET leases = leases + 1
+ WHERE subnet_id = new_subnet_id AND pool_id = new_pool_id
+ AND lease_type = new_lease_type AND state = new_state;
+
+ -- Insert new state record if it does not exist
+ IF NOT FOUND THEN
+ INSERT INTO lease6_pool_stat
+ VALUES (new_subnet_id, new_pool_id, new_lease_type, new_state, 1);
+ END IF;
+ END IF;
+ END IF;
+END;
+\$\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION lease6_ADEL_lease6_pool_stat(IN old_state BIGINT,
+ IN old_subnet_id BIGINT,
+ IN old_pool_id BIGINT,
+ IN old_lease_type SMALLINT)
+RETURNS VOID
+AS \$\$
+BEGIN
+ IF old_state = 0 OR old_state = 1 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease6_pool_stat
+ SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = old_subnet_id AND pool_id = old_pool_id
+ AND lease_type = old_lease_type AND state = old_state;
+ END IF;
+END;
+\$\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease4_AINS()
+RETURNS trigger AS \$lease4_AINS\$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease4_AINS_lease4_stat_by_client_class(NEW.state, NEW.user_context);
+ END IF;
+ PERFORM lease4_AINS_lease4_stat(NEW.state, NEW.subnet_id);
+ PERFORM lease4_AINS_lease4_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id);
+ RETURN NULL;
+END;
+\$lease4_AINS\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease4_AUPD()
+RETURNS trigger AS \$lease4_AUPD\$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease4_AUPD_lease4_stat_by_client_class(OLD.state, OLD.user_context, NEW.state, NEW.user_context);
+ END IF;
+ PERFORM lease4_AUPD_lease4_stat(OLD.state, OLD.subnet_id, NEW.state, NEW.subnet_id);
+ PERFORM lease4_AUPD_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, NEW.state, NEW.subnet_id, NEW.pool_id);
+ RETURN NULL;
+END;
+\$lease4_AUPD\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease4_ADEL()
+RETURNS trigger AS \$lease4_ADEL\$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease4_ADEL_lease4_stat_by_client_class(OLD.state, OLD.user_context);
+ END IF;
+ PERFORM lease4_ADEL_lease4_stat(OLD.state, OLD.subnet_id);
+ PERFORM lease4_ADEL_lease4_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id);
+ RETURN NULL;
+END;
+\$lease4_ADEL\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease6_AINS()
+RETURNS trigger AS \$lease6_AINS\$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease6_AINS_lease6_stat_by_client_class(NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+ PERFORM lease6_AINS_lease6_stat(NEW.state, NEW.subnet_id, NEW.lease_type);
+ PERFORM lease6_AINS_lease6_pool_stat(NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ RETURN NULL;
+END;
+\$lease6_AINS\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease6_AUPD()
+RETURNS trigger AS \$lease6_AUPD\$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease6_AUPD_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type, NEW.state, NEW.user_context, NEW.lease_type);
+ END IF;
+ PERFORM lease6_AUPD_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.lease_type);
+ PERFORM lease6_AUPD_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type, NEW.state, NEW.subnet_id, NEW.pool_id, NEW.lease_type);
+ RETURN NULL;
+END;
+\$lease6_AUPD\$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION func_lease6_ADEL()
+RETURNS trigger AS \$lease6_ADEL\$
+BEGIN
+ IF isJsonSupported() = true THEN
+ PERFORM lease6_ADEL_lease6_stat_by_client_class(OLD.state, OLD.user_context, OLD.lease_type);
+ END IF;
+ PERFORM lease6_ADEL_lease6_stat(OLD.state, OLD.subnet_id, OLD.lease_type);
+ PERFORM lease6_ADEL_lease6_pool_stat(OLD.state, OLD.subnet_id, OLD.pool_id, OLD.lease_type);
+ RETURN NULL;
+END;
+\$lease6_ADEL\$ LANGUAGE plpgsql;
+
+DROP FUNCTION IF EXISTS lease4DumpHeader();
+CREATE OR REPLACE FUNCTION lease4DumpHeader()
+RETURNS text AS \$\$
+ select cast('address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id' as text) as result;
+\$\$ LANGUAGE SQL;
+
+-- Modify the function to output a memfile-ready CSV file.
+-- Some columns that are SMALLINT in the lease4 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+DROP FUNCTION IF EXISTS lease4DumpData();
+CREATE OR REPLACE FUNCTION lease4DumpData()
+RETURNS TABLE (
+ address INET,
+ hwaddr VARCHAR,
+ client_id VARCHAR,
+ valid_lifetime BIGINT,
+ expire BIGINT,
+ subnet_id BIGINT,
+ fqdn_fwd INT,
+ fqdn_rev INT,
+ hostname VARCHAR,
+ state INT8,
+ user_context VARCHAR,
+ pool_id BIGINT
+) AS \$\$
+ SELECT
+ ('0.0.0.0'::inet + address),
+ colonSeparatedHex(encode(hwaddr, 'hex')),
+ colonSeparatedHex(encode(client_id, 'hex')),
+ valid_lifetime,
+ extract(epoch from expire)::bigint,
+ subnet_id,
+ fqdn_fwd::int,
+ fqdn_rev::int,
+ replace(hostname, ',', '&#x2c'),
+ state,
+ replace(user_context, ',', '&#x2c'),
+ pool_id
+ FROM lease4
+ ORDER BY address;
+\$\$ LANGUAGE SQL;
+
+DROP FUNCTION IF EXISTS lease6DumpHeader();
+CREATE OR REPLACE FUNCTION lease6DumpHeader()
+RETURNS TEXT AS \$\$
+ SELECT CAST('address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id' AS TEXT) AS result;
+\$\$ LANGUAGE SQL;
+
+-- Modify the function to output a memfile-ready CSV file.
+-- Some columns that are SMALLINT in the lease6 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+DROP FUNCTION IF EXISTS lease6DumpData();
+CREATE OR REPLACE FUNCTION lease6DumpData()
+RETURNS TABLE (
+ address VARCHAR,
+ duid VARCHAR,
+ valid_lifetime BIGINT,
+ expire BIGINT,
+ subnet_id BIGINT,
+ pref_lifetime BIGINT,
+ lease_type SMALLINT,
+ iaid INT,
+ prefix_len SMALLINT,
+ fqdn_fwd INT,
+ fqdn_rev INT,
+ hostname VARCHAR,
+ hwaddr VARCHAR,
+ state INT8,
+ user_context VARCHAR,
+ hwtype SMALLINT,
+ hwaddr_source SMALLINT,
+ pool_id BIGINT
+) AS \$\$
+ SELECT
+ address,
+ colonSeparatedHex(encode(duid, 'hex')),
+ valid_lifetime,
+ extract(epoch from expire)::bigint,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd::int,
+ fqdn_rev::int,
+ replace(hostname, ',', '&#x2c'),
+ colonSeparatedHex(encode(hwaddr, 'hex')),
+ state,
+ replace(user_context, ',', '&#x2c'),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ FROM lease6
+ ORDER BY address;
+\$\$ LANGUAGE SQL;
+
+-- Create a procedure that inserts a v4 lease from memfile data.
+-- Some columns that are SMALLINT in the lease4 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+CREATE OR REPLACE FUNCTION lease4Upload(
+ IN address VARCHAR,
+ IN hwaddr VARCHAR,
+ IN client_id VARCHAR,
+ IN valid_lifetime BIGINT,
+ IN expire BIGINT,
+ IN subnet_id BIGINT,
+ IN fqdn_fwd INT,
+ IN fqdn_rev INT,
+ IN hostname VARCHAR,
+ IN state INT8,
+ IN user_context VARCHAR,
+ IN pool_id BIGINT
+) RETURNS VOID AS \$\$
+BEGIN
+ INSERT INTO lease4 (
+ address,
+ hwaddr,
+ client_id,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ state,
+ user_context,
+ pool_id
+ ) VALUES (
+ address::inet - '0.0.0.0'::inet,
+ decode(replace(hwaddr, ':', ''), 'hex'),
+ decode(replace(client_id, ':', ''), 'hex'),
+ valid_lifetime,
+ to_timestamp(expire),
+ subnet_id,
+ fqdn_fwd::int::boolean,
+ fqdn_rev::int::boolean,
+ replace(hostname, '&#x2c', ','),
+ state,
+ replace(user_context, '&#x2c', ','),
+ pool_id
+ );
+END
+\$\$ LANGUAGE plpgsql;
+
+-- Create a procedure that inserts a v6 lease from memfile data.
+-- Some columns that are SMALLINT in the lease6 table have their type promoted
+-- to INT in the declaration of this function for backwards compatibility with
+-- PostgreSQL versions.
+CREATE OR REPLACE FUNCTION lease6Upload(
+ IN address VARCHAR,
+ IN duid VARCHAR,
+ IN valid_lifetime BIGINT,
+ IN expire BIGINT,
+ IN subnet_id BIGINT,
+ IN pref_lifetime BIGINT,
+ IN lease_type INT,
+ IN iaid INT,
+ IN prefix_len INT,
+ IN fqdn_fwd INT,
+ IN fqdn_rev INT,
+ IN hostname VARCHAR,
+ IN hwaddr VARCHAR,
+ IN state INT8,
+ IN user_context VARCHAR,
+ IN hwtype INT,
+ IN hwaddr_source INT,
+ IN pool_id BIGINT
+) RETURNS VOID AS \$\$
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source,
+ pool_id
+ ) VALUES (
+ address,
+ decode(replace(duid, ':', ''), 'hex'),
+ valid_lifetime,
+ to_timestamp(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd::int::boolean,
+ fqdn_rev::int::boolean,
+ replace(hostname, '&#x2c', ','),
+ decode(replace(hwaddr, ':', ''), 'hex'),
+ state,
+ replace(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END
+\$\$ LANGUAGE plpgsql;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '17', minor = '0';
diff --git a/src/share/database/scripts/pgsql/wipe_data.sh.in b/src/share/database/scripts/pgsql/wipe_data.sh.in
index 79a0e3f154..7c9c637233 100644
--- a/src/share/database/scripts/pgsql/wipe_data.sh.in
+++ b/src/share/database/scripts/pgsql/wipe_data.sh.in
@@ -69,8 +69,10 @@ DELETE FROM ipv6_reservations;
DELETE FROM dhcp6_options;
DELETE FROM lease4;
DELETE FROM lease4_stat;
+DELETE FROM lease4_pool_stat;
DELETE FROM lease6;
DELETE FROM lease6_stat;
+DELETE FROM lease6_pool_stat;
DELETE FROM logs;
DELETE FROM lease4_stat_by_client_class;
DELETE FROM lease6_stat_by_client_class;