ExpirationConfigParser::parse(ConstElementPtr expiration_config) {
CfgExpirationPtr cfg = CfgMgr::instance().getStagingCfg()->getCfgExpiration();
- BOOST_FOREACH(ConfigPair config_element, expiration_config->mapValue()) {
+ std::string param;
- // Get parameter name and value.
- std::string param_name = config_element.first;
- ConstElementPtr param_value = config_element.second;
-
- try {
- // Set configuration parameters.
- if (param_name == "reclaim-timer-wait-time") {
- cfg->setReclaimTimerWaitTime(param_value->intValue());
-
- } else if (param_name == "flush-reclaimed-timer-wait-time") {
- cfg->setFlushReclaimedTimerWaitTime(param_value->intValue());
-
- } else if (param_name == "hold-reclaimed-time") {
- cfg->setHoldReclaimedTime(param_value->intValue());
+ try {
+ param = "reclaim-timer-wait-time";
+ if (expiration_config->contains(param)) {
+ cfg->setReclaimTimerWaitTime(getInteger(expiration_config, param));
+ }
- } else if (param_name == "max-reclaim-leases") {
- cfg->setMaxReclaimLeases(param_value->intValue());
+ param = "flush-reclaimed-timer-wait-time";
+ if (expiration_config->contains(param)) {
+ cfg->setFlushReclaimedTimerWaitTime(getInteger(expiration_config,
+ param));
+ }
- } else if (param_name == "max-reclaim-time") {
- cfg->setMaxReclaimTime(param_value->intValue());
+ param = "hold-reclaimed-time";
+ if (expiration_config->contains(param)) {
+ cfg->setHoldReclaimedTime(getInteger(expiration_config, param));
+ }
- } else if (param_name == "unwarned-reclaim-cycles") {
- cfg->setUnwarnedReclaimCycles(param_value->intValue());
+ param = "max-reclaim-leases";
+ if (expiration_config->contains(param)) {
+ cfg->setMaxReclaimLeases(getInteger(expiration_config, param));
+ }
- } else {
- isc_throw(DhcpConfigError, "unsupported parameter '"
- << param_name << "'");
- }
+ param = "max-reclaim-time";
+ if (expiration_config->contains(param)) {
+ cfg->setMaxReclaimTime(getInteger(expiration_config, param));
+ }
- } catch (const std::exception& ex) {
- // Append position of the configuration parameter to the error
- // message.
- isc_throw(DhcpConfigError, ex.what() << " ("
- << param_value->getPosition() << ")");
+ param = "unwarned-reclaim-cycles";
+ if (expiration_config->contains(param)) {
+ cfg->setUnwarnedReclaimCycles(
+ getInteger(expiration_config, param));
}
+ } catch (const DhcpConfigError&) {
+ throw;
+ } catch (const std::exception& ex) {
+ // Append position of the configuration parameter to the error message.
+ isc_throw(DhcpConfigError, ex.what() << " ("
+ << getPosition(param, expiration_config) << ")");
}
}
EXPECT_EQ(20, cfg->getUnwarnedReclaimCycles());
}
-// This test verifies that the exception is thrown if unsupported
-// parameter is specified.
-TEST_F(ExpirationConfigParserTest, invalidParameter) {
- addParam("reclaim-timer-wait-time", 20);
- addParam("invalid-parameter", 20);
-
- EXPECT_THROW(renderConfig(), DhcpConfigError);
-}
-
// This test verifies that negative parameter values are not allowed.
TEST_F(ExpirationConfigParserTest, outOfRangeValues) {
testOutOfRange("reclaim-timer-wait-time",