| Kea 3.0.2-git

host_container.h
Go to the documentation of this file.
1// Copyright (C) 2014-2024 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>&,
53 &Host::getIdentifier
54 >,
55 // Identifier type is retrieved from the Host class using
56 // a getIdentifierType method.
57 boost::multi_index::const_mem_fun<
58 Host, Host::IdentifierType,
59 &Host::getIdentifierType
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&,
69 &Host::getIPv4Reservation>
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,
76 &Host::getIPv4SubnetID>
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,
83 &Host::getIPv6SubnetID>
84 >,
85
86 // Fifth index is used to search by increasing host id
87 boost::multi_index::ordered_unique<
88 // Index using values returned by the @c Host::getHostId
89 boost::multi_index::const_mem_fun<Host, uint64_t,
90 &Host::getHostId>
91 >,
92
93 // Sixth index is used to search for the host using hostname
94 // (case-sensitive compare so the key is in lower case).
95 boost::multi_index::ordered_non_unique<
96 // Index using values returned by the @c Host::getLowerHostname
97 boost::multi_index::const_mem_fun<Host, std::string,
98 &Host::getLowerHostname>
99 >
100 >
101> HostContainer;
102
107 typedef HostContainer::nth_index<0>::type HostContainerIndex0;
108
110 typedef std::pair<HostContainerIndex0::iterator,
111 HostContainerIndex0::iterator> HostContainerIndex0Range;
112
117 typedef HostContainer::nth_index<1>::type HostContainerIndex1;
118
120 typedef std::pair<HostContainerIndex1::iterator,
121 HostContainerIndex1::iterator> HostContainerIndex1Range;
122
127 typedef HostContainer::nth_index<2>::type HostContainerIndex2;
128
130 typedef std::pair<HostContainerIndex2::iterator,
131 HostContainerIndex2::iterator> HostContainerIndex2Range;
132
137 typedef HostContainer::nth_index<3>::type HostContainerIndex3;
138
140 typedef std::pair<HostContainerIndex3::iterator,
141 HostContainerIndex3::iterator> HostContainerIndex3Range;
142
146 typedef HostContainer::nth_index<4>::type HostContainerIndex4;
147
149 typedef std::pair<HostContainerIndex4::iterator,
150 HostContainerIndex4::iterator> HostContainerIndex4Range;
151
155 typedef HostContainer::nth_index<5>::type HostContainerIndex5;
156
163 struct HostResrv6Tuple {
164
169 HostResrv6Tuple(const IPv6Resrv& resrv, const HostPtr& host)
170 : resrv_(resrv), host_(host), subnet_id_(host ? host->getIPv6SubnetID() : SUBNET_ID_GLOBAL) {
171 }
172
174 const IPv6Resrv resrv_;
175
177 HostPtr host_;
178
180 const SubnetID subnet_id_;
181
183 const asiolink::IOAddress& getPrefix() const {
184 return (resrv_.getPrefix());
185 }
186
188 HostID getHostId() const {
189 return (host_->getHostId());
190 }
191};
192
198 typedef boost::multi_index_container<
199
200 // This containers stores (IPv6Resrv, HostPtr) tuples
201 HostResrv6Tuple,
202
203 // Start specification of indexes here.
204 boost::multi_index::indexed_by<
205
206 // First index is used to search by an address.
207 boost::multi_index::ordered_non_unique<
208
209 // Address is extracted by calling IPv6Resrv::getPrefix()
210 // and it will return an IOAddress object.
211 boost::multi_index::const_mem_fun<
212 HostResrv6Tuple, const asiolink::IOAddress&, &HostResrv6Tuple::getPrefix>
213 >,
214
215 // Second index is used to search by (subnet_id, address) pair.
216 // This is
217 boost::multi_index::ordered_non_unique<
218
221 boost::multi_index::composite_key<
222
223 // Composite key uses members of the HostResrv6Tuple class.
224 HostResrv6Tuple,
225
226 // First key extractor. Gets subnet-id as a member of the
227 // HostResrv6Tuple structure.
228 boost::multi_index::member<HostResrv6Tuple, const SubnetID,
229 &HostResrv6Tuple::subnet_id_>,
230
231 // Second key extractor. Address is extracted by calling
232 // IPv6Resrv::getPrefix() and it will return an IOAddress object.
233 boost::multi_index::const_mem_fun<
234 HostResrv6Tuple, const asiolink::IOAddress&,
235 &HostResrv6Tuple::getPrefix
236 >
237 >
238 >,
239
240 // Third index is used to search for the host using IPv6 subnet id
241 boost::multi_index::ordered_non_unique<
242 // Index using values returned by the @c Host::getIPv6SubnetID
243 boost::multi_index::member<HostResrv6Tuple, const SubnetID,
244 &HostResrv6Tuple::subnet_id_>
245 >,
246
247 // Fourth index is used to search by increasing host id
248 boost::multi_index::ordered_non_unique<
249 // Index using values returned by the @c Host::getHostId
250 boost::multi_index::const_mem_fun<HostResrv6Tuple, uint64_t,
251 &HostResrv6Tuple::getHostId>
252 >,
253
254 // Fifth index is used to search by the reserved address.
255 boost::multi_index::ordered_non_unique<
256 boost::multi_index::const_mem_fun<
257 HostResrv6Tuple, const asiolink::IOAddress&,
258 &HostResrv6Tuple::getPrefix
259 >
260 >
261 >
262> HostContainer6;
263
268 typedef HostContainer6::nth_index<0>::type HostContainer6Index0;
269
271 typedef std::pair<HostContainer6Index0::iterator,
272 HostContainer6Index0::iterator> HostContainer6Index0Range;
273
278 typedef HostContainer6::nth_index<1>::type HostContainer6Index1;
279
281 typedef std::pair<HostContainer6Index1::iterator,
282 HostContainer6Index1::iterator> HostContainer6Index1Range;
283
288 typedef HostContainer6::nth_index<2>::type HostContainer6Index2;
289
291 typedef std::pair<HostContainer6Index2::iterator,
292 HostContainer6Index2::iterator> HostContainer6Index2Range;
293
297 typedef HostContainer6::nth_index<3>::type HostContainer6Index3;
298
300 typedef std::pair<HostContainer6Index3::iterator,
301 HostContainer6Index3::iterator> HostContainer6Index3Range;
302
306 typedef HostContainer6::nth_index<4>::type HostContainer6Index4;
307
309 typedef std::pair<HostContainer6Index4::iterator,
310 HostContainer6Index4::iterator> HostContainer6Index4Range;
311
312} // namespace dhcp
313} // namespace isc
314
315#endif // HOST_CONTAINER_H
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::dhcp::Host
Represents a device with IPv4 and/or IPv6 reservations.
Definition host.h:327
isc::dhcp::Host::getIPv4SubnetID
SubnetID getIPv4SubnetID() const
Returns subnet identifier for IPv4 reservation.
Definition host.h:535
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition host.h:337
isc::dhcp::Host::getIdentifierType
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:273
isc::dhcp::Host::getLowerHostname
std::string getLowerHostname() const
Returns reserved hostname in lower case.
Definition host.h:611
isc::dhcp::Host::getIPv6SubnetID
SubnetID getIPv6SubnetID() const
Returns subnet identifier for IPv6 reservations.
Definition host.h:540
isc::dhcp::Host::getIPv4Reservation
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition host.h:562
isc::dhcp::Host::getIdentifier
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition host.cc:268
isc::dhcp::Host::getHostId
HostID getHostId() const
Returns Host ID (primary key in MySQL and PostgreSQL backends).
Definition host.h:719
isc::dhcp::IPv6Resrv
IPv6 reservation for a host.
Definition host.h:163
host.h
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::HostContainer6Index4
HostContainer6::nth_index< 4 >::type HostContainer6Index4
Fifth index type in the HostContainer6.
Definition host_container.h:306
isc::dhcp::HostContainerIndex4
HostContainer::nth_index< 4 >::type HostContainerIndex4
Fifth index type in the HostContainer.
Definition host_container.h:146
isc::dhcp::HostContainerIndex1Range
std::pair< HostContainerIndex1::iterator, HostContainerIndex1::iterator > HostContainerIndex1Range
Results range returned using the HostContainerIndex1.
Definition host_container.h:121
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 > >, boost::multi_index::ordered_unique< boost::multi_index::const_mem_fun< Host, uint64_t, &Host::getHostId > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, std::string, &Host::getLowerHostname > > > > HostContainer
Multi-index container holding host reservations.
Definition host_container.h:101
isc::dhcp::HostContainer6Index1Range
std::pair< HostContainer6Index1::iterator, HostContainer6Index1::iterator > HostContainer6Index1Range
Results range returned using the HostContainer6Index1.
Definition host_container.h:282
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
isc::dhcp::HostContainer6Index3
HostContainer6::nth_index< 3 >::type HostContainer6Index3
Fourth index type in the HostContainer6.
Definition host_container.h:297
isc::dhcp::HostContainerIndex0Range
std::pair< HostContainerIndex0::iterator, HostContainerIndex0::iterator > HostContainerIndex0Range
Results range returned using the HostContainerIndex0.
Definition host_container.h:111
isc::dhcp::HostContainer6Index0
HostContainer6::nth_index< 0 >::type HostContainer6Index0
First index type in the HostContainer6.
Definition host_container.h:268
isc::dhcp::HostContainer6Index4Range
std::pair< HostContainer6Index4::iterator, HostContainer6Index4::iterator > HostContainer6Index4Range
Results range returned using the HostContainer6Index4.
Definition host_container.h:310
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::getPrefix > >, boost::multi_index::ordered_non_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::getPrefix > > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< HostResrv6Tuple, const SubnetID, &HostResrv6Tuple::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< HostResrv6Tuple, uint64_t, &HostResrv6Tuple::getHostId > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getPrefix > > > > HostContainer6
Multi-index container holding IPv6 reservations.
Definition host_container.h:262
isc::dhcp::HostContainer6Index1
HostContainer6::nth_index< 1 >::type HostContainer6Index1
Second index type in the HostContainer6.
Definition host_container.h:278
isc::dhcp::HostContainerIndex2Range
std::pair< HostContainerIndex2::iterator, HostContainerIndex2::iterator > HostContainerIndex2Range
Results range returned using the HostContainerIndex2.
Definition host_container.h:131
isc::dhcp::HostContainerIndex1
HostContainer::nth_index< 1 >::type HostContainerIndex1
Second index type in the HostContainer.
Definition host_container.h:117
isc::dhcp::HostContainer6Index2
HostContainer6::nth_index< 2 >::type HostContainer6Index2
Third index type in the HostContainer6.
Definition host_container.h:288
isc::dhcp::HostContainerIndex3
HostContainer::nth_index< 3 >::type HostContainerIndex3
Forth index type in the HostContainer.
Definition host_container.h:137
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::dhcp::HostContainerIndex3Range
std::pair< HostContainerIndex3::iterator, HostContainerIndex3::iterator > HostContainerIndex3Range
Results range returned using the HostContainerIndex3.
Definition host_container.h:141
isc::dhcp::HostID
uint64_t HostID
HostID (used only when storing in MySQL or PostgreSQL backends).
Definition host.h:70
isc::dhcp::HostContainerIndex4Range
std::pair< HostContainerIndex4::iterator, HostContainerIndex4::iterator > HostContainerIndex4Range
Results range returned using the HostContainerIndex4.
Definition host_container.h:150
isc::dhcp::HostContainer6Index0Range
std::pair< HostContainer6Index0::iterator, HostContainer6Index0::iterator > HostContainer6Index0Range
Results range returned using the HostContainer6Index0.
Definition host_container.h:272
isc::dhcp::HostContainerIndex0
HostContainer::nth_index< 0 >::type HostContainerIndex0
First index type in the HostContainer.
Definition host_container.h:107
isc::dhcp::HostContainer6Index3Range
std::pair< HostContainer6Index3::iterator, HostContainer6Index3::iterator > HostContainer6Index3Range
Results range returned using the HostContainer6Index3.
Definition host_container.h:301
isc::dhcp::HostContainerIndex5
HostContainer::nth_index< 5 >::type HostContainerIndex5
Sixth index type in the HostContainer.
Definition host_container.h:155
isc::dhcp::HostContainerIndex2
HostContainer::nth_index< 2 >::type HostContainerIndex2
Third index type in the HostContainer.
Definition host_container.h:127
isc::dhcp::HostContainer6Index2Range
std::pair< HostContainer6Index2::iterator, HostContainer6Index2::iterator > HostContainer6Index2Range
Results range returned using the HostContainer6Index2.
Definition host_container.h:292
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
isc::dhcp::HostResrv6Tuple::resrv_
const IPv6Resrv resrv_
Address or prefix reservation.
Definition host_container.h:174
isc::dhcp::HostResrv6Tuple::getPrefix
const asiolink::IOAddress & getPrefix() const
Key extractor used in the second composite key.
Definition host_container.h:183
isc::dhcp::HostResrv6Tuple::getHostId
HostID getHostId() const
Key extractor used in the fourth composite key.
Definition host_container.h:188
isc::dhcp::HostResrv6Tuple::HostResrv6Tuple
HostResrv6Tuple(const IPv6Resrv &resrv, const HostPtr &host)
Default constructor.
Definition host_container.h:169
isc::dhcp::HostResrv6Tuple::host_
HostPtr host_
Pointer to the host object.
Definition host_container.h:177
isc::dhcp::HostResrv6Tuple::subnet_id_
const SubnetID subnet_id_
Value of the IPv6 Subnet-id.
Definition host_container.h:180
subnet_id.h