44 template<
typename SubnetPtrType,
typename SubnetCollectionType>
45 static void add(SubnetCollectionType& subnets,
const SubnetPtrType& subnet) {
49 " to a shared network");
53 if (getSubnet<SubnetPtrType>(subnets, subnet->getID())) {
55 " duplicated subnet identifier " << subnet->getID());
60 subnet->getSharedNetwork(network);
63 <<
" being added to a shared network" 64 " already belongs to a shared network");
68 subnets.push_back(subnet);
81 template<
typename SubnetPtrType,
typename SubnetCollectionType>
82 static SubnetPtrType del(SubnetCollectionType& subnets,
84 auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
85 auto subnet_it = index.find(subnet_id);
86 if (subnet_it == index.end()) {
88 <<
" from shared network. Subnet doesn't belong" 89 " to this shared network");
91 auto subnet = *subnet_it;
92 index.erase(subnet_it);
107 template<
typename SubnetPtrType,
typename SubnetCollectionType>
108 static SubnetPtrType getSubnet(
const SubnetCollectionType& subnets,
110 const auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
111 auto subnet_it = index.find(subnet_id);
112 if (subnet_it != index.cend()) {
117 return (SubnetPtrType());
159 template<
typename SubnetPtrType,
typename SubnetCollectionType>
160 static SubnetPtrType getNextSubnet(
const SubnetCollectionType& subnets,
161 const SubnetPtrType& first_subnet,
165 if (subnets.empty()) {
166 return (SubnetPtrType());
172 const auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
173 auto subnet_id_it = index.find(current_subnet);
174 if (subnet_id_it == index.cend()) {
176 <<
" within shared network");
181 auto subnet_it = subnets.template project<SubnetRandomAccessIndexTag>(subnet_id_it);
184 if (++subnet_it == subnets.cend()) {
187 subnet_it = subnets.cbegin();
192 if ((*subnet_it)->getID() == first_subnet->getID()) {
193 return (SubnetPtrType());
224 template<
typename SubnetPtrType,
typename SubnetCollectionType>
225 static SubnetPtrType getPreferredSubnet(
const SubnetCollectionType& subnets,
226 const SubnetPtrType& selected_subnet,
229 auto preferred_subnet = selected_subnet;
230 for (
auto s = subnets.begin(); s != subnets.end(); ++s) {
231 if (((*s)->getClientClass() == selected_subnet->getClientClass()) &&
232 ((*s)->getLastAllocatedTime(lease_type) >
233 selected_subnet->getLastAllocatedTime(lease_type))) {
234 preferred_subnet = (*s);
238 return (preferred_subnet);
248 SharedNetwork4::sharedFromThis() {
249 return (shared_from_this());
254 Impl::add(subnets_, subnet);
256 setSharedNetwork(subnet);
261 Subnet4Ptr subnet = Impl::del<Subnet4Ptr>(subnets_, subnet_id);
262 clearSharedNetwork(subnet);
266 SharedNetwork4::delAll() {
267 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
268 clearSharedNetwork(*subnet);
274 SharedNetwork4::getSubnet(
const SubnetID& subnet_id)
const {
275 return (Impl::getSubnet<Subnet4Ptr>(subnets_, subnet_id));
279 SharedNetwork4::getNextSubnet(
const Subnet4Ptr& first_subnet,
280 const SubnetID& current_subnet)
const {
281 return (Impl::getNextSubnet(subnets_, first_subnet, current_subnet));
285 SharedNetwork4::getPreferredSubnet(
const Subnet4Ptr& selected_subnet)
const {
286 return (Impl::getPreferredSubnet<Subnet4Ptr>(subnets_, selected_subnet,
291 SharedNetwork4::toElement()
const {
295 if (!
name_.empty()) {
300 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
301 subnet4->add((*subnet)->toElement());
304 map->set(
"subnet4", subnet4);
310 SharedNetwork6::sharedFromThis() {
311 return (shared_from_this());
316 Impl::add(subnets_, subnet);
318 setSharedNetwork(subnet);
323 Subnet6Ptr subnet = Impl::del<Subnet6Ptr>(subnets_, subnet_id);
324 clearSharedNetwork(subnet);
328 SharedNetwork6::delAll() {
329 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
330 clearSharedNetwork(*subnet);
335 SharedNetwork6::getSubnet(
const SubnetID& subnet_id)
const {
336 return (Impl::getSubnet<Subnet6Ptr>(subnets_, subnet_id));
340 SharedNetwork6::getNextSubnet(
const Subnet6Ptr& first_subnet,
341 const SubnetID& current_subnet)
const {
342 return (Impl::getNextSubnet(subnets_, first_subnet, current_subnet));
346 SharedNetwork6::getPreferredSubnet(
const Subnet6Ptr& selected_subnet,
348 return (Impl::getPreferredSubnet(subnets_, selected_subnet, lease_type));
352 SharedNetwork6::toElement()
const {
356 if (!
name_.empty()) {
361 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
362 subnet6->add((*subnet)->toElement());
365 map->set(
"subnet6", subnet6);
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
boost::shared_ptr< Element > ElementPtr
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Defines the logger used by the top-level component of kea-dhcp-ddns.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Type
Type of lease or pool.
A generic exception that is thrown if a function is called in a prohibited way.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)