summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Pavel <andrei@isc.org>2022-10-05 16:23:58 +0200
committerAndrei Pavel <andrei@isc.org>2022-10-21 16:45:24 +0200
commit8292f08821101b9b16a13b05abc1b87824278f4a (patch)
tree0d2b151bea163ecee10763481543f31da8e11aa8
parent[#2311] fix deprecated capture of 'this' in C++20 (diff)
downloadkea-8292f08821101b9b16a13b05abc1b87824278f4a.tar.xz
kea-8292f08821101b9b16a13b05abc1b87824278f4a.zip
[#2311] migrate src/lib/yang to libyang2 and sysrepo2
-rw-r--r--src/lib/yang/adaptor.h2
-rw-r--r--src/lib/yang/pretests/sysrepo_setup_tests.cc51
-rw-r--r--src/lib/yang/tests/adaptor_host_unittests.cc4
-rw-r--r--src/lib/yang/tests/config_unittests.cc38
-rw-r--r--src/lib/yang/tests/sysrepo_setup.h17
-rw-r--r--src/lib/yang/tests/translator_class_unittests.cc10
-rw-r--r--src/lib/yang/tests/translator_control_socket_unittests.cc33
-rw-r--r--src/lib/yang/tests/translator_database_unittests.cc89
-rw-r--r--src/lib/yang/tests/translator_host_unittests.cc41
-rw-r--r--src/lib/yang/tests/translator_logger_unittests.cc14
-rw-r--r--src/lib/yang/tests/translator_option_data_unittests.cc16
-rw-r--r--src/lib/yang/tests/translator_option_def_unittests.cc18
-rw-r--r--src/lib/yang/tests/translator_pd_pool_unittests.cc65
-rw-r--r--src/lib/yang/tests/translator_pool_unittests.cc46
-rw-r--r--src/lib/yang/tests/translator_shared_network_unittests.cc30
-rw-r--r--src/lib/yang/tests/translator_subnet_unittests.cc47
-rw-r--r--src/lib/yang/tests/translator_unittests.cc561
-rw-r--r--src/lib/yang/tests/translator_utils_unittests.cc153
-rw-r--r--src/lib/yang/tests/yang_configs.h481
-rw-r--r--src/lib/yang/testutils/translator_test.cc383
-rw-r--r--src/lib/yang/testutils/translator_test.h44
-rw-r--r--src/lib/yang/translator.cc329
-rw-r--r--src/lib/yang/translator.h59
-rw-r--r--src/lib/yang/translator_class.cc57
-rw-r--r--src/lib/yang/translator_class.h6
-rw-r--r--src/lib/yang/translator_config.cc215
-rw-r--r--src/lib/yang/translator_config.h2
-rw-r--r--src/lib/yang/translator_control_socket.cc15
-rw-r--r--src/lib/yang/translator_control_socket.h4
-rw-r--r--src/lib/yang/translator_database.cc51
-rw-r--r--src/lib/yang/translator_database.h6
-rw-r--r--src/lib/yang/translator_host.cc31
-rw-r--r--src/lib/yang/translator_host.h6
-rw-r--r--src/lib/yang/translator_logger.cc43
-rw-r--r--src/lib/yang/translator_logger.h8
-rw-r--r--src/lib/yang/translator_option_data.cc25
-rw-r--r--src/lib/yang/translator_option_data.h6
-rw-r--r--src/lib/yang/translator_option_def.cc27
-rw-r--r--src/lib/yang/translator_option_def.h6
-rw-r--r--src/lib/yang/translator_pd_pool.cc56
-rw-r--r--src/lib/yang/translator_pd_pool.h6
-rw-r--r--src/lib/yang/translator_pool.cc56
-rw-r--r--src/lib/yang/translator_pool.h6
-rw-r--r--src/lib/yang/translator_shared_network.cc97
-rw-r--r--src/lib/yang/translator_shared_network.h6
-rw-r--r--src/lib/yang/translator_subnet.cc111
-rw-r--r--src/lib/yang/translator_subnet.h6
47 files changed, 1504 insertions, 1879 deletions
diff --git a/src/lib/yang/adaptor.h b/src/lib/yang/adaptor.h
index 8d1fdf3d95..c0c04aac2d 100644
--- a/src/lib/yang/adaptor.h
+++ b/src/lib/yang/adaptor.h
@@ -78,7 +78,7 @@ public:
/// @brief Modify a configuration in its JSON element format.
///
- /// Smart merging tool, e.g. completing a from yang configuration.
+ /// Smart merging tool, e.g. completing an ElementPtr received from YANG.
///
/// A modification is a path and actions:
/// - path item can be:
diff --git a/src/lib/yang/pretests/sysrepo_setup_tests.cc b/src/lib/yang/pretests/sysrepo_setup_tests.cc
index 6668cc4145..b815d24e9b 100644
--- a/src/lib/yang/pretests/sysrepo_setup_tests.cc
+++ b/src/lib/yang/pretests/sysrepo_setup_tests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,17 +9,20 @@
#define KEATEST_MODULE
#include <yang/yang_revisions.h>
+#include <sysrepo-cpp/Connection.hpp>
#include <sysrepo-cpp/Session.hpp>
+#include <iostream>
#include <unordered_map>
#include <sstream>
using namespace std;
+using namespace libyang;
using namespace sysrepo;
using namespace isc::yang;
-using libyang::S_Context;
-using libyang::S_Module;
+using libyang::Context;
+using libyang::Module;
const string REPOSITORY = SYSREPO_REPO;
@@ -34,6 +37,8 @@ string missingModuleText(const string& name, const string& revision) {
<< "The environment is not suitable for running unit tests." << endl
<< "Please install the module " << name << ":" << endl
<< "$ sysrepoctl -i ./src/share/yang/modules/" << name << "@" << revision << ".yang" << endl
+ << "Or reinstall all modules:" << endl
+ << "$ ./src/share/yang/modules/utils/reinstall.sh -u" << endl
<< endl;
return (tmp.str());
}
@@ -53,6 +58,8 @@ string badRevisionModuleText(const string& name, const string& expected,
<< "Please remove the module " << name << " and reinstall it: " << endl
<< "$ sysrepoctl -u " << name << endl
<< "$ sysrepoctl -i ./src/share/yang/modules/" << name << "@" << expected << ".yang" << endl
+ << "Or reinstall all modules:" << endl
+ << "$ ./src/share/yang/modules/utils/reinstall.sh -u" << endl
<< endl;
return (tmp.str());
}
@@ -66,45 +73,33 @@ string badRevisionModuleText(const string& name, const string& expected,
/// - Kea modules.
/// - daemon required
int main() {
- S_Connection conn;
+ optional<Session> sess;
try {
- conn = std::make_shared<Connection>();
- } catch (const sysrepo_exception& ex) {
- cerr << "ERROR: Can't initialize sysrepo: " << ex.what() << endl;
- cerr << "ERROR: Make sure you have the right permissions to the sysrepo repository." << endl;
- return (1);
- }
-
- S_Session sess;
- try {
- sess.reset(new Session(conn, SR_DS_CANDIDATE));
- } catch (const sysrepo_exception& ex) {
+ sess = Connection{}.sessionStart();
+ sess->switchDatastore(sysrepo::Datastore::Candidate);
+ } catch (Error const& ex) {
cerr << "ERROR: Can't establish a sysrepo session: "
<< ex.what() << endl;
return (2);
}
- vector<S_Module> modules;
+ vector<Module> modules;
try {
- S_Context context(sess->get_context());
- modules = context->get_module_iter();
- } catch (const sysrepo_exception& ex) {
+ Context const& context(sess->getContext());
+ modules = context.modules();
+ } catch (Error const& ex) {
cerr << "ERROR: Can't retrieve available modules: " << ex.what() << endl;
return (3);
}
std::unordered_map<std::string, std::string> installed_modules;
- for (S_Module const& module : modules) {
- if (!module->name()) {
- cerr << "ERROR: module name is mangled" << endl;
- return (4);
- }
- string const name(module->name());
- if (!module->rev() || !module->rev()->date()) {
- cerr << "ERROR: module revision is mangled" << endl;
+ for (Module const& module : modules) {
+ string const name(module.name());
+ if (!module.revision()) {
+ cerr << "ERROR: module " << name << " has no revision." << endl;
return (5);
}
- string const revision(module->rev()->date());
+ string const revision(*module.revision());
installed_modules.emplace(name, revision);
}
diff --git a/src/lib/yang/tests/adaptor_host_unittests.cc b/src/lib/yang/tests/adaptor_host_unittests.cc
index 95eb3a2588..d3431ee0c0 100644
--- a/src/lib/yang/tests/adaptor_host_unittests.cc
+++ b/src/lib/yang/tests/adaptor_host_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -32,7 +32,7 @@ TEST(AdaptorHostTest, notFlexId) {
EXPECT_TRUE(copied->equals(*json));
}
-// Verifies that quoteIdentifier does not touch a flex-id identifier
+// Verifies that quoteIdentifier does not touch a flex-id identifier
// without quotes.
TEST(AdaptorHostTest, noQuote) {
string config = "{\n"
diff --git a/src/lib/yang/tests/config_unittests.cc b/src/lib/yang/tests/config_unittests.cc
index e1c24c9ea4..6873d399c3 100644
--- a/src/lib/yang/tests/config_unittests.cc
+++ b/src/lib/yang/tests/config_unittests.cc
@@ -55,12 +55,12 @@ std::string generateDiff(std::string, std::string) {
/// @brief Test Fixture class for Yang <-> JSON configs.
class ConfigTest : public ::testing::Test {
public:
+ ConfigTest() : session_(Connection{}.sessionStart()) {
+ session_.switchDatastore(Datastore::Candidate);
+ }
virtual ~ConfigTest() = default;
void SetUp() override {
- SysrepoSetup::cleanSharedMemory();
- connection_ = std::make_shared<Connection>();
- session_.reset(new Session(connection_, SR_DS_CANDIDATE));
translator_.reset(new TranslatorBasic(session_, model_));
cleanModelData();
}
@@ -68,8 +68,6 @@ public:
void TearDown() override {
cleanModelData();
translator_.reset();
- session_.reset();
- connection_.reset();
SysrepoSetup::cleanSharedMemory();
}
@@ -176,23 +174,11 @@ public:
return (verify(expected));
}
- /// @brief Validate.
- ///
- /// @note A tree must be loaded first.
- ///
- bool validate() {
- YangRepr repr(model_);
- return (repr.validate(session_, cerr));
- }
-
/// @brief The model.
string model_;
- /// @brief The sysrepo connection.
- S_Connection connection_;
-
/// @brief The sysrepo session.
- S_Session session_;
+ Session session_;
std::unique_ptr<TranslatorBasic> translator_;
};
@@ -264,8 +250,6 @@ TEST_F(ConfigTestIetfV6, subnetTwoPoolsIetf6) {
ASSERT_NO_THROW_LOG(load(subnetTwoPoolsJson6));
EXPECT_TRUE(verify(subnetTwoPoolsTreeIetf6));
-
- EXPECT_FALSE(validate());
}
// Check subnet with a pool and option data lists with
@@ -278,8 +262,6 @@ TEST_F(ConfigTestKeaV4, subnetOptionsKeaDhcp4) {
ASSERT_NO_THROW_LOG(load(subnetOptionsJson4));
EXPECT_TRUE(verify(subnetOptionsTreeKeaDhcp4));
-
- EXPECT_TRUE(validate());
}
// Check subnet with a pool and option data lists with
@@ -292,8 +274,6 @@ TEST_F(ConfigTestKeaV6, subnetOptionsKeaDhcp6) {
ASSERT_NO_THROW_LOG(load(subnetOptionsJson6));
EXPECT_TRUE(verify(subnetOptionsTreeKeaDhcp6));
-
- EXPECT_TRUE(validate());
}
// Check with timers.
@@ -311,14 +291,6 @@ TEST_F(ConfigTestIetfV6, subnetTimersIetf6) {
TEST_F(ConfigTestIetfV6, validateIetf6) {
ASSERT_NO_THROW_LOG(load(validTreeIetf6));
EXPECT_TRUE(verify(validTreeIetf6));
-
- // If this validation fails, make sure you have the model *and its
- // dependencies* are installed. Note when you install ietf-dhcpv6-server
- // module, its dependencies are semi-installed, which is not sufficient.
- // This can be detected in output of sysrepoctl -l.
- // Note the ietf-interfaces module. The conformance status must be
- // "installed". "implemented" (installed as dependency) is not enough.
- EXPECT_TRUE(validate());
}
// Check Kea4 example files.
@@ -358,7 +330,6 @@ TEST_F(ConfigTestKeaV4, examples4) {
ASSERT_NO_THROW_LOG(json = loadFile(path));
json = isc::test::moveComments(json);
EXPECT_TRUE(verify(json));
- EXPECT_TRUE(validate());
}
}
@@ -401,7 +372,6 @@ TEST_F(ConfigTestKeaV6, examples6) {
ASSERT_NO_THROW_LOG(json = loadFile(path));
json = isc::test::moveComments(json);
EXPECT_TRUE(verify(json));
- EXPECT_TRUE(validate());
}
}
diff --git a/src/lib/yang/tests/sysrepo_setup.h b/src/lib/yang/tests/sysrepo_setup.h
index 27cf213d06..7f7a59e363 100644
--- a/src/lib/yang/tests/sysrepo_setup.h
+++ b/src/lib/yang/tests/sysrepo_setup.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,6 +13,8 @@
#include <yang/translator.h>
#include <yang/yang_models.h>
+#include <sysrepo-cpp/Connection.hpp>
+
#include <gtest/gtest.h>
namespace isc {
@@ -59,17 +61,15 @@ public:
void SetUp() override {
SysrepoSetup::cleanSharedMemory();
- conn_.reset(new sysrepo::Connection());
- sess_.reset(new sysrepo::Session(conn_, SR_DS_CANDIDATE));
- t_obj_.reset(new translator_t(sess_, model_));
+ sess_ = sysrepo::Connection{}.sessionStart();
+ sess_->switchDatastore(sysrepo::Datastore::Candidate);
+ t_obj_.reset(new translator_t(*sess_, model_));
cleanModelData();
}
void TearDown() override {
cleanModelData();
t_obj_.reset();
- sess_.reset();
- conn_.reset();
SysrepoSetup::cleanSharedMemory();
}
@@ -81,11 +81,8 @@ public:
t_obj_->delItem("/" + model_ + ":" + toplevel_node);
}
- /// @brief Sysrepo connection.
- sysrepo::S_Connection conn_;
-
/// @brief Sysrepo session.
- sysrepo::S_Session sess_;
+ std::optional<sysrepo::Session> sess_;
/// @brief Shared pointer to the transaction object.
boost::shared_ptr<translator_t> t_obj_;
diff --git a/src/lib/yang/tests/translator_class_unittests.cc b/src/lib/yang/tests/translator_class_unittests.cc
index 3dcb518541..6c64244e2c 100644
--- a/src/lib/yang/tests/translator_class_unittests.cc
+++ b/src/lib/yang/tests/translator_class_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -62,8 +62,9 @@ TEST_F(TranslatorClassesTestv6, get) {
const string& xpath = "/kea-dhcp6-server:config";
const string& xclass = xpath + "/client-class[name='foo']";
const string& xtest = xclass + "/test";
- S_Val v_test(new Val("not member('ALL')", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(xtest.c_str(), v_test));
+ string const v_test("not member('ALL')");
+ EXPECT_NO_THROW(sess_->setItem(xtest, v_test));
+ sess_->applyChanges();
// Get the client class.
ConstElementPtr cclass;
@@ -117,9 +118,6 @@ TEST_F(TranslatorClassesTestv6, set) {
ASSERT_EQ(Element::list, got->getType());
ASSERT_EQ(1, got->size());
EXPECT_TRUE(cclass->equals(*got->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
} // namespace
diff --git a/src/lib/yang/tests/translator_control_socket_unittests.cc b/src/lib/yang/tests/translator_control_socket_unittests.cc
index 3d9d4feb1b..928a7808b2 100644
--- a/src/lib/yang/tests/translator_control_socket_unittests.cc
+++ b/src/lib/yang/tests/translator_control_socket_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -17,6 +17,7 @@ using namespace isc;
using namespace isc::data;
using namespace isc::yang;
using namespace isc::yang::test;
+using namespace libyang;
using namespace sysrepo;
namespace {
@@ -77,12 +78,13 @@ TEST_F(TranslatorControlSocketTestv6, get) {
const string& xname = xpath + "/socket-name";
const string& xtype = xpath + "/socket-type";
const string& xcontext = xpath + "/user-context";
- S_Val s_name(new Val("/tmp/kea.sock"));
- EXPECT_NO_THROW(sess_->set_item(xname.c_str(), s_name));
- S_Val s_type(new Val("unix", SR_ENUM_T));
- EXPECT_NO_THROW(sess_->set_item(xtype.c_str(), s_type));
- S_Val s_context(new Val("{ \"foo\": 1 }"));
- EXPECT_NO_THROW(sess_->set_item(xcontext.c_str(), s_context));
+ string const s_name("/tmp/kea.sock");
+ EXPECT_NO_THROW(sess_->setItem(xname, s_name));
+ string const s_type("unix");
+ EXPECT_NO_THROW(sess_->setItem(xtype, s_type));
+ string const s_context("{ \"foo\": 1 }");
+ EXPECT_NO_THROW(sess_->setItem(xcontext, s_context));
+ sess_->applyChanges();
// Get it.
ConstElementPtr sock;
@@ -137,9 +139,6 @@ TEST_F(TranslatorControlSocketTestCtrlAgent, set) {
ConstElementPtr context = got->get("user-context");
ASSERT_TRUE(context);
EXPECT_EQ("{ \"comment\": \"a comment\" }", context->str());
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
// This test verifies that an empty control socket can be properly
@@ -150,13 +149,13 @@ TEST_F(TranslatorControlSocketTestv4, setEmpty) {
const string& xname = xpath + "/socket-name";
const string& xtype = xpath + "/socket-type";
const string& xcontext = xpath + "/user-context";
- S_Val s_name(new Val("/tmp/kea.sock"));
- EXPECT_NO_THROW(sess_->set_item(xname.c_str(), s_name));
- S_Val s_type(new Val("unix", SR_ENUM_T));
- EXPECT_NO_THROW(sess_->set_item(xtype.c_str(), s_type));
- S_Val s_context(new Val("{ \"foo\": 1 }"));
- EXPECT_NO_THROW(sess_->set_item(xcontext.c_str(), s_context));
- sess_->apply_changes();
+ string const s_name("/tmp/kea.sock");
+ EXPECT_NO_THROW(sess_->setItem(xname, s_name));
+ string const s_type("unix");
+ EXPECT_NO_THROW(sess_->setItem(xtype, s_type));
+ string const s_context("{ \"foo\": 1 }");
+ EXPECT_NO_THROW(sess_->setItem(xcontext, s_context));
+ sess_->applyChanges();
// Get it back.
ConstElementPtr sock;
diff --git a/src/lib/yang/tests/translator_database_unittests.cc b/src/lib/yang/tests/translator_database_unittests.cc
index 6c4eb29b93..79e2cb8513 100644
--- a/src/lib/yang/tests/translator_database_unittests.cc
+++ b/src/lib/yang/tests/translator_database_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -62,11 +62,12 @@ TEST_F(TranslatorDatabaseTestv4, get) {
const string& xpath = "/kea-dhcp4-server:config/lease-database";
const string& xtype = xpath + "/database-type";
const string& xinterval = xpath + "/lfc-interval";
- S_Val s_type(new Val("memfile"));
- EXPECT_NO_THROW(sess_->set_item(xtype.c_str(), s_type));
+ string const s_type("memfile");
+ EXPECT_NO_THROW(sess_->setItem(xtype, s_type));
uint32_t li = 3600;
- S_Val s_interval(new Val(li));
- EXPECT_NO_THROW(sess_->set_item(xinterval.c_str(), s_interval));
+ string const s_interval(to_string(li));
+ EXPECT_NO_THROW(sess_->setItem(xinterval, s_interval));
+ sess_->applyChanges();
// Get empty.
ConstElementPtr database;
@@ -116,12 +117,12 @@ TEST_F(TranslatorDatabaseTestv4, setEmpty) {
const string& xpath = "/kea-dhcp4-server:config/lease-database";
const string& xtype = xpath + "/database-type";
const string& xinterval = xpath + "/lfc-interval";
- S_Val s_type(new Val("memfile"));
- EXPECT_NO_THROW(sess_->set_item(xtype.c_str(), s_type));
+ string const s_type("memfile");
+ EXPECT_NO_THROW(sess_->setItem(xtype, s_type));
uint32_t li = 3600;
- S_Val s_interval(new Val(li));
- EXPECT_NO_THROW(sess_->set_item(xinterval.c_str(), s_interval));
- sess_->apply_changes();
+ string const s_interval(to_string(li));
+ EXPECT_NO_THROW(sess_->setItem(xinterval, s_interval));
+ sess_->applyChanges();
// Reset to empty.
ASSERT_NO_THROW_LOG(t_obj_->setDatabase(xpath, ConstElementPtr()));
@@ -177,17 +178,18 @@ TEST_F(TranslatorDatabasesTestv4, get) {
const string& xpassword = xdatabase + "/password";
const string& xhost = xdatabase + "/host";
const string& xport = xdatabase + "/port";
- S_Val s_name(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xname.c_str(), s_name));
- S_Val s_user(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xuser.c_str(), s_user));
- S_Val s_password(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xpassword.c_str(), s_password));
- S_Val s_host(new Val("localhost"));
- EXPECT_NO_THROW(sess_->set_item(xhost.c_str(), s_host));
+ string const s_name("kea");
+ EXPECT_NO_THROW(sess_->setItem(xname, s_name));
+ string const s_user("kea");
+ EXPECT_NO_THROW(sess_->setItem(xuser, s_user));
+ string const s_password("kea");
+ EXPECT_NO_THROW(sess_->setItem(xpassword, s_password));
+ string const s_host("localhost");
+ EXPECT_NO_THROW(sess_->setItem(xhost, s_host));
uint16_t mport = 3306;
- S_Val s_port(new Val(mport));
- EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port));
+ string const s_port(to_string(mport));
+ EXPECT_NO_THROW(sess_->setItem(xport, s_port));
+ sess_->applyChanges();
// Get empty.
ConstElementPtr databases;
@@ -253,9 +255,6 @@ TEST_F(TranslatorDatabasesTestv6, set) {
ASSERT_TRUE(interval);
ASSERT_EQ(Element::integer, interval->getType());
EXPECT_EQ(3600, interval->intValue());
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
// This test verifies that an emptied database list can be properly
@@ -269,18 +268,18 @@ TEST_F(TranslatorDatabasesTestv4, setEmpty) {
const string& xpassword = xdatabase + "/password";
const string& xhost = xdatabase + "/host";
const string& xport = xdatabase + "/port";
- S_Val s_name(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xname.c_str(), s_name));
- S_Val s_user(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xuser.c_str(), s_user));
- S_Val s_password(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xpassword.c_str(), s_password));
- S_Val s_host(new Val("localhost"));
- EXPECT_NO_THROW(sess_->set_item(xhost.c_str(), s_host));
+ string const s_name("kea");
+ EXPECT_NO_THROW(sess_->setItem(xname, s_name));
+ string const s_user("kea");
+ EXPECT_NO_THROW(sess_->setItem(xuser, s_user));
+ string const s_password("kea");
+ EXPECT_NO_THROW(sess_->setItem(xpassword, s_password));
+ string const s_host("localhost");
+ EXPECT_NO_THROW(sess_->setItem(xhost, s_host));
uint16_t mport = 3306;
- S_Val s_port(new Val(mport));
- EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port));
- sess_->apply_changes();
+ string const s_port(to_string(mport));
+ EXPECT_NO_THROW(sess_->setItem(xport, s_port));
+ sess_->applyChanges();
// Reset to empty.
EXPECT_NO_THROW(t_obj_->setDatabase(xdatabase, ConstElementPtr()));
@@ -302,18 +301,18 @@ TEST_F(TranslatorDatabasesTestv4, setEmpties) {
const string& xpassword = xdatabase + "/password";
const string& xhost = xdatabase + "/host";
const string& xport = xdatabase + "/port";
- S_Val s_name(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xname.c_str(), s_name));
- S_Val s_user(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xuser.c_str(), s_user));
- S_Val s_password(new Val("kea"));
- EXPECT_NO_THROW(sess_->set_item(xpassword.c_str(), s_password));
- S_Val s_host(new Val("localhost"));
- EXPECT_NO_THROW(sess_->set_item(xhost.c_str(), s_host));
+ string const s_name("kea");
+ EXPECT_NO_THROW(sess_->setItem(xname, s_name));
+ string const s_user("kea");
+ EXPECT_NO_THROW(sess_->setItem(xuser, s_user));
+ string const s_password("kea");
+ EXPECT_NO_THROW(sess_->setItem(xpassword, s_password));
+ string const s_host("localhost");
+ EXPECT_NO_THROW(sess_->setItem(xhost, s_host));
uint16_t mport = 3306;
- S_Val s_port(new Val(mport));
- EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port));
- sess_->apply_changes();
+ string const s_port(to_string(mport));
+ EXPECT_NO_THROW(sess_->setItem(xport, s_port));
+ sess_->applyChanges();
// Reset to empty.
EXPECT_NO_THROW(t_obj_->setDatabases(xdatabase, ConstElementPtr()));
diff --git a/src/lib/yang/tests/translator_host_unittests.cc b/src/lib/yang/tests/translator_host_unittests.cc
index 26fd2026dd..c108c1d4c0 100644
--- a/src/lib/yang/tests/translator_host_unittests.cc
+++ b/src/lib/yang/tests/translator_host_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -18,6 +18,7 @@ using namespace isc;
using namespace isc::data;
using namespace isc::yang;
using namespace isc::yang::test;
+using namespace libyang;
using namespace sysrepo;
namespace {
@@ -63,17 +64,19 @@ TEST_F(TranslatorHostsTestv6, get) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Create the host reservation for 2001:db8::1.
ostringstream shost;
shost << xpath + "/host[identifier-type='hw-address']"
<< "[identifier='00:01:02:03:04:05']";
const string& xaddr = shost.str() + "/ip-addresses";
- S_Val s_addr(new Val("2001:db8::1"));
- EXPECT_NO_THROW(sess_->set_item(xaddr.c_str(), s_addr));
+ string const s_addr("2001:db8::1");
+ EXPECT_NO_THROW(sess_->setItem(xaddr, s_addr));
+ sess_->applyChanges();
// Get the host.
ConstElementPtr host;
@@ -102,9 +105,10 @@ TEST_F(TranslatorHostsTestv6, setEmpty) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Set empty list.
ConstElementPtr hosts = Element::createList();
@@ -122,9 +126,10 @@ TEST_F(TranslatorHostsTestv4, set) {
// Create the subnet 10.0.0.0/14 #111.
const string& xpath =
"/kea-dhcp4-server:config/subnet4[id='111']";
- S_Val v_subnet(new Val("10.0.0.0/24", SR_STRING_T));
+ string const v_subnet("10.0.0.0/24");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Set one host.
ElementPtr hosts = Element::createList();
@@ -142,9 +147,6 @@ TEST_F(TranslatorHostsTestv4, set) {
ASSERT_EQ(Element::list, hosts->getType());
ASSERT_EQ(1, hosts->size());
EXPECT_TRUE(host->equals(*hosts->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
// This test verifies that several host reservations can be properly
@@ -153,25 +155,28 @@ TEST_F(TranslatorHostsTestv6, getMany) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Create the host reservation for 2001:db8::1.
ostringstream shost;
shost << xpath + "/host[identifier-type='hw-address']"
<< "[identifier='00:01:02:03:04:05']";
const string& xaddr = shost.str() + "/ip-addresses";
- S_Val s_addr(new Val("2001:db8::1"));
- EXPECT_NO_THROW(sess_->set_item(xaddr.c_str(), s_addr));
+ string const s_addr("2001:db8::1");
+ EXPECT_NO_THROW(sess_->setItem(xaddr, s_addr));
+ sess_->applyChanges();
// Create another reservation for 2001:db8::2
ostringstream shost2;
shost2 << xpath + "/host[identifier-type='hw-address']"
<< "[identifier='00:01:0a:0b:0c:0d']";
const string xaddr2 = shost2.str() + "/ip-addresses";
- S_Val s_addr2(new Val("2001:db8::2"));
- EXPECT_NO_THROW(sess_->set_item(xaddr2.c_str(), s_addr2));
+ string const s_addr2("2001:db8::2");
+ EXPECT_NO_THROW(sess_->setItem(xaddr2, s_addr2));
+ sess_->applyChanges();
// Get the host.
ConstElementPtr hosts;
diff --git a/src/lib/yang/tests/translator_logger_unittests.cc b/src/lib/yang/tests/translator_logger_unittests.cc
index 2dbfbcc1d6..e5aeb45488 100644
--- a/src/lib/yang/tests/translator_logger_unittests.cc
+++ b/src/lib/yang/tests/translator_logger_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -63,11 +63,12 @@ TEST_F(TranslatorLoggersTestv6, get) {
const string& xseverity = xlogger + "/severity";
const string& xoption = xlogger + "/output-option[output='/bar']";
const string& xmaxver = xoption + "/maxver";
- S_Val s_severity(new Val("WARN", SR_ENUM_T));
- EXPECT_NO_THROW(sess_->set_item(xseverity.c_str(), s_severity));
+ string const s_severity("WARN");
+ EXPECT_NO_THROW(sess_->setItem(xseverity, s_severity));
uint32_t max_ver = 10;
- S_Val s_maxver(new Val(max_ver));
- EXPECT_NO_THROW(sess_->set_item(xmaxver.c_str(), s_maxver));
+ string const s_maxver(to_string(max_ver));
+ EXPECT_NO_THROW(sess_->setItem(xmaxver, s_maxver));
+ sess_->applyChanges();
// Get empty.
ConstElementPtr loggers;
@@ -149,9 +150,6 @@ TEST_F(TranslatorLoggersTestv4, set) {
ASSERT_TRUE(maxver);
ASSERT_EQ(Element::integer, maxver->getType());
EXPECT_EQ(10, maxver->intValue());
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
/// @todo: Implement a test that will cover multiple loggers.
diff --git a/src/lib/yang/tests/translator_option_data_unittests.cc b/src/lib/yang/tests/translator_option_data_unittests.cc
index b02284c7f9..c871362fe3 100644
--- a/src/lib/yang/tests/translator_option_data_unittests.cc
+++ b/src/lib/yang/tests/translator_option_data_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -65,11 +65,12 @@ TEST_F(TranslatorOptionDataListTestv6, get) {
const string& xformat = xoption + "/csv-format";
const string& xdata = xoption + "/data";
const string& xsend = xoption + "/always-send";
- S_Val s_false(new Val(false));
- ASSERT_NO_THROW_LOG(sess_->set_item(xformat.c_str(), s_false));
- S_Val s_data(new Val("12121212"));
- ASSERT_NO_THROW_LOG(sess_->set_item(xdata.c_str(), s_data));
- ASSERT_NO_THROW_LOG(sess_->set_item(xsend.c_str(), s_false));
+ string const s_false("false");
+ ASSERT_NO_THROW_LOG(sess_->setItem(xformat, s_false));
+ string const s_data("12121212");
+ ASSERT_NO_THROW_LOG(sess_->setItem(xdata, s_data));
+ ASSERT_NO_THROW_LOG(sess_->setItem(xsend, s_false));
+ sess_->applyChanges();
// Get the option data.
ConstElementPtr option;
@@ -128,9 +129,6 @@ TEST_F(TranslatorOptionDataListTestv6, set) {
ASSERT_TRUE(got);
ASSERT_EQ(1, got->size());
EXPECT_TRUE(option->equals(*got->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
} // namespace
diff --git a/src/lib/yang/tests/translator_option_def_unittests.cc b/src/lib/yang/tests/translator_option_def_unittests.cc
index d6c3cdf9d2..22d4d3f66d 100644
--- a/src/lib/yang/tests/translator_option_def_unittests.cc
+++ b/src/lib/yang/tests/translator_option_def_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -73,12 +73,13 @@ TEST_F(TranslatorOptionDefListTestKeaV6, get) {
const string& xname = xdef + "/name";
const string& xtype = xdef + "/type";
const string& xarray = xdef + "/array";
- S_Val s_name(new Val("foo"));
- ASSERT_NO_THROW_LOG(sess_->set_item(xname.c_str(), s_name));
- S_Val s_type(new Val("string"));
- ASSERT_NO_THROW_LOG(sess_->set_item(xtype.c_str(), s_type));
- S_Val s_array(new Val(false));
- ASSERT_NO_THROW_LOG(sess_->set_item(xarray.c_str(), s_array));
+ string const s_name("foo");
+ ASSERT_NO_THROW_LOG(sess_->setItem(xname, s_name));
+ string const s_type("string");
+ ASSERT_NO_THROW_LOG(sess_->setItem(xtype, s_type));
+ string const s_array("false");
+ ASSERT_NO_THROW_LOG(sess_->setItem(xarray, s_array));
+ sess_->applyChanges();
// Get the option def.
ConstElementPtr def;
@@ -136,9 +137,6 @@ TEST_F(TranslatorOptionDefListTestKeaV6, set) {
ASSERT_TRUE(got);
ASSERT_EQ(1, got->size());
EXPECT_TRUE(def->equals(*got->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
}; // end of anonymous namespace
diff --git a/src/lib/yang/tests/translator_pd_pool_unittests.cc b/src/lib/yang/tests/translator_pd_pool_unittests.cc
index 8d5b3fe020..3686cf684e 100644
--- a/src/lib/yang/tests/translator_pd_pool_unittests.cc
+++ b/src/lib/yang/tests/translator_pd_pool_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -74,19 +74,21 @@ TEST_F(TranslatorPdPoolsTestIetfV6, getIetf) {
const string& subnet =
"/ietf-dhcpv6-server:server/server-config/network-ranges"
"/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet_subnet = subnet + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet_subnet, v_subnet));
+ sess_->applyChanges();
// Create the pd-pool 2001:db8:0:1000::/64 #222.
const string& xpath = subnet + "/pd-pools/pd-pool[pool-id='222']";
const string& prefix = xpath + "/prefix";
- S_Val s_prefix(new Val("2001:db8:0:1000::/56"));
- EXPECT_NO_THROW(sess_->set_item(prefix.c_str(), s_prefix));
+ string const s_prefix("2001:db8:0:1000::/56");
+ EXPECT_NO_THROW(sess_->setItem(prefix, s_prefix));
const string& length = xpath + "/prefix-length";
uint8_t len = 56;
- S_Val s_length(new Val(len));
- EXPECT_NO_THROW(sess_->set_item(length.c_str(), s_length));
+ string const s_length(to_string(len));
+ EXPECT_NO_THROW(sess_->setItem(length, s_length));
+ sess_->applyChanges();
// Get the pool.
ConstElementPtr pool;
@@ -112,9 +114,10 @@ TEST_F(TranslatorPdPoolsTestKeaV6, getKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Create the pd-pool 2001:db8:0:1000::/64.
const string& prefix = "2001:db8:0:1000::/56";
@@ -122,8 +125,9 @@ TEST_F(TranslatorPdPoolsTestKeaV6, getKea) {
spool << xpath + "/pd-pool[prefix='" << prefix << "']";
const string& x_delegated = spool.str() + "/delegated-len";
uint8_t dl = 64;
- S_Val s_delegated(new Val(dl));
- EXPECT_NO_THROW(sess_->set_item(x_delegated.c_str(), s_delegated));
+ string const s_delegated(to_string(dl));
+ EXPECT_NO_THROW(sess_->setItem(x_delegated, s_delegated));
+ sess_->applyChanges();
// Get the pool.
ConstElementPtr pool;
@@ -151,9 +155,10 @@ TEST_F(TranslatorPdPoolsTestIetfV6, setEmptyIetf) {
const string& subnet =
"/ietf-dhcpv6-server:server/server-config/network-ranges"
"/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet_subnet = subnet + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet_subnet, v_subnet));
+ sess_->applyChanges();
// Set empty list.
const string& xpath = subnet + "/pd-pools";
@@ -172,9 +177,10 @@ TEST_F(TranslatorPdPoolsTestKeaV6, setEmptyKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Set empty list.
ConstElementPtr pools = Element::createList();
@@ -193,9 +199,10 @@ TEST_F(TranslatorPdPoolsTestIetfV6, setIetf) {
const string& subnet =
"/ietf-dhcpv6-server:server/server-config/network-ranges"
"/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet_subnet = subnet + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet_subnet, v_subnet));
+ sess_->applyChanges();
// Set one pool.
const string& xpath = subnet + "/pd-pools";
@@ -221,9 +228,10 @@ TEST_F(TranslatorPdPoolsTestKeaV6, setKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Set one pool.
ElementPtr pools = Element::createList();
@@ -241,9 +249,6 @@ TEST_F(TranslatorPdPoolsTestKeaV6, setKea) {
ASSERT_EQ(Element::list, pools->getType());
ASSERT_EQ(1, pools->size());
EXPECT_TRUE(pool->equals(*pools->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
// This test verifies that a non-empty list of pd pools can be properly
@@ -252,9 +257,10 @@ TEST_F(TranslatorPdPoolsTestKeaV6, getListKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Create the first pd-pool 2001:db8:0:1000::/56.
const string& prefix = "2001:db8:0:1000::/56";
@@ -262,8 +268,9 @@ TEST_F(TranslatorPdPoolsTestKeaV6, getListKea) {
spool << xpath + "/pd-pool[prefix='" << prefix << "']";
const string& x_delegated = spool.str() + "/delegated-len";
uint8_t dl = 64;
- S_Val s_delegated(new Val(dl));
- EXPECT_NO_THROW(sess_->set_item(x_delegated.c_str(), s_delegated));
+ string const s_delegated(to_string(dl));
+ EXPECT_NO_THROW(sess_->setItem(x_delegated, s_delegated));
+ sess_->applyChanges();
// Create the second pd-pool 2001:db8:0:2000::/56
const string& prefix2 = "2001:db8:0:2000::/56";
@@ -271,9 +278,9 @@ TEST_F(TranslatorPdPoolsTestKeaV6, getListKea) {
spool2 << xpath + "/pd-pool[prefix='" << prefix2 << "']";
const string& x_delegated2 = spool2.str() + "/delegated-len";
uint8_t dl2 = 60;
- S_Val s_delegated2(new Val(dl2));
- EXPECT_NO_THROW(sess_->set_item(x_delegated2.c_str(), s_delegated2));
-
+ string const s_delegated2(to_string(dl2));
+ EXPECT_NO_THROW(sess_->setItem(x_delegated2, s_delegated2));
+ sess_->applyChanges();
// Get the pools list.
ConstElementPtr pools;
diff --git a/src/lib/yang/tests/translator_pool_unittests.cc b/src/lib/yang/tests/translator_pool_unittests.cc
index d8386b59fd..a6f1866fc6 100644
--- a/src/lib/yang/tests/translator_pool_unittests.cc
+++ b/src/lib/yang/tests/translator_pool_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -35,7 +35,6 @@ public:
model_ = KEA_DHCP4_SERVER;
}
};
-
class TranslatorPoolsTestKeaV6 :
public GenericTranslatorTest<pool_list, TranslatorPools> {
public:
@@ -82,15 +81,17 @@ TEST_F(TranslatorPoolsTestIetfV6, getIetf) {
// Create the subnet 2001:db8::/48 #111.
const string& subnet = "/ietf-dhcpv6-server:server/server-config/"
"network-ranges/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet_subnet = subnet + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet_subnet, v_subnet));
+ sess_->applyChanges();
// Create the pool 2001:db8::1:0/112 #222.
const string& xpath = subnet + "/address-pools";
const string& prefix = xpath + "/address-pool[pool-id='222']/pool-prefix";
- S_Val s_val(new Val("2001:db8::1:0/112"));
- EXPECT_NO_THROW(sess_->set_item(prefix.c_str(), s_val));
+ string const s_val("2001:db8::1:0/112");
+ EXPECT_NO_THROW(sess_->setItem(prefix, s_val));
+ sess_->applyChanges();
// Get the pool.
ConstElementPtr pool;
@@ -113,9 +114,10 @@ TEST_F(TranslatorPoolsTestKeaV6, getKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Create the pool 2001:db8::1:0/112.
const string& prefix = "2001:db8::1:0/112";
@@ -129,8 +131,9 @@ TEST_F(TranslatorPoolsTestKeaV6, getKea) {
spool << xpath + "/pool[start-address='" << start_addr
<< "'][end-address='" << end_addr << "']";
const string& x_prefix = spool.str() + "/prefix";
- S_Val s_prefix(new Val("2001:db8::1:0/112", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(x_prefix.c_str(), s_prefix));
+ string const s_prefix("2001:db8::1:0/112");
+ EXPECT_NO_THROW(sess_->setItem(x_prefix, s_prefix));
+ sess_->applyChanges();
// Get the pool.
ConstElementPtr pool;
@@ -155,9 +158,10 @@ TEST_F(TranslatorPoolsTestIetfV6, setEmptyIetf) {
// Create the subnet 2001:db8::/48 #111.
const string& subnet = "/ietf-dhcpv6-server:server/server-config/"
"network-ranges/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet_subnet = subnet + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet_subnet, v_subnet));
+ sess_->applyChanges();
// Set empty list.
const string& xpath = subnet + "/address-pools";
@@ -176,9 +180,10 @@ TEST_F(TranslatorPoolsTestKeaV6, setEmptyKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Set empty list.
ConstElementPtr pools = Element::createList();
@@ -196,9 +201,10 @@ TEST_F(TranslatorPoolsTestIetfV6, setIetf) {
// Create the subnet 2001:db8::/48 #111.
const string& subnet = "/ietf-dhcpv6-server:server/server-config/"
"network-ranges/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet_subnet = subnet + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet_subnet, v_subnet));
+ sess_->applyChanges();
// Set one pool.
const string& xpath = subnet + "/address-pools";
@@ -223,9 +229,10 @@ TEST_F(TranslatorPoolsTestKeaV6, setKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath =
"/kea-dhcp6-server:config/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& subnet = xpath + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(subnet, v_subnet));
+ sess_->applyChanges();
// Set one pool.
ElementPtr pools = Element::createList();
@@ -242,9 +249,6 @@ TEST_F(TranslatorPoolsTestKeaV6, setKea) {
ASSERT_EQ(Element::list, pools->getType());
ASSERT_EQ(1, pools->size());
EXPECT_TRUE(pool->equals(*pools->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
} // namespace
diff --git a/src/lib/yang/tests/translator_shared_network_unittests.cc b/src/lib/yang/tests/translator_shared_network_unittests.cc
index 253470049e..ea04f287bd 100644
--- a/src/lib/yang/tests/translator_shared_network_unittests.cc
+++ b/src/lib/yang/tests/translator_shared_network_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -61,8 +61,9 @@ TEST_F(TranslatorSharedNetworksTestKeaV6, get) {
const string& xpath = "/kea-dhcp6-server:config";
const string& xnetwork = xpath + "/shared-network[name='foo']";
const string& xsubnet = xnetwork + "/subnet6[id='111']/subnet";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+ string const v_subnet("2001:db8::/48");
+ EXPECT_NO_THROW(sess_->setItem(xsubnet, v_subnet));
+ sess_->applyChanges();
// Get the shared network.
ConstElementPtr network;
@@ -125,9 +126,6 @@ TEST_F(TranslatorSharedNetworksTestKeaV6, set) {
ASSERT_EQ(Element::list, networks->getType());
ASSERT_EQ(1, networks->size());
EXPECT_TRUE(share->equals(*networks->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
// This test verifies that several shared networks can be properly
@@ -164,23 +162,27 @@ TEST_F(TranslatorSharedNetworksTestKeaV6, getList) {
// Create the subnet1: 2001:db8:1::/48 #1 in shared network foo.
const string& xsubnet1 = xnetwork1 + "/subnet6[id='1']/subnet";
- S_Val v_subnet1(new Val("2001:db8:1::/48", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(xsubnet1.c_str(), v_subnet1));
+ string const v_subnet1("2001:db8:1::/48");
+ EXPECT_NO_THROW(sess_->setItem(xsubnet1, v_subnet1));
+ sess_->applyChanges();
// Create the subnet2: 2001:db8:2::/48 #2 in shared network foo.
const string& xsubnet2 = xnetwork1 + "/subnet6[id='2']/subnet";
- S_Val v_subnet2(new Val("2001:db8:2::/48", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(xsubnet2.c_str(), v_subnet2));
+ string const v_subnet2("2001:db8:2::/48");
+ EXPECT_NO_THROW(sess_->setItem(xsubnet2, v_subnet2));
+ sess_->applyChanges();
// Create the subnet1: 2001:db8:101::/48 #101 in shared network foo.
const string& xsubnet3 = xnetwork2 + "/subnet6[id='101']/subnet";
- S_Val v_subnet(new Val("2001:db8:101::/48", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(xsubnet3.c_str(), v_subnet));
+ string const v_subnet("2001:db8:101::/48");
+ EXPECT_NO_THROW(sess_->setItem(xsubnet3, v_subnet));
+ sess_->applyChanges();
// Create the subnet2: 2001:db8:2::/48 #2 in shared network foo.
const string& xsubnet4 = xnetwork2 + "/subnet6[id='102']/subnet";
- S_Val v_subnet4(new Val("2001:db8:102::/48", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(xsubnet4.c_str(), v_subnet4));
+ string const v_subnet4("2001:db8:102::/48");
+ EXPECT_NO_THROW(sess_->setItem(xsubnet4, v_subnet4));
+ sess_->applyChanges();
// Ok, now test the getters. Let's start with the easier ones that
// return a single network.
diff --git a/src/lib/yang/tests/translator_subnet_unittests.cc b/src/lib/yang/tests/translator_subnet_unittests.cc
index cc3459686f..862e717093 100644
--- a/src/lib/yang/tests/translator_subnet_unittests.cc
+++ b/src/lib/yang/tests/translator_subnet_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -81,9 +81,10 @@ TEST_F(TranslatorSubnetsTestIetfV6, getIetf) {
const string& xpath =
"/ietf-dhcpv6-server:server/server-config/network-ranges";
const string& xsub = xpath + "/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& xsubnet = xsub + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(xsubnet, v_subnet));
+ sess_->applyChanges();
// Get the subnet.
ConstElementPtr subnet;
@@ -109,9 +110,10 @@ TEST_F(TranslatorSubnetsTestKeaV6, getKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath = "/kea-dhcp6-server:config";
const string& xsub = xpath + "/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& xsubnet = xsub + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(xsubnet, v_subnet));
+ sess_->applyChanges();
// Get the subnet.
ConstElementPtr subnet;
@@ -138,20 +140,23 @@ TEST_F(TranslatorSubnetsTestIetfV6, getPoolsIetf) {
const string& xpath =
"/ietf-dhcpv6-server:server/server-config/network-ranges";
const string& xsub = xpath + "/network-range[network-range-id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& xsubnet = xsub + "/network-prefix";
- EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(xsubnet, v_subnet));
+ sess_->applyChanges();
// Create the pool 2001:db8::1:0/112 #1.
const string& xpool = xsub + "/address-pools";
const string& prefix1 = xpool + "/address-pool[pool-id='1']/pool-prefix";
- S_Val s_pool1(new Val("2001:db8::1:0/112"));
- EXPECT_NO_THROW(sess_->set_item(prefix1.c_str(), s_pool1));
+ string const s_pool1("2001:db8::1:0/112");
+ EXPECT_NO_THROW(sess_->setItem(prefix1, s_pool1));
+ sess_->applyChanges();
// Create the pool 2001:db8::2:0/112 #2.
const string& prefix2 = xpool + "/address-pool[pool-id='2']/pool-prefix";
- S_Val s_pool2(new Val("2001:db8::2:0/112"));
- EXPECT_NO_THROW(sess_->set_item(prefix2.c_str(), s_pool2));
+ string const s_pool2("2001:db8::2:0/112");
+ EXPECT_NO_THROW(sess_->setItem(prefix2, s_pool2));
+ sess_->applyChanges();
// Get the subnet.
ConstElementPtr subnet;
@@ -187,21 +192,23 @@ TEST_F(TranslatorSubnetsTestKeaV6, getPoolsKea) {
// Create the subnet 2001:db8::/48 #111.
const string& xpath = "/kea-dhcp6-server:config";
const string& xsub = xpath + "/subnet6[id='111']";
- S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+ string const v_subnet("2001:db8::/48");
const string& xsubnet = xsub + "/subnet";
- EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+ EXPECT_NO_THROW(sess_->setItem(xsubnet, v_subnet));
+ sess_->applyChanges();
// Create the pool 2001:db8::1:0/112.
const string& prefix1 = xsub + "/pool[start-address='2001:db8::1:0']" +
"[end-address='2001:db8::1:ffff']/prefix";
- S_Val s_pool1(new Val("2001:db8::1:0/112", SR_STRING_T));
- EXPECT_NO_THROW(sess_->set_item(prefix1.c_str(), s_pool1));
+ string const s_pool1("2001:db8::1:0/112");
+ EXPECT_NO_THROW(sess_->setItem(prefix1, s_pool1));
+ sess_->applyChanges();
// Create the pool 2001:db8::2:0/112.
const string& prefix2 = xsub + "/pool[start-address='2001:db8::2:0']" +
"[end-address='2001:db8::2:ffff']";
- S_Val s_pool2;
- EXPECT_NO_THROW(sess_->set_item(prefix2.c_str(), s_pool2));
+ EXPECT_NO_THROW(sess_->setItem(prefix2, nullopt));
+ sess_->applyChanges();
// Get the subnet.
ConstElementPtr subnet;
@@ -301,9 +308,6 @@ TEST_F(TranslatorSubnetsTestKeaV4, setKea) {
ASSERT_EQ(Element::list, subnets->getType());
ASSERT_EQ(1, subnets->size());
EXPECT_TRUE(subnet->equals(*subnets->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
// This test verifies that one subnet with two pools can be properly
@@ -371,9 +375,6 @@ TEST_F(TranslatorSubnetsTestKeaV4, setTwoKea) {
ASSERT_EQ(Element::list, subnets->getType());
ASSERT_EQ(1, subnets->size());
EXPECT_TRUE(subnet->equals(*subnets->get(0)));
-
- // Check it validates.
- EXPECT_NO_THROW(sess_->validate());
}
} // namespace
diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc
index a602b28604..7a831a12b1 100644
--- a/src/lib/yang/tests/translator_unittests.cc
+++ b/src/lib/yang/tests/translator_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,6 +8,7 @@
#include <testutils/gtest_utils.h>
#include <yang/translator.h>
+#include <yang/tests/sysrepo_setup.h>
#include <boost/scoped_ptr.hpp>
@@ -17,153 +18,61 @@ using namespace std;
using namespace isc;
using namespace isc::data;
using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace libyang;
using namespace sysrepo;
-using libyang::S_Data_Node;
+struct TranslatorBasicTest : ::testing::Test {
+ void SetUp() override {
+ SysrepoSetup::cleanSharedMemory();
+ cleanUp();
+ }
+
+ void TearDown() override {
+ cleanUp();
+ SysrepoSetup::cleanSharedMemory();
+ }
+
+private:
+ void cleanUp() {
+ Session session(sysrepo::Connection{}.sessionStart());
+ session.switchDatastore(sysrepo::Datastore::Candidate);
+ session.deleteItem("/keatest-module:container");
+ session.deleteItem("/keatest-module:kernel-modules");
+ session.deleteItem("/keatest-module:list");
+ session.deleteItem("/keatest-module:main");
+ session.deleteItem("/keatest-module:presence-container");
+ session.applyChanges();
+ }
+};
namespace {
// Test constructor.
-TEST(TranslatorBasicTest, constructor) {
- // Get a connection.
- S_Connection conn(std::make_shared<Connection>());
+TEST_F(TranslatorBasicTest, constructor) {
// Get a session.
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
// Get a translator object.
boost::scoped_ptr<TranslatorBasic> t_obj;
EXPECT_NO_THROW(t_obj.reset(new TranslatorBasic(sess, "")));
}
-// Test basic yang value to JSON using the static method.
-TEST(TranslatorBasicTest, valueFrom) {
- S_Val s_val;
- ConstElementPtr elem;
-
- // Null.
- EXPECT_THROW(TranslatorBasic::value(s_val), BadValue);
-
- // No easy and direct way to build a container or a list...
-
- // String.
- string str("foo");
- s_val.reset(new Val(str.c_str(), SR_STRING_T));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::string, elem->getType());
- EXPECT_EQ(str, elem->stringValue());
- elem.reset();
-
- // Bool.
- s_val.reset(new Val(false, SR_BOOL_T));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::boolean, elem->getType());
- EXPECT_FALSE(elem->boolValue());
- elem.reset();
-
- // Unsigned 8 bit integer.
- uint8_t u8(123);
- s_val.reset(new Val(u8));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::integer, elem->getType());
- EXPECT_EQ(u8, elem->intValue());
- elem.reset();
-
- // Unsigned 16 bit integer.
- uint16_t u16(12345);
- s_val.reset(new Val(u16));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::integer, elem->getType());
- EXPECT_EQ(u16, elem->intValue());
- elem.reset();
-
- // Unsigned 32 bit integer.
- uint32_t u32(123456789);
- s_val.reset(new Val(u32));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::integer, elem->getType());
- EXPECT_EQ(u32, elem->intValue());
- elem.reset();
-
- // Signed 8 bit integer.
- int8_t s8(-123);
- s_val.reset(new Val(s8));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::integer, elem->getType());
- EXPECT_EQ(s8, elem->intValue());
- elem.reset();
-
- // Signed 16 bit integer.
- int16_t s16(-12345);
- s_val.reset(new Val(s16));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::integer, elem->getType());
- EXPECT_EQ(s16, elem->intValue());
- elem.reset();
-
- // Signed 32 bit integer.
- int32_t s32(-123456789);
- s_val.reset(new Val(s32));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::integer, elem->getType());
- EXPECT_EQ(s32, elem->intValue());
- elem.reset();
-
- // Identity reference.
- s_val.reset(new Val(str.c_str(), SR_IDENTITYREF_T));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::string, elem->getType());
- EXPECT_EQ(str, elem->stringValue());
- elem.reset();
-
- // Enumeration item.
- s_val.reset(new Val(str.c_str(), SR_ENUM_T));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::string, elem->getType());
- EXPECT_EQ(str, elem->stringValue());
- elem.reset();
-
- // Binary.
- string binary("Zm9vYmFy");
- s_val.reset(new Val(binary.c_str(), SR_BINARY_T));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::string, elem->getType());
- EXPECT_EQ("foobar", elem->stringValue());
- elem.reset();
-
- // Decimal 64.
- double d64(.1234);
- s_val.reset(new Val(d64));
- EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val));
- ASSERT_TRUE(elem);
- ASSERT_EQ(Element::real, elem->getType());
- EXPECT_DOUBLE_EQ(d64, elem->doubleValue());
-}
-
-// Test basic yang value to JSON using sysrepo test models.
-TEST(TranslatorBasicTest, getItem) {
+// Test basic YANG to JSON value conversion using sysrepo test models.
+TEST_F(TranslatorBasicTest, getItem) {
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
boost::scoped_ptr<TranslatorBasic> t_obj;
ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, "")));
- S_Val s_val;
+ string s_val;
ConstElementPtr elem;
string xpath;
// String.
xpath = "/keatest-module:main/string";
- s_val.reset(new Val("str", SR_STRING_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = "str";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::string, elem->getType());
@@ -172,8 +81,8 @@ TEST(TranslatorBasicTest, getItem) {
// Bool.
xpath = "/keatest-module:main/boolean";
- s_val.reset(new Val(true, SR_BOOL_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = "true";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::boolean, elem->getType());
@@ -183,8 +92,8 @@ TEST(TranslatorBasicTest, getItem) {
// Unsigned 8 bit integer.
xpath = "/keatest-module:main/ui8";
uint8_t u8(8);
- s_val.reset(new Val(u8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(u8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::integer, elem->getType());
@@ -194,8 +103,8 @@ TEST(TranslatorBasicTest, getItem) {
// Unsigned 16 bit integer.
xpath = "/keatest-module:main/ui16";
uint16_t u16(16);
- s_val.reset(new Val(u16));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(u16);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::integer, elem->getType());
@@ -205,8 +114,8 @@ TEST(TranslatorBasicTest, getItem) {
// Unsigned 32 bit integer.
xpath = "/keatest-module:main/ui32";
uint32_t u32(32);
- s_val.reset(new Val(u32));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(u32);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::integer, elem->getType());
@@ -216,8 +125,8 @@ TEST(TranslatorBasicTest, getItem) {
// Signed 8 bit integer.
xpath = "/keatest-module:main/i8";
int8_t s8(8);
- s_val.reset(new Val(s8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(s8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::integer, elem->getType());
@@ -227,8 +136,8 @@ TEST(TranslatorBasicTest, getItem) {
// Signed 16 bit integer.
xpath = "/keatest-module:main/i16";
int16_t s16(16);
- s_val.reset(new Val(s16));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(s16);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::integer, elem->getType());
@@ -238,8 +147,8 @@ TEST(TranslatorBasicTest, getItem) {
// Signed 32 bit integer.
xpath = "/keatest-module:main/i32";
int32_t s32(32);
- s_val.reset(new Val(s32));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(s32);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::integer, elem->getType());
@@ -248,8 +157,8 @@ TEST(TranslatorBasicTest, getItem) {
// Identity reference.
xpath = "/keatest-module:main/id_ref";
- s_val.reset(new Val("keatest-module:id_1", SR_IDENTITYREF_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = "keatest-module:id_1";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::string, elem->getType());
@@ -258,8 +167,8 @@ TEST(TranslatorBasicTest, getItem) {
// Enumeration item.
xpath = "/keatest-module:main/enum";
- s_val.reset(new Val("maybe", SR_ENUM_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = "maybe";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::string, elem->getType());
@@ -268,8 +177,8 @@ TEST(TranslatorBasicTest, getItem) {
// Binary.
xpath = "/keatest-module:main/raw";
- s_val.reset(new Val("Zm9vYmFy", SR_BINARY_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = "Zm9vYmFy";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::string, elem->getType());
@@ -286,14 +195,14 @@ TEST(TranslatorBasicTest, getItem) {
// Leaf-list: 1, 2 and 3.
u8 = 1;
- s_val.reset(new Val(u8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(u8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
u8 = 2;
- s_val.reset(new Val(u8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(u8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
u8 = 3;
- s_val.reset(new Val(u8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(u8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItems(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::list, elem->getType());
@@ -303,8 +212,8 @@ TEST(TranslatorBasicTest, getItem) {
// Unknown / unsupported.
xpath = "/keatest-module:main/dec64";
- s_val.reset(new Val(9.85));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ s_val = to_string(9.85);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
ASSERT_TRUE(elem);
ASSERT_EQ(Element::real, elem->getType());
@@ -313,330 +222,277 @@ TEST(TranslatorBasicTest, getItem) {
// Not found.
xpath = "/keatest-module:main/no_such_string";
-
- // sysrepo_exception: "Invalid argument"
- EXPECT_THROW(sess->delete_item(xpath.c_str()), sysrepo_exception);
+ EXPECT_THROW(t_obj->delItem(xpath), SysrepoError);
EXPECT_THROW(elem = t_obj->getItem(xpath), SysrepoError);
EXPECT_FALSE(elem);
elem.reset();
// Check error.
xpath = "null";
- try {
- elem = t_obj->getItem(xpath);
- ADD_FAILURE() << "expected exception";
- } catch (const SysrepoError& ex) {
- EXPECT_EQ("sysrepo error getting item at 'null': libyang error",
- string(ex.what()));
- } catch (const std::exception& ex) {
- ADD_FAILURE() << "unexpected exception with: " << ex.what();
- }
+ EXPECT_THROW_MSG(elem = t_obj->getItem(xpath), SysrepoError,
+ "sysrepo error getting item at 'null': Couldn't find schema node: null");
+ EXPECT_FALSE(elem);
}
-// Test JSON to basic yang value using the static method.
-TEST(TranslatorBasicTest, valueTo) {
+// Test JSON to basic YANG value conversion using the static method.
+TEST_F(TranslatorBasicTest, valueTo) {
+ optional<string> s_val;
// Null.
ConstElementPtr elem;
- EXPECT_THROW(TranslatorBasic::value(elem, SR_STRING_T), BadValue);
+ EXPECT_NO_THROW_LOG(s_val = TranslatorBasic::value(elem, LeafBaseType::String));
+ EXPECT_EQ(nullopt, s_val);
+ EXPECT_FALSE(elem);
// Container.
elem = Element::createMap();
- EXPECT_THROW(TranslatorBasic::value(elem, SR_CONTAINER_T), NotImplemented);
- EXPECT_THROW(TranslatorBasic::value(elem, SR_CONTAINER_PRESENCE_T), NotImplemented);
+ EXPECT_THROW(TranslatorBasic::value(elem, LeafBaseType::Unknown), NotImplemented);
// List.
elem = Element::createList();
- S_Val s_val;
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_LIST_T));
- EXPECT_FALSE(s_val);
- s_val.reset();
+ EXPECT_THROW(TranslatorBasic::value(elem, LeafBaseType::Unknown), NotImplemented);
// String.
string str("foo");
elem = Element::create(str);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_STRING_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_STRING_T, s_val->type());
- EXPECT_EQ(str, string(s_val->data()->get_string()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::String));
+ EXPECT_EQ(elem->stringValue(), s_val);
// Bool.
elem = Element::create(false);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_BOOL_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_BOOL_T, s_val->type());
- EXPECT_FALSE(s_val->data()->get_bool());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Bool));
+ EXPECT_EQ(elem->str(), s_val);
// Unsigned 8 bit integer.
elem = Element::create(123);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_UINT8_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_UINT8_T, s_val->type());
- EXPECT_EQ(123, s_val->data()->get_uint8());
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Uint8));
+ EXPECT_EQ(elem->str(), s_val);
elem.reset();
// Unsigned 16 bit integer.
elem = Element::create(12345);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_UINT16_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_UINT16_T, s_val->type());
- EXPECT_EQ(12345, s_val->data()->get_uint16());
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Uint16));
+ EXPECT_EQ(elem->str(), s_val);
elem.reset();
// Unsigned 32 bit integer.
elem = Element::create(123456789);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_UINT32_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_UINT32_T, s_val->type());
- EXPECT_EQ(123456789, s_val->data()->get_uint32());
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Uint32));
+ EXPECT_EQ(elem->str(), s_val);
elem.reset();
// Signed 8 bit integer.
elem = Element::create(-123);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_INT8_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_INT8_T, s_val->type());
- EXPECT_EQ(-123, s_val->data()->get_int8());
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Int8));
+ EXPECT_EQ(elem->str(), s_val);
elem.reset();
// Signed 16 bit integer.
elem = Element::create(-12345);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_INT16_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_INT16_T, s_val->type());
- EXPECT_EQ(-12345, s_val->data()->get_int16());
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Int16));
+ EXPECT_EQ(elem->str(), s_val);
elem.reset();
// Signed 32 bit integer.
elem = Element::create(-123456789);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_INT32_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_INT32_T, s_val->type());
- EXPECT_EQ(-123456789, s_val->data()->get_int32());
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Int32));
+ EXPECT_EQ(elem->str(), s_val);
elem.reset();
// Identity reference.
elem = Element::create(str);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_IDENTITYREF_T));
- ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_IDENTITYREF_T, s_val->type());
- EXPECT_EQ(str, string(s_val->data()->get_identityref()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::IdentityRef));
+ EXPECT_EQ(elem->stringValue(), s_val);
// Enumeration item.
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_ENUM_T));
- ASSERT_TRUE(s_val);
- EXPECT_EQ(str, string(s_val->data()->get_enum()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Enum));
+ EXPECT_EQ(elem->stringValue(), s_val);
// Binary.
elem = Element::create(string("foobar"));
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_BINARY_T));
- ASSERT_TRUE(s_val);
- EXPECT_EQ("Zm9vYmFy", string(s_val->data()->get_binary()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Binary));
+ EXPECT_EQ("Zm9vYmFy", s_val);
// Decimal 64.
double d64(.1234);
elem = Element::create(d64);
- EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, SR_DECIMAL64_T));
- ASSERT_TRUE(s_val);
- EXPECT_DOUBLE_EQ(d64, s_val->data()->get_decimal64());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = TranslatorBasic::value(elem, LeafBaseType::Dec64));
+ EXPECT_EQ(elem->str(), s_val);
}
-// Test JSON to basic yang value using sysrepo test models.
-TEST(TranslatorBasicTest, setItem) {
+// Test JSON to basic YANG value conversion using sysrepo test models.
+TEST_F(TranslatorBasicTest, setItem) {
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
boost::scoped_ptr<TranslatorBasic> t_obj;
ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, "")));
- // Container.
- string xpath = "/keatest-module:container";
- ConstElementPtr elem = Element::createMap();
- EXPECT_THROW(t_obj->setItem(xpath, elem, SR_CONTAINER_T), NotImplemented);
- EXPECT_THROW(t_obj->setItem(xpath, elem, SR_CONTAINER_PRESENCE_T),
- NotImplemented);
+ ElementPtr elem;
+ string xpath;
// String.
- S_Val s_val;
+ optional<DataNode> s_val;
xpath = "/keatest-module:main/string";
elem = Element::create(string("str"));
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_STRING_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::String));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_STRING_T, s_val->type());
- EXPECT_EQ("str", string(s_val->data()->get_string()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::String, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->stringValue(), string(s_val->asTerm().valueStr()));
// Bool.
xpath = "/keatest-module:main/boolean";
elem = Element::create(true);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_BOOL_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Bool));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_BOOL_T, s_val->type());
- EXPECT_TRUE(s_val->data()->get_bool());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Bool, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Unsigned 8 bit integer.
xpath = "/keatest-module:main/ui8";
elem = Element::create(8);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_UINT8_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Uint8));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_UINT8_T, s_val->type());
- EXPECT_EQ(8, s_val->data()->get_uint8());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Uint8, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Unsigned 16 bit integer.
xpath = "/keatest-module:main/ui16";
elem = Element::create(16);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_UINT16_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Uint16));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_UINT16_T, s_val->type());
- EXPECT_EQ(16, s_val->data()->get_uint16());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Uint16, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Unsigned 32 bit integer.
xpath = "/keatest-module:main/ui32";
elem = Element::create(32);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_UINT32_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Uint32));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_UINT32_T, s_val->type());
- EXPECT_EQ(32, s_val->data()->get_uint32());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Uint32, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Signed 8 bit integer.
xpath = "/keatest-module:main/i8";
elem = Element::create(8);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_INT8_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Int8));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_INT8_T, s_val->type());
- EXPECT_EQ(8, s_val->data()->get_int8());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Int8, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Signed 16 bit integer.
xpath = "/keatest-module:main/i16";
elem = Element::create(16);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_INT16_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Int16));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_INT16_T, s_val->type());
- EXPECT_EQ(16, s_val->data()->get_int16());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Int16, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Signed 32 bit integer.
xpath = "/keatest-module:main/i32";
elem = Element::create(32);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_INT32_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Int32));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_INT32_T, s_val->type());
- EXPECT_EQ(32, s_val->data()->get_int32());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Int32, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Identity reference.
xpath = "/keatest-module:main/id_ref";
elem = Element::create(string("keatest-module:id_1"));
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_IDENTITYREF_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::IdentityRef));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_IDENTITYREF_T, s_val->type());
- EXPECT_EQ("keatest-module:id_1", string(s_val->data()->get_identityref()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::IdentityRef, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->stringValue(), string(s_val->asTerm().valueStr()));
// Enumeration item.
xpath = "/keatest-module:main/enum";
elem = Element::create(string("maybe"));
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_ENUM_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Enum));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_ENUM_T, s_val->type());
- EXPECT_EQ("maybe", string(s_val->data()->get_enum()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Enum, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->stringValue(), string(s_val->asTerm().valueStr()));
// Binary.
xpath = "/keatest-module:main/raw";
elem = Element::create(string("foobar"));
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_BINARY_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Binary));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_BINARY_T, s_val->type());
- EXPECT_EQ("Zm9vYmFy", string(s_val->data()->get_binary()));
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Binary, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ("Zm9vYmFy", string(s_val->asTerm().valueStr()));
// Decimal 64.
xpath = "/keatest-module:main/dec64";
double d64(9.85);
elem = Element::create(d64);
- EXPECT_NO_THROW(t_obj->setItem(xpath, elem, SR_DECIMAL64_T));
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, elem, LeafBaseType::Dec64));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
ASSERT_TRUE(s_val);
- ASSERT_EQ(SR_DECIMAL64_T, s_val->type());
- EXPECT_DOUBLE_EQ(d64, s_val->data()->get_decimal64());
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(LeafBaseType::Dec64, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ(elem->str(), string(s_val->asTerm().valueStr()));
// Leaf-list.
xpath = "/keatest-module:main/numbers";
- S_Data_Node data_node;
- EXPECT_NO_THROW(data_node = sess->get_subtree(xpath.c_str()));
- EXPECT_FALSE(data_node);
- data_node.reset();
-
- // Fill it.
- sess->set_item_str(xpath.c_str(), "1");
- sess->set_item_str(xpath.c_str(), "2");
- sess->set_item_str(xpath.c_str(), "3");
- sess->apply_changes();
-
- // sysrepo_exception: "Invalid argument"
- EXPECT_THROW(data_node = sess->get_subtree(xpath.c_str()),
- sysrepo_exception);
- EXPECT_FALSE(data_node);
- data_node.reset();
+ EXPECT_NO_THROW(t_obj->setItem(xpath, Element::fromJSON("1"), LeafBaseType::Uint8));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, Element::fromJSON("2"), LeafBaseType::Uint8));
+ EXPECT_NO_THROW(t_obj->setItem(xpath, Element::fromJSON("3"), LeafBaseType::Uint8));
+ ElementPtr got(t_obj->getItem(xpath));
+ ASSERT_EQ(LeafBaseType::Dec64, s_val->schema().asLeaf().valueType().base());
+ EXPECT_EQ("[ 1, 2, 3 ]", got->str());
// Clean it.
EXPECT_NO_THROW(t_obj->delItem(xpath));
- EXPECT_NO_THROW(data_node = sess->get_subtree(xpath.c_str()));
- EXPECT_FALSE(data_node);
- data_node.reset();
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
+ EXPECT_FALSE(s_val);
+ s_val.reset();
// Bad xpath.
xpath = "/keatest-module:main/no_such_string";
elem = Element::create(string("str"));
- try {
- t_obj->setItem(xpath, elem, SR_STRING_T);
- ADD_FAILURE() << "expected exception";
- } catch (const SysrepoError& ex) {
- string expected = "sysrepo error setting item '\"str\"' at '" +
- xpath + "': Invalid argument";
- EXPECT_EQ(expected, string(ex.what()));
- } catch (const std::exception& ex) {
- ADD_FAILURE() << "unexpected exception with: " << ex.what();
- }
+ EXPECT_THROW_MSG(t_obj->setItem(xpath, elem, LeafBaseType::String), SysrepoError,
+ "sysrepo error setting item '\"str\"' at '" + xpath +
+ "': Session::setItem: Couldn't set "
+ "'/keatest-module:main/no_such_string' to 'str': SR_ERR_INVAL_ARG");
// Bad type.
xpath = "/keatest-module:main/string";
elem = Element::create(true);
- try {
- t_obj->setItem(xpath, elem, SR_BOOL_T);
- } catch (const SysrepoError& ex) {
- ADD_FAILURE() << "unexpected exception with: " << ex.what();
- } catch (const std::exception& ex) {
- ADD_FAILURE() << "unexpected exception with: " << ex.what();
- }
+ EXPECT_NO_THROW_LOG(t_obj->setItem(xpath, elem, LeafBaseType::Bool));
- // In sysrepo 1.x, set_item() is based on set_item_str() which sets the
- // value in textual format. After setting a value with SR_BOOL_T, it's value
- // is now "true". :)
elem = t_obj->getItem(xpath);
ASSERT_TRUE(elem);
EXPECT_EQ(elem->getType(), Element::string);
@@ -644,22 +500,25 @@ TEST(TranslatorBasicTest, setItem) {
// Delete (twice).
xpath = "/keatest-module:main/string";
- EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_NO_THROW(s_val = sess.getData(xpath));
EXPECT_TRUE(s_val);
- s_val.reset();
+ EXPECT_NO_THROW(s_val = s_val->findPath(xpath));
+ EXPECT_TRUE(s_val);
+ ASSERT_TRUE(NodeType::Leaf == s_val->schema().nodeType());
+ EXPECT_EQ("true", s_val->asTerm().valueStr());
EXPECT_NO_THROW(t_obj->delItem(xpath));
-
- // sysrepo_exception: "Item not found"
- EXPECT_THROW(s_val = sess->get_item(xpath.c_str()), sysrepo_exception);
+ EXPECT_NO_THROW_LOG(s_val = sess.getData(xpath));
EXPECT_FALSE(s_val);
EXPECT_NO_THROW(t_obj->delItem(xpath));
+ EXPECT_NO_THROW_LOG(s_val = sess.getData(xpath));
+ EXPECT_FALSE(s_val);
}
-// Test yang list item retrieval.
-TEST(TranslatorBasicTest, list) {
+// Test YANG list item retrieval.
+TEST_F(TranslatorBasicTest, list) {
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
boost::scoped_ptr<TranslatorBasic> t_obj;
ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, "")));
string xpath;
@@ -672,12 +531,12 @@ TEST(TranslatorBasicTest, list) {
// Retried with a filled list.
xpath = "/keatest-module:container/list[key1='key1'][key2='key2']/leaf";
- S_Val s_val(new Val("Leaf value"));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ element = Element::create("Leaf value");
+ EXPECT_NO_THROW(t_obj->setItem(xpath, element, LeafBaseType::String));
EXPECT_NO_THROW(element = t_obj->getItem("/keatest-module:container/list"));
- ASSERT_TRUE(element);
+ EXPECT_FALSE(element);
EXPECT_NO_THROW(element = t_obj->getItem("/keatest-module:container/list[key1='key1'][key2='key2']"));
- ASSERT_TRUE(element);
+ EXPECT_FALSE(element);
}
} // anonymous namespace
diff --git a/src/lib/yang/tests/translator_utils_unittests.cc b/src/lib/yang/tests/translator_utils_unittests.cc
index bc68f1268b..5862622faf 100644
--- a/src/lib/yang/tests/translator_utils_unittests.cc
+++ b/src/lib/yang/tests/translator_utils_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -18,16 +18,17 @@ using namespace std;
using namespace isc;
using namespace isc::yang;
using namespace isc::yang::test;
+using namespace libyang;
using namespace sysrepo;
namespace {
-// Test sr_type_t print.
+// Test LeafBaseType print.
TEST(YangReprTest, type) {
ostringstream os;
// Verify that string is "string" (vs a number).
- sr_type_t t = SR_STRING_T;
+ LeafBaseType t(LeafBaseType::String);
os << t;
EXPECT_EQ("string", os.str());
os.str("");
@@ -38,19 +39,23 @@ TEST(YangReprTest, type) {
// Test YangReprItem basic stuff.
TEST(YangReprTest, item) {
// An item.
- YRItem item1("/foo", "bar", SR_STRING_T, true);
+ YRItem item1("/foo", "bar", LeafBaseType::String, true);
EXPECT_EQ("/foo", item1.xpath_);
EXPECT_EQ("bar", item1.value_);
- EXPECT_EQ(SR_STRING_T, item1.type_);
EXPECT_TRUE(item1.settable_);
+ // EXPECT_EQ doesn't work. Tries to << into a stringstream.
+ EXPECT_TRUE(LeafBaseType::String == item1.type_);
+
// Another one.
- YRItem item2("/foo", "bar", SR_STRING_T, false);
+ YRItem item2("/foo", "bar", LeafBaseType::String, false);
EXPECT_EQ("/foo", item2.xpath_);
EXPECT_EQ("bar", item2.value_);
- EXPECT_EQ(SR_STRING_T, item2.type_);
EXPECT_FALSE(item2.settable_);
+ // EXPECT_EQ doesn't work. Tries to << into a stringstream.
+ EXPECT_TRUE(LeafBaseType::String == item2.type_);
+
// Equality.
EXPECT_TRUE(item1 == item2);
EXPECT_TRUE(item2 == item1);
@@ -65,80 +70,80 @@ TEST(YangReprTest, getTest) {
SysrepoSetup::cleanSharedMemory();
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
// Cleanup.
- EXPECT_NO_THROW(sess->delete_item("/keatest-module:container"));
- EXPECT_NO_THROW(sess->apply_changes());
- EXPECT_NO_THROW(sess->delete_item("/keatest-module:main"));
- EXPECT_NO_THROW(sess->apply_changes());
+ EXPECT_NO_THROW(sess.deleteItem("/keatest-module:container"));
+ EXPECT_NO_THROW(sess.applyChanges());
+ EXPECT_NO_THROW(sess.deleteItem("/keatest-module:main"));
+ EXPECT_NO_THROW(sess.applyChanges());
// Fill the test module.
string xpath;
- S_Val s_val;
+ string s_val;
xpath = "/keatest-module:main/string";
- s_val.reset(new Val("str", SR_STRING_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = "str";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/boolean";
- s_val.reset(new Val(true, SR_BOOL_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = "true";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/ui8";
uint8_t u8(8);
- s_val.reset(new Val(u8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = to_string(u8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/ui16";
uint16_t u16(16);
- s_val.reset(new Val(u16));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = to_string(u16);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/ui32";
uint32_t u32(32);
- s_val.reset(new Val(u32));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = to_string(u32);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/i8";
int8_t s8(8);
- s_val.reset(new Val(s8));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = to_string(s8);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/i16";
int16_t s16(16);
- s_val.reset(new Val(s16));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = to_string(s16);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/i32";
int32_t s32(32);
- s_val.reset(new Val(s32));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = to_string(s32);
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/id_ref";
- s_val.reset(new Val("keatest-module:id_1", SR_IDENTITYREF_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = "keatest-module:id_1";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
xpath = "/keatest-module:main/enum";
- s_val.reset(new Val("maybe", SR_ENUM_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = "maybe";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
// Binary.
xpath = "/keatest-module:main/raw";
- s_val.reset(new Val("Zm9vYmFy", SR_BINARY_T));
- EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
- EXPECT_NO_THROW(sess->apply_changes());
+ s_val = "Zm9vYmFy";
+ EXPECT_NO_THROW(sess.setItem(xpath, s_val));
+ EXPECT_NO_THROW(sess.applyChanges());
// Get it.
YangRepr repr(testModel);
@@ -154,14 +159,14 @@ TEST(YangReprTrest, getTestErrors) {
SysrepoSetup::cleanSharedMemory();
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
// Cleanup.
- EXPECT_NO_THROW(sess->delete_item("/keatest-module:container"));
- EXPECT_NO_THROW(sess->apply_changes());
- EXPECT_NO_THROW(sess->delete_item("/keatest-module:main"));
- EXPECT_NO_THROW(sess->apply_changes());
+ EXPECT_NO_THROW(sess.deleteItem("/keatest-module:container"));
+ EXPECT_NO_THROW(sess.applyChanges());
+ EXPECT_NO_THROW(sess.deleteItem("/keatest-module:main"));
+ EXPECT_NO_THROW(sess.applyChanges());
// Get it.
YangRepr repr(testModel);
@@ -186,18 +191,12 @@ TEST(YangReprTrest, getTestErrors) {
badvalue.at(xpath).value_ = "Str";
EXPECT_FALSE(repr.verify(badvalue, sess, cerr));
- // Change a type from SR_INT32_T to SR_UINT32_T.
+ // Change a type from LeafBaseType::Int32 to LeafBaseType::Uint32.
YRTree badtype = testTree;
xpath = "/keatest-module:main/i32";
- badtype.at(xpath).type_ = SR_UINT32_T;
+ badtype.at(xpath).type_ = LeafBaseType::Uint32;
EXPECT_FALSE(repr.verify(badtype, sess, cerr));
- // Add a record at the end.
- YRTree badmissing = testTree;
- xpath = "/keatest-module:presence-container";
- badmissing.emplace(xpath, YRItem(xpath, "", SR_CONTAINER_PRESENCE_T, false));
- EXPECT_FALSE(repr.verify(badmissing, sess, cerr));
-
// Delete last record.
YRTree badextra = testTree;
badextra.erase("/keatest-module:kernel-modules");
@@ -209,14 +208,14 @@ TEST(YangReprTest, setTest) {
SysrepoSetup::cleanSharedMemory();
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
// Cleanup.
- EXPECT_NO_THROW(sess->delete_item("/keatest-module:container"));
- EXPECT_NO_THROW(sess->apply_changes());
- EXPECT_NO_THROW(sess->delete_item("/keatest-module:main"));
- EXPECT_NO_THROW(sess->apply_changes());
+ EXPECT_NO_THROW(sess.deleteItem("/keatest-module:container"));
+ EXPECT_NO_THROW(sess.applyChanges());
+ EXPECT_NO_THROW(sess.deleteItem("/keatest-module:main"));
+ EXPECT_NO_THROW(sess.applyChanges());
// Set the module content.
YangRepr repr(testModel);
@@ -236,16 +235,24 @@ void sanityCheckConfig(const std::string& model, const YRTree& tree) {
SysrepoSetup::cleanSharedMemory();
// Get a translator object to play with.
- S_Connection conn(std::make_shared<Connection>());
- S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ Session sess(Connection{}.sessionStart());
+ sess.switchDatastore(sysrepo::Datastore::Candidate);
// Cleanup.
TranslatorBasic translator(sess, model);
- std::string toplevel_node("config");
- if (model == IETF_DHCPV6_SERVER) {
- toplevel_node = "server";
+ if (model == "keatest-module") {
+ translator.delItem("/keatest-module:container");
+ translator.delItem("/keatest-module:kernel-modules");
+ translator.delItem("/keatest-module:list");
+ translator.delItem("/keatest-module:main");
+ translator.delItem("/keatest-module:presence-container");
+ } else {
+ std::string toplevel_node("config");
+ if (model == IETF_DHCPV6_SERVER) {
+ toplevel_node = "server";
+ }
+ EXPECT_NO_THROW(translator.delItem("/" + model + ":" + toplevel_node));
}
- translator.delItem("/" + model + ":" + toplevel_node);
// Get it.
YangRepr repr(model);
diff --git a/src/lib/yang/tests/yang_configs.h b/src/lib/yang/tests/yang_configs.h
index 71a89eaad9..7f6b7356e5 100644
--- a/src/lib/yang/tests/yang_configs.h
+++ b/src/lib/yang/tests/yang_configs.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -17,559 +17,610 @@ namespace test {
/// @brief The test module from sysrepo tests.
const std::string testModel = "keatest-module";
const YRTree testTree = YangRepr::buildTreeFromVector({
- { "/keatest-module:container", "", SR_CONTAINER_T, false },
- { "/keatest-module:main", "", SR_CONTAINER_T, false },
- { "/keatest-module:main/string", "str", SR_STRING_T, true },
- { "/keatest-module:main/boolean", "true", SR_BOOL_T, true },
- { "/keatest-module:main/ui8", "8", SR_UINT8_T, true },
- { "/keatest-module:main/ui16", "16", SR_UINT16_T, true },
- { "/keatest-module:main/ui32", "32", SR_UINT32_T, true },
- { "/keatest-module:main/i8", "8", SR_INT8_T, true },
- { "/keatest-module:main/i16", "16", SR_INT16_T, true },
- { "/keatest-module:main/i32", "32", SR_INT32_T, true },
- { "/keatest-module:main/id_ref", "keatest-module:id_1",
- SR_IDENTITYREF_T, true },
- { "/keatest-module:main/enum", "maybe", SR_ENUM_T, true },
- { "/keatest-module:main/raw", "Zm9vYmFy", SR_BINARY_T, true },
- { "/keatest-module:kernel-modules", "", SR_CONTAINER_T, false }
+ { "/keatest-module:container",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/keatest-module:main",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/keatest-module:main/string",
+ "str", libyang::LeafBaseType::String, true },
+ { "/keatest-module:main/boolean",
+ "true", libyang::LeafBaseType::Bool, true },
+ { "/keatest-module:main/ui8",
+ "8", libyang::LeafBaseType::Uint8, true },
+ { "/keatest-module:main/ui16",
+ "16", libyang::LeafBaseType::Uint16, true },
+ { "/keatest-module:main/ui32",
+ "32", libyang::LeafBaseType::Uint32, true },
+ { "/keatest-module:main/i8",
+ "8", libyang::LeafBaseType::Int8, true },
+ { "/keatest-module:main/i16",
+ "16", libyang::LeafBaseType::Int16, true },
+ { "/keatest-module:main/i32",
+ "32", libyang::LeafBaseType::Int32, true },
+ { "/keatest-module:main/id_ref",
+ "keatest-module:id_1", libyang::LeafBaseType::IdentityRef, true },
+ { "/keatest-module:main/enum",
+ "maybe", libyang::LeafBaseType::Enum, true },
+ { "/keatest-module:main/raw",
+ "Zm9vYmFy", libyang::LeafBaseType::Binary, true },
+ { "/keatest-module:kernel-modules",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief A subnet with two pools with ietf-dhcpv6-server model.
const std::string subnetTwoPoolsModelIetf6 = IETF_DHCPV6_SERVER;
const YRTree subnetTwoPoolsTreeIetf6 = YangRepr::buildTreeFromVector({
- { "/ietf-dhcpv6-server:server", "", SR_CONTAINER_PRESENCE_T, false },
- { "/ietf-dhcpv6-server:server/server-config", "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/ietf-dhcpv6-server:server/server-config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
- "network-range[network-range-id='111']", "", SR_LIST_T, false },
+ "network-range[network-range-id='111']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-range-id",
- "111", SR_UINT32_T, false },
+ "111", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-prefix",
- "2001:db8::/48", SR_STRING_T, true },
+ "2001:db8::/48", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='0']", "", SR_LIST_T, false },
+ "address-pool[pool-id='0']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='0']/pool-id", "0", SR_UINT32_T, false },
+ "address-pool[pool-id='0']/pool-id",
+ "0", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/pool-prefix",
- "2001:db8::1:0/112", SR_STRING_T, true },
+ "2001:db8::1:0/112", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/start-address",
- "2001:db8::1:0", SR_STRING_T, true },
+ "2001:db8::1:0", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/end-address",
- "2001:db8::1:ffff", SR_STRING_T, true },
+ "2001:db8::1:ffff", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/max-address-count",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='1']", "", SR_LIST_T, false },
+ "address-pool[pool-id='1']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='1']/pool-id", "1", SR_UINT32_T, false },
+ "address-pool[pool-id='1']/pool-id",
+ "1", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/pool-prefix",
- "2001:db8::2:0/112", SR_STRING_T, true },
+ "2001:db8::2:0/112", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/start-address",
- "2001:db8::2:0", SR_STRING_T, true },
+ "2001:db8::2:0", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/end-address",
- "2001:db8::2:ffff", SR_STRING_T, true },
+ "2001:db8::2:ffff", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/max-address-count",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
- "65535", SR_UINT16_T, false },
+ "65535", libyang::LeafBaseType::Uint16, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/host-reservations",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/option-sets",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief A subnet with timers with ietf-dhcpv6-server model.
const std::string subnetTimersModel = IETF_DHCPV6_SERVER;
const YRTree subnetTimersIetf6 = YangRepr::buildTreeFromVector({
- { "/ietf-dhcpv6-server:server", "", SR_CONTAINER_PRESENCE_T, false },
- { "/ietf-dhcpv6-server:server/server-config", "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/ietf-dhcpv6-server:server/server-config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
- "network-range[network-range-id='111']", "", SR_LIST_T, false },
+ "network-range[network-range-id='111']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-range-id",
- "111", SR_UINT32_T, false },
+ "111", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-prefix",
- "2001:db8::/48", SR_STRING_T, true },
+ "2001:db8::/48", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='0']", "", SR_LIST_T, false },
+ "address-pool[pool-id='0']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='0']/pool-id", "0", SR_UINT32_T, false },
+ "address-pool[pool-id='0']/pool-id",
+ "0", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/pool-prefix",
- "2001:db8::1:0/112", SR_STRING_T, true },
+ "2001:db8::1:0/112", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/start-address",
- "2001:db8::1:0", SR_STRING_T, true },
+ "2001:db8::1:0", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/end-address",
- "2001:db8::1:ffff", SR_STRING_T, true },
+ "2001:db8::1:ffff", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='0']/renew-time", "1000", SR_UINT32_T, true },
+ "address-pool[pool-id='0']/renew-time",
+ "1000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='0']/rebind-time", "2000", SR_UINT32_T, true },
+ "address-pool[pool-id='0']/rebind-time",
+ "2000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='0']/max-address-count",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='1']", "", SR_LIST_T, false },
+ "address-pool[pool-id='1']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='1']/pool-id", "1", SR_UINT32_T, false },
+ "address-pool[pool-id='1']/pool-id",
+ "1", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/pool-prefix",
- "2001:db8::2:0/112", SR_STRING_T, true },
+ "2001:db8::2:0/112", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/start-address",
- "2001:db8::2:0", SR_STRING_T, true },
+ "2001:db8::2:0", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/end-address",
- "2001:db8::2:ffff", SR_STRING_T, true },
+ "2001:db8::2:ffff", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='1']/renew-time", "1000", SR_UINT32_T, true },
+ "address-pool[pool-id='1']/renew-time",
+ "1000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
- "address-pool[pool-id='1']/rebind-time", "2000", SR_UINT32_T, true },
+ "address-pool[pool-id='1']/rebind-time",
+ "2000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools/"
"address-pool[pool-id='1']/max-address-count",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
- "65535", SR_UINT16_T, false },
+ "65535", libyang::LeafBaseType::Uint16, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/host-reservations",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/option-sets",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief A subnet with two pools with ietf-dhcpv6-server model
/// which validates.
const std::string validModelIetf6 = IETF_DHCPV6_SERVER;
const YRTree validTreeIetf6 = YangRepr::buildTreeFromVector({
- { "/ietf-dhcpv6-server:server", "", SR_CONTAINER_PRESENCE_T, false },
- { "/ietf-dhcpv6-server:server/server-config", "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/ietf-dhcpv6-server:server/server-config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes"
- "/vendor-info/ent-num", "2495", SR_UINT32_T, true },
+ "/vendor-info/ent-num",
+ "2495", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/option-sets",
- "", SR_CONTAINER_T, false },
- { "/ietf-dhcpv6-server:server/server-config/option-sets"
- "/option-set[option-set-id='0']", "", SR_LIST_T, false },
- { "/ietf-dhcpv6-server:server/server-config/option-sets"
- "/option-set[option-set-id='0']/option-set-id",
- "0", SR_UINT32_T, true },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
- "network-range[network-range-id='111']", "", SR_LIST_T, false },
+ "network-range[network-range-id='111']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-range-id",
- "111", SR_UINT32_T, false },
+ "111", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-description",
- "Subnet#111", SR_STRING_T, true },
+ "Subnet#111", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/network-prefix",
- "2001:db8::/48", SR_STRING_T, true },
+ "2001:db8::/48", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']", "", SR_LIST_T, false },
+ "pd-pool[pool-id='0']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/pool-id", "0", SR_UINT32_T, false },
+ "pd-pool[pool-id='0']/pool-id",
+ "0", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
"pd-pool[pool-id='0']/prefix",
- "2001:db8:1::/48", SR_STRING_T, true },
+ "2001:db8:1::/48", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/prefix-length", "48", SR_UINT8_T, true },
+ "pd-pool[pool-id='0']/prefix-length",
+ "48", libyang::LeafBaseType::Uint8, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/valid-lifetime", "4000", SR_UINT32_T, true },
+ "pd-pool[pool-id='0']/valid-lifetime",
+ "4000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
"pd-pool[pool-id='0']/preferred-lifetime",
- "3000", SR_UINT32_T, true },
+ "3000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/renew-time", "1000", SR_UINT32_T, true },
+ "pd-pool[pool-id='0']/renew-time",
+ "1000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/rebind-time", "2000", SR_UINT32_T, true },
+ "pd-pool[pool-id='0']/rebind-time",
+ "2000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/rapid-commit", "false", SR_BOOL_T, true },
+ "pd-pool[pool-id='0']/rapid-commit",
+ "false", libyang::LeafBaseType::Bool, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='0']/option-set-id", "0", SR_UINT32_T, true },
+ "pd-pool[pool-id='0']/option-set-id",
+ "0", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
"pd-pool[pool-id='0']/max-pd-space-utilization",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']", "", SR_LIST_T, false },
+ "pd-pool[pool-id='1']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/pool-id", "1", SR_UINT32_T, false },
+ "pd-pool[pool-id='1']/pool-id",
+ "1", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
"pd-pool[pool-id='1']/prefix",
- "2001:db8:2::/48", SR_STRING_T, true },
+ "2001:db8:2::/48", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/prefix-length", "48", SR_UINT8_T, true },
+ "pd-pool[pool-id='1']/prefix-length",
+ "48", libyang::LeafBaseType::Uint8, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/valid-lifetime", "4000", SR_UINT32_T, true },
+ "pd-pool[pool-id='1']/valid-lifetime",
+ "4000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
"pd-pool[pool-id='1']/preferred-lifetime",
- "3000", SR_UINT32_T, true },
+ "3000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/renew-time", "1000", SR_UINT32_T, true },
+ "pd-pool[pool-id='1']/renew-time",
+ "1000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/rebind-time", "2000", SR_UINT32_T, true },
+ "pd-pool[pool-id='1']/rebind-time",
+ "2000", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/rapid-commit", "false", SR_BOOL_T, true },
+ "pd-pool[pool-id='1']/rapid-commit",
+ "false", libyang::LeafBaseType::Bool, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
- "pd-pool[pool-id='1']/option-set-id", "0", SR_UINT32_T, true },
+ "pd-pool[pool-id='1']/option-set-id",
+ "0", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools/"
"pd-pool[pool-id='1']/max-pd-space-utilization",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
- "65535", SR_UINT16_T, false },
+ "65535", libyang::LeafBaseType::Uint16, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/address-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/pd-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='111']/host-reservations",
- "", SR_CONTAINER_T, false },
- { "/ietf-dhcpv6-server:server/server-config/serv-attributes",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage",
- "", SR_CONTAINER_T, false },
- { "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info",
- "", SR_CONTAINER_T, false },
- { "/ietf-dhcpv6-server:server/server-config/option-sets",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief A subnet with a pool and option data lists with
/// kea-dhcp4-server:config model.
const std::string subnetOptionsModelKeaDhcp4 = KEA_DHCP4_SERVER;
const YRTree subnetOptionsTreeKeaDhcp4 = YangRepr::buildTreeFromVector({
- { "/kea-dhcp4-server:config", "", SR_CONTAINER_T, false },
- { "/kea-dhcp4-server:config/subnet4[id='111']", "",
- SR_LIST_T, false },
+ { "/kea-dhcp4-server:config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/kea-dhcp4-server:config/subnet4[id='111']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/id",
- "111", SR_UINT32_T, false },
+ "111", libyang::LeafBaseType::Uint32, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
- "option-data[code='100'][space='dns']", "", SR_LIST_T, false },
+ "option-data[code='100'][space='dns']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"option-data[code='100'][space='dns']/code",
- "100", SR_UINT8_T, false },
+ "100", libyang::LeafBaseType::Uint8, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"option-data[code='100'][space='dns']/space",
- "dns", SR_STRING_T, false },
+ "dns", libyang::LeafBaseType::String, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"option-data[code='100'][space='dns']/data",
- "12121212", SR_STRING_T, true },
+ "12121212", libyang::LeafBaseType::String, true },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"option-data[code='100'][space='dns']/csv-format",
- "false", SR_BOOL_T, true },
+ "false", libyang::LeafBaseType::Bool, true },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"option-data[code='100'][space='dns']/always-send",
- "false", SR_BOOL_T, true },
+ "false", libyang::LeafBaseType::Bool, true },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"pool[start-address='10.0.1.0'][end-address='10.0.1.255']",
- "", SR_LIST_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"pool[start-address='10.0.1.0'][end-address='10.0.1.255']/start-address",
- "10.0.1.0", SR_STRING_T, false },
+ "10.0.1.0", libyang::LeafBaseType::String, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"pool[start-address='10.0.1.0'][end-address='10.0.1.255']/end-address",
- "10.0.1.255", SR_STRING_T, false },
+ "10.0.1.255", libyang::LeafBaseType::String, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/"
"pool[start-address='10.0.1.0'][end-address='10.0.1.255']/prefix",
- "10.0.1.0/24", SR_STRING_T, true },
+ "10.0.1.0/24", libyang::LeafBaseType::String, true },
{ "/kea-dhcp4-server:config/subnet4[id='111']/subnet",
- "10.0.0.0/8", SR_STRING_T, true },
+ "10.0.0.0/8", libyang::LeafBaseType::String, true },
{ "/kea-dhcp4-server:config/expired-leases-processing",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/dhcp-ddns",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/config-control",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/sanity-checks",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/interfaces-config",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/subnet4[id='111']/relay",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/compatibility",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/multi-threading",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief A subnet with a pool and option data lists with
/// kea-dhcp6-server:config model.
const std::string subnetOptionsModelKeaDhcp6 = KEA_DHCP6_SERVER;
const YRTree subnetOptionsTreeKeaDhcp6 = YangRepr::buildTreeFromVector({
- { "/kea-dhcp6-server:config", "", SR_CONTAINER_T, false },
- { "/kea-dhcp6-server:config/subnet6[id='111']", "",
- SR_LIST_T, false },
+ { "/kea-dhcp6-server:config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/kea-dhcp6-server:config/subnet6[id='111']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/id",
- "111", SR_UINT32_T, false },
+ "111", libyang::LeafBaseType::Uint32, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']",
- "", SR_LIST_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
- "start-address", "2001:db8::1:0", SR_STRING_T, false },
+ "start-address",
+ "2001:db8::1:0", libyang::LeafBaseType::String, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
- "end-address", "2001:db8::1:ffff", SR_STRING_T, false },
+ "end-address",
+ "2001:db8::1:ffff", libyang::LeafBaseType::String, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
- "prefix", "2001:db8::1:0/112", SR_STRING_T, true },
+ "prefix",
+ "2001:db8::1:0/112", libyang::LeafBaseType::String, true },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
"option-data[code='100'][space='dns']",
- "", SR_LIST_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
"option-data[code='100'][space='dns']/code",
- "100", SR_UINT16_T, false },
+ "100", libyang::LeafBaseType::Uint16, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
"option-data[code='100'][space='dns']/space",
- "dns", SR_STRING_T, false },
+ "dns", libyang::LeafBaseType::String, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
"option-data[code='100'][space='dns']/data",
- "12121212", SR_STRING_T, true },
+ "12121212", libyang::LeafBaseType::String, true },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
"option-data[code='100'][space='dns']/csv-format",
- "false", SR_BOOL_T, true },
+ "false", libyang::LeafBaseType::Bool, true },
{ "/kea-dhcp6-server:config/subnet6[id='111']/"
"pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/"
"option-data[code='100'][space='dns']/always-send",
- "false", SR_BOOL_T, true },
+ "false", libyang::LeafBaseType::Bool, true },
{ "/kea-dhcp6-server:config/subnet6[id='111']/subnet",
- "2001:db8::/48", SR_STRING_T, true },
+ "2001:db8::/48", libyang::LeafBaseType::String, true },
{ "/kea-dhcp6-server:config/expired-leases-processing",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/dhcp-ddns",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/config-control",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/sanity-checks",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/interfaces-config",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/subnet6[id='111']/relay",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/compatibility",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/multi-threading",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief Example from the design document.
const std::string designExampleModel = IETF_DHCPV6_SERVER;
const YRTree designExampleTree = YangRepr::buildTreeFromVector({
- { "/ietf-dhcpv6-server:server", "", SR_CONTAINER_PRESENCE_T, false },
- { "/ietf-dhcpv6-server:server/server-config", "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
+ { "/ietf-dhcpv6-server:server/server-config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
- "network-range[network-range-id='1']", "", SR_LIST_T, false },
+ "network-range[network-range-id='1']",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/network-range-id",
- "1", SR_UINT32_T, false },
+ "1", libyang::LeafBaseType::Uint32, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/network-description",
- "example", SR_STRING_T, true },
+ "example", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/pd-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']",
- "", SR_LIST_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']"
"/pool-id",
- "0", SR_UINT32_T, true },
+ "0", libyang::LeafBaseType::Uint32, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']"
"/prefix",
- "2001:db8:20:b00::/57", SR_STRING_T, true },
+ "2001:db8:20:b00::/57", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']"
"/prefix-length",
- "57", SR_UINT8_T, true },
+ "57", libyang::LeafBaseType::Uint8, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/pd-pools/"
"pd-pool[pool-id='0']/max-pd-space-utilization",
- "disabled", SR_ENUM_T, true },
+ "disabled", libyang::LeafBaseType::Enum, true },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/network-prefix",
- "2001:db8:20:b00::/56", SR_STRING_T, true },
+ "2001:db8:20:b00::/56", libyang::LeafBaseType::String, true },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
- "65535", SR_UINT16_T, false },
+ "65535", libyang::LeafBaseType::Uint16, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/host-reservations",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/option-sets",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/ietf-dhcpv6-server:server/server-config/network-ranges/"
"network-range[network-range-id='1']/address-pools",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
const YRTree emptyTreeKeaDhcp4 = YangRepr::buildTreeFromVector({
- { "/kea-dhcp4-server:config", "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/expired-leases-processing",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/dhcp-ddns",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/config-control",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/sanity-checks",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/interfaces-config",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/compatibility",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp4-server:config/multi-threading",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
const YRTree emptyTreeKeaDhcp6 = YangRepr::buildTreeFromVector({
- { "/kea-dhcp6-server:config", "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config",
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/expired-leases-processing",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/dhcp-ddns",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/config-control",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/sanity-checks",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/interfaces-config",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/compatibility",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
{ "/kea-dhcp6-server:config/multi-threading",
- "", SR_CONTAINER_T, false },
+ std::nullopt, libyang::LeafBaseType::Unknown, false },
});
/// @brief Set of example configurations.
diff --git a/src/lib/yang/testutils/translator_test.cc b/src/lib/yang/testutils/translator_test.cc
index 16fa33b82a..5d66631864 100644
--- a/src/lib/yang/testutils/translator_test.cc
+++ b/src/lib/yang/testutils/translator_test.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019,2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -14,94 +14,93 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
+
namespace isc {
namespace yang {
namespace test {
+LeafBaseType
+YangRepr::YangReprItem::getUnionType(Value const& value) {
+ static_assert(
+ std::is_same<
+ Value, std::variant<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t,
+ uint64_t, bool, Empty, Binary, string, optional<DataNode>,
+ Decimal64, vector<Bit>, Enum, IdentityRef>>::value,
+ "Value type has changed. The if statement needs to be adjusted to include all alternatives "
+ "of the std::variant.");
+
+ if (holds_alternative<int8_t>(value)) {
+ return LeafBaseType::Int8;
+ } else if (holds_alternative<int16_t>(value)) {
+ return LeafBaseType::Int16;
+ } else if (holds_alternative<int32_t>(value)) {
+ return LeafBaseType::Int32;
+ } else if (holds_alternative<int64_t>(value)) {
+ return LeafBaseType::Int64;
+ } else if (holds_alternative<uint8_t>(value)) {
+ return LeafBaseType::Uint8;
+ } else if (holds_alternative<uint16_t>(value)) {
+ return LeafBaseType::Uint16;
+ } else if (holds_alternative<uint32_t>(value)) {
+ return LeafBaseType::Uint32;
+ } else if (holds_alternative<uint64_t>(value)) {
+ return LeafBaseType::Uint64;
+ } else if (holds_alternative<bool>(value)) {
+ return LeafBaseType::Bool;
+ } else if (holds_alternative<Empty>(value)) {
+ return LeafBaseType::Empty;
+ } else if (holds_alternative<Binary>(value)) {
+ return LeafBaseType::Binary;
+ } else if (holds_alternative<string>(value)) {
+ return LeafBaseType::String;
+ } else if (holds_alternative<optional<DataNode>>(value)) {
+ return LeafBaseType::InstanceIdentifier;
+ } else if (holds_alternative<Decimal64>(value)) {
+ return LeafBaseType::Dec64;
+ } else if (holds_alternative<vector<Bit>>(value)) {
+ return LeafBaseType::Bits;
+ } else if (holds_alternative<Enum>(value)) {
+ return LeafBaseType::Enum;
+ } else if (holds_alternative<IdentityRef>(value)) {
+ return LeafBaseType::IdentityRef;
+ }
+ return LeafBaseType::Unknown;
+}
+
YangRepr::YangReprItem
-YangRepr::YangReprItem::get(const string& xpath, S_Session session) {
- string val_xpath = xpath;
- string value = "";
- sr_type_t type = SR_UNKNOWN_T;
+YangRepr::YangReprItem::get(const string& xpath, Session session) {
+ string val_xpath;
+ optional<string> value;
+ LeafBaseType type(LeafBaseType::Unknown);
bool settable = true;
try {
- S_Val s_val = session->get_item(xpath.c_str());
+ optional<DataNode> s_val(session.getData(xpath));
if (!s_val) {
isc_throw(BadValue, "YangReprItem failed at '" << xpath << "'");
}
- val_xpath = string(s_val->xpath());
- type = s_val->type();
- ostringstream num_value;
- switch (type) {
- case SR_CONTAINER_T:
- case SR_CONTAINER_PRESENCE_T:
+ s_val = s_val->findPath(xpath);
+ SchemaNode const& schema(s_val->schema());
+ NodeType const node_type(schema.nodeType());
+ if (node_type == NodeType::Leaf) {
+ type = schema.asLeaf().valueType().base();
+ } else if (node_type == NodeType::Leaflist) {
+ type = schema.asLeafList().valueType().base();
+ } else {
settable = false;
- break;
-
- case SR_LIST_T:
- break;
-
- case SR_STRING_T:
- value = s_val->data()->get_string();
- break;
-
- case SR_BOOL_T:
- value = s_val->data()->get_bool() ? "true" : "false";
- break;
-
- case SR_UINT8_T:
- num_value << static_cast<unsigned>(s_val->data()->get_uint8());
- value = num_value.str();
- break;
-
- case SR_UINT16_T:
- num_value << s_val->data()->get_uint16();
- value = num_value.str();
- break;
-
- case SR_UINT32_T:
- num_value << s_val->data()->get_uint32();
- value = num_value.str();
- break;
-
- case SR_INT8_T:
- num_value << static_cast<unsigned>(s_val->data()->get_int8());
- value = num_value.str();
- break;
-
- case SR_INT16_T:
- num_value << s_val->data()->get_int16();
- value = num_value.str();
- break;
-
- case SR_INT32_T:
- num_value << s_val->data()->get_int32();
- value = num_value.str();
- break;
-
- case SR_DECIMAL64_T:
- num_value << s_val->data()->get_decimal64();
- value = num_value.str();
- break;
-
- case SR_IDENTITYREF_T:
- value = s_val->data()->get_identityref();
- break;
-
- case SR_ENUM_T:
- value = s_val->data()->get_enum();
- break;
-
- case SR_BINARY_T:
- value = s_val->data()->get_binary();
- break;
-
- default:
- isc_throw(NotImplemented,
- "YangReprItem called with unsupported type: " << type);
}
- } catch (const sysrepo_exception& ex) {
+ if (type == LeafBaseType::Union) {
+ // Get the underlying type.
+ type = getUnionType(s_val->asTerm().value());
+ }
+ if (type == LeafBaseType::Leafref) {
+ // Get the underlying type.
+ type = s_val->schema().asLeaf().valueType().asLeafRef().resolvedType().base();
+ }
+ value = TranslatorBasic::value(TranslatorBasic::value(s_val), type);
+ val_xpath = string(s_val->path());
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error in YangReprItem: " << ex.what());
}
@@ -109,24 +108,24 @@ YangRepr::YangReprItem::get(const string& xpath, S_Session session) {
}
YangRepr::Tree
-YangRepr::get(S_Session session) const {
+YangRepr::get(Session session) const {
Tree result;
try {
TranslatorBasic tb(session, model_);
string const xpath0("/" + model_ + ":*//.");
- tb.forAll(xpath0, [&](libyang::S_Data_Node const& node) {
- string const& xpath(node->path());
+ tb.forAll(xpath0, [&](libyang::DataNode const& node) {
+ string const& xpath(node.path());
result.emplace(xpath, YangReprItem::get(xpath, session));
});
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
- "sysrepo error in YangRepr::getTree: " << ex.what());
+ "sysrepo error in YangRepr::getTree: " << ex.what());
}
return (result);
}
bool
-YangRepr::verify(const Tree& expected, S_Session session,
+YangRepr::verify(const Tree& expected, Session session,
ostream& errs) const {
bool result(true);
const Tree& received = get(session);
@@ -166,245 +165,101 @@ YangRepr::verify(const Tree& expected, S_Session session,
}
void
-YangRepr::set(const Tree& tree, S_Session session) const {
+YangRepr::set(const Tree& tree, Session session) const {
for (auto const& kv : tree) {
YangReprItem const& item(kv.second);
if (!item.settable_) {
continue;
}
try {
- S_Val s_val;
- switch (item.type_) {
- case SR_CONTAINER_T:
- case SR_CONTAINER_PRESENCE_T:
- isc_throw(NotImplemented,
- "YangRepr::set called for a container");
-
- case SR_LIST_T:
- isc_throw(NotImplemented,
- "YangRepr::set called for a list");
- break;
-
- case SR_STRING_T:
- case SR_IDENTITYREF_T:
- case SR_ENUM_T:
- case SR_BINARY_T:
- s_val.reset(new Val(item.value_.c_str(), item.type_));
- break;
-
- case SR_BOOL_T:
- if (item.value_ == "true") {
- s_val.reset(new Val(true, SR_BOOL_T));
- } else if (item.value_ == "false") {
- s_val.reset(new Val(false, SR_BOOL_T));
- } else {
- isc_throw(BadValue, "'" << item.value_ << "' not a bool");
- }
- break;
-
- case SR_UINT8_T:
- try {
- uint8_t u8 = boost::lexical_cast<unsigned>(item.value_);
- s_val.reset(new Val(u8));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not an uint8");
- }
- break;
-
- case SR_UINT16_T:
- try {
- uint16_t u16 = boost::lexical_cast<uint16_t>(item.value_);
- s_val.reset(new Val(u16));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not an uint16");
- }
- break;
-
- case SR_UINT32_T:
- try {
- uint32_t u32 = boost::lexical_cast<uint32_t>(item.value_);
- s_val.reset(new Val(u32));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not an uint32");
- }
- break;
-
- case SR_INT8_T:
- try {
- int8_t i8 = boost::lexical_cast<int>(item.value_);
- s_val.reset(new Val(i8));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not an int8");
- }
- break;
-
- case SR_INT16_T:
- try {
- int16_t i16 = boost::lexical_cast<int16_t>(item.value_);
- s_val.reset(new Val(i16));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not an int16");
- }
- break;
-
- case SR_INT32_T:
- try {
- int32_t i32 = boost::lexical_cast<int32_t>(item.value_);
- s_val.reset(new Val(i32));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not an int32");
- }
- break;
-
- case SR_DECIMAL64_T:
- try {
- double d64 = boost::lexical_cast<double>(item.value_);
- s_val.reset(new Val(d64));
- } catch (const boost::bad_lexical_cast&) {
- isc_throw(BadValue,
- "'" << item.value_ << "' not a real");
- }
- break;
-
- default:
- isc_throw(NotImplemented,
- "YangRepr::set called with unsupported type: "
- << item.type_);
+ Context const& context(session.getContext());
+ SchemaNode const& schema(context.findPath(item.xpath_));
+ NodeType const node_type(schema.nodeType());
+ bool is_key(false);
+ if (node_type == NodeType::Leaf) {
+ is_key = schema.asLeaf().isKey();
}
- session->set_item(item.xpath_.c_str(), s_val);
- } catch (const sysrepo_exception& ex) {
+ if (!is_key) {
+ session.setItem(item.xpath_, item.value_);
+ }
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error in YangRepr::set for " << item
<< ", error: " << ex.what());
}
}
- session->apply_changes();
-}
-
-bool
-YangRepr::validate(S_Session session, ostream& errs) const {
- try {
- // Try to validate. If it succeeds, then we're done here.
- session->validate();
- return (true);
- } catch (const std::exception& ex) {
- errs << "validate fails with " << ex.what() << endl;
- }
- try {
- // If we get here, it means the validate() threw exceptions.
- S_Errors errors(session->get_error());
- if (!errors) {
- // This is really weird. An exception was thrown, but
- // get_last_errors() didn't return anything. Maybe we're out of
- // memory or something?
- errs << "no errors" << endl;
- return (false);
- }
- size_t const count(errors->error_cnt());
- errs << "got " << count << " errors" << endl;
- for (size_t i = 0; i < count ; ++i) {
- const char* message(errors->message(i));
- const char* xpath(errors->xpath(i));
- if (!message || !xpath) {
- continue;
- }
- errs << message << " at " << xpath << endl;
- }
- } catch (const std::exception& ex) {
- errs << "double error " << ex.what();
- }
- return (false);
+ session.applyChanges();
}
ostream&
-operator<<(ostream& os, sr_type_t type) {
+operator<<(ostream& os, LeafBaseType type) {
switch (type) {
- case SR_CONTAINER_T:
- os << "container";
- break;
- case SR_CONTAINER_PRESENCE_T:
- os << "container presence";
- break;
- case SR_LIST_T:
- os << "list";
- break;
- case SR_STRING_T:
+ case LeafBaseType::String:
os << "string";
break;
- case SR_BOOL_T:
+ case LeafBaseType::Bool:
os << "bool";
break;
- case SR_UINT8_T:
+ case LeafBaseType::Uint8:
os << "uint8";
break;
- case SR_UINT16_T:
+ case LeafBaseType::Uint16:
os << "uint16";
break;
- case SR_UINT32_T:
+ case LeafBaseType::Uint32:
os << "uint32";
break;
- case SR_INT8_T:
+ case LeafBaseType::Int8:
os << "int8";
break;
- case SR_INT16_T:
+ case LeafBaseType::Int16:
os << "int16";
break;
- case SR_INT32_T:
+ case LeafBaseType::Int32:
os << "int32";
break;
- case SR_IDENTITYREF_T:
+ case LeafBaseType::IdentityRef:
os << "identity ref";
break;
- case SR_ENUM_T:
+ case LeafBaseType::Enum:
os << "enum";
break;
- case SR_BINARY_T:
+ case LeafBaseType::Binary:
os << "binary";
break;
- case SR_LEAF_EMPTY_T:
- os << "leaf empty";
- break;
- case SR_BITS_T:
+ case LeafBaseType::Bits:
os << "bits";
break;
- case SR_DECIMAL64_T:
+ case LeafBaseType::Dec64:
os << "decimal64";
break;
- case SR_INSTANCEID_T:
+ case LeafBaseType::InstanceIdentifier:
os << "instance id";
break;
- case SR_INT64_T:
+ case LeafBaseType::Int64:
os << "int64";
break;
- case SR_UINT64_T:
+ case LeafBaseType::Uint64:
os << "uint64";
break;
- case SR_ANYXML_T:
- os << "any xml";
+ case LeafBaseType::Union:
+ os << "union";
break;
- case SR_ANYDATA_T:
- os << "any data";
+ case LeafBaseType::Leafref:
+ os << "leafref";
break;
-#ifdef SR_UNION_T
- case SR_UNION_T:
- os << "union";
+ case LeafBaseType::Unknown:
+ os << "unknown";
break;
-#endif
default:
- os << type;
- break;
+ isc_throw(BadValue, "unsupported type " << int(type));
}
return (os);
}
ostream& operator<<(ostream& os, const YangRepr::YangReprItem& item) {
- os << item.xpath_ << " = (" << item.type_ << ") '" << item.value_ << "'";
+ os << item.xpath_ << " = (" << item.type_ << ") '" << (item.value_ ? *item.value_ : "nullopt")
+ << "'";
return (os);
}
diff --git a/src/lib/yang/testutils/translator_test.h b/src/lib/yang/testutils/translator_test.h
index b334fbd5f6..b49991d450 100644
--- a/src/lib/yang/testutils/translator_test.h
+++ b/src/lib/yang/testutils/translator_test.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -37,8 +37,8 @@ public:
/// @param value The textual value.
/// @param type The type of the value.
/// @param settable The settable flag.
- YangReprItem(std::string xpath, std::string value,
- sr_type_t type, bool settable)
+ YangReprItem(std::string xpath, std::optional<std::string> value,
+ libyang::LeafBaseType type, bool settable)
: xpath_(xpath), value_(value), type_(type), settable_(settable) {
}
@@ -48,16 +48,16 @@ public:
/// @param session Sysrepo session.
/// @return YangReprItem instance representing configuration parameter.
static YangReprItem get(const std::string& xpath,
- sysrepo::S_Session session);
+ sysrepo::Session session);
/// @brief The xpath.
std::string xpath_;
/// @brief The textual value.
- std::string value_;
+ std::optional<std::string> value_;
/// @brief The type of the value.
- sr_type_t type_;
+ libyang::LeafBaseType type_;
/// @brief The settable flag.
bool settable_;
@@ -79,7 +79,15 @@ public:
bool operator!=(const YangReprItem& other) const {
return (!(*this == other));
}
- };
+
+ private:
+ /// @brief Gets the underlying type behind a union node.
+ ///
+ /// @param value the value obtained from the union node with ->asTerm().value()
+ ///
+ /// @return the underylying type
+ static libyang::LeafBaseType getUnionType(libyang::Value const& value);
+ }; // YangReprItem
/// @brief Tree type.
///
@@ -92,7 +100,7 @@ public:
/// @brief Get tree from session.
///
/// @param session Sysrepo session.
- Tree get(sysrepo::S_Session session) const;
+ Tree get(sysrepo::Session session) const;
/// @brief Verifies a tree.
///
@@ -101,7 +109,7 @@ public:
/// @param errs Error stream.
/// @return true if verification succeeds, false with errors displayed.
/// on errs if it fails.
- bool verify(const Tree& expected, sysrepo::S_Session session,
+ bool verify(const Tree& expected, sysrepo::Session session,
std::ostream& errs) const;
/// @brief Sets specified tree in a sysrepo.
@@ -110,15 +118,7 @@ public:
///
/// @param tree The tree to install.
/// @param session Sysrepo session.
- void set(const Tree& tree, sysrepo::S_Session session) const;
-
- /// @brief Validate.
- ///
- /// @param session Sysrepo session.
- /// @param errs Error stream.
- /// @return True if validation succeeds, false with errors displayed
- /// on errs if it fails.
- bool validate(sysrepo::S_Session session, std::ostream& errs) const;
+ void set(const Tree& tree, sysrepo::Session session) const;
/// @brief Convenience function that indexes a collection of items by xpath.
///
@@ -128,11 +128,15 @@ public:
static Tree buildTreeFromVector(std::vector<YangReprItem> const& v) {
Tree tree;
for (YangReprItem const& item : v) {
+ if (tree.contains(item.xpath_)) {
+ isc_throw(BadValue, "YangRepr::buildTreeFromVector(): duplicate " << item.xpath_);
+ }
tree.emplace(item.xpath_, item);
}
return tree;
}
+private:
/// @brief The model name.
std::string model_;
};
@@ -143,8 +147,8 @@ typedef YangRepr::YangReprItem YRItem;
/// @brief Alias for Trees.
typedef YangRepr::Tree YRTree;
-/// @brief Overrides standard output operator for sr_type_t.
-std::ostream& operator<<(std::ostream& os, sr_type_t type);
+/// @brief Overrides standard output operator for LeafBaseType.
+std::ostream& operator<<(std::ostream& os, libyang::LeafBaseType type);
/// @brief Overrides standard output operator for @c YangReprItem object.
std::ostream& operator<<(std::ostream& os, const YRItem& item);
diff --git a/src/lib/yang/translator.cc b/src/lib/yang/translator.cc
index 9e38cfa3d7..86aa9d6cd2 100644
--- a/src/lib/yang/translator.cc
+++ b/src/lib/yang/translator.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019,2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,11 +8,15 @@
#include <yang/translator.h>
#include <util/encode/base64.h>
+
+#include <sysrepo-cpp/utils/exception.hpp>
+
#include <cstring>
using namespace std;
using namespace isc::data;
using namespace isc::util::encode;
+using namespace libyang;
using namespace sysrepo;
namespace {
@@ -38,7 +42,7 @@ string decode64(const string& input) {
namespace isc {
namespace yang {
-TranslatorBasic::TranslatorBasic(S_Session session, const string& model)
+TranslatorBasic::TranslatorBasic(Session session, const string& model)
: session_(session), model_(model) {
}
@@ -46,228 +50,131 @@ TranslatorBasic::~TranslatorBasic() {
}
ElementPtr
-TranslatorBasic::value(sysrepo::S_Val s_val) {
- if (!s_val) {
- isc_throw(BadValue, "value called with null");
- }
- switch (s_val->type()) {
- case SR_CONTAINER_T:
- case SR_CONTAINER_PRESENCE_T:
- // Internal node.
- return (ElementPtr());
-
- case SR_LIST_T:
- return (Element::createList());
-
- case SR_STRING_T:
- return (Element::create(string(s_val->data()->get_string())));
-
- case SR_BOOL_T:
- return (Element::create(s_val->data()->get_bool() ? true : false));
-
- case SR_UINT8_T:
- return (Element::create(static_cast<long long>(s_val->data()->get_uint8())));
-
- case SR_UINT16_T:
- return (Element::create(static_cast<long long>(s_val->data()->get_uint16())));
-
- case SR_UINT32_T:
- return (Element::create(static_cast<long long>(s_val->data()->get_uint32())));
-
- case SR_INT8_T:
- return (Element::create(static_cast<long long>(s_val->data()->get_int8())));
-
- case SR_INT16_T:
- return (Element::create(static_cast<long long>(s_val->data()->get_int16())));
-
- case SR_INT32_T:
- return (Element::create(static_cast<long long>(s_val->data()->get_int32())));
-
- case SR_DECIMAL64_T:
- return (Element::create(s_val->data()->get_decimal64()));
-
- case SR_IDENTITYREF_T:
- return (Element::create(string(s_val->data()->get_identityref())));
-
- case SR_ENUM_T:
- return (Element::create(string(s_val->data()->get_enum())));
-
- case SR_BINARY_T:
- return (Element::create(decode64(s_val->data()->get_binary())));
-
- default:
- isc_throw(NotImplemented,
- "value called with unsupported type: " << s_val->type());
+TranslatorBasic::value(optional<DataNode> data_node) {
+ NodeType const node_type(data_node->schema().nodeType());
+ if (node_type == NodeType::Leaf || node_type == NodeType::Leaflist) {
+ DataNodeTerm const& leaf(data_node->asTerm());
+ Value const& v(leaf.value());
+ if (holds_alternative<string>(v) ||
+ holds_alternative<Enum>(v) ||
+ holds_alternative<IdentityRef>(v)) {
+ // Should be a string. Call create(). Should be slightly faster
+ // than wrapping value in double quotes and calling fromJSON().
+ return Element::create(string(leaf.valueStr()));
+ } else if (holds_alternative<Binary>(v)) {
+ return Element::create(decode64(string(leaf.valueStr())));
+ } else {
+ // This can be various types so defer to fromJSON().
+ return Element::fromJSON(string(leaf.valueStr()));
+ }
}
+ return ElementPtr();
}
ElementPtr
TranslatorBasic::getItem(const string& xpath) {
- S_Val s_val;
+ // TODO: Remove this if convenient. It is not strictly required and only done to detect
+ // missing schema nodes and throw an exception to keep old behavior.
try {
- s_val = session_->get_item(xpath.c_str());
- } catch (const sysrepo_exception& ex) {
- if (std::string(ex.what()).find("Item not found") != string::npos) {
- // The YANG configuration node was not there.
- return nullptr;
- }
+ Context const& context(session_.getContext());
+ context.findPath(xpath);
+ } catch (libyang::Error const& ex) {
isc_throw(SysrepoError, "sysrepo error getting item at '" << xpath
<< "': " << ex.what());
}
- if (!s_val) {
- return (ElementPtr());
- }
- return (value(s_val));
-}
-ElementPtr
-TranslatorBasic::getItems(const string& xpath) {
- S_Vals s_vals(getValuesFromItems(xpath));
- if (!s_vals) {
- return (ElementPtr());
- }
- ElementPtr result(Element::createList());
try {
- for (size_t i = 0; i < s_vals->val_cnt(); ++i) {
- S_Val s_val = s_vals->val(i);
- result->add(value(s_val));
- }
- } catch (const sysrepo_exception& ex) {
- isc_throw(SysrepoError, "sysrepo error getting item at '"
- << xpath << "': " << ex.what());
- }
- return (result);
-}
-
-S_Val
-TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) {
- if (!elem) {
- isc_throw(BadValue, "value called with null");
- }
- S_Val s_val;
- switch (type) {
- case SR_CONTAINER_T:
- case SR_CONTAINER_PRESENCE_T:
- isc_throw(NotImplemented, "value called for a container");
-
- case SR_LIST_T:
- if (elem->getType() != Element::list) {
- isc_throw(BadValue, "value for a list called with not a list: "
- << elem->str());
- }
- // Return null.
- break;
-
- case SR_STRING_T:
- case SR_IDENTITYREF_T:
- case SR_ENUM_T:
- if (elem->getType() != Element::string) {
- isc_throw(BadValue,
- "value for a string called with not a string: "
- << elem->str());
- }
- s_val.reset(new Val(elem->stringValue().c_str(), type));
- break;
-
- case SR_BOOL_T:
- if (elem->getType() != Element::boolean) {
- isc_throw(BadValue,
- "value for a boolean called with not a boolean: "
- << elem->str());
- }
- s_val.reset(new Val(elem->boolValue(), type));
- break;
-
- case SR_UINT8_T:
- if (elem->getType() != Element::integer) {
- isc_throw(BadValue,
- "value for an integer called with not an integer: "
- << elem->str());
- }
- s_val.reset(new Val(elem->intValue(), type));
- break;
-
- case SR_UINT16_T:
- if (elem->getType() != Element::integer) {
- isc_throw(BadValue,
- "value for an integer called with not an integer: "
- << elem->str());
- }
- s_val.reset(new Val(elem->intValue(), type));
- break;
-
- case SR_UINT32_T:
- if (elem->getType() != Element::integer) {
- isc_throw(BadValue,
- "value for an integer called with not an integer: "
- << elem->str());
+ optional<DataNode> const& s_val(session_.getData(xpath));
+ if (!s_val) {
+ // TODO:
+ // isc_throw(SysrepoError, "no data at '" << xpath << "'");
+ return ElementPtr();
}
- s_val.reset(new Val(elem->intValue(), type));
- break;
-
- case SR_INT8_T:
- if (elem->getType() != Element::integer) {
- isc_throw(BadValue,
- "value for an integer called with not an integer: "
- << elem->str());
+ Set<DataNode> const& nodes(s_val->findXPath(xpath));
+ DataNode const& front(nodes.front());
+ NodeType const node_type(front.schema().nodeType());
+
+ // Leaf-list
+ if (node_type == NodeType::Leaflist) {
+ ElementPtr result(Element::createList());
+ for (DataNode const& i : nodes) {
+ result->add(value(i));
+ }
+ return result;
+ } else if (node_type == NodeType::Container) {
+ // TODO:
+ // isc_throw(SysrepoError, "getting containers not supported, xpath is '" << xpath << "'");
+ return ElementPtr();
+ } else if (node_type == NodeType::List) {
+ // TODO:
+ // isc_throw(SysrepoError, "getting lists not supported, xpath is '" << xpath << "'");
+ return ElementPtr();
}
- s_val.reset(new Val(elem->intValue(), type));
- break;
- case SR_INT16_T:
- if (elem->getType() != Element::integer) {
- isc_throw(BadValue,
- "value for an integer called with not an integer: "
- << elem->str());
- }
- s_val.reset(new Val(elem->intValue(), type));
- break;
+ // Leaf
+ return value(front);
- case SR_INT32_T:
- if (elem->getType() != Element::integer) {
- isc_throw(BadValue,
- "value for an integer called with not an integer: "
- << elem->str());
- }
- s_val.reset(new Val(elem->intValue(), type));
- break;
+ } catch (sysrepo::Error const& ex) {
+ isc_throw(SysrepoError, "sysrepo error getting item at '" << xpath
+ << "': " << ex.what());
+ }
+}
- case SR_DECIMAL64_T:
- if (elem->getType() != Element::real) {
- isc_throw(BadValue, "value for a real called with not a real");
- }
- s_val.reset(new Val(elem->doubleValue()));
- break;
+ElementPtr
+TranslatorBasic::getItems(const string& xpath) {
+ return getItem(xpath);
+}
- case SR_BINARY_T:
- if (elem->getType() != Element::string) {
- isc_throw(BadValue,
- "value for a base64 called with not a string: "
- << elem->str());
+optional<string>
+TranslatorBasic::value(ConstElementPtr const& element,
+ LeafBaseType const type) {
+ if (!element) {
+ // A null ElementPtr is how we signal that this item requires no value.
+ // Useful when setting YANG lists which is the only way to set their
+ // keys in sysrepo since setting the key itself results in an error.
+ return std::nullopt;
+ } else if (element->getType() == Element::map) {
+ // TODO: implement
+ isc_throw(NotImplemented, "TranslatorBasic::value(): map element");
+ } else if (element->getType() == Element::list) {
+ // TODO: implement
+ isc_throw(NotImplemented, "TranslatorBasic::value(): list element");
+ }
+ if (type == LeafBaseType::Enum ||
+ type == LeafBaseType::String ||
+ type == LeafBaseType::Union ||
+ type == LeafBaseType::IdentityRef) {
+ // These types are usually strings in ElementPtr, but are accepted
+ // without the double quotes in sysrepo, so get the stringValue().
+ if (element->getType() == Element::string) {
+ return element->stringValue();
+ } else {
+ // Except for some nodes which are maps e.g. user-context. And also Unions and
+ // IdentityRefs can very well have underlying types that are different than strings.
+ // Use the generic str() for those.
+ return element->str();
}
- s_val.reset(new Val(encode64(elem->stringValue()).c_str(), type));
- break;
-
- default:
- isc_throw(NotImplemented,
- "value called with unsupported type: " << type);
+ } else if (type == LeafBaseType::Binary) {
+ return encode64(element->stringValue());
+ } else {
+ // The rest of YANG values can be expressed using the
+ // general string representation of ElementPtr.
+ return element->str();
}
-
- return (s_val);
}
void
TranslatorBasic::setItem(const string& xpath, ConstElementPtr elem,
- sr_type_t type) {
- S_Val s_val = value(elem, type);
+ LeafBaseType type) {
+ optional<string> const s_val(value(elem, type));
try {
- session_->set_item(xpath.c_str(), s_val);
- } catch (const sysrepo_exception& ex) {
+ session_.setItem(xpath, s_val);
+ } catch (sysrepo::Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting item '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
}
- session_->apply_changes();
+ session_.applyChanges();
}
void
@@ -283,7 +190,7 @@ TranslatorBasic::checkAndGetLeaf(ElementPtr& storage,
void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from,
string const& xpath,
string const& name,
- sr_type_t const type) {
+ LeafBaseType const type) {
ConstElementPtr const& x(from->get(name));
if (x) {
setItem(xpath + "/" + name, x, type);
@@ -292,26 +199,26 @@ void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from,
void
TranslatorBasic::delItem(const std::string& xpath) {
+ // TODO: Remove this if convenient. It is not strictly required and only done to detect
+ // missing schema nodes and throw an exception to keep old behavior.
+ try {
+ Context const& context(session_.getContext());
+ context.findPath(xpath);
+ } catch (libyang::Error const& ex) {
+ isc_throw(SysrepoError, "sysrepo error getting item at '" << xpath
+ << "': " << ex.what());
+ }
+
try {
- session_->delete_item(xpath.c_str());
- } catch (const sysrepo_exception& ex) {
- if (std::string(ex.what()).find("Invalid argument") != string::npos) {
- // The YANG configuration node was not there.
- return;
+ if (session_.getData(xpath)) {
+ session_.deleteItem(xpath);
}
+ } catch (sysrepo::Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error deleting item at '"
<< xpath << "': " << ex.what());
}
- session_->apply_changes();
-}
-
-S_Vals TranslatorBasic::getValuesFromItems(std::string const& xpath) {
- try {
- return session_->get_items(xpath.c_str());
- } catch (sysrepo::sysrepo_exception const& exception) {
- isc_throw(SysrepoError, "sysrepo error getting items: " << exception.what());
- }
+ session_.applyChanges();
}
} // namespace yang
diff --git a/src/lib/yang/translator.h b/src/lib/yang/translator.h
index 838e2d6c7d..6cf521578d 100644
--- a/src/lib/yang/translator.h
+++ b/src/lib/yang/translator.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -10,6 +10,7 @@
#include <cc/data.h>
#include <yang/sysrepo_error.h>
+#include <sysrepo-cpp/Connection.hpp>
#include <sysrepo-cpp/Session.hpp>
namespace isc {
@@ -22,7 +23,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name (used and shared by derived classes).
- TranslatorBasic(sysrepo::S_Session session, const std::string& model);
+ TranslatorBasic(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorBasic();
@@ -34,7 +35,7 @@ public:
/// @param s_val The value.
/// @return The Element representing the sysrepo value.
/// @throw NotImplemented when the value type is not supported.
- static isc::data::ElementPtr value(sysrepo::S_Val s_val);
+ static isc::data::ElementPtr value(std::optional<libyang::DataNode> s_val);
/// @brief Get and translate basic value from YANG to JSON.
///
@@ -66,22 +67,14 @@ public:
const std::string& xpath,
const std::string& name);
- /// @brief Get the values of all siblings at a certain xpath.
- ///
- /// @param xpath the xpath to the element to be retrieved from, usually a
- /// list
- ///
- /// @return all the entries populated with values
- sysrepo::S_Vals getValuesFromItems(std::string const& xpath);
-
/// @brief Translate basic value from JSON to YANG.
///
/// @note Please don't use this outside tests.
///
/// @param elem The JSON element.
/// @param type The sysrepo type.
- static sysrepo::S_Val value(isc::data::ConstElementPtr elem,
- sr_type_t type);
+ static std::optional<std::string> value(isc::data::ConstElementPtr const& elem,
+ libyang::LeafBaseType const type);
/// @brief Translate and set basic value from JSON to YANG.
///
@@ -89,7 +82,7 @@ public:
/// @param elem The JSON element.
/// @param type The sysrepo type.
void setItem(const std::string& xpath, isc::data::ConstElementPtr elem,
- sr_type_t type);
+ libyang::LeafBaseType type);
/// @brief Get an element from given ElementPtr node and set it in sysrepo
@@ -103,7 +96,7 @@ public:
void checkAndSetLeaf(isc::data::ConstElementPtr const& from,
std::string const& xpath,
std::string const& name,
- sr_type_t const type);
+ libyang::LeafBaseType const type);
/// @brief Delete basic value from YANG.
@@ -120,13 +113,13 @@ public:
/// descendant
template <typename functor_t>
void forAll(std::string const& xpath, functor_t f) {
- libyang::S_Data_Node data_node(session_->get_data(xpath.c_str()));
+ std::optional<libyang::DataNode> const& data_node(session_.getData(xpath));
if (!data_node) {
return;
}
- for (libyang::S_Data_Node& root : data_node->tree_for()) {
- for (libyang::S_Data_Node const& n : root->tree_dfs()) {
+ for (libyang::DataNode const& sibling : data_node->siblings()) {
+ for (libyang::DataNode const& n : sibling.childrenDfs()) {
f(n);
}
}
@@ -147,25 +140,29 @@ public:
isc::data::ElementPtr getList(std::string const& xpath,
T& t,
isc::data::ElementPtr (T::*f)(std::string const& xpath)) {
- isc::data::ElementPtr result;
- sysrepo::S_Vals values(getValuesFromItems(xpath));
- if (values) {
- for (size_t i(0); i < values->val_cnt(); ++i) {
- isc::data::ElementPtr x((t.*f)(values->val(i)->xpath()));
- if (x) {
- if (!result) {
- result = isc::data::Element::createList();
- }
- result->add(x);
- }
+ try {
+ std::optional<libyang::DataNode> const& tree(session_.getData(xpath));
+ if (!tree) {
+ return (isc::data::ElementPtr());
+ }
+ libyang::Set<libyang::DataNode> const& s_vals(tree->findXPath(xpath));
+ if (s_vals.empty()) {
+ return (isc::data::ElementPtr());
+ }
+ isc::data::ElementPtr const result(isc::data::Element::createList());
+ for (libyang::DataNode const& i : s_vals) {
+ result->add((t.*f)(i.path()));
}
+ return result;
+ } catch (libyang::Error const& ex) {
+ isc_throw(SysrepoError, "sysrepo error getting item at '"
+ << xpath << "': " << ex.what());
}
- return result;
}
protected:
/// @brief The sysrepo session.
- sysrepo::S_Session session_;
+ sysrepo::Session session_;
/// @brief The model.
std::string model_;
diff --git a/src/lib/yang/translator_class.cc b/src/lib/yang/translator_class.cc
index 0bfddf36c2..c8164de0ee 100644
--- a/src/lib/yang/translator_class.cc
+++ b/src/lib/yang/translator_class.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorClass::TranslatorClass(S_Session session, const string& model)
+TranslatorClass::TranslatorClass(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -36,7 +37,7 @@ TranslatorClass::getClass(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getClassKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting client class at '" << xpath
<< "': " << ex.what());
@@ -108,7 +109,7 @@ TranslatorClass::setClass(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setClass not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting client class '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -117,66 +118,54 @@ TranslatorClass::setClass(const string& xpath, ConstElementPtr elem) {
void
TranslatorClass::setClassKea(const string& xpath, ConstElementPtr elem) {
- bool created = false;
- // Skip key name.
+ // Keys are set by setting the list itself.
+ setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
+
ConstElementPtr test = elem->get("test");
if (test) {
- setItem(xpath + "/test", test, SR_STRING_T);
- created = true;
+ setItem(xpath + "/test", test, LeafBaseType::String);
}
ConstElementPtr required = elem->get("only-if-required");
if (required) {
- setItem(xpath + "/only-if-required", required, SR_BOOL_T);
- created = true;
+ setItem(xpath + "/only-if-required", required, LeafBaseType::Bool);
}
ConstElementPtr options = elem->get("option-data");
if (options) {
setOptionDataList(xpath, options);
- created = true;
}
- checkAndSetLeaf(elem, xpath, "valid-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "min-valid-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "max-valid-lifetime", SR_UINT32_T);
+ 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) {
ConstElementPtr defs = elem->get("option-def");
if (defs) {
setOptionDefList(xpath, defs);
- created = true;
}
ConstElementPtr next = elem->get("next-server");
if (next) {
- setItem(xpath + "/next-server", next, SR_STRING_T);
- created = true;
+ setItem(xpath + "/next-server", next, LeafBaseType::String);
}
ConstElementPtr hostname = elem->get("server-hostname");
if (hostname) {
- setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
- created = true;
+ setItem(xpath + "/server-hostname", hostname, LeafBaseType::String);
}
ConstElementPtr boot = elem->get("boot-file-name");
if (boot) {
- setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
- created = true;
+ setItem(xpath + "/boot-file-name", boot, LeafBaseType::String);
}
} else if (model_ == KEA_DHCP6_SERVER) {
- checkAndSetLeaf(elem, xpath, "preferred-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", SR_UINT32_T);
+ checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
- created = true;
- }
- // There is no mandatory fields outside the key so force creation.
- if (!created) {
- ConstElementPtr list = Element::createList();
- setItem(xpath, list, SR_LIST_T);
+ LeafBaseType::String);
}
}
-TranslatorClasses::TranslatorClasses(S_Session session, const string& model)
+TranslatorClasses::TranslatorClasses(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -195,7 +184,7 @@ TranslatorClasses::getClasses(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getClassesKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting client classes at '" << xpath
<< "': " << ex.what());
@@ -220,7 +209,7 @@ TranslatorClasses::setClasses(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setClasses not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting client classes '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_class.h b/src/lib/yang/translator_class.h
index ca2f9cb703..eb8fe43172 100644
--- a/src/lib/yang/translator_class.h
+++ b/src/lib/yang/translator_class.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018,2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -81,7 +81,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorClass(sysrepo::S_Session session, const std::string& model);
+ TranslatorClass(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorClass();
@@ -127,7 +127,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorClasses(sysrepo::S_Session session, const std::string& model);
+ TranslatorClasses(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorClasses();
diff --git a/src/lib/yang/translator_config.cc b/src/lib/yang/translator_config.cc
index fcb60546a8..0d75847915 100644
--- a/src/lib/yang/translator_config.cc
+++ b/src/lib/yang/translator_config.cc
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorConfig::TranslatorConfig(S_Session session, const string& model)
+TranslatorConfig::TranslatorConfig(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorControlSocket(session, model),
TranslatorDatabase(session, model),
@@ -56,7 +57,7 @@ TranslatorConfig::getConfig() {
} else if (model_ == KEA_DHCP6_SERVER) {
return (getConfigKea6());
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError, "sysrepo error getting config: " << ex.what());
}
isc_throw(NotImplemented,
@@ -443,7 +444,7 @@ TranslatorConfig::setConfig(ConstElementPtr elem) {
isc_throw(NotImplemented,
"setConfig not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting config '" << elem->str()
<< "': " << ex.what());
@@ -493,15 +494,15 @@ TranslatorConfig::setConfigKea6(ConstElementPtr elem) {
void
TranslatorConfig::setServerKeaDhcpCommon(const string& xpath,
ConstElementPtr elem) {
- checkAndSetLeaf(elem, xpath, "valid-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "min-valid-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "max-valid-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "renew-timer", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "rebind-timer", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "calculate-tee-times", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "t1-percent", SR_DECIMAL64_T);
- checkAndSetLeaf(elem, xpath, "t2-percent", SR_DECIMAL64_T);
- checkAndSetLeaf(elem, xpath, "decline-probation-period", SR_UINT32_T);
+ checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "calculate-tee-times", 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);
@@ -529,7 +530,7 @@ TranslatorConfig::setServerKeaDhcpCommon(const string& xpath,
ConstElementPtr host_ids = elem->get("host-reservation-identifiers");
if (host_ids) {
for (ConstElementPtr id : host_ids->listValue()) {
- setItem(xpath + "/host-reservation-identifiers", id, SR_ENUM_T);
+ setItem(xpath + "/host-reservation-identifiers", id, LeafBaseType::Enum);
}
}
ConstElementPtr defs = elem->get("option-def");
@@ -550,121 +551,119 @@ TranslatorConfig::setServerKeaDhcpCommon(const string& 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()),
- SR_STRING_T);
- } else {
- ConstElementPtr list = Element::createList();
- setItem(hook_lib.str(), list, SR_LIST_T);
+ LeafBaseType::String);
}
}
}
ConstElementPtr expired = elem->get("expired-leases-processing");
if (expired) {
string expired_xpath = xpath + "/expired-leases-processing";
- checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", SR_UINT32_T);
- checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", SR_UINT32_T);
- checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", SR_UINT32_T);
- checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", SR_UINT32_T);
- checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", SR_UINT32_T);
- checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", SR_UINT32_T);
- }
- checkAndSetLeaf(elem, xpath, "dhcp4o6-port", SR_UINT16_T);
+ 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", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "hostname-char-replacement", SR_STRING_T);
+ 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", SR_BOOL_T);
- checkAndSetLeaf(ddns, ddns_xpath, "qualifying-suffix", SR_STRING_T);
- checkAndSetLeaf(ddns, ddns_xpath, "server-ip", SR_STRING_T);
- checkAndSetLeaf(ddns, ddns_xpath, "server-port", SR_UINT16_T);
- checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", SR_STRING_T);
- checkAndSetLeaf(ddns, ddns_xpath, "sender-port", SR_UINT16_T);
- checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", SR_UINT32_T);
- checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", SR_ENUM_T);
- checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", SR_ENUM_T);
- checkAndSetLeaf(ddns, ddns_xpath, "override-no-update", SR_BOOL_T);
- checkAndSetLeaf(ddns, ddns_xpath, "override-client-update", SR_BOOL_T);
- checkAndSetLeaf(ddns, ddns_xpath, "replace-client-name", SR_ENUM_T);
- checkAndSetLeaf(ddns, ddns_xpath, "generated-prefix", SR_STRING_T);
- checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-set", SR_STRING_T);
- checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-replacement", SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/user-context", repr, LeafBaseType::String);
}
ConstElementPtr sanity = elem->get("sanity-checks");
if (sanity) {
- checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", SR_ENUM_T);
+ checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum);
}
- checkAndSetLeaf(elem, xpath, "reservation-mode", SR_ENUM_T);
+ 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", SR_UINT32_T);
+ checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32);
databases = config_ctrl->get("config-databases");
if (databases && !databases->empty()) {
setDatabases(xpath + "/config-control/config-database", databases);
}
}
- checkAndSetLeaf(elem, xpath, "server-tag", SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/dhcp-queue-control", repr, LeafBaseType::String);
}
ConstElementPtr loggers = elem->get("loggers");
if (loggers) {
setLoggers(xpath, loggers);
}
- checkAndSetLeaf(elem, xpath, "cache-max-age", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "cache-threshold", SR_DECIMAL64_T);
+ 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", SR_BOOL_T);
- }
- checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-override-client-update", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-override-no-update", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-send-updates", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ip-reservations-unique", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-lookup-first", SR_BOOL_T);
+ 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";
- checkAndSetLeaf(multi_threading, mt_xpath, "enable-multi-threading", SR_BOOL_T);
- checkAndSetLeaf(multi_threading, mt_xpath, "packet-queue-size", SR_UINT32_T);
- checkAndSetLeaf(multi_threading, mt_xpath, "thread-pool-size", SR_UINT32_T);
- }
- checkAndSetLeaf(elem, xpath, "parked-packet-limit", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "reservations-global", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-in-subnet", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "store-extended-info", SR_BOOL_T);
+ 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);
}
void
@@ -681,38 +680,38 @@ TranslatorConfig::setServerKeaDhcp4(ConstElementPtr elem) {
if (ifs && !ifs->empty()) {
for (ConstElementPtr intf : ifs->listValue()) {
setItem(xpath + "/interfaces-config/interfaces",
- intf, SR_STRING_T);
+ intf, LeafBaseType::String);
}
}
string if_cfg_xpath = xpath + "/interfaces-config";
- checkAndSetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type", SR_ENUM_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "outbound-interface", SR_ENUM_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", SR_BOOL_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", SR_UINT32_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", SR_UINT32_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", SR_BOOL_T);
+ 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-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()), SR_STRING_T);
+ Element::create(context->str()), LeafBaseType::String);
}
}
- checkAndSetLeaf(elem, xpath, "echo-client-id", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "match-client-id", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "next-server", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "server-hostname", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "boot-file-name", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "authoritative", SR_BOOL_T);
+ 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", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "preferred-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", SR_UINT32_T);
+ 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);
@@ -723,45 +722,45 @@ TranslatorConfig::setServerKeaDhcp6(ConstElementPtr elem) {
if (ifs && !ifs->empty()) {
for (ConstElementPtr intf : ifs->listValue()) {
setItem(xpath + "/interfaces-config/interfaces",
- intf, SR_STRING_T);
+ intf, LeafBaseType::String);
}
}
string if_cfg_xpath = xpath + "/interfaces-config";
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", SR_BOOL_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", SR_UINT32_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", SR_UINT32_T);
- checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", SR_BOOL_T);
+ 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-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()), SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/mac-sources", source, LeafBaseType::String);
}
}
ConstElementPtr server_id = elem->get("server-id");
if (server_id) {
string srv_id_xpath = xpath + "/server-id";
- checkAndSetLeaf(server_id, srv_id_xpath, "type", SR_ENUM_T);
- checkAndSetLeaf(server_id, srv_id_xpath, "identifier", SR_STRING_T);
- checkAndSetLeaf(server_id, srv_id_xpath, "time", SR_UINT32_T);
- checkAndSetLeaf(server_id, srv_id_xpath, "htype", SR_UINT16_T);
- checkAndSetLeaf(server_id, srv_id_xpath, "enterprise-id", SR_UINT32_T);
- checkAndSetLeaf(server_id, srv_id_xpath, "persist", SR_BOOL_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/server-id/user-context", repr, LeafBaseType::String);
}
}
}
diff --git a/src/lib/yang/translator_config.h b/src/lib/yang/translator_config.h
index 5a45c65880..888508ce5e 100644
--- a/src/lib/yang/translator_config.h
+++ b/src/lib/yang/translator_config.h
@@ -413,7 +413,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorConfig(sysrepo::S_Session session, const std::string& model);
+ TranslatorConfig(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorConfig();
diff --git a/src/lib/yang/translator_control_socket.cc b/src/lib/yang/translator_control_socket.cc
index 4a685ce878..78aabdd2e0 100644
--- a/src/lib/yang/translator_control_socket.cc
+++ b/src/lib/yang/translator_control_socket.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorControlSocket::TranslatorControlSocket(S_Session session,
+TranslatorControlSocket::TranslatorControlSocket(Session session,
const string& model)
: TranslatorBasic(session, model) {
}
@@ -35,7 +36,7 @@ TranslatorControlSocket::getControlSocket(const string& xpath) {
(model_ == KEA_CTRL_AGENT)) {
return (getControlSocketKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting control socket at '" << xpath
<< "': " << ex.what());
@@ -76,7 +77,7 @@ TranslatorControlSocket::setControlSocket(const string& xpath,
"setControlSocket not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting control socket '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -98,12 +99,12 @@ TranslatorControlSocket::setControlSocketKea(const string& xpath,
if (!type) {
isc_throw(BadValue, "setControlSocket missing socket type");
}
- setItem(xpath + "/socket-name", name, SR_STRING_T);
- setItem(xpath + "/socket-type", type, SR_ENUM_T);
+ 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()),
- SR_STRING_T);
+ LeafBaseType::String);
}
}
diff --git a/src/lib/yang/translator_control_socket.h b/src/lib/yang/translator_control_socket.h
index 6af0430c09..4aaffa71a4 100644
--- a/src/lib/yang/translator_control_socket.h
+++ b/src/lib/yang/translator_control_socket.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -73,7 +73,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorControlSocket(sysrepo::S_Session session,
+ TranslatorControlSocket(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
diff --git a/src/lib/yang/translator_database.cc b/src/lib/yang/translator_database.cc
index 1536dd7a8c..50d80934de 100644
--- a/src/lib/yang/translator_database.cc
+++ b/src/lib/yang/translator_database.cc
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorDatabase::TranslatorDatabase(S_Session session, const string& model)
+TranslatorDatabase::TranslatorDatabase(Session session, const string& model)
: TranslatorBasic(session, model) {
}
@@ -32,7 +33,7 @@ TranslatorDatabase::getDatabase(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getDatabaseKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting database access at '" << xpath
<< "': " << ex.what());
@@ -85,7 +86,7 @@ TranslatorDatabase::setDatabase(const string& xpath,
isc_throw(NotImplemented,
"setDatabase not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting database access '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -106,33 +107,33 @@ TranslatorDatabase::setDatabaseKea(const string& xpath,
isc_throw(BadValue, "setDatabase requires database type: "
<< elem->str());
}
- setItem(xpath + "/database-type", type, SR_STRING_T);
+ setItem(xpath + "/database-type", type, LeafBaseType::String);
}
- checkAndSetLeaf(elem, xpath, "user", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "password", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "host", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "name", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "persist", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "port", SR_UINT16_T);
- checkAndSetLeaf(elem, xpath, "lfc-interval", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "readonly", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "trust-anchor", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "cert-file", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "key-file", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "cipher-list", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "connect-timeout", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "max-reconnect-tries", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "reconnect-wait-time", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "max-row-errors", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "on-fail", SR_STRING_T);
+ checkAndSetLeaf(elem, xpath, "user", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "password", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "host", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "name", 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()),
- SR_STRING_T);
+ LeafBaseType::String);
}
}
-TranslatorDatabases::TranslatorDatabases(S_Session session,
+TranslatorDatabases::TranslatorDatabases(Session session,
const string& model)
: TranslatorBasic(session, model),
TranslatorDatabase(session, model) {
@@ -148,7 +149,7 @@ TranslatorDatabases::getDatabases(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getDatabasesKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting database accesses at '" << xpath
<< "': " << ex.what());
@@ -174,7 +175,7 @@ TranslatorDatabases::setDatabases(const string& xpath, ConstElementPtr elem) {
"setDatabases not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting database accesses '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_database.h b/src/lib/yang/translator_database.h
index f1aa566fb2..6ef11cbd83 100644
--- a/src/lib/yang/translator_database.h
+++ b/src/lib/yang/translator_database.h
@@ -108,7 +108,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorDatabase(sysrepo::S_Session session, const std::string& model);
+ TranslatorDatabase(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorDatabase();
@@ -161,7 +161,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorDatabases(sysrepo::S_Session session, const std::string& model);
+ TranslatorDatabases(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorDatabases();
@@ -186,7 +186,7 @@ protected:
/// @brief getDatabases JSON for kea-dhcp[46]-server models.
///
/// @param xpath The xpath of databases including the list name.
- /// @return JSON representation of databases.
+ /// @return JSON representation of databases.
/// @throw SysrepoError when sysrepo raises an error.
isc::data::ElementPtr getDatabasesKea(const std::string& xpath);
diff --git a/src/lib/yang/translator_host.cc b/src/lib/yang/translator_host.cc
index f9e0d11a48..a9463b14c1 100644
--- a/src/lib/yang/translator_host.cc
+++ b/src/lib/yang/translator_host.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorHost::TranslatorHost(S_Session session, const string& model)
+TranslatorHost::TranslatorHost(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model) {
@@ -34,7 +35,7 @@ ElementPtr
(model_ == KEA_DHCP6_SERVER)) {
return (getHostKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting host reservation at '" << xpath
<< "': " << ex.what());
@@ -111,7 +112,7 @@ TranslatorHost::setHost(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setHost not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting host reservation '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -123,24 +124,24 @@ TranslatorHost::setHostKea(const string& xpath, ConstElementPtr elem) {
ConstElementPtr hostname = elem->get("hostname");
// Skip identifier and identifier type as they are keys.
if (hostname) {
- setItem(xpath + "/hostname", hostname, SR_STRING_T);
+ setItem(xpath + "/hostname", hostname, LeafBaseType::String);
}
if (model_ == KEA_DHCP4_SERVER) {
ConstElementPtr address = elem->get("ip-address");
if (address) {
- setItem(xpath + "/ip-address", address, SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/prefixes", prefix, LeafBaseType::String);
}
}
}
@@ -151,7 +152,7 @@ TranslatorHost::setHostKea(const string& xpath, ConstElementPtr elem) {
ConstElementPtr classes = elem->get("client-classes");
if (classes && (classes->size() > 0)) {
for (ConstElementPtr cclass : classes->listValue()) {
- setItem(xpath + "/client-classes", cclass, SR_STRING_T);
+ setItem(xpath + "/client-classes", cclass, LeafBaseType::String);
}
}
@@ -159,15 +160,15 @@ TranslatorHost::setHostKea(const string& xpath, ConstElementPtr elem) {
if (model_ == KEA_DHCP4_SERVER) {
ConstElementPtr next = elem->get("next-server");
if (next) {
- setItem(xpath + "/next-server", next, SR_STRING_T);
+ setItem(xpath + "/next-server", next, LeafBaseType::String);
}
ConstElementPtr server_hostname = elem->get("server-hostname");
if (server_hostname) {
- setItem(xpath + "/server-hostname", server_hostname, SR_STRING_T);
+ setItem(xpath + "/server-hostname", server_hostname, LeafBaseType::String);
}
ConstElementPtr boot = elem->get("boot-file-name");
if (boot) {
- setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ setItem(xpath + "/boot-file-name", boot, LeafBaseType::String);
}
}
@@ -175,11 +176,11 @@ TranslatorHost::setHostKea(const string& xpath, ConstElementPtr elem) {
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
+ LeafBaseType::String);
}
}
-TranslatorHosts::TranslatorHosts(S_Session session, const string& model)
+TranslatorHosts::TranslatorHosts(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -205,7 +206,7 @@ TranslatorHosts::setHosts(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setHosts not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting host reservations '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_host.h b/src/lib/yang/translator_host.h
index b67880a3f0..528664baa7 100644
--- a/src/lib/yang/translator_host.h
+++ b/src/lib/yang/translator_host.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -118,7 +118,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorHost(sysrepo::S_Session session, const std::string& model);
+ TranslatorHost(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorHost();
@@ -165,7 +165,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorHosts(sysrepo::S_Session session, const std::string& model);
+ TranslatorHosts(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorHosts();
diff --git a/src/lib/yang/translator_logger.cc b/src/lib/yang/translator_logger.cc
index de0442840a..e0dab0adb5 100644
--- a/src/lib/yang/translator_logger.cc
+++ b/src/lib/yang/translator_logger.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorLogger::TranslatorLogger(S_Session session, const string& model)
+TranslatorLogger::TranslatorLogger(Session session, const string& model)
: TranslatorBasic(session, model) {
}
@@ -34,7 +35,7 @@ TranslatorLogger::getLogger(const string& xpath) {
(model_ == KEA_CTRL_AGENT)) {
return (getLoggerKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting logger at '" << xpath
<< "': " << ex.what());
@@ -117,7 +118,7 @@ TranslatorLogger::setLogger(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setLogger not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting logger '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -133,47 +134,39 @@ TranslatorLogger::setLoggerKea(const string& xpath, ConstElementPtr elem) {
}
ConstElementPtr debuglevel = elem->get("debuglevel");
if (debuglevel) {
- setItem(xpath + "/debuglevel", debuglevel, SR_UINT8_T);
+ setItem(xpath + "/debuglevel", debuglevel, LeafBaseType::Uint8);
}
ConstElementPtr severity = elem->get("severity");
if (severity) {
- setItem(xpath + "/severity", severity, SR_ENUM_T);
+ setItem(xpath + "/severity", severity, LeafBaseType::Enum);
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
+ LeafBaseType::String);
}
}
void
TranslatorLogger::setOutputOption(const string& xpath, ConstElementPtr elem) {
- bool created = false;
- // Skip output as it is the key.
+ // Keys are set by setting the list itself.
+ setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
+
ConstElementPtr maxver = elem->get("maxver");
if (maxver) {
- setItem(xpath + "/maxver", maxver, SR_UINT32_T);
- created = true;
+ setItem(xpath + "/maxver", maxver, LeafBaseType::Uint32);
}
ConstElementPtr maxsize = elem->get("maxsize");
if (maxsize) {
- setItem(xpath + "/maxsize", maxsize, SR_UINT32_T);
- created = true;
+ setItem(xpath + "/maxsize", maxsize, LeafBaseType::Uint32);
}
ConstElementPtr flush = elem->get("flush");
if (flush) {
- setItem(xpath + "/flush", flush, SR_BOOL_T);
- created = true;
+ setItem(xpath + "/flush", flush, LeafBaseType::Bool);
}
ConstElementPtr pattern = elem->get("pattern");
if (pattern) {
- setItem(xpath + "/pattern", pattern, SR_STRING_T);
- created = true;
- }
- // There is no mandatory fields outside the key so force creation.
- if (!created) {
- ConstElementPtr list = Element::createList();
- setItem(xpath, list, SR_LIST_T);
+ setItem(xpath + "/pattern", pattern, LeafBaseType::String);
}
}
@@ -192,7 +185,7 @@ TranslatorLogger::setOutputOptions(const string& xpath, ConstElementPtr elem) {
}
}
-TranslatorLoggers::TranslatorLoggers(S_Session session, const string& model)
+TranslatorLoggers::TranslatorLoggers(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorLogger(session, model) {
}
@@ -209,7 +202,7 @@ TranslatorLoggers::getLoggers(const string& xpath) {
(model_ == KEA_CTRL_AGENT)) {
return (getLoggersKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting loggeres at '" << xpath
<< "': " << ex.what());
@@ -236,7 +229,7 @@ TranslatorLoggers::setLoggers(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setLoggers not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting loggeres '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_logger.h b/src/lib/yang/translator_logger.h
index 6939414512..04ae8a0db5 100644
--- a/src/lib/yang/translator_logger.h
+++ b/src/lib/yang/translator_logger.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019,2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -98,7 +98,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorLogger(sysrepo::S_Session session, const std::string& model);
+ TranslatorLogger(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorLogger();
@@ -172,7 +172,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorLoggers(sysrepo::S_Session session, const std::string& model);
+ TranslatorLoggers(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorLoggers();
@@ -195,7 +195,7 @@ protected:
/// @brief getLoggers JSON for loggers.
///
/// @param xpath The xpath of loggers.
- /// @return JSON representation of loggers.
+ /// @return JSON representation of loggers.
/// @throw SysrepoError when sysrepo raises an error.
isc::data::ElementPtr getLoggersKea(const std::string& xpath);
diff --git a/src/lib/yang/translator_option_data.cc b/src/lib/yang/translator_option_data.cc
index 9947fdc55b..867bb96127 100644
--- a/src/lib/yang/translator_option_data.cc
+++ b/src/lib/yang/translator_option_data.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorOptionData::TranslatorOptionData(S_Session session,
+TranslatorOptionData::TranslatorOptionData(Session session,
const string& model)
: TranslatorBasic(session, model) {
}
@@ -33,7 +34,7 @@ TranslatorOptionData::getOptionData(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getOptionDataKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting option data at '" << xpath
<< "': " << ex.what());
@@ -89,7 +90,7 @@ TranslatorOptionData::setOptionData(const string& xpath,
"setOptionData not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting option data '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -102,28 +103,28 @@ TranslatorOptionData::setOptionDataKea(const string& xpath,
// Skip keys code and space.
ConstElementPtr name = elem->get("name");
if (name) {
- setItem(xpath + "/name", name, SR_STRING_T);
+ setItem(xpath + "/name", name, LeafBaseType::String);
}
ConstElementPtr data = elem->get("data");
if (data) {
- setItem(xpath + "/data", data, SR_STRING_T);
+ setItem(xpath + "/data", data, LeafBaseType::String);
}
ConstElementPtr format = elem->get("csv-format");
if (format) {
- setItem(xpath + "/csv-format", format, SR_BOOL_T);
+ setItem(xpath + "/csv-format", format, LeafBaseType::Bool);
}
ConstElementPtr send = elem->get("always-send");
if (send) {
- setItem(xpath + "/always-send", send, SR_BOOL_T);
+ setItem(xpath + "/always-send", send, LeafBaseType::Bool);
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
+ LeafBaseType::String);
}
}
-TranslatorOptionDataList::TranslatorOptionDataList(S_Session session,
+TranslatorOptionDataList::TranslatorOptionDataList(Session session,
const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model) {
@@ -139,7 +140,7 @@ TranslatorOptionDataList::getOptionDataList(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getOptionDataListKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting option data list at '" << xpath
<< "': " << ex.what());
@@ -166,7 +167,7 @@ TranslatorOptionDataList::setOptionDataList(const string& xpath,
"setOptionDataList not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting option data list '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_option_data.h b/src/lib/yang/translator_option_data.h
index 868109b25c..8739259b95 100644
--- a/src/lib/yang/translator_option_data.h
+++ b/src/lib/yang/translator_option_data.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -80,7 +80,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorOptionData(sysrepo::S_Session session, const std::string& model);
+ TranslatorOptionData(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorOptionData();
@@ -127,7 +127,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorOptionDataList(sysrepo::S_Session session,
+ TranslatorOptionDataList(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc
index a552191aa8..891c1fce0d 100644
--- a/src/lib/yang/translator_option_def.cc
+++ b/src/lib/yang/translator_option_def.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorOptionDef::TranslatorOptionDef(S_Session session,
+TranslatorOptionDef::TranslatorOptionDef(Session session,
const string& model)
: TranslatorBasic(session, model) {
}
@@ -33,7 +34,7 @@ TranslatorOptionDef::getOptionDef(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getOptionDefKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting option definition at '" << xpath
<< "': " << ex.what());
@@ -92,7 +93,7 @@ TranslatorOptionDef::setOptionDef(const string& xpath, ConstElementPtr elem) {
"setOptionDef not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting option definition '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -107,32 +108,32 @@ TranslatorOptionDef::setOptionDefKea(const string& xpath,
if (!name) {
isc_throw(BadValue, "option definition with name: " << elem->str());
}
- setItem(xpath + "/name", name, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/type", type, LeafBaseType::String);
ConstElementPtr record = elem->get("record-types");
if (record) {
- setItem(xpath + "/record-types", record, SR_STRING_T);
+ setItem(xpath + "/record-types", record, LeafBaseType::String);
}
ConstElementPtr array = elem->get("array");
if (array) {
- setItem(xpath + "/array", array, SR_BOOL_T);
+ setItem(xpath + "/array", array, LeafBaseType::Bool);
}
ConstElementPtr encapsulate = elem->get("encapsulate");
if (encapsulate) {
- setItem(xpath + "/encapsulate", encapsulate, SR_STRING_T);
+ setItem(xpath + "/encapsulate", encapsulate, LeafBaseType::String);
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
+ LeafBaseType::String);
}
}
-TranslatorOptionDefList::TranslatorOptionDefList(S_Session session,
+TranslatorOptionDefList::TranslatorOptionDefList(Session session,
const string& model)
: TranslatorBasic(session, model),
TranslatorOptionDef(session, model) {
@@ -148,7 +149,7 @@ TranslatorOptionDefList::getOptionDefList(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getOptionDefListKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting option definition list at '" << xpath
<< "': " << ex.what());
@@ -175,7 +176,7 @@ TranslatorOptionDefList::setOptionDefList(const string& xpath,
"setOptionDefList not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting option definition list '"
<< elem->str() << "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_option_def.h b/src/lib/yang/translator_option_def.h
index b8b0827fe9..c897517daa 100644
--- a/src/lib/yang/translator_option_def.h
+++ b/src/lib/yang/translator_option_def.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -83,7 +83,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorOptionDef(sysrepo::S_Session session, const std::string& model);
+ TranslatorOptionDef(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorOptionDef();
@@ -132,7 +132,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorOptionDefList(sysrepo::S_Session session,
+ TranslatorOptionDefList(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc
index f6ffe71707..3e38136fbd 100644
--- a/src/lib/yang/translator_pd_pool.cc
+++ b/src/lib/yang/translator_pd_pool.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -14,12 +14,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorPdPool::TranslatorPdPool(S_Session session, const string& model)
+TranslatorPdPool::TranslatorPdPool(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model) {
@@ -36,7 +37,7 @@ TranslatorPdPool::getPdPool(const string& xpath) {
} else if (model_ == KEA_DHCP6_SERVER) {
return (getPdPoolKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting pd-pool at '" << xpath
<< "': " << ex.what());
@@ -188,7 +189,7 @@ TranslatorPdPool::setPdPool(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setPdPool not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting pd-pool '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -206,44 +207,45 @@ TranslatorPdPool::setPdPoolIetf6(const string& xpath, ConstElementPtr elem) {
}
ostringstream prefix;
prefix << base->stringValue() << "/" << length->intValue();
- setItem(xpath + "/prefix", Element::create(prefix.str()), SR_STRING_T);
- setItem(xpath + "/prefix-length", length, SR_UINT8_T);
+ 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, SR_UINT32_T);
+ setItem(xpath + "/valid-lifetime", valid_lifetime, LeafBaseType::Uint32);
}
ConstElementPtr preferred_lifetime = elem->get("preferred-lifetime");
if (preferred_lifetime) {
setItem(xpath + "/preferred-lifetime",
- preferred_lifetime, SR_UINT32_T);
+ preferred_lifetime, LeafBaseType::Uint32);
}
ConstElementPtr renew_timer = elem->get("renew-timer");
if (renew_timer) {
- setItem(xpath + "/renew-time", renew_timer, SR_UINT32_T);
+ setItem(xpath + "/renew-time", renew_timer, LeafBaseType::Uint32);
}
ConstElementPtr rebind_timer = elem->get("rebind-timer");
if (rebind_timer) {
- setItem(xpath + "/rebind-time", rebind_timer, SR_UINT32_T);
+ setItem(xpath + "/rebind-time", rebind_timer, LeafBaseType::Uint32);
}
// Skip rapid-commit.
ConstElementPtr guard = elem->get("client-class");
if (guard) {
- setItem(xpath + "/client-class", guard, SR_STRING_T);
+ setItem(xpath + "/client-class", guard, LeafBaseType::String);
}
// Set max pd space utilization to disabled.
setItem(xpath + "/max-pd-space-utilization",
Element::create(string("disabled")),
- SR_ENUM_T);
+ LeafBaseType::Enum);
// @todo option-data.
}
void
TranslatorPdPool::setPdPoolKea(const string& xpath, ConstElementPtr elem) {
- // Skip prefix as it is the key.
- bool created = false;
+ // 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, SR_UINT8_T);
+ setItem(xpath + "/delegated-len", delegated, LeafBaseType::Uint8);
}
ConstElementPtr xprefix = elem->get("excluded-prefix");
ConstElementPtr xlen = elem->get("excluded-prefix-len");
@@ -251,40 +253,30 @@ TranslatorPdPool::setPdPoolKea(const string& xpath, ConstElementPtr elem) {
ostringstream xpref;
xpref << xprefix->stringValue() << "/" << xlen->intValue();
setItem(xpath + "/excluded-prefix", Element::create(xpref.str()),
- SR_STRING_T);
- created = true;
+ LeafBaseType::String);
}
ConstElementPtr options = elem->get("option-data");
if (options && (options->size() > 0)) {
setOptionDataList(xpath, options);
- created = true;
}
ConstElementPtr guard = elem->get("client-class");
if (guard) {
- setItem(xpath + "/client-class", guard, SR_STRING_T);
- created = true;
+ 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, SR_STRING_T);
- created = true;
+ setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
}
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
- created = true;
- }
- // There is no mandatory fields outside the keys so force creation.
- if (!created) {
- ConstElementPtr list = Element::createList();
- setItem(xpath, list, SR_LIST_T);
+ LeafBaseType::String);
}
}
-TranslatorPdPools::TranslatorPdPools(S_Session session, const string& model)
+TranslatorPdPools::TranslatorPdPools(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -301,7 +293,7 @@ TranslatorPdPools::getPdPools(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getPdPoolsCommon(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting pd-pools at '" << xpath
<< "': " << ex.what());
@@ -327,7 +319,7 @@ TranslatorPdPools::setPdPools(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setPdPools not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting pools '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_pd_pool.h b/src/lib/yang/translator_pd_pool.h
index 6431b3fb2a..6f6258383d 100644
--- a/src/lib/yang/translator_pd_pool.h
+++ b/src/lib/yang/translator_pd_pool.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -121,7 +121,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorPdPool(sysrepo::S_Session session, const std::string& model);
+ TranslatorPdPool(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorPdPool();
@@ -184,7 +184,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorPdPools(sysrepo::S_Session session, const std::string& model);
+ TranslatorPdPools(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorPdPools();
diff --git a/src/lib/yang/translator_pool.cc b/src/lib/yang/translator_pool.cc
index d4593855cf..0d6f14c651 100644
--- a/src/lib/yang/translator_pool.cc
+++ b/src/lib/yang/translator_pool.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -17,12 +17,13 @@
using namespace std;
using namespace isc::data;
using namespace isc::asiolink;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorPool::TranslatorPool(S_Session session, const string& model)
+TranslatorPool::TranslatorPool(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model) {
@@ -40,7 +41,7 @@ TranslatorPool::getPool(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getPoolKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting pool at '" << xpath
<< "': " << ex.what());
@@ -139,7 +140,7 @@ TranslatorPool::setPool(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setPool not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting pool '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -158,45 +159,45 @@ TranslatorPool::setPoolIetf6(const string& xpath, ConstElementPtr elem) {
"setPoolIetf only supports pools in prefix (vs range) "
"format and was called with '" << prefix << "'");
}
- setItem(xpath + "/pool-prefix", pool, SR_STRING_T);
+ setItem(xpath + "/pool-prefix", pool, LeafBaseType::String);
string addr = prefix.substr(0, prefix.find_first_of(" /"));
uint8_t plen = boost::lexical_cast<unsigned>
(prefix.substr(prefix.find_last_of(" /") + 1, string::npos));
const IOAddress& base(addr);
setItem(xpath + "/start-address",
Element::create(firstAddrInPrefix(base, plen).toText()),
- SR_STRING_T);
+ LeafBaseType::String);
setItem(xpath + "/end-address",
Element::create(lastAddrInPrefix(base, plen).toText()),
- SR_STRING_T);
+ LeafBaseType::String);
ConstElementPtr valid_lifetime = elem->get("valid-lifetime");
if (valid_lifetime) {
- setItem(xpath + "/valid-lifetime", valid_lifetime, SR_UINT32_T);
+ setItem(xpath + "/valid-lifetime", valid_lifetime, LeafBaseType::Uint32);
}
ConstElementPtr preferred_lifetime = elem->get("preferred-lifetime");
if (preferred_lifetime) {
setItem(xpath + "/preferred-lifetime",
- preferred_lifetime, SR_UINT32_T);
+ preferred_lifetime, LeafBaseType::Uint32);
}
ConstElementPtr renew_timer = elem->get("renew-timer");
if (renew_timer) {
- setItem(xpath + "/renew-time", renew_timer, SR_UINT32_T);
+ setItem(xpath + "/renew-time", renew_timer, LeafBaseType::Uint32);
}
ConstElementPtr rebind_timer = elem->get("rebind-timer");
if (rebind_timer) {
- setItem(xpath + "/rebind-time", rebind_timer, SR_UINT32_T);
+ setItem(xpath + "/rebind-time", rebind_timer, LeafBaseType::Uint32);
}
// skip rapid-commit
ConstElementPtr guard = elem->get("client-class");
if (guard) {
- setItem(xpath + "/client-class", guard, SR_STRING_T);
+ setItem(xpath + "/client-class", guard, LeafBaseType::String);
}
// skip max-addr-count
// @todo option-data
// Set max address count to disabled.
setItem(xpath + "/max-address-count",
Element::create(string("disabled")),
- SR_ENUM_T);
+ LeafBaseType::Enum);
}
void
@@ -205,43 +206,36 @@ TranslatorPool::setPoolKea(const string& xpath, ConstElementPtr elem) {
if (!pool) {
isc_throw(BadValue, "setPoolKea requires pool: " << elem->str());
}
- bool created = false;
+
+ // Keys are set by setting the list itself.
+ setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
+
string prefix = pool->stringValue();
string start_addr;
string end_addr;
getAddresses(prefix, start_addr, end_addr);
if (prefix.find("/") != string::npos) {
- setItem(xpath + "/prefix", pool, SR_STRING_T);
- created = true;
+ 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)) {
setOptionDataList(xpath, options);
- created = true;
}
ConstElementPtr guard = elem->get("client-class");
if (guard) {
- setItem(xpath + "/client-class", guard, SR_STRING_T);
- created = true;
+ 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, SR_STRING_T);
- created = true;
+ setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
}
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
setItem(xpath + "/user-context", Element::create(context->str()),
- SR_STRING_T);
- created = true;
- }
- // There is no mandatory fields outside the keys so force creation.
- if (!created) {
- ConstElementPtr list = Element::createList();
- setItem(xpath, list, SR_LIST_T);
+ LeafBaseType::String);
}
}
@@ -266,7 +260,7 @@ TranslatorPool::getAddresses(const string& prefix,
end_address = prefix.substr(prefix.find_last_of(" -") + 1, string::npos);
}
-TranslatorPools::TranslatorPools(S_Session session, const string& model)
+TranslatorPools::TranslatorPools(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -285,7 +279,7 @@ TranslatorPools::getPools(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getPoolsKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting pools at '" << xpath
<< "': " << ex.what());
@@ -318,7 +312,7 @@ TranslatorPools::setPools(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setPools not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting pools '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_pool.h b/src/lib/yang/translator_pool.h
index f9a9bc7f38..6135fc9a2d 100644
--- a/src/lib/yang/translator_pool.h
+++ b/src/lib/yang/translator_pool.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -129,7 +129,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorPool(sysrepo::S_Session session, const std::string& model);
+ TranslatorPool(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorPool();
@@ -199,7 +199,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorPools(sysrepo::S_Session session, const std::string& model);
+ TranslatorPools(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorPools();
diff --git a/src/lib/yang/translator_shared_network.cc b/src/lib/yang/translator_shared_network.cc
index 4f4622a34a..08293452d9 100644
--- a/src/lib/yang/translator_shared_network.cc
+++ b/src/lib/yang/translator_shared_network.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorSharedNetwork::TranslatorSharedNetwork(S_Session session,
+TranslatorSharedNetwork::TranslatorSharedNetwork(Session session,
const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
@@ -44,7 +45,7 @@ TranslatorSharedNetwork::getSharedNetwork(const string& xpath) {
} else if (model_ == KEA_DHCP6_SERVER) {
return (getSharedNetworkKea(xpath, "subnet6"));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting shared network at '" << xpath
<< "': " << ex.what());
@@ -207,7 +208,7 @@ TranslatorSharedNetwork::setSharedNetwork(const string& xpath,
"setSharedNetwork not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting shared network '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -226,48 +227,48 @@ TranslatorSharedNetwork::setSharedNetworkKea(const string& xpath,
if (subsel == "subnet6") {
ConstElementPtr preferred = elem->get("preferred-lifetime");
if (preferred) {
- setItem(xpath + "/preferred-lifetime", preferred, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ setItem(xpath + "/max-preferred-lifetime", max_pref, LeafBaseType::Uint32);
}
}
ConstElementPtr valid = elem->get("valid-lifetime");
if (valid) {
- setItem(xpath + "/valid-lifetime", valid, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ setItem(xpath + "/max-valid-lifetime", max_valid, LeafBaseType::Uint32);
}
ConstElementPtr renew = elem->get("renew-timer");
if (renew) {
- setItem(xpath + "/renew-timer", renew, SR_UINT32_T);
+ setItem(xpath + "/renew-timer", renew, LeafBaseType::Uint32);
}
ConstElementPtr rebind = elem->get("rebind-timer");
if (rebind) {
- setItem(xpath + "/rebind-timer", rebind, SR_UINT32_T);
+ setItem(xpath + "/rebind-timer", rebind, LeafBaseType::Uint32);
}
ConstElementPtr calculate = elem->get("calculate-tee-times");
if (calculate) {
- setItem(xpath + "/calculate-tee-times", calculate, SR_BOOL_T);
+ setItem(xpath + "/calculate-tee-times", calculate, LeafBaseType::Bool);
}
ConstElementPtr t1_percent = elem->get("t1-percent");
if (t1_percent) {
- setItem(xpath + "/t1-percent", t1_percent, SR_DECIMAL64_T);
+ setItem(xpath + "/t1-percent", t1_percent, LeafBaseType::Dec64);
}
ConstElementPtr t2_percent = elem->get("t2-percent");
if (t2_percent) {
- setItem(xpath + "/t2-percent", t2_percent, SR_DECIMAL64_T);
+ setItem(xpath + "/t2-percent", t2_percent, LeafBaseType::Dec64);
}
ConstElementPtr options = elem->get("option-data");
if (options && (options->size() > 0)) {
@@ -275,90 +276,90 @@ TranslatorSharedNetwork::setSharedNetworkKea(const string& xpath,
}
ConstElementPtr interface = elem->get("interface");
if (interface) {
- setItem(xpath + "/interface", interface, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/interface-id", interface_id, LeafBaseType::String);
}
ConstElementPtr rapid_commit = elem->get("rapid-commit");
if (rapid_commit) {
- setItem(xpath + "/rapid-commit", rapid_commit, SR_BOOL_T);
+ setItem(xpath + "/rapid-commit", rapid_commit, LeafBaseType::Bool);
}
}
ConstElementPtr guard = elem->get("client-class");
if (guard) {
- setItem(xpath + "/client-class", guard, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
}
}
ConstElementPtr mode = elem->get("reservation-mode");
if (mode) {
- setItem(xpath + "/reservation-mode", mode, SR_ENUM_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_BOOL_T);
+ setItem(xpath + "/match-client-id", match, LeafBaseType::Bool);
}
ConstElementPtr auth = elem->get("authoritative");
if (auth) {
- setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+ setItem(xpath + "/authoritative", auth, LeafBaseType::Bool);
}
ConstElementPtr next = elem->get("next-server");
if (next) {
- setItem(xpath + "/next-server", next, SR_STRING_T);
+ setItem(xpath + "/next-server", next, LeafBaseType::String);
}
ConstElementPtr hostname = elem->get("server-hostname");
if (hostname) {
- setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
+ setItem(xpath + "/server-hostname", hostname, LeafBaseType::String);
}
ConstElementPtr boot = elem->get("boot-file-name");
if (boot) {
- setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ 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, SR_STRING_T);
- }
- checkAndSetLeaf(elem, xpath, "cache-max-age", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "cache-threshold", SR_DECIMAL64_T);
- checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-override-client-update", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-override-no-update", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-send-updates", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "hostname-char-replacement", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "hostname-char-set", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "reservations-global", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-in-subnet", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "store-extended-info", SR_BOOL_T);
+ setItem(xpath + "/user-context", repr, LeafBaseType::String);
+ }
+ checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
+ 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, "hostname-char-replacement", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
+ 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);
}
-TranslatorSharedNetworks::TranslatorSharedNetworks(S_Session session,
+TranslatorSharedNetworks::TranslatorSharedNetworks(Session session,
const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
@@ -395,7 +396,7 @@ TranslatorSharedNetworks::setSharedNetworks(const string& xpath,
"setSharedNetworks not implemented for the model: "
<< model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting shared networks '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
diff --git a/src/lib/yang/translator_shared_network.h b/src/lib/yang/translator_shared_network.h
index 799af4b185..1d1b8fd879 100644
--- a/src/lib/yang/translator_shared_network.h
+++ b/src/lib/yang/translator_shared_network.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -170,7 +170,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorSharedNetwork(sysrepo::S_Session session,
+ TranslatorSharedNetwork(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
@@ -224,7 +224,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorSharedNetworks(sysrepo::S_Session session,
+ TranslatorSharedNetworks(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
diff --git a/src/lib/yang/translator_subnet.cc b/src/lib/yang/translator_subnet.cc
index 126b04df06..334d2fd3b7 100644
--- a/src/lib/yang/translator_subnet.cc
+++ b/src/lib/yang/translator_subnet.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -14,12 +14,13 @@
using namespace std;
using namespace isc::data;
+using namespace libyang;
using namespace sysrepo;
namespace isc {
namespace yang {
-TranslatorSubnet::TranslatorSubnet(S_Session session, const string& model)
+TranslatorSubnet::TranslatorSubnet(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -43,7 +44,7 @@ TranslatorSubnet::getSubnet(const string& xpath) {
(model_ == KEA_DHCP6_SERVER)) {
return (getSubnetKea(xpath));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting subnet at '" << xpath
<< "': " << ex.what());
@@ -273,7 +274,7 @@ TranslatorSubnet::setSubnet(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setSubnet not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting subnet '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -288,14 +289,14 @@ TranslatorSubnet::setSubnetIetf6(const string& xpath, ConstElementPtr elem) {
if (context && context->contains("description")) {
ConstElementPtr description = context->get("description");
if (description->getType() == Element::string) {
- setItem(xpath + "/network-description", description, SR_STRING_T);
+ setItem(xpath + "/network-description", description, LeafBaseType::String);
}
}
ConstElementPtr subnet = elem->get("subnet");
if (!subnet) {
isc_throw(BadValue, "setSubnetIetf6 requires subnet: " << elem->str());
}
- setItem(xpath + "/network-prefix", subnet, SR_STRING_T);
+ setItem(xpath + "/network-prefix", subnet, LeafBaseType::String);
/// @todo option-data
ConstElementPtr pools = elem->get("pools");
if (pools && (pools->size() > 0)) {
@@ -314,48 +315,48 @@ TranslatorSubnet::setSubnetKea(const string& xpath, ConstElementPtr elem) {
if (model_ == KEA_DHCP6_SERVER) {
ConstElementPtr preferred = elem->get("preferred-lifetime");
if (preferred) {
- setItem(xpath + "/preferred-lifetime", preferred, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ setItem(xpath + "/max-preferred-lifetime", max_pref, LeafBaseType::Uint32);
}
}
ConstElementPtr valid = elem->get("valid-lifetime");
if (valid) {
- setItem(xpath + "/valid-lifetime", valid, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ 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, SR_UINT32_T);
+ setItem(xpath + "/max-valid-lifetime", max_valid, LeafBaseType::Uint32);
}
ConstElementPtr renew = elem->get("renew-timer");
if (renew) {
- setItem(xpath + "/renew-timer", renew, SR_UINT32_T);
+ setItem(xpath + "/renew-timer", renew, LeafBaseType::Uint32);
}
ConstElementPtr rebind = elem->get("rebind-timer");
if (rebind) {
- setItem(xpath + "/rebind-timer", rebind, SR_UINT32_T);
+ setItem(xpath + "/rebind-timer", rebind, LeafBaseType::Uint32);
}
ConstElementPtr calculate = elem->get("calculate-tee-times");
if (calculate) {
- setItem(xpath + "/calculate-tee-times", calculate, SR_BOOL_T);
+ setItem(xpath + "/calculate-tee-times", calculate, LeafBaseType::Bool);
}
ConstElementPtr t1_percent = elem->get("t1-percent");
if (t1_percent) {
- setItem(xpath + "/t1-percent", t1_percent, SR_DECIMAL64_T);
+ setItem(xpath + "/t1-percent", t1_percent, LeafBaseType::Dec64);
}
ConstElementPtr t2_percent = elem->get("t2-percent");
if (t2_percent) {
- setItem(xpath + "/t2-percent", t2_percent, SR_DECIMAL64_T);
+ setItem(xpath + "/t2-percent", t2_percent, LeafBaseType::Dec64);
}
ConstElementPtr options = elem->get("option-data");
if (options && (options->size() > 0)) {
@@ -375,31 +376,31 @@ TranslatorSubnet::setSubnetKea(const string& xpath, ConstElementPtr elem) {
if (!subnet) {
isc_throw(BadValue, "setSubnetKea requires subnet: " << elem->str());
}
- setItem(xpath + "/subnet", subnet, SR_STRING_T);
+ setItem(xpath + "/subnet", subnet, LeafBaseType::String);
ConstElementPtr interface = elem->get("interface");
if (interface) {
- setItem(xpath + "/interface", interface, SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_BOOL_T);
+ setItem(xpath + "/rapid-commit", rapid_commit, LeafBaseType::Bool);
}
}
ConstElementPtr guard = elem->get("client-class");
if (guard) {
- setItem(xpath + "/client-class", guard, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/require-client-classes", rclass, LeafBaseType::String);
}
}
ConstElementPtr hosts = elem->get("reservations");
@@ -408,78 +409,78 @@ TranslatorSubnet::setSubnetKea(const string& xpath, ConstElementPtr elem) {
}
ConstElementPtr mode = elem->get("reservation-mode");
if (mode) {
- setItem(xpath + "/reservation-mode", mode, SR_ENUM_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String);
}
}
}
- checkAndSetLeaf(elem, xpath, "cache-max-age", SR_UINT32_T);
- checkAndSetLeaf(elem, xpath, "cache-threshold", SR_DECIMAL64_T);
- checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-override-client-update", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-override-no-update", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "ddns-send-updates", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "hostname-char-replacement", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "hostname-char-set", SR_STRING_T);
- checkAndSetLeaf(elem, xpath, "reservations-global", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-in-subnet", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", SR_BOOL_T);
- checkAndSetLeaf(elem, xpath, "store-extended-info", SR_BOOL_T);
+ checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
+ checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
+ 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, "hostname-char-replacement", LeafBaseType::String);
+ checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
+ 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, SR_BOOL_T);
+ setItem(xpath + "/match-client-id", match, LeafBaseType::Bool);
}
ConstElementPtr auth = elem->get("authoritative");
if (auth) {
- setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+ setItem(xpath + "/authoritative", auth, LeafBaseType::Bool);
}
ConstElementPtr next = elem->get("next-server");
if (next) {
- setItem(xpath + "/next-server", next, SR_STRING_T);
+ setItem(xpath + "/next-server", next, LeafBaseType::String);
}
ConstElementPtr hostname = elem->get("server-hostname");
if (hostname) {
- setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
+ setItem(xpath + "/server-hostname", hostname, LeafBaseType::String);
}
ConstElementPtr boot = elem->get("boot-file-name");
if (boot) {
- setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ 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, SR_STRING_T);
+ setItem(xpath + "/subnet-4o6-subnet", s4o6_subnet, LeafBaseType::String);
}
}
ConstElementPtr context = Adaptor::getContext(elem);
if (context) {
ConstElementPtr repr = Element::create(context->str());
- setItem(xpath + "/user-context", repr, SR_STRING_T);
+ setItem(xpath + "/user-context", repr, LeafBaseType::String);
}
}
-TranslatorSubnets::TranslatorSubnets(S_Session session, const string& model)
+TranslatorSubnets::TranslatorSubnets(Session session, const string& model)
: TranslatorBasic(session, model),
TranslatorOptionData(session, model),
TranslatorOptionDataList(session, model),
@@ -505,7 +506,7 @@ TranslatorSubnets::getSubnets(const string& xpath) {
} else if (model_ == KEA_DHCP6_SERVER) {
return (getSubnetsCommon(xpath, "subnet6"));
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error getting subnets at '" << xpath
<< "': " << ex.what());
@@ -534,7 +535,7 @@ TranslatorSubnets::setSubnets(const string& xpath, ConstElementPtr elem) {
isc_throw(NotImplemented,
"setSubnets not implemented for the model: " << model_);
}
- } catch (const sysrepo_exception& ex) {
+ } catch (Error const& ex) {
isc_throw(SysrepoError,
"sysrepo error setting subnets '" << elem->str()
<< "' at '" << xpath << "': " << ex.what());
@@ -552,7 +553,7 @@ TranslatorSubnets::setSubnetsIetf6(const string& xpath, ConstElementPtr elem) {
isc_throw(BadValue, "subnet without id: " << elem->str());
}
range << id->intValue() << "']";
- setSubnet(range.str().c_str(), subnet);
+ setSubnet(range.str(), subnet);
}
}
diff --git a/src/lib/yang/translator_subnet.h b/src/lib/yang/translator_subnet.h
index 2584047f1e..84dfd4c066 100644
--- a/src/lib/yang/translator_subnet.h
+++ b/src/lib/yang/translator_subnet.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019,2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -278,7 +278,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorSubnet(sysrepo::S_Session session, const std::string& model);
+ TranslatorSubnet(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorSubnet();
@@ -337,7 +337,7 @@ public:
///
/// @param session Sysrepo session.
/// @param model Model name.
- TranslatorSubnets(sysrepo::S_Session session, const std::string& model);
+ TranslatorSubnets(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorSubnets();