#!/bin/sh

# Copyright (C) 2021-2025 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu

LOG_FILE="@abs_top_builddir@/src/hooks/dhcp/run_script/tests/test.log"

ECHO_TO_FILE() {
    echo "${@}"
    echo "${@}" > ${LOG_FILE}
}

ASSERT_EQ() {
    EXPECTED=${1}
    ACTUAL=${2}
    if ! test "${EXPECTED}" = "${ACTUAL}"; then
        ECHO_TO_FILE "FAILED"
        ECHO_TO_FILE "Values differ:"
        ECHO_TO_FILE "    expected: ${EXPECTED}"
        ECHO_TO_FILE "    actual: ${ACTUAL}"
        exit 123
    fi
}

TEST_EQ() {
    TEST_VARIABLE=${1}
    TEST_EXPECTED="${1}=${2}"
    TEST_ACTUAL=$(env | grep -E "^${TEST_VARIABLE}=")
    ASSERT_EQ "${TEST_EXPECTED}" "${TEST_ACTUAL}"
}

unknown_handle() {
    ECHO_TO_FILE "Unhandled function call ${*}"
    exit 123
}

lease4_renew () {
    TEST_EQ "QUERY4_TYPE" "UNKNOWN"
    TEST_EQ "QUERY4_TXID" "0"
    TEST_EQ "QUERY4_LOCAL_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_LOCAL_PORT" "67"
    TEST_EQ "QUERY4_REMOTE_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_REMOTE_PORT" "68"
    TEST_EQ "QUERY4_IFACE_INDEX" "2"
    TEST_EQ "QUERY4_IFACE_NAME" "eth1"
    TEST_EQ "QUERY4_HOPS" "0"
    TEST_EQ "QUERY4_SECS" "0"
    TEST_EQ "QUERY4_FLAGS" "0"
    TEST_EQ "QUERY4_CIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_SIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_YIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_GIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_RELAYED" "false"
    TEST_EQ "QUERY4_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_LOCAL_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_LOCAL_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_OPTION_82" "0x0105686F776479020587F67977EF06061A2B3C4D5E6F"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_1" "0x686F776479"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_2" "0x87F67977EF"
    TEST_EQ "SUBNET4_ID" "6"
    TEST_EQ "SUBNET4_NAME" "182.168.0.1/2"
    TEST_EQ "SUBNET4_PREFIX" "182.168.0.1"
    TEST_EQ "SUBNET4_PREFIX_LEN" "2"
    TEST_EQ "PKT4_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "PKT4_HWADDR" "00:01:02:03"
    TEST_EQ "PKT4_HWADDR_TYPE" "1"
    TEST_EQ "LEASE4_ADDRESS" "192.168.0.1"
    TEST_EQ "LEASE4_CLTT" "3"
    TEST_EQ "LEASE4_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE4_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE4_HWADDR_TYPE" "1"
    TEST_EQ "LEASE4_STATE" "default"
    TEST_EQ "LEASE4_SUBNET_ID" "4"
    TEST_EQ "LEASE4_VALID_LIFETIME" "2"
    TEST_EQ "LEASE4_CLIENT_ID" "00:01:02:03:04:05:06"
    ECHO_TO_FILE "SUCCESS"
}

lease4_expire () {
    TEST_EQ "LEASE4_ADDRESS" "192.168.0.1"
    TEST_EQ "LEASE4_CLTT" "3"
    TEST_EQ "LEASE4_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE4_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE4_HWADDR_TYPE" "1"
    TEST_EQ "LEASE4_STATE" "default"
    TEST_EQ "LEASE4_SUBNET_ID" "4"
    TEST_EQ "LEASE4_VALID_LIFETIME" "2"
    TEST_EQ "LEASE4_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "REMOVE_LEASE" "true"
    ECHO_TO_FILE "SUCCESS"
}

lease4_recover () {
    TEST_EQ "LEASE4_ADDRESS" "192.168.0.1"
    TEST_EQ "LEASE4_CLTT" "3"
    TEST_EQ "LEASE4_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE4_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE4_HWADDR_TYPE" "1"
    TEST_EQ "LEASE4_STATE" "default"
    TEST_EQ "LEASE4_SUBNET_ID" "4"
    TEST_EQ "LEASE4_VALID_LIFETIME" "2"
    TEST_EQ "LEASE4_CLIENT_ID" "00:01:02:03:04:05:06"
    ECHO_TO_FILE "SUCCESS"
}

leases4_committed () {
    TEST_EQ "QUERY4_TYPE" "UNKNOWN"
    TEST_EQ "QUERY4_TXID" "0"
    TEST_EQ "QUERY4_LOCAL_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_LOCAL_PORT" "67"
    TEST_EQ "QUERY4_REMOTE_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_REMOTE_PORT" "68"
    TEST_EQ "QUERY4_IFACE_INDEX" "2"
    TEST_EQ "QUERY4_IFACE_NAME" "eth1"
    TEST_EQ "QUERY4_HOPS" "0"
    TEST_EQ "QUERY4_SECS" "0"
    TEST_EQ "QUERY4_FLAGS" "0"
    TEST_EQ "QUERY4_CIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_SIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_YIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_GIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_RELAYED" "false"
    TEST_EQ "QUERY4_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_LOCAL_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_LOCAL_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_OPTION_82" "0x0105686F776479020587F67977EF06061A2B3C4D5E6F"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_1" "0x686F776479"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_2" "0x87F67977EF"
    TEST_EQ "LEASES4_SIZE" "2"
    TEST_EQ "LEASES4_AT0_ADDRESS" ""
    TEST_EQ "LEASES4_AT0_CLTT" ""
    TEST_EQ "LEASES4_AT0_HOSTNAME" ""
    TEST_EQ "LEASES4_AT0_HWADDR" ""
    TEST_EQ "LEASES4_AT0_HWADDR_TYPE" ""
    TEST_EQ "LEASES4_AT0_STATE" ""
    TEST_EQ "LEASES4_AT0_SUBNET_ID" ""
    TEST_EQ "LEASES4_AT0_VALID_LIFETIME" ""
    TEST_EQ "LEASES4_AT0_CLIENT_ID" ""
    TEST_EQ "LEASES4_AT1_ADDRESS" "192.168.0.1"
    TEST_EQ "LEASES4_AT1_CLTT" "3"
    TEST_EQ "LEASES4_AT1_HOSTNAME" "test.hostname"
    TEST_EQ "LEASES4_AT1_HWADDR" "00:01:02:03"
    TEST_EQ "LEASES4_AT1_HWADDR_TYPE" "1"
    TEST_EQ "LEASES4_AT1_STATE" "default"
    TEST_EQ "LEASES4_AT1_SUBNET_ID" "4"
    TEST_EQ "LEASES4_AT1_VALID_LIFETIME" "2"
    TEST_EQ "LEASES4_AT1_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "DELETED_LEASES4_SIZE" "2"
    TEST_EQ "DELETED_LEASES4_AT0_ADDRESS" "192.168.0.1"
    TEST_EQ "DELETED_LEASES4_AT0_CLTT" "3"
    TEST_EQ "DELETED_LEASES4_AT0_HOSTNAME" "test.hostname"
    TEST_EQ "DELETED_LEASES4_AT0_HWADDR" "00:01:02:03"
    TEST_EQ "DELETED_LEASES4_AT0_HWADDR_TYPE" "1"
    TEST_EQ "DELETED_LEASES4_AT0_STATE" "default"
    TEST_EQ "DELETED_LEASES4_AT0_SUBNET_ID" "4"
    TEST_EQ "DELETED_LEASES4_AT0_VALID_LIFETIME" "2"
    TEST_EQ "DELETED_LEASES4_AT0_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "DELETED_LEASES4_AT1_ADDRESS" ""
    TEST_EQ "DELETED_LEASES4_AT1_CLTT" ""
    TEST_EQ "DELETED_LEASES4_AT1_HOSTNAME" ""
    TEST_EQ "DELETED_LEASES4_AT1_HWADDR" ""
    TEST_EQ "DELETED_LEASES4_AT1_HWADDR_TYPE" ""
    TEST_EQ "DELETED_LEASES4_AT1_STATE" ""
    TEST_EQ "DELETED_LEASES4_AT1_SUBNET_ID" ""
    TEST_EQ "DELETED_LEASES4_AT1_VALID_LIFETIME" ""
    TEST_EQ "DELETED_LEASES4_AT1_CLIENT_ID" ""
    ECHO_TO_FILE "SUCCESS"
}

lease4_release () {
    TEST_EQ "QUERY4_TYPE" "UNKNOWN"
    TEST_EQ "QUERY4_TXID" "0"
    TEST_EQ "QUERY4_LOCAL_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_LOCAL_PORT" "67"
    TEST_EQ "QUERY4_REMOTE_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_REMOTE_PORT" "68"
    TEST_EQ "QUERY4_IFACE_INDEX" "2"
    TEST_EQ "QUERY4_IFACE_NAME" "eth1"
    TEST_EQ "QUERY4_HOPS" "0"
    TEST_EQ "QUERY4_SECS" "0"
    TEST_EQ "QUERY4_FLAGS" "0"
    TEST_EQ "QUERY4_CIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_SIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_YIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_GIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_RELAYED" "false"
    TEST_EQ "QUERY4_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_LOCAL_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_LOCAL_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_OPTION_82" "0x0105686F776479020587F67977EF06061A2B3C4D5E6F"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_1" "0x686F776479"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_2" "0x87F67977EF"
    TEST_EQ "LEASE4_ADDRESS" "192.168.0.1"
    TEST_EQ "LEASE4_CLTT" "3"
    TEST_EQ "LEASE4_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE4_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE4_HWADDR_TYPE" "1"
    TEST_EQ "LEASE4_STATE" "default"
    TEST_EQ "LEASE4_SUBNET_ID" "4"
    TEST_EQ "LEASE4_VALID_LIFETIME" "2"
    TEST_EQ "LEASE4_CLIENT_ID" "00:01:02:03:04:05:06"
    ECHO_TO_FILE "SUCCESS"
}

lease4_decline () {
    TEST_EQ "QUERY4_TYPE" "UNKNOWN"
    TEST_EQ "QUERY4_TXID" "0"
    TEST_EQ "QUERY4_LOCAL_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_LOCAL_PORT" "67"
    TEST_EQ "QUERY4_REMOTE_ADDR" "0.0.0.0"
    TEST_EQ "QUERY4_REMOTE_PORT" "68"
    TEST_EQ "QUERY4_IFACE_INDEX" "2"
    TEST_EQ "QUERY4_IFACE_NAME" "eth1"
    TEST_EQ "QUERY4_HOPS" "0"
    TEST_EQ "QUERY4_SECS" "0"
    TEST_EQ "QUERY4_FLAGS" "0"
    TEST_EQ "QUERY4_CIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_SIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_YIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_GIADDR" "0.0.0.0"
    TEST_EQ "QUERY4_RELAYED" "false"
    TEST_EQ "QUERY4_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_LOCAL_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_LOCAL_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY4_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY4_OPTION_82" "0x0105686F776479020587F67977EF06061A2B3C4D5E6F"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_1" "0x686F776479"
    TEST_EQ "QUERY4_OPTION_82_SUB_OPTION_2" "0x87F67977EF"
    TEST_EQ "LEASE4_ADDRESS" "192.168.0.1"
    TEST_EQ "LEASE4_CLTT" "3"
    TEST_EQ "LEASE4_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE4_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE4_HWADDR_TYPE" "1"
    TEST_EQ "LEASE4_STATE" "default"
    TEST_EQ "LEASE4_SUBNET_ID" "4"
    TEST_EQ "LEASE4_VALID_LIFETIME" "2"
    TEST_EQ "LEASE4_CLIENT_ID" "00:01:02:03:04:05:06"
    ECHO_TO_FILE "SUCCESS"
}

lease6_renew () {
    TEST_EQ "QUERY6_TYPE" "UNKNOWN"
    TEST_EQ "QUERY6_TXID" "0"
    TEST_EQ "QUERY6_LOCAL_ADDR" "ff02::1:2"
    TEST_EQ "QUERY6_LOCAL_PORT" "0"
    TEST_EQ "QUERY6_REMOTE_ADDR" "fe80::21e:8cff:fe9b:7349"
    TEST_EQ "QUERY6_REMOTE_PORT" "546"
    TEST_EQ "QUERY6_IFACE_INDEX" "2"
    TEST_EQ "QUERY6_IFACE_NAME" "eth1"
    TEST_EQ "QUERY6_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY6_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY6_PROTO" "UDP"
    TEST_EQ "QUERY6_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASE6_CLTT" "7"
    TEST_EQ "LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "LEASE6_STATE" "default"
    TEST_EQ "LEASE6_SUBNET_ID" "5"
    TEST_EQ "LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_IAID" "2"
    TEST_EQ "LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASE6_PREFIX_LEN" "128"
    TEST_EQ "LEASE6_TYPE" "IA_NA"
    TEST_EQ "PKT6_IA_IAID" "2711790500"
    TEST_EQ "PKT6_IA_IA_TYPE" "3"
    TEST_EQ "PKT6_IA_IA_T1" "2164392708"
    TEST_EQ "PKT6_IA_IA_T2" "2214789633"
    ECHO_TO_FILE "SUCCESS"
}

lease6_rebind () {
    TEST_EQ "QUERY6_TYPE" "UNKNOWN"
    TEST_EQ "QUERY6_TXID" "0"
    TEST_EQ "QUERY6_LOCAL_ADDR" "ff02::1:2"
    TEST_EQ "QUERY6_LOCAL_PORT" "0"
    TEST_EQ "QUERY6_REMOTE_ADDR" "fe80::21e:8cff:fe9b:7349"
    TEST_EQ "QUERY6_REMOTE_PORT" "546"
    TEST_EQ "QUERY6_IFACE_INDEX" "2"
    TEST_EQ "QUERY6_IFACE_NAME" "eth1"
    TEST_EQ "QUERY6_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY6_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY6_PROTO" "UDP"
    TEST_EQ "QUERY6_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASE6_CLTT" "7"
    TEST_EQ "LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "LEASE6_STATE" "default"
    TEST_EQ "LEASE6_SUBNET_ID" "5"
    TEST_EQ "LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_IAID" "2"
    TEST_EQ "LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASE6_PREFIX_LEN" "128"
    TEST_EQ "LEASE6_TYPE" "IA_NA"
    TEST_EQ "PKT6_IA_IAID" "2711790500"
    TEST_EQ "PKT6_IA_IA_TYPE" "3"
    TEST_EQ "PKT6_IA_IA_T1" "2164392708"
    TEST_EQ "PKT6_IA_IA_T2" "2214789633"
    ECHO_TO_FILE "SUCCESS"
}

lease6_expire () {
    TEST_EQ "LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASE6_CLTT" "7"
    TEST_EQ "LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "LEASE6_STATE" "default"
    TEST_EQ "LEASE6_SUBNET_ID" "5"
    TEST_EQ "LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_IAID" "2"
    TEST_EQ "LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASE6_PREFIX_LEN" "128"
    TEST_EQ "LEASE6_TYPE" "IA_NA"
    TEST_EQ "REMOVE_LEASE" "true"
    ECHO_TO_FILE "SUCCESS"
}

lease6_recover () {
    TEST_EQ "LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASE6_CLTT" "7"
    TEST_EQ "LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "LEASE6_STATE" "default"
    TEST_EQ "LEASE6_SUBNET_ID" "5"
    TEST_EQ "LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_IAID" "2"
    TEST_EQ "LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASE6_PREFIX_LEN" "128"
    TEST_EQ "LEASE6_TYPE" "IA_NA"
    ECHO_TO_FILE "SUCCESS"
}

leases6_committed () {
    TEST_EQ "QUERY6_TYPE" "UNKNOWN"
    TEST_EQ "QUERY6_TXID" "0"
    TEST_EQ "QUERY6_LOCAL_ADDR" "ff02::1:2"
    TEST_EQ "QUERY6_LOCAL_PORT" "0"
    TEST_EQ "QUERY6_REMOTE_ADDR" "fe80::21e:8cff:fe9b:7349"
    TEST_EQ "QUERY6_REMOTE_PORT" "546"
    TEST_EQ "QUERY6_IFACE_INDEX" "2"
    TEST_EQ "QUERY6_IFACE_NAME" "eth1"
    TEST_EQ "QUERY6_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY6_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY6_PROTO" "UDP"
    TEST_EQ "QUERY6_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASES6_SIZE" "2"
    TEST_EQ "LEASES6_AT0_ADDRESS" ""
    TEST_EQ "LEASES6_AT0_CLTT" ""
    TEST_EQ "LEASES6_AT0_HOSTNAME" ""
    TEST_EQ "LEASES6_AT0_HWADDR" ""
    TEST_EQ "LEASES6_AT0_HWADDR_TYPE" ""
    TEST_EQ "LEASES6_AT0_STATE" ""
    TEST_EQ "LEASES6_AT0_SUBNET_ID" ""
    TEST_EQ "LEASES6_AT0_VALID_LIFETIME" ""
    TEST_EQ "LEASES6_AT0_DUID" ""
    TEST_EQ "LEASES6_AT0_IAID" ""
    TEST_EQ "LEASES6_AT0_PREFERRED_LIFETIME" ""
    TEST_EQ "LEASES6_AT0_PREFIX_LEN" ""
    TEST_EQ "LEASES6_AT0_TYPE" ""
    TEST_EQ "LEASES6_AT1_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASES6_AT1_CLTT" "7"
    TEST_EQ "LEASES6_AT1_HOSTNAME" "test.hostname"
    TEST_EQ "LEASES6_AT1_HWADDR" "00:01:02:03"
    TEST_EQ "LEASES6_AT1_HWADDR_TYPE" "1"
    TEST_EQ "LEASES6_AT1_STATE" "default"
    TEST_EQ "LEASES6_AT1_SUBNET_ID" "5"
    TEST_EQ "LEASES6_AT1_VALID_LIFETIME" "4"
    TEST_EQ "LEASES6_AT1_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASES6_AT1_IAID" "2"
    TEST_EQ "LEASES6_AT1_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASES6_AT1_PREFIX_LEN" "128"
    TEST_EQ "LEASES6_AT1_TYPE" "IA_NA"
    TEST_EQ "DELETED_LEASES6_SIZE" "2"
    TEST_EQ "DELETED_LEASES6_AT0_ADDRESS" "2003:db8::1"
    TEST_EQ "DELETED_LEASES6_AT0_CLTT" "7"
    TEST_EQ "DELETED_LEASES6_AT0_HOSTNAME" "test.hostname"
    TEST_EQ "DELETED_LEASES6_AT0_HWADDR" "00:01:02:03"
    TEST_EQ "DELETED_LEASES6_AT0_HWADDR_TYPE" "1"
    TEST_EQ "DELETED_LEASES6_AT0_STATE" "default"
    TEST_EQ "DELETED_LEASES6_AT0_SUBNET_ID" "5"
    TEST_EQ "DELETED_LEASES6_AT0_VALID_LIFETIME" "4"
    TEST_EQ "DELETED_LEASES6_AT0_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "DELETED_LEASES6_AT0_IAID" "2"
    TEST_EQ "DELETED_LEASES6_AT0_PREFERRED_LIFETIME" "3"
    TEST_EQ "DELETED_LEASES6_AT0_PREFIX_LEN" "128"
    TEST_EQ "DELETED_LEASES6_AT0_TYPE" "IA_NA"
    TEST_EQ "DELETED_LEASES6_AT1_ADDRESS" ""
    TEST_EQ "DELETED_LEASES6_AT1_CLTT" ""
    TEST_EQ "DELETED_LEASES6_AT1_HOSTNAME" ""
    TEST_EQ "DELETED_LEASES6_AT1_HWADDR" ""
    TEST_EQ "DELETED_LEASES6_AT1_HWADDR_TYPE" ""
    TEST_EQ "DELETED_LEASES6_AT1_STATE" ""
    TEST_EQ "DELETED_LEASES6_AT1_SUBNET_ID" ""
    TEST_EQ "DELETED_LEASES6_AT1_VALID_LIFETIME" ""
    TEST_EQ "DELETED_LEASES6_AT1_DUID" ""
    TEST_EQ "DELETED_LEASES6_AT1_IAID" ""
    TEST_EQ "DELETED_LEASES6_AT1_PREFERRED_LIFETIME" ""
    TEST_EQ "DELETED_LEASES6_AT1_PREFIX_LEN" ""
    TEST_EQ "DELETED_LEASES6_AT1_TYPE" ""
    ECHO_TO_FILE "SUCCESS"
}

lease6_release () {
    TEST_EQ "QUERY6_TYPE" "UNKNOWN"
    TEST_EQ "QUERY6_TXID" "0"
    TEST_EQ "QUERY6_LOCAL_ADDR" "ff02::1:2"
    TEST_EQ "QUERY6_LOCAL_PORT" "0"
    TEST_EQ "QUERY6_REMOTE_ADDR" "fe80::21e:8cff:fe9b:7349"
    TEST_EQ "QUERY6_REMOTE_PORT" "546"
    TEST_EQ "QUERY6_IFACE_INDEX" "2"
    TEST_EQ "QUERY6_IFACE_NAME" "eth1"
    TEST_EQ "QUERY6_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY6_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY6_PROTO" "UDP"
    TEST_EQ "QUERY6_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASE6_CLTT" "7"
    TEST_EQ "LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "LEASE6_STATE" "default"
    TEST_EQ "LEASE6_SUBNET_ID" "5"
    TEST_EQ "LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_IAID" "2"
    TEST_EQ "LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASE6_PREFIX_LEN" "128"
    TEST_EQ "LEASE6_TYPE" "IA_NA"
    ECHO_TO_FILE "SUCCESS"
}

lease6_decline () {
    TEST_EQ "QUERY6_TYPE" "UNKNOWN"
    TEST_EQ "QUERY6_TXID" "0"
    TEST_EQ "QUERY6_LOCAL_ADDR" "ff02::1:2"
    TEST_EQ "QUERY6_LOCAL_PORT" "0"
    TEST_EQ "QUERY6_REMOTE_ADDR" "fe80::21e:8cff:fe9b:7349"
    TEST_EQ "QUERY6_REMOTE_PORT" "546"
    TEST_EQ "QUERY6_IFACE_INDEX" "2"
    TEST_EQ "QUERY6_IFACE_NAME" "eth1"
    TEST_EQ "QUERY6_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY6_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY6_PROTO" "UDP"
    TEST_EQ "QUERY6_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "LEASE6_CLTT" "7"
    TEST_EQ "LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "LEASE6_STATE" "default"
    TEST_EQ "LEASE6_SUBNET_ID" "5"
    TEST_EQ "LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "LEASE6_IAID" "2"
    TEST_EQ "LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "LEASE6_PREFIX_LEN" "128"
    TEST_EQ "LEASE6_TYPE" "IA_NA"
    ECHO_TO_FILE "SUCCESS"
}

addr6_register() {
    TEST_EQ "QUERY6_TYPE" "UNKNOWN"
    TEST_EQ "QUERY6_TXID" "0"
    TEST_EQ "QUERY6_LOCAL_ADDR" "ff02::1:2"
    TEST_EQ "QUERY6_LOCAL_PORT" "0"
    TEST_EQ "QUERY6_REMOTE_ADDR" "fe80::21e:8cff:fe9b:7349"
    TEST_EQ "QUERY6_REMOTE_PORT" "546"
    TEST_EQ "QUERY6_IFACE_INDEX" "2"
    TEST_EQ "QUERY6_IFACE_NAME" "eth1"
    TEST_EQ "QUERY6_REMOTE_HWADDR" "00:01:02:03"
    TEST_EQ "QUERY6_REMOTE_HWADDR_TYPE" "1"
    TEST_EQ "QUERY6_PROTO" "UDP"
    TEST_EQ "QUERY6_CLIENT_ID" "00:01:02:03:04:05:06"
    TEST_EQ "ADDRESS6" "2003:db8::1"
    TEST_EQ "NEW_LEASE6_ADDRESS" "2003:db8::1"
    TEST_EQ "NEW_LEASE6_CLTT" "7"
    TEST_EQ "NEW_LEASE6_HOSTNAME" "test.hostname"
    TEST_EQ "NEW_LEASE6_HWADDR" "00:01:02:03"
    TEST_EQ "NEW_LEASE6_HWADDR_TYPE" "1"
    TEST_EQ "NEW_LEASE6_STATE" "default"
    TEST_EQ "NEW_LEASE6_SUBNET_ID" "5"
    TEST_EQ "NEW_LEASE6_VALID_LIFETIME" "4"
    TEST_EQ "NEW_LEASE6_DUID" "00:01:02:03:04:05:06"
    TEST_EQ "NEW_LEASE6_IAID" "2"
    TEST_EQ "NEW_LEASE6_PREFERRED_LIFETIME" "3"
    TEST_EQ "NEW_LEASE6_PREFIX_LEN" "128"
    TEST_EQ "NEW_LEASE6_TYPE" "IA_NA"
    ECHO_TO_FILE "SUCCESS"
}

case "$1" in
    "lease4_renew")
        lease4_renew
        ;;
    "lease4_expire")
        lease4_expire
        ;;
    "lease4_recover")
        lease4_recover
        ;;
    "leases4_committed")
        leases4_committed
        ;;
    "lease4_release")
        lease4_release
        ;;
    "lease4_decline")
        lease4_decline
        ;;
    "lease6_renew")
        lease6_renew
        ;;
    "lease6_rebind")
        lease6_rebind
        ;;
    "lease6_expire")
        lease6_expire
        ;;
    "lease6_recover")
        lease6_recover
        ;;
    "leases6_committed")
        leases6_committed
        ;;
    "lease6_release")
        lease6_release
        ;;
    "lease6_decline")
        lease6_decline
        ;;
    "addr6_register")
        addr6_register
        ;;
    *)
        unknown_handle "${@}"
        ;;
esac
