OptionPtr
Dhcpv4Srv::getNetmaskOption(const Subnet4Ptr& subnet) {
- uint32_t netmask = getNetmask4(subnet->get().second);
+ uint32_t netmask = getNetmask4(subnet->get().second).toUint32();
OptionPtr opt(new OptionInt<uint32_t>(Option::V4,
DHO_SUBNET_MASK, netmask));
-// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2016 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
// Modify the client's address to force it to decline a different address
// than it has obtained from the server.
- client.config_.lease_.addr_ = IOAddress(static_cast<uint32_t>(leased_address) + 1);
+ client.config_.lease_.addr_ = IOAddress(leased_address.toUint32() + 1);
// Send DHCPDECLINE and make sure it was unsuccessful, i.e. the lease
// remains in the database.
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 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
// Modify the client's address to force it to release a different address
// than it has obtained from the server.
- client.config_.lease_.addr_ = IOAddress(static_cast<uint32_t>(leased_address) + 1);
+ client.config_.lease_.addr_ = IOAddress(leased_address.toUint32() + 1);
// Send DHCPRELEASE and make sure it was unsuccessful, i.e. the lease
// remains in the database.
OptionPtr opt_requested_address =
OptionPtr(new Option(Option::V4, DHO_DHCP_REQUESTED_ADDRESS,
OptionBuffer()));
- opt_requested_address->setUint32(static_cast<uint32_t>(yiaddr));
+ opt_requested_address->setUint32(yiaddr.toUint32());
pkt4->addOption(opt_requested_address);
OptionPtr opt_parameter_list =
Option::factory(Option::V4, DHO_DHCP_PARAMETER_REQUEST_LIST);
DHO_DHCP_REQUESTED_ADDRESS,
OptionBuffer(),
rip_offset));
- // The IOAddress is castable to uint32_t and returns exactly what we need.
- opt_requested_ip->setUint32(static_cast<uint32_t>(yiaddr));
+ // The IOAddress is convertible to uint32_t and returns exactly what we need.
+ opt_requested_ip->setUint32(yiaddr.toUint32());
pkt4->addOption(opt_requested_ip);
setDefaults4(socket, boost::static_pointer_cast<Pkt4>(pkt4));
return (asio_address_.to_v6().is_multicast());
}
-IOAddress::operator uint32_t() const {
+uint32_t
+IOAddress::toUint32() const {
if (asio_address_.is_v4()) {
return (asio_address_.to_v4().to_ulong());
} else {
isc_throw(BadValue, "Both addresses have to be the same family");
}
if (a.isV4()) {
- // Subtracting v4 is easy. We have uint32_t operator.
- return (IOAddress(static_cast<uint32_t>(a) - static_cast<uint32_t>(b)));
+ // Subtracting v4 is easy. We have a conversion function to uint32_t.
+ return (IOAddress(a.toUint32() - b.toUint32()));
} else {
// v6 is more involved.
-// Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2016 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
///
/// \return uint32_t that represents IPv4 address in
/// network byte order
- operator uint32_t () const;
+ uint32_t toUint32() const;
/// @name Methods returning @c IOAddress objects encapsulating typical addresses.
///
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2016 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
IOAddress addr1("192.0.2.5");
// operator uint_32() is used here
- uint32_t tmp = addr1;
+ uint32_t tmp = addr1.toUint32();
uint32_t expected = (192U << 24) + (0U << 16) + (2U << 8) + 5U;
AddressContainer::const_iterator addr = addrs_.begin();
while (addr != addrs_.end()) {
- buf.writeUint32(*addr);
+ buf.writeUint32(addr->toUint32());
++addr;
}
}
buffer_out_.writeUint32(transid_);
buffer_out_.writeUint16(secs_);
buffer_out_.writeUint16(flags_);
- buffer_out_.writeUint32(ciaddr_);
- buffer_out_.writeUint32(yiaddr_);
- buffer_out_.writeUint32(siaddr_);
- buffer_out_.writeUint32(giaddr_);
+ buffer_out_.writeUint32(ciaddr_.toUint32());
+ buffer_out_.writeUint32(yiaddr_.toUint32());
+ buffer_out_.writeUint32(siaddr_.toUint32());
+ buffer_out_.writeUint32(giaddr_.toUint32());
if ((hw_len > 0) && (hw_len <= MAX_CHADDR_LEN)) {
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 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
struct sockaddr_in addr4;
memset(&addr4, 0, sizeof(addr4));
addr4.sin_family = AF_INET;
- addr4.sin_addr.s_addr = htonl(addr);
+ addr4.sin_addr.s_addr = htonl(addr.toUint32());
addr4.sin_port = htons(port);
if (bind(sock, reinterpret_cast<struct sockaddr*>(&addr4),
// Configure the BPF program to receive unicast packets sent to the
// specified address. The program will also allow packets sent to the
// 255.255.255.255 broadcast address.
- prog.bf_insns[8].k = static_cast<uint32_t>(addr);
+ prog.bf_insns[8].k = addr.toUint32();
// Configure the BPF program to receive packets on the specified port.
prog.bf_insns[11].k = port;
if (receive_bcast && iface.flag_broadcast_) {
addr4.sin_addr.s_addr = INADDR_ANY;
} else {
- addr4.sin_addr.s_addr = htonl(addr);
+ addr4.sin_addr.s_addr = htonl(addr.toUint32());
}
int sock = socket(AF_INET, SOCK_DGRAM, 0);
memset(&to, 0, sizeof(to));
to.sin_family = AF_INET;
to.sin_port = htons(pkt->getRemotePort());
- to.sin_addr.s_addr = htonl(pkt->getRemoteAddr());
+ to.sin_addr.s_addr = htonl(pkt->getRemoteAddr().toUint32());
struct msghdr m;
// Initialize our message header structure.
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 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
out_buf.writeUint8(128); // TTL
out_buf.writeUint8(IPPROTO_UDP); // Protocol UDP.
out_buf.writeUint16(0); // Temporarily set checksum to 0.
- out_buf.writeUint32(pkt->getLocalAddr()); // Source address.
- out_buf.writeUint32(pkt->getRemoteAddr()); // Destination address.
+ out_buf.writeUint32(pkt->getLocalAddr().toUint32()); // Source address.
+ out_buf.writeUint32(pkt->getRemoteAddr().toUint32()); // Destination address.
// Calculate pseudo header checksum. It will be necessary to compute
// UDP checksum.
memset(&dest_addr4, 0, sizeof(sockaddr));
dest_addr4.sin_family = AF_INET;
dest_addr4.sin_port = htons(port_);
- dest_addr4.sin_addr.s_addr = htonl(dest);
+ dest_addr4.sin_addr.s_addr = htonl(dest.toUint32());
ASSERT_EQ(sendto(send_msg_sock_, test_message_->getBuffer().getData(),
test_message_->getBuffer().getLength(), 0,
reinterpret_cast<struct sockaddr*>(&dest_addr4),
-// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2016 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
// We don't check that it is a valid IPv4 address and thus has
// a required length of 4 bytes because it has been already
// checked by the calling function.
- uint32_t addr = prefix;
+ uint32_t addr = prefix.toUint32();
return (IOAddress(addr & (~bitMask4[len])));
}
isc_throw(isc::BadValue, "Too large netmask. 0..32 is allowed in IPv4");
}
- uint32_t addr = prefix;
+ uint32_t addr = prefix.toUint32();
return (IOAddress(addr | bitMask4[len]));
}
// Let's explicitly cast last_ and first_ (IOAddress). This conversion is
// automatic, but let's explicitly cast it show that we moved to integer
// domain and addresses are now substractable.
- uint64_t max_numeric = static_cast<uint32_t>(max);
- uint64_t min_numeric = static_cast<uint32_t>(min);
+ uint64_t max_numeric = static_cast<uint64_t>(max.toUint32());
+ uint64_t min_numeric = static_cast<uint64_t>(min.toUint32());
// We can simply subtract the values. We need to increase the result
// by one, as both min and max are included in the range. So even if
virtual ConstHostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const = 0;
+ /// @brief Returns a host connected to the IPv6 subnet and having
+ /// a reservation for a specified IPv6 address or prefix.
+ ///
+ /// @param subnet_id Subnet identifier.
+ /// @param address reserved IPv6 address/prefix.
+ ///
+ /// @return Const @c Host object using a specified IPv6 address/prefix.
+ virtual ConstHostPtr
+ get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const = 0;
+
/// @brief Adds a new host to the collection.
///
/// The implementations of this method should guard against duplicate
// ipv4_address : INT UNSIGNED NULL
// The address in the Host structure is an IOAddress object. Convert
// this to an integer for storage.
- ipv4_address_ = static_cast<uint32_t>(host->getIPv4Reservation());
+ ipv4_address_ = host->getIPv4Reservation().toUint32();
bind_[5].buffer_type = MYSQL_TYPE_LONG;
bind_[5].buffer = reinterpret_cast<char*>(&ipv4_address_);
bind_[5].is_unsigned = MLM_TRUE;
// ipv4_address : INT UNSIGNED NULL
// The address in the Host structure is an IOAddress object. Convert
// this to an integer for storage.
- dhcp4_next_server_ = static_cast<uint32_t>(host->getNextServer());
+ dhcp4_next_server_ = host->getNextServer().toUint32();
bind_[9].buffer_type = MYSQL_TYPE_LONG;
bind_[9].buffer = reinterpret_cast<char*>(&dhcp4_next_server_);
bind_[9].is_unsigned = MLM_TRUE;
GET_HOST_SUBID6_DHCPID, // Gets host by IPv6 SubnetID, HW address/DUID
GET_HOST_SUBID_ADDR, // Gets host by IPv4 SubnetID and IPv4 address
GET_HOST_PREFIX, // Gets host by IPv6 prefix
+ GET_HOST_SUBID6_ADDR, // Gets host by IPv6 SubnetID and IPv6 prefix
GET_VERSION, // Obtain version number
INSERT_HOST, // Insert new host to collection
INSERT_V6_RESRV, // Insert v6 reservation
"WHERE address = ? AND prefix_len = ?) "
"ORDER BY h.host_id, o.option_id, r.reservation_id"},
+ // Retrieves host information, IPv6 reservations and DHCPv6 options
+ // associated with a host using subnet id and prefix. This query
+ // returns host information for a single host. However, multiple rows
+ // are returned due to left joining IPv6 reservations and DHCPv6 options.
+ // The number of rows returned is multiplication of number of existing
+ // IPv6 reservations and DHCPv6 options.
+ {MySqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR,
+ "SELECT h.host_id, h.dhcp_identifier, "
+ "h.dhcp_identifier_type, h.dhcp4_subnet_id, "
+ "h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
+ "h.dhcp4_client_classes, h.dhcp6_client_classes, "
+ "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+ "o.option_id, o.code, o.value, o.formatted_value, o.space, "
+ "o.persistent, "
+ "r.reservation_id, r.address, r.prefix_len, r.type, "
+ "r.dhcp6_iaid "
+ "FROM hosts AS h "
+ "LEFT JOIN dhcp6_options AS o "
+ "ON h.host_id = o.host_id "
+ "LEFT JOIN ipv6_reservations AS r "
+ "ON h.host_id = r.host_id "
+ "WHERE h.dhcp6_subnet_id = ? AND r.address = ? "
+ "ORDER BY h.host_id, o.option_id, r.reservation_id"},
+
// Retrieves MySQL schema version.
{MySqlHostDataSourceImpl::GET_VERSION,
"SELECT version, minor FROM schema_version"},
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
- uint32_t addr4 = static_cast<uint32_t>(address);
+ uint32_t addr4 = address.toUint32();
inbind[0].buffer_type = MYSQL_TYPE_LONG;
inbind[0].buffer = reinterpret_cast<char*>(&addr4);
inbind[0].is_unsigned = MLM_TRUE;
inbind[0].buffer = reinterpret_cast<char*>(&subnet);
inbind[0].is_unsigned = MLM_TRUE;
- uint32_t addr4 = static_cast<uint32_t>(address);
+ uint32_t addr4 = address.toUint32();
inbind[1].buffer_type = MYSQL_TYPE_LONG;
inbind[1].buffer = reinterpret_cast<char*>(&addr4);
inbind[1].is_unsigned = MLM_TRUE;
return (result);
}
+ConstHostPtr
+MySqlHostDataSource::get6(const SubnetID& subnet_id,
+ const asiolink::IOAddress& address) const {
+ // Set up the WHERE clause value
+ MYSQL_BIND inbind[2];
+ memset(inbind, 0, sizeof(inbind));
+
+ uint32_t subnet_buffer = static_cast<uint32_t>(subnet_id);
+ inbind[0].buffer_type = MYSQL_TYPE_LONG;
+ inbind[0].buffer = reinterpret_cast<char*>(&subnet_buffer);
+ inbind[0].is_unsigned = MLM_TRUE;
+
+ std::string addr6 = address.toText();
+ unsigned long addr6_length = addr6.size();
+
+ inbind[1].buffer_type = MYSQL_TYPE_BLOB;
+ inbind[1].buffer = reinterpret_cast<char*>
+ (const_cast<char*>(addr6.c_str()));
+ inbind[1].length = &addr6_length;
+ inbind[1].buffer_length = addr6_length;
+
+ ConstHostCollection collection;
+ impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR,
+ inbind, impl_->host_ipv6_exchange_,
+ collection, true);
+
+ // Return single record if present, else clear the host.
+ ConstHostPtr result;
+ if (!collection.empty()) {
+ result = *collection.begin();
+ }
+
+ return (result);
+}
+
+
// Miscellaneous database methods.
std::string MySqlHostDataSource::getName() const {
virtual ConstHostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
+ /// @brief Returns a host connected to the IPv6 subnet and having
+ /// a reservation for a specified IPv6 address or prefix.
+ ///
+ /// @param subnet_id Subnet identifier.
+ /// @param address reserved IPv6 address/prefix.
+ ///
+ /// @return Const @c Host object using a specified IPv6 address/prefix.
+ virtual ConstHostPtr
+ get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
+
/// @brief Adds a new host to the collection.
///
/// The implementations of this method should guard against duplicate
// Address: uint32_t
// The address in the Lease structure is an IOAddress object. Convert
// this to an integer for storage.
- addr4_ = static_cast<uint32_t>(lease_->addr_);
+ addr4_ = lease_->addr_.toUint32();
bind_[0].buffer_type = MYSQL_TYPE_LONG;
bind_[0].buffer = reinterpret_cast<char*>(&addr4_);
bind_[0].is_unsigned = MLM_TRUE;
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
- uint32_t addr4 = static_cast<uint32_t>(addr);
+ uint32_t addr4 = addr.toUint32();
inbind[0].buffer_type = MYSQL_TYPE_LONG;
inbind[0].buffer = reinterpret_cast<char*>(&addr4);
inbind[0].is_unsigned = MLM_TRUE;
MYSQL_BIND where;
memset(&where, 0, sizeof(where));
- uint32_t addr4 = static_cast<uint32_t>(lease->addr_);
+ uint32_t addr4 = lease->addr_.toUint32();
where.buffer_type = MYSQL_TYPE_LONG;
where.buffer = reinterpret_cast<char*>(&addr4);
where.is_unsigned = MLM_TRUE;
memset(inbind, 0, sizeof(inbind));
if (addr.isV4()) {
- uint32_t addr4 = static_cast<uint32_t>(addr);
+ uint32_t addr4 = addr.toUint32();
inbind[0].buffer_type = MYSQL_TYPE_LONG;
inbind[0].buffer = reinterpret_cast<char*>(&addr4);
void PsqlBindArray::add(const isc::asiolink::IOAddress& addr) {
if (addr.isV4()) {
addTempString(boost::lexical_cast<std::string>
- (static_cast<uint32_t>(addr)));
+ (addr.toUint32()));
} else {
addTempString(addr.toText());
}
GET_HOST_SUBID6_DHCPID, // Gets host by IPv6 SubnetID, HW address/DUID
GET_HOST_SUBID_ADDR, // Gets host by IPv4 SubnetID and IPv4 address
GET_HOST_PREFIX, // Gets host by IPv6 prefix
+ GET_HOST_SUBID6_ADDR, // Gets host by IPv6 SubnetID and IPv6 prefix
GET_VERSION, // Obtain version number
INSERT_HOST, // Insert new host to collection
INSERT_V6_RESRV, // Insert v6 reservation
"ORDER BY h.host_id, o.option_id, r.reservation_id"
},
+ // PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR
+ // Retrieves host information, IPv6 reservations and DHCPv6 options
+ // associated with a host using IPv6 subnet id and prefix. This query
+ // returns host information for a single host. However, multiple rows
+ // are returned due to left joining IPv6 reservations and DHCPv6 options.
+ // The number of rows returned is multiplication of number of existing
+ // IPv6 reservations and DHCPv6 options.
+ {2,
+ { OID_INT4, OID_VARCHAR },
+ "get_host_subid6_addr",
+ "SELECT h.host_id, h.dhcp_identifier, "
+ " h.dhcp_identifier_type, h.dhcp4_subnet_id, "
+ " h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
+ " h.dhcp4_client_classes, h.dhcp6_client_classes, "
+ " h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+ " o.option_id, o.code, o.value, o.formatted_value, o.space, "
+ " o.persistent, "
+ " r.reservation_id, r.address, r.prefix_len, r.type, "
+ " r.dhcp6_iaid "
+ "FROM hosts AS h "
+ "LEFT JOIN dhcp6_options AS o ON h.host_id = o.host_id "
+ "LEFT JOIN ipv6_reservations AS r ON h.host_id = r.host_id "
+ "WHERE h.dhcp6_subnet_id = $1 AND r.address = $2 "
+ "ORDER BY h.host_id, o.option_id, r.reservation_id"
+ },
+
// PgSqlHostDataSourceImpl::GET_VERSION
// Retrieves MySQL schema version.
{0,
return (result);
}
+ConstHostPtr
+PgSqlHostDataSource::get6(const SubnetID& subnet_id,
+ const asiolink::IOAddress& address) const {
+ /// @todo: Check that prefix is v6 address, not v4.
+
+ // Set up the WHERE clause value
+ PsqlBindArrayPtr bind_array(new PsqlBindArray());
+
+ // Add the subnet id
+ bind_array->add(subnet_id);
+
+ // Add the prefix
+ bind_array->add(address);
+
+ ConstHostCollection collection;
+ impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR,
+ bind_array, impl_->host_ipv6_exchange_,
+ collection, true);
+
+ // Return single record if present, else clear the host.
+ ConstHostPtr result;
+ if (!collection.empty()) {
+ result = *collection.begin();
+ }
+
+ return (result);
+}
+
// Miscellaneous database methods.
std::string PgSqlHostDataSource::getName() const {
virtual ConstHostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
+ /// @brief Returns a host connected to the IPv6 subnet and having
+ /// a reservation for a specified IPv6 address or prefix.
+ ///
+ /// @param subnet_id Subnet identifier.
+ /// @param address reserved IPv6 address/prefix.
+ ///
+ /// @return Const @c Host object using a specified IPv6 address/prefix.
+ virtual ConstHostPtr
+ get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
+
/// @brief Adds a new host to the collection.
///
/// The method will insert the given host and all of its children (v4
try {
addr_str_ = boost::lexical_cast<std::string>
- (static_cast<uint32_t>(lease->addr_));
+ (lease->addr_.toUint32());
bind_array.add(addr_str_);
if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
// LEASE ADDRESS
std::string addr_str = boost::lexical_cast<std::string>
- (static_cast<uint32_t>(addr));
+ (addr.toUint32());
bind_array.add(addr_str);
// Get the data
// Set up the WHERE clause and append it to the SQL_BIND array
std::string addr4_ = boost::lexical_cast<std::string>
- (static_cast<uint32_t>(lease->addr_));
+ (lease->addr_.toUint32());
bind_array.add(addr4_);
// Drop to common update code
if (addr.isV4()) {
std::string addr4_str = boost::lexical_cast<std::string>
- (static_cast<uint32_t>(addr));
+ (addr.toUint32());
bind_array.add(addr4_str);
return (deleteLeaseCommon(DELETE_LEASE4, bind_array) > 0);
}
EXPECT_FALSE(hdsptr_->get6(IOAddress("2001:db8::5"), len));
}
+void GenericHostDataSourceTest::testGetBySubnetIPv6() {
+ // Make sure we have a pointer to the host data source.
+ ASSERT_TRUE(hdsptr_);
+
+ // Let's create a couple of hosts...
+ HostPtr host1 = initializeHost6("2001:db8:1::", Host::IDENT_DUID, true);
+ HostPtr host2 = initializeHost6("2001:db8:2::", Host::IDENT_DUID, true);
+ HostPtr host3 = initializeHost6("2001:db8:3::", Host::IDENT_DUID, true);
+ HostPtr host4 = initializeHost6("2001:db8:4::", Host::IDENT_DUID, true);
+
+ // ... and add them to the data source.
+ ASSERT_NO_THROW(hdsptr_->add(host1));
+ ASSERT_NO_THROW(hdsptr_->add(host2));
+ ASSERT_NO_THROW(hdsptr_->add(host3));
+ ASSERT_NO_THROW(hdsptr_->add(host4));
+
+ // And then try to retrieve them back.
+ ConstHostPtr from_hds1 = hdsptr_->get6(host1->getIPv6SubnetID(),
+ IOAddress("2001:db8:1::"));
+ ConstHostPtr from_hds2 = hdsptr_->get6(host2->getIPv6SubnetID(),
+ IOAddress("2001:db8:2::"));
+ ConstHostPtr from_hds3 = hdsptr_->get6(host3->getIPv6SubnetID(),
+ IOAddress("2001:db8:3::"));
+ ConstHostPtr from_hds4 = hdsptr_->get6(host4->getIPv6SubnetID(),
+ IOAddress("2001:db8:4::"));
+
+ // Make sure we got something back.
+ ASSERT_TRUE(from_hds1);
+ ASSERT_TRUE(from_hds2);
+ ASSERT_TRUE(from_hds3);
+ ASSERT_TRUE(from_hds4);
+
+ // Then let's check that what we got seems correct.
+ compareHosts(host1, from_hds1);
+ compareHosts(host2, from_hds2);
+ compareHosts(host3, from_hds3);
+ compareHosts(host4, from_hds4);
+}
+
+
void GenericHostDataSourceTest::testAddDuplicate6WithSameDUID() {
// Make sure we have the pointer to the host data source.
ASSERT_TRUE(hdsptr_);
/// @param prefix true - reserve IPv6 prefix, false - reserve IPv6 address
void testGetByIPv6(Host::IdentifierType id, bool prefix);
+ /// @brief Test inserts several hosts with unique prefixes and checks
+ /// that the can be retrieved by subnet id and prefix value.
+ void testGetBySubnetIPv6();
+
+
/// @brief Test that hosts can be retrieved by hardware address.
///
/// Uses gtest macros to report failures.
current_time, SUBNET_ID, true, true,
"hostname.example.com.");
- EXPECT_EQ(ADDRESS[i], static_cast<uint32_t>(lease.addr_));
+ EXPECT_EQ(ADDRESS[i], lease.addr_.toUint32());
EXPECT_TRUE(util::equalValues(hwaddr_, lease.hwaddr_));
EXPECT_TRUE(util::equalValues(clientid_, lease.client_id_));
EXPECT_EQ(0, lease.t1_);
testGetByIPv6(Host::IDENT_HWADDR, true);
}
+// Test verifies that host with IPv6 prefix reservation can be retrieved
+// by subnet id and prefix value.
+TEST_F(MySqlHostDataSourceTest, get6SubnetPrefix) {
+ testGetBySubnetIPv6();
+}
+
// Test verifies if a host reservation can be added and later retrieved by
// hardware address.
TEST_F(MySqlHostDataSourceTest, get6ByHWaddr) {
testGetByIPv6(Host::IDENT_HWADDR, true);
}
+// Test verifies that host with IPv6 prefix reservation can be retrieved
+// by subnet id and prefix value.
+TEST_F(PgSqlHostDataSourceTest, get6SubnetPrefix) {
+ testGetBySubnetIPv6();
+}
+
// Test verifies if a host reservation can be added and later retrieved by
// hardware address.
TEST_F(PgSqlHostDataSourceTest, get6ByHWaddr) {
virtual HostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) = 0;
+ /// @brief Returns a host connected to the IPv6 subnet and having
+ /// a reservation for a specified IPv6 address or prefix.
+ ///
+ /// @param subnet_id Subnet identifier.
+ /// @param address reserved IPv6 address/prefix.
+ ///
+ /// @return @c Host object using a specified IPv6 address/prefix.
+ virtual HostPtr
+ get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) = 0;
};
}