-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ˎxampleˌom,2,{ "a": 1, "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ˎxampleˌom,2,{ "a": 1, "b": "c" },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
-::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ˎxampleˌom,38:30,2,{ "a": 1, "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ˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },90,4,0
# 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ˎxampleˌom,0,{"a":1,"b":2}'
+ printf '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,oneˎxampleˌom,0,{"a":1,"b":2},0'
}
memfile_data_v6() {
- printf '::10,32:30:33,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{"a":1,"b":2},90,16'
+ printf '::10,32:30:33,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{"a":1,"b":2},90,16,0'
}
# @}
# 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ˎxampleˌom,0,{ "a": 1, "b": 2 }' "${output}"
+ assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,oneˎxampleˌom,0,{ "a": 1, "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ˎxampleˌom,38:30,0,{ "a": 1, "b": 2 },90,16' "${output}"
+ assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{ "a": 1, "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}"
}
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.
# 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"
# 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"
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ˎxampleˌom,0,{ "a": 1, "b": 2 }' "${OUTPUT}"
+ assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,oneˎxampleˌom,0,{ "a": 1, "b": 2 },0' "${OUTPUT}"
# Check lease6Dump*().
run_command \
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ˎxampleˌom,38:30,0,{ "a": 1, "b": 2 },16,0' "${OUTPUT}"
+ assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{ "a": 1, "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}"
}
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);
}
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));
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.
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));
+ }
+ }
}
}
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));
// 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_) {
"{ \"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"
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);
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();
// 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
// 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
// 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"));
// 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";
// 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"));
// 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.
// 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");
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));
+ }
}
}
}
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));
+ }
}
}
}
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 {
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));
+ }
}
}
}
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_) {
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 {
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));
+ }
}
}
}
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));
+ }
}
}
}
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));
+ }
}
}
}
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) {
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;
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) {
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;
return (impl_->leaseWriteHandler(handle));
}
-LeaseCmds::LeaseCmds()
- :impl_(new LeaseCmdsImpl()) {
+LeaseCmds::LeaseCmds() : impl_(new LeaseCmdsImpl()) {
}
} // end of namespace lease_cmds
#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>
"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
"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);
"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.
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));
}
}
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));
}
// 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);
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));
}
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));
}
}
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
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
// 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);
// 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.
.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));
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));
+ }
+ }
}
}
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));
// 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));
}
// 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));
}
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);
}
}
}
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);
}
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")));
+ }
}
}
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.
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);
}
// 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"));
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"));
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")));
+ }
}
}
"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));
}
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.
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&) {
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_;
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");
}
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"));
/// - hostname
/// - state
/// - user_context
+ /// - pool_id
void initColumns();
///
/// @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.
/// @param row CSV file row holding lease information.
data::ConstElementPtr readContext(const util::CSVRow& row);
//@}
-
};
} // namespace isc::dhcp
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&) {
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_;
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");
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"));
/// - user_context
/// - hwtype
/// - hwaddr_source
+ /// - pool_id
void initColumns();
///
/// @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.
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);
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
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());
}
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());
}
// 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) {
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");
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");
#include <sstream>
#include <iostream>
-
using namespace isc::util;
using namespace isc::data;
using namespace std;
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) {
isc_throw(BadValue, "parsed lease data is not a JSON map");
}
-
if (!lease) {
isc_throw(Unexpected, "pointer to parsed lease is null");
}
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) {
if (other.client_id_) {
client_id_.reset(new ClientId(other.client_id_->getClientId()));
-
} else {
client_id_.reset();
-
}
if (other.getContext()) {
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_;
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_) {
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) {
<< "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()) {
<< "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"
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_ &&
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_ &&
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_)));
/// 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.
"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
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()
"assigned-nas"),
zero);
+ stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
+ "assigned-pds"),
+ zero);
+
stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
"declined-addresses"),
zero);
zero);
}
- stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
- "assigned-pds"),
- zero);
-
if (!stats_mgr.getObservation(
StatsMgr::generateName("subnet", subnet_id,
"reclaimed-leases"))) {
"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
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.
// 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;
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;
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
/// 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
/// 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;
/// @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 { };
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.
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.
/// @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;
/// @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;
//@}
"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 "
"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 "
"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 "
"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"
"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"
"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"
"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 "
"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"
"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"
"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"
"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, "
"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,
"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,
"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 = ?"},
"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 "
"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,
"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,
"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,
"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 "
"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 = ?, "
"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 = ?, "
"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 "
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:
/// 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_));
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
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,
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.
remote_id_buffer_ + remote_id_length_);
}
+ // Set pool ID
+ lease->pool_id_ = pool_id_;
+
return (lease);
}
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
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:
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) {
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
// 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,
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.
result->setContext(ctx);
}
+ // Set pool ID.
+ result->pool_id_ = pool_id_;
+
return (result);
}
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
} else {
def.reset(new OptionDefinition(name, code, space, type,
- encapsulates.c_str()));
+ encapsulates.c_str()));
}
} else {
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.
"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
"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"},
"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"},
"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"},
"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"},
"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"},
"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 "
"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"},
"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"},
"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 "
"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 "
"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 "
"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 "
"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 "
"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 "
"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 "
"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 "
"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 "
"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
"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"},
"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"},
"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"},
"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 "
"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"},
"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"},
"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"},
"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 "
"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 },
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(){}
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_;
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:
: 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_));
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: "
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_,
remote_id_buffer_ + remote_id_length_);
}
+ result->pool_id_ = pool_id_;
+
return (result);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
/// @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.
/// 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:
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_));
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: "
}
}
+ getColumnValue(r, row , POOL_ID_COL, pool_id_);
+
Lease6Ptr result(boost::make_shared<Lease6>(lease_type_, addr,
duid_ptr,
iaid_u_.uval_,
result->setContext(ctx);
}
+ result->pool_id_ = pool_id_;
+
return (result);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
/// @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.
//@{
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 {
/// @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
/// 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.
///
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_;
/// @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
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
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
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.
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
///
/// @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());
}
/// @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());
-};
+}
}
// 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;
// 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);
// 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);
// 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
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);
}
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;
}
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()) {
// 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);
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());
}
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());
}
/// @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).
///
/// 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)
///
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("::"));
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());
}
}
}
-
// Verifies that a lease file with fewer header columns than the
// minimum allowed will not open.
TEST_F(CSVLeaseFile4Test, tooFewHeaderColumns) {
// 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_);
// 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());
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.
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
-
// Fifth lease is invalid - DUID is empty, state is not DECLINED
{
SCOPED_TRACE("Fifth lease invalid");
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());
}
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_);
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());
}
}
-
// 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.
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));
}
// 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_);
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));
}
// 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_);
/// @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";
}
};
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)
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
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",
"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;
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,
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
// 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",
"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;
// 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;
<< "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"
<< "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";
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 0,"
"\"user-context\": { \"foobar\": 1234 },"
"\"valid-lft\": 3600 "
"}";
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 0,"
"\"valid-lft\": 3600 "
"}";
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 0,"
"\"valid-lft\": 3600 "
"}";
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
"\"subnet-id\": 789,"
+ "\"pool-id\": 5,"
"\"user-context\": { \"foo\": \"bar\" },"
"\"valid-lft\": 3600 "
"}";
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_);
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);
// 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[] = {
// 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[] = {
}
// 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)));
<< "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";
<< "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());
}
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 0,"
"\"type\": \"IA_NA\","
"\"user-context\": { \"foobar\": 1234 },"
"\"valid-lft\": 800"
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 0,"
"\"type\": \"IA_NA\","
"\"valid-lft\": 800"
"}";
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 0,"
"\"type\": \"IA_NA\","
"\"valid-lft\": 800"
"}";
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());
"\"preferred-lft\": 400,"
"\"state\": 1,"
"\"subnet-id\": 5678,"
+ "\"pool-id\": 5,"
"\"type\": \"IA_NA\","
"\"user-context\": { \"foobar\": 1234 },"
"\"valid-lft\": 800"
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_);
"\"prefix-len\": 32,"
"\"state\": 0,"
"\"subnet-id\": 1234,"
+ "\"pool-id\": 5,"
"\"type\": \"IA_PD\","
"\"valid-lft\": 600"
"}";
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_);
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"));
// 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);
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
"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);
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
// 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
// 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);
"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);
// 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);
"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);
// 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);
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);
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);
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);
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);
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);
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);
"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 +
// 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.
<< "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());
}
"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 +
// 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.
<< "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());
}
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\","
- " \"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\", \"c\": { \"d\": 1,\"e\": 2 } }\n"
+ "{ \"a\": \"b\", \"c\": { \"d\": 1,\"e\": 2 } },0\n"
);
// Not sanitize user contexts.
"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"
"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"
"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"
"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"
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\","
- " \"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\", \"c\": { \"d\": 1,\"e\": 2 } }\n"
+ "{ \"a\": \"b\", \"c\": { \"d\": 1,\"e\": 2 } },,,0\n"
);
// Not sanitize user contexts.
"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"
);
"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"
"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"
// 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"
"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"
);
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
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;
}
}
"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);
// 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);
// 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);
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);
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);
// 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();
// 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();
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();
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();
// 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");
// 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");
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");
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");
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.
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.
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.
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\", "
"\"remote-id\": \"010203\", "
- "\"sub-options\": \"0x02030102030C03AABBCC\" } } }\n";
+ "\"sub-options\": \"0x02030102030C03AABBCC\" } } },0\n";
string expected = content + new_content;
EXPECT_EQ(expected, io.readFile());
}
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,"
" \"link\": \"2001:db8::4\", \"peer\": \"2001:db8::5\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Start the lease manager.
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,"
" \"link\": \"2001:db8::4\", \"peer\": \"2001:db8::5\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Disable sanitizing.
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,"
" \"remote-id\": \"010203040506\","
" \"relay-id\": \"6464646464646464\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Disable sanitizing.
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,"
" \"remote-id\": \"010203040506\","
" \"relay-id\": \"6464646464646464\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Start the lease manager.
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,"
" \"link\": \"2001:db8::4\", \"peer\": \"2001:db8::5\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n";
+ " } ] } },,,0\n";
io.writeFile(content);
// Disable sanitizing.
// 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,"
" \"options\": \"0x00250006010203040506003500086464646464646464\""
", \"peer\": \"2001:db8::5\","
" \"relay-id\": \"6464646464646464\","
- " \"remote-id\": \"010203040506\" } ] } },,\n";
+ " \"remote-id\": \"010203040506\" } ] } },,,0\n";
string expected = content + new_content;
EXPECT_EQ(expected, io.readFile());
}
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,"
" \"remote-id\": \"010203040506\","
" \"relay-id\": \"6464646464646464\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""
- " } ] } },,\n"
+ " } ] } },,,0\n"
);
// Disable sanitizing.
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"));
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);
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"));
BadValue);
}
-TEST(Pool6Test, in_range) {
+TEST(Pool6Test, inRange) {
Pool6 pool1(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
IOAddress("2001:db8:1::f"));
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"),
EXPECT_TRUE(pool.getRequiredClasses().contains("foo"));
}
-}; // end of anonymous namespace
+} // end of anonymous namespace
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
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
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
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
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.
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, ',', ','),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', ','),
+ 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, ',', ','),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', ','),
+ 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, ',', ','),
+ state,
+ REPLACE(user_context, ',', ','),
+ 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, ',', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, ',', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END $$
+DELIMITER ;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '18', minor = '0';
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;
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;
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
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
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
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
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.
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, ',', ','),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', ','),
+ 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, ',', ','),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', ','),
+ 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, ',', ','),
+ state,
+ REPLACE(user_context, ',', ','),
+ 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, ',', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, ',', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END $$
+DELIMITER ;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '18', minor = '0';
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;
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, ',', ','),
+ state,
+ replace(user_context, ',', ','),
+ 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, ',', ','),
+ colonSeparatedHex(encode(hwaddr, 'hex')),
+ state,
+ replace(user_context, ',', ','),
+ 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, ',', ','),
+ state,
+ replace(user_context, ',', ','),
+ 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, ',', ','),
+ decode(replace(hwaddr, ':', ''), 'hex'),
+ state,
+ replace(user_context, ',', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END
+$$ LANGUAGE plpgsql;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '17', minor = '0';
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 ();
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(
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, ',', ','),
+ state,
+ replace(user_context, ',', ','),
+ 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, ',', ','),
+ colonSeparatedHex(encode(hwaddr, 'hex')),
+ state,
+ replace(user_context, ',', ','),
+ 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, ',', ','),
+ state,
+ replace(user_context, ',', ','),
+ 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, ',', ','),
+ decode(replace(hwaddr, ':', ''), 'hex'),
+ state,
+ replace(user_context, ',', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END
+\$\$ LANGUAGE plpgsql;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '17', minor = '0';
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;