]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4492] Replaced create cmd with rebuild cmd
authorThomas Markwalder <tmark@isc.org>
Thu, 14 May 2026 12:55:17 +0000 (08:55 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 12 May 2026 17:17:33 +0000 (17:17 +0000)
Replaced sflq-poolX-create with sflq-poolX-rebuild,
the latter takes only start and end addresses and
the pool must already exist.

/src/hooks/dhcp/lease_cmds/lease_cmds_callouts.cc
/src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes
/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds_unittest.cc
/src/hooks/dhcp/lease_cmds/libloadtests/sflq_cmds_unittests.cc
/src/hooks/dhcp/lease_cmds/sflq_cmds.cc
/src/hooks/dhcp/lease_cmds/sflq_cmds.h

/doc/sphinx/api-files.txt
/doc/sphinx/arm/hooks-lease-cmds.rst
/src/share/api/sflq-pool4-rebuild.json
/src/share/api/sflq-pool6-rebuild.json

/src/hooks/dhcp/mysql/mysql_lease_mgr.cc
    fixed a shadow warning

14 files changed:
doc/sphinx/api-files.txt
doc/sphinx/arm/hooks-lease-cmds.rst
src/hooks/dhcp/lease_cmds/lease_cmds_callouts.cc
src/hooks/dhcp/lease_cmds/lease_cmds_messages.cc
src/hooks/dhcp/lease_cmds/lease_cmds_messages.h
src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds_unittest.cc
src/hooks/dhcp/lease_cmds/libloadtests/sflq_cmds_unittests.cc
src/hooks/dhcp/lease_cmds/sflq_cmds.cc
src/hooks/dhcp/lease_cmds/sflq_cmds.h
src/hooks/dhcp/mysql/mysql_lease_mgr.cc
src/share/api/sflq-pool4-rebuild.json [moved from src/share/api/sflq-pool4-create.json with 53% similarity]
src/share/api/sflq-pool6-create.json [deleted file]
src/share/api/sflq-pool6-rebuild.json [new file with mode: 0644]

index 5662788d1ceceafe3e249daab82788040900b05f..1a55ac40026ffb5a3af06952b6f2028a6fae9d2c 100644 (file)
@@ -171,16 +171,16 @@ src/share/api/reservation-get-by-id.json
 src/share/api/reservation-get-page.json
 src/share/api/reservation-update.json
 src/share/api/server-tag-get.json
-src/share/api/sflq-pool4-create.json
 src/share/api/sflq-pool4-del.json
 src/share/api/sflq-pool4-get-all.json
 src/share/api/sflq-pool4-get-by-range.json
 src/share/api/sflq-pool4-get-by-subnet.json
-src/share/api/sflq-pool6-create.json
+src/share/api/sflq-pool4-rebuild.json
 src/share/api/sflq-pool6-del.json
 src/share/api/sflq-pool6-get-all.json
 src/share/api/sflq-pool6-get-by-range.json
 src/share/api/sflq-pool6-get-by-subnet.json
+src/share/api/sflq-pool6-rebuild.json
 src/share/api/shutdown.json
 src/share/api/statistic-get.json
 src/share/api/statistic-get-all.json
index c2e1cda0869ee067bb030f4a64475234f1ca9e31..dafd79fb6562df4c7ebe1798882e65b74dcdeda3 100644 (file)
@@ -113,30 +113,30 @@ This library provides the following commands:
 
 -  :isccmd:`lease6-write` - writes the IPv6 memfile lease database into a file.
 
--  :iscmd:`sflq-pool4-create` - creates an IPv4 SFLQ pool in the lease back end.
+-  :isccmd:`sflq-pool4-rebuild` - rebuilds an IPv4 SFLQ pool in the lease back end.
 
--  :iscmd:`sflq-pool6-create` - creates an IPv6 SFLQ pool in the lease back end.
+-  :isccmd:`sflq-pool6-rebuild` - rebuilds an IPv6 SFLQ pool in the lease back end.
 
--  :iscmd:`sflq-pool4-get-all` - fetches all IPv4 SFLQ pools from the lease back end.
+-  :isccmd:`sflq-pool4-get-all` - fetches all IPv4 SFLQ pools from the lease back end.
 
--  :iscmd:`sflq-pool6-get-all` - fetches all IPv6 SFLQ pools from the lease back end.
+-  :isccmd:`sflq-pool6-get-all` - fetches all IPv6 SFLQ pools from the lease back end.
 
--  :iscmd:`sflq-pool4-get-by-subnet` - fetches all IPv4 SFLQ pools that belong to
+-  :isccmd:`sflq-pool4-get-by-subnet` - fetches all IPv4 SFLQ pools that belong to
    a subnet from the lease back end.
 
--  :iscmd:`sflq-pool6-get-by-subnet` - fetches all IPv6 SFLQ pools that belong to
+-  :isccmd:`sflq-pool6-get-by-subnet` - fetches all IPv6 SFLQ pools that belong to
    a subnet from the lease back end.
 
--  :iscmd:`sflq-pool4-get-by-range` - fetches all IPv4 SFLQ pools that overlap an
+-  :isccmd:`sflq-pool4-get-by-range` - fetches all IPv4 SFLQ pools that overlap an
    address range from the lease back end.
 
--  :iscmd:`sflq-pool6-get-by-range` - fetches all IPv6 SFLQ pools that overlap an
+-  :isccmd:`sflq-pool6-get-by-range` - fetches all IPv6 SFLQ pools that overlap an
    address range from the lease back end.
 
--  :iscmd:`sflq-pool4-del` - deletes an IPv4 SFLQ pool that matches an address
+-  :isccmd:`sflq-pool4-del` - deletes an IPv4 SFLQ pool that matches an address
    range from the lease back end.
 
--  :iscmd:`sflq-pool6-del` - deletes an IPv6 SFLQ pool that matches an address
+-  :isccmd:`sflq-pool6-del` - deletes an IPv6 SFLQ pool that matches an address
    range from the lease back end.
 
 All commands use JSON syntax and can be issued either using the control
@@ -1195,7 +1195,7 @@ Allocation to work properly, all servers allocating from a given pool (i.e.
 address or prefix range), must use SFLQ. If some servers do while others
 do not, the SFLQ data can quickly become inaccurate. This can be remedied
 by stopping any servers that are not using SFLQ for the pool(s) in question
-and recreating the pool(s) using the sflq-pool*-create commands, changing
+and rebuilding the pool(s) using the sflq-pool*-rebuild commands, changing
 those servers to use SFLQ for the pool(s) and then restarting them.
 
 The third use case is that of overlapping pools, (i.e. pools whose
@@ -1211,23 +1211,24 @@ range.
     from their address ranges could lead to inconsistent results and is generally
     not recommended.  Commands that fetch SFLQ pools may be safely used at anytime.
 
-.. isccmd:: sflq-pool4-create
-.. _command-sflq-pool4-create:
+.. isccmd:: sflq-pool4-rebuild
+.. _command-sflq-pool4-rebuild:
 
-.. isccmd:: sflq-pool6-create
-.. _command-sflq-pool6-create:
+.. isccmd:: sflq-pool6-rebuild
+.. _command-sflq-pool6-rebuild:
 
-The ``sflq-pool4-create``, ``sflq-pool6-create`` Commands
----------------------------------------------------------
+The ``sflq-pool4-rebuild``, ``sflq-pool6-rebuild`` Commands
+-----------------------------------------------------------
 
-:isccmd:`sflq-pool4-create` and :isccmd:`sflq-pool6-create` can be used to
-(re)create SFLQ pools and their free lease data.  This is useful in cases
+:isccmd:`sflq-pool4-rebuild` and :isccmd:`sflq-pool6-rebuild` can be used to
+rebuild the free lease data for existing SFLQ pools.  This is useful in cases
 where one or more servers have been using other allocator schemes for
-the address ranges that include SFLQ pools. If the pool already exists,
-the call will simply return. The option ``recreate`` parameter, which
-defaults to false, can be used to force the pool to recreated.
+the address ranges that include SFLQ pools. Issuing the command will cause
+the lease back end to discard and then rebuild the free lease data for the
+given pool. Only a pool that exactly matches the start and end adddress
+given will rebuilt.
 
-An example :isccmd:`sflq-pool4-create` command for recreating an IPv4 SFLQ
+An example :isccmd:`sflq-pool4-rebuild` command for rebuiding an IPv4 SFLQ
 Pool is shown below:
 
 ::
@@ -1236,17 +1237,12 @@ Pool is shown below:
         "command": "sflq-pool4-create",
         "arguments": {
             "start-address": "192.0.2.0",
-            "end-address": "192.0.2.255",
-            "subnet-id" : 100,
-            "recreate": true
+            "end-address": "192.0.2.255"
         }
     }
 
-Of the parameters shown above, only ``recreate`` is optional.
-
-For IPv6 pools the parameter ``lease-type`` with a value of either "IA_NA"
-or "IA_PD" is required.  An example :isccmd:`sflq-pool6-create` command for
-recreating an IPv6 SFLQ pool for an address pool is shown below:
+An example :isccmd:`sflq-pool6-rebuild` command for rebuilding an IPv6
+SFLQ pool for an address pool is shown below:
 
 ::
 
@@ -1254,29 +1250,7 @@ recreating an IPv6 SFLQ pool for an address pool is shown below:
         "command": "sflq-pool6-create",
         "arguments": {
             "start-address": "2001:db8:1::",
-            "end-address": "2001:db8:1::FFFF",
-            "subnet-id" : 100,
-            "lease-type": "IA_NA",
-            "recreate": true
-        }
-    }
-
-For IPv6 prefix delegation pools, the delegated prefix length must be
-specified as ``delegated-len`` which must be greater than 0 and less
-or equal to 128.  An example :isccmd:`sflq-pool6-create` command for
-recreating an IPv6 SFLQ pool for a prefix delegation pool is shown below:
-
-::
-
-    {
-        "command": "sflq-pool6-create",
-        "arguments": {
-            "start-address": "3001:20::",
-            "end-address": "3001:20:0:ff:ffff:ffff:ffff:ffff",
-            "subnet-id" : 100,
-            "lease-type": "IA_PD",
-            "delegated-len": 64,
-            "recreate": true
+            "end-address": "2001:db8:1::FFFF"
         }
     }
 
@@ -1294,13 +1268,7 @@ parameter that explains the cause of failure. For example:
 
 ::
 
-   { "result": 0, "text": "SFLQ pool created." }
-
-Example failure:
-
-::
-
-   { "result": 1, "text": "missing 'lease-type' parameter" }
+   { "result": 0, "text": "SFLQ pool rebuilt." }
 
 .. isccmd:: sflq-pool4-get-all
 .. _command-sflq-pool4-get-all:
index 0ac03d1f7e13984550bc5eaf1da1fc16fc4f3cab..85c0d94aa6225e5c586fe4335f18a377aac5865e 100644 (file)
@@ -335,15 +335,15 @@ int lease6_write(CalloutHandle& handle) {
     return(lease_cmds.leaseWriteHandler(handle));
 }
 
-/// @brief This is a command callout for 'sflq-pool4-create' command.
+/// @brief This is a command callout for 'sflq-pool4-rebuild' command.
 ///
 /// @param handle Callout handle used to retrieve a command and
 /// provide a response.
 /// @return 0 if this callout has been invoked successfully,
 /// 1 otherwise.
-int sflq_pool4_create(CalloutHandle& handle) {
+int sflq_pool4_rebuild(CalloutHandle& handle) {
     SflqCmds sflq_cmds;
-    return(sflq_cmds.sflqPool4CreateHandler(handle));
+    return(sflq_cmds.sflqPool4RebuildHandler(handle));
 }
 
 /// @brief This is a command callout for 'sflq-pool4-get-all' command.
@@ -390,15 +390,15 @@ int sflq_pool4_del(CalloutHandle& handle) {
     return(sflq_cmds.sflqPool4DelHandler(handle));
 }
 
-/// @brief This is a command callout for 'sflq-pool6-create' command.
+/// @brief This is a command callout for 'sflq-pool6-rebuild' command.
 ///
 /// @param handle Callout handle used to retrieve a command and
 /// provide a response.
 /// @return 0 if this callout has been invoked successfully,
 /// 1 otherwise.
-int sflq_pool6_create(CalloutHandle& handle) {
+int sflq_pool6_rebuild(CalloutHandle& handle) {
     SflqCmds sflq_cmds;
-    return(sflq_cmds.sflqPool6CreateHandler(handle));
+    return(sflq_cmds.sflqPool6RebuildHandler(handle));
 }
 
 /// @brief This is a command callout for 'sflq-pool6-get-all' command.
@@ -497,12 +497,12 @@ int load(LibraryHandle& handle) {
     handle.registerCommandCallout("lease6-resend-ddns", lease6_resend_ddns);
     handle.registerCommandCallout("lease4-write", lease4_write);
     handle.registerCommandCallout("lease6-write", lease6_write);
-    handle.registerCommandCallout("sflq-pool4-create", sflq_pool4_create);
+    handle.registerCommandCallout("sflq-pool4-rebuild", sflq_pool4_rebuild);
     handle.registerCommandCallout("sflq-pool4-get-all", sflq_pool4_get_all);
     handle.registerCommandCallout("sflq-pool4-get-by-subnet", sflq_pool4_get_by_subnet);
     handle.registerCommandCallout("sflq-pool4-get-by-range", sflq_pool4_get_by_range);
     handle.registerCommandCallout("sflq-pool4-del", sflq_pool4_del);
-    handle.registerCommandCallout("sflq-pool6-create", sflq_pool6_create);
+    handle.registerCommandCallout("sflq-pool6-rebuild", sflq_pool6_rebuild);
     handle.registerCommandCallout("sflq-pool6-get-all", sflq_pool6_get_all);
     handle.registerCommandCallout("sflq-pool6-get-by-subnet", sflq_pool6_get_by_subnet);
     handle.registerCommandCallout("sflq-pool6-get-by-range", sflq_pool6_get_by_range);
index db97467eebb43509197968ea9873a7763d2a1256..a33fe21e87921979438c2a6e313795715db70cde 100644 (file)
@@ -41,8 +41,6 @@ extern const isc::log::MessageID LEASE_CMDS_WIPE4 = "LEASE_CMDS_WIPE4";
 extern const isc::log::MessageID LEASE_CMDS_WIPE4_FAILED = "LEASE_CMDS_WIPE4_FAILED";
 extern const isc::log::MessageID LEASE_CMDS_WIPE6 = "LEASE_CMDS_WIPE6";
 extern const isc::log::MessageID LEASE_CMDS_WIPE6_FAILED = "LEASE_CMDS_WIPE6_FAILED";
-extern const isc::log::MessageID SFLQ_POOL4_CREATE = "SFLQ_POOL4_CREATE";
-extern const isc::log::MessageID SFLQ_POOL4_CREATE_FAILED = "SFLQ_POOL4_CREATE_FAILED";
 extern const isc::log::MessageID SFLQ_POOL4_DEL = "SFLQ_POOL4_DEL";
 extern const isc::log::MessageID SFLQ_POOL4_DEL_FAILED = "SFLQ_POOL4_DEL_FAILED";
 extern const isc::log::MessageID SFLQ_POOL4_GET_ALL = "SFLQ_POOL4_GET_ALL";
@@ -51,8 +49,8 @@ extern const isc::log::MessageID SFLQ_POOL4_GET_BY_RANGE = "SFLQ_POOL4_GET_BY_RA
 extern const isc::log::MessageID SFLQ_POOL4_GET_BY_RANGE_FAILED = "SFLQ_POOL4_GET_BY_RANGE_FAILED";
 extern const isc::log::MessageID SFLQ_POOL4_GET_BY_SUBNET = "SFLQ_POOL4_GET_BY_SUBNET";
 extern const isc::log::MessageID SFLQ_POOL4_GET_BY_SUBNET_FAILED = "SFLQ_POOL4_GET_BY_SUBNET_FAILED";
-extern const isc::log::MessageID SFLQ_POOL6_CREATE = "SFLQ_POOL6_CREATE";
-extern const isc::log::MessageID SFLQ_POOL6_CREATE_FAILED = "SFLQ_POOL6_CREATE_FAILED";
+extern const isc::log::MessageID SFLQ_POOL4_REBUILD = "SFLQ_POOL4_REBUILD";
+extern const isc::log::MessageID SFLQ_POOL4_REBUILD_FAILED = "SFLQ_POOL4_REBUILD_FAILED";
 extern const isc::log::MessageID SFLQ_POOL6_DEL = "SFLQ_POOL6_DEL";
 extern const isc::log::MessageID SFLQ_POOL6_DEL_FAILED = "SFLQ_POOL6_DEL_FAILED";
 extern const isc::log::MessageID SFLQ_POOL6_GET_ALL = "SFLQ_POOL6_GET_ALL";
@@ -61,6 +59,8 @@ extern const isc::log::MessageID SFLQ_POOL6_GET_BY_RANGE = "SFLQ_POOL6_GET_BY_RA
 extern const isc::log::MessageID SFLQ_POOL6_GET_BY_RANGE_FAILED = "SFLQ_POOL6_GET_BY_RANGE_FAILED";
 extern const isc::log::MessageID SFLQ_POOL6_GET_BY_SUBNET = "SFLQ_POOL6_GET_BY_SUBNET";
 extern const isc::log::MessageID SFLQ_POOL6_GET_BY_SUBNET_FAILED = "SFLQ_POOL6_GET_BY_SUBNET_FAILED";
+extern const isc::log::MessageID SFLQ_POOL6_REBUILD = "SFLQ_POOL6_REBUILD";
+extern const isc::log::MessageID SFLQ_POOL6_REBUILD_FAILED = "SFLQ_POOL6_REBUILD_FAILED";
 
 namespace {
 
@@ -102,8 +102,6 @@ const char* values[] = {
     "LEASE_CMDS_WIPE4_FAILED", "lease4-wipe command failed (parameters: %1, reason: %2)",
     "LEASE_CMDS_WIPE6", "lease6-wipe command successful (parameters: %1)",
     "LEASE_CMDS_WIPE6_FAILED", "lease6-wipe command failed (parameters: %1, reason: %2)",
-    "SFLQ_POOL4_CREATE", "sflq-pool4-create command succeeded, (parameters: %1)",
-    "SFLQ_POOL4_CREATE_FAILED", "sflq-pool4-create command failed, (parameters: %1, reason: %2)",
     "SFLQ_POOL4_DEL", "sflq-pool4-del command succeeded, (parameters: %1) pools deleted: %2",
     "SFLQ_POOL4_DEL_FAILED", "sflq-pool4-del command failed, (parameters: %1, reason: %2)",
     "SFLQ_POOL4_GET_ALL", "sflq-pool4-get-all command succeeded, pools found: %1",
@@ -112,8 +110,8 @@ const char* values[] = {
     "SFLQ_POOL4_GET_BY_RANGE_FAILED", "sflq-pool4-get-by-range command failed, (parameters: %1, reason: %2)",
     "SFLQ_POOL4_GET_BY_SUBNET", "sflq-pool4-get-by-subnet command succeeded, (parameters: %1) pools found: %2",
     "SFLQ_POOL4_GET_BY_SUBNET_FAILED", "sflq-pool4-get-by-subnet command failed, (parameters: %1, reason: %2)",
-    "SFLQ_POOL6_CREATE", "sflq-pool6-create command succeeded, (parameters: %1)",
-    "SFLQ_POOL6_CREATE_FAILED", "sflq-pool6-create command failed, (parameters: %1, reason: %2)",
+    "SFLQ_POOL4_REBUILD", "sflq-pool4-rebuild command succeeded, (parameters: %1) pools rebuilt: %2",
+    "SFLQ_POOL4_REBUILD_FAILED", "sflq-pool4-rebuild command failed, (parameters: %1, reason: %2)",
     "SFLQ_POOL6_DEL", "sflq-pool4-del command succeeded, (parameters: %1) pools deleted: %2",
     "SFLQ_POOL6_DEL_FAILED", "sflq-pool4-del command failed, (parameters: %1, reason: %2)",
     "SFLQ_POOL6_GET_ALL", "sflq-pool6-get-all command succeeded, pools found: %1",
@@ -122,6 +120,8 @@ const char* values[] = {
     "SFLQ_POOL6_GET_BY_RANGE_FAILED", "sflq-pool6-get-by-range command failed, (parameters: %1, reason: %2)",
     "SFLQ_POOL6_GET_BY_SUBNET", "sflq-pool6-get-by-subnet command succeeded, (parameters: %1) pools found: %2",
     "SFLQ_POOL6_GET_BY_SUBNET_FAILED", "sflq-pool6-get-by-subnet command failed, (parameters: %1, reason: %2)",
+    "SFLQ_POOL6_REBUILD", "sflq-pool6-rebuild command succeeded, (parameters: %1) pools rebuilt: %2",
+    "SFLQ_POOL6_REBUILD_FAILED", "sflq-pool6-rebuild command failed, (parameters: %1, reason: %2)",
     NULL
 };
 
index dda429bfe05de785652032e9e7156d44b513cdfb..1565d6e611e28156ecdede1780900d9f28204e34 100644 (file)
@@ -42,8 +42,6 @@ extern const isc::log::MessageID LEASE_CMDS_WIPE4;
 extern const isc::log::MessageID LEASE_CMDS_WIPE4_FAILED;
 extern const isc::log::MessageID LEASE_CMDS_WIPE6;
 extern const isc::log::MessageID LEASE_CMDS_WIPE6_FAILED;
-extern const isc::log::MessageID SFLQ_POOL4_CREATE;
-extern const isc::log::MessageID SFLQ_POOL4_CREATE_FAILED;
 extern const isc::log::MessageID SFLQ_POOL4_DEL;
 extern const isc::log::MessageID SFLQ_POOL4_DEL_FAILED;
 extern const isc::log::MessageID SFLQ_POOL4_GET_ALL;
@@ -52,8 +50,8 @@ extern const isc::log::MessageID SFLQ_POOL4_GET_BY_RANGE;
 extern const isc::log::MessageID SFLQ_POOL4_GET_BY_RANGE_FAILED;
 extern const isc::log::MessageID SFLQ_POOL4_GET_BY_SUBNET;
 extern const isc::log::MessageID SFLQ_POOL4_GET_BY_SUBNET_FAILED;
-extern const isc::log::MessageID SFLQ_POOL6_CREATE;
-extern const isc::log::MessageID SFLQ_POOL6_CREATE_FAILED;
+extern const isc::log::MessageID SFLQ_POOL4_REBUILD;
+extern const isc::log::MessageID SFLQ_POOL4_REBUILD_FAILED;
 extern const isc::log::MessageID SFLQ_POOL6_DEL;
 extern const isc::log::MessageID SFLQ_POOL6_DEL_FAILED;
 extern const isc::log::MessageID SFLQ_POOL6_GET_ALL;
@@ -62,5 +60,7 @@ extern const isc::log::MessageID SFLQ_POOL6_GET_BY_RANGE;
 extern const isc::log::MessageID SFLQ_POOL6_GET_BY_RANGE_FAILED;
 extern const isc::log::MessageID SFLQ_POOL6_GET_BY_SUBNET;
 extern const isc::log::MessageID SFLQ_POOL6_GET_BY_SUBNET_FAILED;
+extern const isc::log::MessageID SFLQ_POOL6_REBUILD;
+extern const isc::log::MessageID SFLQ_POOL6_REBUILD_FAILED;
 
 #endif // LEASE_CMDS_MESSAGES_H
index 4c7b5df88964a6b09af687ef9bedcc4ea0f651a9..b4ad9613e5dc758caea87f0e7d645174f4fbad79 100644 (file)
@@ -174,12 +174,12 @@ are logged.
 The lease6-wipe command has failed. Both the reason as well as the
 parameters passed are logged.
 
-% SFLQ_POOL4_CREATE sflq-pool4-create command succeeded, (parameters: %1)
+% SFLQ_POOL4_REBUILD sflq-pool4-rebuild command succeeded, (parameters: %1) pools rebuilt: %2
 Logged at debug log level 20.
-The sflq-pool4-create command was successful.
+The sflq-pool4-rebuild command was successful.
 
-% SFLQ_POOL4_CREATE_FAILED sflq-pool4-create command failed, (parameters: %1, reason: %2)
-The sflq-pool4-create command has failed. Both the reason as well as the
+% SFLQ_POOL4_REBUILD_FAILED sflq-pool4-rebuild command failed, (parameters: %1, reason: %2)
+The sflq-pool4-rebuild command has failed. Both the reason as well as the
 parameters passed are logged.
 
 % SFLQ_POOL4_GET_ALL sflq-pool4-get-all command succeeded, pools found: %1
@@ -214,17 +214,17 @@ The sflq-pool4-del command was successful.
 The sflq-pool4-del command has failed. Both the reason as well as the
 parameters passed are logged.
 
-% SFLQ_POOL6_CREATE sflq-pool6-create command succeeded, (parameters: %1)
+% SFLQ_POOL6_REBUILD sflq-pool6-rebuild command succeeded, (parameters: %1) pools rebuilt: %2
 Logged at debug log level 20.
-The sflq-pool6-create command was successful.
+The sflq-pool6-rebuild command was successful.
 
-% SFLQ_POOL6_CREATE_FAILED sflq-pool6-create command failed, (parameters: %1, reason: %2)
-The sflq-pool6-create command has failed. Both the reason as well as the
+% SFLQ_POOL6_REBUILD_FAILED sflq-pool6-rebuild command failed, (parameters: %1, reason: %2)
+The sflq-pool6-rebuild command has failed. Both the reason as well as the
 parameters passed are logged.
 
 % SFLQ_POOL6_GET_ALL sflq-pool6-get-all command succeeded, pools found: %1
 Logged at debug log level 20.
-The sflq-pool6-create command was successful.
+The sflq-pool6-rebuild command was successful.
 
 % SFLQ_POOL6_GET_ALL_FAILED sflq-pool6-get-all command failed, (parameters: %1, reason: %2)
 The sflq-pool6-get-all command has failed. Both the reason as well as the
index e74dc48f1aa8010a875fc3ab4208f94e3fbfcb63..7cc27890d7df36a44356ad55bcfffd5dcfc7e975 100644 (file)
@@ -54,7 +54,7 @@ TEST_F(LeaseCmdsTest, commands) {
         "lease4-update",            "lease6-update",
         "lease4-wipe",              "lease6-wipe",
         "lease4-resend-ddns",       "lease6-resend-ddns",
-        "sflq-pool4-create",        "sflq-pool6-create",
+        "sflq-pool4-rebuild",       "sflq-pool6-rebuild",
         "sflq-pool4-get-all",       "sflq-pool6-get-all",
         "sflq-pool4-get-by-subnet", "sflq-pool6-get-by-subnet",
         "sflq-pool4-get-by-range",  "sflq-pool6-get-by-range",
index 5b42d3ec968264ba50486897deb7eb03d591e62f..a1e3c94133c5c2034eef438282b6c9ccd7bcb0b3 100644 (file)
@@ -70,9 +70,6 @@ struct BadParamScenario {
 /// Provides convenience methods for loading, testing the SLFQ commands.
 class SflqCmdsTest : public LibLoadTest {
 public:
-    /// @brief Pointer to the lease manager
-    isc::dhcp::LeaseMgr* lmptr_;
-
     /// @brief Constructor
     ///
     /// Sets the library filename and clears the lease manager pointer.
@@ -97,7 +94,6 @@ public:
 
         ASSERT_TRUE(LeaseMgrFactory::haveInstance());
         ASSERT_EQ(LeaseMgrFactory::instance().getType(), "sflqtest");
-        // initSubnet4();
         SharedFlqAllocator::setInUse(false);
     }
 
@@ -109,7 +105,6 @@ public:
         // a clang/boost bug
         isc::dhcp::LeaseMgrFactory::destroy();
         unloadLibs();
-        lmptr_ = 0;
         isc::util::file::PathChecker::enableEnforcement(true);
     }
 
@@ -256,8 +251,8 @@ public:
     /// @brief Destructor
     virtual ~SflqCmds4Test() {}
 
-    /// @brief Exercises invalid parameter checks for sflq-pool4-create.
-    void sflqPool4CreateBadParams();
+    /// @brief Exercises invalid parameter checks for sflq-pool4-rebuild.
+    void sflqPool4RebuildBadParams();
 
     /// @brief Exercises invalid parameter checks for sflq-pool4-get-all.
     void sflqPool4GetAllBadParams();
@@ -280,7 +275,7 @@ public:
     void testSflqCommands();
 };
 
-void SflqCmds4Test::sflqPool4CreateBadParams() {
+void SflqCmds4Test::sflqPool4RebuildBadParams() {
     std::list<BadParamScenario> scenarios = {
     {
         __LINE__,
@@ -294,20 +289,11 @@ void SflqCmds4Test::sflqPool4CreateBadParams() {
         )",
         "missing 'end-address' parameter"
     },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "178.0.0.10",
-            "end-address" : "178.0.0.20"
-        )",
-        "missing 'subnet-id' parameter"
-    },
     {
         __LINE__,
         R"(
             "start-address" : "3001::",
-            "end-address" : "178.0.0.20",
-            "subnet-id" : 1
+            "end-address" : "178.0.0.20"
         )",
         "invalid V4 range - start_address 3001::, end_address 178.0.0.20,"
         " must be V4 addresses where start_address <= end_address"
@@ -316,8 +302,7 @@ void SflqCmds4Test::sflqPool4CreateBadParams() {
         __LINE__,
         R"(
             "start-address" : "178.0.0.20",
-            "end-address" : "178.0.0.10",
-            "subnet-id" : 1
+            "end-address" : "178.0.0.10"
         )",
         "invalid V4 range - start_address 178.0.0.20, end_address 178.0.0.10,"
         " must be V4 addresses where start_address <= end_address"
@@ -327,36 +312,6 @@ void SflqCmds4Test::sflqPool4CreateBadParams() {
         R"(
             "start-address" : "178.0.0.10",
             "end-address" : "178.0.0.20",
-            "subnet-id" : "bogus"
-        )",
-        "'subnet-id' parameter is not an integer"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "178.0.0.10",
-            "end-address" : "178.0.0.20",
-            "subnet-id" : 0
-        )",
-        "'subnet-id' must be greater than zero"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "178.0.0.10",
-            "end-address" : "178.0.0.20",
-            "subnet-id" : 0,
-            "recreate" : 1
-        )",
-        "'recreate' parameter is not a boolean"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "178.0.0.10",
-            "end-address" : "178.0.0.20",
-            "subnet-id" : 0,
-            "recreate" : true,
             "bogus" : "fluff"
         )",
         "spurious 'bogus' parameter"
@@ -367,7 +322,7 @@ void SflqCmds4Test::sflqPool4CreateBadParams() {
         oss << "Scenario at line: " << scenario.line_;
         SCOPED_TRACE(oss.str());
         std::ostringstream command;
-        command << R"({ "command": "sflq-pool4-create", "arguments": {)"
+        command << R"({ "command": "sflq-pool4-rebuild", "arguments": {)"
                 << scenario.args_ << "}}";
 
         testCommand(command.str(), CONTROL_RESULT_ERROR, scenario.exp_rsp_);
@@ -600,29 +555,29 @@ SflqCmds4Test::testSflqCommands() {
 
     // Now create the pools.
     for ( auto const& test_pool : test_pools) {
-        auto args = test_pool->toElement();
-        // Take out what we don't need.
-        args->remove("lease-type");
-        args->remove("delegated-len");
-        args->remove("created-ts");
-        args->remove("modified-ts");
-        args->remove("free-leases");
-        // Add recreate flag.
-        args->set("recreate", Element::create(false));
-
-        // Initial create should work.
-        command = buildCommand("sflq-pool4-create", args);
-        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool created.");
-
-        // Trying again without recreate should say it already exists.
-        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool already exists.");
-
-        // Recreating it should work.
-        args->set("recreate", Element::create(true));
-        command = buildCommand("sflq-pool4-create", args);
-        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool created.");
+        // Create the pool directly through lease manager.
+        bool created = false;
+        ASSERT_NO_THROW_LOG(created = LeaseMgrFactory::instance().sflqCreateFlqPool4(
+            test_pool->start_address_, test_pool->end_address_,
+            test_pool->subnet_id_, false));
+        ASSERT_TRUE(created);
+
+        // Rebuild should work.
+        auto args = Element::createMap();
+        args->set("start-address", Element::create(test_pool->start_address_.toText()));
+        args->set("end-address", Element::create(test_pool->end_address_.toText()));
+        command = buildCommand("sflq-pool4-rebuild", args);
+        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool rebuilt.");
     }
 
+
+    // Rebuild should fail without an exact match.
+    auto args = Element::createMap();
+    args->set("start-address", Element::create(test_pools[0]->start_address_.toText()));
+    args->set("end-address", Element::create(test_pools[2]->end_address_.toText()));
+    command = buildCommand("sflq-pool4-rebuild", args);
+    testCommand(command, CONTROL_RESULT_EMPTY, "SFLQ pool does not exist.");
+
     // Fetching all pools should find all three.
     command = buildCommand("sflq-pool4-get-all");
     auto cmd_rsp = testCommand(command, CONTROL_RESULT_SUCCESS, "3 pool(s) found.");
@@ -635,7 +590,7 @@ SflqCmds4Test::testSflqCommands() {
 
     // Fetch by subnet id for subnet_id = 1.
     pool_infos.reset();
-    auto args = Element::fromJSON("{\"subnet-id\": 1}");
+    args = Element::fromJSON("{\"subnet-id\": 1}");
     command = buildCommand("sflq-pool4-get-by-subnet", args);
     cmd_rsp = testCommand(command, CONTROL_RESULT_SUCCESS, "2 pool(s) found.");
     pool_infos = extractPools(cmd_rsp);
@@ -716,8 +671,8 @@ SflqCmds4Test::testSflqCommands() {
     }
 }
 
-TEST_F(SflqCmds4Test, sflqPool4CreateBadParams) {
-    sflqPool4CreateBadParams();
+TEST_F(SflqCmds4Test, sflqPool4RebuildBadParams) {
+    sflqPool4RebuildBadParams();
 }
 
 TEST_F(SflqCmds4Test, sflqPool4GetAllBadParams) {
@@ -761,8 +716,8 @@ public:
     /// @brief Destructor
     virtual ~SflqCmds6Test() {}
 
-    /// @brief Exercises invalid parameter checks for sflq-pool6-create.
-    void sflqPool6CreateBadParams();
+    /// @brief Exercises invalid parameter checks for sflq-pool6-rebuild.
+    void sflqPool6RebuildBadParams();
 
     /// @brief Exercises invalid parameter checks for sflq-pool6-get-all.
     void sflqPool6GetAllBadParams();
@@ -788,7 +743,7 @@ public:
     void testSflqCommands(Lease::Type lease_type);
 };
 
-void SflqCmds6Test::sflqPool6CreateBadParams() {
+void SflqCmds6Test::sflqPool6RebuildBadParams() {
     std::list<BadParamScenario> scenarios = {
     {
         __LINE__,
@@ -806,26 +761,7 @@ void SflqCmds6Test::sflqPool6CreateBadParams() {
         __LINE__,
         R"(
             "start-address" : "3001::10",
-            "end-address" : "3001::20"
-        )",
-        "missing 'subnet-id' parameter"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 1
-        )",
-        "missing 'lease-type' parameter"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "178.0.0.20",
-            "subnet-id" : 1,
-            "lease-type": "IA_NA"
+            "end-address" : "178.0.0.20"
         )",
         "invalid V6 range - start_address 3001::10, end_address 178.0.0.20,"
         " must be V6 addresses where start_address <= end_address"
@@ -834,9 +770,7 @@ void SflqCmds6Test::sflqPool6CreateBadParams() {
         __LINE__,
         R"(
             "start-address" : "3001::20",
-            "end-address" : "3001::10",
-            "subnet-id" : 1,
-            "lease-type": "IA_NA"
+            "end-address" : "3001::10"
         )",
         "invalid V6 range - start_address 3001::20, end_address 3001::10,"
         " must be V6 addresses where start_address <= end_address"
@@ -846,107 +780,9 @@ void SflqCmds6Test::sflqPool6CreateBadParams() {
         R"(
             "start-address" : "3001::10",
             "end-address" : "3001::20",
-            "subnet-id" : "bogus",
-            "lease-type": "IA_NA"
-        )",
-        "'subnet-id' parameter is not an integer"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 0,
-            "lease-type": "IA_NA"
-        )",
-        "'subnet-id' must be greater than zero"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 1,
-            "lease-type": "bogus"
-        )",
-        "invalid V6 'lease-type': bogus, valid values are IA_NA and IA_PD"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 1,
-            "lease-type": "IA_PD",
-            "delegated-len": "bogus"
-        )",
-        "'delegated-len' parameter is not an integer"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 1,
-            "lease-type": "IA_PD",
-            "delegated-len": 0
-        )",
-        "'delegated-len' invalid: 0, it must be >= 1 and =< 128"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 1,
-            "lease-type": "IA_PD",
-            "delegated-len": 129
-        )",
-        "'delegated-len' invalid: 129, it must be >= 1 and =< 128"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 0,
-            "lease-type": "IA_NA",
-            "recreate" : 1
-        )",
-        "'recreate' parameter is not a boolean"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 0,
-            "lease-type": "IA_NA",
-            "recreate" : true,
             "bogus" : "fluff"
         )",
         "spurious 'bogus' parameter"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 100,
-            "lease-type": "IA_NA",
-            "delegated-len": 56
-        )",
-        "'delegated-len' must only be 128 for IA_NA pools"
-    },
-    {
-        __LINE__,
-        R"(
-            "start-address" : "3001::10",
-            "end-address" : "3001::20",
-            "subnet-id" : 100,
-            "lease-type": "IA_PD"
-        )",
-        "'delegated-len' is required for IA_PD pools"
     }
     };
 
@@ -955,7 +791,7 @@ void SflqCmds6Test::sflqPool6CreateBadParams() {
         oss << "Scenario at line: " << scenario.line_;
         SCOPED_TRACE(oss.str());
         std::ostringstream command;
-        command << R"({ "command": "sflq-pool6-create", "arguments": {)"
+        command << R"({ "command": "sflq-pool6-rebuild", "arguments": {)"
                 << scenario.args_ << "}}";
 
         testCommand(command.str(), CONTROL_RESULT_ERROR, scenario.exp_rsp_);
@@ -1196,28 +1032,29 @@ SflqCmds6Test::testSflqCommands(Lease::Type lease_type) {
 
     // Now create the pools.
     for ( auto const& test_pool : test_pools) {
-        auto args = test_pool->toElement();
-        // Take out what we don't need.
-        args->remove("created-ts");
-        args->remove("modified-ts");
-        args->remove("free-leases");
-        // Add recreate flag.
-        args->set("recreate", Element::create(false));
-
-        // Initial create should work.
-        command = buildCommand("sflq-pool6-create", args);
-        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool created.");
-
-        // Trying again without recreate should say it already exists.
-        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool already exists.");
-
-        // Recreating it should work.
-        args->set("recreate", Element::create(true));
-        command = buildCommand("sflq-pool6-create", args);
-        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool created.");
-
+        // Create the pool directly through lease manager.
+        bool created = false;
+        ASSERT_NO_THROW_LOG(created = LeaseMgrFactory::instance().sflqCreateFlqPool6(
+            test_pool->start_address_, test_pool->end_address_,
+            test_pool->lease_type_, test_pool->delegated_len_,
+            test_pool->subnet_id_, false));
+        ASSERT_TRUE(created);
+
+        // Rebuild should work.
+        auto args = Element::createMap();
+        args->set("start-address", Element::create(test_pool->start_address_.toText()));
+        args->set("end-address", Element::create(test_pool->end_address_.toText()));
+        command = buildCommand("sflq-pool6-rebuild", args);
+        testCommand(command, CONTROL_RESULT_SUCCESS, "SFLQ pool rebuilt.");
     }
 
+    // Rebuild should fail without an exact match.
+    auto args = Element::createMap();
+    args->set("start-address", Element::create(test_pools[0]->start_address_.toText()));
+    args->set("end-address", Element::create(test_pools[2]->end_address_.toText()));
+    command = buildCommand("sflq-pool6-rebuild", args);
+    testCommand(command, CONTROL_RESULT_EMPTY, "SFLQ pool does not exist.");
+
     // Fetching all pools should find all three.
     command = buildCommand("sflq-pool6-get-all");
     cmd_rsp = testCommand(command, CONTROL_RESULT_SUCCESS, "3 pool(s) found.");
@@ -1230,7 +1067,7 @@ SflqCmds6Test::testSflqCommands(Lease::Type lease_type) {
 
    // Fetch by subnet id for subnet_id = 1.
     pool_infos.reset();
-    auto args = Element::fromJSON("{\"subnet-id\": 1}");
+    args = Element::fromJSON("{\"subnet-id\": 1}");
     command = buildCommand("sflq-pool6-get-by-subnet", args);
     cmd_rsp = testCommand(command, CONTROL_RESULT_SUCCESS, "2 pool(s) found.");
     pool_infos = extractPools(cmd_rsp);
@@ -1309,8 +1146,8 @@ SflqCmds6Test::testSflqCommands(Lease::Type lease_type) {
     }
 }
 
-TEST_F(SflqCmds6Test, sflqPool6CreateBadParams) {
-    sflqPool6CreateBadParams();
+TEST_F(SflqCmds6Test, sflqPool6RebuildBadParams) {
+    sflqPool6RebuildBadParams();
 }
 
 TEST_F(SflqCmds6Test, sflqPool6GetAllBadParams) {
index a19d5f0238f5a5b71fec04c8e93a1c04304f3161..6265db063d9371961105568b01af26d69bdc4275 100644 (file)
@@ -36,20 +36,17 @@ namespace isc {
 namespace lease_cmds {
 
 int
-SflqCmdsImpl::sflqPool4CreateHandler(CalloutHandle& handle) {
+SflqCmdsImpl::sflqPool4RebuildHandler(CalloutHandle& handle) {
     static const data::SimpleKeywords keywords =
     {
         { "start-address",  Element::string  },
         { "end-address",    Element::string  },
-        { "subnet-id",      Element::integer },
-        { "recreate",       Element::boolean }
     };
 
     static const data::SimpleRequiredKeywords required_keywords =
     {
         "start-address",
         "end-address",
-        "subnet-id",
     };
 
     stringstream resp;
@@ -67,32 +64,46 @@ SflqCmdsImpl::sflqPool4CreateHandler(CalloutHandle& handle) {
         IOAddress end_address(IOAddress::IPV4_ZERO_ADDRESS());
         extractRange(cmd_args_, AF_INET, start_address, end_address);
 
-        /// @todo Should we verify the subnet-id and/or check allocator for subnet?
-        SubnetID subnet_id = SimpleParser::getInteger(cmd_args_, "subnet-id");
-        if (subnet_id <= 0) {
-            isc_throw(isc::BadValue, "'subnet-id' must be greater than zero");
+        // Fetch pools by range.
+        auto pools = LeaseMgrFactory::instance().sflqPool4Get(start_address, end_address);
+
+        // Since get can return more than one, look for an exact match.
+        bool rebuilt = false;
+        for (auto const& pool : *pools ) {
+            if (pool->start_address_ == start_address && pool->end_address_ == end_address) {
+                // Found a match, rebuild it.
+                // Invoke the pool create function inside a CriticalSection. Rebuilding
+                // large pools can take a long time.
+                MultiThreadingCriticalSection cs;
+                LeaseMgrFactory::instance().sflqCreateFlqPool4(start_address, end_address,
+                                                               pool->subnet_id_, true);
+                rebuilt = true;
+                break;
+            }
         }
 
-        bool recreate = extractBool(cmd_args_, "recreate", false);
+        if (rebuilt){
+            auto response = createAnswer(CONTROL_RESULT_SUCCESS,
+                                         "SFLQ pool rebuilt.", cmd_args_);
+            setResponse(handle, response);
+        } else {
+            auto response = createAnswer(CONTROL_RESULT_EMPTY,
+                                         "SFLQ pool does not exist.", cmd_args_);
+            setResponse(handle, response);
+        }
 
-        // Invoke the pool create function inside a CriticalSection.
-        MultiThreadingCriticalSection cs;
-        bool created = LeaseMgrFactory::instance().
-                       sflqCreateFlqPool4(start_address, end_address, subnet_id, recreate);
+        LOG_DEBUG(lease_cmds_logger, LEASE_CMDS_DBG_COMMAND_DATA, SFLQ_POOL4_REBUILD)
+                  .arg(cmd_args_)
+                  .arg(rebuilt ? 1 : 0);
 
-        resp << (created ? "SFLQ pool created" : "SFLQ pool already exists") << ".";
     } catch (const std::exception& ex) {
-        LOG_ERROR(lease_cmds_logger, SFLQ_POOL4_CREATE_FAILED)
+        LOG_ERROR(lease_cmds_logger, SFLQ_POOL4_REBUILD_FAILED)
             .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
             .arg(ex.what());
         setErrorResponse(handle, ex.what());
         return (1);
     }
 
-    LOG_DEBUG(lease_cmds_logger, LEASE_CMDS_DBG_COMMAND_DATA, SFLQ_POOL4_CREATE)
-        .arg(cmd_args_->str());
-
-    setSuccessResponse(handle, resp.str());
     return (0);
 }
 
@@ -117,23 +128,17 @@ SflqCmdsImpl::sflqPool4DelHandler(CalloutHandle& handle) {
 }
 
 int
-SflqCmdsImpl::sflqPool6CreateHandler(CalloutHandle& handle) {
+SflqCmdsImpl::sflqPool6RebuildHandler(CalloutHandle& handle) {
     static const data::SimpleKeywords keywords =
     {
         { "start-address",  Element::string  },
         { "end-address",    Element::string  },
-        { "subnet-id",      Element::integer },
-        { "lease-type",     Element::string  },
-        { "delegated-len",  Element::integer },
-        { "recreate",       Element::boolean }
     };
 
     static const data::SimpleRequiredKeywords required_keywords =
     {
         "start-address",
         "end-address",
-        "subnet-id",
-        "lease-type"
     };
 
     stringstream resp;
@@ -151,35 +156,47 @@ SflqCmdsImpl::sflqPool6CreateHandler(CalloutHandle& handle) {
         IOAddress end_address(IOAddress::IPV6_ZERO_ADDRESS());
         extractRange(cmd_args_, AF_INET6, start_address, end_address);
 
-        /// @todo Should we verify the subnet-id and/or check allocator for subnet?
-        SubnetID subnet_id = SimpleParser::getInteger(cmd_args_, "subnet-id");
-        if (subnet_id <= 0) {
-            isc_throw(isc::BadValue, "'subnet-id' must be greater than zero");
+        // Fetch pools by range.
+        auto pools = LeaseMgrFactory::instance().sflqPool6Get(start_address, end_address);
+
+        // Since get can return more than one, look for an exact match.
+        bool rebuilt = false;
+        for (auto const& pool : *pools ) {
+            if (pool->start_address_ == start_address && pool->end_address_ == end_address) {
+                // Found a match, rebuild it.
+                // Invoke the pool create function inside a CriticalSection. Rebuilding
+                // large pools can take a long time.
+                MultiThreadingCriticalSection cs;
+                LeaseMgrFactory::instance().sflqCreateFlqPool6(start_address, end_address,
+                                                               pool->lease_type_,
+                                                               pool->delegated_len_,
+                                                               pool->subnet_id_, true);
+                rebuilt = true;
+                break;
+            }
         }
 
-        auto lease_type = extractLeaseType(cmd_args_, AF_INET6);
-        uint8_t delegated_len = extractDelegatedLen(cmd_args_, lease_type);
-        bool recreate = extractBool(cmd_args_, "recreate", false);
-
-        // Invoke the pool create function inside a CriticalSection.
-        MultiThreadingCriticalSection cs;
-        bool created = LeaseMgrFactory::instance().
-                       sflqCreateFlqPool6(start_address, end_address, lease_type,
-                                          delegated_len, subnet_id, recreate);
+        if (rebuilt){
+            auto response = createAnswer(CONTROL_RESULT_SUCCESS,
+                                         "SFLQ pool rebuilt.", cmd_args_);
+            setResponse(handle, response);
+        } else {
+            auto response = createAnswer(CONTROL_RESULT_EMPTY,
+                                         "SFLQ pool does not exist.", cmd_args_);
+            setResponse(handle, response);
+        }
 
-        resp << (created ? "SFLQ pool created" : "SFLQ pool already exists") << ".";
+        LOG_DEBUG(lease_cmds_logger, LEASE_CMDS_DBG_COMMAND_DATA, SFLQ_POOL6_REBUILD)
+                  .arg(cmd_args_)
+                  .arg(rebuilt ? 1 : 0);
     } catch (const std::exception& ex) {
-        LOG_ERROR(lease_cmds_logger, SFLQ_POOL6_CREATE_FAILED)
+        LOG_ERROR(lease_cmds_logger, SFLQ_POOL6_REBUILD_FAILED)
             .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
             .arg(ex.what());
         setErrorResponse(handle, ex.what());
         return (1);
     }
 
-    LOG_DEBUG(lease_cmds_logger, LEASE_CMDS_DBG_COMMAND_DATA, SFLQ_POOL6_CREATE)
-        .arg(cmd_args_->str());
-
-    setSuccessResponse(handle, resp.str());
     return (0);
 }
 
@@ -468,42 +485,13 @@ SflqCmdsImpl::extractLeaseType(ConstElementPtr& params, uint16_t family) {
               << tmp << ", valid values are IA_NA and IA_PD");
 }
 
-uint8_t
-SflqCmdsImpl::extractDelegatedLen(ConstElementPtr& params,
-                                  Lease::Type lease_type) {
-    auto tmp = params->get("delegated-len");
-    if (!tmp) {
-        if (lease_type == Lease::TYPE_PD) {
-            isc_throw(BadValue, "'delegated-len' is required for IA_PD pools");
-        }
-
-        return (128);
-    }
-
-    if (tmp->getType() != Element::integer) {
-        isc_throw(BadValue, "'delegated-len' parameter is not integer.");
-    }
-
-    auto val = tmp->intValue();
-    if (val <= 0 || val > 128) {
-        isc_throw(BadValue, "'delegated-len' invalid: " << val
-                  << ", it must be >= 1 and =< 128");
-    }
-
-    if (lease_type == Lease::TYPE_NA && val != 128) {
-        isc_throw(BadValue, "'delegated-len' must only be 128 for IA_NA pools");
-    }
-
-    return (val);
-}
-
 SflqCmds::SflqCmds()
     : sflq_impl_(new SflqCmdsImpl()) {
 }
 
 int
-SflqCmds::sflqPool4CreateHandler(CalloutHandle& handle) {
-    return (sflq_impl_->sflqPool4CreateHandler(handle));
+SflqCmds::sflqPool4RebuildHandler(CalloutHandle& handle) {
+    return (sflq_impl_->sflqPool4RebuildHandler(handle));
 }
 
 int
@@ -527,8 +515,8 @@ SflqCmds::sflqPool4DelHandler(CalloutHandle& handle) {
 }
 
 int
-SflqCmds::sflqPool6CreateHandler(CalloutHandle& handle) {
-    return (sflq_impl_->sflqPool6CreateHandler(handle));
+SflqCmds::sflqPool6RebuildHandler(CalloutHandle& handle) {
+    return (sflq_impl_->sflqPool6RebuildHandler(handle));
 }
 
 int
index e967792b7feaa5e577743f3fde73089932e98f28..faded44f4b608e5baa0564251645db1aae92951b 100644 (file)
@@ -31,7 +31,7 @@ public:
     /// @brief Destructor.
     virtual ~SflqCmdsImpl() {};
 
-    /// @brief The 'sflq-pool4-create' command handler
+    /// @brief The 'sflq-pool4-rebuild' command handler
     ///
     /// It extracts the command name and arguments from the given CalloutHandle,
     /// attempts to process them, and then set's the handle's "response"
@@ -39,21 +39,17 @@ public:
     ///
     /// An example command with all supported arguments is shown below:
     /// {
-    ///     "command": "sflq-pool4-create",
+    ///     "command": "sflq-pool4-rebuild",
     ///     "arguments": {
     ///         "start-address": "192.0.2.0",
-    ///         "end-address": "192.0.2.255",
-    ///         "subnet-id": 77,
-    ///         "recreate": true
+    ///         "end-address": "192.0.2.255"
     ///     }
     /// }
     ///
-    /// The 'recreate' parameter is optional, it defaults false.
-    ///
     /// @param handle Callout context - which is expected to contain the
     /// the command JSON text in the "command" argument
     /// @return result of the operation
-    int sflqPool4CreateHandler(hooks::CalloutHandle& handle);
+    int sflqPool4RebuildHandler(hooks::CalloutHandle& handle);
 
     /// @brief The 'sflq-pool4-get-all' command handler
     ///
@@ -132,7 +128,7 @@ public:
     /// @return result of the operation
     int sflqPool4DelHandler(hooks::CalloutHandle& handle);
 
-    /// @brief The 'sflq-pool6-create' command handler
+    /// @brief The 'sflq-pool6-rebuild' command handler
     ///
     /// It extracts the command name and arguments from the given CalloutHandle,
     /// attempts to process them, and then set's the handle's "response"
@@ -140,23 +136,17 @@ public:
     ///
     /// An example command with all supported arguments is shown below:
     /// {
-    ///     "command": "sflq-pool6-create",
+    ///     "command": "sflq-pool6-rebuild",
     ///     "arguments": {
     ///         "start-address": "3001::",
-    ///         "end-address": "3001::FF",
-    ///         "subnet-id": 77,
-    ///         "lease-type" : "IA_PD",
-    ///         "delegated_len: 64
-    ///         "recreate": true
+    ///         "end-address": "3001::FF"
     ///     }
     /// }
     ///
-    /// The 'recreate' parameter is optional, it defaults false.
-    ///
     /// @param handle Callout context - which is expected to contain the
     /// the command JSON text in the "command" argument
     /// @return result of the operation
-    int sflqPool6CreateHandler(hooks::CalloutHandle& handle);
+    int sflqPool6RebuildHandler(hooks::CalloutHandle& handle);
 
     /// @brief The 'sflq-pool6-get-all' command handler
     ///
@@ -363,22 +353,7 @@ public:
     static bool extractBool(data::ConstElementPtr& params, const std::string& name,
                             bool default_value = false);
 
-    /// @brief Extracts 'delegated-len' from given parameters map
-    ///
-    /// Extracts an integer element, 'delegate-len' from the given map
-    /// if it is present and is >= 1 and <= 128. If it is not present
-    /// it returns a value of 128.
-    ///
-    /// @param params Element map containing the command arguments.
-    /// @param lease_type Lease::Type supplied with the arguments (IA_NA
-    /// or IA_PD)
-    ///
-    /// @throw BadValue if the parameter is specified as anything other
-    /// than an integer value >= 1 and <= 128.
-    static uint8_t extractDelegatedLen(data::ConstElementPtr& params,
-                                       dhcp::Lease::Type lease_type);
-
-    /// @brief Extracts 'delegated-len' from given parameters map
+    /// @brief Extracts 'lease-type' from given parameters map
     ///
     /// Extracts a string element, 'lease-type' from the given map
     /// For v4 it can be either "V4" or "3", for V6 it can be "IA_NA"
@@ -404,7 +379,7 @@ public:
     /// It creates an instance of the @c SflqCmds
     SflqCmds();
 
-    /// @brief sflq-pool4-create handler.
+    /// @brief sflq-pool4-rebuild handler.
     ///
     /// Invokes LeaseMgr::sflqCreateFlqPool4() after parsing the arguments.
     /// @brief lease6-resend-ddns command handler
@@ -415,21 +390,17 @@ public:
     ///
     /// An example command with all supported arguments is shown below:
     /// {
-    ///     "command": "sflq-pool4-create",
+    ///     "command": "sflq-pool4-rebuild",
     ///     "arguments": {
     ///         "start-address": "192.0.2.0",
-    ///         "end-address": "192.0.2.255",
-    ///         "subnet-id": 77,
-    ///         "recreate": true
+    ///         "end-address": "192.0.2.255"
     ///     }
     /// }
     ///
-    /// The 'recreate' parameter is optional, it defaults false.
-    ///
     /// @param handle Callout context - which is expected to contain the
     /// the command JSON text in the "command" argument
     /// @return result of the operation
-    int sflqPool4CreateHandler(hooks::CalloutHandle& handle);
+    int sflqPool4RebuildHandler(hooks::CalloutHandle& handle);
 
     /// @brief The 'sflq-pool4-get-all' command handler
     ///
@@ -508,7 +479,7 @@ public:
     /// @return result of the operation
     int sflqPool4DelHandler(hooks::CalloutHandle& handle);
 
-    /// @brief The 'sflq-pool6-create' command handler
+    /// @brief The 'sflq-pool6-rebuild' command handler
     ///
     /// It extracts the command name and arguments from the given CalloutHandle,
     /// attempts to process them, and then set's the handle's "response"
@@ -516,24 +487,17 @@ public:
     ///
     /// An example command with all supported arguments is shown below:
     /// {
-    ///     "command": "sflq-pool6-create",
+    ///     "command": "sflq-pool6-rebuild",
     ///     "arguments": {
     ///         "start-address": "3001::",
-    ///         "end-address": "3001::FF",
-    ///         "subnet-id": 77,
-    ///         "lease-type" : "IA_PD",
-    ///         "delegated_len: 64
-    ///         "recreate": true
+    ///         "end-address": "3001::FF"
     ///     }
     /// }
     ///
-    /// The 'delegated-len' is optional, it defaults to 128.
-    /// The 'recreate' parameter is optional, it defaults false.
-    ///
     /// @param handle Callout context - which is expected to contain the
     /// the command JSON text in the "command" argument
     /// @return result of the operation
-    int sflqPool6CreateHandler(hooks::CalloutHandle& handle);
+    int sflqPool6RebuildHandler(hooks::CalloutHandle& handle);
 
     /// @brief The 'sflq-pool6-get-all' command handler
     ///
index 13841b1bdb356fb0b17b67e8df6954534122fbff..fb919b1c3d16ec3aae78e607ac26976e6a28d85a 100644 (file)
@@ -5534,12 +5534,12 @@ MySqlLeaseMgr::sflqPoolGetCommon(StatementIndex stindex,
 
     ctx->conn_.selectQuery(stindex, where_bindings, out_bindings,
                            [&pools]
-                           (MySqlBindingCollection& out_bindings) {
+                           (MySqlBindingCollection& result) {
 
         SflqPoolInfoPtr info(new SflqPoolInfo());
         // db pool id is 0, we skip it
-        info->subnet_id_ = out_bindings[1]->getInteger<uint32_t>();
-        auto lease_type_ = out_bindings[2]->getInteger<uint32_t>();
+        info->subnet_id_ = result[1]->getInteger<uint32_t>();
+        auto lease_type_ = result[2]->getInteger<uint32_t>();
         switch(lease_type_) {
         case Lease::TYPE_V4:
             info->lease_type_ = Lease::TYPE_V4;
@@ -5556,17 +5556,17 @@ MySqlLeaseMgr::sflqPoolGetCommon(StatementIndex stindex,
         }
 
         if (lease_type_ == Lease::TYPE_V4) {
-            info->start_address_ = IOAddress(out_bindings[3]->getInteger<uint32_t>());
-            info->end_address_ = IOAddress(out_bindings[4]->getInteger<uint32_t>());
+            info->start_address_ = IOAddress(result[3]->getInteger<uint32_t>());
+            info->end_address_ = IOAddress(result[4]->getInteger<uint32_t>());
         } else {
-            info->start_address_ = IOAddress(out_bindings[3]->getString());
-            info->end_address_ = IOAddress(out_bindings[4]->getString());
+            info->start_address_ = IOAddress(result[3]->getString());
+            info->end_address_ = IOAddress(result[4]->getString());
         }
 
-        info->delegated_len_ = out_bindings[5]->getInteger<uint32_t>();
-        info->created_ts_ = out_bindings[6]->getTimestamp();
-        info->modified_ts_ = out_bindings[7]->getTimestamp();
-        info->free_leases_ = out_bindings[8]->getInteger<uint64_t>();
+        info->delegated_len_ = result[5]->getInteger<uint32_t>();
+        info->created_ts_ = result[6]->getTimestamp();
+        info->modified_ts_ = result[7]->getTimestamp();
+        info->free_leases_ = result[8]->getInteger<uint64_t>();
         pools->push_back(info);
     });
 
similarity index 53%
rename from src/share/api/sflq-pool4-create.json
rename to src/share/api/sflq-pool4-rebuild.json
index 22ccdd43526b63a2fc1df716e33442aedaadd878..97d2ba1205c526bdbbd96ebac80b06c412d3add2 100644 (file)
@@ -2,26 +2,24 @@
     "access": "write",
     "avail": "3.1.9",
     "brief": [
-        "This command instructs the lease back end to create a v4 SFLQ pool and its free lease data."
+        "This command instructs the lease back rebuild the free lease data for a v4 SFLQ pool."
     ],
     "cmd-syntax": [
         "{",
         "    \"command\": \"sflq-pool4-create\",",
         "    \"arguments\": {",
         "       \"start-address\": \"1.2.3.4\",",
-        "       \"end-address\": \"1.2.3.4\",",
-        "       \"subnet-id\": 123,",
-        "       \"recreate\" : false",
+        "       \"end-address\": \"1.2.3.4\"",
         "    }",
         "}"
     ],
-    "description": "See <xref linkend=\"command-sflq-pool4-create\"/>",
+    "description": "See <xref linkend=\"command-sflq-pool4-rebuild\"/>",
     "hook": "lease_cmds",
-    "name": "sflq-pool4-create",
+    "name": "sflq-pool4-rebuild",
     "resp-syntax": [
         "{",
         "    \"result\": 0,",
-        "    \"text\": \"SFLQ pool created.\"",
+        "    \"text\": \"SFLQ pool rebuilt.\"",
         "}"
     ],
     "support": [
diff --git a/src/share/api/sflq-pool6-create.json b/src/share/api/sflq-pool6-create.json
deleted file mode 100644 (file)
index d6e9809..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-{
-    "access": "write",
-    "avail": "3.1.9",
-    "brief": [
-        "This command instructs the lease back end to create a v6 SFLQ pool and its free lease data."
-    ],
-    "cmd-syntax": [
-        "{",
-        "    \"command\": \"sflq-pool6-create\",",
-        "    \"arguments\": {",
-        "       \"start-address\": \"2001:db8:1::\",",
-        "       \"end-address\": \"2001:db8:1::ffff\",",
-        "       \"lease-type\": \"IA_PD\"," ,
-        "       \"delegated-len\": 120,",
-        "       \"recreate\" : false",
-        "    }",
-        "}"
-    ],
-    "description": "See <xref linkend=\"command-sflq-pool6-create\"/>",
-    "hook": "lease_cmds",
-    "name": "sflq-pool6-create",
-    "resp-syntax": [
-        "{",
-        "    \"result\": 0,",
-        "    \"text\": \"SFLQ pool created.\"",
-        "}"
-    ],
-    "support": [
-        "kea-dhcp4",
-        "kea-dhcp6"
-    ]
-}
diff --git a/src/share/api/sflq-pool6-rebuild.json b/src/share/api/sflq-pool6-rebuild.json
new file mode 100644 (file)
index 0000000..4ee232a
--- /dev/null
@@ -0,0 +1,29 @@
+{
+    "access": "write",
+    "avail": "3.1.9",
+    "brief": [
+        "This command instructs the lease back end rebuild the free lease data for a v6 SFLQ pool."
+    ],
+    "cmd-syntax": [
+        "{",
+        "    \"command\": \"sflq-pool6-rebuild\",",
+        "    \"arguments\": {",
+        "       \"start-address\": \"2001:db8:1::\",",
+        "       \"end-address\": \"2001:db8:1::ffff\"",
+        "    }",
+        "}"
+    ],
+    "description": "See <xref linkend=\"command-sflq-pool6-rebuild\"/>",
+    "hook": "lease_cmds",
+    "name": "sflq-pool6-rebuild",
+    "resp-syntax": [
+        "{",
+        "    \"result\": 0,",
+        "    \"text\": \"SFLQ pool rebuilt.\"",
+        "}"
+    ],
+    "support": [
+        "kea-dhcp4",
+        "kea-dhcp6"
+    ]
+}