/// Supported values are: "address", hw-address and duid.
///
/// @param txt text to be converted
+ ///
/// @return value converted to Parameters::Type
+ ///
/// @throw BadValue if unsupported type is specified
static Type txtToType(const std::string& txt) {
if (txt == "address") {
///
/// @param handle Callout context - which is expected to contain the
/// add command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
leaseAddHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// add command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease6BulkApplyHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// get command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
leaseGetHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// get command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise.
int
leaseGetAllHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// get commands JSON text in the "command" argument.
+ ///
/// @return 0 if the handler has been invoked successfully, 1 if an
/// error occurs, 3 if no leases are returned.
int
///
/// @param handle Callout context - which is expected to contain the
/// get command JSON text in the "command" argument
+ ///
/// @return 0 if the handler has been invoked successfully, 1 if an
/// error occurs, 3 if no leases are returned.
int
///
/// @param handle Callout context - which is expected to contain the
/// get command JSON text in the "command" argument
+ ///
/// @return 0 if the handler has been invoked successfully, 1 if an
/// error occurs, 3 if no leases are returned.
int
///
/// @param handle Callout context - which is expected to contain the
/// get command JSON text in the "command" argument
+ ///
/// @return 0 if the handler has been invoked successfully, 1 if an
/// error occurs, 3 if no leases are returned.
int
///
/// @param handle Callout context - which is expected to contain the
/// get command JSON text in the "command" argument
+ ///
/// @return 0 if the handler has been invoked successfully, 1 if an
/// error occurs, 3 if no leases are returned.
int
///
/// @param handle Callout context - which is expected to contain the
/// delete command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease4DelHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// delete command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease6DelHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// update command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease4UpdateHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// update command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease6UpdateHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// wipe command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease4WipeHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// wipe command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int
lease6WipeHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// lease4-resend-ddns command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int lease4ResendDdnsHandler(CalloutHandle& handle);
///
/// @param handle Callout context - which is expected to contain the
/// lease6-resend-ddns command JSON text in the "command" argument
+ ///
/// @return 0 upon success, non-zero otherwise
int lease6ResendDdnsHandler(CalloutHandle& handle);
///
/// @param v6 whether addresses allowed are v4 (false) or v6 (true)
/// @param args arguments passed to command
+ ///
/// @return parsed parameters
+ ///
/// @throw BadValue if input arguments don't make sense.
Parameters getParameters(bool v6, const ConstElementPtr& args);
/// @param control_result Control result: "empty" of the lease was
/// not found, "error" otherwise.
/// @param error_message Error message.
+ ///
+ /// @return The JSON map of the failed leases.
ElementPtr createFailedLeaseMap(const Lease::Type& lease_type,
const IOAddress& lease_address,
const DuidPtr& duid,
const std::string& error_message) const;
/// @brief Fetches an IP address parameter from a map of parameters
+ ///
/// @param map of parameters in which to look
/// @name name of the parameter desired
/// @param family expected protocol family of the address parameter,
/// AF_INET or AF_INET6
+ ///
/// @return IOAddress containing the value of the parameter.
+ ///
/// @throw BadValue if the parameter is missing or invalid
IOAddress getAddressParam(ConstElementPtr params, const std::string name,
short family = AF_INET) const;
///
/// @param lease Deleted lease.
static void updateStatsOnDelete(const Lease6Ptr& lease);
+
+ /// @brief Add or update lease.
+ ///
+ /// @param lease The lease to be added or updated (if exists).
+ /// @param force_create Flag to indicate if the function should try to
+ /// create the lease if it does not exists, or simply update and fail in
+ /// such case.
+ ///
+ /// @return true if lease has been successfully added, false otherwise.
+ static bool addOrUpdate4(Lease4Ptr lease, bool force_create);
+
+ /// @brief Add or update lease.
+ ///
+ /// @param lease The lease to be added or updated (if exists).
+ /// @param force_create Flag to indicate if the function should try to
+ /// create the lease if it does not exists, or simply update and fail in
+ /// such case.
+ ///
+ /// @return true if lease has been successfully added, false otherwise.
+ static bool addOrUpdate6(Lease6Ptr lease, bool force_create);
};
void
}
}
-namespace { // anonymous namespace.
-
bool
-addOrUpdate4(Lease4Ptr lease, bool force_create) {
+LeaseCmdsImpl::addOrUpdate4(Lease4Ptr lease, bool force_create) {
Lease4Ptr existing = LeaseMgrFactory::instance().getLease4(lease->addr_);
if (force_create && !existing) {
// lease does not exist
}
bool
-addOrUpdate6(Lease6Ptr lease, bool force_create) {
+LeaseCmdsImpl::addOrUpdate6(Lease6Ptr lease, bool force_create) {
Lease6Ptr existing =
LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_);
if (force_create && !existing) {
return (false);
}
-} // end of anonymous namespace.
-
int
LeaseCmdsImpl::leaseAddHandler(CalloutHandle& handle) {
// Arbitrary defaulting to DHCPv4 or with other words extractCommand
}
if (id) {
- // Wipe a single subnet
+ // Wipe a single subnet.
num = LeaseMgrFactory::instance().wipeLeases4(id);
ids << " " << id;
- int64_t previous_declined = StatsMgr::instance().getObservation(
- StatsMgr::generateName("subnet", id, "declined-addresses"))->getInteger().first;
+ auto observation = StatsMgr::instance().getObservation(
+ StatsMgr::generateName("subnet", id, "declined-addresses"));
+
+ int64_t previous_declined = 0;
+
+ if (observation) {
+ previous_declined = observation->getInteger().first;
+ }
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "assigned-addresses"),
num = LeaseMgrFactory::instance().wipeLeases6(id);
ids << " " << id;
- int64_t previous_declined = StatsMgr::instance().getObservation(
- StatsMgr::generateName("subnet", id, "declined-addresses"))->getInteger().first;
+ auto observation = StatsMgr::instance().getObservation(
+ StatsMgr::generateName("subnet", id, "declined-addresses"));
+
+ int64_t previous_declined = 0;
+
+ if (observation) {
+ previous_declined = observation->getInteger().first;
+ }
StatsMgr::instance().setValue(
StatsMgr::generateName("subnet", id, "assigned-nas" ),
}
// Check that a simple, well formed lease4 can be added.
-TEST_F(LeaseCmdsTest, Lease4AddWithStats) {
+TEST_F(LeaseCmdsTest, Lease4AddDeclinedLeases) {
// Initialize lease manager (false = v4, false = don't add leases)
initLeaseMgr(false, false);
// Check that subnet-id is optional. If not specified, Kea should select
// it on its own.
-TEST_F(LeaseCmdsTest, Lease4AddSubnetIdMissingWithStats) {
+TEST_F(LeaseCmdsTest, Lease4AddSubnetIdMissingDeclinedLeases) {
// Initialize lease manager (false = v4, false = don't add leases)
initLeaseMgr(false, false);
}
// Check that a simple, well formed lease6 can be added.
-TEST_F(LeaseCmdsTest, Lease6AddWithStats) {
+TEST_F(LeaseCmdsTest, Lease6AddDeclinedLeases) {
// Initialize lease manager (true = v6, false = don't add leases)
initLeaseMgr(true, false);
// Check that subnet-id is optional. If not specified, Kea should select
// it on its own.
-TEST_F(LeaseCmdsTest, Lease6AddSubnetIdMissingWithStats) {
+TEST_F(LeaseCmdsTest, Lease6AddSubnetIdMissingDeclinedLeases) {
// Initialize lease manager (true = v6, false = don't add leases)
initLeaseMgr(true, false);
// Check that a lease4 can be updated. We're changing hw-address
// and a hostname.
-TEST_F(LeaseCmdsTest, Lease4UpdateWithStats) {
+TEST_F(LeaseCmdsTest, Lease4UpdateDeclinedLeases) {
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true, true);
// Check that a lease4 can be updated. We're changing hw-address
// and a hostname. The subnet-id is not specified.
-TEST_F(LeaseCmdsTest, Lease4UpdateNoSubnetIdWithStats) {
+TEST_F(LeaseCmdsTest, Lease4UpdateNoSubnetIdDeclinedLeases) {
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true, true);
// Check that a lease6 can be updated. We're changing hw-address
// and a hostname.
-TEST_F(LeaseCmdsTest, Lease6UpdateWithStats) {
+TEST_F(LeaseCmdsTest, Lease6UpdateDeclinedLeases) {
// Initialize lease manager (true = v6, true = add leases)
initLeaseMgr(true, true, true);
// Check that a lease6 can be updated. We're changing hw-address
// and a hostname. The subnet-id is not specified.
-TEST_F(LeaseCmdsTest, Lease6UpdateNoSubnetIdWithStats) {
+TEST_F(LeaseCmdsTest, Lease6UpdateNoSubnetIdDeclinedLeases) {
// Initialize lease manager (true = v6, true = add leases)
initLeaseMgr(true, true, true);
}
// Checks that lease4-del can return a lease by address.
-TEST_F(LeaseCmdsTest, Lease4DelByAddrWithStats) {
+TEST_F(LeaseCmdsTest, Lease4DelByAddrDeclinedLeases) {
// Initialize lease manager (false = v4, true = add leases)
initLeaseMgr(false, true, true);
// Checks that lease6-del(subnet-id, addr6) can handle a situation when
// the query is correctly formed and the lease is returned.
-TEST_F(LeaseCmdsTest, Lease6DelByAddrWithStats) {
+TEST_F(LeaseCmdsTest, Lease6DelByAddrDeclinedLeases) {
initLeaseMgr(true, true, true); // (true = v6, true = create a lease)