Skip to content

Commit ee64ceb

Browse files
committed
[#28,!20] Implemented Config Backend pool for DHCPv4.
1 parent 3bc730d commit ee64ceb

File tree

5 files changed

+1138
-1
lines changed

5 files changed

+1138
-1
lines changed

src/lib/config_backend/base_config_backend_pool.h

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <database/backend_selector.h>
1313
#include <database/db_exceptions.h>
1414
#include <database/server_selector.h>
15+
#include <util/optional_value.h>
1516
#include <functional>
1617
#include <list>
1718
#include <string>
@@ -75,7 +76,7 @@ class BaseConfigBackendPool {
7576
/// const BackendSelector& selector,
7677
/// const ServerSelector& server_selector) const {
7778
/// Subnet4Ptr subnet;
78-
/// getPropertyPtrConst<Subnet4Ptr, const SubnetID&, ConfigBackendDHCPv4::getSubnet4>
79+
/// getPropertyPtrConst<Subnet4Ptr, const SubnetID&>
7980
/// (&ConfigBackendDHCPv4::getSubnet4, selector, subnet, subnet_id);
8081
/// return (subnet);
8182
/// }
@@ -142,6 +143,84 @@ class BaseConfigBackendPool {
142143
}
143144
}
144145

146+
/// @brief Retrieve a single value encapsulated in the @c OptionalValue
147+
/// template.
148+
///
149+
/// This is common method for retrieving a single configuration property
150+
/// from the databases. The property is encapsulated in the @c OptionalValue
151+
/// class. The value is set to "unspecified" if it is null in the database.
152+
/// The following is the example implementation of the method retrieving
153+
/// global conifguration value:
154+
///
155+
/// @code
156+
/// OptionalValue<std::string>
157+
/// getGlobalParameter4(const std::string& parameter_name,
158+
/// const BackendSelector& selector,
159+
/// const ServerSelector& server_selector) const {
160+
/// std::string parameter;
161+
/// getOptionalPropertyConst<std::string, const std::string&>
162+
/// (&ConfigBackendDHCPv4::getGlobalParameter4, selector, server_selector,
163+
/// parameter, parameter_name);
164+
/// return (parameter);
165+
/// }
166+
/// @endcode
167+
///
168+
/// where @c ConfigBackendDHCPv4::getGlobalParameter has the following signature:
169+
///
170+
/// @code
171+
/// std::string getGlobalParameter4(const ServerSelector&, const std::string&) const;
172+
/// @endcode
173+
///
174+
///
175+
/// @tparam PropertyType Type of the object returned by the backend call.
176+
/// @tparam InputType Type of the objects used as input to the backend call.
177+
///
178+
/// @param MethodPointer Pointer to the backend method to be called.
179+
/// @param selector Backend selector.
180+
/// @param server_selector Server selector.
181+
/// @param [out] property Reference to the shared pointer where retrieved
182+
/// property should be assigned.
183+
/// @param input Values to be used as input to the backend call.
184+
///
185+
/// @throw db::NoSuchDatabase if no database matching the given selector
186+
/// was found.
187+
template<typename PropertyType, typename... InputType>
188+
void getOptionalPropertyConst(util::OptionalValue<PropertyType>
189+
(ConfigBackendType::*MethodPointer)
190+
(const db::ServerSelector&, InputType...) const,
191+
const db::BackendSelector& selector,
192+
const db::ServerSelector& server_selector,
193+
util::OptionalValue<PropertyType>& property,
194+
InputType... input) const {
195+
196+
// If no particular backend is selected, call each backend and return
197+
// the first non-null (non zero) value.
198+
if (selector.amUnspecified()) {
199+
for (auto backend : backends_) {
200+
property = ((*backend).*MethodPointer)(server_selector, input...);
201+
if (property.isSpecified()) {
202+
break;
203+
}
204+
}
205+
206+
} else {
207+
// Backend selected, find the one that matches selection.
208+
auto backends = selectBackends(selector);
209+
if (!backends.empty()) {
210+
for (auto backend : backends) {
211+
property = ((*backend).*MethodPointer)(server_selector, input...);
212+
if (property.isSpecified()) {
213+
break;
214+
}
215+
}
216+
217+
} else {
218+
isc_throw(db::NoSuchDatabase, "no such database found for selector: "
219+
<< selector.toText());
220+
}
221+
}
222+
}
223+
145224
/// @brief Retrieve multiple configuration properties from the pool.
146225
///
147226
/// This is a common method for retrieving multiple configuration properties

src/lib/dhcpsrv/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ libkea_dhcpsrv_la_SOURCES += cfg_subnets6.cc cfg_subnets6.h
108108
libkea_dhcpsrv_la_SOURCES += cfg_mac_source.cc cfg_mac_source.h
109109
libkea_dhcpsrv_la_SOURCES += cfgmgr.cc cfgmgr.h
110110
libkea_dhcpsrv_la_SOURCES += client_class_def.cc client_class_def.h
111+
libkea_dhcpsrv_la_SOURCES += config_backend_dhcp4.h
112+
libkea_dhcpsrv_la_SOURCES += config_backend_pool_dhcp4.cc config_backend_pool_dhcp4.h
111113
libkea_dhcpsrv_la_SOURCES += csv_lease_file4.cc csv_lease_file4.h
112114
libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
113115
libkea_dhcpsrv_la_SOURCES += d2_client_cfg.cc d2_client_cfg.h
@@ -211,6 +213,7 @@ if HAVE_CQL
211213
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/cql/libkea-cql.la
212214
endif
213215

216+
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/config_backend/libkea-cb.la
214217
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/database/libkea-database.la
215218
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
216219
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la
@@ -270,6 +273,8 @@ libkea_dhcpsrv_include_HEADERS = \
270273
cfg_subnets6.h \
271274
cfgmgr.h \
272275
client_class_def.h \
276+
config_backend_dhcp4.h \
277+
config_backend_pool_dhcp4.h \
273278
csv_lease_file4.h \
274279
csv_lease_file6.h \
275280
dhcpsrv_exceptions.h \

0 commit comments

Comments
 (0)