From: Francis Dupont Date: Thu, 18 Oct 2018 16:46:26 +0000 (+0200) Subject: [65-libyang-adaptors] Addressed comments X-Git-Tag: 65-libyang-config-adaptor_base~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09963c4aa43760de2c92500ab9f16ca5be44a56a;p=thirdparty%2Fkea.git [65-libyang-adaptors] Addressed comments --- diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h index 4e9d82923b..d0336e7d43 100644 --- a/src/lib/dhcp/std_option_defs.h +++ b/src/lib/dhcp/std_option_defs.h @@ -12,6 +12,10 @@ #include #include +// NOTE: +// When adding a new space, make sure you also update +// src/lib/yang/adaptor_option.cc + namespace isc { namespace dhcp { diff --git a/src/lib/yang/adaptor_host.cc b/src/lib/yang/adaptor_host.cc index 0a7ed9ec08..3f153d592a 100644 --- a/src/lib/yang/adaptor_host.cc +++ b/src/lib/yang/adaptor_host.cc @@ -34,8 +34,9 @@ AdaptorHost::quoteIdentifier(ElementPtr host) { return; } const string& id = flex_id->stringValue(); + // Empty is allowed. if (id.empty()) { - isc_throw(BadValue, "empty flexible identifier in " << host->str()); + return; } // No special and no not printable characters? if (id.find_first_not_of(STD_CHARACTERS) == string::npos) { diff --git a/src/lib/yang/adaptor_option.cc b/src/lib/yang/adaptor_option.cc index 901fccb9e8..a177a40905 100644 --- a/src/lib/yang/adaptor_option.cc +++ b/src/lib/yang/adaptor_option.cc @@ -45,10 +45,10 @@ AdaptorOption::checkCode(ConstElementPtr option) { void AdaptorOption::collect(ConstElementPtr option, OptionCodes& codes) { - ConstElementPtr space = option->get("space"); - ConstElementPtr code = option->get("code"); ConstElementPtr name = option->get("name"); if (name) { + ConstElementPtr space = option->get("space"); + ConstElementPtr code = option->get("code"); string index = space->stringValue() + "@" + name->stringValue(); uint16_t val = static_cast(code->intValue()); codes.insert(std::pair(index, val)); diff --git a/src/lib/yang/adaptor_option.h b/src/lib/yang/adaptor_option.h index 0d408f1581..594c883882 100644 --- a/src/lib/yang/adaptor_option.h +++ b/src/lib/yang/adaptor_option.h @@ -22,6 +22,9 @@ namespace yang { /// @brief Map for DHCP option definitions handling code and /// an index built from space and name. +/// +/// The map is used to store space+name to code mappings so for +/// an option data without a code entry the code entry can be supplied. typedef std::map OptionCodes; /// @brief JSON adaptor for option data or definition setting defaults. @@ -69,6 +72,10 @@ public: /// @brief Collect definition. /// + /// This method looks at an option definition and adds the + /// space+name to code maping into the OptionCodes codes store + /// aka definitions. + /// /// @param option The option definition. /// @param codes The reference to option definitions. static void collect(isc::data::ConstElementPtr option, OptionCodes& codes); diff --git a/src/lib/yang/adaptor_pool.h b/src/lib/yang/adaptor_pool.h index 40924a9669..6f541acbba 100644 --- a/src/lib/yang/adaptor_pool.h +++ b/src/lib/yang/adaptor_pool.h @@ -60,6 +60,9 @@ public: /// supported model is ietf-dhcpv6-server. The parameters moved are /// valid-lifetime, preferred-lifetime, renew-timer, renbind-timer. /// + /// @note: currently it is the only from YANH to JSON aka + /// post-processing adaptor. + /// /// @param model Model name. /// @param subnet The subnet element. /// @param pools The children pools. diff --git a/src/lib/yang/adaptor_subnet.h b/src/lib/yang/adaptor_subnet.h index d6ad80b2ca..0bfcae00ef 100644 --- a/src/lib/yang/adaptor_subnet.h +++ b/src/lib/yang/adaptor_subnet.h @@ -53,7 +53,7 @@ public: /// @brief Update relay. /// - /// Force the use of ip-addresses vs. ip-address. + /// Force the use of ip-addresses when it finds an ip-address entry. /// Can be used for shared networks too. /// /// @param subnet The subnet. diff --git a/src/lib/yang/yang.dox b/src/lib/yang/yang.dox index 60c03709a8..05bf4c33a7 100644 --- a/src/lib/yang/yang.dox +++ b/src/lib/yang/yang.dox @@ -70,9 +70,24 @@ from YANG to follow the Kea syntax, for instance by adding static components which are not in the model. Methods provided by adaptors are class methods (i.e. declared static). -Specific adaptors are derived from the isc::yang::Adaptor base class. - - @page unitTestsSysrepo Running unit-tests with Sysrepo +Specific adaptors can be derived from the isc::yang::Adaptor base class. + +There are a few basic adaptors and per structure adaptors. The second +category of adaptors are divided into: + - from JSON to YANG adaptors or pre-processing which adapt a JSON + configuration to make it acceptable by a from JSON to YANG (setXXX) + translators. For a Kea model this kind of adaptors fill some required + but missing fields, or only transform a configuration into a canonical + form. Note for a Kea model and a configuration taken from config-get + or config-write it likely does nearly nothing but the code must + handle any hand written configuration so these adaptors are always + applied. + + - from YANG to JSON adaptors or post-processing which adapt translated + YANG configuration (by getXXX) to make it acceptable by a Kea server. + By definition they are not defined for Kea models. + +@section unitTestsSysrepo Running unit-tests with Sysrepo To run YANG/NETCONF/Sysrepo tests you obviously need to compile Kea with Sysrepo support: