Kea  1.5.0
host_container.h
Go to the documentation of this file.
1 // Copyright (C) 2014-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 HOST_CONTAINER_H
8 #define HOST_CONTAINER_H
9 
10 #include <dhcpsrv/host.h>
11 #include <dhcpsrv/subnet_id.h>
12 #include <boost/multi_index_container.hpp>
13 #include <boost/multi_index/composite_key.hpp>
14 #include <boost/multi_index/mem_fun.hpp>
15 #include <boost/multi_index/member.hpp>
16 #include <boost/multi_index/ordered_index.hpp>
17 #include <boost/multi_index/hashed_index.hpp>
18 
19 namespace isc {
20 namespace dhcp {
21 
33 typedef boost::multi_index_container<
34  // This container stores pointers to Host objects.
35  HostPtr,
36  // Start specification of indexes here.
37  boost::multi_index::indexed_by<
38  // First index is used to search for the host using one of the
39  // identifiers, i.e. HW address or DUID. The elements of this
40  // index are non-unique because there may be multiple reservations
41  // for the same host belonging to a different subnets.
42  boost::multi_index::ordered_non_unique<
43  // The index comprises actual identifier (HW address or DUID) in
44  // a binary form and a type of the identifier which indicates
45  // that it is HW address or DUID.
46  boost::multi_index::composite_key<
47  // Composite key uses members of the Host class.
48  Host,
49  // Binary identifier is retrieved from the Host class using
50  // a getIdentifier method.
51  boost::multi_index::const_mem_fun<
52  Host, const std::vector<uint8_t>&,
54  >,
55  // Identifier type is retrieved from the Host class using
56  // a getIdentifierType method.
57  boost::multi_index::const_mem_fun<
60  >
61  >
62  >,
63 
64  // Second index is used to search for the host using reserved IPv4
65  // address.
66  boost::multi_index::ordered_non_unique<
67  // Index using values returned by the @c Host::getIPv4Reservation.
68  boost::multi_index::const_mem_fun<Host, const asiolink::IOAddress&,
70  >,
71 
72  // Third index is used to search for the host using IPv4 subnet id
73  boost::multi_index::ordered_non_unique<
74  // Index using values returned by the @c Host::getIPv4SubnetID
75  boost::multi_index::const_mem_fun<Host, SubnetID,
77  >,
78 
79  // Forth index is used to search for the host using IPv6 subnet id
80  boost::multi_index::ordered_non_unique<
81  // Index using values returned by the @c Host::getIPv6SubnetID
82  boost::multi_index::const_mem_fun<Host, SubnetID,
84  >
85  >
87 
92 typedef HostContainer::nth_index<0>::type HostContainerIndex0;
93 
95 typedef std::pair<HostContainerIndex0::iterator,
96  HostContainerIndex0::iterator> HostContainerIndex0Range;
97 
102 typedef HostContainer::nth_index<1>::type HostContainerIndex1;
103 
105 typedef std::pair<HostContainerIndex1::iterator,
106  HostContainerIndex1::iterator> HostContainerIndex1Range;
107 
112 typedef HostContainer::nth_index<2>::type HostContainerIndex2;
113 
115 typedef std::pair<HostContainerIndex2::iterator,
116  HostContainerIndex2::iterator> HostContainerIndex2Range;
117 
122 typedef HostContainer::nth_index<3>::type HostContainerIndex3;
123 
125 typedef std::pair<HostContainerIndex3::iterator,
126  HostContainerIndex3::iterator> HostContainerIndex3Range;
127 
135 
140  HostResrv6Tuple(const IPv6Resrv& resrv, const HostPtr& host)
141  :resrv_(resrv), host_(host), subnet_id_(host ? host->getIPv6SubnetID() : 0) {
142  }
143 
146 
149 
152 
154  const asiolink::IOAddress& getKey() const {
155  return (resrv_.getPrefix());
156  }
157 };
158 
164 typedef boost::multi_index_container<
165 
166  // This containers stores (IPv6Resrv, HostPtr) tuples
167  HostResrv6Tuple,
168 
169  // Start specification of indexes here.
170  boost::multi_index::indexed_by<
171 
172  // First index is used to search by an address.
173  boost::multi_index::ordered_non_unique<
174 
175  // Address is extracted by calling IPv6Resrv::getPrefix()
176  // and it will return an IOAddress object.
177  boost::multi_index::const_mem_fun<
178  HostResrv6Tuple, const asiolink::IOAddress&, &HostResrv6Tuple::getKey>
179  >,
180 
181  // Second index is used to search by (subnet_id, address) pair.
182  // This is
183  boost::multi_index::ordered_unique<
184 
187  boost::multi_index::composite_key<
188 
189  // Composite key uses members of the HostResrv6Tuple class.
190  HostResrv6Tuple,
191 
192  // First key extractor. Gets subnet-id as a member of the
193  // HostResrv6Tuple structure.
194  boost::multi_index::member<HostResrv6Tuple, const SubnetID,
196 
197  // Second key extractor. Address is extracted by calling
198  // IPv6Resrv::getPrefix() and it will return an IOAddress object.
199  boost::multi_index::const_mem_fun<
200  HostResrv6Tuple, const asiolink::IOAddress&,
202  >
203  >
204  >,
205 
206  // Third index is used to search for the host using IPv6 subnet id
207  boost::multi_index::ordered_non_unique<
208  // Index using values returned by the @c Host::getIPv6SubnetID
209  boost::multi_index::member<HostResrv6Tuple, const SubnetID,
211  >
212  >
214 
219 typedef HostContainer6::nth_index<0>::type HostContainer6Index0;
220 
222 typedef std::pair<HostContainer6Index0::iterator,
223  HostContainer6Index0::iterator> HostContainer6Index0Range;
224 
229 typedef HostContainer6::nth_index<1>::type HostContainer6Index1;
230 
232 typedef std::pair<HostContainer6Index1::iterator,
233  HostContainer6Index1::iterator> HostContainer6Index1Range;
234 
239 typedef HostContainer6::nth_index<2>::type HostContainer6Index2;
240 
242 typedef std::pair<HostContainer6Index2::iterator,
243  HostContainer6Index2::iterator> HostContainer6Index2Range;
244 
245 }; // end of isc::dhcp namespace
246 }; // end of isc namespace
247 
248 #endif // HOST_CONTAINER_H
isc::dhcp::HostResrv6Tuple::resrv_
const IPv6Resrv resrv_
Address or prefix reservation.
Definition: host_container.h:145
host.h
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition: host.h:252
isc::dhcp::HostResrv6Tuple::subnet_id_
const SubnetID subnet_id_
Value of the IPv6 Subnet-id.
Definition: host_container.h:151
isc::dhcp::HostContainerIndex3
HostContainer::nth_index< 3 >::type HostContainerIndex3
Forth index type in the HostContainer.
Definition: host_container.h:122
isc::dhcp::HostContainerIndex0
HostContainer::nth_index< 0 >::type HostContainerIndex0
First index type in the HostContainer.
Definition: host_container.h:92
isc::dhcp::HostContainer6Index1
HostContainer6::nth_index< 1 >::type HostContainer6Index1
Second index type in the HostContainer6.
Definition: host_container.h:229
isc::dhcp::Host::getIdentifier
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition: host.cc:195
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
isc::dhcp::HostResrv6Tuple::host_
HostPtr host_
Pointer to the host object.
Definition: host_container.h:148
isc::dhcp::HostResrv6Tuple
Defines one entry for the Host Container for v6 hosts.
Definition: host_container.h:134
isc::dhcp::Host::getIdentifierType
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition: host.cc:200
isc::dhcp::HostContainer6Index0Range
std::pair< HostContainer6Index0::iterator, HostContainer6Index0::iterator > HostContainer6Index0Range
Results range returned using the HostContainer6Index0.
Definition: host_container.h:223
isc::dhcp::HostContainer6Index1Range
std::pair< HostContainer6Index1::iterator, HostContainer6Index1::iterator > HostContainer6Index1Range
Results range returned using the HostContainer6Index1.
Definition: host_container.h:233
isc::dhcp::IPv6Resrv::getPrefix
const asiolink::IOAddress & getPrefix() const
Returns prefix for the reservation.
Definition: host.h:135
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::HostContainerIndex3Range
std::pair< HostContainerIndex3::iterator, HostContainerIndex3::iterator > HostContainerIndex3Range
Results range returned using the HostContainerIndex3.
Definition: host_container.h:126
isc::dhcp::HostContainerIndex2Range
std::pair< HostContainerIndex2::iterator, HostContainerIndex2::iterator > HostContainerIndex2Range
Results range returned using the HostContainerIndex2.
Definition: host_container.h:116
isc::dhcp::Host::getIPv4SubnetID
SubnetID getIPv4SubnetID() const
Returns subnet identifier for IPv4 reservation.
Definition: host.h:443
isc::dhcp::HostContainerIndex1Range
std::pair< HostContainerIndex1::iterator, HostContainerIndex1::iterator > HostContainerIndex1Range
Results range returned using the HostContainerIndex1.
Definition: host_container.h:106
isc::dhcp::Host::getIPv4Reservation
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition: host.h:470
isc::dhcp::IPv6Resrv
IPv6 reservation for a host.
Definition: host.h:106
isc::dhcp::HostContainerIndex0Range
std::pair< HostContainerIndex0::iterator, HostContainerIndex0::iterator > HostContainerIndex0Range
Results range returned using the HostContainerIndex0.
Definition: host_container.h:96
isc::dhcp::HostContainer6Index0
HostContainer6::nth_index< 0 >::type HostContainer6Index0
First index type in the HostContainer6.
Definition: host_container.h:219
isc::dhcp::HostContainer
boost::multi_index_container< HostPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::composite_key< Host, boost::multi_index::const_mem_fun< Host, const std::vector< uint8_t > &, &Host::getIdentifier >, boost::multi_index::const_mem_fun< Host, Host::IdentifierType, &Host::getIdentifierType > > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, const asiolink::IOAddress &, &Host::getIPv4Reservation > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, SubnetID, &Host::getIPv4SubnetID > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, SubnetID, &Host::getIPv6SubnetID > > >> HostContainer
Multi-index container holding host reservations.
Definition: host_container.h:86
isc::dhcp::HostContainer6Index2Range
std::pair< HostContainer6Index2::iterator, HostContainer6Index2::iterator > HostContainer6Index2Range
Results range returned using the HostContainer6Index2.
Definition: host_container.h:243
isc::dhcp::HostContainerIndex1
HostContainer::nth_index< 1 >::type HostContainerIndex1
Second index type in the HostContainer.
Definition: host_container.h:102
subnet_id.h
isc::dhcp::HostResrv6Tuple::getKey
const asiolink::IOAddress & getKey() const
Key extractor (used in the second composite key)
Definition: host_container.h:154
isc::dhcp::HostContainer6
boost::multi_index_container< HostResrv6Tuple, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getKey > >, boost::multi_index::ordered_unique< boost::multi_index::composite_key< HostResrv6Tuple, boost::multi_index::member< HostResrv6Tuple, const SubnetID, &HostResrv6Tuple::subnet_id_ >, boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getKey > > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< HostResrv6Tuple, const SubnetID, &HostResrv6Tuple::subnet_id_ > > >> HostContainer6
Multi-index container holding IPv6 reservations.
Definition: host_container.h:213
isc::dhcp::Host::getIPv6SubnetID
SubnetID getIPv6SubnetID() const
Returns subnet identifier for IPv6 reservations.
Definition: host.h:448
isc::dhcp::HostResrv6Tuple::HostResrv6Tuple
HostResrv6Tuple(const IPv6Resrv &resrv, const HostPtr &host)
Default constructor.
Definition: host_container.h:140
isc::dhcp::SubnetID
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
isc::dhcp::HostContainer6Index2
HostContainer6::nth_index< 2 >::type HostContainer6Index2
Third index type in the HostContainer6.
Definition: host_container.h:239
isc::dhcp::HostContainerIndex2
HostContainer::nth_index< 2 >::type HostContainerIndex2
Third index type in the HostContainer.
Definition: host_container.h:112