Kea  1.5.0
shared_network.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef SHARED_NETWORK_H
8 #define SHARED_NETWORK_H
9 
10 #include <asiolink/io_address.h>
11 #include <cc/data.h>
12 #include <exceptions/exceptions.h>
14 #include <dhcpsrv/subnet.h>
15 #include <dhcpsrv/subnet_id.h>
16 #include <boost/enable_shared_from_this.hpp>
17 #include <boost/multi_index/mem_fun.hpp>
18 #include <boost/multi_index/indexed_by.hpp>
19 #include <boost/multi_index/ordered_index.hpp>
20 #include <boost/multi_index/random_access_index.hpp>
21 #include <boost/multi_index_container.hpp>
22 #include <boost/shared_ptr.hpp>
23 #include <string>
24 
25 namespace isc {
26 namespace dhcp {
27 
30 
33 
36 
40 class SharedNetwork4 : public Network4,
41  public boost::enable_shared_from_this<SharedNetwork4>,
42  public AssignableNetwork {
43 public:
44 
48  explicit SharedNetwork4(const std::string& name)
49  : name_(name), subnets_() {
50  }
51 
57  virtual NetworkPtr sharedFromThis();
58 
60  std::string getName() const {
61  return (name_);
62  }
63 
67  void setName(const std::string& name) {
68  name_ = name;
69  }
70 
80  void add(const Subnet4Ptr& subnet);
81 
87  void del(const SubnetID& subnet_id);
88 
90  void delAll();
91 
95  return (&subnets_);
96  }
97 
104  Subnet4Ptr getSubnet(const SubnetID& subnet_id) const;
105 
120  Subnet4Ptr getNextSubnet(const Subnet4Ptr& first_subnet,
121  const SubnetID& current_subnet) const;
122 
146  Subnet4Ptr getPreferredSubnet(const Subnet4Ptr& selected_subnet) const;
147 
151  virtual data::ElementPtr toElement() const;
152 
153 private:
154 
156  std::string name_;
157 
159  Subnet4Collection subnets_;
160 };
161 
163 typedef boost::shared_ptr<SharedNetwork4> SharedNetwork4Ptr;
164 
170 typedef boost::multi_index_container<
171  // Multi index container holds pointers to the shared networks.
173  boost::multi_index::indexed_by<
174  // First is the random access index allowing for accessing objects
175  // just like we'd do with vector.
176  boost::multi_index::random_access<
177  boost::multi_index::tag<SharedNetworkRandomAccessIndexTag>
178  >,
179  // Second index allows for access by shared network's name.
180  boost::multi_index::ordered_unique<
181  boost::multi_index::tag<SharedNetworkNameIndexTag>,
182  boost::multi_index::const_mem_fun<SharedNetwork4, std::string,
184  >,
185  // Third index allows for access by server identifier specified for the
186  // network.
187  boost::multi_index::ordered_non_unique<
188  boost::multi_index::tag<SharedNetworkServerIdIndexTag>,
189  boost::multi_index::const_mem_fun<Network4, asiolink::IOAddress,
191  >
192 
193  >
195 
199 class SharedNetwork6 : public Network6,
200  public boost::enable_shared_from_this<SharedNetwork6>,
201  public AssignableNetwork {
202 public:
203 
207  explicit SharedNetwork6(const std::string& name)
208  : name_(name), subnets_() {
209  }
210 
216  virtual NetworkPtr sharedFromThis();
217 
219  std::string getName() const {
220  return (name_);
221  }
222 
226  void setName(const std::string& name) {
227  name_ = name;
228  }
229 
239  void add(const Subnet6Ptr& subnet);
240 
246  void del(const SubnetID& subnet_id);
247 
249  void delAll();
250 
254  return (&subnets_);
255  }
256 
263  Subnet6Ptr getSubnet(const SubnetID& subnet_id) const;
264 
279  Subnet6Ptr getNextSubnet(const Subnet6Ptr& first_subnet,
280  const SubnetID& current_subnet) const;
281 
304  Subnet6Ptr getPreferredSubnet(const Subnet6Ptr& selected_subnet,
305  const Lease::Type& lease_type) const;
306 
310  virtual data::ElementPtr toElement() const;
311 
312 private:
313 
315  std::string name_;
316 
318  Subnet6Collection subnets_;
319 };
320 
322 typedef boost::shared_ptr<SharedNetwork6> SharedNetwork6Ptr;
323 
329 typedef boost::multi_index_container<
330  // Multi index container holds pointers to the shared networks.
332  boost::multi_index::indexed_by<
333  // First is the random access index allowing for accessing objects
334  // just like we'd do with vector.
335  boost::multi_index::random_access<
336  boost::multi_index::tag<SharedNetworkRandomAccessIndexTag>
337  >,
338  // Second index allows for access by shared network's name.
339  boost::multi_index::ordered_unique<
340  boost::multi_index::tag<SharedNetworkNameIndexTag>,
341  boost::multi_index::const_mem_fun<SharedNetwork6, std::string,
343  >
344  >
346 
347 } // end of namespace isc::dhcp
348 } // end of namespace isc
349 
350 #endif // SHARED_NETWORK_H
Subnet4Ptr getSubnet(const SubnetID &subnet_id) const
Returns a subnet for a specified subnet id.
const Subnet4Collection * getAllSubnets() const
Returns a pointer to the collection of subnets within this shared network.
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
Definition: network.h:360
void setName(const std::string &name)
Sets new name for the shared network.
boost::multi_index_container< SharedNetwork6Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SharedNetworkRandomAccessIndexTag > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SharedNetworkNameIndexTag >, boost::multi_index::const_mem_fun< SharedNetwork6, std::string, &SharedNetwork6::getName > > >> SharedNetwork6Collection
Multi index container holding shared networks.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > > >> Subnet6Collection
A collection of Subnet6 objects.
Definition: subnet.h:843
void add(const Subnet6Ptr &subnet)
Adds IPv6 subnet to a shared network.
const Subnet6Collection * getAllSubnets() const
Returns a pointer to the collection of subnets within this shared network.
Subnet6Ptr getSubnet(const SubnetID &subnet_id) const
Returns a subnet for a specified subnet id.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
Definition: subnet.h:464
Subnet6Ptr getNextSubnet(const Subnet6Ptr &first_subnet, const SubnetID &current_subnet) const
Retrieves next available IPv6 subnet within shared network.
std::string getName() const
Returns a name of the shared network.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
virtual NetworkPtr sharedFromThis()
Returns shared pointer to this network.
boost::multi_index_container< SharedNetwork4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SharedNetworkRandomAccessIndexTag > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SharedNetworkNameIndexTag >, boost::multi_index::const_mem_fun< SharedNetwork4, std::string, &SharedNetwork4::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SharedNetworkServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > > >> SharedNetwork4Collection
Multi index container holding shared networks.
virtual data::ElementPtr toElement() const
Unparses shared network object.
Shared network holding IPv4 subnets.
Specialization of the Network object for DHCPv6 case.
Definition: network.h:431
void del(const SubnetID &subnet_id)
Removes subnet from a 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.
A tag for accessing index by shared network name.
Represents a network that can be associated with a subnet.
SharedNetwork4(const std::string &name)
Constructor.
void delAll()
Removes all subnets from a shared network.
void add(const Subnet4Ptr &subnet)
Adds IPv4 subnet to a shared network.
std::string getName() const
Returns a name of the shared network.
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
virtual data::ElementPtr toElement() const
Unparses shared network object.
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
A tag for accessing index by server identifier.
Defines the logger used by the top-level component of kea-dhcp-ddns.
A tag for accessing random access index.
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > > >> Subnet4Collection
A collection of Subnet4 objects.
Definition: subnet.h:798
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.
Type
Type of lease or pool.
Definition: lease.h:38
void delAll()
Removes all subnets from a shared network.
virtual asiolink::IOAddress getServerId() const
Returns binary representation of the dhcp-server-identifier option (54).
Definition: network.cc:205
Shared network holding IPv6 subnets.
Specialization of the Network object for DHCPv4 case.
Definition: network.h:366
void del(const SubnetID &subnet_id)
Removes subnet from a shared network.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
Definition: subnet.h:629
virtual NetworkPtr sharedFromThis()
Returns shared pointer to this network.
Subnet4Ptr getNextSubnet(const Subnet4Ptr &first_subnet, const SubnetID &current_subnet) const
Retrieves next available IPv4 subnet within shared network.
SharedNetwork6(const std::string &name)
Constructor.
void setName(const std::string &name)
Sets new name for the shared network.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24