test_finish 0
}
+# Handy shortcut for running a single test.
+if [ $# -gt 0 ]; then
+ echo "RUNNING ${1} only"
+ ${1}
+ exit $?
+fi
+
# Run tests.
mysql_db_init_test
mysql_host_reservation_init_test
run_command \
pgsql_execute "${qry}"
assert_eq 3 "${EXIT_CODE}" "select isJsonSupported() should have failed. (expected status code %d, returned %d)"
+
+ # Makse sure all four SFLQ tables exist.
+ check_table_column start_address flq_pool4
+ check_table_column address free_lease4
+ check_table_column start_address flq_pool6
+ check_table_column address free_lease4
+
+# # Verify incrementV6Prefix.
+# qry="select inet6_ntoa(incrementV6Prefix(inet6_aton('1020:3040:5060:70FF:90A0:B0C0:0DE0:F000'), 64))"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select incrementV6Prefix failed. (expected status code %d, returned %d)"
+# count=$(echo "${OUTPUT}" | grep -Fci "1020:3040:5060:7100:90a0:b0c0:de0:f000")
+# assert_eq 1 "${count}" "incrementV6Prefix output is wrong. (expected count %d, actual %d)"
+#
+# # Verify createShareFlqPool4.
+# qry="call createShareFlqPool4(inet_aton('127.0.0.0'), inet_aton('127.0.0.1'), 0, 0)"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "call createShareFlqPool4 failed. (expected status code %d, returned %d)"
+#
+# qry="select count(start_address) from flq_pool4 where start_address = inet_aton('127.0.0.0')\
+# and end_address = inet_aton('127.0.0.1')"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select from flq_pool4 failed. (expected status code %d, returned %d)"
+# count="${OUTPUT}"
+# assert_eq 1 "${count}" "flq_pool4 content wrong. (expected count %d, actual %d)"
+#
+# qry="select count(address) from free_lease4 join flq_pool4 where\
+# address >= flq_pool4.start_address and address <= flq_pool4.end_address"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select from free_lease4 failed. (expected status code %d, returned %d)"
+# count="${OUTPUT}"
+# assert_eq 2 "${count}" "free_lease4 content wrong. (expected count %d, actual %d)"
+#
+# # Verify pickFreeLease4.
+# qry="select inet_ntoa(pickFreeLease4(inet_aton('127.0.0.0'),inet_aton('127.0.0.1')))"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select from pickFreeLease4 failed. (expected status code %d, returned %d)"
+# assert_str_eq '127.0.0.0' "${OUTPUT}"
+#
+# # Verify createShareFlqPool6.
+# qry="call createShareFlqPool6('3001::', '3001::1', 2, 1, 128, 0)"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "call createShareFlqPool6 failed. (expected status code %d, returned %d)"
+#
+# qry="select count(start_address) from flq_pool6 where start_address = '3001::'\
+# and end_address = '3001::1'"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select from flq_pool6 failed. (expected status code %d, returned %d)"
+# count="${OUTPUT}"
+# assert_eq 1 "${count}" "flq_pool6 content wrong. (expected count %d, actual %d)"
+#
+# qry="select count(address) from free_lease6 join flq_pool6 where\
+# address >= flq_pool6.start_address and address <= flq_pool6.end_address"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select from free_lease6 failed. (expected status code %d, returned %d)"
+# count="${OUTPUT}"
+#
+# # Verify pickFreeLease6.
+# qry="select pickFreeLease6('3001::', '3001::1')"
+# run_command \
+# pgsql_execute "${qry}"
+# assert_eq 0 "${EXIT_CODE}" "select from pickFreeLease6 failed. (expected status code %d, returned %d)"
+# assert_str_eq '3001::' "${OUTPUT}"
}
pgsql_upgrade_test() {
test_finish 0
}
+# Handy shortcut for running a single test.
+if [ $# -gt 0 ]; then
+ echo "RUNNING ${1} only"
+ ${1}
+ exit $?
+fi
+
# Run tests.
pgsql_db_init_test
pgsql_db_version_test
END;
$lease6_ADEL$ LANGUAGE plpgsql;
+-- Create the SFLQ tables.
+
+DROP TABLE IF EXISTS flq_pool4;
+CREATE TABLE IF NOT EXISTS flq_pool4 (
+ id SERIAL PRIMARY KEY NOT NULL,
+ start_address INET NOT NULL,
+ end_address INET NOT NULL,
+ last_returned_address INET NOT NULL DEFAULT '0.0.0.0',
+ subnet_id BIGINT NOT NULL,
+ created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool4_start_end_address ON flq_pool4 (start_address, end_address);
+CREATE INDEX flq_pool4_by_subnet_id ON flq_pool4 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease4;
+CREATE TABLE IF NOT EXISTS free_lease4 (
+ address INET PRIMARY KEY NOT NULL,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+DROP TABLE IF EXISTS flq_pool6;
+CREATE TABLE IF NOT EXISTS flq_pool6 (
+ id SERIAL PRIMARY KEY NOT NULL,
+ start_address INET NOT NULL,
+ end_address INET NOT NULL,
+ lease_type SMALLINT NOT NULL,
+ delegated_len SMALLINT NOT NULL,
+ last_returned_address INET NOT NULL DEFAULT ('::'),
+ subnet_id BIGINT NOT NULL,
+ created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool6_start_end_address ON flq_pool6 (start_address, end_address);
+CREATE INDEX flq_pool6_by_subnet_id ON flq_pool6 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease6;
+CREATE TABLE IF NOT EXISTS free_lease6 (
+ lease_type SMALLINT NOT NULL,
+ address INET NOT NULL,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (address, lease_type)
+);
+
-- Update the schema version number.
UPDATE schema_version
SET version = '33', minor = '0';
-- v6 BLQ cross-tables
DROP TABLE IF EXISTS lease6_relay_id;
DROP TABLE IF EXISTS lease6_remote_id;
+
+-- Drop SFLQ tables and procedures
+DROP PROCEDURE IF EXISTS createShareFlqPool4;
+DROP PROCEDURE IF EXISTS createShareFlqPool6;
+DROP TABLE IF EXISTS free_lease4;
+DROP TABLE IF EXISTS flq_pool4;
+DROP TABLE IF EXISTS free_lease6;
+DROP TABLE IF EXISTS flq_pool6;
END;
\$lease6_ADEL\$ LANGUAGE plpgsql;
+-- Create the SFLQ tables.
+
+DROP TABLE IF EXISTS flq_pool4;
+CREATE TABLE IF NOT EXISTS flq_pool4 (
+ id SERIAL PRIMARY KEY NOT NULL,
+ start_address INET NOT NULL,
+ end_address INET NOT NULL,
+ last_returned_address INET NOT NULL DEFAULT '0.0.0.0',
+ subnet_id BIGINT NOT NULL,
+ created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool4_start_end_address ON flq_pool4 (start_address, end_address);
+CREATE INDEX flq_pool4_by_subnet_id ON flq_pool4 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease4;
+CREATE TABLE IF NOT EXISTS free_lease4 (
+ address INET PRIMARY KEY NOT NULL,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+DROP TABLE IF EXISTS flq_pool6;
+CREATE TABLE IF NOT EXISTS flq_pool6 (
+ id SERIAL PRIMARY KEY NOT NULL,
+ start_address INET NOT NULL,
+ end_address INET NOT NULL,
+ lease_type SMALLINT NOT NULL,
+ delegated_len SMALLINT NOT NULL,
+ last_returned_address INET NOT NULL DEFAULT ('::'),
+ subnet_id BIGINT NOT NULL,
+ created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool6_start_end_address ON flq_pool6 (start_address, end_address);
+CREATE INDEX flq_pool6_by_subnet_id ON flq_pool6 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease6;
+CREATE TABLE IF NOT EXISTS free_lease6 (
+ lease_type SMALLINT NOT NULL,
+ address INET NOT NULL,
+ modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (address, lease_type)
+);
+
-- Update the schema version number.
UPDATE schema_version
SET version = '33', minor = '0';