DROP INDEX key_dhcp6_identifier_subnet_id ON hosts;
CREATE UNIQUE INDEX key_dhcp6_identifier_subnet_id ON hosts (dhcp_identifier ASC , dhcp_identifier_type ASC , dhcp6_subnet_id ASC);
+# Create index to search for reservations using IP address and subnet id.
+# This unique index guarantees that there is only one occurence of the
+# particular IPv4 address for a given subnet.
+CREATE UNIQUE INDEX key_dhcp4_ipv4_address_subnet_id ON hosts (ipv4_address ASC , dhcp4_subnet_id ASC);
+
+# Create index to search for reservations using address/prefix and prefix
+# length.
+CREATE INDEX key_dhcp6_address_prefix_len ON ipv6_reservations (address ASC , prefix_len ASC);
+
# Create a table mapping host identifiers to their names. Values in this
# table are used as a foreign key in hosts table to guarantee that only
# identifiers present in host_identifier_type table are used in hosts
// Then try to add it again, it should throw an exception.
ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
+
+ // This time use a different host identifier and try again.
+ // This update should be rejected because of duplicated
+ // address.
+ ASSERT_NO_THROW(host->setIdentifier("01:02:03:04:05:06", "hw-address"));
+ ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
+
+ // Modify address to avoid its duplication and make sure
+ // we can now add the host.
+ ASSERT_NO_THROW(host->setIPv4Reservation(IOAddress("192.0.2.3")));
+ EXPECT_NO_THROW(hdsptr_->add(host));
}
void GenericHostDataSourceTest::testAddr6AndPrefix(){
"ON hosts "
"(dhcp_identifier ASC , dhcp_identifier_type ASC , dhcp6_subnet_id ASC)",
+ "CREATE UNIQUE INDEX key_dhcp4_ipv4_address_subnet_id "
+ "ON hosts "
+ "(ipv4_address ASC, dhcp4_subnet_id ASC)",
+
+ "CREATE INDEX key_dhcp6_address_prefix_len "
+ "ON ipv6_reservations (address ASC , prefix_len ASC)",
+
"CREATE TABLE IF NOT EXISTS host_identifier_type ("
"type TINYINT PRIMARY KEY NOT NULL,"
"name VARCHAR(32)"