namespace isc {
namespace dhcp {
+IPv6Resrv::IPv6Resrv(const asiolink::IOAddress& prefix,
+ const uint8_t prefix_len)
+ : prefix_(prefix), prefix_len_(prefix_len) {
+ if (!prefix.isV6() || prefix.isV6Multicast()) {
+ isc_throw(isc::BadValue, "invalid prefix '" << prefix
+ << " for new IPv6 reservation");
+ }
+}
+
bool
IPv6Resrv::operator==(const IPv6Resrv& other) const {
return (prefix_ == other.prefix_ &&
///
/// @param prefix Address or prefix to be reserved.
/// @param prefix_len Prefix length.
+ ///
+ /// @throw isc::BadValue if address is not IPv6 address or is a
+ /// multicast address.
IPv6Resrv(const asiolink::IOAddress& prefix,
- const uint8_t prefix_len = 128)
- : prefix_(prefix), prefix_len_(prefix_len) {
- }
+ const uint8_t prefix_len = 128);
/// @brief Returns prefix for the reservation.
const asiolink::IOAddress& getPrefix() const {
EXPECT_EQ(IPv6Resrv::TYPE_PD, resrv.getType());
}
+TEST(IPv6ResrvTest, constructorInvalidPrefix) {
+ EXPECT_THROW(IPv6Resrv(IOAddress("10.0.0.1"), 128), isc::BadValue);
+ EXPECT_THROW(IPv6Resrv(IOAddress("ff02:1::2"), 128), isc::BadValue);
+}
+
// This test verifies that it is possible to modify prefix and its
// length in an existing reservation.
TEST(IPv6ResrvTest, setPrefix) {