Kea 1.5.0
memfile_lease_storage.h
Go to the documentation of this file.
1// Copyright (C) 2015-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 MEMFILE_LEASE_STORAGE_H
8#define MEMFILE_LEASE_STORAGE_H
9
10#include <asiolink/io_address.h>
11#include <dhcpsrv/lease.h>
12#include <dhcpsrv/subnet_id.h>
13
14#include <boost/multi_index/indexed_by.hpp>
15#include <boost/multi_index/member.hpp>
16#include <boost/multi_index/mem_fun.hpp>
17#include <boost/multi_index/ordered_index.hpp>
18#include <boost/multi_index_container.hpp>
19#include <boost/multi_index/composite_key.hpp>
20
21#include <vector>
22
23namespace isc {
24namespace dhcp {
25
26
28struct AddressIndexTag { };
29
32
35
38
41
44
47
49struct DuidIndexTag { };
52
53
65typedef boost::multi_index_container<
66 // It holds pointers to Lease6 objects.
68 boost::multi_index::indexed_by<
69 // Specification of the first index starts here.
70 // This index sorts leases by IPv6 addresses represented as
71 // IOAddress objects.
72 boost::multi_index::ordered_unique<
73 boost::multi_index::tag<AddressIndexTag>,
74 boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
75 >,
76
77 // Specification of the second index starts here.
78 boost::multi_index::ordered_non_unique<
79 boost::multi_index::tag<DuidIaidTypeIndexTag>,
80 // This is a composite index that will be used to search for
81 // the lease using three attributes: DUID, IAID and lease type.
82 boost::multi_index::composite_key<
83 Lease6,
84 // The DUID can be retrieved from the Lease6 object using
85 // a getDuidVector const function.
86 boost::multi_index::const_mem_fun<Lease6, const std::vector<uint8_t>&,
88 // The two other ingredients of this index are IAID and
89 // lease type.
90 boost::multi_index::member<Lease6, uint32_t, &Lease6::iaid_>,
91 boost::multi_index::member<Lease6, Lease::Type, &Lease6::type_>
92 >
93 >,
94
95 // Specification of the third index starts here.
96 boost::multi_index::ordered_non_unique<
97 boost::multi_index::tag<ExpirationIndexTag>,
98 // This is a composite index that will be used to search for
99 // the expired leases. Depending on the value of the first component
100 // of the search key, the reclaimed or not reclaimed leases will can
101 // be searched.
102 boost::multi_index::composite_key<
103 Lease6,
104 // The boolean value specifying if lease is reclaimed or not.
105 boost::multi_index::const_mem_fun<Lease, bool,
107 // Lease expiration time.
108 boost::multi_index::const_mem_fun<Lease, int64_t,
110 >
111 >,
112
113 // Specification of the fourth index starts here.
114 // This index sorts leases by SubnetID.
115 boost::multi_index::ordered_non_unique<
116 boost::multi_index::tag<SubnetIdIndexTag>,
117 boost::multi_index::member<Lease, isc::dhcp::SubnetID,
119 >,
120
121 // Specification of the fifth index starts here
122 // This index is used to retrieve leases for matching duid.
123 boost::multi_index::ordered_non_unique<
124 boost::multi_index::tag<DuidIndexTag>,
125 boost::multi_index::const_mem_fun<Lease6,
126 const std::vector<uint8_t>&,
128 >
129 >
130> Lease6Storage; // Specify the type name of this container.
131
145typedef boost::multi_index_container<
146 // It holds pointers to Lease4 objects.
147 Lease4Ptr,
148 // Specification of search indexes starts here.
149 boost::multi_index::indexed_by<
150 // Specification of the first index starts here.
151 // This index sorts leases by IPv4 addresses represented as
152 // IOAddress objects.
153 boost::multi_index::ordered_unique<
154 boost::multi_index::tag<AddressIndexTag>,
155 // The IPv4 address are held in addr_ members that belong to
156 // Lease class.
157 boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
158 >,
159
160 // Specification of the second index starts here.
161 boost::multi_index::ordered_non_unique<
162 boost::multi_index::tag<HWAddressSubnetIdIndexTag>,
163 // This is a composite index that combines two attributes of the
164 // Lease4 object: hardware address and subnet id.
165 boost::multi_index::composite_key<
166 Lease4,
167 // The hardware address is held in the hwaddr_ member of the
168 // Lease4 object, which is a HWAddr object. Boost does not
169 // provide a key extractor for getting a member of a member,
170 // so we need a simple method for that.
171 boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
173 // The subnet id is held in the subnet_id_ member of Lease4
174 // class. Note that the subnet_id_ is defined in the base
175 // class (Lease) so we have to point to this class rather
176 // than derived class: Lease4.
177 boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
178 >
179 >,
180
181 // Specification of the third index starts here.
182 boost::multi_index::ordered_non_unique<
183 boost::multi_index::tag<ClientIdSubnetIdIndexTag>,
184 // This is a composite index that uses two values to search for a
185 // lease: client id and subnet id.
186 boost::multi_index::composite_key<
187 Lease4,
188 // The client id can be retrieved from the Lease4 object by
189 // calling getClientIdVector const function.
190 boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
192 // The subnet id is accessed through the subnet_id_ member.
193 boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_>
194 >
195 >,
196
197 // Specification of the fourth index starts here.
198 boost::multi_index::ordered_non_unique<
199 boost::multi_index::tag<ClientIdHWAddressSubnetIdIndexTag>,
200 // This is a composite index that uses three values to search for a
201 // lease: client id, HW address and subnet id.
202 boost::multi_index::composite_key<
203 Lease4,
204 // The client id can be retrieved from the Lease4 object by
205 // calling getClientIdVector const function.
206 boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
208 // The hardware address is held in the hwaddr_ object. We can
209 // access the raw data using lease->hwaddr_->hwaddr_, but Boost
210 // doesn't seem to provide a way to use member of a member for this,
211 // so we need a simple key extractor method (getHWAddrVector).
212 boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
214 // The subnet id is accessed through the subnet_id_ member.
215 boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
216 >
217 >,
218
219 // Specification of the fifth index starts here.
220 boost::multi_index::ordered_non_unique<
221 boost::multi_index::tag<ExpirationIndexTag>,
222 // This is a composite index that will be used to search for
223 // the expired leases. Depending on the value of the first component
224 // of the search key, the reclaimed or not reclaimed leases will can
225 // be searched.
226 boost::multi_index::composite_key<
227 Lease4,
228 // The boolean value specifying if lease is reclaimed or not.
229 boost::multi_index::const_mem_fun<Lease, bool,
231 // Lease expiration time.
232 boost::multi_index::const_mem_fun<Lease, int64_t,
234 >
235 >,
236
237 // Specification of the sixth index starts here.
238 // This index sorts leases by SubnetID.
239 boost::multi_index::ordered_non_unique<
240 boost::multi_index::tag<SubnetIdIndexTag>,
241 boost::multi_index::member<Lease, isc::dhcp::SubnetID, &Lease::subnet_id_>
242 >
243
244 >
245> Lease4Storage; // Specify the type name for this container.
246
248
251
252
254typedef Lease6Storage::index<AddressIndexTag>::type Lease6StorageAddressIndex;
255
257typedef Lease6Storage::index<DuidIaidTypeIndexTag>::type Lease6StorageDuidIaidTypeIndex;
258
260typedef Lease6Storage::index<ExpirationIndexTag>::type Lease6StorageExpirationIndex;
261
263typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;
264
266typedef Lease6Storage::index<DuidIndexTag>::type Lease6StorageDuidIndex;
267
269typedef Lease4Storage::index<AddressIndexTag>::type Lease4StorageAddressIndex;
270
272typedef Lease4Storage::index<ExpirationIndexTag>::type Lease4StorageExpirationIndex;
273
275typedef Lease4Storage::index<HWAddressSubnetIdIndexTag>::type
277
279typedef Lease4Storage::index<ClientIdSubnetIdIndexTag>::type
281
283typedef Lease4Storage::index<ClientIdHWAddressSubnetIdIndexTag>::type
285
287typedef Lease4Storage::index<SubnetIdIndexTag>::type Lease4StorageSubnetIdIndex;
288
290} // end of isc::dhcp namespace
291} // end of isc namespace
292
293#endif // MEMFILE_LEASE_STORAGE_H
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
Lease4Storage::index< ClientIdHWAddressSubnetIdIndexTag >::type Lease4StorageClientIdHWAddressSubnetIdIndex
DHCPv4 lease storage index by client id, HW address and subnet id.
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by Subnet-id.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:463
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client and subnet identifier.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
boost::multi_index_container< Lease4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HWAddressSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, const std::vector< uint8_t > &, &Lease::getHWAddrVector >, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ClientIdSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease4, const std::vector< uint8_t > &, &Lease4::getClientIdVector >, boost::multi_index::member< Lease, uint32_t, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ClientIdHWAddressSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease4, const std::vector< uint8_t > &, &Lease4::getClientIdVector >, boost::multi_index::const_mem_fun< Lease, const std::vector< uint8_t > &, &Lease::getHWAddrVector >, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > > > > Lease4Storage
A multi index container holding DHCPv4 leases.
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index by client id, HW address and subnet id.
boost::multi_index_container< Lease6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIaidTypeIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector >, boost::multi_index::member< Lease6, uint32_t, &Lease6::iaid_ >, boost::multi_index::member< Lease6, Lease::Type, &Lease6::type_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIndexTag >, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector > > > > Lease6Storage
A multi index container holding DHCPv6 leases.
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:248
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Tag for indexes by address.
Tag for indexes by client id, HW address and subnet id.
Tag for indexes by client and subnet identifiers.
Tag for indexes by DUID, IAID, lease type tuple.
Tag for index using DUID.
Tag for indexes by expiration time.
Tag for indexes by HW address, subnet identifier tuple.
Structure that holds a lease for IPv4 address.
Definition: lease.h:256
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:317
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:471
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:506
a common structure for IPv4 and IPv6 leases
Definition: lease.h:35
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:100
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:136
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:327
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:110
Tag for indexs by subnet-id.