(config_pair.first == "shared-networks") ||
(config_pair.first == "reservations") ||
(config_pair.first == "config-control") ||
+ (config_pair.first == "loggers") ||
(config_pair.first == "compatibility")) {
continue;
}
(config_pair.first == "t2-percent") ||
(config_pair.first == "cache-threshold") ||
(config_pair.first == "cache-max-age") ||
- (config_pair.first == "loggers") ||
(config_pair.first == "hostname-char-set") ||
(config_pair.first == "hostname-char-replacement") ||
(config_pair.first == "ddns-send-updates") ||
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
ASSERT_TRUE(subnet);
// Reset the fetch global function to staging (vs current) config.
- subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_EQ("1.2.3.4", subnet->getSiaddr().get().toText());
Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet1);
// Reset the fetch global function to staging (vs current) config.
- subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_TRUE(subnet1->getMatchClientId());
Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet2);
// Reset the fetch global function to staging (vs current) config.
- subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet2->getMatchClientId());
Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet1);
// Reset the fetch global function to staging (vs current) config.
- subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet1->getMatchClientId());
Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet2);
// Reset the fetch global function to staging (vs current) config.
- subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_TRUE(subnet2->getMatchClientId());
Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet1);
// Reset the fetch global function to staging (vs current) config.
- subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_TRUE(subnet1->getAuthoritative());
Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet2);
// Reset the fetch global function to staging (vs current) config.
- subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet2->getAuthoritative());
Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet1);
// Reset the fetch global function to staging (vs current) config.
- subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet1->getAuthoritative());
Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet2);
// Reset the fetch global function to staging (vs current) config.
- subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_TRUE(subnet2->getAuthoritative());
subnet = subnets->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet);
// Reset the fetch global function to staging (vs current) config.
- subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet->getReservationsGlobal());
subnet = subnets->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet);
// Reset the fetch global function to staging (vs current) config.
- subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet->getReservationsGlobal());
Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet1);
// Reset the fetch global function to staging (vs current) config.
- subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_TRUE(subnet1->getStoreExtendedInfo());
Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet2);
// Reset the fetch global function to staging (vs current) config.
- subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet2->getStoreExtendedInfo());
Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
ASSERT_TRUE(subnet1);
// Reset the fetch global function to staging (vs current) config.
- subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_FALSE(subnet1->getStoreExtendedInfo());
Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
ASSERT_TRUE(subnet2);
// Reset the fetch global function to staging (vs current) config.
- subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
});
EXPECT_TRUE(subnet2->getStoreExtendedInfo());
(config_pair.first == "reservations") ||
(config_pair.first == "config-control") ||
(config_pair.first == "relay-supplied-options") ||
+ (config_pair.first == "loggers") ||
(config_pair.first == "compatibility")) {
continue;
}
(config_pair.first == "t2-percent") ||
(config_pair.first == "cache-threshold") ||
(config_pair.first == "cache-max-age") ||
- (config_pair.first == "loggers") ||
(config_pair.first == "hostname-char-set") ||
(config_pair.first == "hostname-char-replacement") ||
(config_pair.first == "ddns-send-updates") ||
// In order to take advantage of the dynamic inheritance of global
// parameters to a shared network we need to set a callback function
// for each network to allow for fetching global parameters.
- (*network)->setFetchGlobalsFn([] () -> ConstElementPtr {
+ (*network)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
external_cfg->getCfgSharedNetworks4()->add((*network));
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- (*subnet)->setFetchGlobalsFn([] () -> ConstElementPtr {
+ (*subnet)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
external_cfg->getCfgSubnets4()->add((*subnet));
// In order to take advantage of the dynamic inheritance of global
// parameters to a shared network we need to set a callback function
// for each network to allow for fetching global parameters.
- (*network)->setFetchGlobalsFn([] () -> ConstElementPtr {
+ (*network)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
external_cfg->getCfgSharedNetworks6()->add((*network));
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- (*subnet)->setFetchGlobalsFn([] () -> ConstElementPtr {
+ (*subnet)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
external_cfg->getCfgSubnets6()->add((*subnet));
{ "renew-timer", RENEW_TIMER },
{ "rebind-timer", REBIND_TIMER },
{ "decline-probation-period", DECLINE_PROBATION_PERIOD },
- { "shared-networks", SHARED_NETWORKS },
- { "interfaces-config", INTERFACES_CONFIG },
- { "lease-database", LEASE_DATABASE },
- { "hosts-database", HOSTS_DATABASE },
- { "hosts-databases", HOSTS_DATABASES },
- { "host-reservation-identifiers", HOST_RESERVATION_IDENTIFIERS },
- { "client-classes", CLIENT_CLASSES },
- { "option-def", OPTION_DEF },
- { "option-data", OPTION_DATA },
- { "hooks-libraries", HOOKS_LIBRARIES },
- { "expired-leases-processing", EXPIRED_LEASES_PROCESSING },
{ "dhcp4o6-port", DHCP4O6_PORT },
- { "control-socket", CONTROL_SOCKET },
- { "dhcp-queue-control", DHCP_QUEUE_CONTROL },
- { "dhcp-ddns", DHCP_DDNS },
- { "user-context", USER_CONTEXT },
{ "comment", COMMENT },
- { "sanity-checks", SANITY_CHECKS },
- { "reservations", RESERVATIONS },
- { "config-control", CONFIG_CONTROL },
{ "server-tag", SERVER_TAG },
{ "reservation-mode", RESERVATION_MODE },
{ "reservations-global", RESERVATIONS_GLOBAL },
{ "calculate-tee-times", CALCULATE_TEE_TIMES },
{ "t1-percent", T1_PERCENT },
{ "t2-percent", T2_PERCENT },
- { "loggers", LOGGERS },
{ "hostname-char-set", HOSTNAME_CHAR_SET },
{ "hostname-char-replacement", HOSTNAME_CHAR_REPLACEMENT },
{ "ddns-send-updates", DDNS_SEND_UPDATES },
{ "store-extended-info", STORE_EXTENDED_INFO },
{ "statistic-default-sample-count", STATISTIC_DEFAULT_SAMPLE_COUNT },
{ "statistic-default-sample-age", STATISTIC_DEFAULT_SAMPLE_AGE },
- { "multi-threading", MULTI_THREADING },
{ "cache-threshold", CACHE_THRESHOLD },
{ "cache-max-age", CACHE_MAX_AGE },
{ "ip-reservations-unique", IP_RESERVATIONS_UNIQUE },
{ "ddns-use-conflict-resolution", DDNS_USE_CONFLICT_RESOLUTION },
// DHCPv4 specific parameters.
- { "subnet4", SUBNET4 },
{ "echo-client-id", ECHO_CLIENT_ID },
{ "match-client-id", MATCH_CLIENT_ID },
{ "authoritative", AUTHORITATIVE },
{ "data-directory", DATA_DIRECTORY },
{ "preferred-lifetime", PREFERRED_LIFETIME },
{ "min-preferred-lifetime", MIN_PREFERRED_LIFETIME },
- { "max-preferred-lifetime", MAX_PREFERRED_LIFETIME },
- { "subnet6", SUBNET6 },
- { "mac-sources", MAC_SOURCES },
- { "relay-supplied-options", RELAY_SUPPLIED_OPTIONS },
- { "server-id", SERVER_ID }
+ { "max-preferred-lifetime", MAX_PREFERRED_LIFETIME }
};
// Load time sanity check.
}
}
+const CfgGlobals::MapType
+CfgGlobals::valuesMap() const {
+ MapType map;
+ for (auto it = nameToIndex.cbegin(); it != nameToIndex.cend(); ++it) {
+ int idx = it->second;
+ ConstElementPtr value = values_[idx];
+ if (value) {
+ map.insert(make_pair(it->first, value));
+ }
+ }
+ return (map);
+}
+
ElementPtr
CfgGlobals::toElement() const {
ElementPtr result = Element::createMap();
RENEW_TIMER,
REBIND_TIMER,
DECLINE_PROBATION_PERIOD,
- SHARED_NETWORKS,
- INTERFACES_CONFIG,
- LEASE_DATABASE,
- HOSTS_DATABASE,
- HOSTS_DATABASES,
- HOST_RESERVATION_IDENTIFIERS,
- CLIENT_CLASSES,
- OPTION_DEF,
- OPTION_DATA,
- HOOKS_LIBRARIES,
- EXPIRED_LEASES_PROCESSING,
DHCP4O6_PORT,
- CONTROL_SOCKET,
- DHCP_QUEUE_CONTROL,
- DHCP_DDNS,
- USER_CONTEXT,
COMMENT,
- SANITY_CHECKS,
- RESERVATIONS,
- CONFIG_CONTROL,
SERVER_TAG,
RESERVATION_MODE,
RESERVATIONS_GLOBAL,
CALCULATE_TEE_TIMES,
T1_PERCENT,
T2_PERCENT,
- LOGGERS,
HOSTNAME_CHAR_SET,
HOSTNAME_CHAR_REPLACEMENT,
DDNS_SEND_UPDATES,
STORE_EXTENDED_INFO,
STATISTIC_DEFAULT_SAMPLE_COUNT,
STATISTIC_DEFAULT_SAMPLE_AGE,
- MULTI_THREADING,
CACHE_THRESHOLD,
CACHE_MAX_AGE,
IP_RESERVATIONS_UNIQUE,
DDNS_USE_CONFLICT_RESOLUTION,
// DHCPv4 specific parameters.
- SUBNET4,
ECHO_CLIENT_ID,
MATCH_CLIENT_ID,
AUTHORITATIVE,
DATA_DIRECTORY,
PREFERRED_LIFETIME,
MIN_PREFERRED_LIFETIME,
- MAX_PREFERRED_LIFETIME,
- SUBNET6,
- MAC_SOURCES,
- RELAY_SUPPLIED_OPTIONS,
- SERVER_ID
+ MAX_PREFERRED_LIFETIME
};
/// @brief Last index.
///
/// @note: please update when a new element is appended to the Index enum.
- static const int MAX_INDEX = SERVER_ID;
+ static const int MAX_INDEX = MAX_PREFERRED_LIFETIME;
/// @brief Size of configured global objects.
static const size_t SIZE = MAX_INDEX + 1;
/// @brief Clear configured parameter values.
void clear();
- /// @brief Unparse configured globals.
+ /// @brief Type of name and value map.
+ typedef std::map<std::string, isc::data::ConstElementPtr> MapType;
+
+ /// @brief Returns configured parameters as a map.
+ ///
+ /// @note: the map includes only set global parameters i.e.
+ /// ConstElementPtr values are never null.
+ const MapType valuesMap() const;
+
+ /// @brief Unparse configured global parameters.
///
- /// @return a pointer to unparsed globals.
+ /// @return a pointer to unparsed global parameters.
isc::data::ElementPtr toElement() const;
protected:
std::vector<isc::data::ConstElementPtr> values_;
};
-/// @brief Shared pointer to a CfgGlobals instance.
+/// @brief Non-const shared pointer to a CfgGlobals instance.
typedef boost::shared_ptr<CfgGlobals> CfgGlobalsPtr;
+/// @brief Const shared pointer to a CfgGlobals instance.
+typedef boost::shared_ptr<const CfgGlobals> ConstCfgGlobalsPtr;
+
} // namespace isc::dhcp
} // namespace isc
#include <cc/cfg_to_element.h>
#include <cc/user_context.h>
#include <dhcp_ddns/ncr_io.h>
+#include <dhcpsrv/cfg_globals.h>
#include <exceptions/exceptions.h>
#include <util/optional.h>
/// @brief Callback function for @c D2ClientConfig that retrieves globally
/// configured parameters.
-typedef std::function<data::ConstElementPtr()> FetchNetworkGlobalsFn;
+typedef std::function<ConstCfgGlobalsPtr()> FetchNetworkGlobalsFn;
/// @brief Acts as a storage vault for D2 client configuration
const std::string& /*min_name*/,
const std::string& /*max_name*/) const {
if (!global_name.empty() && fetch_globals_fn_) {
- ConstElementPtr globals = fetch_globals_fn_();
- if (globals && (globals->getType() == Element::map)) {
+ ConstCfgGlobalsPtr globals = fetch_globals_fn_();
+ if (globals) {
ConstElementPtr global_param = globals->get(global_name);
if (global_param) {
std::string global_str = global_param->stringValue();
#include <cc/user_context.h>
#include <dhcp/classify.h>
#include <dhcp/option.h>
+#include <dhcpsrv/cfg_globals.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfg_4o6.h>
#include <dhcpsrv/d2_client_cfg.h>
/// @brief Callback function for @c Network that retrieves globally
/// configured parameters.
-typedef std::function<data::ConstElementPtr()> FetchNetworkGlobalsFn;
+typedef std::function<ConstCfgGlobalsPtr()> FetchNetworkGlobalsFn;
/// @brief Common interface representing a network to which the DHCP clients
/// are connected.
const std::string& max_name = "") const {
unused(min_name, max_name);
if (!global_name.empty() && fetch_globals_fn_) {
- data::ConstElementPtr globals = fetch_globals_fn_();
- if (globals && (globals->getType() == data::Element::map)) {
+ ConstCfgGlobalsPtr globals = fetch_globals_fn_();
+ if (globals) {
data::ConstElementPtr global_param = globals->get(global_name);
if (global_param) {
// If there is a global parameter, convert it to the
const std::string& max_name = "") const {
if (!global_name.empty() && fetch_globals_fn_) {
- data::ConstElementPtr globals = fetch_globals_fn_();
- if (globals && (globals->getType() == data::Element::map)) {
+ ConstCfgGlobalsPtr globals = fetch_globals_fn_();
+ if (globals) {
data::ConstElementPtr param = globals->get(global_name);
if (param) {
NumType def_value = static_cast<NumType>(param->intValue());
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- subnet_->setFetchGlobalsFn([]() -> ConstElementPtr {
+ subnet_->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
}
// In order to take advantage of the dynamic inheritance of global
// parameters to a shared network we need to set a callback function
// for each shared network to allow for fetching global parameters.
- shared_network->setFetchGlobalsFn([]() -> ConstElementPtr {
+ shared_network->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
// In order to take advantage of the dynamic inheritance of global
// parameters to a shared network we need to set a callback function
// for each shared network which can be used to fetch global parameters.
- shared_network->setFetchGlobalsFn([]() -> ConstElementPtr {
+ shared_network->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
});
class_dictionary_(new ClientClassDictionary()),
decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0),
d2_client_config_(new D2ClientConfig()),
- configured_globals_(Element::createMap()),
+ configured_globals_(new CfgGlobals()),
cfg_consist_(new CfgConsistency()),
lenient_option_parsing_(false) {
}
class_dictionary_(new ClientClassDictionary()),
decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0),
d2_client_config_(new D2ClientConfig()),
- configured_globals_(Element::createMap()),
+ configured_globals_(new CfgGlobals()),
cfg_consist_(new CfgConsistency()),
lenient_option_parsing_(false) {
}
}
// Iterate over the "other" globals, adding/overwriting them into
// this config's list of globals.
- for (auto other_global : other.getConfiguredGlobals()->mapValue()) {
+ for (auto other_global : other.getConfiguredGlobals()->valuesMap()) {
addConfiguredGlobal(other_global.first, other_global.second);
}
BaseNetworkParser::moveReservationMode(mutable_cfg);
// A handful of values are stored as members in SrvConfig. So we'll
- // iterate over the merged globals, setting appropriate members.
- for (auto merged_global : config_set->mapValue()) {
+ // iterate over the merged globals, setting approprate members.
+ for (auto merged_global : getConfiguredGlobals()->valuesMap()) {
std::string name = merged_global.first;
ConstElementPtr element = merged_global.second;
try {
}
}
-isc::data::ConstElementPtr
-SrvConfig::getConfiguredGlobal(std::string name) const {
- isc::data::ConstElementPtr global;
- if (configured_globals_->contains(name)) {
- global = configured_globals_->get(name);
- }
-
- return (global);
-}
-
-void
-SrvConfig::clearConfiguredGlobals() {
- configured_globals_ = isc::data::Element::createMap();
-}
-
void
SrvConfig::applyDefaultsConfiguredGlobals(const SimpleDefaults& defaults) {
// Code from SimpleParser::setDefaults
// we're inserting here are not present in whatever the config file
// came from, we need to make sure it's clearly labeled as default.
const Element::Position pos("<default-value>", 0, 0);
- ConstElementPtr globals = getConfiguredGlobals();
// Let's go over all parameters we have defaults for.
for (auto def_value : defaults) {
// Try if such a parameter is there. If it is, let's
// skip it, because user knows best *cough*.
- ConstElementPtr x = globals->get(def_value.name_);
+ ConstElementPtr x = getConfiguredGlobal(def_value.name_);
if (x) {
// There is such a value already, skip it.
continue;
// Get family for the configuration manager
uint16_t family = CfgMgr::instance().getFamily();
- // DhcpX global map
- ElementPtr dhcp = ConfigBase::toElement();
- // Add in explicitly configured globals.
- dhcp->setValue(configured_globals_->mapValue());
+ // DhcpX global map initialiazed from configured globals
+ ElementPtr dhcp = configured_globals_->toElement();
// Set user-context
contextToElement(dhcp);
#include <dhcpsrv/cfg_db_access.h>
#include <dhcpsrv/cfg_duid.h>
#include <dhcpsrv/cfg_expiration.h>
+#include <dhcpsrv/cfg_globals.h>
#include <dhcpsrv/cfg_host_operations.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_iface.h>
d2_client_config_ = d2_client_config;
}
- /// @brief Returns pointer to configured global parameters
- isc::data::ConstElementPtr getConfiguredGlobals() const {
- return (isc::data::ConstElementPtr(configured_globals_));
+ /// @brief Returns non-const pointer to configured global parameters.
+ ///
+ /// This function returns a non-const pointer to the configured
+ /// global parameters.
+ ///
+ /// @return Object representing configured global parameters.
+ CfgGlobalsPtr getConfiguredGlobals() {
+ return (configured_globals_);
+ }
+
+ /// @brief Returns const pointer to configured global parameters.
+ ///
+ /// This function returns a onst pointer to the configured
+ /// global parameters.
+ ///
+ /// @return Object representing configured global parameters.
+ ConstCfgGlobalsPtr getConfiguredGlobals() const {
+ return (configured_globals_);
}
/// @brief Returns pointer to a given configured global parameter
/// @param name name of the parameter to fetch
/// @return Pointer to the parameter if it exists, otherwise an
/// empty pointer.
- isc::data::ConstElementPtr getConfiguredGlobal(std::string name) const;
+ isc::data::ConstElementPtr getConfiguredGlobal(std::string name) const {
+ return (configured_globals_->get(name));
+ }
+
+ /// @brief Returns pointer to a given configured global parameter
+ /// @param index index of the parameter to fetch
+ /// @return Pointer to the parameter if it exists, otherwise an
+ /// empty pointer.
+ isc::data::ConstElementPtr getConfiguredGlobal(int index) const {
+ return (configured_globals_->get(index));
+ }
/// @brief Removes all configured global parameters.
/// @note This removes the default values too so either
/// @c applyDefaultsConfiguredGlobals and @c mergeGlobals,
/// or @c isc::data::SimpleParser::setDefaults and
/// @c extractConfiguredGlobals should be called after.
- void clearConfiguredGlobals();
+ void clearConfiguredGlobals() {
+ configured_globals_->clear();
+ }
/// @brief Applies defaults to global parameters.
/// @param defaults vector of (name, type, value) defaults to apply.
D2ClientConfigPtr d2_client_config_;
/// @brief Stores the global parameters specified via configuration
- isc::data::ElementPtr configured_globals_;
+ CfgGlobalsPtr configured_globals_;
/// @brief Pointer to the configuration consistency settings
CfgConsistencyPtr cfg_consist_;
public:
/// @brief Constructor.
- NetworkTest()
- : globals_(Element::createMap()) {
+ NetworkTest() : globals_(new CfgGlobals()) {
}
/// @brief Returns pointer to the function which returns configured
}
/// @brief Returns configured global parameters.
- ConstElementPtr fetchGlobalsFn() {
+ ConstCfgGlobalsPtr fetchGlobalsFn() {
return (globals_);
}
}
/// @brief Holds the collection of configured globals.
- ElementPtr globals_;
+ CfgGlobalsPtr globals_;
};
// This test verifies that the inheritance is supported for certain
SrvConfig conf(32);
// The map of configured globals should be empty.
- ConstElementPtr srv_globals = conf.getConfiguredGlobals();
+ ConstCfgGlobalsPtr srv_globals = conf.getConfiguredGlobals();
ASSERT_TRUE(srv_globals);
- ASSERT_EQ(Element::map, srv_globals->getType());
- ASSERT_TRUE(srv_globals->mapValue().empty());
+ ASSERT_TRUE(srv_globals->valuesMap().empty());
// Attempting to extract globals from a non-map should throw.
ASSERT_THROW(conf.extractConfiguredGlobals(Element::create(777)), isc::BadValue);
// Now see if the extract was correct.
srv_globals = conf.getConfiguredGlobals();
- ASSERT_TRUE(srv_globals);
- ASSERT_EQ(Element::map, srv_globals->getType());
- ASSERT_FALSE(srv_globals->mapValue().empty());
+ ASSERT_FALSE(srv_globals->valuesMap().empty());
// Maps and lists should be excluded.
- auto globals = srv_globals->mapValue();
+ auto globals = srv_globals->valuesMap();
for (auto global = globals.begin(); global != globals.end(); ++global) {
if (global->first == "astring") {
ASSERT_EQ(Element::string, global->second->getType());
ASSERT_NO_THROW(expected_globals = Element::fromJSON(exp_globals))
<< "exp_globals didn't parse, test is broken";
- EXPECT_TRUE(isEquivalent(expected_globals, cfg_to.getConfiguredGlobals()));
-
+ EXPECT_TRUE(isEquivalent(expected_globals,
+ cfg_to.getConfiguredGlobals()->toElement()));
}
// This test verifies that globals from one SrvConfig
ASSERT_NO_THROW(expected_globals = Element::fromJSON(exp_globals))
<< "exp_globals didn't parse, test is broken";
- EXPECT_TRUE(isEquivalent(expected_globals, cfg_to.getConfiguredGlobals()));
+ EXPECT_TRUE(isEquivalent(expected_globals,
+ cfg_to.getConfiguredGlobals()->toElement()));
}
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- subnet1->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
return (conf.getConfiguredGlobals());
});
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- subnet2->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
return (conf.getConfiguredGlobals());
});
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- subnet1->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+ subnet1->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
return (conf.getConfiguredGlobals());
});
// In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each
// subnet to allow for fetching global parameters.
- subnet2->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+ subnet2->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
return (conf.getConfiguredGlobals());
});
-// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
GenericBackendTest::checkConfiguredGlobal(const SrvConfigPtr& srv_cfg,
const std::string &name,
ConstElementPtr exp_value) {
- ConstElementPtr globals = srv_cfg->getConfiguredGlobals();
+ ConstCfgGlobalsPtr globals = srv_cfg->getConfiguredGlobals();
ConstElementPtr found_global = globals->get(name);
ASSERT_TRUE(found_global) << "expected global: "
<< name << " not found";
checkConfiguredGlobal(srv_cfg, exp_global->getName(), exp_global->getElementValue());
}
-
} // end of namespace isc::dhcp::test
} // end of namespace isc::dhcp
} // end of namespace isc