Skip to content

Commit 00d2434

Browse files
author
Razvan Becheriu
committed
[#3944] add support for CB global scalar lists
1 parent 9bc3a19 commit 00d2434

30 files changed

+232
-98
lines changed

doc/sphinx/arm/dhcp4-srv.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8569,6 +8569,16 @@ Some scalar parameters contained by top-level global maps are supported by the c
85698569
| dhcp-queue-control.capacity | dhcp-queue-control | capacity |
85708570
+------------------------------------------------------------------+------------------------------+----------------------------------+
85718571

8572+
Some scalar parameters contained by top-level global list are supported by the configuration backend.
8573+
8574+
.. table:: List of DHCPv4 list parameters supported by the configuration backend
8575+
8576+
+------------------------------------------------------------------+
8577+
| Parameter name | List container parameter type |
8578+
+==================================================================+
8579+
| host-reservation-identifiers | string |
8580+
+------------------------------------------------------------------+
8581+
85728582
.. _dhcp4-cb-json:
85738583

85748584
Enabling the Configuration Backend

doc/sphinx/arm/dhcp6-srv.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8404,6 +8404,16 @@ Some scalar parameters contained by top level global maps are supported by the c
84048404
| dhcp-queue-control.capacity | dhcp-queue-control | capacity |
84058405
+------------------------------------------------------------------+------------------------------+----------------------------------+
84068406

8407+
Some scalar parameters contained by top-level global list are supported by the configuration backend.
8408+
8409+
.. table:: List of DHCPv6 list parameters supported by the configuration backend
8410+
8411+
+------------------------------------------------------------------+
8412+
| Parameter name | List container parameter type |
8413+
+==================================================================+
8414+
| host-reservation-identifiers | string |
8415+
+------------------------------------------------------------------+
8416+
84078417
.. _dhcp6-cb-json:
84088418

84098419
Enabling the Configuration Backend

src/bin/dhcp4/json_config_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ processDhcp4Config(isc::data::ConstElementPtr config_set) {
459459
mutable_cfg->get("host-reservation-identifiers");
460460
if (hr_identifiers) {
461461
parameter_name = "host-reservation-identifiers";
462-
HostReservationIdsParser4 parser;
462+
HostReservationIdsParser4 parser(srv_config->getCfgHostOperations4());
463463
parser.parse(hr_identifiers);
464464
}
465465

src/bin/dhcp4/tests/config_backend_unittest.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ TEST_F(Dhcp4CBTest, mergeGlobals) {
194194
StampedValuePtr renew_timer(new StampedValue("renew-timer", Element::create(500)));
195195
StampedValuePtr mt_enabled(new StampedValue("multi-threading.enable-multi-threading", Element::create(true)));
196196
StampedValuePtr mt_pool_size(new StampedValue("multi-threading.thread-pool-size", Element::create(256)));
197+
StampedValuePtr hr_identifiers(new StampedValue("host-reservation-identifiers", "[ \"hw-address\", \"flex-id\" ]"));
197198

198199
// Let's add all of the globals to the second backend. This will verify
199200
// we find them there.
@@ -204,6 +205,7 @@ TEST_F(Dhcp4CBTest, mergeGlobals) {
204205
db2_->createUpdateGlobalParameter4(ServerSelector::ALL(), renew_timer);
205206
db2_->createUpdateGlobalParameter4(ServerSelector::ALL(), mt_enabled);
206207
db2_->createUpdateGlobalParameter4(ServerSelector::ALL(), mt_pool_size);
208+
db2_->createUpdateGlobalParameter4(ServerSelector::ALL(), hr_identifiers);
207209

208210
// Should parse and merge without error.
209211
ASSERT_NO_FATAL_FAILURE(configure(base_config, CONTROL_RESULT_SUCCESS, ""));
@@ -233,6 +235,12 @@ TEST_F(Dhcp4CBTest, mergeGlobals) {
233235
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, renew_timer));
234236
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, mt_enabled));
235237
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, mt_pool_size));
238+
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, hr_identifiers, true));
239+
240+
auto const& ex_hr_i = staging_cfg->getCfgHostOperations4()->getIdentifierTypes();
241+
EXPECT_EQ(ex_hr_i.size(), 2);
242+
EXPECT_EQ(ex_hr_i.front(), Host::IDENT_HWADDR);
243+
EXPECT_EQ(ex_hr_i.back(), Host::IDENT_FLEX);
236244
}
237245

238246
// This test verifies that externally configured option definitions

src/bin/dhcp6/json_config_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ processDhcp6Config(isc::data::ConstElementPtr config_set) {
561561
mutable_cfg->get("host-reservation-identifiers");
562562
if (hr_identifiers) {
563563
parameter_name = "host-reservation-identifiers";
564-
HostReservationIdsParser6 parser;
564+
HostReservationIdsParser6 parser(srv_config->getCfgHostOperations6());
565565
parser.parse(hr_identifiers);
566566
}
567567

src/bin/dhcp6/tests/config_backend_unittest.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ TEST_F(Dhcp6CBTest, mergeGlobals) {
194194
StampedValuePtr renew_timer(new StampedValue("renew-timer", Element::create(500)));
195195
StampedValuePtr mt_enabled(new StampedValue("multi-threading.enable-multi-threading", Element::create(true)));
196196
StampedValuePtr mt_pool_size(new StampedValue("multi-threading.thread-pool-size", Element::create(256)));
197+
StampedValuePtr hr_identifiers(new StampedValue("host-reservation-identifiers", "[ \"hw-address\", \"flex-id\" ]"));
197198

198199
// Let's add all of the globals to the second backend. This will verify
199200
// we find them there.
@@ -202,6 +203,7 @@ TEST_F(Dhcp6CBTest, mergeGlobals) {
202203
db2_->createUpdateGlobalParameter6(ServerSelector::ALL(), renew_timer);
203204
db2_->createUpdateGlobalParameter6(ServerSelector::ALL(), mt_enabled);
204205
db2_->createUpdateGlobalParameter6(ServerSelector::ALL(), mt_pool_size);
206+
db2_->createUpdateGlobalParameter6(ServerSelector::ALL(), hr_identifiers);
205207

206208
// Should parse and merge without error.
207209
ASSERT_NO_FATAL_FAILURE(configure(base_config, CONTROL_RESULT_SUCCESS, ""));
@@ -225,6 +227,12 @@ TEST_F(Dhcp6CBTest, mergeGlobals) {
225227
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, renew_timer));
226228
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, mt_enabled));
227229
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, mt_pool_size));
230+
ASSERT_NO_FATAL_FAILURE(checkConfiguredGlobal(staging_cfg, hr_identifiers, true));
231+
232+
auto const& ex_hr_i = staging_cfg->getCfgHostOperations6()->getIdentifierTypes();
233+
EXPECT_EQ(ex_hr_i.size(), 2);
234+
EXPECT_EQ(ex_hr_i.front(), Host::IDENT_HWADDR);
235+
EXPECT_EQ(ex_hr_i.back(), Host::IDENT_FLEX);
228236
}
229237

230238
// This test verifies that externally configured option definitions

src/bin/dhcp6/tests/parser_unittest.cc

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -299,34 +299,33 @@ void testFile(const std::string& fname) {
299299
// twice: first with the existing Element::fromJSONFile() and then
300300
// the second time with Parser6. Both JSON trees are then compared.
301301
TEST(ParserTest, file) {
302-
vector<string> configs;
303-
configs.push_back("advanced.json");
304-
configs.push_back("all-keys.json");
305-
configs.push_back("all-options.json");
306-
configs.push_back("backends.json");
307-
configs.push_back("classify.json");
308-
configs.push_back("classify2.json");
309-
configs.push_back("comments.json");
310-
configs.push_back("config-backend.json");
311-
configs.push_back("dhcpv4-over-dhcpv6.json");
312-
configs.push_back("duid.json");
313-
configs.push_back("global-reservations.json");
314-
configs.push_back("ha-hot-standby-server1-with-tls.json");
315-
configs.push_back("ha-hot-standby-server2.json");
316-
configs.push_back("hooks.json");
317-
configs.push_back("iPXE.json");
318-
configs.push_back("leases-expiration.json");
319-
configs.push_back("multiple-options.json");
320-
configs.push_back("mysql-reservations.json");
321-
configs.push_back("pgsql-reservations.json");
322-
configs.push_back("reservations.json");
323-
configs.push_back("several-subnets.json");
324-
configs.push_back("shared-network.json");
325-
configs.push_back("simple.json");
326-
configs.push_back("softwire46.json");
327-
configs.push_back("stateless.json");
328-
configs.push_back("tee-times.json");
329-
configs.push_back("with-ddns.json");
302+
vector<string> configs = { "advanced.json",
303+
"all-keys.json",
304+
"all-options.json",
305+
"backends.json",
306+
"classify.json",
307+
"classify2.json",
308+
"comments.json",
309+
"config-backend.json",
310+
"dhcpv4-over-dhcpv6.json",
311+
"duid.json",
312+
"global-reservations.json",
313+
"ha-hot-standby-server1-with-tls.json",
314+
"ha-hot-standby-server2.json",
315+
"hooks.json",
316+
"iPXE.json",
317+
"leases-expiration.json",
318+
"multiple-options.json",
319+
"mysql-reservations.json",
320+
"pgsql-reservations.json",
321+
"reservations.json",
322+
"several-subnets.json",
323+
"shared-network.json",
324+
"simple.json",
325+
"softwire46.json",
326+
"stateless.json",
327+
"tee-times.json",
328+
"with-ddns.json" };
330329

331330
for (unsigned i = 0; i<configs.size(); i++) {
332331
testFile(string(CFG_EXAMPLES) + "/" + configs[i]);

src/lib/dhcpsrv/cb_ctl_dhcp.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,45 @@ class CBControlDHCP : public process::CBControlBase<ConfigBackendMgrType> {
6060

6161
/// @brief It translates the top level map parameters from flat naming
6262
/// format (e.g. param-name.sub-param-name) to proper ElementMap objects and
63-
/// adds all globals fetched from config backend(s) to a SrvConfig instance
63+
/// adds all globals fetched from config backend(s) to a SrvConfig instance.
64+
/// The top level list parameters are converted from StringElement objects to
65+
/// ListElement objects.
6466
///
6567
/// Iterates over the given collection of global parameters and adds them to
6668
/// the given configuration's list of configured globals.
6769
///
68-
///
6970
/// @param external_cfg SrvConfig instance to update
7071
/// @param cb_globals collection of global parameters supplied by configuration
7172
/// backend
73+
/// @param global_lists All keywords matching supported global list parameters.
7274
void translateAndAddGlobalsToConfig(SrvConfigPtr external_cfg,
73-
data::StampedValueCollection& cb_globals) const {
75+
data::StampedValueCollection& cb_globals,
76+
data::SimpleKeywords global_lists) const {
7477
auto const& index = cb_globals.get<data::StampedValueNameIndexTag>();
7578
for (auto const& cb_global : index) {
76-
7779
if (cb_global->amNull()) {
7880
continue;
7981
}
80-
82+
data::ConstElementPtr value = cb_global->getElementValue();
83+
// All ListElement parameters must be converted from StringElement
84+
// (used by CB to store global list parameters).
85+
data::ElementPtr mutable_value = boost::const_pointer_cast<data::Element>(value);
86+
if (global_lists.count(cb_global->getName())) {
87+
mutable_value = data::Element::fromJSON(value->stringValue());
88+
}
89+
data::ConstElementPtr global_value = boost::const_pointer_cast<data::Element>(mutable_value);
8190
std::string param_name;
8291
std::string sub_param_name;
8392
if (translateName(cb_global->getName(), param_name, sub_param_name)) {
8493
data::ElementPtr sub_param = boost::const_pointer_cast<data::Element>(external_cfg->getConfiguredGlobal(param_name));
8594
if (!sub_param) {
8695
sub_param = data::Element::createMap();
8796
}
88-
sub_param->set(sub_param_name, cb_global->getElementValue());
97+
sub_param->set(sub_param_name, global_value);
8998
external_cfg->addConfiguredGlobal(param_name, sub_param);
9099
} else {
91100
// Reuse name and value.
92-
external_cfg->addConfiguredGlobal(param_name, cb_global->getElementValue());
101+
external_cfg->addConfiguredGlobal(param_name, global_value);
93102
}
94103
}
95104
}

src/lib/dhcpsrv/cb_ctl_dhcp4.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector,
7979
// database query and the number of global parameters is small.
8080
data::StampedValueCollection globals;
8181
globals = getMgr().getPool()->getAllGlobalParameters4(backend_selector, server_selector);
82-
translateAndAddGlobalsToConfig(external_cfg, globals);
82+
translateAndAddGlobalsToConfig(external_cfg, globals, SimpleParser4::GLOBAL4_LIST_PARAMETERS);
8383

8484
// Add defaults.
8585
external_cfg->applyDefaultsConfiguredGlobals(SimpleParser4::GLOBAL4_DEFAULTS);
@@ -166,7 +166,7 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector,
166166
data::StampedValueCollection globals;
167167
globals = getMgr().getPool()->getModifiedGlobalParameters4(backend_selector, server_selector,
168168
lb_modification_time);
169-
translateAndAddGlobalsToConfig(external_cfg, globals);
169+
translateAndAddGlobalsToConfig(external_cfg, globals, SimpleParser4::GLOBAL4_LIST_PARAMETERS);
170170
globals_fetched = true;
171171
}
172172
}

src/lib/dhcpsrv/cb_ctl_dhcp6.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector
7777
// database query and the number of global parameters is small.
7878
data::StampedValueCollection globals;
7979
globals = getMgr().getPool()->getAllGlobalParameters6(backend_selector, server_selector);
80-
translateAndAddGlobalsToConfig(external_cfg, globals);
80+
translateAndAddGlobalsToConfig(external_cfg, globals, SimpleParser6::GLOBAL6_LIST_PARAMETERS);
8181

8282
// Add defaults.
8383
external_cfg->applyDefaultsConfiguredGlobals(SimpleParser6::GLOBAL6_DEFAULTS);
@@ -165,7 +165,7 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector
165165
data::StampedValueCollection globals;
166166
globals = getMgr().getPool()->getModifiedGlobalParameters6(backend_selector, server_selector,
167167
lb_modification_time);
168-
translateAndAddGlobalsToConfig(external_cfg, globals);
168+
translateAndAddGlobalsToConfig(external_cfg, globals, SimpleParser6::GLOBAL6_LIST_PARAMETERS);
169169
globals_fetched = true;
170170
}
171171
}

0 commit comments

Comments
 (0)