last_def->setServerTag(out_bindings[10]->getString());
// Store created option definition.
- auto ret = option_defs.push_back(last_def);
- if (!ret.second) {
- // option_defs is a multi-index container so push_back()
- // can in theory fails. Now it has no unique indexes...
- isc_throw(Unexpected, "can't store the option definition");
- }
+ // (option_defs is a multi-index container with no unique
+ // indexes so push_back can't fail).
+ static_cast<void>(option_defs.push_back(last_def));
}
});
}
throw;
}
- auto ret = defs->push_back(definition);
- if (!ret.second) {
- // defs points to a multi index container with only not unique
- // indexes so this is for sanity only.
- isc_throw(isc::Unexpected, "can't store option definition");
- }
+ // option_defs is a multi-index container with no unique indexes
+ // so push_back can't fail).
+ static_cast<void>(defs->push_back(definition));
}
}
if (getSubnet<SubnetPtrType>(subnets, subnet->getID())) {
isc_throw(DuplicateSubnetID, "attempted to add subnet with a"
" duplicated subnet identifier " << subnet->getID());
+ } else if (getSubnet<SubnetPtrType>(subnets, subnet->toText())) {
+ isc_throw(DuplicateSubnetID, "attempted to add subnet with a"
+ " duplicated subnet pre3fix " << subnet->toText());
}
// Check if the subnet is already associated with some network.
return (SubnetPtrType());
}
+ /// @brief Returns a subnet belonging to this network for a given subnet
+ /// prefix.
+ ///
+ /// @param subnets Container holding subnets for this shared network.
+ /// @param subnet_prefix Prefix of a subnet being retrieved.
+ ///
+ /// @tparam SubnetPtrType Type of a pointer to a subnet, i.e. Subnet4Ptr
+ /// or @ref Subnet6Ptr.
+ /// @tparam SubnetCollectionType Type of a container holding subnets, i.e.
+ /// @ref Subnet4Collection or @ref Subnet6Collection.
+ ///
+ /// @return Pointer to the subnet or null if the subnet doesn't exist.
+ template<typename SubnetPtrType, typename SubnetCollectionType>
+ static SubnetPtrType getSubnet(const SubnetCollectionType& subnets,
+ const std::string& subnet_prefix) {
+ const auto& index = subnets.template get<SubnetPrefixIndexTag>();
+ auto subnet_it = index.find(subnet_prefix);
+ if (subnet_it != index.cend()) {
+ return (*subnet_it);
+ }
+
+ // Subnet not found.
+ return (SubnetPtrType());
+ }
+
/// @brief Retrieves next available subnet within shared network.
///
/// This method returns next available subnet within a shared network.
/// if such subnet doesn't exist within shared network.
Subnet4Ptr getSubnet(const SubnetID& subnet_id) const;
+ /// @brief Returns a subnet for a specified subnet prefix.
+ ///
+ /// @param subnet_prefix Subnet prefix.
+ ///
+ /// @return Shared pointer to a subnet using this prefix or null pointer
+ /// if such subnet doesn't exist within shared network.
+ Subnet4Ptr getSubnet(const std::string& subnet_prefix) const;
+
/// @brief Retrieves next available IPv4 subnet within shared network.
///
/// See documentation for @ref SharedNetwork4::getNextSubnet.
// same ID should cause an error.
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.0"), 24, 10, 20, 30,
SubnetID(15)));
- ASSERT_THROW(network->add(subnet), DuplicateSubnetID);
+ ASSERT_THROW(network->add(subnet2), DuplicateSubnetID);
+
+ // Create another subnet with the same prefix. Adding a network with the
+ // same prefix should cause an error.
+ subnet2.reset(new Subnet4(IOAddress("10.0.0.0"), 8, 10, 20, 30,
+ SubnetID(1234)));
+ ASSERT_THROW(network->add(subnet2), DuplicateSubnetID);
// Create another network and try to add a subnet to it. It should fail
// because the subnet is already associated with the first network.
// same ID should cause an error.
Subnet6Ptr subnet2(new Subnet6(IOAddress("3000::"), 16, 10, 20, 30, 40,
SubnetID(15)));
- ASSERT_THROW(network->add(subnet), DuplicateSubnetID);
+ ASSERT_THROW(network->add(subnet2), DuplicateSubnetID);
+
+ // Create another subnet with the same prefix. Adding a network with the
+ // same prefix should cause an error.
+ subnet2.reset(new Subnet6(IOAddress("2001:db8:1::"), 64, 10, 20, 30, 40,
+ SubnetID(1234)));
+ ASSERT_THROW(network->add(subnet2), DuplicateSubnetID);
// Create another network and try to add a subnet to it. It should fail
// because the subnet is already associated with the first network.