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);
249 return (shared_from_this());
254 Impl::add(subnets_, subnet);
261 Subnet4Ptr subnet = Impl::del<Subnet4Ptr>(subnets_, subnet_id);
267 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
275 return (Impl::getSubnet<Subnet4Ptr>(subnets_, subnet_id));
280 const SubnetID& current_subnet)
const {
281 return (Impl::getNextSubnet(subnets_, first_subnet, current_subnet));
286 return (Impl::getPreferredSubnet<Subnet4Ptr>(subnets_, selected_subnet,
295 if (!name_.empty()) {
300 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
301 subnet4->add((*subnet)->toElement());
304 map->set(
"subnet4", subnet4);
311 return (shared_from_this());
316 Impl::add(subnets_, subnet);
323 Subnet6Ptr subnet = Impl::del<Subnet6Ptr>(subnets_, subnet_id);
329 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
336 return (Impl::getSubnet<Subnet6Ptr>(subnets_, subnet_id));
341 const SubnetID& current_subnet)
const {
342 return (Impl::getNextSubnet(subnets_, first_subnet, current_subnet));
348 return (Impl::getPreferredSubnet(subnets_, selected_subnet, lease_type));
356 if (!name_.empty()) {
361 for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
362 subnet6->add((*subnet)->toElement());
365 map->set(
"subnet6", subnet6);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
void setSharedNetwork(const SubnetPtr &subnet)
Associates a subnet with this network.
void clearSharedNetwork(const SubnetPtr &subnet)
Removes association of a subnet with a network.
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
virtual data::ElementPtr toElement() const
Unparses network object.
virtual data::ElementPtr toElement() const
Unparses network object.
virtual NetworkPtr sharedFromThis()
Returns shared pointer to this network.
Subnet4Ptr getNextSubnet(const Subnet4Ptr &first_subnet, const SubnetID ¤t_subnet) const
Retrieves next available IPv4 subnet within shared network.
Subnet4Ptr getPreferredSubnet(const Subnet4Ptr &selected_subnet) const
Attempts to find a subnet which is more likely to include available leases than selected subnet.
virtual data::ElementPtr toElement() const
Unparses shared network object.
void add(const Subnet4Ptr &subnet)
Adds IPv4 subnet to a shared network.
void del(const SubnetID &subnet_id)
Removes subnet from a shared network.
Subnet4Ptr getSubnet(const SubnetID &subnet_id) const
Returns a subnet for a specified subnet id.
void delAll()
Removes all subnets from a shared network.
Subnet6Ptr getNextSubnet(const Subnet6Ptr &first_subnet, const SubnetID ¤t_subnet) const
Retrieves next available IPv6 subnet within shared network.
Subnet6Ptr getSubnet(const SubnetID &subnet_id) const
Returns a subnet for a specified subnet id.
void del(const SubnetID &subnet_id)
Removes subnet from a shared network.
void add(const Subnet6Ptr &subnet)
Adds IPv6 subnet to a shared network.
virtual NetworkPtr sharedFromThis()
Returns shared pointer to this network.
virtual data::ElementPtr toElement() const
Unparses shared network object.
Subnet6Ptr getPreferredSubnet(const Subnet6Ptr &selected_subnet, const Lease::Type &lease_type) const
Attempts to find a subnet which is more likely to include available leases than selected subnet.
void delAll()
Removes all subnets from a shared network.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Type
Type of lease or pool.