}
bool
-AdaptorConfig::shareNetworksCollectID(ConstElementPtr networks,
- SubnetIDSet& set, const string& subsel) {
+AdaptorConfig::sharedNetworksCollectID(ConstElementPtr networks,
+ SubnetIDSet& set,
+ const string& subsel) {
bool have_ids = true;
if (networks && (networks->size() > 0)) {
for (size_t i = 0; i < networks->size(); ++i) {
}
void
-AdaptorConfig::shareNetworksAssignID(ConstElementPtr networks,
- SubnetIDSet& set, SubnetID& next,
- const string& subsel) {
+AdaptorConfig::sharedNetworksAssignID(ConstElementPtr networks,
+ SubnetIDSet& set, SubnetID& next,
+ const string& subsel) {
if (networks && (networks->size() > 0)) {
for (ConstElementPtr network : networks->listValue()) {
ConstElementPtr subnets = network->get(subsel);
ConstElementPtr networks = dhcp->get("shared-networks");
if (networks) {
if (networks->size() > 0) {
- if (!shareNetworksCollectID(networks, set, subsel)) {
+ if (!sharedNetworksCollectID(networks, set, subsel)) {
have_ids = false;
}
} else {
if (!have_ids) {
SubnetID next(1);
subnetsAssignID(subnets, set, next);
- shareNetworksAssignID(networks, set, next, subsel);
+ sharedNetworksAssignID(networks, set, next, subsel);
}
OptionCodes codes;
void
AdaptorConfig::preProcess4(ConstElementPtr config) {
+ if (!config) {
+ isc_throw(BadValue, "preProcess4: null config");
+ }
+ if (config->getType() != Element::map) {
+ isc_throw(BadValue, "preProcess4: not map: " << config->str());
+ }
ConstElementPtr dhcp = config->get("Dhcp4");
- preProcess(config->get("Dhcp4"), "subnet4", "dhcp4");
+ if (!dhcp) {
+ return;
+ }
+ preProcess(dhcp, "subnet4", "dhcp4");
}
void
AdaptorConfig::preProcess6(ConstElementPtr config) {
+ if (!config) {
+ isc_throw(BadValue, "preProcess6: null config");
+ }
+ if (config->getType() != Element::map) {
+ isc_throw(BadValue, "preProcess6: not map: " << config->str());
+ }
ConstElementPtr dhcp = config->get("Dhcp6");
- preProcess(config->get("Dhcp6"), "subnet6", "dhcp6");
+ if (!dhcp) {
+ return;
+ }
+ preProcess(dhcp, "subnet6", "dhcp6");
}
}; // end of namespace isc::yang
namespace isc {
namespace yang {
-/// @brief JSON adaptor for configurations.
+/// @brief JSON adaptor for Kea server configurations.
+///
+/// Currently only from JSON to YANG for DHCPv4 and DHCPv6 available
+/// as preProcess4 and preProcess6 class methods, filling some required
+/// (by YANG) fields (e.g. subnet IDs, or option code and space), or
+/// transforming a hand-written JSON configuration into a canonical form.
class AdaptorConfig : public AdaptorHost, public AdaptorOption,
public AdaptorSubnet {
public:
///
/// @param config The configuration.
/// @throw MissingKey when a required key is missing.
+ /// @throw BadValue when null or not a map
+ /// @note Does nothing if "Dhcp4" is not present in the map.
static void preProcess4(isc::data::ConstElementPtr config);
/// @brief Pre process a DHCPv6 configuration.
///
/// @param config The configuration.
/// @throw MissingKey when a required key is missing.
+ /// @throw BadValue when null or not a map
+ /// @note Does nothing if "Dhcp6" is not present in the map.
static void preProcess6(isc::data::ConstElementPtr config);
protected:
- /// @brief collectID for a subnet list.
+ /// @brief collectID applied to a subnet list.
///
/// @param subnets The subnet list.
/// @param set The reference to the set of assigned IDs.
static bool subnetsCollectID(isc::data::ConstElementPtr subnets,
SubnetIDSet& set);
- /// @brief collectID for a shared network list.
+ /// @brief collectID applied to a shared network list.
///
/// @param networks The shared network list.
/// @param set The reference to the set of assigned IDs.
/// @param subsel The subnet list name.
/// @return True if all subnets have an ID, false otherwise.
- static bool shareNetworksCollectID(isc::data::ConstElementPtr networks,
- SubnetIDSet& set,
- const std::string& subsel);
+ static bool sharedNetworksCollectID(isc::data::ConstElementPtr networks,
+ SubnetIDSet& set,
+ const std::string& subsel);
- /// @brief assignID for a subnet list.
+ /// @brief assignID applied to a subnet list.
///
/// @param subnets The subnet list.
/// @param set The reference to the set of assigned IDs.
static void subnetsAssignID(isc::data::ConstElementPtr subnets,
SubnetIDSet& set, isc::dhcp::SubnetID& next);
- /// @brief assignID for a shared network list.
+ /// @brief assignID applied to a shared network list.
///
/// @param networks The shared network list.
/// @param set The reference to the set of assigned IDs.
/// @param next The next ID.
/// @param subsel The subnet list name.
/// @return True if all subnets have an ID, false otherwise.
- static void shareNetworksAssignID(isc::data::ConstElementPtr networks,
- SubnetIDSet& set,
- isc::dhcp::SubnetID& next,
- const std::string& subsel);
+ static void sharedNetworksAssignID(isc::data::ConstElementPtr networks,
+ SubnetIDSet& set,
+ isc::dhcp::SubnetID& next,
+ const std::string& subsel);
- /// @brief canonizePool for a pool list.
+ /// @brief canonizePool applied to a pool list.
///
/// @param pools The pool list.
static void canonizePools(isc::data::ConstElementPtr pools);
- /// @brief canonizePool for a subnet list.
+ /// @brief canonizePool applied to a subnet list.
///
/// @param subnets The subnet list.
static void poolSubnets(isc::data::ConstElementPtr subnets);
- /// @brief canonizePool for a shared network list.
+ /// @brief canonizePool applied to a shared network list.
///
/// @param networks The shared network list.
/// @param subsel The subnet list name.
static void poolShareNetworks(isc::data::ConstElementPtr networks,
const std::string& subsel);
- /// @brief Process an option definition list.
+ /// @brief Collect option definitions from an option definition list.
///
/// @param defs The option definition list.
/// @param space The default space name.
const std::string& space,
OptionCodes& codes);
- /// @brief Process an option data list.
+ /// @brief Set missing option codes to an option data list.
///
/// @param options The option data list.
/// @param space The default space name.
const std::string& space,
const OptionCodes& codes);
- /// @brief Process options in a client class list.
+ /// @brief Collect option definitions from a client class list
+ /// and set missing option codes.
///
/// @param classes The client class list.
/// @param space The default space name.
const std::string& space,
OptionCodes& codes);
- /// @brief Process options in a pool list.
+ /// @brief Set missing option codes to a pool list.
///
/// @param pools The pool list.
/// @param space The default space name.
const std::string& space,
const OptionCodes& codes);
- /// @brief Process options in a host reservation list.
+ /// @brief Set missing option codes to a host reservation list.
///
/// @param hosts The host reservation list.
/// @param space The default space name.
const std::string& space,
const OptionCodes& codes);
- /// @brief Process options in a subnet list.
+ /// @brief Set missing option codes to a subnet list.
///
/// @param subnets The subnet list.
/// @param space The default space name.
const std::string& space,
const OptionCodes& codes);
- /// @brief Process options in a shared network list.
+ /// @brief Set missing option codes to a shared network list.
///
/// @param networks The shared network list.
/// @param space The default space name.
/// @brief Process host reservation list.
///
+ /// Quote when needed flex-id identifiers.
+ ///
/// @param hosts The host reservation list.
static void hostList(isc::data::ConstElementPtr hosts);
/// @brief Process host reservations in a subnet list.
///
+ /// Quote when needed flex-id identifiers.
+ ///
/// @param subnets The subnet list.
static void hostSubnets(isc::data::ConstElementPtr subnets);
/// @brief Process host reservations in a shared network list.
///
+ /// Quote when needed flex-id identifiers.
+ ///
/// @param networks The shared network list.
/// @param space The default space name.
static void hostSharedNetworks(isc::data::ConstElementPtr networks,
/// @brief updateRelay in a subnet list.
///
+ /// Force the use of ip-addresses when it finds an ip-address entry.
+ ///
/// @param subnets The subnet list.
static void relaySubnets(isc::data::ConstElementPtr subnets);
/// @brief updateRelay in a shared network list.
///
+ /// Force the use of ip-addresses when it finds an ip-address entry.
+ ///
/// @param networks The shared network list.
/// @param subsel The subnet list name.
static void relaySharedNetworks(isc::data::ConstElementPtr networks,
/// @brief Pre process a configuration.
///
- /// Assign subnet IDs, check and set default in options.
+ /// Assign subnet IDs, check and set default in options, etc.
///
/// @param dhcp The server configuration.
/// @param subsel The subnet list name.