From: Francis Dupont Date: Fri, 5 Oct 2018 22:54:44 +0000 (+0200) Subject: [65-libyang-pool] Addressed comments and updated base code X-Git-Tag: 153-netconf-control-socket_base~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8788c935401579e65efdfc7e5d4bba4def266b3b;p=thirdparty%2Fkea.git [65-libyang-pool] Addressed comments and updated base code --- diff --git a/src/lib/yang/models/kea-dhcp4-server.yang b/src/lib/yang/models/kea-dhcp4-server.yang index bbd5422c16..e997dfbede 100644 --- a/src/lib/yang/models/kea-dhcp4-server.yang +++ b/src/lib/yang/models/kea-dhcp4-server.yang @@ -115,7 +115,7 @@ module kea-dhcp4-server { uses server-hostname; uses boot-file-name; uses dhcp:host-user-context; - } + } grouping reservations { description "Host reservations grouping."; diff --git a/src/lib/yang/pretests/sysrepo_setup_tests.cc b/src/lib/yang/pretests/sysrepo_setup_tests.cc index f385ab858f..5f7e5e1ee2 100644 --- a/src/lib/yang/pretests/sysrepo_setup_tests.cc +++ b/src/lib/yang/pretests/sysrepo_setup_tests.cc @@ -11,6 +11,8 @@ using namespace std; +/// Not using libyang headers, e.g. yang_models.h. + const string TEST_MODULE = "keatest-module"; const string IETF_TYPES = "ietf-inet-types"; const string YANG_TYPES = "ietf-yang-types"; diff --git a/src/lib/yang/tests/adaptor_unittests.cc b/src/lib/yang/tests/adaptor_unittests.cc index 7ddf419e68..73660be3de 100644 --- a/src/lib/yang/tests/adaptor_unittests.cc +++ b/src/lib/yang/tests/adaptor_unittests.cc @@ -8,7 +8,6 @@ #include -#include #include using namespace std; diff --git a/src/lib/yang/tests/sysrepo_setup.h b/src/lib/yang/tests/sysrepo_setup.h index fbab42c5dd..b600504916 100644 --- a/src/lib/yang/tests/sysrepo_setup.h +++ b/src/lib/yang/tests/sysrepo_setup.h @@ -59,7 +59,7 @@ public: /// @brief Shared pointer to the transaction object. boost::shared_ptr t_obj_; }; - + } // namespace test } // namespace yang } // namespace isc diff --git a/src/lib/yang/tests/translator_option_data_unittests.cc b/src/lib/yang/tests/translator_option_data_unittests.cc index 8365f60f5d..f02911607a 100644 --- a/src/lib/yang/tests/translator_option_data_unittests.cc +++ b/src/lib/yang/tests/translator_option_data_unittests.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -38,7 +39,7 @@ public: // This test verifies that an empty option data list can be properly // translated from YANG to JSON. TEST_F(TranslatorOptionDataListTest, getEmpty) { - useModel("kea-dhcp4-server"); + useModel(KEA_DHCP4_SERVER); // Get the option data list and checks it is empty. const string& xpath = "/kea-dhcp4-server:config/option-data-list"; @@ -52,7 +53,7 @@ TEST_F(TranslatorOptionDataListTest, getEmpty) { // This test verifies that one option data can be properly translated // from YANG to JSON. TEST_F(TranslatorOptionDataListTest, get) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Create the option code 100. const string& xpath = "/kea-dhcp6-server:config/option-data-list"; @@ -65,7 +66,7 @@ TEST_F(TranslatorOptionDataListTest, get) { S_Val s_data(new Val("12121212")); ASSERT_NO_THROW(sess_->set_item(xdata.c_str(), s_data)); ASSERT_NO_THROW(sess_->set_item(xsend.c_str(), s_false)); - + // Get the option data. ConstElementPtr option; EXPECT_NO_THROW(option = t_obj_->getOptionData(xoption)); @@ -91,7 +92,7 @@ TEST_F(TranslatorOptionDataListTest, get) { // This test verifies that an empty option data list can be properly // translated from JSON to YANG. TEST_F(TranslatorOptionDataListTest, setEmpty) { - useModel("kea-dhcp4-server"); + useModel(KEA_DHCP4_SERVER); // Set empty list. const string& xpath = "/kea-dhcp4-server:config/option-data-list"; @@ -113,7 +114,7 @@ TEST_F(TranslatorOptionDataListTest, setEmpty) { // This test verifies that one option data can be properly translated // from JSON to YANG. TEST_F(TranslatorOptionDataListTest, set) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Set one option data. const string& xpath = "/kea-dhcp6-server:config/option-data-list"; diff --git a/src/lib/yang/tests/translator_option_def_unittests.cc b/src/lib/yang/tests/translator_option_def_unittests.cc index 490efe5f27..556d81f63a 100644 --- a/src/lib/yang/tests/translator_option_def_unittests.cc +++ b/src/lib/yang/tests/translator_option_def_unittests.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -38,7 +39,7 @@ public: // This test verifies that an empty option definition list can be properly // translated from YANG to JSON. TEST_F(TranslatorOptionDefListTest, getEmpty) { - useModel("kea-dhcp4-server"); + useModel(KEA_DHCP4_SERVER); // Get the option definition list and checks it is empty. const string& xpath = "/kea-dhcp4-server:config/option-def-list"; @@ -52,7 +53,7 @@ TEST_F(TranslatorOptionDefListTest, getEmpty) { // This test verifies that one option definition can be properly // translated from YANG to JSON. TEST_F(TranslatorOptionDefListTest, get) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Create the option code 100. const string& xpath = "/kea-dhcp6-server:config/option-def-list"; @@ -66,7 +67,7 @@ TEST_F(TranslatorOptionDefListTest, get) { ASSERT_NO_THROW(sess_->set_item(xtype.c_str(), s_type)); S_Val s_array(new Val(false)); ASSERT_NO_THROW(sess_->set_item(xarray.c_str(), s_array)); - + // Get the option def. ConstElementPtr def; EXPECT_NO_THROW(def = t_obj_->getOptionDef(xdef)); @@ -91,7 +92,7 @@ TEST_F(TranslatorOptionDefListTest, get) { // This test verifies that an empty option definition list can be properly // translated from JSON to YANG. TEST_F(TranslatorOptionDefListTest, setEmpty) { - useModel("kea-dhcp4-server"); + useModel(KEA_DHCP4_SERVER); // Set empty list. const string& xpath = "/kea-dhcp4-server:config/option-def-list"; @@ -113,7 +114,7 @@ TEST_F(TranslatorOptionDefListTest, setEmpty) { // This test verifies that one option definition can be properly // translated from JSON to YANG. TEST_F(TranslatorOptionDefListTest, set) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Set one option def. const string& xpath = "/kea-dhcp6-server:config/option-def-list"; diff --git a/src/lib/yang/tests/translator_pool_unittests.cc b/src/lib/yang/tests/translator_pool_unittests.cc index 29b4c7ef75..82a56efb06 100644 --- a/src/lib/yang/tests/translator_pool_unittests.cc +++ b/src/lib/yang/tests/translator_pool_unittests.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -38,7 +39,7 @@ public: // This test verifies that an empty pool list can be properly // translated from YANG to JSON using IETF model. TEST_F(TranslatorPoolsTest, getEmptyIetf) { - useModel("ietf-dhcpv6-server"); + useModel(IETF_DHCPV6_SERVER); // Get the pool list and checks it is empty. const string& xpath = "/ietf-dhcpv6-server:server/server-config/" @@ -53,7 +54,7 @@ TEST_F(TranslatorPoolsTest, getEmptyIetf) { // This test verifies that an empty pool list can be properly // translated from YANG to JSON using Kea ad hoc model. TEST_F(TranslatorPoolsTest, getEmptyKea) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Get the pool list and checks it is empty. const string& xpath = @@ -68,7 +69,7 @@ TEST_F(TranslatorPoolsTest, getEmptyKea) { // This test verifies that one pool can be properly // translated from YANG to JSON using IETF model. TEST_F(TranslatorPoolsTest, getIetf) { - useModel("ietf-dhcpv6-server"); + useModel(IETF_DHCPV6_SERVER); // Create the subnet 2001:db8::/48 #111. const string& subnet = "/ietf-dhcpv6-server:server/server-config/" @@ -101,7 +102,7 @@ TEST_F(TranslatorPoolsTest, getIetf) { // This test verifies that one pool can be properly // translated from YANG to JSON using Kea ad hoc model. TEST_F(TranslatorPoolsTest, getKea) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Create the subnet 2001:db8::/48 #111. const string& subnet = @@ -146,7 +147,7 @@ TEST_F(TranslatorPoolsTest, getKea) { // This test verifies that an empty pool list can be properly // translated from JSON to YANG using IETF model. TEST_F(TranslatorPoolsTest, setEmptyIetf) { - useModel("ietf-dhcpv6-server"); + useModel(IETF_DHCPV6_SERVER); // Create the subnet 2001:db8::/48 #111. const string& subnet = "/ietf-dhcpv6-server:server/server-config/" @@ -171,7 +172,7 @@ TEST_F(TranslatorPoolsTest, setEmptyIetf) { // This test verifies that an empty pool list can be properly // translated from JSON to YANG using Kea ad hoc model. TEST_F(TranslatorPoolsTest, setEmptyKea) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Create the subnet 2001:db8::/48 #111. const string& subnet = @@ -196,7 +197,7 @@ TEST_F(TranslatorPoolsTest, setEmptyKea) { // This test verifies that one pool can be properly // translated from JSON to YANG using IETF model. TEST_F(TranslatorPoolsTest, setIetf) { - useModel("ietf-dhcpv6-server"); + useModel(IETF_DHCPV6_SERVER); // Create the subnet 2001:db8::/48 #111. const string& subnet = "/ietf-dhcpv6-server:server/server-config/" @@ -257,7 +258,7 @@ TEST_F(TranslatorPoolsTest, setIetf) { // This test verifies that one pool can be properly // translated from JSON to YANG using Kea ad hoc model. TEST_F(TranslatorPoolsTest, setKea) { - useModel("kea-dhcp6-server"); + useModel(KEA_DHCP6_SERVER); // Create the subnet 2001:db8::/48 #111. const string& subnet = diff --git a/src/lib/yang/translator_option_data.cc b/src/lib/yang/translator_option_data.cc index fde715bbbf..1c7c6d812d 100644 --- a/src/lib/yang/translator_option_data.cc +++ b/src/lib/yang/translator_option_data.cc @@ -6,6 +6,7 @@ #include #include +#include #include using namespace std; @@ -25,8 +26,8 @@ TranslatorOptionData::~TranslatorOptionData() { ElementPtr TranslatorOptionData::getOptionData(const string& xpath) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { return (getOptionDataKea(xpath)); } } catch (const sysrepo_exception& ex) { @@ -77,8 +78,8 @@ void TranslatorOptionData::setOptionData(const string& xpath, ConstElementPtr elem) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { setOptionDataKea(xpath, elem); } else { isc_throw(NotImplemented, @@ -131,8 +132,8 @@ TranslatorOptionDataList::~TranslatorOptionDataList() { ConstElementPtr TranslatorOptionDataList::getOptionDataList(const string& xpath) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { return (getOptionDataListKea(xpath)); } } catch (const sysrepo_exception& ex) { @@ -167,8 +168,8 @@ void TranslatorOptionDataList::setOptionDataList(const string& xpath, ConstElementPtr elem) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { setOptionDataListKea(xpath, elem); } else { isc_throw(NotImplemented, diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc index 47e279cd05..b5365052c5 100644 --- a/src/lib/yang/translator_option_def.cc +++ b/src/lib/yang/translator_option_def.cc @@ -6,6 +6,7 @@ #include #include +#include #include using namespace std; @@ -25,8 +26,8 @@ TranslatorOptionDef::~TranslatorOptionDef() { ElementPtr TranslatorOptionDef::getOptionDef(const string& xpath) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { return (getOptionDefKea(xpath)); } } catch (const sysrepo_exception& ex) { @@ -80,8 +81,8 @@ TranslatorOptionDef::getOptionDefKea(const string& xpath) { void TranslatorOptionDef::setOptionDef(const string& xpath, ConstElementPtr elem) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { setOptionDefKea(xpath, elem); } else { isc_throw(NotImplemented, @@ -140,8 +141,8 @@ TranslatorOptionDefList::~TranslatorOptionDefList() { ConstElementPtr TranslatorOptionDefList::getOptionDefList(const string& xpath) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { return (getOptionDefListKea(xpath)); } } catch (const sysrepo_exception& ex) { @@ -176,8 +177,8 @@ void TranslatorOptionDefList::setOptionDefList(const string& xpath, ConstElementPtr elem) { try { - if ((model_ == "kea-dhcp4-server") || - (model_ == "kea-dhcp6-server")) { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { setOptionDefListKea(xpath, elem); } else { isc_throw(NotImplemented, diff --git a/src/lib/yang/translator_pool.cc b/src/lib/yang/translator_pool.cc index ca4988ae28..d9c0385669 100644 --- a/src/lib/yang/translator_pool.cc +++ b/src/lib/yang/translator_pool.cc @@ -54,7 +54,7 @@ TranslatorPool::getPoolIetf6(const string& xpath) { // Skip pool-id which exists but is not used. ConstElementPtr pool = getItem(xpath + "/pool-prefix"); if (!pool) { - isc_throw(BadValue, "getPoolIetf6 requires pool prefix"); + isc_throw(BadValue, "getPoolIetf6 requires pool prefix at " << xpath); } result->set("pool", pool); // Ignore start-address - end-address as prefix form is mandatory? @@ -97,7 +97,7 @@ TranslatorPool::getPoolKea(const string& xpath) { ConstElementPtr end_addr = getItem(xpath + "/end-address"); if (!start_addr || !end_addr) { isc_throw(BadValue, "getPoolKea requires either prefix or " - "both start and end addresses"); + "both start and end addresses at " << xpath); } ostringstream range; range << start_addr->stringValue() << " - " @@ -161,7 +161,7 @@ TranslatorPool::setPoolIetf6(const string& xpath, ConstElementPtr elem) { const IOAddress& base(addr); setItem(xpath + "/start-address", Element::create(firstAddrInPrefix(base, plen).toText()), - SR_STRING_T); + SR_STRING_T); setItem(xpath + "/end-address", Element::create(lastAddrInPrefix(base, plen).toText()), SR_STRING_T); @@ -301,10 +301,10 @@ void TranslatorPools::setPools(const string& xpath, ConstElementPtr elem) { try { if (model_ == IETF_DHCPV6_SERVER) { - setPoolsbyId(xpath, elem); + setPoolsById(xpath, elem); } else if ((model_ == KEA_DHCP4_SERVER) || (model_ == KEA_DHCP6_SERVER)) { - setPoolsbyAddresses(xpath, elem); + setPoolsByAddresses(xpath, elem); } else { isc_throw(NotImplemented, "setPools not implemented for the model: " << model_); @@ -317,7 +317,7 @@ TranslatorPools::setPools(const string& xpath, ConstElementPtr elem) { } void -TranslatorPools::setPoolsbyId(const string& xpath, ConstElementPtr elem) { +TranslatorPools::setPoolsById(const string& xpath, ConstElementPtr elem) { for (size_t i = 0; i < elem->size(); ++i) { ConstElementPtr pool = elem->get(i); ostringstream prefix; @@ -327,12 +327,12 @@ TranslatorPools::setPoolsbyId(const string& xpath, ConstElementPtr elem) { } void -TranslatorPools::setPoolsbyAddresses(const string& xpath, +TranslatorPools::setPoolsByAddresses(const string& xpath, ConstElementPtr elem) { for (size_t i = 0; i < elem->size(); ++i) { ConstElementPtr pool = elem->get(i); if (!pool->contains("pool")) { - isc_throw(BadValue, "setPoolsbyAddresses: missing required pool: " + isc_throw(BadValue, "setPoolsByAddresses: missing required pool: " << pool->str()); } string pref = pool->get("pool")->stringValue(); diff --git a/src/lib/yang/translator_pool.h b/src/lib/yang/translator_pool.h index 0a8e3421c2..1e702af7c7 100644 --- a/src/lib/yang/translator_pool.h +++ b/src/lib/yang/translator_pool.h @@ -225,7 +225,7 @@ protected: /// /// @param xpath The xpath of the pool list. /// @param elem The JSON element. - void setPoolsbyId(const std::string& xpath, + void setPoolsById(const std::string& xpath, isc::data::ConstElementPtr elem); /// @brief setPools using address pair. @@ -233,7 +233,7 @@ protected: /// @param xpath The xpath of the pool list. /// @param elem The JSON element. /// @throw BadValue on a pool without a prefix. - void setPoolsbyAddresses(const std::string& xpath, + void setPoolsByAddresses(const std::string& xpath, isc::data::ConstElementPtr elem); /// @brief The model. diff --git a/src/lib/yang/yang_models.h b/src/lib/yang/yang_models.h index 31aa9a2c42..42f0f0fac2 100644 --- a/src/lib/yang/yang_models.h +++ b/src/lib/yang/yang_models.h @@ -7,6 +7,8 @@ #ifndef ISC_YANG_MODELS #define ISC_YANG_MODELS 1 +#include + namespace isc { namespace yang { @@ -18,9 +20,16 @@ static const std::string IETF_DHCPV6_SERVER = "ietf-dhcpv6-server"; /// This model is being developed by ISC and is dedicated to Kea. static const std::string KEA_DHCP4_SERVER = "kea-dhcp4-server"; +/// This model is being developed by ISC and is dedicated to Kea. +static const std::string KEA_DHCP6_SERVER = "kea-dhcp6-server"; + /// This model is currently in prototype phase. It will be developed /// by ISC in the near future. -static const std::string KEA_DHCP6_SERVER = "kea-dhcp6-server"; +static const std::string KEA_DHCP_DDNS = "kea-dhcp-ddns"; + +/// This model is currently in prototype phase. It will be developed +/// by ISC in the near future. + static const std::string KEA_CTRL_AGENT = "kea-ctrl-agent"; }; // end of namespace isc::yang }; // end of namespace isc