summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bin/netconf/netconf.cc2
-rw-r--r--src/lib/yang/adaptor.cc3
-rw-r--r--src/lib/yang/adaptor.h8
-rw-r--r--src/lib/yang/adaptor_config.cc2
-rw-r--r--src/lib/yang/adaptor_option.cc1
-rw-r--r--src/lib/yang/netconf_error.h21
-rw-r--r--src/lib/yang/tests/adaptor_option_unittests.cc1
-rw-r--r--src/lib/yang/translator.cc118
-rw-r--r--src/lib/yang/translator.h130
-rw-r--r--src/lib/yang/translator_class.cc111
-rw-r--r--src/lib/yang/translator_config.cc712
-rw-r--r--src/lib/yang/translator_control_socket.cc39
-rw-r--r--src/lib/yang/translator_database.cc80
-rw-r--r--src/lib/yang/translator_host.cc126
-rw-r--r--src/lib/yang/translator_logger.cc106
-rw-r--r--src/lib/yang/translator_option_data.cc72
-rw-r--r--src/lib/yang/translator_option_def.cc84
-rw-r--r--src/lib/yang/translator_pd_pool.cc149
-rw-r--r--src/lib/yang/translator_pool.cc138
-rw-r--r--src/lib/yang/translator_shared_network.cc347
-rw-r--r--src/lib/yang/translator_subnet.cc465
21 files changed, 1144 insertions, 1571 deletions
diff --git a/src/bin/netconf/netconf.cc b/src/bin/netconf/netconf.cc
index 4f7af1a2d3..407828197f 100644
--- a/src/bin/netconf/netconf.cc
+++ b/src/bin/netconf/netconf.cc
@@ -547,7 +547,7 @@ NetconfAgent::change(Session sess, const CfgServersMapPair& service_pair) {
LOG_ERROR(netconf_logger, NETCONF_VALIDATE_CONFIG_FAILED)
.arg(server)
.arg(msg.str());
- return (sysrepo::ErrorCode::ValidationFailed);;
+ return (sysrepo::ErrorCode::ValidationFailed);
}
ControlSocketBasePtr comm;
try {
diff --git a/src/lib/yang/adaptor.cc b/src/lib/yang/adaptor.cc
index fc66339d63..fc2350f8ee 100644
--- a/src/lib/yang/adaptor.cc
+++ b/src/lib/yang/adaptor.cc
@@ -17,8 +17,7 @@ namespace isc {
namespace yang {
ConstElementPtr
-Adaptor::getContext(ConstElementPtr parent)
-{
+Adaptor::getContext(ConstElementPtr parent) {
ConstElementPtr context = parent->get("user-context");
ConstElementPtr comment = parent->get("comment");
if (!comment) {
diff --git a/src/lib/yang/adaptor.h b/src/lib/yang/adaptor.h
index 8142725872..1018847282 100644
--- a/src/lib/yang/adaptor.h
+++ b/src/lib/yang/adaptor.h
@@ -13,14 +13,6 @@
namespace isc {
namespace yang {
-/// @brief Missing key error.
-class MissingKey : public isc::Exception {
-public:
- MissingKey(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what)
- {}
-}; // MissingKey
-
/// @brief JSON adaptor between canonical Kea and YANG models.
///
/// An adaptor slightly modifies a JSON configuration between canonical Kea
diff --git a/src/lib/yang/adaptor_config.cc b/src/lib/yang/adaptor_config.cc
index bf1d0a90eb..4c7aad7cb2 100644
--- a/src/lib/yang/adaptor_config.cc
+++ b/src/lib/yang/adaptor_config.cc
@@ -554,7 +554,7 @@ AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
}
OptionCodes codes;
- initCodes(codes, space);;
+ initCodes(codes, space);
ConstElementPtr defs = dhcp->get("option-def");
if (defs) {
if (!defs->empty()) {
diff --git a/src/lib/yang/adaptor_option.cc b/src/lib/yang/adaptor_option.cc
index 811de8eb1b..4839d844e8 100644
--- a/src/lib/yang/adaptor_option.cc
+++ b/src/lib/yang/adaptor_option.cc
@@ -9,6 +9,7 @@
#include <dhcp/docsis3_option_defs.h>
#include <dhcp/std_option_defs.h>
#include <yang/adaptor_option.h>
+#include <yang/netconf_error.h>
using namespace std;
using namespace isc::data;
diff --git a/src/lib/yang/netconf_error.h b/src/lib/yang/netconf_error.h
index d575d0c8f3..6cf4796289 100644
--- a/src/lib/yang/netconf_error.h
+++ b/src/lib/yang/netconf_error.h
@@ -12,11 +12,24 @@
namespace isc {
namespace yang {
-/// @brief Sysrepo error.
-class NetconfError : public isc::Exception {
-public:
+/// @brief Missing node error
+struct MissingNode : public Exception {
+ MissingNode(const char* file, size_t line, const char* what) :
+ Exception(file, line, what)
+ {}
+}; // MissingNode
+
+/// @brief Missing key error
+struct MissingKey : public MissingNode {
+ MissingKey(const char* file, size_t line, const char* what) :
+ MissingNode(file, line, what)
+ {}
+}; // MissingKey
+
+/// @brief Generic NETCONF error
+struct NetconfError : public Exception {
NetconfError(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what)
+ Exception(file, line, what)
{}
}; // NetconfError
diff --git a/src/lib/yang/tests/adaptor_option_unittests.cc b/src/lib/yang/tests/adaptor_option_unittests.cc
index 8d073ef595..9fdcb9cb4c 100644
--- a/src/lib/yang/tests/adaptor_option_unittests.cc
+++ b/src/lib/yang/tests/adaptor_option_unittests.cc
@@ -14,6 +14,7 @@
#include <dhcp/option_space.h>
#include <testutils/gtest_utils.h>
#include <yang/adaptor_option.h>
+#include <yang/netconf_error.h>
using namespace std;
using namespace isc;
diff --git a/src/lib/yang/translator.cc b/src/lib/yang/translator.cc
index 0922f248fe..c2642c88b3 100644
--- a/src/lib/yang/translator.cc
+++ b/src/lib/yang/translator.cc
@@ -7,6 +7,7 @@
#include <config.h>
#include <util/encode/base64.h>
+#include <yang/adaptor.h>
#include <yang/translator.h>
#include <sysrepo-cpp/utils/exception.hpp>
@@ -30,13 +31,45 @@ TranslatorBasic::TranslatorBasic(Session session, const string& model)
void
TranslatorBasic::checkAndGetLeaf(ElementPtr& storage,
DataNode const& data_node,
- string const& name) {
- ConstElementPtr x = getItem(data_node, name);
+ string const& name) const {
+ ElementPtr const& x(getItem(data_node, name));
if (x) {
storage->set(name, x);
}
}
+void
+TranslatorBasic::checkAndGetDivergingLeaf(ElementPtr& storage,
+ DataNode const& data_node,
+ string const& name,
+ string const& yang_name) const {
+ ElementPtr const& x(getItem(data_node, yang_name));
+ if (x) {
+ storage->set(name, x);
+ }
+}
+
+void
+TranslatorBasic::checkAndGetAndJsonifyLeaf(ElementPtr& storage,
+ DataNode const& data_node,
+ string const& name) const {
+ ElementPtr const& x(getItem(data_node, name));
+ if (x) {
+ storage->set(name, Element::fromJSON(x->stringValue()));
+ }
+}
+
+void
+TranslatorBasic::checkAndJsonifyAndSetLeaf(ConstElementPtr const& from,
+ string const& xpath,
+ string const& name) {
+ ConstElementPtr const& x(from->get(name));
+ if (x) {
+ ElementPtr const& json(Element::create(x->str()));
+ setItem(xpath + "/" + name, json, LeafBaseType::String);
+ }
+}
+
void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from,
string const& xpath,
string const& name,
@@ -47,6 +80,38 @@ void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from,
}
}
+void TranslatorBasic::checkAndSetDivergingLeaf(ConstElementPtr const& from,
+ string const& xpath,
+ string const& name,
+ string const& yang_name,
+ LeafBaseType const type) {
+ ConstElementPtr const& x(from->get(name));
+ if (x) {
+ setItem(xpath + "/" + yang_name, x, type);
+ }
+}
+
+void TranslatorBasic::checkAndSetLeafList(ConstElementPtr const& from,
+ string const& xpath,
+ string const& name,
+ LeafBaseType const type) {
+ ConstElementPtr const& leaf_list(from->get(name));
+ if (leaf_list && !leaf_list->empty()) {
+ for (ElementPtr const& leaf : leaf_list->listValue()) {
+ setItem(xpath + "/" + name, leaf, type);
+ }
+ }
+}
+
+void TranslatorBasic::checkAndSetUserContext(ConstElementPtr const& from,
+ string const& xpath) {
+ ConstElementPtr const& user_context(Adaptor::getContext(from));
+ if (user_context) {
+ setItem(xpath + "/user-context", Element::create(user_context->str()),
+ LeafBaseType::String);
+ }
+}
+
string
TranslatorBasic::decode64(string const& input) {
vector<uint8_t> binary;
@@ -173,6 +238,30 @@ TranslatorBasic::getItemFromAbsoluteXpath(string const& xpath) const {
}
void
+TranslatorBasic::getMandatoryLeaf(ElementPtr& storage,
+ DataNode const& data_node,
+ string const& name) const {
+ ElementPtr const& x(getItem(data_node, name));
+ if (!x) {
+ isc_throw(MissingNode, name);
+ }
+ storage->set(name, x);
+}
+
+
+void
+TranslatorBasic::getMandatoryDivergingLeaf(ElementPtr& storage,
+ DataNode const& data_node,
+ string const& name,
+ string const& yang_name) const {
+ ElementPtr const& x(getItem(data_node, yang_name));
+ if (!x) {
+ isc_throw(MissingNode, yang_name);
+ }
+ storage->set(name, x);
+}
+
+void
TranslatorBasic::setItem(const string& xpath, ConstElementPtr elem,
LeafBaseType type) {
optional<string> const value(translateToYang(elem, type));
@@ -185,6 +274,31 @@ TranslatorBasic::setItem(const string& xpath, ConstElementPtr elem,
session_.applyChanges();
}
+void
+TranslatorBasic::setMandatoryLeaf(ConstElementPtr const& from,
+ string const& xpath,
+ string const& name,
+ LeafBaseType const type) {
+ ConstElementPtr const& x(from->get(name));
+ if (!x) {
+ isc_throw(MissingNode, "xpath: " << xpath << ", name: " << name);
+ }
+ setItem(xpath + "/" + name, x, type);
+}
+
+void
+TranslatorBasic::setMandatoryDivergingLeaf(ConstElementPtr const& from,
+ string const& xpath,
+ string const& name,
+ string const& yang_name,
+ LeafBaseType const type) {
+ ConstElementPtr const& x(from->get(name));
+ if (!x) {
+ isc_throw(MissingNode, "xpath: " << xpath << ", name: " << name);
+ }
+ setItem(xpath + "/" + yang_name, x, type);
+}
+
ElementPtr
TranslatorBasic::translateFromYang(optional<DataNode> data_node) {
NodeType const node_type(data_node->schema().nodeType());
diff --git a/src/lib/yang/translator.h b/src/lib/yang/translator.h
index 14c7c11dd9..0dbdc01705 100644
--- a/src/lib/yang/translator.h
+++ b/src/lib/yang/translator.h
@@ -36,7 +36,40 @@ public:
/// @param name name of the parameter
void checkAndGetLeaf(isc::data::ElementPtr& storage,
libyang::DataNode const& data_node,
- const std::string& name);
+ std::string const& name) const;
+
+ /// @brief Retrieves a child YANG data node identified by name from the
+ /// given parent YANG container node and stores it in the specified storage.
+ ///
+ /// @param storage ElementMap where result will be stored
+ /// @param data_node parent data node of container type
+ /// @param name name of the parameter
+ void checkAndGetDivergingLeaf(isc::data::ElementPtr& storage,
+ libyang::DataNode const& data_node,
+ std::string const& name,
+ std::string const& yang_name) const;
+
+ /// @brief Retrieves a child YANG data node identified by name from the given parent YANG
+ /// container node, converts it from string to JSON and stores it in the specified storage.
+ ///
+ /// @param storage ElementMap where result will be stored
+ /// @param data_node parent data node of container type
+ /// @param name name of the parameter
+ void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr& storage,
+ libyang::DataNode const& data_node,
+ const std::string& name) const;
+
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void checkAndJsonifyAndSetLeaf(isc::data::ConstElementPtr const& from,
+ std::string const& xpath,
+ std::string const& name);
/// @brief Get an element from given ElementPtr node and set it in sysrepo
/// at given xpath.
@@ -51,6 +84,44 @@ public:
std::string const& name,
libyang::LeafBaseType const type);
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void checkAndSetDivergingLeaf(isc::data::ConstElementPtr const& from,
+ std::string const& xpath,
+ std::string const& name,
+ std::string const& yang_name,
+ libyang::LeafBaseType const type);
+
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath as a leaf-list.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void checkAndSetLeafList(isc::data::ConstElementPtr const& from,
+ std::string const& xpath,
+ std::string const& name,
+ libyang::LeafBaseType const type);
+
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void checkAndSetUserContext(isc::data::ConstElementPtr const& from,
+ std::string const& xpath);
+
/// @brief Delete basic value from YANG.
///
/// @param xpath The xpath of the basic value.
@@ -163,6 +234,36 @@ public:
}
}
+ /// @brief Retrieves a child YANG data node identified by name from the
+ /// given parent YANG container node and stores it in the specified storage.
+ ///
+ /// Unlike @ref checkAndGetLeaf, the leaf is expected to be present.
+ ///
+ /// @param storage ElementMap where result will be stored
+ /// @param data_node parent data node of container type
+ /// @param name name of the parameter
+ ///
+ /// @throw MissingNode if leaf is not found
+ void getMandatoryLeaf(isc::data::ElementPtr& storage,
+ libyang::DataNode const& data_node,
+ std::string const& name) const;
+
+ /// @brief Retrieves a child YANG data node identified by one name from the
+ /// given parent YANG container node and stores it in the specified storage
+ /// uner a different name.
+ ///
+ /// Unlike @ref checkAndGetLeaf, the leaf is expected to be present.
+ ///
+ /// @param storage ElementMap where result will be stored
+ /// @param data_node parent data node of container type
+ /// @param name name of the parameter
+ ///
+ /// @throw MissingNode if leaf is not found
+ void getMandatoryDivergingLeaf(isc::data::ElementPtr& storage,
+ libyang::DataNode const& data_node,
+ std::string const& name,
+ std::string const& yang_name) const;
+
/// @brief Translate and set basic value from JSON to YANG.
///
/// @param xpath The xpath of the basic value.
@@ -172,6 +273,33 @@ public:
isc::data::ConstElementPtr elem,
libyang::LeafBaseType type);
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void setMandatoryLeaf(isc::data::ConstElementPtr const& from,
+ std::string const& xpath,
+ std::string const& name,
+ libyang::LeafBaseType const type);
+
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void setMandatoryDivergingLeaf(isc::data::ConstElementPtr const& from,
+ std::string const& xpath,
+ std::string const& name,
+ std::string const& yang_name,
+ libyang::LeafBaseType const type);
+
/// @brief Translate basic value from the given YANG data node to JSON element.
///
/// @param data_node the YANG data node
diff --git a/src/lib/yang/translator_class.cc b/src/lib/yang/translator_class.cc
index 868ed931e2..2cf714aefb 100644
--- a/src/lib/yang/translator_class.cc
+++ b/src/lib/yang/translator_class.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_class.h>
#include <yang/yang_models.h>
@@ -55,55 +54,38 @@ TranslatorClass::getClassFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorClass::getClassKea(DataNode const& data_node) {
- ConstElementPtr name = getItem(data_node, "name");
- if (!name) {
- // Can't happen as the name is the key.
- isc_throw(Unexpected, "getClassKea requires name");
- }
ElementPtr result = Element::createMap();
- result->set("name", name);
- ConstElementPtr test = getItem(data_node, "test");
- if (test) {
- result->set("test", test);
- }
- ConstElementPtr required = getItem(data_node, "only-if-required");
- if (required) {
- result->set("only-if-required", required);
- }
+
+ getMandatoryLeaf(result, data_node, "name");
+
+ checkAndGetLeaf(result, data_node, "max-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "min-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "only-if-required");
+ checkAndGetLeaf(result, data_node, "test");
+ checkAndGetLeaf(result, data_node, "valid-lifetime");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
ConstElementPtr options = getOptionDataList(data_node);
- if (options && (options->size() > 0)) {
+ if (options) {
result->set("option-data", options);
}
- checkAndGetLeaf(result, data_node, "valid-lifetime");
- checkAndGetLeaf(result, data_node, "min-valid-lifetime");
- checkAndGetLeaf(result, data_node, "max-valid-lifetime");
+ ConstElementPtr defs = getOptionDefList(data_node);
+ if (defs) {
+ result->set("option-def", defs);
+ }
+
if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr defs = getOptionDefList(data_node);
- if (defs && (defs->size() > 0)) {
- result->set("option-def", defs);
- }
- ConstElementPtr next = getItem(data_node, "next-server");
- if (next) {
- result->set("next-server", next);
- }
- ConstElementPtr hostname = getItem(data_node, "server-hostname");
- if (hostname) {
- result->set("server-hostname", hostname);
- }
- ConstElementPtr boot = getItem(data_node, "boot-file-name");
- if (boot) {
- result->set("boot-file-name", boot);
- }
+ checkAndGetLeaf(result, data_node, "boot-file-name");
+ checkAndGetLeaf(result, data_node, "next-server");
+ checkAndGetLeaf(result, data_node, "server-hostname");
} else if (model_ == KEA_DHCP6_SERVER) {
- checkAndGetLeaf(result, data_node, "preferred-lifetime");
- checkAndGetLeaf(result, data_node, "min-preferred-lifetime");
checkAndGetLeaf(result, data_node, "max-preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "min-preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "preferred-lifetime");
}
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -128,48 +110,33 @@ TranslatorClass::setClassKea(string const& xpath, ConstElementPtr elem) {
// Keys are set by setting the list itself.
setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
- ConstElementPtr test = elem->get("test");
- if (test) {
- setItem(xpath + "/test", test, LeafBaseType::String);
- }
- ConstElementPtr required = elem->get("only-if-required");
- if (required) {
- setItem(xpath + "/only-if-required", required, LeafBaseType::Bool);
- }
+ checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "only-if-required", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "test", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+
ConstElementPtr options = elem->get("option-data");
if (options) {
setOptionDataList(xpath, options);
}
- checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
+
if (model_ == KEA_DHCP4_SERVER) {
+ checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
+
ConstElementPtr defs = elem->get("option-def");
if (defs) {
setOptionDefList(xpath, defs);
}
- ConstElementPtr next = elem->get("next-server");
- if (next) {
- setItem(xpath + "/next-server", next, LeafBaseType::String);
- }
- ConstElementPtr hostname = elem->get("server-hostname");
- if (hostname) {
- setItem(xpath + "/server-hostname", hostname, LeafBaseType::String);
- }
- ConstElementPtr boot = elem->get("boot-file-name");
- if (boot) {
- setItem(xpath + "/boot-file-name", boot, LeafBaseType::String);
- }
} else if (model_ == KEA_DHCP6_SERVER) {
- checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
}
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
+
+ checkAndSetUserContext(elem, xpath);
}
TranslatorClasses::TranslatorClasses(Session session, const string& model)
diff --git a/src/lib/yang/translator_config.cc b/src/lib/yang/translator_config.cc
index b53ea660e8..648a8a433b 100644
--- a/src/lib/yang/translator_config.cc
+++ b/src/lib/yang/translator_config.cc
@@ -74,6 +74,7 @@ TranslatorConfig::getConfigIetf6() {
} catch(NetconfError const&) {
return result;
}
+
Set<DataNode> const& nodes(config->findXPath("server-config/network-ranges"));
if (!nodes.empty()) {
ConstElementPtr ranges = getSubnets(nodes.front());
@@ -81,6 +82,7 @@ TranslatorConfig::getConfigIetf6() {
dhcp6->set("subnet6", ranges);
}
}
+
// Skip everything else.
return (result);
}
@@ -102,16 +104,9 @@ TranslatorConfig::getConfigKea6() {
}
ElementPtr TranslatorConfig::getHook(DataNode const& data_node) {
- ElementPtr const& hook_library(Element::createMap());
- ElementPtr const& name(getItem(data_node, "library"));
- if (name) {
- hook_library->set("library", name);
- ElementPtr const& parameters(getItem(data_node, "parameters"));
- if (parameters) {
- hook_library->set("parameters",
- Element::fromJSON(parameters->stringValue()));
- }
- }
+ ElementPtr hook_library(Element::createMap());
+ checkAndGetLeaf(hook_library, data_node, "library");
+ checkAndGetAndJsonifyLeaf(hook_library, data_node, "parameters");
return hook_library;
}
@@ -122,70 +117,52 @@ TranslatorConfig::getHooksKea(DataNode const& data_node) {
isc::data::ElementPtr
TranslatorConfig::getExpiredKea(DataNode const& data_node) {
- ElementPtr expired = Element::createMap();
-
- checkAndGetLeaf(expired, data_node, "reclaim-timer-wait-time");
- checkAndGetLeaf(expired, data_node, "flush-reclaimed-timer-wait-time");
- checkAndGetLeaf(expired, data_node, "hold-reclaimed-time");
- checkAndGetLeaf(expired, data_node, "max-reclaim-leases");
- checkAndGetLeaf(expired, data_node, "max-reclaim-time");
- checkAndGetLeaf(expired, data_node, "unwarned-reclaim-cycles");
+ ElementPtr result = Element::createMap();
- if (!expired->empty()) {
- return (expired);
- }
+ checkAndGetLeaf(result, data_node, "flush-reclaimed-timer-wait-time");
+ checkAndGetLeaf(result, data_node, "hold-reclaimed-time");
+ checkAndGetLeaf(result, data_node, "max-reclaim-leases");
+ checkAndGetLeaf(result, data_node, "max-reclaim-time");
+ checkAndGetLeaf(result, data_node, "reclaim-timer-wait-time");
+ checkAndGetLeaf(result, data_node, "unwarned-reclaim-cycles");
- return (ElementPtr());
+ return (result->empty() ? ElementPtr() : result);
}
isc::data::ElementPtr
TranslatorConfig::getDdnsKea(DataNode const& data_node) {
- ElementPtr ddns = Element::createMap();
- checkAndGetLeaf(ddns, data_node, "enable-updates");
- checkAndGetLeaf(ddns, data_node, "qualifying-suffix");
- checkAndGetLeaf(ddns, data_node, "server-ip");
- checkAndGetLeaf(ddns, data_node, "server-port");
- checkAndGetLeaf(ddns, data_node, "sender-ip");
- checkAndGetLeaf(ddns, data_node, "sender-port");
- checkAndGetLeaf(ddns, data_node, "max-queue-size");
- checkAndGetLeaf(ddns, data_node, "ncr-protocol");
- checkAndGetLeaf(ddns, data_node, "ncr-format");
- checkAndGetLeaf(ddns, data_node, "override-no-update");
- checkAndGetLeaf(ddns, data_node, "override-client-update");
- checkAndGetLeaf(ddns, data_node, "replace-client-name");
- checkAndGetLeaf(ddns, data_node, "generated-prefix");
- checkAndGetLeaf(ddns, data_node, "hostname-char-set");
- checkAndGetLeaf(ddns, data_node, "hostname-char-replacement");
-
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- ddns->set("user-context", Element::fromJSON(context->stringValue()));
- }
-
- if (!ddns->empty()) {
- // If there's something to return, use it.
- return (ddns);
- }
-
- // If not, return null.
- return (ElementPtr());
+ ElementPtr result(Element::createMap());
+
+ checkAndGetLeaf(result, data_node, "enable-updates");
+ checkAndGetLeaf(result, data_node, "generated-prefix");
+ checkAndGetLeaf(result, data_node, "hostname-char-replacement");
+ checkAndGetLeaf(result, data_node, "hostname-char-set");
+ checkAndGetLeaf(result, data_node, "max-queue-size");
+ checkAndGetLeaf(result, data_node, "ncr-format");
+ checkAndGetLeaf(result, data_node, "ncr-protocol");
+ checkAndGetLeaf(result, data_node, "qualifying-suffix");
+ checkAndGetLeaf(result, data_node, "override-client-update");
+ checkAndGetLeaf(result, data_node, "override-no-update");
+ checkAndGetLeaf(result, data_node, "replace-client-name");
+ checkAndGetLeaf(result, data_node, "sender-ip");
+ checkAndGetLeaf(result, data_node, "sender-port");
+ checkAndGetLeaf(result, data_node, "server-ip");
+ checkAndGetLeaf(result, data_node, "server-port");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
TranslatorConfig::getConfigControlKea(DataNode const& data_node) {
- ElementPtr config_ctrl = Element::createMap();
- checkAndGetLeaf(config_ctrl, data_node, "config-fetch-wait-time");
+ ElementPtr result(Element::createMap());
+ checkAndGetLeaf(result, data_node, "config-fetch-wait-time");
ConstElementPtr databases = getDatabases(data_node, "config-database");
if (databases && !databases->empty()) {
- config_ctrl->set("config-databases", databases);
+ result->set("config-databases", databases);
}
- if (!config_ctrl->empty()) {
- // If there's something to return, use it.
- return (config_ctrl);
- }
-
- // If not, return null.
- return (ElementPtr());
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
@@ -195,17 +172,16 @@ TranslatorConfig::getInterfacesKea(DataNode const& config) {
if (interfaces_config_optional) {
DataNode const interfaces_config(*interfaces_config_optional);
result = Element::createMap();
+
checkAndGetLeaf(result, interfaces_config, "dhcp-socket-type");
checkAndGetLeaf(result, interfaces_config, "interfaces");
checkAndGetLeaf(result, interfaces_config, "outbound-interface");
checkAndGetLeaf(result, interfaces_config, "re-detect");
- checkAndGetLeaf(result, interfaces_config, "service-sockets-require-all");
checkAndGetLeaf(result, interfaces_config, "service-sockets-max-retries");
+ checkAndGetLeaf(result, interfaces_config, "service-sockets-require-all");
checkAndGetLeaf(result, interfaces_config, "service-sockets-retry-wait-time");
- ConstElementPtr const& context(getItem(interfaces_config, "user-context"));
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
+
+ checkAndGetAndJsonifyLeaf(result, interfaces_config, "user-context");
}
return result;
}
@@ -214,55 +190,67 @@ ElementPtr
TranslatorConfig::getServerKeaDhcpCommon(DataNode const& data_node) {
ElementPtr result = Element::createMap();
- checkAndGetLeaf(result, data_node, "valid-lifetime");
- checkAndGetLeaf(result, data_node, "min-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "cache-max-age");
+ checkAndGetLeaf(result, data_node, "cache-threshold");
+ checkAndGetLeaf(result, data_node, "calculate-tee-times");
+ checkAndGetLeaf(result, data_node, "dhcp4o6-port");
+ checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
+ checkAndGetLeaf(result, data_node, "ddns-override-client-update");
+ checkAndGetLeaf(result, data_node, "ddns-override-no-update");
+ checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix");
+ checkAndGetLeaf(result, data_node, "ddns-replace-client-name");
+ checkAndGetLeaf(result, data_node, "ddns-send-updates");
+ checkAndGetLeaf(result, data_node, "ddns-update-on-renew");
+ checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
+ checkAndGetLeaf(result, data_node, "decline-probation-period");
+ checkAndGetLeaf(result, data_node, "early-global-reservations-lookup");
+ checkAndGetLeaf(result, data_node, "host-reservation-identifiers");
+ checkAndGetLeaf(result, data_node, "hostname-char-replacement");
+ checkAndGetLeaf(result, data_node, "hostname-char-set");
+ checkAndGetLeaf(result, data_node, "ip-reservations-unique");
checkAndGetLeaf(result, data_node, "max-valid-lifetime");
- checkAndGetLeaf(result, data_node, "renew-timer");
+ checkAndGetLeaf(result, data_node, "min-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "parked-packet-limit");
checkAndGetLeaf(result, data_node, "rebind-timer");
- checkAndGetLeaf(result, data_node, "calculate-tee-times");
+ checkAndGetLeaf(result, data_node, "renew-timer");
+ checkAndGetLeaf(result, data_node, "reservation-mode");
+ checkAndGetLeaf(result, data_node, "reservations-global");
+ checkAndGetLeaf(result, data_node, "reservations-in-subnet");
+ checkAndGetLeaf(result, data_node, "reservations-lookup-first");
+ checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
+ checkAndGetLeaf(result, data_node, "server-tag");
+ checkAndGetLeaf(result, data_node, "statistic-default-sample-age");
+ checkAndGetLeaf(result, data_node, "statistic-default-sample-count");
+ checkAndGetLeaf(result, data_node, "store-extended-info");
checkAndGetLeaf(result, data_node, "t1-percent");
checkAndGetLeaf(result, data_node, "t2-percent");
- checkAndGetLeaf(result, data_node, "decline-probation-period");
- checkAndGetLeaf(result, data_node, "hostname-char-set");
- checkAndGetLeaf(result, data_node, "hostname-char-replacement");
+ checkAndGetLeaf(result, data_node, "valid-lifetime");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "dhcp-queue-control");
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
- ConstElementPtr networks = getSharedNetworks(data_node);
- if (networks && !networks->empty()) {
- result->set("shared-networks", networks);
- }
ConstElementPtr classes = getClasses(data_node);
if (classes && !classes->empty()) {
result->set("client-classes", classes);
}
- ConstElementPtr const& hosts_databases(getDatabases(data_node, "hosts-database"));
- if (hosts_databases && !hosts_databases->empty()) {
- result->set("hosts-databases", hosts_databases);
- }
- Set<DataNode> const& yang_lease_database(data_node.findXPath("lease-database"));
- if (!yang_lease_database.empty()) {
- ConstElementPtr const& lease_database(getDatabase(yang_lease_database.front()));
- if (lease_database && !lease_database->empty()) {
- result->set("lease-database", lease_database);
+
+ Set<DataNode> const& yang_compatibility(data_node.findXPath("compatibility"));
+ if (!yang_compatibility.empty()) {
+ ElementPtr compatibility(Element::createMap());
+ checkAndGetLeaf(compatibility, yang_compatibility.front(), "lenient-option-parsing");
+ if (!compatibility->empty()) {
+ result->set("compatibility", compatibility);
}
}
- ConstElementPtr host_ids =
- getItem(data_node, "host-reservation-identifiers");
- if (host_ids) {
- result->set("host-reservation-identifiers", host_ids);
- }
- ConstElementPtr defs = getOptionDefList(data_node);
- if (defs && !defs->empty()) {
- result->set("option-def", defs);
- }
- ConstElementPtr options = getOptionDataList(data_node);
- if (options && !options->empty()) {
- result->set("option-data", options);
- }
- ConstElementPtr hooks = getHooksKea(data_node);
- if (hooks && !hooks->empty()) {
- result->set("hooks-libraries", hooks);
+
+ Set<DataNode> const& yang_config_control(data_node.findXPath("config-control"));
+ if (!yang_config_control.empty()) {
+ ConstElementPtr const& config_control(getConfigControlKea(yang_config_control.front()));
+ if (config_control) {
+ result->set("config-control", config_control);
+ }
}
- checkAndGetLeaf(result, data_node, "dhcp4o6-port");
+
Set<DataNode> const& yang_control_socket(data_node.findXPath("control-socket"));
if (!yang_control_socket.empty()) {
ConstElementPtr const& control_socket(getControlSocket(yang_control_socket.front()));
@@ -270,6 +258,7 @@ TranslatorConfig::getServerKeaDhcpCommon(DataNode const& data_node) {
result->set("control-socket", control_socket);
}
}
+
Set<DataNode> const& yang_dhcp_ddns(data_node.findXPath("dhcp-ddns"));
if (!yang_dhcp_ddns.empty()) {
ConstElementPtr const& dhcp_ddns(getDdnsKea(yang_dhcp_ddns.front()));
@@ -277,6 +266,7 @@ TranslatorConfig::getServerKeaDhcpCommon(DataNode const& data_node) {
result->set("dhcp-ddns", dhcp_ddns);
}
}
+
Set<DataNode> const& yang_expired_leases_processing(
data_node.findXPath("expired-leases-processing"));
if (!yang_expired_leases_processing.empty()) {
@@ -285,77 +275,71 @@ TranslatorConfig::getServerKeaDhcpCommon(DataNode const& data_node) {
result->set("expired-leases-processing", expired_leases_processing);
}
}
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- ConstElementPtr checks = getItem(data_node, "sanity-checks/lease-checks");
- if (checks) {
- ElementPtr sanity = Element::createMap();
- sanity->set("lease-checks", checks);
- result->set("sanity-checks", sanity);
+
+ ConstElementPtr hooks = getHooksKea(data_node);
+ if (hooks && !hooks->empty()) {
+ result->set("hooks-libraries", hooks);
}
- checkAndGetLeaf(result, data_node, "reservation-mode");
- ConstElementPtr hosts = getHosts(data_node);
- if (hosts && !hosts->empty()) {
- result->set("reservations", hosts);
+
+ ConstElementPtr const& hosts_databases(getDatabases(data_node, "hosts-database"));
+ if (hosts_databases && !hosts_databases->empty()) {
+ result->set("hosts-databases", hosts_databases);
}
- Set<DataNode> const& yang_config_control(data_node.findXPath("config-control"));
- if (!yang_config_control.empty()) {
- ConstElementPtr const& config_control(getConfigControlKea(yang_config_control.front()));
- if (config_control) {
- result->set("config-control", config_control);
+
+ Set<DataNode> const& yang_lease_database(data_node.findXPath("lease-database"));
+ if (!yang_lease_database.empty()) {
+ ConstElementPtr const& lease_database(getDatabase(yang_lease_database.front()));
+ if (lease_database && !lease_database->empty()) {
+ result->set("lease-database", lease_database);
}
}
- checkAndGetLeaf(result, data_node, "server-tag");
- ConstElementPtr queue_ctrl = getItem(data_node, "dhcp-queue-control");
- if (queue_ctrl) {
- result->set("dhcp-queue-control",
- Element::fromJSON(queue_ctrl->stringValue()));
- }
+
ConstElementPtr loggers = getLoggers(data_node);
if (loggers && !loggers->empty()) {
result->set("loggers", loggers);
}
- checkAndGetLeaf(result, data_node, "cache-max-age");
- checkAndGetLeaf(result, data_node, "cache-threshold");
- ElementPtr compatibility = Element::createMap();
- Set<DataNode> const& yang_compatibility(data_node.findXPath("compatibility"));
- if (!yang_compatibility.empty()) {
- checkAndGetLeaf(compatibility, yang_compatibility.front(), "lenient-option-parsing");
- }
- if (!compatibility->empty()) {
- result->set("compatibility", compatibility);
- }
- checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
- checkAndGetLeaf(result, data_node, "ddns-override-client-update");
- checkAndGetLeaf(result, data_node, "ddns-override-no-update");
- checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix");
- checkAndGetLeaf(result, data_node, "ddns-replace-client-name");
- checkAndGetLeaf(result, data_node, "ddns-send-updates");
- checkAndGetLeaf(result, data_node, "ddns-update-on-renew");
- checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
- checkAndGetLeaf(result, data_node, "ip-reservations-unique");
- checkAndGetLeaf(result, data_node, "early-global-reservations-lookup");
- checkAndGetLeaf(result, data_node, "reservations-lookup-first");
- ElementPtr multi_threading = Element::createMap();
+
Set<DataNode> const& yang_multi_threading(data_node.findXPath("multi-threading"));
if (!yang_multi_threading.empty()) {
DataNode const& mt(yang_multi_threading.front());
+ ElementPtr multi_threading(Element::createMap());
checkAndGetLeaf(multi_threading, mt, "enable-multi-threading");
checkAndGetLeaf(multi_threading, mt, "packet-queue-size");
checkAndGetLeaf(multi_threading, mt, "thread-pool-size");
+ if (!multi_threading->empty()) {
+ result->set("multi-threading", multi_threading);
+ }
}
- if (!multi_threading->empty()) {
- result->set("multi-threading", multi_threading);
+
+ ConstElementPtr options = getOptionDataList(data_node);
+ if (options && !options->empty()) {
+ result->set("option-data", options);
}
- checkAndGetLeaf(result, data_node, "parked-packet-limit");
- checkAndGetLeaf(result, data_node, "reservations-global");
- checkAndGetLeaf(result, data_node, "reservations-in-subnet");
- checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
- checkAndGetLeaf(result, data_node, "statistic-default-sample-age");
- checkAndGetLeaf(result, data_node, "statistic-default-sample-count");
- checkAndGetLeaf(result, data_node, "store-extended-info");
+
+ ConstElementPtr defs = getOptionDefList(data_node);
+ if (defs && !defs->empty()) {
+ result->set("option-def", defs);
+ }
+
+ ConstElementPtr hosts = getHosts(data_node);
+ if (hosts && !hosts->empty()) {
+ result->set("reservations", hosts);
+ }
+
+ ConstElementPtr networks = getSharedNetworks(data_node);
+ if (networks && !networks->empty()) {
+ result->set("shared-networks", networks);
+ }
+
+ Set<DataNode> const& yang_sanity_checks(data_node.findXPath("sanity-checks"));
+ if (!yang_sanity_checks.empty()) {
+ ElementPtr sanity_checks = Element::createMap();
+ checkAndGetLeaf(sanity_checks, yang_sanity_checks.front(), "lease-checks");
+ if (!sanity_checks->empty()) {
+ result->set("sanity-checks", sanity_checks);
+ }
+ }
+
return (result);
}
@@ -370,11 +354,14 @@ TranslatorConfig::getServerKeaDhcp4() {
}
DataNode const config(*config_optional);
ElementPtr result = getServerKeaDhcpCommon(config);
- // Handle subnets.
- ConstElementPtr subnets = getSubnets(config);
- if (subnets && !subnets->empty()) {
- result->set("subnet4", subnets);
- }
+
+ // Handle DHCPv4 specific global parameters.
+ checkAndGetLeaf(result, config, "authoritative");
+ checkAndGetLeaf(result, config, "boot-file-name");
+ checkAndGetLeaf(result, config, "echo-client-id");
+ checkAndGetLeaf(result, config, "match-client-id");
+ checkAndGetLeaf(result, config, "next-server");
+ checkAndGetLeaf(result, config, "server-hostname");
// Handle interfaces.
ElementPtr interfaces_config(getInterfacesKea(config));
@@ -382,13 +369,12 @@ TranslatorConfig::getServerKeaDhcp4() {
result->set("interfaces-config", interfaces_config);
}
- // Handle DHCPv4 specific global parameters.
- checkAndGetLeaf(result, config, "echo-client-id");
- checkAndGetLeaf(result, config, "match-client-id");
- checkAndGetLeaf(result, config, "next-server");
- checkAndGetLeaf(result, config, "server-hostname");
- checkAndGetLeaf(result, config, "boot-file-name");
- checkAndGetLeaf(result, config, "authoritative");
+ // Handle subnets.
+ ConstElementPtr subnets = getSubnets(config);
+ if (subnets && !subnets->empty()) {
+ result->set("subnet4", subnets);
+ }
+
return (result);
}
@@ -403,16 +389,14 @@ TranslatorConfig::getServerKeaDhcp6() {
}
DataNode const config(*config_optional);
ElementPtr result = getServerKeaDhcpCommon(config);
+
// Handle DHCPv6 specific global parameters.
checkAndGetLeaf(result, config, "data-directory");
- checkAndGetLeaf(result, config, "preferred-lifetime");
- checkAndGetLeaf(result, config, "min-preferred-lifetime");
+ checkAndGetLeaf(result, config, "mac-sources");
checkAndGetLeaf(result, config, "max-preferred-lifetime");
- // Handle subnets.
- ConstElementPtr subnets = getSubnets(config);
- if (subnets && !subnets->empty()) {
- result->set("subnet6", subnets);
- }
+ checkAndGetLeaf(result, config, "min-preferred-lifetime");
+ checkAndGetLeaf(result, config, "preferred-lifetime");
+ checkAndGetLeaf(result, config, "relay-supplied-options");
// Handle interfaces.
ElementPtr interfaces_config(getInterfacesKea(config));
@@ -420,18 +404,7 @@ TranslatorConfig::getServerKeaDhcp6() {
result->set("interfaces-config", interfaces_config);
}
- // Handle DHCPv6 specific global entries.
- ConstElementPtr relay = getItem(config, "relay-supplied-options");
- if (relay) {
- result->set("relay-supplied-options", relay);
- }
- ConstElementPtr macs = getItem(config, "mac-sources");
- if (macs) {
- result->set("mac-sources", macs);
- }
-
// Handle server-id.
- // @todo: move to a DUID translator.
optional<DataNode> const& server_id_optional(config.findPath("server-id"));
if (server_id_optional) {
DataNode const server_id(*server_id_optional);
@@ -442,15 +415,18 @@ TranslatorConfig::getServerKeaDhcp6() {
checkAndGetLeaf(server_id_map, server_id, "htype");
checkAndGetLeaf(server_id_map, server_id, "enterprise-id");
checkAndGetLeaf(server_id_map, server_id, "persist");
- ElementPtr const& context(getItem(server_id, "user-context"));
- if (context) {
- server_id_map->set("user-context",
- Element::fromJSON(context->stringValue()));
- }
+ checkAndGetAndJsonifyLeaf(server_id_map, server_id, "user-context");
if (!server_id_map->empty()) {
result->set("server-id", server_id_map);
}
}
+
+ // Handle subnets.
+ ConstElementPtr subnets = getSubnets(config);
+ if (subnets && !subnets->empty()) {
+ result->set("subnet6", subnets);
+ }
+
return (result);
}
@@ -501,10 +477,12 @@ TranslatorConfig::setConfigIetf6(ConstElementPtr elem) {
if (!dhcp6) {
isc_throw(BadValue, "no Dhcp6 entry in " << elem->str());
}
+
ConstElementPtr ranges = dhcp6->get("subnet6");
if (ranges && !ranges->empty()) {
setSubnets(xpath + "/network-ranges", ranges);
}
+
// Skip everything else.
}
@@ -532,45 +510,103 @@ TranslatorConfig::setConfigKea6(ConstElementPtr elem) {
void
TranslatorConfig::setServerKeaDhcpCommon(string const& xpath,
ConstElementPtr elem) {
- checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
+ checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "dhcp4o6-port", LeafBaseType::Uint16);
+ checkAndSetLeaf(elem, xpath, "decline-probation-period", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "ip-reservations-unique", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "parked-packet-limit", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum);
+ checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "reservations-lookup-first", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "server-tag", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
- checkAndSetLeaf(elem, xpath, "decline-probation-period", LeafBaseType::Uint32);
- ConstElementPtr networks = elem->get("shared-networks");
- if (networks) {
- setSharedNetworks(xpath, networks);
- }
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+
+ checkAndSetLeafList(elem, xpath, "host-reservation-identifiers", LeafBaseType::Enum);
+
+ checkAndJsonifyAndSetLeaf(elem, xpath, "dhcp-queue-control");
+
+ checkAndSetUserContext(elem, xpath);
+
ConstElementPtr classes = elem->get("client-classes");
if (classes && !classes->empty()) {
setClasses(xpath, classes);
}
- ConstElementPtr database = elem->get("lease-database");
- if (database) {
- setDatabase(xpath + "/lease-database", database);
- }
- ConstElementPtr hosts_databases = elem->get("hosts-databases");
- if (hosts_databases && !hosts_databases->empty()) {
- setDatabases(xpath + "/hosts-database", hosts_databases);
+
+ ConstElementPtr compatibility(elem->get("compatibility"));
+ if (compatibility) {
+ checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", LeafBaseType::Bool);
}
- ConstElementPtr host_ids = elem->get("host-reservation-identifiers");
- if (host_ids) {
- for (ConstElementPtr id : host_ids->listValue()) {
- setItem(xpath + "/host-reservation-identifiers", id, LeafBaseType::Enum);
+
+ ConstElementPtr config_ctrl = elem->get("config-control");
+ if (config_ctrl && !config_ctrl->empty()) {
+ checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32);
+ ConstElementPtr config_databases = config_ctrl->get("config-databases");
+ if (config_databases && !config_databases->empty()) {
+ setDatabases(xpath + "/config-control/config-database", config_databases);
}
}
- ConstElementPtr defs = elem->get("option-def");
- if (defs && !defs->empty()) {
- setOptionDefList(xpath, defs);
+
+ ConstElementPtr socket = elem->get("control-socket");
+ if (socket && !socket->empty()) {
+ setControlSocket(xpath + "/control-socket", socket);
}
- ConstElementPtr options = elem->get("option-data");
- if (options && !options->empty()) {
- setOptionDataList(xpath, options);
+
+ ConstElementPtr ddns = elem->get("dhcp-ddns");
+ if (ddns) {
+ string const ddns_xpath(xpath + "/dhcp-ddns");
+ checkAndSetLeaf(ddns, ddns_xpath, "enable-updates", LeafBaseType::Bool);
+ checkAndSetLeaf(ddns, ddns_xpath, "generated-prefix", LeafBaseType::String);
+ checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-replacement", LeafBaseType::String);
+ checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-set", LeafBaseType::String);
+ checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", LeafBaseType::Uint32);
+ checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", LeafBaseType::Enum);
+ checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", LeafBaseType::Enum);
+ checkAndSetLeaf(ddns, ddns_xpath, "override-client-update", LeafBaseType::Bool);
+ checkAndSetLeaf(ddns, ddns_xpath, "override-no-update", LeafBaseType::Bool);
+ checkAndSetLeaf(ddns, ddns_xpath, "qualifying-suffix", LeafBaseType::String);
+ checkAndSetLeaf(ddns, ddns_xpath, "replace-client-name", LeafBaseType::Enum);
+ checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", LeafBaseType::String);
+ checkAndSetLeaf(ddns, ddns_xpath, "sender-port", LeafBaseType::Uint16);
+ checkAndSetLeaf(ddns, ddns_xpath, "server-ip", LeafBaseType::String);
+ checkAndSetLeaf(ddns, ddns_xpath, "server-port", LeafBaseType::Uint16);
+ checkAndSetUserContext(ddns, ddns_xpath);
+ }
+
+ ConstElementPtr expired = elem->get("expired-leases-processing");
+ if (expired) {
+ string const expired_xpath(xpath + "/expired-leases-processing");
+ checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", LeafBaseType::Uint32);
+ checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", LeafBaseType::Uint32);
+ checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", LeafBaseType::Uint32);
+ checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", LeafBaseType::Uint32);
+ checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", LeafBaseType::Uint32);
+ checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", LeafBaseType::Uint32);
}
+
ConstElementPtr hook_libs = elem->get("hooks-libraries");
if (hook_libs) {
for (ConstElementPtr lib : hook_libs->listValue()) {
@@ -581,217 +617,133 @@ TranslatorConfig::setServerKeaDhcpCommon(string const& xpath,
ostringstream hook_lib;
hook_lib << xpath << "/hook-library[library='"
<< name->stringValue() << "']";
- setItem(hook_lib.str(), ElementPtr(), LeafBaseType::Unknown);
- ConstElementPtr params = lib->get("parameters");
- if (params) {
- hook_lib << "/parameters";
- setItem(hook_lib.str(), Element::create(params->str()),
- LeafBaseType::String);
- }
+ string const hook_xpath(hook_lib.str());
+ setItem(hook_xpath, ElementPtr(), LeafBaseType::Unknown);
+ checkAndJsonifyAndSetLeaf(lib, hook_xpath, "parameters");
}
}
- ConstElementPtr expired = elem->get("expired-leases-processing");
- if (expired) {
- string expired_xpath = xpath + "/expired-leases-processing";
- checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", LeafBaseType::Uint32);
- checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", LeafBaseType::Uint32);
- checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", LeafBaseType::Uint32);
- checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", LeafBaseType::Uint32);
- checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", LeafBaseType::Uint32);
- checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", LeafBaseType::Uint32);
- }
- checkAndSetLeaf(elem, xpath, "dhcp4o6-port", LeafBaseType::Uint16);
- ConstElementPtr socket = elem->get("control-socket");
- if (socket) {
- setControlSocket(xpath + "/control-socket", socket);
- }
- checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
- ConstElementPtr ddns = elem->get("dhcp-ddns");
- if (ddns) {
- string ddns_xpath = xpath + "/dhcp-ddns";
- checkAndSetLeaf(ddns, ddns_xpath, "enable-updates", LeafBaseType::Bool);
- checkAndSetLeaf(ddns, ddns_xpath, "qualifying-suffix", LeafBaseType::String);
- checkAndSetLeaf(ddns, ddns_xpath, "server-ip", LeafBaseType::String);
- checkAndSetLeaf(ddns, ddns_xpath, "server-port", LeafBaseType::Uint16);
- checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", LeafBaseType::String);
- checkAndSetLeaf(ddns, ddns_xpath, "sender-port", LeafBaseType::Uint16);
- checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", LeafBaseType::Uint32);
- checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", LeafBaseType::Enum);
- checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", LeafBaseType::Enum);
- checkAndSetLeaf(ddns, ddns_xpath, "override-no-update", LeafBaseType::Bool);
- checkAndSetLeaf(ddns, ddns_xpath, "override-client-update", LeafBaseType::Bool);
- checkAndSetLeaf(ddns, ddns_xpath, "replace-client-name", LeafBaseType::Enum);
- checkAndSetLeaf(ddns, ddns_xpath, "generated-prefix", LeafBaseType::String);
- checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-set", LeafBaseType::String);
- checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-replacement", LeafBaseType::String);
- ConstElementPtr context = Adaptor::getContext(ddns);
- if (context) {
- ConstElementPtr repr = Element::create(context->str());
- setItem(xpath + "/dhcp-ddns/user-context", repr, LeafBaseType::String);
- }
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- ConstElementPtr repr = Element::create(context->str());
- setItem(xpath + "/user-context", repr, LeafBaseType::String);
- }
- ConstElementPtr sanity = elem->get("sanity-checks");
- if (sanity) {
- checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum);
- }
- checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum);
- ConstElementPtr hosts = elem->get("reservations");
- if (hosts && !hosts->empty()) {
- setHosts(xpath, hosts);
- }
- ConstElementPtr config_ctrl = elem->get("config-control");
- if (config_ctrl && !config_ctrl->empty()) {
- checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32);
- ConstElementPtr config_databases = config_ctrl->get("config-databases");
- if (config_databases && !config_databases->empty()) {
- setDatabases(xpath + "/config-control/config-database", config_databases);
- }
+
+ ConstElementPtr hosts_databases = elem->get("hosts-databases");
+ if (hosts_databases && !hosts_databases->empty()) {
+ setDatabases(xpath + "/hosts-database", hosts_databases);
}
- checkAndSetLeaf(elem, xpath, "server-tag", LeafBaseType::String);
- ConstElementPtr queue_ctrl = elem->get("dhcp-queue-control");
- if (queue_ctrl) {
- ConstElementPtr repr = Element::create(queue_ctrl->str());
- setItem(xpath + "/dhcp-queue-control", repr, LeafBaseType::String);
+
+ ConstElementPtr database = elem->get("lease-database");
+ if (database && !database->empty()) {
+ setDatabase(xpath + "/lease-database", database);
}
+
ConstElementPtr loggers = elem->get("loggers");
if (loggers) {
setLoggers(xpath, loggers);
}
- checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
- ConstElementPtr compatibility(elem->get("compatibility"));
- if (compatibility) {
- checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", LeafBaseType::Bool);
- }
- checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "ip-reservations-unique", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "reservations-lookup-first", LeafBaseType::Bool);
+
ConstElementPtr multi_threading(elem->get("multi-threading"));
if (multi_threading) {
- string mt_xpath = xpath + "/multi-threading";
+ string const mt_xpath(xpath + "/multi-threading");
checkAndSetLeaf(multi_threading, mt_xpath, "enable-multi-threading", LeafBaseType::Bool);
checkAndSetLeaf(multi_threading, mt_xpath, "packet-queue-size", LeafBaseType::Uint32);
checkAndSetLeaf(multi_threading, mt_xpath, "thread-pool-size", LeafBaseType::Uint32);
}
- checkAndSetLeaf(elem, xpath, "parked-packet-limit", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
+
+ ConstElementPtr options = elem->get("option-data");
+ if (options && !options->empty()) {
+ setOptionDataList(xpath, options);
+ }
+
+ ConstElementPtr defs = elem->get("option-def");
+ if (defs && !defs->empty()) {
+ setOptionDefList(xpath, defs);
+ }
+
+ ConstElementPtr hosts = elem->get("reservations");
+ if (hosts && !hosts->empty()) {
+ setHosts(xpath, hosts);
+ }
+
+ ConstElementPtr sanity = elem->get("sanity-checks");
+ if (sanity) {
+ checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum);
+ }
+
+ ConstElementPtr networks = elem->get("shared-networks");
+ if (networks && !networks->empty()) {
+ setSharedNetworks(xpath, networks);
+ }
}
void
TranslatorConfig::setServerKeaDhcp4(ConstElementPtr elem) {
string xpath = "/kea-dhcp4-server:config";
+
setServerKeaDhcpCommon(xpath, elem);
- ConstElementPtr subnets = elem->get("subnet4");
- if (subnets) {
- setSubnets(xpath, subnets);
- }
+
+ checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "echo-client-id", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
+
ConstElementPtr if_config = elem->get("interfaces-config");
if (if_config) {
- ConstElementPtr ifs = if_config->get("interfaces");
- if (ifs && !ifs->empty()) {
- for (ConstElementPtr intf : ifs->listValue()) {
- setItem(xpath + "/interfaces-config/interfaces",
- intf, LeafBaseType::String);
- }
- }
- string if_cfg_xpath = xpath + "/interfaces-config";
+ string const if_cfg_xpath(xpath + "/interfaces-config");
checkAndSetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type", LeafBaseType::Enum);
checkAndSetLeaf(if_config, if_cfg_xpath, "outbound-interface", LeafBaseType::Enum);
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
+ checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
- ConstElementPtr context = Adaptor::getContext(if_config);
- if (context) {
- setItem(xpath + "/interfaces-config/user-context",
- Element::create(context->str()), LeafBaseType::String);
- }
+ checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
+ checkAndSetUserContext(if_config, if_cfg_xpath);
+ }
+
+ ConstElementPtr subnets = elem->get("subnet4");
+ if (subnets) {
+ setSubnets(xpath, subnets);
}
- checkAndSetLeaf(elem, xpath, "echo-client-id", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
}
void
TranslatorConfig::setServerKeaDhcp6(ConstElementPtr elem) {
string xpath = "/kea-dhcp6-server:config";
+
setServerKeaDhcpCommon(xpath, elem);
+
checkAndSetLeaf(elem, xpath, "data-directory", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
- ConstElementPtr subnets = elem->get("subnet6");
- if (subnets) {
- setSubnets(xpath, subnets);
- }
+ checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+
+ checkAndSetLeafList(elem, xpath, "mac-sources", LeafBaseType::String);
+ checkAndSetLeafList(elem, xpath, "relay-supplied-options", LeafBaseType::String);
+
ConstElementPtr if_config = elem->get("interfaces-config");
if (if_config) {
- ConstElementPtr ifs = if_config->get("interfaces");
- if (ifs && !ifs->empty()) {
- for (ConstElementPtr intf : ifs->listValue()) {
- setItem(xpath + "/interfaces-config/interfaces",
- intf, LeafBaseType::String);
- }
- }
- string if_cfg_xpath = xpath + "/interfaces-config";
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
+ string const if_cfg_xpath(xpath + "/interfaces-config");
checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
+ checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
- ConstElementPtr context = Adaptor::getContext(if_config);
- if (context) {
- setItem(xpath + "/interfaces-config/user-context",
- Element::create(context->str()), LeafBaseType::String);
- }
- }
- ConstElementPtr relay = elem->get("relay-supplied-options");
- if (relay) {
- for (ConstElementPtr addr : relay->listValue()) {
- setItem(xpath + "/relay-supplied-options", addr, LeafBaseType::String);
- }
- }
- ConstElementPtr macs = elem->get("mac-sources");
- if (macs) {
- for (ConstElementPtr source : macs->listValue()) {
- setItem(xpath + "/mac-sources", source, LeafBaseType::String);
- }
+ checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
+ checkAndSetUserContext(if_config, if_cfg_xpath);
}
+
ConstElementPtr server_id = elem->get("server-id");
if (server_id) {
- string srv_id_xpath = xpath + "/server-id";
+ string const srv_id_xpath(xpath + "/server-id");
checkAndSetLeaf(server_id, srv_id_xpath, "type", LeafBaseType::Enum);
checkAndSetLeaf(server_id, srv_id_xpath, "identifier", LeafBaseType::String);
checkAndSetLeaf(server_id, srv_id_xpath, "time", LeafBaseType::Uint32);
checkAndSetLeaf(server_id, srv_id_xpath, "htype", LeafBaseType::Uint16);
checkAndSetLeaf(server_id, srv_id_xpath, "enterprise-id", LeafBaseType::Uint32);
checkAndSetLeaf(server_id, srv_id_xpath, "persist", LeafBaseType::Bool);
- ConstElementPtr context = Adaptor::getContext(server_id);
- if (context) {
- ConstElementPtr repr = Element::create(context->str());
- setItem(xpath + "/server-id/user-context", repr, LeafBaseType::String);
- }
+ checkAndSetUserContext(server_id, srv_id_xpath);
+ }
+
+ ConstElementPtr subnets = elem->get("subnet6");
+ if (subnets) {
+ setSubnets(xpath, subnets);
}
}
diff --git a/src/lib/yang/translator_control_socket.cc b/src/lib/yang/translator_control_socket.cc
index e881479a4e..d9cc3c4b3b 100644
--- a/src/lib/yang/translator_control_socket.cc
+++ b/src/lib/yang/translator_control_socket.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_control_socket.h>
#include <yang/yang_models.h>
@@ -44,20 +43,11 @@ TranslatorControlSocket::getControlSocket(DataNode const& data_node) {
ElementPtr
TranslatorControlSocket::getControlSocketKea(DataNode const& data_node) {
- ConstElementPtr name = getItem(data_node, "socket-name");
- ConstElementPtr type = getItem(data_node, "socket-type");
- if (name && type) {
- ElementPtr result = Element::createMap();
- result->set("socket-name", name);
- result->set("socket-type", type);
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context",
- Element::fromJSON(context->stringValue()));
- }
- return (result);
- }
- return (ElementPtr());
+ ElementPtr result(Element::createMap());
+ getMandatoryLeaf(result, data_node, "socket-name");
+ getMandatoryLeaf(result, data_node, "socket-type");
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
@@ -97,21 +87,10 @@ TranslatorControlSocket::setControlSocketKea(string const& xpath,
deleteItem(xpath);
return;
}
- ConstElementPtr name = elem->get("socket-name");
- if (!name) {
- isc_throw(BadValue, "setControlSocket missing socket name");
- }
- ConstElementPtr type = elem->get("socket-type");
- if (!type) {
- isc_throw(BadValue, "setControlSocket missing socket type");
- }
- setItem(xpath + "/socket-name", name, LeafBaseType::String);
- setItem(xpath + "/socket-type", type, LeafBaseType::Enum);
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
+
+ setMandatoryLeaf(elem, xpath, "socket-name", LeafBaseType::String);
+ setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum);
+ checkAndSetUserContext(elem, xpath);
}
} // namespace yang
diff --git a/src/lib/yang/translator_database.cc b/src/lib/yang/translator_database.cc
index a37914495f..1039568af3 100644
--- a/src/lib/yang/translator_database.cc
+++ b/src/lib/yang/translator_database.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_database.h>
#include <yang/yang_models.h>
@@ -50,34 +49,31 @@ TranslatorDatabase::getDatabaseFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorDatabase::getDatabaseKea(DataNode const& data_node) {
- ConstElementPtr type = getItem(data_node, "database-type");
- if (!type) {
- return (ElementPtr());
- }
ElementPtr result = Element::createMap();
- result->set("type", type);
- checkAndGetLeaf(result, data_node, "user");
- checkAndGetLeaf(result, data_node, "password");
- checkAndGetLeaf(result, data_node, "host");
- checkAndGetLeaf(result, data_node, "name");
- checkAndGetLeaf(result, data_node, "persist");
- checkAndGetLeaf(result, data_node, "port");
- checkAndGetLeaf(result, data_node, "lfc-interval");
- checkAndGetLeaf(result, data_node, "readonly");
- checkAndGetLeaf(result, data_node, "trust-anchor");
+
+ getMandatoryDivergingLeaf(result, data_node, "type", "database-type");
+
checkAndGetLeaf(result, data_node, "cert-file");
- checkAndGetLeaf(result, data_node, "key-file");
checkAndGetLeaf(result, data_node, "cipher-list");
checkAndGetLeaf(result, data_node, "connect-timeout");
+ checkAndGetLeaf(result, data_node, "host");
+ checkAndGetLeaf(result, data_node, "key-file");
+ checkAndGetLeaf(result, data_node, "lfc-interval");
checkAndGetLeaf(result, data_node, "max-reconnect-tries");
- checkAndGetLeaf(result, data_node, "reconnect-wait-time");
checkAndGetLeaf(result, data_node, "max-row-errors");
+ checkAndGetLeaf(result, data_node, "name");
checkAndGetLeaf(result, data_node, "on-fail");
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+ checkAndGetLeaf(result, data_node, "password");
+ checkAndGetLeaf(result, data_node, "persist");
+ checkAndGetLeaf(result, data_node, "port");
+ checkAndGetLeaf(result, data_node, "readonly");
+ checkAndGetLeaf(result, data_node, "reconnect-wait-time");
+ checkAndGetLeaf(result, data_node, "trust-anchor");
+ checkAndGetLeaf(result, data_node, "user");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -107,35 +103,29 @@ TranslatorDatabase::setDatabaseKea(string const& xpath,
deleteItem(xpath);
return;
}
- if (!skip) {
- ConstElementPtr type = elem->get("type");
- if (!type) {
- isc_throw(BadValue, "setDatabase requires database type: "
- << elem->str());
- }
- setItem(xpath + "/database-type", type, LeafBaseType::String);
- }
- checkAndSetLeaf(elem, xpath, "user", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "password", LeafBaseType::String);
+
+ checkAndSetLeaf(elem, xpath, "connect-timeout", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "cert-file", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "cipher-list", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "host", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "key-file", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "lfc-interval", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "max-reconnect-tries", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "max-row-errors", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "on-fail", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "password", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "persist", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "port", LeafBaseType::Uint16);
- checkAndSetLeaf(elem, xpath, "lfc-interval", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "readonly", LeafBaseType::Bool);
- checkAndSetLeaf(elem, xpath, "trust-anchor", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "cert-file", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "key-file", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "cipher-list", LeafBaseType::String);
- checkAndSetLeaf(elem, xpath, "connect-timeout", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "max-reconnect-tries", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "reconnect-wait-time", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "max-row-errors", LeafBaseType::Uint32);
- checkAndSetLeaf(elem, xpath, "on-fail", LeafBaseType::String);
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "trust-anchor", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "user", LeafBaseType::String);
+
+ checkAndSetUserContext(elem, xpath);
+
+ if (!skip) {
+ setMandatoryDivergingLeaf(elem, xpath, "type", "database-type", LeafBaseType::String);
}
}
diff --git a/src/lib/yang/translator_host.cc b/src/lib/yang/translator_host.cc
index f24ae783b5..b82670db45 100644
--- a/src/lib/yang/translator_host.cc
+++ b/src/lib/yang/translator_host.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_host.h>
#include <yang/yang_models.h>
@@ -56,57 +55,32 @@ TranslatorHost::getHostKea(DataNode const& data_node) {
ConstElementPtr id_type = getItem(data_node, "identifier-type");
ConstElementPtr id = getItem(data_node, "identifier");
if (!id_type || !id) {
- isc_throw(Unexpected, "getHostKea requires both identifier and "
- "identifier-type");
+ isc_throw(MissingNode, "getHostKea requires both identifier and identifier-type");
}
ElementPtr result = Element::createMap();
result->set(id_type->stringValue(), id);
- ConstElementPtr hostname = getItem(data_node, "hostname");
- if (hostname) {
- result->set("hostname", hostname);
- }
- if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr address = getItem(data_node, "ip-address");
- if (address) {
- result->set("ip-address", address);
- }
- } else {
- ConstElementPtr addresses = getItem(data_node, "ip-addresses");
- if (addresses && (addresses->size() > 0)) {
- result->set("ip-addresses", addresses);
- }
- ConstElementPtr prefixes = getItem(data_node, "prefixes");
- if (prefixes && (prefixes->size() > 0)) {
- result->set("prefixes", prefixes);
- }
- }
+
+ checkAndGetLeaf(result, data_node, "client-classes");
+ checkAndGetLeaf(result, data_node, "hostname");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
ConstElementPtr options = getOptionDataList(data_node);
- if (options && (options->size() > 0)) {
+ if (options) {
result->set("option-data", options);
}
- ConstElementPtr classes = getItem(data_node, "client-classes");
- if (classes) {
- result->set("client-classes", classes);
- }
+
if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr next = getItem(data_node, "next-server");
- if (next) {
- result->set("next-server", next);
- }
- ConstElementPtr server_hostname = getItem(data_node, "server-hostname");
- if (server_hostname) {
- result->set("server-hostname", server_hostname);
- }
- ConstElementPtr boot = getItem(data_node, "boot-file-name");
- if (boot) {
- result->set("boot-file-name", boot);
- }
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
+ checkAndGetLeaf(result, data_node, "boot-file-name");
+ checkAndGetLeaf(result, data_node, "ip-address");
+ checkAndGetLeaf(result, data_node, "next-server");
+ checkAndGetLeaf(result, data_node, "server-hostname");
+ } else {
+ checkAndGetLeaf(result, data_node, "ip-addresses");
+ checkAndGetLeaf(result, data_node, "prefixes");
}
- return (result);
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -128,63 +102,29 @@ TranslatorHost::setHost(string const& xpath, ConstElementPtr elem) {
void
TranslatorHost::setHostKea(string const& xpath, ConstElementPtr elem) {
- ConstElementPtr hostname = elem->get("hostname");
- // Skip identifier and identifier type as they are keys.
- if (hostname) {
- setItem(xpath + "/hostname", hostname, LeafBaseType::String);
- }
- if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr address = elem->get("ip-address");
- if (address) {
- setItem(xpath + "/ip-address", address, LeafBaseType::String);
- }
- } else {
- ConstElementPtr addresses = elem->get("ip-addresses");
- if (addresses && (addresses->size() > 0)) {
- for (ConstElementPtr address : addresses->listValue()) {
- setItem(xpath + "/ip-addresses", address, LeafBaseType::String);
- }
- }
- ConstElementPtr prefixes = elem->get("prefixes");
- if (prefixes && (prefixes->size() > 0)) {
- for (ConstElementPtr prefix : prefixes->listValue()) {
- setItem(xpath + "/prefixes", prefix, LeafBaseType::String);
- }
- }
- }
+ // Skip keys "identifier" and "identifier-type".
+
+ checkAndSetLeaf(elem, xpath, "hostname", LeafBaseType::String);
+
+ checkAndSetLeafList(elem, xpath, "client-classes", LeafBaseType::String);
+
ConstElementPtr options = elem->get("option-data");
- if (options && (options->size() > 0)) {
+ if (options && !options->empty()) {
setOptionDataList(xpath, options);
}
- ConstElementPtr classes = elem->get("client-classes");
- if (classes && (classes->size() > 0)) {
- for (ConstElementPtr cclass : classes->listValue()) {
- setItem(xpath + "/client-classes", cclass, LeafBaseType::String);
- }
- }
- // These are DHCPv4-specific parameters.
if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr next = elem->get("next-server");
- if (next) {
- setItem(xpath + "/next-server", next, LeafBaseType::String);
- }
- ConstElementPtr server_hostname = elem->get("server-hostname");
- if (server_hostname) {
- setItem(xpath + "/server-hostname", server_hostname, LeafBaseType::String);
- }
- ConstElementPtr boot = elem->get("boot-file-name");
- if (boot) {
- setItem(xpath + "/boot-file-name", boot, LeafBaseType::String);
- }
+ checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "ip-address", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
+ } else {
+ checkAndSetLeafList(elem, xpath, "ip-addresses", LeafBaseType::String);
+ checkAndSetLeafList(elem, xpath, "prefixes", LeafBaseType::String);
}
// User context is supported in both kea-dhcp4-server and kea-dhcp6-server.
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
+ checkAndSetUserContext(elem, xpath);
}
TranslatorHosts::TranslatorHosts(Session session, const string& model)
diff --git a/src/lib/yang/translator_logger.cc b/src/lib/yang/translator_logger.cc
index fb1856f380..9d04e5768c 100644
--- a/src/lib/yang/translator_logger.cc
+++ b/src/lib/yang/translator_logger.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_logger.h>
#include <yang/yang_models.h>
@@ -43,58 +42,35 @@ TranslatorLogger::getLogger(DataNode const& data_node) {
ElementPtr
TranslatorLogger::getLoggerKea(DataNode const& data_node) {
- ConstElementPtr name = getItem(data_node, "name");
- if (!name) {
- // Can't happen as name is the key.
- isc_throw(Unexpected, "getLoggerKea requires name: ");
- }
ElementPtr result = Element::createMap();
- result->set("name", name);
+
+ getMandatoryLeaf(result, data_node, "name");
+
+ checkAndGetLeaf(result, data_node, "debuglevel");
+ checkAndGetLeaf(result, data_node, "severity");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
ConstElementPtr options = getOutputOptions(data_node);
- if (options && (options->size() > 0)) {
+ if (options) {
result->set("output_options", options);
}
- ConstElementPtr severity = getItem(data_node, "severity");
- if (severity) {
- result->set("severity", severity);
- }
- ConstElementPtr debuglevel = getItem(data_node, "debuglevel");
- if (debuglevel) {
- result->set("debuglevel", debuglevel);
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
TranslatorLogger::getOutputOption(DataNode const& data_node) {
- ConstElementPtr output = getItem(data_node, "output");
- if (!output) {
- // Can't happen as output is the key.
- isc_throw(Unexpected, "getOutputOption requires (!output): ");
- }
ElementPtr result = Element::createMap();
- result->set("output", output);
- ConstElementPtr maxver = getItem(data_node, "maxver");
- if (maxver) {
- result->set("maxver", maxver);
- }
- ConstElementPtr maxsize = getItem(data_node, "maxsize");
- if (maxsize) {
- result->set("maxsize", maxsize);
- }
- ConstElementPtr flush = getItem(data_node, "flush");
- if (flush) {
- result->set("flush", flush);
- }
- ConstElementPtr pattern = getItem(data_node, "pattern");
- if (pattern) {
- result->set("pattern", pattern);
- }
- return (result);
+
+ getMandatoryLeaf(result, data_node, "output");
+
+ checkAndGetLeaf(result, data_node, "flush");
+ checkAndGetLeaf(result, data_node, "maxsize");
+ checkAndGetLeaf(result, data_node, "maxver");
+ checkAndGetLeaf(result, data_node, "pattern");
+
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
@@ -124,24 +100,16 @@ TranslatorLogger::setLogger(string const& xpath, ConstElementPtr elem) {
void
TranslatorLogger::setLoggerKea(string const& xpath, ConstElementPtr elem) {
- // Skip name as it is the key.
+ // Skip key "name".
+
+ checkAndSetLeaf(elem, xpath, "debuglevel", LeafBaseType::Uint8);
+ checkAndSetLeaf(elem, xpath, "severity", LeafBaseType::Enum);
+ checkAndSetUserContext(elem, xpath);
+
ConstElementPtr options = elem->get("output_options");
- if (options && (options->size() > 0)) {
+ if (options && !options->empty()) {
setOutputOptions(xpath, options);
}
- ConstElementPtr debuglevel = elem->get("debuglevel");
- if (debuglevel) {
- setItem(xpath + "/debuglevel", debuglevel, LeafBaseType::Uint8);
- }
- ConstElementPtr severity = elem->get("severity");
- if (severity) {
- setItem(xpath + "/severity", severity, LeafBaseType::Enum);
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
}
void
@@ -149,22 +117,10 @@ TranslatorLogger::setOutputOption(string const& xpath, ConstElementPtr elem) {
// Keys are set by setting the list itself.
setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
- ConstElementPtr maxver = elem->get("maxver");
- if (maxver) {
- setItem(xpath + "/maxver", maxver, LeafBaseType::Uint32);
- }
- ConstElementPtr maxsize = elem->get("maxsize");
- if (maxsize) {
- setItem(xpath + "/maxsize", maxsize, LeafBaseType::Uint32);
- }
- ConstElementPtr flush = elem->get("flush");
- if (flush) {
- setItem(xpath + "/flush", flush, LeafBaseType::Bool);
- }
- ConstElementPtr pattern = elem->get("pattern");
- if (pattern) {
- setItem(xpath + "/pattern", pattern, LeafBaseType::String);
- }
+ checkAndSetLeaf(elem, xpath, "flush", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "maxsize", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "maxver", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "pattern", LeafBaseType::String);
}
void
diff --git a/src/lib/yang/translator_option_data.cc b/src/lib/yang/translator_option_data.cc
index bb75c47568..47e836f475 100644
--- a/src/lib/yang/translator_option_data.cc
+++ b/src/lib/yang/translator_option_data.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_option_data.h>
#include <yang/yang_models.h>
@@ -52,36 +51,19 @@ TranslatorOptionData::getOptionDataFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorOptionData::getOptionDataKea(DataNode const& data_node) {
- ConstElementPtr code = getItem(data_node, "code");
- ConstElementPtr space = getItem(data_node, "space");
- if (!code || !space) {
- // Can't happen as code and space are the keys.
- isc_throw(Unexpected, "getOptionDataKea requires code and space");
- }
ElementPtr result = Element::createMap();
- result->set("code", code);
- result->set("space", space);
- ConstElementPtr name = getItem(data_node, "name");
- if (name) {
- result->set("name", name);
- }
- ConstElementPtr data = getItem(data_node, "data");
- if (data) {
- result->set("data", data);
- }
- ConstElementPtr format = getItem(data_node, "csv-format");
- if (format) {
- result->set("csv-format", format);
- }
- ConstElementPtr send = getItem(data_node, "always-send");
- if (send) {
- result->set("always-send", send);
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+
+ getMandatoryLeaf(result, data_node, "code");
+ getMandatoryLeaf(result, data_node, "space");
+
+ checkAndGetLeaf(result, data_node, "always-send");
+ checkAndGetLeaf(result, data_node, "csv-format");
+ checkAndGetLeaf(result, data_node, "data");
+ checkAndGetLeaf(result, data_node, "name");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -106,28 +88,14 @@ TranslatorOptionData::setOptionData(string const& xpath,
void
TranslatorOptionData::setOptionDataKea(string const& xpath,
ConstElementPtr elem) {
- // Skip keys code and space.
- ConstElementPtr name = elem->get("name");
- if (name) {
- setItem(xpath + "/name", name, LeafBaseType::String);
- }
- ConstElementPtr data = elem->get("data");
- if (data) {
- setItem(xpath + "/data", data, LeafBaseType::String);
- }
- ConstElementPtr format = elem->get("csv-format");
- if (format) {
- setItem(xpath + "/csv-format", format, LeafBaseType::Bool);
- }
- ConstElementPtr send = elem->get("always-send");
- if (send) {
- setItem(xpath + "/always-send", send, LeafBaseType::Bool);
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
+ // Skip keys "code" and "space".
+
+ checkAndSetLeaf(elem, xpath, "always-send", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "csv-format", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "data", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "name", LeafBaseType::String);
+
+ checkAndSetUserContext(elem, xpath);
}
TranslatorOptionDataList::TranslatorOptionDataList(Session session,
diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc
index 0154f88d52..b9ab01ea0a 100644
--- a/src/lib/yang/translator_option_def.cc
+++ b/src/lib/yang/translator_option_def.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_option_def.h>
#include <yang/yang_models.h>
@@ -52,39 +51,20 @@ TranslatorOptionDef::getOptionDefFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorOptionDef::getOptionDefKea(DataNode const& data_node) {
- ConstElementPtr code = getItem(data_node, "code");
- ConstElementPtr name = getItem(data_node, "name");
- ConstElementPtr type = getItem(data_node, "type");
- ConstElementPtr space = getItem(data_node, "space");
- if (!code || !space) {
- // Can't happen as code and space are the keys.
- isc_throw(Unexpected, "getOptionDefKea requires code and space");
- }
- if (!name || !type) {
- isc_throw(BadValue, "getOptionDefKea requires name and type");
- }
ElementPtr result = Element::createMap();
- result->set("code", code);
- result->set("name", name);
- result->set("type", type);
- result->set("space", getItem(data_node, "space"));
- ConstElementPtr record = getItem(data_node, "record-types");
- if (record) {
- result->set("record-types", record);
- }
- ConstElementPtr array = getItem(data_node, "array");
- if (array) {
- result->set("array", array);
- }
- ConstElementPtr encapsulate = getItem(data_node, "encapsulate");
- if (encapsulate) {
- result->set("encapsulate", encapsulate);
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+
+ getMandatoryLeaf(result, data_node, "code");
+ getMandatoryLeaf(result, data_node, "name");
+ getMandatoryLeaf(result, data_node, "space");
+ getMandatoryLeaf(result, data_node, "type");
+
+ checkAndGetLeaf(result, data_node, "array");
+ checkAndGetLeaf(result, data_node, "encapsulate");
+ checkAndGetLeaf(result, data_node, "record-types");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -108,34 +88,16 @@ TranslatorOptionDef::setOptionDef(string const& xpath, ConstElementPtr elem) {
void
TranslatorOptionDef::setOptionDefKea(string const& xpath,
ConstElementPtr elem) {
- // Skip code and space as they are the keys.
- ConstElementPtr name = elem->get("name");
- if (!name) {
- isc_throw(BadValue, "option definition with name: " << elem->str());
- }
- setItem(xpath + "/name", name, LeafBaseType::String);
- ConstElementPtr type = elem->get("type");
- if (!type) {
- isc_throw(BadValue, "option definition with type: " << elem->str());
- }
- setItem(xpath + "/type", type, LeafBaseType::String);
- ConstElementPtr record = elem->get("record-types");
- if (record) {
- setItem(xpath + "/record-types", record, LeafBaseType::String);
- }
- ConstElementPtr array = elem->get("array");
- if (array) {
- setItem(xpath + "/array", array, LeafBaseType::Bool);
- }
- ConstElementPtr encapsulate = elem->get("encapsulate");
- if (encapsulate) {
- setItem(xpath + "/encapsulate", encapsulate, LeafBaseType::String);
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
+ // Skip keys "code" and "space".
+
+ setMandatoryLeaf(elem, xpath, "name", LeafBaseType::String);
+ setMandatoryLeaf(elem, xpath, "type", LeafBaseType::String);
+
+ checkAndSetLeaf(elem, xpath, "array", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "encapsulate", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "record-types", LeafBaseType::String);
+
+ checkAndSetUserContext(elem, xpath);
}
TranslatorOptionDefList::TranslatorOptionDefList(Session session,
diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc
index 81bdcb7941..efc4fd15bf 100644
--- a/src/lib/yang/translator_pd_pool.cc
+++ b/src/lib/yang/translator_pd_pool.cc
@@ -6,7 +6,6 @@
#include <config.h>
-#include <yang/adaptor.h>
#include <yang/translator_pd_pool.h>
#include <yang/yang_models.h>
@@ -57,54 +56,40 @@ TranslatorPdPool::getPdPoolFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorPdPool::getPdPoolIetf6(DataNode const& data_node) {
ElementPtr result = Element::createMap();
+
ConstElementPtr pref = getItem(data_node, "prefix");
if (!pref) {
- isc_throw(BadValue, "getPdPoolIetf6: prefix is required");
+ isc_throw(MissingNode, "getPdPoolIetf6: prefix is required");
}
const string& prefix = pref->stringValue();
size_t slash = prefix.find("/");
if (slash == string::npos) {
- isc_throw(BadValue,
+ isc_throw(MissingNode,
"getPdPoolIetf6: no '/' in prefix '" << prefix << "'");
}
const string& address = prefix.substr(0, slash);
if (address.empty()) {
- isc_throw(BadValue,
+ isc_throw(MissingNode,
"getPdPoolIetf6: malformed prefix '" << prefix << "'");
}
result->set("prefix", Element::create(address));
+
// Silly: the prefix length is specified twice...
- ConstElementPtr preflen = getItem(data_node, "prefix-length");
- if (!preflen) {
- isc_throw(BadValue, "getPdPoolIetf6: prefix length is required");
- }
- result->set("prefix-len", preflen);
- ConstElementPtr valid_lifetime = getItem(data_node, "valid-lifetime");
- if (valid_lifetime) {
- result->set("valid-lifetime", valid_lifetime);
- }
- ConstElementPtr preferred_lifetime =
- getItem(data_node, "preferred-lifetime");
- if (preferred_lifetime) {
- result->set("preferred-lifetime", preferred_lifetime);
- }
- ConstElementPtr renew_time = getItem(data_node, "renew-time");
- if (renew_time) {
- result->set("renew-timer", renew_time);
- }
- ConstElementPtr rebind_time = getItem(data_node, "rebind-time");
- if (rebind_time) {
- result->set("rebind-timer", rebind_time);
- }
- // Skip rapid-commit.
- ConstElementPtr guard = getItem(data_node, "client-class");
- if (guard) {
- result->set("client-class", guard);
- }
+ getMandatoryDivergingLeaf(result, data_node, "prefix-len", "prefix-length");
+
+ checkAndGetLeaf(result, data_node, "preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "client-class");
+ checkAndGetLeaf(result, data_node, "valid-lifetime");
+
+ checkAndGetDivergingLeaf(result, data_node, "rebind-timer", "rebind-time");
+ checkAndGetDivergingLeaf(result, data_node, "renew-timer", "renew-time");
+
// no require-client-classes nor user-context.
// Skip max-pd-space-utilization.
- // @todo option-data.
- return (result);
+ // Skip rapid-commit.
+ // @todo: option-data
+
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
@@ -112,7 +97,7 @@ TranslatorPdPool::getPdPoolKea(DataNode const& data_node) {
ElementPtr result = Element::createMap();
ConstElementPtr pref = getItem(data_node, "prefix");
if (!pref) {
- isc_throw(BadValue, "getPdPoolKea: no prefix defined");
+ isc_throw(MissingNode, "getPdPoolKea: no prefix defined");
}
const string& prefix = pref->stringValue();
size_t slash = prefix.find("/");
@@ -134,7 +119,6 @@ TranslatorPdPool::getPdPoolKea(DataNode const& data_node) {
isc_throw(BadValue,
"getPdPoolKea: bad prefix length in '" << prefix << "'");
}
-
ConstElementPtr xpref = getItem(data_node, "excluded-prefix");
if (xpref) {
const string& xprefix = xpref->stringValue();
@@ -163,27 +147,18 @@ TranslatorPdPool::getPdPoolKea(DataNode const& data_node) {
}
}
- ConstElementPtr delegated = getItem(data_node, "delegated-len");
- if (delegated) {
- result->set("delegated-len", delegated);
- }
+ checkAndGetLeaf(result, data_node, "client-class");
+ checkAndGetLeaf(result, data_node, "delegated-len");
+ checkAndGetLeaf(result, data_node, "require-client-classes");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
ConstElementPtr options = getOptionDataList(data_node);
- if (options && (options->size() > 0)) {
+ if (options) {
result->set("option-data", options);
}
- ConstElementPtr guard = getItem(data_node, "client-class");
- if (guard) {
- result->set("client-class", guard);
- }
- ConstElementPtr required = getItem(data_node, "require-client-classes");
- if (required && (required->size() > 0)) {
- result->set("require-client-classes", required);
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -217,33 +192,20 @@ TranslatorPdPool::setPdPoolIetf6(string const& xpath, ConstElementPtr elem) {
prefix << base->stringValue() << "/" << length->intValue();
setItem(xpath + "/prefix", Element::create(prefix.str()), LeafBaseType::String);
setItem(xpath + "/prefix-length", length, LeafBaseType::Uint8);
- ConstElementPtr valid_lifetime = elem->get("valid-lifetime");
- if (valid_lifetime) {
- setItem(xpath + "/valid-lifetime", valid_lifetime, LeafBaseType::Uint32);
- }
- ConstElementPtr preferred_lifetime = elem->get("preferred-lifetime");
- if (preferred_lifetime) {
- setItem(xpath + "/preferred-lifetime",
- preferred_lifetime, LeafBaseType::Uint32);
- }
- ConstElementPtr renew_timer = elem->get("renew-timer");
- if (renew_timer) {
- setItem(xpath + "/renew-time", renew_timer, LeafBaseType::Uint32);
- }
- ConstElementPtr rebind_timer = elem->get("rebind-timer");
- if (rebind_timer) {
- setItem(xpath + "/rebind-time", rebind_timer, LeafBaseType::Uint32);
- }
- // Skip rapid-commit.
- ConstElementPtr guard = elem->get("client-class");
- if (guard) {
- setItem(xpath + "/client-class", guard, LeafBaseType::String);
- }
+
+ checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+
+ checkAndSetDivergingLeaf(elem, xpath, "rebind-timer", "rebind-time", LeafBaseType::Uint32);
+ checkAndSetDivergingLeaf(elem, xpath, "renew-timer", "renew-time", LeafBaseType::Uint32);
+
// Set max pd space utilization to disabled.
- setItem(xpath + "/max-pd-space-utilization",
- Element::create(string("disabled")),
+ setItem(xpath + "/max-pd-space-utilization", Element::create(string("disabled")),
LeafBaseType::Enum);
- // @todo option-data.
+
+ // Skip rapid-commit.
+ // @todo: option-data
}
void
@@ -251,37 +213,24 @@ TranslatorPdPool::setPdPoolKea(string const& xpath, ConstElementPtr elem) {
// Keys are set by setting the list itself.
setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
- ConstElementPtr delegated = elem->get("delegated-len");
- if (delegated) {
- setItem(xpath + "/delegated-len", delegated, LeafBaseType::Uint8);
- }
+ checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "delegated-len", LeafBaseType::Uint8);
+
+ checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String);
+
+ checkAndSetUserContext(elem, xpath);
+
ConstElementPtr xprefix = elem->get("excluded-prefix");
ConstElementPtr xlen = elem->get("excluded-prefix-len");
if (xprefix && xlen) {
ostringstream xpref;
xpref << xprefix->stringValue() << "/" << xlen->intValue();
- setItem(xpath + "/excluded-prefix", Element::create(xpref.str()),
- LeafBaseType::String);
+ setItem(xpath + "/excluded-prefix", Element::create(xpref.str()), LeafBaseType::String);
}
ConstElementPtr options = elem->get("option-data");
- if (options && (options->size() > 0)) {
+ if (options && !options->empty()) {
setOptionDataList(xpath, options);
}
- ConstElementPtr guard = elem->get("client-class");
- if (guard) {
- setItem(xpath + "/client-class", guard, LeafBaseType::String);
- }
- ConstElementPtr required = elem->get("require-client-classes");
- if (required && (required->size() > 0)) {
- for (ConstElementPtr rclass : required->listValue()) {
- setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
- }
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
}
TranslatorPdPools::TranslatorPdPools(Session session, const string& model)
diff --git a/src/lib/yang/translator_pool.cc b/src/lib/yang/translator_pool.cc
index 04ddb5da6d..5db1effd72 100644
--- a/src/lib/yang/translator_pool.cc
+++ b/src/lib/yang/translator_pool.cc
@@ -8,7 +8,6 @@
#include <asiolink/addr_utilities.h>
#include <asiolink/io_address.h>
-#include <yang/adaptor.h>
#include <yang/translator_pool.h>
#include <yang/yang_models.h>
@@ -61,42 +60,25 @@ TranslatorPool::getPoolFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorPool::getPoolIetf6(DataNode const& data_node) {
ElementPtr result = Element::createMap();
+
+ getMandatoryDivergingLeaf(result, data_node, "pool", "pool-prefix");
+
+ checkAndGetLeaf(result, data_node, "client-class");
+ checkAndGetLeaf(result, data_node, "preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "valid-lifetime");
+
+ checkAndGetDivergingLeaf(result, data_node, "rebind-timer", "rebind-time");
+ checkAndGetDivergingLeaf(result, data_node, "renew-timer", "renew-time");
+
+ // Skip max-addr-count.
// Skip pool-id which exists but is not used.
- ConstElementPtr pool = getItem(data_node, "pool-prefix");
- if (!pool) {
- isc_throw(BadValue, "getPoolIetf6 requires pool prefix");
- }
- result->set("pool", pool);
- // Ignore start-address - end-address as prefix form is mandatory?
- ConstElementPtr guard = getItem(data_node, "client-class");
- if (guard) {
- result->set("client-class", guard);
- }
- ConstElementPtr valid_lifetime = getItem(data_node, "valid-lifetime");
- if (valid_lifetime) {
- result->set("valid-lifetime", valid_lifetime);
- }
- ConstElementPtr preferred_lifetime =
- getItem(data_node, "preferred-lifetime");
- if (preferred_lifetime) {
- result->set("preferred-lifetime", preferred_lifetime);
- }
- ConstElementPtr renew_time = getItem(data_node, "renew-time");
- if (renew_time) {
- result->set("renew-timer", renew_time);
- }
- ConstElementPtr rebind_time = getItem(data_node, "rebind-time");
- if (rebind_time) {
- result->set("rebind-timer", rebind_time);
- }
- // Skip max-addr-count
- // @todo: option-data
- /// no require-client-classes nor user-context.
// Skip rapid-commit.
- if (result->empty()) {
- return ElementPtr();
- }
- return (result);
+ // Skip start-address - end-address as prefix form is mandatory?
+ // @todo: option-data
+ // No require-client-classes.
+ // No user-context.
+
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
@@ -109,7 +91,7 @@ TranslatorPool::getPoolKea(DataNode const& data_node) {
ConstElementPtr start_addr = getItem(data_node, "start-address");
ConstElementPtr end_addr = getItem(data_node, "end-address");
if (!start_addr || !end_addr) {
- isc_throw(BadValue, "getPoolKea requires either prefix or "
+ isc_throw(MissingNode, "getPoolKea requires either prefix or "
"both start and end addresses");
}
ostringstream range;
@@ -118,22 +100,16 @@ TranslatorPool::getPoolKea(DataNode const& data_node) {
result->set("pool", Element::create(range.str()));
}
ConstElementPtr options = getOptionDataList(data_node);
- if (options && (options->size() > 0)) {
+ if (options) {
result->set("option-data", options);
}
- ConstElementPtr guard = getItem(data_node, "client-class");
- if (guard) {
- result->set("client-class", guard);
- }
- ConstElementPtr required = getItem(data_node, "require-client-classes");
- if (required && (required->size() > 0)) {
- result->set("require-client-classes", required);
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
- return (result);
+
+ checkAndGetLeaf(result, data_node, "client-class");
+ checkAndGetLeaf(result, data_node, "require-client-classes");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -178,38 +154,28 @@ TranslatorPool::setPoolIetf6(string const& xpath, ConstElementPtr elem) {
setItem(xpath + "/end-address",
Element::create(lastAddrInPrefix(base, plen).toText()),
LeafBaseType::String);
- ConstElementPtr valid_lifetime = elem->get("valid-lifetime");
- if (valid_lifetime) {
- setItem(xpath + "/valid-lifetime", valid_lifetime, LeafBaseType::Uint32);
- }
- ConstElementPtr preferred_lifetime = elem->get("preferred-lifetime");
- if (preferred_lifetime) {
- setItem(xpath + "/preferred-lifetime",
- preferred_lifetime, LeafBaseType::Uint32);
- }
- ConstElementPtr renew_timer = elem->get("renew-timer");
- if (renew_timer) {
- setItem(xpath + "/renew-time", renew_timer, LeafBaseType::Uint32);
- }
- ConstElementPtr rebind_timer = elem->get("rebind-timer");
- if (rebind_timer) {
- setItem(xpath + "/rebind-time", rebind_timer, LeafBaseType::Uint32);
- }
- // skip rapid-commit
- ConstElementPtr guard = elem->get("client-class");
- if (guard) {
- setItem(xpath + "/client-class", guard, LeafBaseType::String);
- }
- // skip max-addr-count
- // @todo option-data
+
+ checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+
+ checkAndSetDivergingLeaf(elem, xpath, "rebind-timer", "rebind-time", LeafBaseType::Uint32);
+ checkAndSetDivergingLeaf(elem, xpath, "renew-timer", "renew-time", LeafBaseType::Uint32);
+
// Set max address count to disabled.
setItem(xpath + "/max-address-count",
Element::create(string("disabled")),
LeafBaseType::Enum);
+
+ // Skip max-addr-count.
+ // Skip rapid-commit.
+ // @todo: option-data
}
void
TranslatorPool::setPoolKea(string const& xpath, ConstElementPtr elem) {
+ // Skip keys "start-address" and "end-address".
+
ConstElementPtr pool = elem->get("pool");
if (!pool) {
isc_throw(BadValue, "setPoolKea requires pool: " << elem->str());
@@ -218,6 +184,12 @@ TranslatorPool::setPoolKea(string const& xpath, ConstElementPtr elem) {
// Keys are set by setting the list itself.
setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
+ checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String);
+
+ checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String);
+
+ checkAndSetUserContext(elem, xpath);
+
string prefix = pool->stringValue();
string start_addr;
string end_addr;
@@ -225,26 +197,10 @@ TranslatorPool::setPoolKea(string const& xpath, ConstElementPtr elem) {
if (prefix.find("/") != string::npos) {
setItem(xpath + "/prefix", pool, LeafBaseType::String);
}
- // Skip start-address and end-address as are the keys.
ConstElementPtr options = elem->get("option-data");
- if (options && (options->size() > 0)) {
+ if (options && !options->empty()) {
setOptionDataList(xpath, options);
}
- ConstElementPtr guard = elem->get("client-class");
- if (guard) {
- setItem(xpath + "/client-class", guard, LeafBaseType::String);
- }
- ConstElementPtr required = elem->get("require-client-classes");
- if (required && (required->size() > 0)) {
- for (ConstElementPtr rclass : required->listValue()) {
- setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
- }
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- setItem(xpath + "/user-context", Element::create(context->str()),
- LeafBaseType::String);
- }
}
void
diff --git a/src/lib/yang/translator_shared_network.cc b/src/lib/yang/translator_shared_network.cc
index 517b59a0e7..aff8d460f9 100644
--- a/src/lib/yang/translator_shared_network.cc
+++ b/src/lib/yang/translator_shared_network.cc
@@ -64,126 +64,13 @@ ElementPtr
TranslatorSharedNetwork::getSharedNetworkKea(DataNode const& data_node,
const std::string& subsel) {
ElementPtr result = Element::createMap();
- ConstElementPtr name = getItem(data_node, "name");
- if (!name) {
- // Can't happen as the name is the key.
- isc_throw(Unexpected, "getSharedNetworkKea requires name");
- }
- result->set("name", name);
- ConstElementPtr subnets = getSubnets(data_node);
- if (subnets && (subnets->size() > 0)) {
- result->set(subsel, subnets);
- }
- if (subsel == "subnet6") {
- ConstElementPtr preferred = getItem(data_node, "preferred-lifetime");
- if (preferred) {
- result->set("preferred-lifetime", preferred);
- }
- ConstElementPtr min_pref = getItem(data_node, "min-preferred-lifetime");
- if (min_pref) {
- result->set("min-preferred-lifetime", min_pref);
- }
- ConstElementPtr max_pref = getItem(data_node, "max-preferred-lifetime");
- if (max_pref) {
- result->set("max-preferred-lifetime", max_pref);
- }
- }
- ConstElementPtr valid = getItem(data_node, "valid-lifetime");
- if (valid) {
- result->set("valid-lifetime", valid);
- }
- ConstElementPtr min_valid = getItem(data_node, "min-valid-lifetime");
- if (min_valid) {
- result->set("min-valid-lifetime", min_valid);
- }
- ConstElementPtr max_valid = getItem(data_node, "max-valid-lifetime");
- if (max_valid) {
- result->set("max-valid-lifetime", max_valid);
- }
- ConstElementPtr renew = getItem(data_node, "renew-timer");
- if (renew) {
- result->set("renew-timer", renew);
- }
- ConstElementPtr rebind = getItem(data_node, "rebind-timer");
- if (rebind) {
- result->set("rebind-timer", rebind);
- }
- ConstElementPtr calculate = getItem(data_node, "calculate-tee-times");
- if (calculate) {
- result->set("calculate-tee-times", calculate);
- }
- ConstElementPtr t1_percent = getItem(data_node, "t1-percent");
- if (t1_percent) {
- result->set("t1-percent", t1_percent);
- }
- ConstElementPtr t2_percent = getItem(data_node, "t2-percent");
- if (t2_percent) {
- result->set("t2-percent", t2_percent);
- }
- ConstElementPtr options = getOptionDataList(data_node);
- if (options && (options->size() > 0)) {
- result->set("option-data", options);
- }
- ConstElementPtr interface = getItem(data_node, "interface");
- if (interface) {
- result->set("interface", interface);
- }
- if (subsel == "subnet6") {
- ConstElementPtr interface_id = getItem(data_node, "interface-id");
- if (interface_id) {
- result->set("interface-id", interface_id);
- }
- ConstElementPtr rapid_commit = getItem(data_node, "rapid-commit");
- if (rapid_commit) {
- result->set("rapid-commit", rapid_commit);
- }
- }
- ConstElementPtr guard = getItem(data_node, "client-class");
- if (guard) {
- result->set("client-class", guard);
- }
- ConstElementPtr required = getItem(data_node, "require-client-classes");
- if (required && (required->size() > 0)) {
- result->set("require-client-classes", required);
- }
- ConstElementPtr mode = getItem(data_node, "reservation-mode");
- if (mode) {
- result->set("reservation-mode", mode);
- }
- ConstElementPtr relay = getItem(data_node, "relay/ip-addresses");
- if (relay && (relay->size() > 0)) {
- ElementPtr relay_map = Element::createMap();
- relay_map->set("ip-addresses", relay);
- result->set("relay", relay_map);
- }
- if (subsel == "subnet4") {
- ConstElementPtr match = getItem(data_node, "match-client-id");
- if (match) {
- result->set("match-client-id", match);
- }
- ConstElementPtr auth = getItem(data_node, "authoritative");
- if (auth) {
- result->set("authoritative", auth);
- }
- ConstElementPtr next = getItem(data_node, "next-server");
- if (next) {
- result->set("next-server", next);
- }
- ConstElementPtr hostname = getItem(data_node, "server-hostname");
- if (hostname) {
- result->set("server-hostname", hostname);
- }
- ConstElementPtr boot = getItem(data_node, "boot-file-name");
- if (boot) {
- result->set("boot-file-name", boot);
- }
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
+
+ getMandatoryLeaf(result, data_node, "name");
+
checkAndGetLeaf(result, data_node, "cache-max-age");
checkAndGetLeaf(result, data_node, "cache-threshold");
+ checkAndGetLeaf(result, data_node, "calculate-tee-times");
+ checkAndGetLeaf(result, data_node, "client-class");
checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
checkAndGetLeaf(result, data_node, "ddns-override-client-update");
checkAndGetLeaf(result, data_node, "ddns-override-no-update");
@@ -194,11 +81,57 @@ TranslatorSharedNetwork::getSharedNetworkKea(DataNode const& data_node,
checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
checkAndGetLeaf(result, data_node, "hostname-char-replacement");
checkAndGetLeaf(result, data_node, "hostname-char-set");
+ checkAndGetLeaf(result, data_node, "interface");
+ checkAndGetLeaf(result, data_node, "max-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "min-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "rebind-timer");
+ checkAndGetLeaf(result, data_node, "renew-timer");
+ checkAndGetLeaf(result, data_node, "require-client-classes");
+ checkAndGetLeaf(result, data_node, "reservation-mode");
checkAndGetLeaf(result, data_node, "reservations-global");
checkAndGetLeaf(result, data_node, "reservations-in-subnet");
checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
checkAndGetLeaf(result, data_node, "store-extended-info");
- return (result);
+ checkAndGetLeaf(result, data_node, "t1-percent");
+ checkAndGetLeaf(result, data_node, "t2-percent");
+ checkAndGetLeaf(result, data_node, "valid-lifetime");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ ConstElementPtr options = getOptionDataList(data_node);
+ if (options) {
+ result->set("option-data", options);
+ }
+
+ ConstElementPtr subnets = getSubnets(data_node);
+ if (subnets) {
+ result->set(subsel, subnets);
+ }
+
+ Set<DataNode> const& yang_relay(data_node.findXPath("relay"));
+ if (!yang_relay.empty()) {
+ ElementPtr relay_map(Element::createMap());
+ checkAndGetLeaf(relay_map, yang_relay.front(), "ip-addresses");
+ if (!relay_map->empty()) {
+ result->set("relay", relay_map);
+ }
+ }
+
+ if (subsel == "subnet6") {
+ checkAndGetLeaf(result, data_node, "interface-id");
+ checkAndGetLeaf(result, data_node, "max-preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "min-preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "rapid-commit");
+ } else if (subsel == "subnet4") {
+ checkAndGetLeaf(result, data_node, "authoritative");
+ checkAndGetLeaf(result, data_node, "boot-file-name");
+ checkAndGetLeaf(result, data_node, "match-client-id");
+ checkAndGetLeaf(result, data_node, "next-server");
+ checkAndGetLeaf(result, data_node, "server-hostname");
+ }
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -225,130 +158,12 @@ void
TranslatorSharedNetwork::setSharedNetworkKea(string const& xpath,
ConstElementPtr elem,
const std::string& subsel) {
- // Skip name which is the key.
- ConstElementPtr subnets = elem->get(subsel);
- if (subnets && (subnets->size() > 0)) {
- setSubnets(xpath, subnets);
- }
- if (subsel == "subnet6") {
- ConstElementPtr preferred = elem->get("preferred-lifetime");
- if (preferred) {
- setItem(xpath + "/preferred-lifetime", preferred, LeafBaseType::Uint32);
- }
- ConstElementPtr min_pref = elem->get("min-preferred-lifetime");
- if (min_pref) {
- setItem(xpath + "/min-preferred-lifetime", min_pref, LeafBaseType::Uint32);
- }
- ConstElementPtr max_pref = elem->get("max-preferred-lifetime");
- if (max_pref) {
- setItem(xpath + "/max-preferred-lifetime", max_pref, LeafBaseType::Uint32);
- }
- }
- ConstElementPtr valid = elem->get("valid-lifetime");
- if (valid) {
- setItem(xpath + "/valid-lifetime", valid, LeafBaseType::Uint32);
- }
- ConstElementPtr min_valid = elem->get("min-valid-lifetime");
- if (min_valid) {
- setItem(xpath + "/min-valid-lifetime", min_valid, LeafBaseType::Uint32);
- }
- ConstElementPtr max_valid = elem->get("max-valid-lifetime");
- if (max_valid) {
- setItem(xpath + "/max-valid-lifetime", max_valid, LeafBaseType::Uint32);
- }
- ConstElementPtr renew = elem->get("renew-timer");
- if (renew) {
- setItem(xpath + "/renew-timer", renew, LeafBaseType::Uint32);
- }
- ConstElementPtr rebind = elem->get("rebind-timer");
- if (rebind) {
- setItem(xpath + "/rebind-timer", rebind, LeafBaseType::Uint32);
- }
- ConstElementPtr calculate = elem->get("calculate-tee-times");
- if (calculate) {
- setItem(xpath + "/calculate-tee-times", calculate, LeafBaseType::Bool);
- }
- ConstElementPtr t1_percent = elem->get("t1-percent");
- if (t1_percent) {
- setItem(xpath + "/t1-percent", t1_percent, LeafBaseType::Dec64);
- }
- ConstElementPtr t2_percent = elem->get("t2-percent");
- if (t2_percent) {
- setItem(xpath + "/t2-percent", t2_percent, LeafBaseType::Dec64);
- }
- ConstElementPtr options = elem->get("option-data");
- if (options && (options->size() > 0)) {
- setOptionDataList(xpath, options);
- }
- ConstElementPtr interface = elem->get("interface");
- if (interface) {
- setItem(xpath + "/interface", interface, LeafBaseType::String);
- }
- if (subsel == "subnet6") {
- ConstElementPtr interface_id = elem->get("interface-id");
- if (interface_id) {
- setItem(xpath + "/interface-id", interface_id, LeafBaseType::String);
- }
- ConstElementPtr rapid_commit = elem->get("rapid-commit");
- if (rapid_commit) {
- setItem(xpath + "/rapid-commit", rapid_commit, LeafBaseType::Bool);
- }
- }
- ConstElementPtr guard = elem->get("client-class");
- if (guard) {
- setItem(xpath + "/client-class", guard, LeafBaseType::String);
- }
- ConstElementPtr required = elem->get("require-client-classes");
- if (required && (required->size() > 0)) {
- for (ConstElementPtr rclass : required->listValue()) {
- setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
- }
- }
- ConstElementPtr mode = elem->get("reservation-mode");
- if (mode) {
- setItem(xpath + "/reservation-mode", mode, LeafBaseType::Enum);
- }
- ConstElementPtr relay = elem->get("relay");
- if (relay) {
- ConstElementPtr address = relay->get("ip-address");
- ConstElementPtr addresses = relay->get("ip-addresses");
- if (address) {
- setItem(xpath + "/relay/ip-addresses", address, LeafBaseType::String);
- } else if (addresses && (addresses->size() > 0)) {
- for (ConstElementPtr addr : addresses->listValue()) {
- setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String);
- }
- }
- }
- if (subsel == "subnet4") {
- ConstElementPtr match = elem->get("match-client-id");
- if (match) {
- setItem(xpath + "/match-client-id", match, LeafBaseType::Bool);
- }
- ConstElementPtr auth = elem->get("authoritative");
- if (auth) {
- setItem(xpath + "/authoritative", auth, LeafBaseType::Bool);
- }
- ConstElementPtr next = elem->get("next-server");
- if (next) {
- setItem(xpath + "/next-server", next, LeafBaseType::String);
- }
- ConstElementPtr hostname = elem->get("server-hostname");
- if (hostname) {
- setItem(xpath + "/server-hostname", hostname, LeafBaseType::String);
- }
- ConstElementPtr boot = elem->get("boot-file-name");
- if (boot) {
- setItem(xpath + "/boot-file-name", boot, LeafBaseType::String);
- }
- }
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- ConstElementPtr repr = Element::create(context->str());
- setItem(xpath + "/user-context", repr, LeafBaseType::String);
- }
+ // Skip key "name".
+
checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
+ checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
@@ -359,10 +174,60 @@ TranslatorSharedNetwork::setSharedNetworkKea(string const& xpath,
checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "interface", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum);
checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
+ checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
+
+ checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String);
+
+ checkAndSetUserContext(elem, xpath);
+
+ ConstElementPtr relay = elem->get("relay");
+ if (relay) {
+ ConstElementPtr address = relay->get("ip-address");
+ ConstElementPtr addresses = relay->get("ip-addresses");
+ if (address) {
+ setItem(xpath + "/relay/ip-addresses", address, LeafBaseType::String);
+ } else if (addresses && !addresses->empty()) {
+ for (ConstElementPtr addr : addresses->listValue()) {
+ setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String);
+ }
+ }
+ }
+
+ ConstElementPtr options = elem->get("option-data");
+ if (options && !options->empty()) {
+ setOptionDataList(xpath, options);
+ }
+
+ ConstElementPtr subnets = elem->get(subsel);
+ if (subnets && !subnets->empty()) {
+ setSubnets(xpath, subnets);
+ }
+
+ if (subsel == "subnet6") {
+ checkAndSetLeaf(elem, xpath, "interface-id", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "rapid-commit", LeafBaseType::Bool);
+ } else {
+ checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
+ }
}
TranslatorSharedNetworks::TranslatorSharedNetworks(Session session,
diff --git a/src/lib/yang/translator_subnet.cc b/src/lib/yang/translator_subnet.cc
index 429e417aaf..68cc2b4dee 100644
--- a/src/lib/yang/translator_subnet.cc
+++ b/src/lib/yang/translator_subnet.cc
@@ -62,8 +62,9 @@ TranslatorSubnet::getSubnetFromAbsoluteXpath(string const& xpath) {
ElementPtr
TranslatorSubnet::getSubnetIetf6(DataNode const& data_node) {
ElementPtr result = Element::createMap();
- /// @todo timers
- /// @todo: option-data
+ getMandatoryDivergingLeaf(result, data_node, "subnet", "network-prefix");
+ getMandatoryDivergingLeaf(result, data_node, "id", "network-range-id");
+
Set<DataNode> const& address_pools(data_node.findXPath("address-pools"));
if (!address_pools.empty()) {
ConstElementPtr const& pools(getPools(address_pools.front()));
@@ -71,6 +72,7 @@ TranslatorSubnet::getSubnetIetf6(DataNode const& data_node) {
result->set("pools", pools);
}
}
+
Set<DataNode> const& yang_pd_pools(data_node.findXPath("pd-pools"));
if (!yang_pd_pools.empty()) {
ConstElementPtr const& pd_pools(getPdPools(yang_pd_pools.front()));
@@ -78,184 +80,36 @@ TranslatorSubnet::getSubnetIetf6(DataNode const& data_node) {
result->set("pd-pools", pd_pools);
}
}
- ConstElementPtr subnet = getItem(data_node, "network-prefix");
- if (!subnet) {
- isc_throw(BadValue, "getSubnetIetf6 requires network prefix");
- }
- result->set("subnet", subnet);
- ConstElementPtr id = getItem(data_node, "network-range-id");
- if (!id) {
- isc_throw(BadValue, "getSubnetIetf6 requires network range id");
- }
- result->set("id", id);
- /// @todo: reservations
- /// missing a lot of things
+
ConstElementPtr description = getItem(data_node, "network-description");
- /// Adding description if exists.
if (description) {
ElementPtr context = Element::createMap();
context->set("description", description);
result->set("user-context", context);
}
- /// missing a lot of things
+
if (result->get("pools")) {
AdaptorPool::toSubnet(model_, result, result->get("pools"));
}
- return (result);
+
+ /// @todo: timers
+ /// @todo: option-data
+ /// @todo: reservations
+
+ return (result->empty() ? ElementPtr() : result);
}
ElementPtr
TranslatorSubnet::getSubnetKea(DataNode const& data_node) {
ElementPtr result = Element::createMap();
- if (model_ == KEA_DHCP6_SERVER) {
- ConstElementPtr preferred = getItem(data_node, "preferred-lifetime");
- if (preferred) {
- result->set("preferred-lifetime", preferred);
- }
- ConstElementPtr min_pref = getItem(data_node, "min-preferred-lifetime");
- if (min_pref) {
- result->set("min-preferred-lifetime", min_pref);
- }
- ConstElementPtr max_pref = getItem(data_node, "max-preferred-lifetime");
- if (max_pref) {
- result->set("max-preferred-lifetime", max_pref);
- }
- }
- ConstElementPtr valid = getItem(data_node, "valid-lifetime");
- if (valid) {
- result->set("valid-lifetime", valid);
- }
- ConstElementPtr min_valid = getItem(data_node, "min-valid-lifetime");
- if (min_valid) {
- result->set("min-valid-lifetime", min_valid);
- }
- ConstElementPtr max_valid = getItem(data_node, "max-valid-lifetime");
- if (max_valid) {
- result->set("max-valid-lifetime", max_valid);
- }
- ConstElementPtr renew = getItem(data_node, "renew-timer");
- if (renew) {
- result->set("renew-timer", renew);
- }
- ConstElementPtr rebind = getItem(data_node, "rebind-timer");
- if (rebind) {
- result->set("rebind-timer", rebind);
- }
- ConstElementPtr calculate = getItem(data_node, "calculate-tee-times");
- if (calculate) {
- result->set("calculate-tee-times", calculate);
- }
- ConstElementPtr t1_percent = getItem(data_node, "t1-percent");
- if (t1_percent) {
- result->set("t1-percent", t1_percent);
- }
- ConstElementPtr t2_percent = getItem(data_node, "t2-percent");
- if (t2_percent) {
- result->set("t2-percent", t2_percent);
- }
- ConstElementPtr options = getOptionDataList(data_node);
- if (options && (options->size() > 0)) {
- result->set("option-data", options);
- }
- ConstElementPtr pools = getPools(data_node);
- if (pools && (pools->size() > 0)) {
- result->set("pools", pools);
- }
- if (model_ == KEA_DHCP6_SERVER) {
- ElementPtr pd_pools = getPdPools(data_node);
- if (pd_pools && (pd_pools->size() > 0)) {
- result->set("pd-pools", pd_pools);
- }
- }
- ConstElementPtr subnet = getItem(data_node, "subnet");
- if (!subnet) {
- isc_throw(BadValue, "getSubnetKea requires subnet");
- }
- result->set("subnet", subnet);
- ConstElementPtr interface = getItem(data_node, "interface");
- if (interface) {
- result->set("interface", interface);
- }
- if (model_ == KEA_DHCP6_SERVER) {
- ConstElementPtr interface_id = getItem(data_node, "interface-id");
- if (interface_id) {
- result->set("interface-id", interface_id);
- }
- }
- ConstElementPtr id = getItem(data_node, "id");
- if (!id) {
- isc_throw(BadValue, "getSubnetKea requires id");
- }
- result->set("id", id);
- if (model_ == KEA_DHCP6_SERVER) {
- ConstElementPtr rapid_commit = getItem(data_node, "rapid-commit");
- if (rapid_commit) {
- result->set("rapid-commit", rapid_commit);
- }
- }
- ConstElementPtr guard = getItem(data_node, "client-class");
- if (guard) {
- result->set("client-class", guard);
- }
- ConstElementPtr required = getItem(data_node, "require-client-classes");
- if (required && (required->size() > 0)) {
- result->set("require-client-classes", required);
- }
- ConstElementPtr hosts = getHosts(data_node);
- if (hosts && (hosts->size() > 0)) {
- result->set("reservations", hosts);
- }
- ConstElementPtr mode = getItem(data_node, "reservation-mode");
- if (mode) {
- result->set("reservation-mode", mode);
- }
- ConstElementPtr relay = getItem(data_node, "relay/ip-addresses");
- if (relay && (relay->size() > 0)) {
- ElementPtr relay_map = Element::createMap();
- relay_map->set("ip-addresses", relay);
- result->set("relay", relay_map);
- }
- if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr match = getItem(data_node, "match-client-id");
- if (match) {
- result->set("match-client-id", match);
- }
- ConstElementPtr auth = getItem(data_node, "authoritative");
- if (auth) {
- result->set("authoritative", auth);
- }
- ConstElementPtr next = getItem(data_node, "next-server");
- if (next) {
- result->set("next-server", next);
- }
- ConstElementPtr hostname = getItem(data_node, "server-hostname");
- if (hostname) {
- result->set("server-hostname", hostname);
- }
- ConstElementPtr boot = getItem(data_node, "boot-file-name");
- if (boot) {
- result->set("boot-file-name", boot);
- }
- ConstElementPtr s4o6_if = getItem(data_node, "subnet-4o6-interface");
- if (s4o6_if) {
- result->set("4o6-interface", s4o6_if);
- }
- ConstElementPtr s4o6_id = getItem(data_node, "subnet-4o6-interface-id");
- if (s4o6_id) {
- result->set("4o6-interface-id", s4o6_id);
- }
- ConstElementPtr s4o6_sub = getItem(data_node, "subnet-4o6-subnet");
- if (s4o6_sub) {
- result->set("4o6-subnet", s4o6_sub);
- }
- }
- ConstElementPtr context = getItem(data_node, "user-context");
- if (context) {
- result->set("user-context", Element::fromJSON(context->stringValue()));
- }
+ getMandatoryLeaf(result, data_node, "id");
+ getMandatoryLeaf(result, data_node, "subnet");
+
checkAndGetLeaf(result, data_node, "cache-max-age");
checkAndGetLeaf(result, data_node, "cache-threshold");
+ checkAndGetLeaf(result, data_node, "calculate-tee-times");
+ checkAndGetLeaf(result, data_node, "client-class");
checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
checkAndGetLeaf(result, data_node, "ddns-override-client-update");
checkAndGetLeaf(result, data_node, "ddns-override-no-update");
@@ -266,11 +120,71 @@ TranslatorSubnet::getSubnetKea(DataNode const& data_node) {
checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
checkAndGetLeaf(result, data_node, "hostname-char-replacement");
checkAndGetLeaf(result, data_node, "hostname-char-set");
+ checkAndGetLeaf(result, data_node, "interface");
+ checkAndGetLeaf(result, data_node, "max-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "min-valid-lifetime");
+ checkAndGetLeaf(result, data_node, "rebind-timer");
+ checkAndGetLeaf(result, data_node, "renew-timer");
+ checkAndGetLeaf(result, data_node, "require-client-classes");
+ checkAndGetLeaf(result, data_node, "reservation-mode");
checkAndGetLeaf(result, data_node, "reservations-global");
checkAndGetLeaf(result, data_node, "reservations-in-subnet");
checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
checkAndGetLeaf(result, data_node, "store-extended-info");
- return (result);
+ checkAndGetLeaf(result, data_node, "t1-percent");
+ checkAndGetLeaf(result, data_node, "t2-percent");
+ checkAndGetLeaf(result, data_node, "valid-lifetime");
+
+ checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
+
+ ConstElementPtr options = getOptionDataList(data_node);
+ if (options) {
+ result->set("option-data", options);
+ }
+
+ ConstElementPtr pools = getPools(data_node);
+ if (pools) {
+ result->set("pools", pools);
+ }
+
+ Set<DataNode> const& yang_relay(data_node.findXPath("relay"));
+ if (!yang_relay.empty()) {
+ ElementPtr relay_map(Element::createMap());
+ checkAndGetLeaf(relay_map, yang_relay.front(), "ip-addresses");
+ if (!relay_map->empty()) {
+ result->set("relay", relay_map);
+ }
+ }
+
+ ConstElementPtr hosts = getHosts(data_node);
+ if (hosts) {
+ result->set("reservations", hosts);
+ }
+
+ if (model_ == KEA_DHCP6_SERVER) {
+ checkAndGetLeaf(result, data_node, "interface-id");
+ checkAndGetLeaf(result, data_node, "max-preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "min-preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "preferred-lifetime");
+ checkAndGetLeaf(result, data_node, "rapid-commit");
+
+ ElementPtr pd_pools = getPdPools(data_node);
+ if (pd_pools) {
+ result->set("pd-pools", pd_pools);
+ }
+ } else if (model_ == KEA_DHCP4_SERVER) {
+ checkAndGetLeaf(result, data_node, "authoritative");
+ checkAndGetLeaf(result, data_node, "boot-file-name");
+ checkAndGetLeaf(result, data_node, "match-client-id");
+ checkAndGetLeaf(result, data_node, "next-server");
+ checkAndGetLeaf(result, data_node, "server-hostname");
+
+ checkAndGetDivergingLeaf(result, data_node, "4o6-interface", "subnet-4o6-interface");
+ checkAndGetDivergingLeaf(result, data_node, "4o6-interface-id", "subnet-4o6-interface-id");
+ checkAndGetDivergingLeaf(result, data_node, "4o6-subnet", "subnet-4o6-subnet");
+ }
+
+ return (result->empty() ? ElementPtr() : result);
}
void
@@ -294,7 +208,10 @@ TranslatorSubnet::setSubnet(string const& xpath, ConstElementPtr elem) {
void
TranslatorSubnet::setSubnetIetf6(string const& xpath, ConstElementPtr elem) {
- /// Skip id as it is the key.
+ /// Skip key "id".
+
+ setMandatoryDivergingLeaf(elem, xpath, "subnet", "network-prefix", LeafBaseType::String);
+
AdaptorPool::fromSubnet(model_, elem, elem->get("pools"));
ConstElementPtr context = elem->get("user-context");
if (context && context->contains("description")) {
@@ -308,134 +225,33 @@ TranslatorSubnet::setSubnetIetf6(string const& xpath, ConstElementPtr elem) {
isc_throw(BadValue, "setSubnetIetf6 requires subnet: " << elem->str());
}
setItem(xpath + "/network-prefix", subnet, LeafBaseType::String);
- /// @todo option-data
ConstElementPtr pools = elem->get("pools");
- if (pools && (pools->size() > 0)) {
+ if (pools && !pools->empty()) {
setPools(xpath + "/address-pools", pools);
}
pools = elem->get("pd-pools");
- if (pools && (pools->size() > 0)) {
+ if (pools && !pools->empty()) {
setPdPools(xpath + "/pd-pools", pools);
}
- /// @todo reservations
+
+ /// @todo: option-data
+ /// @todo: reservations
}
void
TranslatorSubnet::setSubnetKea(string const& xpath, ConstElementPtr elem) {
- /// Skip id as it is the key.
- if (model_ == KEA_DHCP6_SERVER) {
- ConstElementPtr preferred = elem->get("preferred-lifetime");
- if (preferred) {
- setItem(xpath + "/preferred-lifetime", preferred, LeafBaseType::Uint32);
- }
- ConstElementPtr min_pref = elem->get("min-preferred-lifetime");
- if (min_pref) {
- setItem(xpath + "/min-preferred-lifetime", min_pref, LeafBaseType::Uint32);
- }
- ConstElementPtr max_pref = elem->get("max-preferred-lifetime");
- if (max_pref) {
- setItem(xpath + "/max-preferred-lifetime", max_pref, LeafBaseType::Uint32);
- }
- }
- ConstElementPtr valid = elem->get("valid-lifetime");
- if (valid) {
- setItem(xpath + "/valid-lifetime", valid, LeafBaseType::Uint32);
- }
- ConstElementPtr min_valid = elem->get("min-valid-lifetime");
- if (min_valid) {
- setItem(xpath + "/min-valid-lifetime", min_valid, LeafBaseType::Uint32);
- }
- ConstElementPtr max_valid = elem->get("max-valid-lifetime");
- if (max_valid) {
- setItem(xpath + "/max-valid-lifetime", max_valid, LeafBaseType::Uint32);
- }
- ConstElementPtr renew = elem->get("renew-timer");
- if (renew) {
- setItem(xpath + "/renew-timer", renew, LeafBaseType::Uint32);
- }
- ConstElementPtr rebind = elem->get("rebind-timer");
- if (rebind) {
- setItem(xpath + "/rebind-timer", rebind, LeafBaseType::Uint32);
- }
- ConstElementPtr calculate = elem->get("calculate-tee-times");
- if (calculate) {
- setItem(xpath + "/calculate-tee-times", calculate, LeafBaseType::Bool);
- }
- ConstElementPtr t1_percent = elem->get("t1-percent");
- if (t1_percent) {
- setItem(xpath + "/t1-percent", t1_percent, LeafBaseType::Dec64);
- }
- ConstElementPtr t2_percent = elem->get("t2-percent");
- if (t2_percent) {
- setItem(xpath + "/t2-percent", t2_percent, LeafBaseType::Dec64);
- }
- ConstElementPtr options = elem->get("option-data");
- if (options && (options->size() > 0)) {
- setOptionDataList(xpath, options);
- }
- ConstElementPtr pools = elem->get("pools");
- if (pools && (pools->size() > 0)) {
- setPools(xpath, pools);
- }
- if (model_ == KEA_DHCP6_SERVER) {
- pools = elem->get("pd-pools");
- if (pools && (pools->size() > 0)) {
- setPdPools(xpath, pools);
- }
- }
+ /// Skip key "id".
+
ConstElementPtr subnet = elem->get("subnet");
if (!subnet) {
isc_throw(BadValue, "setSubnetKea requires subnet: " << elem->str());
}
setItem(xpath + "/subnet", subnet, LeafBaseType::String);
- ConstElementPtr interface = elem->get("interface");
- if (interface) {
- setItem(xpath + "/interface", interface, LeafBaseType::String);
- }
- if (model_ == KEA_DHCP6_SERVER) {
- ConstElementPtr interface_id = elem->get("interface-id");
- if (interface_id) {
- setItem(xpath + "/interface-id", interface_id, LeafBaseType::String);
- }
- }
- if (model_ == KEA_DHCP6_SERVER) {
- ConstElementPtr rapid_commit = elem->get("rapid-commit");
- if (rapid_commit) {
- setItem(xpath + "/rapid-commit", rapid_commit, LeafBaseType::Bool);
- }
- }
- ConstElementPtr guard = elem->get("client-class");
- if (guard) {
- setItem(xpath + "/client-class", guard, LeafBaseType::String);
- }
- ConstElementPtr required = elem->get("require-client-classes");
- if (required && (required->size() > 0)) {
- for (ConstElementPtr rclass : required->listValue()) {
- setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
- }
- }
- ConstElementPtr hosts = elem->get("reservations");
- if (hosts && (hosts->size() > 0)) {
- setHosts(xpath, hosts);
- }
- ConstElementPtr mode = elem->get("reservation-mode");
- if (mode) {
- setItem(xpath + "/reservation-mode", mode, LeafBaseType::Enum);
- }
- ConstElementPtr relay = elem->get("relay");
- if (relay) {
- ConstElementPtr address = relay->get("ip-address");
- ConstElementPtr addresses = relay->get("ip-addresses");
- if (address) {
- setItem(xpath + "/relay/ip-addresses", address, LeafBaseType::String);
- } else if (addresses && (addresses->size() > 0)) {
- for (ConstElementPtr addr : addresses->listValue()) {
- setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String);
- }
- }
- }
+
checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
+ checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
@@ -446,49 +262,74 @@ TranslatorSubnet::setSubnetKea(string const& xpath, ConstElementPtr elem) {
checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "interface", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum);
checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
- if (model_ == KEA_DHCP4_SERVER) {
- ConstElementPtr match = elem->get("match-client-id");
- if (match) {
- setItem(xpath + "/match-client-id", match, LeafBaseType::Bool);
- }
- ConstElementPtr auth = elem->get("authoritative");
- if (auth) {
- setItem(xpath + "/authoritative", auth, LeafBaseType::Bool);
- }
- ConstElementPtr next = elem->get("next-server");
- if (next) {
- setItem(xpath + "/next-server", next, LeafBaseType::String);
- }
- ConstElementPtr hostname = elem->get("server-hostname");
- if (hostname) {
- setItem(xpath + "/server-hostname", hostname, LeafBaseType::String);
- }
- ConstElementPtr boot = elem->get("boot-file-name");
- if (boot) {
- setItem(xpath + "/boot-file-name", boot, LeafBaseType::String);
- }
- ConstElementPtr s4o6_if = elem->get("4o6-interface");
- if (s4o6_if) {
- setItem(xpath + "/subnet-4o6-interface", s4o6_if, LeafBaseType::String);
- }
- ConstElementPtr s4o6_id = elem->get("4o6-interface-id");
- if (s4o6_id) {
- setItem(xpath + "/subnet-4o6-interface-id", s4o6_id, LeafBaseType::String);
- }
- ConstElementPtr s4o6_subnet = elem->get("4o6-subnet");
- if (s4o6_subnet) {
- setItem(xpath + "/subnet-4o6-subnet", s4o6_subnet, LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
+ checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+
+ checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String);
+
+ ConstElementPtr options = elem->get("option-data");
+ if (options && !options->empty()) {
+ setOptionDataList(xpath, options);
+ }
+ ConstElementPtr pools = elem->get("pools");
+ if (pools && !pools->empty()) {
+ setPools(xpath, pools);
+ }
+ ConstElementPtr relay = elem->get("relay");
+ if (relay) {
+ ConstElementPtr address = relay->get("ip-address");
+ ConstElementPtr addresses = relay->get("ip-addresses");
+ if (address) {
+ setItem(xpath + "/relay/ip-addresses", address, LeafBaseType::String);
+ } else if (addresses && !addresses->empty()) {
+ for (ConstElementPtr addr : addresses->listValue()) {
+ setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String);
+ }
}
}
- ConstElementPtr context = Adaptor::getContext(elem);
- if (context) {
- ConstElementPtr repr = Element::create(context->str());
- setItem(xpath + "/user-context", repr, LeafBaseType::String);
+ ConstElementPtr hosts = elem->get("reservations");
+ if (hosts && !hosts->empty()) {
+ setHosts(xpath, hosts);
+ }
+
+ if (model_ == KEA_DHCP6_SERVER) {
+ checkAndSetLeaf(elem, xpath, "interface-id", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "rapid-commit", LeafBaseType::Bool);
+
+ pools = elem->get("pd-pools");
+ if (pools && !pools->empty()) {
+ setPdPools(xpath, pools);
+ }
+ } else {
+ checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "rapid-commit", LeafBaseType::Bool);
+ checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
+
+ checkAndSetDivergingLeaf(elem, xpath, "4o6-interface", "subnet-4o6-interface", LeafBaseType::String);
+ checkAndSetDivergingLeaf(elem, xpath, "4o6-interface-id", "subnet-4o6-interface-id", LeafBaseType::String);
+ checkAndSetDivergingLeaf(elem, xpath, "4o6-subnet", "subnet-4o6-subnet", LeafBaseType::String);
}
+ checkAndSetUserContext(elem, xpath);
}
TranslatorSubnets::TranslatorSubnets(Session session, const string& model)