Kea 3.1.1
container.h
Go to the documentation of this file.
1// Copyright (C) 2018-2025 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 CONTAINER_H
8#define 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/sequenced_index.hpp>
18#include <boost/multi_index/hashed_index.hpp>
19#include <boost/multi_index/identity.hpp>
20
21namespace isc {
22namespace host_cache {
23
26
29
32
35
45typedef boost::multi_index_container<
46 // This container stores pointers to Host objects.
48 // Start specification of indexes here.
49 boost::multi_index::indexed_by<
50 // Sequenced index implements least-recently-used.
51 boost::multi_index::sequenced<
52 boost::multi_index::tag<HostSequencedIndexTag>
53 >,
54 // Hash index for direct retrieval.
55 boost::multi_index::hashed_unique<
56 boost::multi_index::tag<HostHashedIndexTag>,
57 boost::multi_index::identity<dhcp::HostPtr>
58 >,
59 // This index is used to search for the host using one of the
60 // identifiers, i.e. HW address or DUID. The elements of this
61 // index are non-unique because there may be multiple reservations
62 // for the same host belonging to a different subnets.
63 boost::multi_index::ordered_non_unique<
64 boost::multi_index::tag<HostIdentifierIndexTag>,
65 // The index comprises actual identifier (HW address or DUID) in
66 // a binary form and a type of the identifier which indicates
67 // that it is HW address or DUID.
68 boost::multi_index::composite_key<
69 // Composite key uses members of the Host class.
71 // Binary identifier is retrieved from the Host class using
72 // a getIdentifier method.
73 boost::multi_index::const_mem_fun<
74 dhcp::Host, const std::vector<uint8_t>&,
76 >,
77 // Identifier type is retrieved from the Host class using
78 // a getIdentifierType method.
79 boost::multi_index::const_mem_fun<
82 >
83 >
84 >,
85
86 // This index is used to search for the host using reserved IPv4
87 // address.
88 boost::multi_index::ordered_non_unique<
89 boost::multi_index::tag<HostAddress4IndexTag>,
90 // Index using values returned by the @c Host::getIPv4Reservation.
91 boost::multi_index::const_mem_fun<dhcp::Host,
94 >
95 >
97
101typedef HostContainer::index<HostSequencedIndexTag>::type HostContainerSequencedIndex;
102
106typedef HostContainer::index<HostHashedIndexTag>::type HostContainerHashedIndex;
107
112typedef HostContainer::index<HostIdentifierIndexTag>::type HostContainerIdentifierIndex;
113
115typedef std::pair<HostContainerIdentifierIndex::iterator,
116 HostContainerIdentifierIndex::iterator> HostContainerIdentifierIndexRange;
117
122typedef HostContainer::index<HostAddress4IndexTag>::type HostContainerAddress4Index;
123
125typedef std::pair<HostContainerAddress4Index::iterator,
126 HostContainerAddress4Index::iterator> HostContainerAddress4IndexRange;
127
135
141 : resrv_(resrv), host_(host),
142 subnet_id_(host ? host->getIPv6SubnetID() : dhcp::SUBNET_ID_UNUSED) {
143 }
144
147
150
153
156 return (resrv_.getPrefix());
157 }
158};
159
162
165
171typedef boost::multi_index_container<
172
173 // This containers stores (IPv6Resrv, HostPtr) tuples
175
176 // Start specification of indexes here.
177 boost::multi_index::indexed_by<
178
179 // First index is used to search by an address.
180 boost::multi_index::ordered_non_unique<
181 boost::multi_index::tag<Resv6AddressIndexTag>,
182
183 // Address is extracted by calling IPv6Resrv::getPrefix()
184 // and it will return an IOAddress object.
185 boost::multi_index::const_mem_fun<
187 >,
188
189 // Second index is used to search by (subnet_id, address) pair.
190 boost::multi_index::ordered_unique<
191 boost::multi_index::tag<Resv6SubnetAddressIndexTag>,
192
195 boost::multi_index::composite_key<
196
197 // Composite key uses members of the HostResrv6Tuple class.
199
200 // First key extractor. Gets subnet-id as a member of the
201 // HostResrv6Tuple structure.
202 boost::multi_index::member<HostResrv6Tuple,
203 const dhcp::SubnetID,
205
206 // Second key extractor. Address is extracted by calling
207 // IPv6Resrv::getPrefix() and it will return an IOAddress object.
208 boost::multi_index::const_mem_fun<
211 >
212 >
213 >
214 >
216
221typedef Resv6Container::index<Resv6AddressIndexTag>::type
223
225typedef std::pair<Resv6ContainerAddressIndex::iterator,
226 Resv6ContainerAddressIndex::iterator> Resv6ContainerAddressIndexRange;
227
232typedef Resv6Container::index<Resv6SubnetAddressIndexTag>::type
234
236typedef std::pair<Resv6ContainerSubnetAddressIndex::iterator,
237 Resv6ContainerSubnetAddressIndex::iterator> Resv6ContainerSubnetAddressIndexRange;
238
239}; // end of isc::dhcp namespace
240}; // end of isc namespace
241
242#endif // CONTAINER_H
Represents a device with IPv4 and/or IPv6 reservations.
Definition host.h:327
IdentifierType
Type of the host identifier.
Definition host.h:337
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:273
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition host.h:562
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition host.cc:268
IPv6 reservation for a host.
Definition host.h:163
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
HostContainer::index< HostAddress4IndexTag >::type HostContainerAddress4Index
Reserved Ipv4 address index type in the HostContainer.
Definition container.h:122
std::pair< Resv6ContainerSubnetAddressIndex::iterator, Resv6ContainerSubnetAddressIndex::iterator > Resv6ContainerSubnetAddressIndexRange
Results range returned using the Resv6ContainerSubnetAddressIndex.
Definition container.h:237
HostContainer::index< HostIdentifierIndexTag >::type HostContainerIdentifierIndex
Identifier index type in the HostContainer.
Definition container.h:112
std::pair< HostContainerAddress4Index::iterator, HostContainerAddress4Index::iterator > HostContainerAddress4IndexRange
Results range returned using the HostContainerAddress4Index.
Definition container.h:126
HostContainer::index< HostHashedIndexTag >::type HostContainerHashedIndex
Hashed index type in the HostContainer.
Definition container.h:106
std::pair< HostContainerIdentifierIndex::iterator, HostContainerIdentifierIndex::iterator > HostContainerIdentifierIndexRange
Results range returned using the HostContainerIdentifierIndex.
Definition container.h:116
boost::multi_index_container< dhcp::HostPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< HostSequencedIndexTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< HostHashedIndexTag >, boost::multi_index::identity< dhcp::HostPtr > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostIdentifierIndexTag >, boost::multi_index::composite_key< dhcp::Host, boost::multi_index::const_mem_fun< dhcp::Host, const std::vector< uint8_t > &, &dhcp::Host::getIdentifier >, boost::multi_index::const_mem_fun< dhcp::Host, dhcp::Host::IdentifierType, &dhcp::Host::getIdentifierType > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostAddress4IndexTag >, boost::multi_index::const_mem_fun< dhcp::Host, const asiolink::IOAddress &, &dhcp::Host::getIPv4Reservation > > > > HostContainer
Multi-index container holding host cache entries.
Definition container.h:96
std::pair< Resv6ContainerAddressIndex::iterator, Resv6ContainerAddressIndex::iterator > Resv6ContainerAddressIndexRange
Results range returned using the Resv6ContainerAddressIndex.
Definition container.h:226
boost::multi_index_container< HostResrv6Tuple, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< Resv6AddressIndexTag >, boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getKey > >, boost::multi_index::ordered_unique< boost::multi_index::tag< Resv6SubnetAddressIndexTag >, boost::multi_index::composite_key< HostResrv6Tuple, boost::multi_index::member< HostResrv6Tuple, const dhcp::SubnetID, &HostResrv6Tuple::subnet_id_ >, boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getKey > > > > > Resv6Container
Multi-index container holding IPv6 reservations.
Definition container.h:215
Resv6Container::index< Resv6AddressIndexTag >::type Resv6ContainerAddressIndex
First index type in the Resv6Container.
Definition container.h:222
HostContainer::index< HostSequencedIndexTag >::type HostContainerSequencedIndex
Sequenced index type in the HostContainer.
Definition container.h:101
Resv6Container::index< Resv6SubnetAddressIndexTag >::type Resv6ContainerSubnetAddressIndex
Second index type in the Resv6Container.
Definition container.h:233
Defines the logger used by the top-level component of kea-lfc.
Tag for the index for searching by reserved IPv4 address.
Definition container.h:34
Tag for the hashed index.
Definition container.h:28
Tag for the index for searching by identifier.
Definition container.h:31
Defines one entry for the Host Container for v6 hosts.
Definition container.h:134
const dhcp::IPv6Resrv resrv_
Address or prefix reservation.
Definition container.h:146
dhcp::HostPtr host_
Pointer to the host object.
Definition container.h:149
HostResrv6Tuple(const dhcp::IPv6Resrv &resrv, const dhcp::HostPtr &host)
Default constructor.
Definition container.h:140
const dhcp::SubnetID subnet_id_
Value of the IPv6 Subnet-id.
Definition container.h:152
const asiolink::IOAddress & getKey() const
Key extractor (used in the second composite key)
Definition container.h:155
Tag for the sequenced index.
Definition container.h:25
Tag for the index for searching by address.
Definition container.h:161
Tag for the index for searching by subnet and address.
Definition container.h:164