summaryrefslogtreecommitdiffstats
path: root/src/lib/yang
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:36:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:36:04 +0000
commit040eee1aa49b49df4698d83a05af57c220127fd1 (patch)
treef635435954e6ccde5eee9893889e24f30ca68346 /src/lib/yang
parentInitial commit. (diff)
downloadisc-kea-040eee1aa49b49df4698d83a05af57c220127fd1.tar.xz
isc-kea-040eee1aa49b49df4698d83a05af57c220127fd1.zip
Adding upstream version 2.2.0.upstream/2.2.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/yang')
-rw-r--r--src/lib/yang/Makefile.am73
-rw-r--r--src/lib/yang/Makefile.in1040
-rw-r--r--src/lib/yang/adaptor.cc308
-rw-r--r--src/lib/yang/adaptor.h133
-rw-r--r--src/lib/yang/adaptor_config.cc658
-rw-r--r--src/lib/yang/adaptor_config.h292
-rw-r--r--src/lib/yang/adaptor_host.cc68
-rw-r--r--src/lib/yang/adaptor_host.h47
-rw-r--r--src/lib/yang/adaptor_option.cc128
-rw-r--r--src/lib/yang/adaptor_option.h111
-rw-r--r--src/lib/yang/adaptor_pool.cc87
-rw-r--r--src/lib/yang/adaptor_pool.h98
-rw-r--r--src/lib/yang/adaptor_subnet.cc73
-rw-r--r--src/lib/yang/adaptor_subnet.h66
-rw-r--r--src/lib/yang/pretests/Makefile.am14
-rw-r--r--src/lib/yang/pretests/Makefile.in823
-rw-r--r--src/lib/yang/pretests/sysrepo_setup_tests.cc126
-rw-r--r--src/lib/yang/sysrepo_error.h26
-rw-r--r--src/lib/yang/tests/Makefile.am60
-rw-r--r--src/lib/yang/tests/Makefile.in1285
-rw-r--r--src/lib/yang/tests/adaptor_config_unittests.cc145
-rw-r--r--src/lib/yang/tests/adaptor_host_unittests.cc119
-rw-r--r--src/lib/yang/tests/adaptor_option_unittests.cc241
-rw-r--r--src/lib/yang/tests/adaptor_pool_unittests.cc274
-rw-r--r--src/lib/yang/tests/adaptor_subnet_unittests.cc213
-rw-r--r--src/lib/yang/tests/adaptor_unittests.cc394
-rw-r--r--src/lib/yang/tests/config_unittests.cc417
-rw-r--r--src/lib/yang/tests/json_configs.h174
-rw-r--r--src/lib/yang/tests/run_unittests.cc20
-rw-r--r--src/lib/yang/tests/sysrepo_setup.h99
-rw-r--r--src/lib/yang/tests/translator_class_unittests.cc125
-rw-r--r--src/lib/yang/tests/translator_control_socket_unittests.cc176
-rw-r--r--src/lib/yang/tests/translator_database_unittests.cc327
-rw-r--r--src/lib/yang/tests/translator_host_unittests.cc188
-rw-r--r--src/lib/yang/tests/translator_logger_unittests.cc159
-rw-r--r--src/lib/yang/tests/translator_option_data_unittests.cc136
-rw-r--r--src/lib/yang/tests/translator_option_def_unittests.cc144
-rw-r--r--src/lib/yang/tests/translator_pd_pool_unittests.cc290
-rw-r--r--src/lib/yang/tests/translator_pool_unittests.cc250
-rw-r--r--src/lib/yang/tests/translator_shared_network_unittests.cc209
-rw-r--r--src/lib/yang/tests/translator_subnet_unittests.cc379
-rw-r--r--src/lib/yang/tests/translator_unittests.cc683
-rw-r--r--src/lib/yang/tests/translator_utils_unittests.cc270
-rw-r--r--src/lib/yang/tests/yang_configs.h591
-rw-r--r--src/lib/yang/testutils/Makefile.am24
-rw-r--r--src/lib/yang/testutils/Makefile.in840
-rw-r--r--src/lib/yang/testutils/translator_test.cc421
-rw-r--r--src/lib/yang/testutils/translator_test.h159
-rw-r--r--src/lib/yang/translator.cc318
-rw-r--r--src/lib/yang/translator.h177
-rw-r--r--src/lib/yang/translator_class.cc245
-rw-r--r--src/lib/yang/translator_class.h169
-rw-r--r--src/lib/yang/translator_config.cc770
-rw-r--r--src/lib/yang/translator_config.h548
-rw-r--r--src/lib/yang/translator_control_socket.cc111
-rw-r--r--src/lib/yang/translator_control_socket.h120
-rw-r--r--src/lib/yang/translator_database.cc204
-rw-r--r--src/lib/yang/translator_database.h205
-rw-r--r--src/lib/yang/translator_host.cc261
-rw-r--r--src/lib/yang/translator_host.h198
-rw-r--r--src/lib/yang/translator_logger.cc261
-rw-r--r--src/lib/yang/translator_logger.h214
-rw-r--r--src/lib/yang/translator_option_data.cc197
-rw-r--r--src/lib/yang/translator_option_data.h168
-rw-r--r--src/lib/yang/translator_option_def.cc208
-rw-r--r--src/lib/yang/translator_option_def.h175
-rw-r--r--src/lib/yang/translator_pd_pool.cc365
-rw-r--r--src/lib/yang/translator_pd_pool.h230
-rw-r--r--src/lib/yang/translator_pool.cc359
-rw-r--r--src/lib/yang/translator_pool.h249
-rw-r--r--src/lib/yang/translator_shared_network.cc422
-rw-r--r--src/lib/yang/translator_shared_network.h260
-rw-r--r--src/lib/yang/translator_subnet.cc575
-rw-r--r--src/lib/yang/translator_subnet.h386
-rw-r--r--src/lib/yang/yang.dox204
-rw-r--r--src/lib/yang/yang_models.h37
-rw-r--r--src/lib/yang/yang_revisions.h35
-rw-r--r--src/lib/yang/yang_revisions.h.skel27
78 files changed, 20681 insertions, 0 deletions
diff --git a/src/lib/yang/Makefile.am b/src/lib/yang/Makefile.am
new file mode 100644
index 0000000..78b6678
--- /dev/null
+++ b/src/lib/yang/Makefile.am
@@ -0,0 +1,73 @@
+SUBDIRS = . testutils pretests tests
+
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+AM_CPPFLAGS += $(SYSREPO_INCLUDEDIR)
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+lib_LTLIBRARIES = libkea-yang.la
+libkea_yang_la_SOURCES = adaptor.cc adaptor.h
+libkea_yang_la_SOURCES += adaptor_host.cc adaptor_host.h
+libkea_yang_la_SOURCES += adaptor_pool.cc adaptor_pool.h
+libkea_yang_la_SOURCES += adaptor_option.cc adaptor_option.h
+libkea_yang_la_SOURCES += adaptor_subnet.cc adaptor_subnet.h
+libkea_yang_la_SOURCES += adaptor_config.cc adaptor_config.h
+libkea_yang_la_SOURCES += sysrepo_error.h
+libkea_yang_la_SOURCES += translator.cc translator.h
+libkea_yang_la_SOURCES += translator_control_socket.cc
+libkea_yang_la_SOURCES += translator_control_socket.h
+libkea_yang_la_SOURCES += translator_database.cc translator_database.h
+libkea_yang_la_SOURCES += translator_logger.cc translator_logger.h
+libkea_yang_la_SOURCES += translator_option_data.cc
+libkea_yang_la_SOURCES += translator_option_data.h
+libkea_yang_la_SOURCES += translator_option_def.cc
+libkea_yang_la_SOURCES += translator_option_def.h
+libkea_yang_la_SOURCES += translator_class.cc translator_class.h
+libkea_yang_la_SOURCES += translator_pool.cc translator_pool.h
+libkea_yang_la_SOURCES += translator_pd_pool.cc translator_pd_pool.h
+libkea_yang_la_SOURCES += translator_host.cc translator_host.h
+libkea_yang_la_SOURCES += translator_subnet.cc translator_subnet.h
+libkea_yang_la_SOURCES += translator_shared_network.cc
+libkea_yang_la_SOURCES += translator_shared_network.h
+libkea_yang_la_SOURCES += translator_config.cc translator_config.h
+libkea_yang_la_SOURCES += yang_models.h yang_revisions.h
+
+libkea_yang_la_LIBADD = $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+libkea_yang_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+libkea_yang_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la
+libkea_yang_la_LIBADD += $(top_builddir)/src/lib/util/libkea-util.la
+libkea_yang_la_LIBADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+libkea_yang_la_LIBADD += $(LOG4CPLUS_LIBS) $(BOOST_LIBS) $(SYSREPO_LIBS)
+
+libkea_yang_la_LDFLAGS = -no-undefined -version-info 29:0:0
+
+# Specify the headers for copying into the installation directory tree.
+libkea_yang_includedir = $(pkgincludedir)/yang
+libkea_yang_include_HEADERS = \
+ adaptor.h \
+ adaptor_config.h \
+ adaptor_host.h \
+ adaptor_option.h \
+ adaptor_pool.h \
+ adaptor_subnet.h \
+ sysrepo_error.h \
+ translator.h \
+ translator_class.h \
+ translator_config.h \
+ translator_control_socket.h \
+ translator_database.h \
+ translator_host.h \
+ translator_logger.h \
+ translator_option_data.h \
+ translator_option_def.h \
+ translator_pd_pool.h \
+ translator_pool.h \
+ translator_shared_network.h \
+ translator_subnet.h \
+ yang_models.h \
+ yang_revisions.h
+
+EXTRA_DIST = yang.dox yang_revisions.h.skel
+
+CLEANFILES = *.gcno *.gcda
diff --git a/src/lib/yang/Makefile.in b/src/lib/yang/Makefile.in
new file mode 100644
index 0000000..c229989
--- /dev/null
+++ b/src/lib/yang/Makefile.in
@@ -0,0 +1,1040 @@
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src/lib/yang
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \
+ $(top_srcdir)/m4macros/ax_cpp11.m4 \
+ $(top_srcdir)/m4macros/ax_crypto.m4 \
+ $(top_srcdir)/m4macros/ax_find_library.m4 \
+ $(top_srcdir)/m4macros/ax_gssapi.m4 \
+ $(top_srcdir)/m4macros/ax_gtest.m4 \
+ $(top_srcdir)/m4macros/ax_isc_rpath.m4 \
+ $(top_srcdir)/m4macros/ax_sysrepo.m4 \
+ $(top_srcdir)/m4macros/libtool.m4 \
+ $(top_srcdir)/m4macros/ltoptions.m4 \
+ $(top_srcdir)/m4macros/ltsugar.m4 \
+ $(top_srcdir)/m4macros/ltversion.m4 \
+ $(top_srcdir)/m4macros/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(libkea_yang_include_HEADERS) \
+ $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+am__installdirs = "$(DESTDIR)$(libdir)" \
+ "$(DESTDIR)$(libkea_yang_includedir)"
+LTLIBRARIES = $(lib_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+libkea_yang_la_DEPENDENCIES = \
+ $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \
+ $(top_builddir)/src/lib/cc/libkea-cc.la \
+ $(top_builddir)/src/lib/log/libkea-log.la \
+ $(top_builddir)/src/lib/util/libkea-util.la \
+ $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1)
+am_libkea_yang_la_OBJECTS = adaptor.lo adaptor_host.lo adaptor_pool.lo \
+ adaptor_option.lo adaptor_subnet.lo adaptor_config.lo \
+ translator.lo translator_control_socket.lo \
+ translator_database.lo translator_logger.lo \
+ translator_option_data.lo translator_option_def.lo \
+ translator_class.lo translator_pool.lo translator_pd_pool.lo \
+ translator_host.lo translator_subnet.lo \
+ translator_shared_network.lo translator_config.lo
+libkea_yang_la_OBJECTS = $(am_libkea_yang_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+libkea_yang_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
+ $(AM_CXXFLAGS) $(CXXFLAGS) $(libkea_yang_la_LDFLAGS) \
+ $(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/adaptor.Plo \
+ ./$(DEPDIR)/adaptor_config.Plo ./$(DEPDIR)/adaptor_host.Plo \
+ ./$(DEPDIR)/adaptor_option.Plo ./$(DEPDIR)/adaptor_pool.Plo \
+ ./$(DEPDIR)/adaptor_subnet.Plo ./$(DEPDIR)/translator.Plo \
+ ./$(DEPDIR)/translator_class.Plo \
+ ./$(DEPDIR)/translator_config.Plo \
+ ./$(DEPDIR)/translator_control_socket.Plo \
+ ./$(DEPDIR)/translator_database.Plo \
+ ./$(DEPDIR)/translator_host.Plo \
+ ./$(DEPDIR)/translator_logger.Plo \
+ ./$(DEPDIR)/translator_option_data.Plo \
+ ./$(DEPDIR)/translator_option_def.Plo \
+ ./$(DEPDIR)/translator_pd_pool.Plo \
+ ./$(DEPDIR)/translator_pool.Plo \
+ ./$(DEPDIR)/translator_shared_network.Plo \
+ ./$(DEPDIR)/translator_subnet.Plo
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(libkea_yang_la_SOURCES)
+DIST_SOURCES = $(libkea_yang_la_SOURCES)
+RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
+ ctags-recursive dvi-recursive html-recursive info-recursive \
+ install-data-recursive install-dvi-recursive \
+ install-exec-recursive install-html-recursive \
+ install-info-recursive install-pdf-recursive \
+ install-ps-recursive install-recursive installcheck-recursive \
+ installdirs-recursive pdf-recursive ps-recursive \
+ tags-recursive uninstall-recursive
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+HEADERS = $(libkea_yang_include_HEADERS)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
+ distclean-recursive maintainer-clean-recursive
+am__recursive_targets = \
+ $(RECURSIVE_TARGETS) \
+ $(RECURSIVE_CLEAN_TARGETS) \
+ $(am__extra_recursive_targets)
+AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
+ distdir distdir-am
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+ dir0=`pwd`; \
+ sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+ sed_rest='s,^[^/]*/*,,'; \
+ sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+ sed_butlast='s,/*[^/]*$$,,'; \
+ while test -n "$$dir1"; do \
+ first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+ if test "$$first" != "."; then \
+ if test "$$first" = ".."; then \
+ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+ else \
+ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+ if test "$$first2" = "$$first"; then \
+ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+ else \
+ dir2="../$$dir2"; \
+ fi; \
+ dir0="$$dir0"/"$$first"; \
+ fi; \
+ fi; \
+ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+ done; \
+ reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+ASCIIDOC = @ASCIIDOC@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BOOST_INCLUDES = @BOOST_INCLUDES@
+BOOST_LIBS = @BOOST_LIBS@
+BOTAN_TOOL = @BOTAN_TOOL@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONTRIB_DIR = @CONTRIB_DIR@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CRYPTO_CFLAGS = @CRYPTO_CFLAGS@
+CRYPTO_INCLUDES = @CRYPTO_INCLUDES@
+CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@
+CRYPTO_LIBS = @CRYPTO_LIBS@
+CRYPTO_PACKAGE = @CRYPTO_PACKAGE@
+CRYPTO_RPATH = @CRYPTO_RPATH@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@
+DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@
+DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@
+DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@
+DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@
+DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@
+DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@
+DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GENHTML = @GENHTML@
+GREP = @GREP@
+GSSAPI_CFLAGS = @GSSAPI_CFLAGS@
+GSSAPI_LIBS = @GSSAPI_LIBS@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_SOURCE = @GTEST_SOURCE@
+HAVE_SYSREPO = @HAVE_SYSREPO@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+KEA_CXXFLAGS = @KEA_CXXFLAGS@
+KEA_SRCID = @KEA_SRCID@
+KRB5_CONFIG = @KRB5_CONFIG@
+LCOV = @LCOV@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@
+LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@
+MYSQL_LIBS = @MYSQL_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PDFLATEX = @PDFLATEX@
+PERL = @PERL@
+PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@
+PGSQL_LIBS = @PGSQL_LIBS@
+PKGPYTHONDIR = @PKGPYTHONDIR@
+PKG_CONFIG = @PKG_CONFIG@
+PLANTUML = @PLANTUML@
+PREMIUM_DIR = @PREMIUM_DIR@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+SED = @SED@
+SEP = @SEP@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SPHINXBUILD = @SPHINXBUILD@
+SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@
+SR_REPO_PATH = @SR_REPO_PATH@
+STRIP = @STRIP@
+SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@
+SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@
+SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@
+SYSREPO_LIBS = @SYSREPO_LIBS@
+SYSREPO_VERSION = @SYSREPO_VERSION@
+USE_LCOV = @USE_LCOV@
+VALGRIND = @VALGRIND@
+VERSION = @VERSION@
+WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@
+YACC = @YACC@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+SUBDIRS = . testutils pretests tests
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib \
+ $(BOOST_INCLUDES) $(SYSREPO_CPPFLAGS) $(SYSREPO_INCLUDEDIR)
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+lib_LTLIBRARIES = libkea-yang.la
+libkea_yang_la_SOURCES = adaptor.cc adaptor.h adaptor_host.cc \
+ adaptor_host.h adaptor_pool.cc adaptor_pool.h \
+ adaptor_option.cc adaptor_option.h adaptor_subnet.cc \
+ adaptor_subnet.h adaptor_config.cc adaptor_config.h \
+ sysrepo_error.h translator.cc translator.h \
+ translator_control_socket.cc translator_control_socket.h \
+ translator_database.cc translator_database.h \
+ translator_logger.cc translator_logger.h \
+ translator_option_data.cc translator_option_data.h \
+ translator_option_def.cc translator_option_def.h \
+ translator_class.cc translator_class.h translator_pool.cc \
+ translator_pool.h translator_pd_pool.cc translator_pd_pool.h \
+ translator_host.cc translator_host.h translator_subnet.cc \
+ translator_subnet.h translator_shared_network.cc \
+ translator_shared_network.h translator_config.cc \
+ translator_config.h yang_models.h yang_revisions.h
+libkea_yang_la_LIBADD = \
+ $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \
+ $(top_builddir)/src/lib/cc/libkea-cc.la \
+ $(top_builddir)/src/lib/log/libkea-log.la \
+ $(top_builddir)/src/lib/util/libkea-util.la \
+ $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \
+ $(LOG4CPLUS_LIBS) $(BOOST_LIBS) $(SYSREPO_LIBS)
+libkea_yang_la_LDFLAGS = -no-undefined -version-info 29:0:0
+
+# Specify the headers for copying into the installation directory tree.
+libkea_yang_includedir = $(pkgincludedir)/yang
+libkea_yang_include_HEADERS = \
+ adaptor.h \
+ adaptor_config.h \
+ adaptor_host.h \
+ adaptor_option.h \
+ adaptor_pool.h \
+ adaptor_subnet.h \
+ sysrepo_error.h \
+ translator.h \
+ translator_class.h \
+ translator_config.h \
+ translator_control_socket.h \
+ translator_database.h \
+ translator_host.h \
+ translator_logger.h \
+ translator_option_data.h \
+ translator_option_def.h \
+ translator_pd_pool.h \
+ translator_pool.h \
+ translator_shared_network.h \
+ translator_subnet.h \
+ yang_models.h \
+ yang_revisions.h
+
+EXTRA_DIST = yang.dox yang_revisions.h.skel
+CLEANFILES = *.gcno *.gcda
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .cc .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/yang/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/lib/yang/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+ }
+
+uninstall-libLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
+ done
+
+clean-libLTLIBRARIES:
+ -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+ @list='$(lib_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
+libkea-yang.la: $(libkea_yang_la_OBJECTS) $(libkea_yang_la_DEPENDENCIES) $(EXTRA_libkea_yang_la_DEPENDENCIES)
+ $(AM_V_CXXLD)$(libkea_yang_la_LINK) -rpath $(libdir) $(libkea_yang_la_OBJECTS) $(libkea_yang_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adaptor.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adaptor_config.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adaptor_host.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adaptor_option.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adaptor_pool.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adaptor_subnet.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_class.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_config.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_control_socket.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_database.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_host.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_logger.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_option_data.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_option_def.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_pd_pool.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_pool.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_shared_network.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translator_subnet.Plo@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.cc.o:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cc.lo:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+install-libkea_yang_includeHEADERS: $(libkea_yang_include_HEADERS)
+ @$(NORMAL_INSTALL)
+ @list='$(libkea_yang_include_HEADERS)'; test -n "$(libkea_yang_includedir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(libkea_yang_includedir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(libkea_yang_includedir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libkea_yang_includedir)'"; \
+ $(INSTALL_HEADER) $$files "$(DESTDIR)$(libkea_yang_includedir)" || exit $$?; \
+ done
+
+uninstall-libkea_yang_includeHEADERS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(libkea_yang_include_HEADERS)'; test -n "$(libkea_yang_includedir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(libkea_yang_includedir)'; $(am__uninstall_files_from_dir)
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run 'make' without going through this Makefile.
+# To change the values of 'make' variables: instead of editing Makefiles,
+# (1) if the variable is set in 'config.status', edit 'config.status'
+# (which will cause the Makefiles to be regenerated when you run 'make');
+# (2) otherwise, pass the desired values on the 'make' command line.
+$(am__recursive_targets):
+ @fail=; \
+ if $(am__make_keepgoing); then \
+ failcom='fail=yes'; \
+ else \
+ failcom='exit 1'; \
+ fi; \
+ dot_seen=no; \
+ target=`echo $@ | sed s/-recursive//`; \
+ case "$@" in \
+ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+ *) list='$(SUBDIRS)' ;; \
+ esac; \
+ for subdir in $$list; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+ fi; test -z "$$fail"
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-recursive
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+ include_option=--etags-include; \
+ empty_fix=.; \
+ else \
+ include_option=--include; \
+ empty_fix=; \
+ fi; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test ! -f $$subdir/TAGS || \
+ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+ fi; \
+ done; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-recursive
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-recursive
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+ @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ $(am__make_dryrun) \
+ || test -d "$(distdir)/$$subdir" \
+ || $(MKDIR_P) "$(distdir)/$$subdir" \
+ || exit 1; \
+ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+ $(am__relativize); \
+ new_distdir=$$reldir; \
+ dir1=$$subdir; dir2="$(top_distdir)"; \
+ $(am__relativize); \
+ new_top_distdir=$$reldir; \
+ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+ ($(am__cd) $$subdir && \
+ $(MAKE) $(AM_MAKEFLAGS) \
+ top_distdir="$$new_top_distdir" \
+ distdir="$$new_distdir" \
+ am__remove_distdir=: \
+ am__skip_length_check=: \
+ am__skip_mode_fix=: \
+ distdir) \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs: installdirs-recursive
+installdirs-am:
+ for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libkea_yang_includedir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+ mostlyclean-am
+
+distclean: distclean-recursive
+ -rm -f ./$(DEPDIR)/adaptor.Plo
+ -rm -f ./$(DEPDIR)/adaptor_config.Plo
+ -rm -f ./$(DEPDIR)/adaptor_host.Plo
+ -rm -f ./$(DEPDIR)/adaptor_option.Plo
+ -rm -f ./$(DEPDIR)/adaptor_pool.Plo
+ -rm -f ./$(DEPDIR)/adaptor_subnet.Plo
+ -rm -f ./$(DEPDIR)/translator.Plo
+ -rm -f ./$(DEPDIR)/translator_class.Plo
+ -rm -f ./$(DEPDIR)/translator_config.Plo
+ -rm -f ./$(DEPDIR)/translator_control_socket.Plo
+ -rm -f ./$(DEPDIR)/translator_database.Plo
+ -rm -f ./$(DEPDIR)/translator_host.Plo
+ -rm -f ./$(DEPDIR)/translator_logger.Plo
+ -rm -f ./$(DEPDIR)/translator_option_data.Plo
+ -rm -f ./$(DEPDIR)/translator_option_def.Plo
+ -rm -f ./$(DEPDIR)/translator_pd_pool.Plo
+ -rm -f ./$(DEPDIR)/translator_pool.Plo
+ -rm -f ./$(DEPDIR)/translator_shared_network.Plo
+ -rm -f ./$(DEPDIR)/translator_subnet.Plo
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-libkea_yang_includeHEADERS
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am: install-libLTLIBRARIES
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+ -rm -f ./$(DEPDIR)/adaptor.Plo
+ -rm -f ./$(DEPDIR)/adaptor_config.Plo
+ -rm -f ./$(DEPDIR)/adaptor_host.Plo
+ -rm -f ./$(DEPDIR)/adaptor_option.Plo
+ -rm -f ./$(DEPDIR)/adaptor_pool.Plo
+ -rm -f ./$(DEPDIR)/adaptor_subnet.Plo
+ -rm -f ./$(DEPDIR)/translator.Plo
+ -rm -f ./$(DEPDIR)/translator_class.Plo
+ -rm -f ./$(DEPDIR)/translator_config.Plo
+ -rm -f ./$(DEPDIR)/translator_control_socket.Plo
+ -rm -f ./$(DEPDIR)/translator_database.Plo
+ -rm -f ./$(DEPDIR)/translator_host.Plo
+ -rm -f ./$(DEPDIR)/translator_logger.Plo
+ -rm -f ./$(DEPDIR)/translator_option_data.Plo
+ -rm -f ./$(DEPDIR)/translator_option_def.Plo
+ -rm -f ./$(DEPDIR)/translator_pd_pool.Plo
+ -rm -f ./$(DEPDIR)/translator_pool.Plo
+ -rm -f ./$(DEPDIR)/translator_shared_network.Plo
+ -rm -f ./$(DEPDIR)/translator_subnet.Plo
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-libLTLIBRARIES \
+ uninstall-libkea_yang_includeHEADERS
+
+.MAKE: $(am__recursive_targets) install-am install-strip
+
+.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \
+ am--depfiles check check-am clean clean-generic \
+ clean-libLTLIBRARIES clean-libtool cscopelist-am ctags \
+ ctags-am distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-libLTLIBRARIES \
+ install-libkea_yang_includeHEADERS install-man install-pdf \
+ install-pdf-am install-ps install-ps-am install-strip \
+ installcheck installcheck-am installdirs installdirs-am \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \
+ uninstall-libLTLIBRARIES uninstall-libkea_yang_includeHEADERS
+
+.PRECIOUS: Makefile
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/lib/yang/adaptor.cc b/src/lib/yang/adaptor.cc
new file mode 100644
index 0000000..2de0a29
--- /dev/null
+++ b/src/lib/yang/adaptor.cc
@@ -0,0 +1,308 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor.h>
+#include <boost/foreach.hpp>
+
+#include <iostream>
+
+using namespace std;
+using namespace isc::data;
+
+namespace isc {
+namespace yang {
+
+Adaptor::Adaptor() {
+}
+
+Adaptor::~Adaptor() {
+}
+
+ConstElementPtr
+Adaptor::getContext(ConstElementPtr parent)
+{
+ ConstElementPtr context = parent->get("user-context");
+ ConstElementPtr comment = parent->get("comment");
+ if (!comment) {
+ return (context);
+ }
+ ElementPtr result;
+ if (context) {
+ result = copy(context);
+ } else {
+ result = Element::createMap();
+ }
+ result->set("comment", comment);
+ return (result);
+}
+
+void
+Adaptor::fromParent(const string& name, ConstElementPtr parent,
+ ConstElementPtr list) {
+ ConstElementPtr param = parent->get(name);
+ if (!param) {
+ return;
+ }
+ BOOST_FOREACH(ElementPtr item, list->listValue()) {
+ // don't override. Skip this entry if it already has the parameter.
+ if (item->contains(name)) {
+ continue;
+ }
+ item->set(name, param);
+ }
+}
+
+void
+Adaptor::toParent(const string& name, ElementPtr parent,
+ ConstElementPtr list) {
+ ConstElementPtr param;
+ bool first = true;
+ BOOST_FOREACH(ElementPtr item, list->listValue()) {
+ if (first) {
+ first = false;
+ param = item->get(name);
+ } else if ((!param && item->contains(name)) ||
+ (param && !item->contains(name)) ||
+ (param && item->contains(name) &&
+ !param->equals(*item->get(name)))) {
+ isc_throw(BadValue,
+ "inconsistent value of " << name
+ << " in " << list->str());
+ }
+ }
+ if (!first && param) {
+ BOOST_FOREACH(ElementPtr item, list->listValue()) {
+ if (param) {
+ item->remove(name);
+ }
+ }
+ parent->set(name, param);
+ }
+}
+
+namespace {
+
+/// @brief Apply insert.
+///
+/// This function applies an insert action at the given scope:
+/// - in a map it adds the value at the key when the key does not exist
+/// - in a list it appends the value
+/// - in other scope type it does nothing
+/// @note a copy of the value is used to avoid unwanted sharing/side effects.
+///
+/// @param key The key of the modification.
+/// @param value The value of the modification.
+/// @param scope The place to apply the insert.
+void applyInsert(ConstElementPtr key, ConstElementPtr value,
+ ElementPtr scope) {
+ if (scope->getType() == Element::map) {
+ if (!key || !value || (key->getType() != Element::string)) {
+ return;
+ }
+ string name = key->stringValue();
+ if (!name.empty() && !scope->contains(name)) {
+ scope->set(name, copy(value));
+ }
+ } else if (scope->getType() == Element::list) {
+ if (value) {
+ scope->add(copy(value));
+ }
+ }
+}
+
+/// @brief Apply replace.
+///
+/// This function works only on map scopes and acts as insert at the
+/// exception the new value is set even if the key already exists.
+///
+/// @param key The key of the modification.
+/// @param value The value of the modification.
+/// @param scope The place to apply the replace.
+void applyReplace(ConstElementPtr key, ConstElementPtr value,
+ ElementPtr scope) {
+ if ((scope->getType() != Element::map) ||
+ !key || !value || (key->getType() != Element::string)) {
+ return;
+ }
+ string name = key->stringValue();
+ if (!name.empty()) {
+ scope->set(name, copy(value));
+ }
+}
+
+/// @brief Apply delete.
+///
+/// This function deletes the value designed by the key from the given scope:
+/// - in a map the key is the key of the value to remove
+/// - in a list the key is:
+/// * when it is an integer the index of the value to remove
+/// * when it is a map the key / value pair which belongs to the value
+/// to remove
+/// - in other scope type it does nothing
+///
+/// @param key The key item of the path.
+/// @param scope The place to apply the delete.
+void applyDelete(ConstElementPtr key, ElementPtr scope) {
+ if (scope->getType() == Element::map) {
+ if (!key || (key->getType() != Element::string)) {
+ return;
+ }
+ string name = key->stringValue();
+ if (!name.empty()) {
+ scope->remove(name);
+ }
+ } else if (scope->getType() == Element::list) {
+ if (!key) {
+ return;
+ } else if (key->getType() == Element::integer) {
+ int index = key->intValue();
+ if ((index >= 0) && (index < scope->size())) {
+ scope->remove(index);
+ }
+ } else if (key->getType() == Element::map) {
+ ConstElementPtr entry = key->get("key");
+ ConstElementPtr value = key->get("value");
+ if (!entry || !value || (entry->getType() != Element::string)) {
+ return;
+ }
+ string name = entry->stringValue();
+ if (name.empty()) {
+ return;
+ }
+ for (int i = 0; i < scope->size(); ++i) {
+ ConstElementPtr item = scope->get(i);
+ if (!item || (item->getType() != Element::map)) {
+ continue;
+ }
+ ConstElementPtr compare = item->get(name);
+ if (compare && value->equals(*compare)) {
+ scope->remove(i);
+ return;
+ }
+ }
+ }
+ }
+}
+
+/// @brief Apply action.
+///
+/// This function applies one action (insert, replace or delete) using
+/// applyInsert, applyReplace or applyDelete.
+///
+/// @param actions The action list.
+/// @param scope The current scope.
+/// @param next The index of the next action.
+void applyAction(ConstElementPtr actions, ElementPtr scope, size_t next) {
+ if (next == actions->size()) {
+ return;
+ }
+ ConstElementPtr action = actions->get(next);
+ ++next;
+ if (!action || (action->getType() != Element::map) ||
+ !action->contains("action")) {
+ applyAction(actions, scope, next);
+ return;
+ }
+ string name = action->get("action")->stringValue();
+ if (name == "insert") {
+ applyInsert(action->get("key"), action->get("value"), scope);
+ } else if (name == "replace") {
+ applyReplace(action->get("key"), action->get("value"), scope);
+ } else if (name == "delete") {
+ applyDelete(action->get("key"), scope);
+ }
+ applyAction(actions, scope, next);
+}
+
+/// @brief Apply recursively actions following the path and going down
+/// in the to-be-modified structure.
+///
+/// The recursive call when the end of the path is not reached is done:
+/// - in a map on the value at the key
+/// - in a list the next path item is:
+/// * if it is a positive integer on the value at the index
+/// * if it is -1 on all elements of the list
+/// * if a map on the element where the key / value pair belongs to
+///
+/// @param path The search list.
+/// @param actions The action list.
+/// @param scope The current scope.
+/// @param next The index of the next item to use in the path.
+void applyDown(ConstElementPtr path, ConstElementPtr actions, ElementPtr scope,
+ size_t next) {
+ if (!scope) {
+ return;
+ }
+ if (next == path->size()) {
+ applyAction(actions, scope, 0);
+ return;
+ }
+ ConstElementPtr step = path->get(next);
+ ++next;
+ if (scope->getType() == Element::map) {
+ if (!step || (step->getType() != Element::string)) {
+ return;
+ }
+ string name = step->stringValue();
+ if (name.empty() || !scope->contains(name)) {
+ return;
+ }
+ ElementPtr down = boost::const_pointer_cast<Element>(scope->get(name));
+ if (down) {
+ applyDown(path, actions, down, next);
+ }
+ } else if (scope->getType() == Element::list) {
+ if (!step) {
+ return;
+ }
+ auto downs = scope->listValue();
+ if (step->getType() == Element::map) {
+ ConstElementPtr key = step->get("key");
+ ConstElementPtr value = step->get("value");
+ if (!key || !value || (key->getType() != Element::string)) {
+ return;
+ }
+ string name = key->stringValue();
+ if (name.empty()) {
+ return;
+ }
+ for (ElementPtr down : downs) {
+ if (!down || (down->getType() != Element::map)) {
+ continue;
+ }
+ ConstElementPtr compare = down->get(name);
+ if (compare && value->equals(*compare)) {
+ applyDown(path, actions, down, next);
+ return;
+ }
+ }
+ } else if (step->getType() != Element::integer) {
+ return;
+ }
+ int index = step->intValue();
+ if (index == -1) {
+ for (ElementPtr down : downs) {
+ applyDown(path, actions, down, next);
+ }
+ } else if ((index >= 0) && (index < scope->size())) {
+ applyDown(path, actions, scope->getNonConst(index), next);
+ }
+ }
+}
+
+} // end of anonymous namespace
+
+/// Apply recursively starting at the beginning of the path.
+void
+Adaptor::modify(ConstElementPtr path, ConstElementPtr actions,
+ ElementPtr config) {
+ applyDown(path, actions, config, 0);
+}
+
+} // end of namespace isc::yang
+} // end of namespace isc
diff --git a/src/lib/yang/adaptor.h b/src/lib/yang/adaptor.h
new file mode 100644
index 0000000..8d1fdf3
--- /dev/null
+++ b/src/lib/yang/adaptor.h
@@ -0,0 +1,133 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_ADAPTOR_H
+#define ISC_ADAPTOR_H 1
+
+#include <exceptions/exceptions.h>
+#include <cc/data.h>
+
+namespace isc {
+namespace yang {
+
+/// @brief Missing key error.
+class MissingKey : public isc::Exception {
+public:
+ MissingKey(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what)
+ {}
+};
+
+/// @brief JSON adaptor between canonical Kea and YANG models.
+///
+/// An adaptor slightly modifies a JSON configuration between canonical Kea
+/// what required or rendered by a YANG model, e.g. moving a parameter
+/// to/from a parent.
+/// The basic adaptor provides a set of tools.
+class Adaptor {
+public:
+
+ /// @brief Constructor.
+ Adaptor();
+
+ /// @brief Destructor.
+ virtual ~Adaptor();
+
+ /// @brief Get user context.
+ ///
+ /// Get user-context and/or comment and return it with the comment
+ /// if exists moved inside the user-context (without checking if
+ /// there is already a comment as it should never be the case).
+ ///
+ /// This behavior is used to handle comments. For historical purposes
+ /// Kea allows to define comments in some scopes. Once the user-context
+ /// has been introduced, the comment (as a separate text field)
+ /// disappeared and was moved to comment key within user-context.
+ /// Nevertheless, the old syntax is still supported.
+ static isc::data::ConstElementPtr
+ getContext(isc::data::ConstElementPtr parent);
+
+ /// @brief Moves a parameter from parent to a list of children.
+ ///
+ /// Move a parameter from the parent to each item in a list.
+ /// If the parameter exists in a child, it is skipped for this
+ /// particular child, not overridden.
+ ///
+ /// @param name The parameter name.
+ /// @param parent The parent element.
+ /// @param list The children list.
+ static void fromParent(const std::string& name,
+ isc::data::ConstElementPtr parent,
+ isc::data::ConstElementPtr list);
+
+ /// @brief Moves a parameter to a parent.
+ ///
+ /// Move a parameter from children to the parent. All children
+ /// on the list must have the parameter specified and it has to have
+ /// the same value.
+ ///
+ /// @param name The parameter name.
+ /// @param parent The parent element.
+ /// @param list The children list.
+ static void toParent(const std::string& name,
+ isc::data::ElementPtr parent,
+ isc::data::ConstElementPtr list);
+
+ /// @brief Modify a configuration in its JSON element format.
+ ///
+ /// Smart merging tool, e.g. completing a from yang configuration.
+ ///
+ /// A modification is a path and actions:
+ /// - path item can be:
+ /// * a string: current scope is a map, go down following the string
+ /// as a key.
+ /// * a number: current scope is a list, go down the number as an index.
+ /// * special value -1: current scope is a list, apply to all items.
+ /// * map { "<key>": <value> }: current scope is a list, go down to
+ /// the item using the key / value pair.
+ /// - an action can be: insert, replace or delete:
+ /// * insert adds a value at a key:
+ /// . in a map the key is the new entry key
+ /// . in a list an integer key is the new element index
+ /// . in a list a map key is the key / value pair the to-be-modified
+ /// element contains
+ /// * replace adds or replaces if it already exists a value at
+ /// an entry key in a map.
+ /// * delete removes a value designed by a key
+ ///
+ /// For instance to add a control-socket entry in a configuration
+ /// from a generic (vs Kea) model:
+ /// @code
+ /// path := [ ]
+ /// actions := [ {
+ /// "action": "insert",
+ /// "key": "Dhcp4",
+ /// "value":
+ /// {
+ /// "control-socket":
+ /// {
+ /// "socket-type": "unix",
+ /// "socket-name": "/tmp/kea4-ctrl-socket"
+ /// }
+ /// }
+ /// }
+ /// @endcode
+ ///
+ /// @param path The search list to follow down to the place to
+ /// apply the action list.
+ /// @param actions The action list
+ /// @param config The configuration (JSON map) to modify.
+ /// @note modify does not throw but returns on unexpected conditions.
+ static void modify(isc::data::ConstElementPtr path,
+ isc::data::ConstElementPtr actions,
+ isc::data::ElementPtr config);
+
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_ADAPTOR_H
diff --git a/src/lib/yang/adaptor_config.cc b/src/lib/yang/adaptor_config.cc
new file mode 100644
index 0000000..2fff557
--- /dev/null
+++ b/src/lib/yang/adaptor_config.cc
@@ -0,0 +1,658 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor_config.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::dhcp;
+
+namespace {
+const string DHCP4_SPACE = "dhcp4";
+const string DHCP6_SPACE = "dhcp6";
+}
+
+namespace isc {
+namespace yang {
+
+AdaptorConfig::AdaptorConfig() {
+}
+
+AdaptorConfig::~AdaptorConfig() {
+}
+
+bool
+AdaptorConfig::subnetsCollectID(ConstElementPtr subnets, SubnetIDSet& set) {
+ bool have_ids = true;
+
+ if (!subnets || subnets->empty()) {
+ // There are no subnets defined, so technically there are no ids.
+ // However, the flag is used to determine whether the code later
+ // needs to call assignIDs. Since there is no need to assign
+ // anything, the code returns true here.
+ return (true);
+ }
+
+ // If there are subnets defined, let's go over them one by one and
+ // collect subnet-ids used in them.
+ for (ConstElementPtr subnet : subnets->listValue()) {
+ if (!collectID(subnet, set)) {
+ have_ids = false;
+ }
+ }
+ return (have_ids);
+}
+
+bool
+AdaptorConfig::sharedNetworksCollectID(ConstElementPtr networks,
+ SubnetIDSet& set,
+ const string& subsel) {
+ if (!networks || networks->empty()) {
+ // There are no shared networks defined, so technically there are no
+ // ids. However, the flag is used to determine whether the code later
+ // needs to call assignIDs. Since there is no need to assign anything,
+ // the code returns true here.
+ return (true);
+ }
+
+ // This determines if EVERY subnet has subnet-id defined.
+ bool have_ids = true;
+ for (size_t i = 0; i < networks->size(); ++i) {
+ ElementPtr network = networks->getNonConst(i);
+ ConstElementPtr subnets = network->get(subsel);
+ if (subnets) {
+ if (!subnets->empty()) {
+ // If there are subnets, collect their subnet-ids. If any
+ // of them doesn't have a subnet-id, return false.
+ if (!subnetsCollectID(subnets, set)) {
+ have_ids = false;
+ }
+ } else {
+ // There's empty subnets list, so just remove it.
+ network->remove(subsel);
+ }
+ }
+ }
+ return (have_ids);
+}
+
+void
+AdaptorConfig::subnetsAssignID(ConstElementPtr subnets, SubnetIDSet& set,
+ SubnetID& next) {
+ if (!subnets || subnets->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < subnets->size(); ++i) {
+ ElementPtr subnet = subnets->getNonConst(i);
+ assignID(subnet, set, next);
+ }
+}
+
+void
+AdaptorConfig::sharedNetworksAssignID(ConstElementPtr networks,
+ SubnetIDSet& set, SubnetID& next,
+ const string& subsel) {
+ if (!networks || networks->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (ConstElementPtr network : networks->listValue()) {
+ ConstElementPtr subnets = network->get(subsel);
+ if (!subnets || subnets->empty()) {
+ continue;
+ }
+
+ for (size_t i = 0; i < subnets->size(); ++i) {
+ ElementPtr subnet = subnets->getNonConst(i);
+ assignID(subnet, set, next);
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizePools(ConstElementPtr pools) {
+ if (!pools || pools->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ // Canonize (clean up name, remove extra spaces, add one space where
+ // needed) every pool on the list.
+ for (size_t i = 0; i < pools->size(); ++i) {
+ ElementPtr pool = pools->getNonConst(i);
+ AdaptorPool::canonizePool(pool);
+ }
+}
+
+void
+AdaptorConfig::sanitizePoolsInSubnets(ConstElementPtr subnets) {
+ if (!subnets || subnets->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (ConstElementPtr subnet : subnets->listValue()) {
+ sanitizePools(subnet->get("pools"));
+ }
+}
+
+void
+AdaptorConfig::sanitizePoolsInSharedNetworks(ConstElementPtr networks,
+ const string& subsel) {
+ if (!networks || networks->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (ConstElementPtr network : networks->listValue()) {
+ sanitizePoolsInSubnets(network->get(subsel));
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionDefList(ConstElementPtr defs,
+ const string& space,
+ OptionCodes& codes) {
+ if (!defs || defs->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ // Do sanity checks on every option definition and fill any missing
+ // fields with default values.
+ for (size_t i = 0; i < defs->size(); ++i) {
+ ElementPtr def = defs->getNonConst(i);
+ checkCode(def);
+ checkType(def);
+ setSpace(def, space);
+ collect(def, codes);
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionDataList(ConstElementPtr options,
+ const string& space,
+ const OptionCodes& codes) {
+ if (!options || options->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ // Sanitize option-data. The only missing elements we may possibly
+ // need to fill are option space and option code.
+ for (size_t i = 0; i < options->size(); ++i) {
+ ElementPtr option = options->getNonConst(i);
+ setSpace(option, space);
+ setCode(option, codes);
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionClasses(ConstElementPtr classes,
+ const string& space,
+ OptionCodes& codes) {
+ if (!classes || classes->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ // For every client class defined...
+ for (size_t i = 0; i < classes->size(); ++i) {
+ ElementPtr cclass = classes->getNonConst(i);
+
+ if (space == DHCP4_SPACE) {
+ ConstElementPtr options = cclass->get("option-def");
+ if (options) {
+ if (!options->empty()) {
+ // If present, sanitize it.
+ sanitizeOptionDefList(options, space, codes);
+ } else {
+ // If empty, remove it.
+ cclass->remove("option-def");
+ }
+ }
+ }
+
+ // also sanitize option data.
+ ConstElementPtr options = cclass->get("option-data");
+ if (options) {
+ if (!options->empty()) {
+ // If present, sanitize it.
+ sanitizeOptionDataList(options, space, codes);
+ } else {
+ // If empty, remove it.
+ cclass->remove("option-data");
+ }
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionPools(ConstElementPtr pools, const string& space,
+ const OptionCodes& codes) {
+ if (!pools || pools->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < pools->size(); ++i) {
+ ElementPtr pool = pools->getNonConst(i);
+ ConstElementPtr options = pool->get("option-data");
+ if (options) {
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
+ } else {
+ pool->remove("option-data");
+ }
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionHosts(ConstElementPtr hosts, const string& space,
+ const OptionCodes& codes) {
+ if (!hosts || hosts->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < hosts->size(); ++i) {
+ ElementPtr host = hosts->getNonConst(i);
+ ConstElementPtr options = host->get("option-data");
+ if (options) {
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
+ } else {
+ host->remove("option-data");
+ }
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionSubnets(ConstElementPtr subnets,
+ const string& space,
+ const OptionCodes& codes) {
+ if (!subnets || subnets->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < subnets->size(); ++i) {
+ ElementPtr subnet = subnets->getNonConst(i);
+
+ // Let's try to sanitize option-data first.
+ ConstElementPtr options = subnet->get("option-data");
+ if (options) {
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
+ } else {
+ subnet->remove("option-data");
+ }
+ }
+
+ // Then try to sanitize pools.
+ ConstElementPtr pools = subnet->get("pools");
+ if (pools) {
+ if (!pools->empty()) {
+ sanitizeOptionPools(pools, space, codes);
+ } else {
+ subnet->remove("pools");
+ }
+ }
+
+ // If this is v6, also sanitize pd-pools.
+ if (space == DHCP6_SPACE) {
+ ConstElementPtr pools = subnet->get("pd-pools");
+ if (pools) {
+ if (!pools->empty()) {
+ sanitizeOptionPools(pools, space, codes);
+ } else {
+ subnet->remove("pd-pools");
+ }
+ }
+ }
+
+ // Finally, sanitize host reservations.
+ ConstElementPtr hosts = subnet->get("reservations");
+ if (hosts) {
+ if (!hosts->empty()) {
+ sanitizeOptionHosts(hosts, space, codes);
+ } else {
+ subnet->remove("reservations");
+ }
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeOptionSharedNetworks(ConstElementPtr networks,
+ const string& space,
+ const OptionCodes& codes) {
+ if (!networks || networks->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ // For every shared network...
+ for (size_t i = 0; i < networks->size(); ++i) {
+ ElementPtr network = networks->getNonConst(i);
+
+ // try to sanitize shared network options first.
+ ConstElementPtr options = network->get("option-data");
+ if (options) {
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
+ } else {
+ network->remove("option-data");
+ }
+ }
+ string subnet = "subnet";
+ if (space == DHCP4_SPACE) {
+ subnet += "4";
+ } else {
+ subnet += "6";
+ }
+
+ // Now try to sanitize subnets.
+ ConstElementPtr subnets = network->get(subnet);
+ if (subnets) {
+ if (!subnets->empty()) {
+ sanitizeOptionSubnets(subnets, space, codes);
+ } else {
+ network->remove(subnet);
+ }
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeRequireClassesPools(ConstElementPtr pools) {
+ if (!pools || pools->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < pools->size(); ++i) {
+ ElementPtr pool = pools->getNonConst(i);
+ ConstElementPtr requires = pool->get("require-client-classes");
+ if (requires && requires->empty()) {
+ pool->remove("require-client-classes");
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeRequireClassesSubnets(ConstElementPtr subnets) {
+ if (!subnets || subnets->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < subnets->size(); ++i) {
+ ElementPtr subnet = subnets->getNonConst(i);
+ sanitizeRequireClassesPools(subnet->get("pools"));
+ sanitizeRequireClassesPools(subnet->get("pd-pools"));
+ ConstElementPtr requires = subnet->get("require-client-classes");
+ if (requires && requires->empty()) {
+ subnet->remove("require-client-classes");
+ }
+ }
+}
+
+void
+AdaptorConfig::requireClassesSharedNetworks(ConstElementPtr networks,
+ const string& subsel) {
+ if (!networks || networks->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < networks->size(); ++i) {
+ ElementPtr network = networks->getNonConst(i);
+ sanitizeRequireClassesSubnets(network->get(subsel));
+ ConstElementPtr requires = network->get("require-client-classes");
+ if (requires && requires->empty()) {
+ network->remove("require-client-classes");
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeHostList(ConstElementPtr hosts) {
+
+ if (!hosts || hosts->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < hosts->size(); ++i) {
+ ElementPtr host = hosts->getNonConst(i);
+ quoteIdentifier(host);
+ }
+}
+
+void
+AdaptorConfig::sanitizeHostSubnets(ConstElementPtr subnets) {
+
+ if (!subnets || subnets->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (ConstElementPtr subnet : subnets->listValue()) {
+ sanitizeHostList(subnet->get("reservations"));
+ }
+}
+
+void
+AdaptorConfig::SanitizeHostsInSharedNetworks(ConstElementPtr networks,
+ const string& space) {
+ if (!networks || networks->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (ConstElementPtr network : networks->listValue()) {
+ if (space == DHCP4_SPACE) {
+ sanitizeHostSubnets(network->get("subnet4"));
+ } else {
+ sanitizeHostSubnets(network->get("subnet6"));
+ }
+ }
+}
+
+void
+AdaptorConfig::sanitizeRelaySubnets(ConstElementPtr subnets) {
+ if (!subnets || subnets->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < subnets->size(); ++i) {
+ ElementPtr subnet = subnets->getNonConst(i);
+ updateRelay(subnet);
+ }
+}
+
+void
+AdaptorConfig::sanitizeRelayInSharedNetworks(ConstElementPtr networks,
+ const string& subsel) {
+ if (!networks || networks->empty()) {
+ // nothing to do here.
+ return;
+ }
+
+ for (size_t i = 0; i < networks->size(); ++i) {
+ ElementPtr network = networks->getNonConst(i);
+ updateRelay(network);
+ sanitizeRelaySubnets(network->get(subsel));
+ }
+}
+
+void
+AdaptorConfig::sanitizeDatabase(ConstElementPtr dhcp) {
+ ConstElementPtr database = dhcp->get("hosts-database");
+ if (!database) {
+ // nothing to do here.
+ return;
+ }
+
+ ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+ mutable_dhcp->remove("hosts-database");
+ ElementPtr list = Element::createList();
+ list->add(boost::const_pointer_cast<Element>(database));
+ mutable_dhcp->set("hosts-databases", list);
+}
+
+void
+AdaptorConfig::sanitizeRelaySuppliedOptions(ConstElementPtr dhcp) {
+ ConstElementPtr options = dhcp->get("relay-supplied-options");
+ if (!options || !options->empty()) {
+ // nothing to do here.
+ return;
+ }
+ ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+ mutable_dhcp->remove("relay-supplied-options");
+}
+
+void
+AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
+ const string& space) {
+ if (!dhcp) {
+ isc_throw(BadValue, "preProcess: null DHCP config");
+ }
+ bool have_ids = true;
+ SubnetIDSet set;
+ ConstElementPtr subnets = dhcp->get(subsel);
+ if (subnets) {
+ if (!subnets->empty()) {
+ if (!subnetsCollectID(subnets, set)) {
+ have_ids = false;
+ }
+ } else {
+ dhcp->remove(subsel);
+ }
+ }
+ ConstElementPtr networks = dhcp->get("shared-networks");
+ if (networks) {
+ if (!networks->empty()) {
+ if (!sharedNetworksCollectID(networks, set, subsel)) {
+ have_ids = false;
+ }
+ } else {
+ dhcp->remove("shared-networks");
+ }
+ }
+
+ if (!have_ids) {
+ SubnetID next(1);
+ subnetsAssignID(subnets, set, next);
+ sharedNetworksAssignID(networks, set, next, subsel);
+ }
+
+ OptionCodes codes;
+ initCodes(codes, space);;
+ ConstElementPtr defs = dhcp->get("option-def");
+ if (defs) {
+ if (!defs->empty()) {
+ sanitizeOptionDefList(defs, space, codes);
+ } else {
+ dhcp->remove("option-def");
+ }
+ }
+ ConstElementPtr options = dhcp->get("option-data");
+ if (options) {
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
+ } else {
+ dhcp->remove("option-data");
+ }
+ }
+ ConstElementPtr classes = dhcp->get("client-classes");
+ if (classes) {
+ if (!classes->empty()) {
+ sanitizeOptionClasses(classes, space, codes);
+ } else {
+ dhcp->remove("client-classes");
+ }
+ }
+ ConstElementPtr hosts = dhcp->get("reservations");
+ if (hosts) {
+ if (!hosts->empty()) {
+ sanitizeHostList(hosts);
+ sanitizeOptionHosts(hosts, space, codes);
+ } else {
+ dhcp->remove("reservations");
+ }
+ }
+ sanitizeOptionSubnets(subnets, space, codes);
+ sanitizeOptionSharedNetworks(networks, space, codes);
+
+ sanitizePoolsInSubnets(subnets);
+ sanitizePoolsInSharedNetworks(networks, subsel);
+
+ sanitizeHostSubnets(subnets);
+ SanitizeHostsInSharedNetworks(networks, space);
+
+ sanitizeRelaySubnets(subnets);
+ sanitizeRelayInSharedNetworks(networks, subsel);
+
+ sanitizeRequireClassesSubnets(subnets);
+ requireClassesSharedNetworks(networks, subsel);
+
+ sanitizeDatabase(dhcp);
+
+ if (space == DHCP6_SPACE) {
+ sanitizeRelaySuppliedOptions(dhcp);
+ }
+}
+
+void
+AdaptorConfig::preProcess4(ConstElementPtr config) {
+ if (!config) {
+ isc_throw(BadValue, "preProcess4: null config");
+ }
+ if (config->getType() != Element::map) {
+ isc_throw(BadValue, "preProcess4: not map: " << config->str());
+ }
+ if (config->contains("Logging")) {
+ isc_throw(BadValue, "preProcess4: got Logging object");
+ }
+ ConstElementPtr dhcp = config->get("Dhcp4");
+ if (!dhcp) {
+ return;
+ }
+ ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+ preProcess(mutable_dhcp, "subnet4", DHCP4_SPACE);
+}
+
+void
+AdaptorConfig::preProcess6(ConstElementPtr config) {
+ if (!config) {
+ isc_throw(BadValue, "preProcess6: null config");
+ }
+ if (config->getType() != Element::map) {
+ isc_throw(BadValue, "preProcess6: not map: " << config->str());
+ }
+ if (config->contains("Logging")) {
+ isc_throw(BadValue, "preProcess6: got Logging object");
+ }
+ ConstElementPtr dhcp = config->get("Dhcp6");
+ if (!dhcp) {
+ return;
+ }
+ ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+ preProcess(mutable_dhcp, "subnet6", DHCP6_SPACE);
+}
+
+} // end of namespace isc::yang
+} // end of namespace isc
diff --git a/src/lib/yang/adaptor_config.h b/src/lib/yang/adaptor_config.h
new file mode 100644
index 0000000..88cfd4c
--- /dev/null
+++ b/src/lib/yang/adaptor_config.h
@@ -0,0 +1,292 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_ADAPTOR_CONFIG_H
+#define ISC_ADAPTOR_CONFIG_H 1
+
+#include <yang/adaptor_host.h>
+#include <yang/adaptor_option.h>
+#include <yang/adaptor_pool.h>
+#include <yang/adaptor_subnet.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// @brief JSON adaptor for Kea server configurations.
+///
+/// Currently only from JSON to YANG for DHCPv4 and DHCPv6 available
+/// as preProcess4 and preProcess6 class methods, filling some required
+/// (by YANG) fields (e.g. subnet IDs, or option code and space), or
+/// transforming a hand-written JSON configuration into a canonical form.
+class AdaptorConfig : public AdaptorHost, public AdaptorOption,
+ public AdaptorSubnet {
+public:
+
+ /// @brief Constructor.
+ AdaptorConfig();
+
+ /// @brief Destructor.
+ virtual ~AdaptorConfig();
+
+ /// @brief Pre process a DHCPv4 configuration.
+ ///
+ /// Assign subnet IDs, check and set defaults in options, etc.
+ /// Note even though the parameter is a ConstElementPtr and is not modified,
+ /// sub-structures can modify it, so if you need a copy do a deep one.
+ ///
+ /// @param config The configuration.
+ /// @throw MissingKey when a required key is missing.
+ /// @throw BadValue when null or not a map or deprecated Logging present.
+ /// @note Does nothing if "Dhcp4" is not present in the map.
+ static void preProcess4(isc::data::ConstElementPtr config);
+
+ /// @brief Pre process a DHCPv6 configuration.
+ ///
+ /// Assign subnet IDs, check and set default in options, etc.
+ /// Note even though the parameter is a ConstElementPtr and is not modified,
+ /// sub-structures can modify it, so if you need a copy do a deep one.
+ ///
+ /// @param config The configuration.
+ /// @throw MissingKey when a required key is missing.
+ /// @throw BadValue when null or not a map or deprecated Logging present.
+ /// @note Does nothing if "Dhcp6" is not present in the map.
+ static void preProcess6(isc::data::ConstElementPtr config);
+
+protected:
+ /// @brief Collects subnet-ids on all subnets.
+ ///
+ /// It will go over all subnets and collect their ids. It will then return
+ /// true if all subnets have ids. If the subnets list is empty, it will also
+ /// return true. False will be returned if there is at least one subnet that
+ /// doesn't have subnet-id.
+ ///
+ /// @param subnets The subnet list.
+ /// @param set The reference to the set of assigned IDs.
+ /// @return True if all subnets have an ID, false otherwise.
+ static bool subnetsCollectID(isc::data::ConstElementPtr subnets,
+ SubnetIDSet& set);
+
+ /// @brief Collects subnet-ids in all subnets in all shared network list.
+ ///
+ /// It will go over all subnets in all shared networks specified to collect
+ /// their subnet-ids. It will then return true if all subnets have ids. If
+ /// the subnets list is empty, it will also return true. False will be
+ /// returned if there is at least one subnet that doesn't have subnet-id.
+ ///
+ /// @param networks The shared network list.
+ /// @param set The reference to the set of assigned IDs.
+ /// @param subsel The subnet list name.
+ /// @return True if all subnets have an ID, false otherwise.
+ static bool sharedNetworksCollectID(isc::data::ConstElementPtr networks,
+ SubnetIDSet& set,
+ const std::string& subsel);
+
+ /// @brief Assigns subnet-id to every subnet in a subnet list.
+ ///
+ /// Only those subnets that don't have one subnet-id assigned yet,
+ /// will get a new subnet-id value.
+ ///
+ /// @param subnets The subnet list.
+ /// @param set The reference to the set of assigned IDs.
+ /// @param next The next ID.
+ static void subnetsAssignID(isc::data::ConstElementPtr subnets,
+ SubnetIDSet& set, isc::dhcp::SubnetID& next);
+
+ /// @brief Assigns subnet-id to every subnet in a shared network list.
+ ///
+ /// Only those subnets that don't have one subnet-id assigned yet,
+ /// will get a new subnet-id value.
+ ///
+ /// @param networks The shared network list.
+ /// @param set The reference to the set of assigned IDs.
+ /// @param next The next ID.
+ /// @param subsel The subnet list name.
+ static void sharedNetworksAssignID(isc::data::ConstElementPtr networks,
+ SubnetIDSet& set,
+ isc::dhcp::SubnetID& next,
+ const std::string& subsel);
+
+ /// @brief Sanitizes all pools in a pools list.
+ ///
+ /// Goes over each pool and cleans up its definition (removes extra spaces,
+ /// adds one space before and after - ).
+ ///
+ /// @param pools The pool list.
+ static void sanitizePools(isc::data::ConstElementPtr pools);
+
+ /// @brief Sanitizes all pools in a subnets list.
+ ///
+ /// @param subnets The subnet list.
+ static void sanitizePoolsInSubnets(isc::data::ConstElementPtr subnets);
+
+ /// @brief Sanitizes all pools in all subnets in a shared network list.
+ ///
+ /// @param networks The shared network list.
+ /// @param subsel The subnet list name.
+ static void sanitizePoolsInSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& subsel);
+
+ /// @brief Collect option definitions from an option definition list.
+ ///
+ /// Collects options definitions, but also sets missing option space
+ /// with default.
+ ///
+ /// @param defs The option definition list.
+ /// @param space The default space name (missing will be filled with this)
+ /// @param codes Option definitions.
+ static void sanitizeOptionDefList(isc::data::ConstElementPtr defs,
+ const std::string& space,
+ OptionCodes& codes);
+
+ /// @brief Set missing option codes to an option data list.
+ ///
+ /// @param options The option data list.
+ /// @param space The default space name.
+ /// @param codes Option definitions.
+ static void sanitizeOptionDataList(isc::data::ConstElementPtr options,
+ const std::string& space,
+ const OptionCodes& codes);
+
+ /// @brief Collect option definitions from a client class list
+ /// and set missing option codes.
+ ///
+ /// @param classes The client class list.
+ /// @param space The default space name.
+ /// @param codes Option definitions.
+ static void sanitizeOptionClasses(isc::data::ConstElementPtr classes,
+ const std::string& space,
+ OptionCodes& codes);
+
+ /// @brief Set missing option codes to a pool list.
+ ///
+ /// @param pools The pool list.
+ /// @param space The default space name.
+ /// @param codes Option definitions.
+ static void sanitizeOptionPools(isc::data::ConstElementPtr pools,
+ const std::string& space,
+ const OptionCodes& codes);
+
+ /// @brief Set missing option codes to a host reservation list.
+ ///
+ /// @param hosts The host reservation list.
+ /// @param space The default space name.
+ /// @param codes Option definitions.
+ static void sanitizeOptionHosts(isc::data::ConstElementPtr hosts,
+ const std::string& space,
+ const OptionCodes& codes);
+
+ /// @brief Set missing option codes to a subnet list.
+ ///
+ /// @param subnets The subnet list.
+ /// @param space The default space name.
+ /// @param codes Option definitions.
+ static void sanitizeOptionSubnets(isc::data::ConstElementPtr subnets,
+ const std::string& space,
+ const OptionCodes& codes);
+
+ /// @brief Set missing option codes to a shared network list.
+ ///
+ /// @param networks The shared network list.
+ /// @param space The default space name.
+ /// @param codes Option definitions.
+ static void sanitizeOptionSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& space,
+ const OptionCodes& codes);
+
+ /// @brief Process require client classes in a pool list.
+ ///
+ /// Remove empty require client class list.
+ ///
+ /// @param pools The pool list.
+ static void sanitizeRequireClassesPools(isc::data::ConstElementPtr pools);
+
+ /// @brief Process require client classes in a subnet list.
+ ///
+ /// Remove empty require client class lists.
+ ///
+ /// @param subnets The subnet list.
+ static void sanitizeRequireClassesSubnets(isc::data::ConstElementPtr subnets);
+
+ /// @brief Process require client classes in a shared network list.
+ ///
+ /// Remove empty require client class lists.
+ ///
+ /// @param networks The shared network list.
+ /// @param subsel The subnet list name.
+ static void requireClassesSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& subsel);
+
+ /// @brief Process host reservation list.
+ ///
+ /// Quote when needed flex-id identifiers.
+ ///
+ /// @param hosts The host reservation list.
+ static void sanitizeHostList(isc::data::ConstElementPtr hosts);
+
+ /// @brief Process host reservations in a subnet list.
+ ///
+ /// Quote when needed flex-id identifiers.
+ ///
+ /// @param subnets The subnet list.
+ static void sanitizeHostSubnets(isc::data::ConstElementPtr subnets);
+
+ /// @brief Process host reservations in a shared network list.
+ ///
+ /// Quote when needed flex-id identifiers.
+ ///
+ /// @param networks The shared network list.
+ /// @param space The default space name.
+ static void SanitizeHostsInSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& space);
+
+ /// @brief Sanitizes relay information in subnets in a subnet list.
+ ///
+ /// Force the use of ip-addresses when it finds an ip-address entry.
+ ///
+ /// @param subnets The subnet list.
+ static void sanitizeRelaySubnets(isc::data::ConstElementPtr subnets);
+
+ /// @brief Sanitizes relay information in a shared network list.
+ ///
+ /// Force the use of ip-addresses when it finds an ip-address entry.
+ ///
+ /// @param networks The shared network list.
+ /// @param subsel The subnet list name.
+ static void sanitizeRelayInSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& subsel);
+
+ /// @brief Update (hosts) database.
+ ///
+ /// Force the use of hosts-databases vs. hosts-database.
+ ///
+ /// @param dhcp The DHCP server.
+ static void sanitizeDatabase(isc::data::ConstElementPtr dhcp);
+
+ /// @brief Update relay supplied options.
+ ///
+ /// Remove empty relay supplied option list.
+ ///
+ /// @param dhcp The DHCPv6 server.
+ static void sanitizeRelaySuppliedOptions(isc::data::ConstElementPtr dhcp);
+
+ /// @brief Pre process a configuration.
+ ///
+ /// Assign subnet IDs, check and set default in options, etc.
+ ///
+ /// @param dhcp The server configuration.
+ /// @param subsel The subnet list name.
+ /// @param space The default option space name.
+ /// @throw MissingKey when a required key is missing.
+ static void preProcess(isc::data::ElementPtr dhcp,
+ const std::string& subsel,
+ const std::string& space);
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_ADAPTOR_CONFIG_H
diff --git a/src/lib/yang/adaptor_host.cc b/src/lib/yang/adaptor_host.cc
new file mode 100644
index 0000000..9df7d5b
--- /dev/null
+++ b/src/lib/yang/adaptor_host.cc
@@ -0,0 +1,68 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <util/encode/hex.h>
+#include <util/strutil.h>
+#include <yang/adaptor_host.h>
+#include <iomanip>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::util;
+
+namespace isc {
+namespace yang {
+
+const string
+AdaptorHost::STD_CHARACTERS =
+ "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.@_";
+
+AdaptorHost::AdaptorHost() {
+}
+
+AdaptorHost::~AdaptorHost() {
+}
+
+void
+AdaptorHost::quoteIdentifier(ElementPtr host) {
+ ConstElementPtr flex_id = host->get("flex-id");
+ if (!flex_id) {
+ return;
+ }
+ const string& id = flex_id->stringValue();
+ // Empty is allowed.
+ if (id.empty()) {
+ return;
+ }
+ // No special and no not printable characters?
+ if (id.find_first_not_of(STD_CHARACTERS) == string::npos) {
+ return;
+ }
+ // Quoted identifier?
+ vector<uint8_t> binary = str::quotedStringToBinary(id);
+ if (binary.empty()) {
+ binary.assign(id.begin(), id.end());
+ }
+ // Convert in hexadecimal (from DUID::toText()).
+ stringstream tmp;
+ tmp << hex;
+ bool delim = false;
+ for (vector<uint8_t>::const_iterator it = binary.begin();
+ it != binary.end(); ++it) {
+ if (delim) {
+ tmp << ":";
+ }
+ tmp << setw(2) << setfill('0') << static_cast<unsigned int>(*it);
+ delim = true;
+ }
+ host->set("flex-id", Element::create(tmp.str()));
+}
+
+} // end of namespace isc::yang
+} // end of namespace isc
diff --git a/src/lib/yang/adaptor_host.h b/src/lib/yang/adaptor_host.h
new file mode 100644
index 0000000..62f80c1
--- /dev/null
+++ b/src/lib/yang/adaptor_host.h
@@ -0,0 +1,47 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_ADAPTOR_HOST_H
+#define ISC_ADAPTOR_HOST_H 1
+
+#include <yang/adaptor.h>
+
+namespace isc {
+namespace yang {
+
+/// @brief JSON adaptor for host reservations quoting identifiers.
+///
+/// The identifier type and identifier value are used as keys in YANG
+/// host reservation lists so some constraints were put on their contents.
+/// For instance a quoted flex-id identifier raises an error (keys
+/// are between quotes in setItem commands).
+class AdaptorHost {
+public:
+
+ /// @brief The string of standard (vs special or not printable)
+ /// characters (digit, letters, -, ., @, _).
+ static const std::string STD_CHARACTERS;
+
+ /// @brief Constructor.
+ AdaptorHost();
+
+ /// @brief Destructor.
+ virtual ~AdaptorHost();
+
+ /// @brief Quote when needed a host identifier.
+ ///
+ /// Check if the flex-id identifier includes a special (including quote)
+ /// or not printable character. When it is the case produce and replace
+ /// by a hexadecimal identifier trying first for a quoted identifier.
+ ///
+ /// @param host The host.
+ static void quoteIdentifier(isc::data::ElementPtr host);
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_ADAPTOR_HOST_H
diff --git a/src/lib/yang/adaptor_option.cc b/src/lib/yang/adaptor_option.cc
new file mode 100644
index 0000000..c40554a
--- /dev/null
+++ b/src/lib/yang/adaptor_option.cc
@@ -0,0 +1,128 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor_option.h>
+#include <dhcp/std_option_defs.h>
+#include <dhcp/docsis3_option_defs.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::dhcp;
+
+namespace isc {
+namespace yang {
+
+AdaptorOption::AdaptorOption() {
+}
+
+AdaptorOption::~AdaptorOption() {
+}
+
+void
+AdaptorOption::setSpace(ElementPtr option, const string& space) {
+ if (!option->contains("space")) {
+ option->set("space", Element::create(space));
+ }
+}
+
+void
+AdaptorOption::checkType(ConstElementPtr option) {
+ if (!option->contains("type")) {
+ isc_throw(MissingKey, "missing type in option definition "
+ << option->str());
+ }
+}
+
+void
+AdaptorOption::checkCode(ConstElementPtr option) {
+ if (!option->contains("code")) {
+ isc_throw(MissingKey, "missing code in option " << option->str());
+ }
+}
+
+void
+AdaptorOption::collect(ConstElementPtr option, OptionCodes& codes) {
+ ConstElementPtr name = option->get("name");
+ if (name) {
+ ConstElementPtr space = option->get("space");
+ ConstElementPtr code = option->get("code");
+ string index = space->stringValue() + "@" + name->stringValue();
+ uint16_t val = static_cast<uint16_t>(code->intValue());
+ codes.insert(std::pair<string, uint16_t>(index, val));
+ }
+}
+
+void
+AdaptorOption::setCode(ElementPtr option, const OptionCodes& codes) {
+ ConstElementPtr code = option->get("code");
+ if (!code) {
+ ConstElementPtr name = option->get("name");
+ if (!name) {
+ isc_throw(MissingKey, "missing name and code in option "
+ << option->str());
+ }
+ ConstElementPtr space = option->get("space");
+ string index = space->stringValue() + "@" + name->stringValue();
+ OptionCodes::const_iterator it = codes.find(index);
+ if (it == codes.end()) {
+ isc_throw(MissingKey, "can't get code from option "
+ << option->str());
+ }
+ option->set("code", Element::create(static_cast<int>(it->second)));
+ }
+}
+
+void
+AdaptorOption::initCodes(OptionCodes& codes, const string& space) {
+ if (space == DHCP4_OPTION_SPACE) {
+ initCodesInternal(codes, space, STANDARD_V4_OPTION_DEFINITIONS,
+ STANDARD_V4_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, space, LAST_RESORT_V4_OPTION_DEFINITIONS,
+ LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, "vendor-4491",
+ DOCSIS3_V4_OPTION_DEFINITIONS,
+ DOCSIS3_V4_OPTION_DEFINITIONS_SIZE);
+ } else if (space == DHCP6_OPTION_SPACE) {
+ initCodesInternal(codes, space, STANDARD_V6_OPTION_DEFINITIONS,
+ STANDARD_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, "vendor-4491",
+ DOCSIS3_V6_OPTION_DEFINITIONS,
+ DOCSIS3_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, MAPE_V6_OPTION_SPACE,
+ MAPE_V6_OPTION_DEFINITIONS,
+ MAPE_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, MAPT_V6_OPTION_SPACE,
+ MAPT_V6_OPTION_DEFINITIONS,
+ MAPT_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, LW_V6_OPTION_SPACE,
+ LW_V6_OPTION_DEFINITIONS,
+ LW_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, V4V6_RULE_OPTION_SPACE,
+ V4V6_RULE_OPTION_DEFINITIONS,
+ V4V6_RULE_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, V4V6_BIND_OPTION_SPACE,
+ V4V6_BIND_OPTION_DEFINITIONS,
+ V4V6_BIND_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, "vendor-2495",
+ ISC_V6_OPTION_DEFINITIONS,
+ ISC_V6_OPTION_DEFINITIONS_SIZE);
+ }
+}
+
+void
+AdaptorOption::initCodesInternal(OptionCodes& codes, const string& space,
+ const OptionDefParams* params,
+ size_t params_size) {
+ for (size_t i = 0; i < params_size; ++i) {
+ string index = space + "@" + params[i].name;
+ codes.insert(std::pair<string, uint16_t>(index, params[i].code));
+ }
+}
+
+} // end of namespace isc::yang
+} // end of namespace isc
diff --git a/src/lib/yang/adaptor_option.h b/src/lib/yang/adaptor_option.h
new file mode 100644
index 0000000..a3842c7
--- /dev/null
+++ b/src/lib/yang/adaptor_option.h
@@ -0,0 +1,111 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_ADAPTOR_OPTION_H
+#define ISC_ADAPTOR_OPTION_H 1
+
+#include <yang/adaptor.h>
+#include <map>
+#include <list>
+
+namespace isc {
+
+namespace dhcp {
+/// @brief Forward declaration of option definition parameters.
+struct OptionDefParams;
+};
+
+namespace yang {
+
+/// @brief Map for DHCP option definitions handling code and
+/// an index built from space and name.
+///
+/// The map is used to store space+name to code mappings so for
+/// an option data without a code entry the code entry can be supplied.
+typedef std::map<std::string, uint16_t> OptionCodes;
+
+/// @brief JSON adaptor for option data or definition setting defaults.
+///
+/// Both option data and option definition lists are keyed by the code
+/// and space pair so both must be available in setOptionXXX methods.
+/// For space there is an implicit default so setSpace must be called
+/// to add this default to option entries without space.
+/// Note remaining adaptors assume this was done first.
+///
+/// checkCode and checkType can be used to check if code or type is present
+/// (type is mandatory in option definitions).
+///
+/// A missing code can be found in standard definitions (loaded by initCodes)
+/// or in configuration option definitions (at global and client classes
+/// scopes). setCode uses the space+name to code map to set missing codes
+/// and raises an error when it can't.
+class AdaptorOption {
+public:
+
+ /// @brief Constructor.
+ AdaptorOption();
+
+ /// @brief Destructor.
+ virtual ~AdaptorOption();
+
+ /// @brief Set space.
+ ///
+ /// @param option The option.
+ /// @param space The default space name.
+ static void setSpace(isc::data::ElementPtr option,
+ const std::string& space);
+
+ /// @brief Checks if type is specified in option definition.
+ ///
+ /// @param option The option.
+ /// @throw MissingKey if the type is not present.
+ static void checkType(isc::data::ConstElementPtr option);
+
+ /// @brief Check if code is specified in option defintion.
+ ///
+ /// @param option The option.
+ /// @throw MissingKey if the code is not present.
+ static void checkCode(isc::data::ConstElementPtr option);
+
+ /// @brief Collect definition.
+ ///
+ /// This method looks at an option definition and adds the
+ /// space+name to code mapping into the OptionCodes codes store
+ /// aka definitions.
+ ///
+ /// @param option The option definition.
+ /// @param codes The reference to option definitions.
+ static void collect(isc::data::ConstElementPtr option, OptionCodes& codes);
+
+ /// @brief Set code from name and definitions.
+ ///
+ /// @param option The option data.
+ /// @param codes Option definitions.
+ static void setCode(isc::data::ElementPtr option,
+ const OptionCodes& codes);
+
+ /// @brief Initialize code map.
+ ///
+ /// @param codes The reference to option definitions.
+ /// @param space The space name.
+ static void initCodes(OptionCodes& codes, const std::string& space);
+
+protected:
+ /// @brief Initialize code map from option definition parameters.
+ ///
+ /// @param codes The reference to option definitions.
+ /// @param space The space name.
+ /// @param params Array of option definition parameters
+ /// @param params_size The size of the array.
+ static void initCodesInternal(OptionCodes& codes, const std::string& space,
+ const isc::dhcp::OptionDefParams* params,
+ size_t params_size);
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_ADAPTOR_OPTION_H
diff --git a/src/lib/yang/adaptor_pool.cc b/src/lib/yang/adaptor_pool.cc
new file mode 100644
index 0000000..4a84bc0
--- /dev/null
+++ b/src/lib/yang/adaptor_pool.cc
@@ -0,0 +1,87 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor_pool.h>
+#include <yang/yang_models.h>
+
+using namespace std;
+using namespace isc::data;
+
+namespace isc {
+namespace yang {
+
+AdaptorPool::AdaptorPool() {
+}
+
+AdaptorPool::~AdaptorPool() {
+}
+
+void
+AdaptorPool::canonizePool(ElementPtr pool) {
+ const string& orig = pool->get("pool")->stringValue();
+ vector<char> v;
+ for (char ch : orig) {
+ if ((ch == ' ') || (ch == '\t') || (ch == '\n')) {
+ continue;
+ } else if (ch == '-') {
+ v.push_back(' ');
+ v.push_back(ch);
+ v.push_back(' ');
+ } else {
+ v.push_back(ch);
+ }
+ }
+ string canon;
+ canon.assign(v.begin(), v.end());
+ if (orig != canon) {
+ pool->set("pool", Element::create(canon));
+ }
+}
+
+void
+AdaptorPool::fromSubnet(const string& model, ConstElementPtr subnet,
+ ConstElementPtr pools) {
+ if (model == IETF_DHCPV6_SERVER) {
+ fromSubnetIetf6(subnet, pools);
+ } else if ((model != KEA_DHCP4_SERVER) &&
+ (model != KEA_DHCP6_SERVER)) {
+ isc_throw(NotImplemented,
+ "fromSubnet not implemented for the model: " << model);
+ }
+}
+
+void
+AdaptorPool::fromSubnetIetf6(ConstElementPtr subnet, ConstElementPtr pools) {
+ Adaptor::fromParent("valid-lifetime", subnet, pools);
+ Adaptor::fromParent("preferred-lifetime", subnet, pools);
+ Adaptor::fromParent("renew-timer", subnet, pools);
+ Adaptor::fromParent("rebind-timer", subnet, pools);
+}
+
+void
+AdaptorPool::toSubnet(const string& model, ElementPtr subnet,
+ ConstElementPtr pools) {
+ if (model == IETF_DHCPV6_SERVER) {
+ toSubnetIetf6(subnet, pools);
+ } else if ((model != KEA_DHCP4_SERVER) &&
+ (model != KEA_DHCP6_SERVER)) {
+ isc_throw(NotImplemented,
+ "toSubnet not implemented for the model: " << model);
+ }
+}
+
+void
+AdaptorPool::toSubnetIetf6(ElementPtr subnet, ConstElementPtr pools) {
+ Adaptor::toParent("valid-lifetime", subnet, pools);
+ Adaptor::toParent("preferred-lifetime", subnet, pools);
+ Adaptor::toParent("renew-timer", subnet, pools);
+ Adaptor::toParent("rebind-timer", subnet, pools);
+}
+
+} // end of namespace isc::yang
+} // end of namespace isc
diff --git a/src/lib/yang/adaptor_pool.h b/src/lib/yang/adaptor_pool.h
new file mode 100644
index 0000000..2c92681
--- /dev/null
+++ b/src/lib/yang/adaptor_pool.h
@@ -0,0 +1,98 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_ADAPTOR_POOL_H
+#define ISC_ADAPTOR_POOL_H 1
+
+#include <yang/adaptor.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// @brief JSON adaptor for pools between canonical Kea and YANG models.
+///
+/// First adaptor canonizePool checks and fixes if needed the pool entry
+/// to a canonical form which is no space for prefix and one space each
+/// side of the minus character for ranges.
+///
+/// Second adaptor is specific to the IETF DHCPv6 model (and does nothing
+/// with a Kea DHCP model): it moves timer definitions from the subnet scope,
+/// i.e. the scope where they are in Kea, to the pool scope, i.e. the scope
+/// where they are in the IETF model, and back. The from way leaves timers
+/// in the subnet scope as they are ignored by the translator, the to way
+/// removes timers from pools as they are not expected by Kea at this scope.
+class AdaptorPool {
+public:
+
+ /// @brief Constructor.
+ AdaptorPool();
+
+ /// @brief Destructor.
+ virtual ~AdaptorPool();
+
+ /// @brief Canonize pool.
+ ///
+ /// Remove spaces and replace "-" by " - " for readability.
+ /// @param pool The pool.
+ static void canonizePool(isc::data::ElementPtr pool);
+
+ /// @brief Moves parameters from subnets to pools.
+ ///
+ /// Move parameters from the subnet to each pool. Currently the only
+ /// supported model is ietf-dhcpv6-server. The parameters moved are
+ /// valid-lifetime, preferred-lifetime, renew-timer, rebind-timer.
+ ///
+ /// @param model Model name.
+ /// @param subnet The subnet element.
+ /// @param pools The children pools.
+ /// @throw NotImplemented on unexpected model.
+ static void fromSubnet(const std::string& model,
+ isc::data::ConstElementPtr subnet,
+ isc::data::ConstElementPtr pools);
+
+ /// @brief Move parameters from pools to the subnet.
+ ///
+ /// Move parameters from pool to its parent subnet. Currently the only
+ /// supported model is ietf-dhcpv6-server. The parameters moved are
+ /// valid-lifetime, preferred-lifetime, renew-timer, rebind-timer.
+ ///
+ /// @note: currently it is the only from YANG to JSON aka
+ /// post-processing adaptor.
+ ///
+ /// @param model Model name.
+ /// @param subnet The subnet element.
+ /// @param pools The children pools.
+ /// @throw NotImplemented on unexpected model.
+ /// @throw BadValue on inconsistent (different timer values) pools.
+ static void toSubnet(const std::string& model,
+ isc::data::ElementPtr subnet,
+ isc::data::ConstElementPtr pools);
+
+protected:
+ /// @brief From subnets for ietf-dhcpv6-server.
+ ///
+ /// Use common and move valid-lifetime and preferred-lifetime.
+ ///
+ /// @param subnet The subnet element.
+ /// @param pools The children pools.
+ static void fromSubnetIetf6(isc::data::ConstElementPtr subnet,
+ isc::data::ConstElementPtr pools);
+
+ /// @brief To subnet for ietf-dhcpv6-server.
+ ///
+ /// Use common and move valid-lifetime and preferred-lifetime.
+ ///
+ /// @param subnet The subnet element.
+ /// @param pools The children pools.
+ static void toSubnetIetf6(isc::data::ElementPtr subnet,
+ isc::data::ConstElementPtr pools);
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_ADAPTOR_POOL_H
diff --git a/src/lib/yang/adaptor_subnet.cc b/src/lib/yang/adaptor_subnet.cc
new file mode 100644
index 0000000..5e4d6f3
--- /dev/null
+++ b/src/lib/yang/adaptor_subnet.cc
@@ -0,0 +1,73 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor_subnet.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::dhcp;
+
+namespace isc {
+namespace yang {
+
+AdaptorSubnet::AdaptorSubnet() {
+}
+
+AdaptorSubnet::~AdaptorSubnet() {
+}
+
+bool
+AdaptorSubnet::collectID(ConstElementPtr subnet, SubnetIDSet& set) {
+ ConstElementPtr id = subnet->get("id");
+ if (id) {
+ set.insert(static_cast<SubnetID>(id->intValue()));
+ return (true);
+ }
+ return (false);
+}
+
+void
+AdaptorSubnet::assignID(ElementPtr subnet, SubnetIDSet& set, SubnetID& next) {
+ ConstElementPtr id = subnet->get("id");
+ if (!id) {
+ // Skip already used.
+ while (set.count(next) > 0) {
+ ++next;
+ }
+ subnet->set("id", Element::create(static_cast<long long>(next)));
+ set.insert(next);
+ ++next;
+ }
+}
+
+void
+AdaptorSubnet::updateRelay(ElementPtr subnet) {
+ ConstElementPtr relay = subnet->get("relay");
+ if (!relay) {
+ return;
+ }
+ ConstElementPtr addresses = relay->get("ip-addresses");
+ if (!addresses) {
+ ConstElementPtr address = relay->get("ip-address");
+ if (!address) {
+ subnet->remove("relay");
+ return;
+ }
+ ElementPtr addr = Element::create(address->stringValue());
+ ElementPtr addrs = Element::createList();
+ addrs->add(addr);
+ ElementPtr updated = Element::createMap();
+ updated->set("ip-addresses", addrs);
+ subnet->set("relay", updated);
+ } else if (addresses->size() == 0) {
+ subnet->remove("relay");
+ }
+}
+
+} // end of namespace isc::yang
+} // end of namespace isc
diff --git a/src/lib/yang/adaptor_subnet.h b/src/lib/yang/adaptor_subnet.h
new file mode 100644
index 0000000..acdf541
--- /dev/null
+++ b/src/lib/yang/adaptor_subnet.h
@@ -0,0 +1,66 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_ADAPTOR_SUBNET_H
+#define ISC_ADAPTOR_SUBNET_H 1
+
+#include <yang/adaptor.h>
+#include <dhcpsrv/subnet_id.h>
+#include <set>
+
+namespace isc {
+namespace yang {
+
+/// @brief Set of SubnetIDs.
+typedef std::set<isc::dhcp::SubnetID> SubnetIDSet;
+
+/// @brief JSON adaptor for subnets adding IDs and canonizes relays.
+///
+/// Adding IDs is done in two passes walking through subnets.
+/// -1- Add in the set used values and return false when there is no ID
+/// so the caller can decide if the second pass is needed.
+/// -2- For a subnet without an ID, assigned the next unused ID.
+///
+/// For relays an old syntax ip-address is translated into a new syntax
+/// ip-addresses. Note as all canonization adaptor it is optional, i.e.,
+/// code should work without it.
+class AdaptorSubnet {
+public:
+
+ /// @brief Constructor.
+ AdaptorSubnet();
+
+ /// @brief Destructor.
+ virtual ~AdaptorSubnet();
+
+ /// @brief Collect a subnet ID.
+ ///
+ /// @param subnet The subnet.
+ /// @param set The reference to the set of assigned IDs.
+ /// @return True if the subnet has an ID, false otherwise.
+ static bool collectID(isc::data::ConstElementPtr subnet, SubnetIDSet& set);
+
+ /// @brief Assign subnet ID.
+ ///
+ /// @param subnet The subnet.
+ /// @param set The reference to the set of assigned IDs.
+ /// @param next The next ID.
+ static void assignID(isc::data::ElementPtr subnet, SubnetIDSet& set,
+ isc::dhcp::SubnetID& next);
+
+ /// @brief Update relay.
+ ///
+ /// Force the use of ip-addresses when it finds an ip-address entry.
+ /// Can be used for shared networks too.
+ ///
+ /// @param subnet The subnet.
+ static void updateRelay(isc::data::ElementPtr subnet);
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_ADAPTOR_SUBNET_H
diff --git a/src/lib/yang/pretests/Makefile.am b/src/lib/yang/pretests/Makefile.am
new file mode 100644
index 0000000..e27e503
--- /dev/null
+++ b/src/lib/yang/pretests/Makefile.am
@@ -0,0 +1,14 @@
+CLEANFILES = *.gcno *.gcda
+
+TESTS = sysrepo_setup_tests
+
+sysrepo_setup_tests_SOURCES = sysrepo_setup_tests.cc
+sysrepo_setup_tests_CPPFLAGS = -I$(top_builddir)/src/lib
+sysrepo_setup_tests_CPPFLAGS += -I$(top_srcdir)/src/lib
+sysrepo_setup_tests_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+sysrepo_setup_tests_CPPFLAGS += $(SYSREPO_INCLUDEDIR)
+sysrepo_setup_tests_CPPFLAGS += -DSYSREPO_REPO=\"@SR_REPO_PATH@\"
+sysrepo_setup_tests_LDFLAGS = $(AM_LDFLAGS)
+sysrepo_setup_tests_LDADD = $(SYSREPO_LIBS)
+
+noinst_PROGRAMS = $(TESTS)
diff --git a/src/lib/yang/pretests/Makefile.in b/src/lib/yang/pretests/Makefile.in
new file mode 100644
index 0000000..9203afe
--- /dev/null
+++ b/src/lib/yang/pretests/Makefile.in
@@ -0,0 +1,823 @@
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+TESTS = sysrepo_setup_tests$(EXEEXT)
+noinst_PROGRAMS = $(am__EXEEXT_1)
+subdir = src/lib/yang/pretests
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \
+ $(top_srcdir)/m4macros/ax_cpp11.m4 \
+ $(top_srcdir)/m4macros/ax_crypto.m4 \
+ $(top_srcdir)/m4macros/ax_find_library.m4 \
+ $(top_srcdir)/m4macros/ax_gssapi.m4 \
+ $(top_srcdir)/m4macros/ax_gtest.m4 \
+ $(top_srcdir)/m4macros/ax_isc_rpath.m4 \
+ $(top_srcdir)/m4macros/ax_sysrepo.m4 \
+ $(top_srcdir)/m4macros/libtool.m4 \
+ $(top_srcdir)/m4macros/ltoptions.m4 \
+ $(top_srcdir)/m4macros/ltsugar.m4 \
+ $(top_srcdir)/m4macros/ltversion.m4 \
+ $(top_srcdir)/m4macros/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__EXEEXT_1 = sysrepo_setup_tests$(EXEEXT)
+PROGRAMS = $(noinst_PROGRAMS)
+am_sysrepo_setup_tests_OBJECTS = \
+ sysrepo_setup_tests-sysrepo_setup_tests.$(OBJEXT)
+sysrepo_setup_tests_OBJECTS = $(am_sysrepo_setup_tests_OBJECTS)
+am__DEPENDENCIES_1 =
+sysrepo_setup_tests_DEPENDENCIES = $(am__DEPENDENCIES_1)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+sysrepo_setup_tests_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
+ $(AM_CXXFLAGS) $(CXXFLAGS) $(sysrepo_setup_tests_LDFLAGS) \
+ $(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = \
+ ./$(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Po
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
+SOURCES = $(sysrepo_setup_tests_SOURCES)
+DIST_SOURCES = $(sysrepo_setup_tests_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+am__tty_colors_dummy = \
+ mgn= red= grn= lgn= blu= brg= std=; \
+ am__color_tests=no
+am__tty_colors = { \
+ $(am__tty_colors_dummy); \
+ if test "X$(AM_COLOR_TESTS)" = Xno; then \
+ am__color_tests=no; \
+ elif test "X$(AM_COLOR_TESTS)" = Xalways; then \
+ am__color_tests=yes; \
+ elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \
+ am__color_tests=yes; \
+ fi; \
+ if test $$am__color_tests = yes; then \
+ red=''; \
+ grn=''; \
+ lgn=''; \
+ blu=''; \
+ mgn=''; \
+ brg=''; \
+ std=''; \
+ fi; \
+}
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+ASCIIDOC = @ASCIIDOC@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BOOST_INCLUDES = @BOOST_INCLUDES@
+BOOST_LIBS = @BOOST_LIBS@
+BOTAN_TOOL = @BOTAN_TOOL@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONTRIB_DIR = @CONTRIB_DIR@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CRYPTO_CFLAGS = @CRYPTO_CFLAGS@
+CRYPTO_INCLUDES = @CRYPTO_INCLUDES@
+CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@
+CRYPTO_LIBS = @CRYPTO_LIBS@
+CRYPTO_PACKAGE = @CRYPTO_PACKAGE@
+CRYPTO_RPATH = @CRYPTO_RPATH@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@
+DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@
+DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@
+DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@
+DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@
+DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@
+DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@
+DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GENHTML = @GENHTML@
+GREP = @GREP@
+GSSAPI_CFLAGS = @GSSAPI_CFLAGS@
+GSSAPI_LIBS = @GSSAPI_LIBS@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_SOURCE = @GTEST_SOURCE@
+HAVE_SYSREPO = @HAVE_SYSREPO@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+KEA_CXXFLAGS = @KEA_CXXFLAGS@
+KEA_SRCID = @KEA_SRCID@
+KRB5_CONFIG = @KRB5_CONFIG@
+LCOV = @LCOV@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@
+LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@
+MYSQL_LIBS = @MYSQL_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PDFLATEX = @PDFLATEX@
+PERL = @PERL@
+PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@
+PGSQL_LIBS = @PGSQL_LIBS@
+PKGPYTHONDIR = @PKGPYTHONDIR@
+PKG_CONFIG = @PKG_CONFIG@
+PLANTUML = @PLANTUML@
+PREMIUM_DIR = @PREMIUM_DIR@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+SED = @SED@
+SEP = @SEP@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SPHINXBUILD = @SPHINXBUILD@
+SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@
+SR_REPO_PATH = @SR_REPO_PATH@
+STRIP = @STRIP@
+SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@
+SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@
+SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@
+SYSREPO_LIBS = @SYSREPO_LIBS@
+SYSREPO_VERSION = @SYSREPO_VERSION@
+USE_LCOV = @USE_LCOV@
+VALGRIND = @VALGRIND@
+VERSION = @VERSION@
+WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@
+YACC = @YACC@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+CLEANFILES = *.gcno *.gcda
+sysrepo_setup_tests_SOURCES = sysrepo_setup_tests.cc
+sysrepo_setup_tests_CPPFLAGS = -I$(top_builddir)/src/lib \
+ -I$(top_srcdir)/src/lib $(SYSREPO_CPPFLAGS) \
+ $(SYSREPO_INCLUDEDIR) -DSYSREPO_REPO=\"@SR_REPO_PATH@\"
+sysrepo_setup_tests_LDFLAGS = $(AM_LDFLAGS)
+sysrepo_setup_tests_LDADD = $(SYSREPO_LIBS)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/yang/pretests/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/lib/yang/pretests/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstPROGRAMS:
+ @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+
+sysrepo_setup_tests$(EXEEXT): $(sysrepo_setup_tests_OBJECTS) $(sysrepo_setup_tests_DEPENDENCIES) $(EXTRA_sysrepo_setup_tests_DEPENDENCIES)
+ @rm -f sysrepo_setup_tests$(EXEEXT)
+ $(AM_V_CXXLD)$(sysrepo_setup_tests_LINK) $(sysrepo_setup_tests_OBJECTS) $(sysrepo_setup_tests_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.cc.o:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cc.lo:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+sysrepo_setup_tests-sysrepo_setup_tests.o: sysrepo_setup_tests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(sysrepo_setup_tests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sysrepo_setup_tests-sysrepo_setup_tests.o -MD -MP -MF $(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Tpo -c -o sysrepo_setup_tests-sysrepo_setup_tests.o `test -f 'sysrepo_setup_tests.cc' || echo '$(srcdir)/'`sysrepo_setup_tests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Tpo $(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='sysrepo_setup_tests.cc' object='sysrepo_setup_tests-sysrepo_setup_tests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(sysrepo_setup_tests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sysrepo_setup_tests-sysrepo_setup_tests.o `test -f 'sysrepo_setup_tests.cc' || echo '$(srcdir)/'`sysrepo_setup_tests.cc
+
+sysrepo_setup_tests-sysrepo_setup_tests.obj: sysrepo_setup_tests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(sysrepo_setup_tests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sysrepo_setup_tests-sysrepo_setup_tests.obj -MD -MP -MF $(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Tpo -c -o sysrepo_setup_tests-sysrepo_setup_tests.obj `if test -f 'sysrepo_setup_tests.cc'; then $(CYGPATH_W) 'sysrepo_setup_tests.cc'; else $(CYGPATH_W) '$(srcdir)/sysrepo_setup_tests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Tpo $(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='sysrepo_setup_tests.cc' object='sysrepo_setup_tests-sysrepo_setup_tests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(sysrepo_setup_tests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sysrepo_setup_tests-sysrepo_setup_tests.obj `if test -f 'sysrepo_setup_tests.cc'; then $(CYGPATH_W) 'sysrepo_setup_tests.cc'; else $(CYGPATH_W) '$(srcdir)/sysrepo_setup_tests.cc'; fi`
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list=' $(TESTS) '; \
+ $(am__tty_colors); \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=XPASS; \
+ ;; \
+ *) \
+ col=$$grn; res=PASS; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xfail=`expr $$xfail + 1`; \
+ col=$$lgn; res=XFAIL; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=FAIL; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ col=$$blu; res=SKIP; \
+ fi; \
+ echo "$${col}$$res$${std}: $$tst"; \
+ done; \
+ if test "$$all" -eq 1; then \
+ tests="test"; \
+ All=""; \
+ else \
+ tests="tests"; \
+ All="All "; \
+ fi; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="$$All$$all $$tests passed"; \
+ else \
+ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all $$tests failed"; \
+ else \
+ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ if test "$$skip" -eq 1; then \
+ skipped="($$skip test was not run)"; \
+ else \
+ skipped="($$skip tests were not run)"; \
+ fi; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ if test "$$failed" -eq 0; then \
+ col="$$grn"; \
+ else \
+ col="$$red"; \
+ fi; \
+ echo "$${col}$$dashes$${std}"; \
+ echo "$${col}$$banner$${std}"; \
+ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
+ test -z "$$report" || echo "$${col}$$report$${std}"; \
+ echo "$${col}$$dashes$${std}"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -f ./$(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Po
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f ./$(DEPDIR)/sysrepo_setup_tests-sysrepo_setup_tests.Po
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-TESTS \
+ check-am clean clean-generic clean-libtool \
+ clean-noinstPROGRAMS cscopelist-am ctags ctags-am distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am
+
+.PRECIOUS: Makefile
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/lib/yang/pretests/sysrepo_setup_tests.cc b/src/lib/yang/pretests/sysrepo_setup_tests.cc
new file mode 100644
index 0000000..6668cc4
--- /dev/null
+++ b/src/lib/yang/pretests/sysrepo_setup_tests.cc
@@ -0,0 +1,126 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#define KEATEST_MODULE
+#include <yang/yang_revisions.h>
+
+#include <sysrepo-cpp/Session.hpp>
+
+#include <unordered_map>
+#include <sstream>
+
+using namespace std;
+using namespace sysrepo;
+using namespace isc::yang;
+
+using libyang::S_Context;
+using libyang::S_Module;
+
+const string REPOSITORY = SYSREPO_REPO;
+
+/// @brief Returns nicely formed error message if module is missing
+///
+/// @param name name of the YANG module to complain about
+/// @param revision revision of the YANG module
+/// @return a text explaining what the problem is and how to fix it
+string missingModuleText(const string& name, const string& revision) {
+ stringstream tmp;
+ tmp << "ERROR: YANG module " << name << " is not installed." << endl
+ << "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
+ << endl;
+ return (tmp.str());
+}
+
+/// @brief Returns nicely formed error message if module does not have
+/// the expected revision.
+///
+/// @param name name of the YANG module to complain about
+/// @param expected expected revision of the YANG module
+/// @param got got (bad) revision of the YANG module
+string badRevisionModuleText(const string& name, const string& expected,
+ const string& got) {
+ stringstream tmp;
+ tmp << endl
+ << "ERROR: YANG module " << name << " is not installed with the right "
+ << "revision: got " << got << ", but expected " << expected << "." << endl
+ << "Please remove the module " << name << " and reinstall it: " << endl
+ << "$ sysrepoctl -u " << name << endl
+ << "$ sysrepoctl -i ./src/share/yang/modules/" << name << "@" << expected << ".yang" << endl
+ << endl;
+ return (tmp.str());
+}
+
+/// @brief Checks sysrepo setup:
+/// - connection establishment
+/// - session establishment
+/// - test module
+/// - type modules
+/// - IETF module
+/// - Kea modules.
+/// - daemon required
+int main() {
+ S_Connection conn;
+ 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) {
+ cerr << "ERROR: Can't establish a sysrepo session: "
+ << ex.what() << endl;
+ return (2);
+ }
+
+ vector<S_Module> modules;
+ try {
+ S_Context context(sess->get_context());
+ modules = context->get_module_iter();
+ } catch (const sysrepo_exception& 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;
+ return (5);
+ }
+ string const revision(module->rev()->date());
+ installed_modules.emplace(name, revision);
+ }
+
+ for (auto const& kv : YANG_REVISIONS) {
+ std::string const& name(kv.first);
+ std::string const& expected_revision(kv.second);
+ if (!installed_modules.count(name)) {
+ cerr << missingModuleText(name, expected_revision);
+ return (6);
+ }
+ string const& revision(installed_modules.at(name));
+ if (expected_revision != revision) {
+ cerr << badRevisionModuleText(name, expected_revision, revision);
+ return (7);
+ }
+ }
+
+ return 0;
+}
diff --git a/src/lib/yang/sysrepo_error.h b/src/lib/yang/sysrepo_error.h
new file mode 100644
index 0000000..c4f3a61
--- /dev/null
+++ b/src/lib/yang/sysrepo_error.h
@@ -0,0 +1,26 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_SYSREPO_ERROR_H
+#define ISC_SYSREPO_ERROR_H 1
+
+#include <exceptions/exceptions.h>
+
+namespace isc {
+namespace yang {
+
+/// @brief Sysrepo error.
+class SysrepoError : public isc::Exception {
+public:
+ SysrepoError(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what)
+ {}
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_SYSREPO_ERROR_H
diff --git a/src/lib/yang/tests/Makefile.am b/src/lib/yang/tests/Makefile.am
new file mode 100644
index 0000000..9fe7693
--- /dev/null
+++ b/src/lib/yang/tests/Makefile.am
@@ -0,0 +1,60 @@
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+AM_CPPFLAGS += $(SYSREPO_INCLUDEDIR)
+AM_CPPFLAGS += -DCFG_EXAMPLES=\"$(abs_top_srcdir)/doc/examples\"
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+ $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = json_configs.h yang_configs.h
+run_unittests_SOURCES += adaptor_unittests.cc
+run_unittests_SOURCES += adaptor_option_unittests.cc
+run_unittests_SOURCES += adaptor_pool_unittests.cc
+run_unittests_SOURCES += adaptor_host_unittests.cc
+run_unittests_SOURCES += adaptor_subnet_unittests.cc
+run_unittests_SOURCES += adaptor_config_unittests.cc
+run_unittests_SOURCES += sysrepo_setup.h
+run_unittests_SOURCES += translator_unittests.cc
+run_unittests_SOURCES += translator_control_socket_unittests.cc
+run_unittests_SOURCES += translator_database_unittests.cc
+run_unittests_SOURCES += translator_logger_unittests.cc
+run_unittests_SOURCES += translator_option_data_unittests.cc
+run_unittests_SOURCES += translator_option_def_unittests.cc
+run_unittests_SOURCES += translator_class_unittests.cc
+run_unittests_SOURCES += translator_pool_unittests.cc
+run_unittests_SOURCES += translator_pd_pool_unittests.cc
+run_unittests_SOURCES += translator_host_unittests.cc
+run_unittests_SOURCES += translator_subnet_unittests.cc
+run_unittests_SOURCES += translator_shared_network_unittests.cc
+run_unittests_SOURCES += translator_utils_unittests.cc
+run_unittests_SOURCES += config_unittests.cc
+run_unittests_SOURCES += run_unittests.cc
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+run_unittests_LDADD = $(top_builddir)/src/lib/yang/testutils/libyangtest.la
+run_unittests_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
+run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
+run_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+run_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+run_unittests_LDADD += $(LOG4CPLUS_LIBS) $(BOOST_LIBS)
+run_unittests_LDADD += $(SYSREPO_LIBS) $(GTEST_LDADD)
+
+endif
+
+noinst_PROGRAMS = $(TESTS)
diff --git a/src/lib/yang/tests/Makefile.in b/src/lib/yang/tests/Makefile.in
new file mode 100644
index 0000000..4f60eb2
--- /dev/null
+++ b/src/lib/yang/tests/Makefile.in
@@ -0,0 +1,1285 @@
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+TESTS = $(am__EXEEXT_1)
+@HAVE_GTEST_TRUE@am__append_1 = run_unittests
+noinst_PROGRAMS = $(am__EXEEXT_2)
+subdir = src/lib/yang/tests
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \
+ $(top_srcdir)/m4macros/ax_cpp11.m4 \
+ $(top_srcdir)/m4macros/ax_crypto.m4 \
+ $(top_srcdir)/m4macros/ax_find_library.m4 \
+ $(top_srcdir)/m4macros/ax_gssapi.m4 \
+ $(top_srcdir)/m4macros/ax_gtest.m4 \
+ $(top_srcdir)/m4macros/ax_isc_rpath.m4 \
+ $(top_srcdir)/m4macros/ax_sysrepo.m4 \
+ $(top_srcdir)/m4macros/libtool.m4 \
+ $(top_srcdir)/m4macros/ltoptions.m4 \
+ $(top_srcdir)/m4macros/ltsugar.m4 \
+ $(top_srcdir)/m4macros/ltversion.m4 \
+ $(top_srcdir)/m4macros/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+@HAVE_GTEST_TRUE@am__EXEEXT_1 = run_unittests$(EXEEXT)
+am__EXEEXT_2 = $(am__EXEEXT_1)
+PROGRAMS = $(noinst_PROGRAMS)
+am__run_unittests_SOURCES_DIST = json_configs.h yang_configs.h \
+ adaptor_unittests.cc adaptor_option_unittests.cc \
+ adaptor_pool_unittests.cc adaptor_host_unittests.cc \
+ adaptor_subnet_unittests.cc adaptor_config_unittests.cc \
+ sysrepo_setup.h translator_unittests.cc \
+ translator_control_socket_unittests.cc \
+ translator_database_unittests.cc \
+ translator_logger_unittests.cc \
+ translator_option_data_unittests.cc \
+ translator_option_def_unittests.cc \
+ translator_class_unittests.cc translator_pool_unittests.cc \
+ translator_pd_pool_unittests.cc translator_host_unittests.cc \
+ translator_subnet_unittests.cc \
+ translator_shared_network_unittests.cc \
+ translator_utils_unittests.cc config_unittests.cc \
+ run_unittests.cc
+@HAVE_GTEST_TRUE@am_run_unittests_OBJECTS = \
+@HAVE_GTEST_TRUE@ run_unittests-adaptor_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-adaptor_option_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-adaptor_pool_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-adaptor_host_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-adaptor_subnet_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-adaptor_config_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_control_socket_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_database_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_logger_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_option_data_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_option_def_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_class_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_pool_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_pd_pool_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_host_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_subnet_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_shared_network_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-translator_utils_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-config_unittests.$(OBJEXT) \
+@HAVE_GTEST_TRUE@ run_unittests-run_unittests.$(OBJEXT)
+run_unittests_OBJECTS = $(am_run_unittests_OBJECTS)
+am__DEPENDENCIES_1 =
+@HAVE_GTEST_TRUE@run_unittests_DEPENDENCIES = $(top_builddir)/src/lib/yang/testutils/libyangtest.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/yang/libkea-yang.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/testutils/libkea-testutils.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/cc/libkea-cc.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/log/libkea-log.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/util/unittests/libutil_unittests.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/util/libkea-util.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \
+@HAVE_GTEST_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+@HAVE_GTEST_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+run_unittests_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
+ $(AM_CXXFLAGS) $(CXXFLAGS) $(run_unittests_LDFLAGS) $(LDFLAGS) \
+ -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = \
+ ./$(DEPDIR)/run_unittests-adaptor_config_unittests.Po \
+ ./$(DEPDIR)/run_unittests-adaptor_host_unittests.Po \
+ ./$(DEPDIR)/run_unittests-adaptor_option_unittests.Po \
+ ./$(DEPDIR)/run_unittests-adaptor_pool_unittests.Po \
+ ./$(DEPDIR)/run_unittests-adaptor_subnet_unittests.Po \
+ ./$(DEPDIR)/run_unittests-adaptor_unittests.Po \
+ ./$(DEPDIR)/run_unittests-config_unittests.Po \
+ ./$(DEPDIR)/run_unittests-run_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_class_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_control_socket_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_database_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_host_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_logger_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_option_data_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_option_def_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_pd_pool_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_pool_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_shared_network_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_subnet_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_unittests.Po \
+ ./$(DEPDIR)/run_unittests-translator_utils_unittests.Po
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(run_unittests_SOURCES)
+DIST_SOURCES = $(am__run_unittests_SOURCES_DIST)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+am__tty_colors_dummy = \
+ mgn= red= grn= lgn= blu= brg= std=; \
+ am__color_tests=no
+am__tty_colors = { \
+ $(am__tty_colors_dummy); \
+ if test "X$(AM_COLOR_TESTS)" = Xno; then \
+ am__color_tests=no; \
+ elif test "X$(AM_COLOR_TESTS)" = Xalways; then \
+ am__color_tests=yes; \
+ elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \
+ am__color_tests=yes; \
+ fi; \
+ if test $$am__color_tests = yes; then \
+ red=''; \
+ grn=''; \
+ lgn=''; \
+ blu=''; \
+ mgn=''; \
+ brg=''; \
+ std=''; \
+ fi; \
+}
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+ASCIIDOC = @ASCIIDOC@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BOOST_INCLUDES = @BOOST_INCLUDES@
+BOOST_LIBS = @BOOST_LIBS@
+BOTAN_TOOL = @BOTAN_TOOL@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONTRIB_DIR = @CONTRIB_DIR@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CRYPTO_CFLAGS = @CRYPTO_CFLAGS@
+CRYPTO_INCLUDES = @CRYPTO_INCLUDES@
+CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@
+CRYPTO_LIBS = @CRYPTO_LIBS@
+CRYPTO_PACKAGE = @CRYPTO_PACKAGE@
+CRYPTO_RPATH = @CRYPTO_RPATH@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@
+DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@
+DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@
+DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@
+DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@
+DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@
+DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@
+DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GENHTML = @GENHTML@
+GREP = @GREP@
+GSSAPI_CFLAGS = @GSSAPI_CFLAGS@
+GSSAPI_LIBS = @GSSAPI_LIBS@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_SOURCE = @GTEST_SOURCE@
+HAVE_SYSREPO = @HAVE_SYSREPO@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+KEA_CXXFLAGS = @KEA_CXXFLAGS@
+KEA_SRCID = @KEA_SRCID@
+KRB5_CONFIG = @KRB5_CONFIG@
+LCOV = @LCOV@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@
+LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@
+MYSQL_LIBS = @MYSQL_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PDFLATEX = @PDFLATEX@
+PERL = @PERL@
+PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@
+PGSQL_LIBS = @PGSQL_LIBS@
+PKGPYTHONDIR = @PKGPYTHONDIR@
+PKG_CONFIG = @PKG_CONFIG@
+PLANTUML = @PLANTUML@
+PREMIUM_DIR = @PREMIUM_DIR@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+SED = @SED@
+SEP = @SEP@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SPHINXBUILD = @SPHINXBUILD@
+SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@
+SR_REPO_PATH = @SR_REPO_PATH@
+STRIP = @STRIP@
+SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@
+SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@
+SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@
+SYSREPO_LIBS = @SYSREPO_LIBS@
+SYSREPO_VERSION = @SYSREPO_VERSION@
+USE_LCOV = @USE_LCOV@
+VALGRIND = @VALGRIND@
+VERSION = @VERSION@
+WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@
+YACC = @YACC@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib \
+ $(BOOST_INCLUDES) $(SYSREPO_CPPFLAGS) $(SYSREPO_INCLUDEDIR) \
+ -DCFG_EXAMPLES=\"$(abs_top_srcdir)/doc/examples\"
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+@USE_STATIC_LINK_TRUE@AM_LDFLAGS = -static
+CLEANFILES = *.gcno *.gcda
+TESTS_ENVIRONMENT = \
+ $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+@HAVE_GTEST_TRUE@run_unittests_SOURCES = json_configs.h yang_configs.h \
+@HAVE_GTEST_TRUE@ adaptor_unittests.cc \
+@HAVE_GTEST_TRUE@ adaptor_option_unittests.cc \
+@HAVE_GTEST_TRUE@ adaptor_pool_unittests.cc \
+@HAVE_GTEST_TRUE@ adaptor_host_unittests.cc \
+@HAVE_GTEST_TRUE@ adaptor_subnet_unittests.cc \
+@HAVE_GTEST_TRUE@ adaptor_config_unittests.cc sysrepo_setup.h \
+@HAVE_GTEST_TRUE@ translator_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_control_socket_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_database_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_logger_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_option_data_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_option_def_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_class_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_pool_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_pd_pool_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_host_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_subnet_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_shared_network_unittests.cc \
+@HAVE_GTEST_TRUE@ translator_utils_unittests.cc \
+@HAVE_GTEST_TRUE@ config_unittests.cc run_unittests.cc
+@HAVE_GTEST_TRUE@run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+@HAVE_GTEST_TRUE@run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+@HAVE_GTEST_TRUE@run_unittests_LDADD = $(top_builddir)/src/lib/yang/testutils/libyangtest.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/yang/libkea-yang.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/testutils/libkea-testutils.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/cc/libkea-cc.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/log/libkea-log.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/util/unittests/libutil_unittests.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/util/libkea-util.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \
+@HAVE_GTEST_TRUE@ $(LOG4CPLUS_LIBS) $(BOOST_LIBS) \
+@HAVE_GTEST_TRUE@ $(SYSREPO_LIBS) $(GTEST_LDADD)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/yang/tests/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/lib/yang/tests/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstPROGRAMS:
+ @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+
+run_unittests$(EXEEXT): $(run_unittests_OBJECTS) $(run_unittests_DEPENDENCIES) $(EXTRA_run_unittests_DEPENDENCIES)
+ @rm -f run_unittests$(EXEEXT)
+ $(AM_V_CXXLD)$(run_unittests_LINK) $(run_unittests_OBJECTS) $(run_unittests_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-adaptor_config_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-adaptor_host_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-adaptor_option_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-adaptor_pool_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-adaptor_subnet_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-adaptor_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-config_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-run_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_class_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_control_socket_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_database_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_host_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_logger_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_option_data_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_option_def_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_pd_pool_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_pool_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_shared_network_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_subnet_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_unittests.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_unittests-translator_utils_unittests.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.cc.o:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cc.lo:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+run_unittests-adaptor_unittests.o: adaptor_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_unittests.Tpo -c -o run_unittests-adaptor_unittests.o `test -f 'adaptor_unittests.cc' || echo '$(srcdir)/'`adaptor_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_unittests.cc' object='run_unittests-adaptor_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_unittests.o `test -f 'adaptor_unittests.cc' || echo '$(srcdir)/'`adaptor_unittests.cc
+
+run_unittests-adaptor_unittests.obj: adaptor_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_unittests.Tpo -c -o run_unittests-adaptor_unittests.obj `if test -f 'adaptor_unittests.cc'; then $(CYGPATH_W) 'adaptor_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_unittests.cc' object='run_unittests-adaptor_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_unittests.obj `if test -f 'adaptor_unittests.cc'; then $(CYGPATH_W) 'adaptor_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_unittests.cc'; fi`
+
+run_unittests-adaptor_option_unittests.o: adaptor_option_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_option_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_option_unittests.Tpo -c -o run_unittests-adaptor_option_unittests.o `test -f 'adaptor_option_unittests.cc' || echo '$(srcdir)/'`adaptor_option_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_option_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_option_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_option_unittests.cc' object='run_unittests-adaptor_option_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_option_unittests.o `test -f 'adaptor_option_unittests.cc' || echo '$(srcdir)/'`adaptor_option_unittests.cc
+
+run_unittests-adaptor_option_unittests.obj: adaptor_option_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_option_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_option_unittests.Tpo -c -o run_unittests-adaptor_option_unittests.obj `if test -f 'adaptor_option_unittests.cc'; then $(CYGPATH_W) 'adaptor_option_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_option_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_option_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_option_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_option_unittests.cc' object='run_unittests-adaptor_option_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_option_unittests.obj `if test -f 'adaptor_option_unittests.cc'; then $(CYGPATH_W) 'adaptor_option_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_option_unittests.cc'; fi`
+
+run_unittests-adaptor_pool_unittests.o: adaptor_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_pool_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_pool_unittests.Tpo -c -o run_unittests-adaptor_pool_unittests.o `test -f 'adaptor_pool_unittests.cc' || echo '$(srcdir)/'`adaptor_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_pool_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_pool_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_pool_unittests.cc' object='run_unittests-adaptor_pool_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_pool_unittests.o `test -f 'adaptor_pool_unittests.cc' || echo '$(srcdir)/'`adaptor_pool_unittests.cc
+
+run_unittests-adaptor_pool_unittests.obj: adaptor_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_pool_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_pool_unittests.Tpo -c -o run_unittests-adaptor_pool_unittests.obj `if test -f 'adaptor_pool_unittests.cc'; then $(CYGPATH_W) 'adaptor_pool_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_pool_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_pool_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_pool_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_pool_unittests.cc' object='run_unittests-adaptor_pool_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_pool_unittests.obj `if test -f 'adaptor_pool_unittests.cc'; then $(CYGPATH_W) 'adaptor_pool_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_pool_unittests.cc'; fi`
+
+run_unittests-adaptor_host_unittests.o: adaptor_host_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_host_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_host_unittests.Tpo -c -o run_unittests-adaptor_host_unittests.o `test -f 'adaptor_host_unittests.cc' || echo '$(srcdir)/'`adaptor_host_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_host_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_host_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_host_unittests.cc' object='run_unittests-adaptor_host_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_host_unittests.o `test -f 'adaptor_host_unittests.cc' || echo '$(srcdir)/'`adaptor_host_unittests.cc
+
+run_unittests-adaptor_host_unittests.obj: adaptor_host_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_host_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_host_unittests.Tpo -c -o run_unittests-adaptor_host_unittests.obj `if test -f 'adaptor_host_unittests.cc'; then $(CYGPATH_W) 'adaptor_host_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_host_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_host_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_host_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_host_unittests.cc' object='run_unittests-adaptor_host_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_host_unittests.obj `if test -f 'adaptor_host_unittests.cc'; then $(CYGPATH_W) 'adaptor_host_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_host_unittests.cc'; fi`
+
+run_unittests-adaptor_subnet_unittests.o: adaptor_subnet_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_subnet_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_subnet_unittests.Tpo -c -o run_unittests-adaptor_subnet_unittests.o `test -f 'adaptor_subnet_unittests.cc' || echo '$(srcdir)/'`adaptor_subnet_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_subnet_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_subnet_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_subnet_unittests.cc' object='run_unittests-adaptor_subnet_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_subnet_unittests.o `test -f 'adaptor_subnet_unittests.cc' || echo '$(srcdir)/'`adaptor_subnet_unittests.cc
+
+run_unittests-adaptor_subnet_unittests.obj: adaptor_subnet_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_subnet_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_subnet_unittests.Tpo -c -o run_unittests-adaptor_subnet_unittests.obj `if test -f 'adaptor_subnet_unittests.cc'; then $(CYGPATH_W) 'adaptor_subnet_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_subnet_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_subnet_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_subnet_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_subnet_unittests.cc' object='run_unittests-adaptor_subnet_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_subnet_unittests.obj `if test -f 'adaptor_subnet_unittests.cc'; then $(CYGPATH_W) 'adaptor_subnet_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_subnet_unittests.cc'; fi`
+
+run_unittests-adaptor_config_unittests.o: adaptor_config_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_config_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_config_unittests.Tpo -c -o run_unittests-adaptor_config_unittests.o `test -f 'adaptor_config_unittests.cc' || echo '$(srcdir)/'`adaptor_config_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_config_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_config_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_config_unittests.cc' object='run_unittests-adaptor_config_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_config_unittests.o `test -f 'adaptor_config_unittests.cc' || echo '$(srcdir)/'`adaptor_config_unittests.cc
+
+run_unittests-adaptor_config_unittests.obj: adaptor_config_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-adaptor_config_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-adaptor_config_unittests.Tpo -c -o run_unittests-adaptor_config_unittests.obj `if test -f 'adaptor_config_unittests.cc'; then $(CYGPATH_W) 'adaptor_config_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_config_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-adaptor_config_unittests.Tpo $(DEPDIR)/run_unittests-adaptor_config_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='adaptor_config_unittests.cc' object='run_unittests-adaptor_config_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-adaptor_config_unittests.obj `if test -f 'adaptor_config_unittests.cc'; then $(CYGPATH_W) 'adaptor_config_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/adaptor_config_unittests.cc'; fi`
+
+run_unittests-translator_unittests.o: translator_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_unittests.Tpo -c -o run_unittests-translator_unittests.o `test -f 'translator_unittests.cc' || echo '$(srcdir)/'`translator_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_unittests.Tpo $(DEPDIR)/run_unittests-translator_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_unittests.cc' object='run_unittests-translator_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_unittests.o `test -f 'translator_unittests.cc' || echo '$(srcdir)/'`translator_unittests.cc
+
+run_unittests-translator_unittests.obj: translator_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_unittests.Tpo -c -o run_unittests-translator_unittests.obj `if test -f 'translator_unittests.cc'; then $(CYGPATH_W) 'translator_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_unittests.Tpo $(DEPDIR)/run_unittests-translator_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_unittests.cc' object='run_unittests-translator_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_unittests.obj `if test -f 'translator_unittests.cc'; then $(CYGPATH_W) 'translator_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_unittests.cc'; fi`
+
+run_unittests-translator_control_socket_unittests.o: translator_control_socket_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_control_socket_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_control_socket_unittests.Tpo -c -o run_unittests-translator_control_socket_unittests.o `test -f 'translator_control_socket_unittests.cc' || echo '$(srcdir)/'`translator_control_socket_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_control_socket_unittests.Tpo $(DEPDIR)/run_unittests-translator_control_socket_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_control_socket_unittests.cc' object='run_unittests-translator_control_socket_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_control_socket_unittests.o `test -f 'translator_control_socket_unittests.cc' || echo '$(srcdir)/'`translator_control_socket_unittests.cc
+
+run_unittests-translator_control_socket_unittests.obj: translator_control_socket_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_control_socket_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_control_socket_unittests.Tpo -c -o run_unittests-translator_control_socket_unittests.obj `if test -f 'translator_control_socket_unittests.cc'; then $(CYGPATH_W) 'translator_control_socket_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_control_socket_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_control_socket_unittests.Tpo $(DEPDIR)/run_unittests-translator_control_socket_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_control_socket_unittests.cc' object='run_unittests-translator_control_socket_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_control_socket_unittests.obj `if test -f 'translator_control_socket_unittests.cc'; then $(CYGPATH_W) 'translator_control_socket_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_control_socket_unittests.cc'; fi`
+
+run_unittests-translator_database_unittests.o: translator_database_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_database_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_database_unittests.Tpo -c -o run_unittests-translator_database_unittests.o `test -f 'translator_database_unittests.cc' || echo '$(srcdir)/'`translator_database_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_database_unittests.Tpo $(DEPDIR)/run_unittests-translator_database_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_database_unittests.cc' object='run_unittests-translator_database_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_database_unittests.o `test -f 'translator_database_unittests.cc' || echo '$(srcdir)/'`translator_database_unittests.cc
+
+run_unittests-translator_database_unittests.obj: translator_database_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_database_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_database_unittests.Tpo -c -o run_unittests-translator_database_unittests.obj `if test -f 'translator_database_unittests.cc'; then $(CYGPATH_W) 'translator_database_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_database_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_database_unittests.Tpo $(DEPDIR)/run_unittests-translator_database_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_database_unittests.cc' object='run_unittests-translator_database_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_database_unittests.obj `if test -f 'translator_database_unittests.cc'; then $(CYGPATH_W) 'translator_database_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_database_unittests.cc'; fi`
+
+run_unittests-translator_logger_unittests.o: translator_logger_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_logger_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_logger_unittests.Tpo -c -o run_unittests-translator_logger_unittests.o `test -f 'translator_logger_unittests.cc' || echo '$(srcdir)/'`translator_logger_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_logger_unittests.Tpo $(DEPDIR)/run_unittests-translator_logger_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_logger_unittests.cc' object='run_unittests-translator_logger_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_logger_unittests.o `test -f 'translator_logger_unittests.cc' || echo '$(srcdir)/'`translator_logger_unittests.cc
+
+run_unittests-translator_logger_unittests.obj: translator_logger_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_logger_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_logger_unittests.Tpo -c -o run_unittests-translator_logger_unittests.obj `if test -f 'translator_logger_unittests.cc'; then $(CYGPATH_W) 'translator_logger_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_logger_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_logger_unittests.Tpo $(DEPDIR)/run_unittests-translator_logger_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_logger_unittests.cc' object='run_unittests-translator_logger_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_logger_unittests.obj `if test -f 'translator_logger_unittests.cc'; then $(CYGPATH_W) 'translator_logger_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_logger_unittests.cc'; fi`
+
+run_unittests-translator_option_data_unittests.o: translator_option_data_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_option_data_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_option_data_unittests.Tpo -c -o run_unittests-translator_option_data_unittests.o `test -f 'translator_option_data_unittests.cc' || echo '$(srcdir)/'`translator_option_data_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_option_data_unittests.Tpo $(DEPDIR)/run_unittests-translator_option_data_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_option_data_unittests.cc' object='run_unittests-translator_option_data_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_option_data_unittests.o `test -f 'translator_option_data_unittests.cc' || echo '$(srcdir)/'`translator_option_data_unittests.cc
+
+run_unittests-translator_option_data_unittests.obj: translator_option_data_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_option_data_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_option_data_unittests.Tpo -c -o run_unittests-translator_option_data_unittests.obj `if test -f 'translator_option_data_unittests.cc'; then $(CYGPATH_W) 'translator_option_data_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_option_data_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_option_data_unittests.Tpo $(DEPDIR)/run_unittests-translator_option_data_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_option_data_unittests.cc' object='run_unittests-translator_option_data_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_option_data_unittests.obj `if test -f 'translator_option_data_unittests.cc'; then $(CYGPATH_W) 'translator_option_data_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_option_data_unittests.cc'; fi`
+
+run_unittests-translator_option_def_unittests.o: translator_option_def_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_option_def_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_option_def_unittests.Tpo -c -o run_unittests-translator_option_def_unittests.o `test -f 'translator_option_def_unittests.cc' || echo '$(srcdir)/'`translator_option_def_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_option_def_unittests.Tpo $(DEPDIR)/run_unittests-translator_option_def_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_option_def_unittests.cc' object='run_unittests-translator_option_def_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_option_def_unittests.o `test -f 'translator_option_def_unittests.cc' || echo '$(srcdir)/'`translator_option_def_unittests.cc
+
+run_unittests-translator_option_def_unittests.obj: translator_option_def_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_option_def_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_option_def_unittests.Tpo -c -o run_unittests-translator_option_def_unittests.obj `if test -f 'translator_option_def_unittests.cc'; then $(CYGPATH_W) 'translator_option_def_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_option_def_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_option_def_unittests.Tpo $(DEPDIR)/run_unittests-translator_option_def_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_option_def_unittests.cc' object='run_unittests-translator_option_def_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_option_def_unittests.obj `if test -f 'translator_option_def_unittests.cc'; then $(CYGPATH_W) 'translator_option_def_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_option_def_unittests.cc'; fi`
+
+run_unittests-translator_class_unittests.o: translator_class_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_class_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_class_unittests.Tpo -c -o run_unittests-translator_class_unittests.o `test -f 'translator_class_unittests.cc' || echo '$(srcdir)/'`translator_class_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_class_unittests.Tpo $(DEPDIR)/run_unittests-translator_class_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_class_unittests.cc' object='run_unittests-translator_class_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_class_unittests.o `test -f 'translator_class_unittests.cc' || echo '$(srcdir)/'`translator_class_unittests.cc
+
+run_unittests-translator_class_unittests.obj: translator_class_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_class_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_class_unittests.Tpo -c -o run_unittests-translator_class_unittests.obj `if test -f 'translator_class_unittests.cc'; then $(CYGPATH_W) 'translator_class_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_class_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_class_unittests.Tpo $(DEPDIR)/run_unittests-translator_class_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_class_unittests.cc' object='run_unittests-translator_class_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_class_unittests.obj `if test -f 'translator_class_unittests.cc'; then $(CYGPATH_W) 'translator_class_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_class_unittests.cc'; fi`
+
+run_unittests-translator_pool_unittests.o: translator_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_pool_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_pool_unittests.Tpo -c -o run_unittests-translator_pool_unittests.o `test -f 'translator_pool_unittests.cc' || echo '$(srcdir)/'`translator_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_pool_unittests.Tpo $(DEPDIR)/run_unittests-translator_pool_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_pool_unittests.cc' object='run_unittests-translator_pool_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_pool_unittests.o `test -f 'translator_pool_unittests.cc' || echo '$(srcdir)/'`translator_pool_unittests.cc
+
+run_unittests-translator_pool_unittests.obj: translator_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_pool_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_pool_unittests.Tpo -c -o run_unittests-translator_pool_unittests.obj `if test -f 'translator_pool_unittests.cc'; then $(CYGPATH_W) 'translator_pool_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_pool_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_pool_unittests.Tpo $(DEPDIR)/run_unittests-translator_pool_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_pool_unittests.cc' object='run_unittests-translator_pool_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_pool_unittests.obj `if test -f 'translator_pool_unittests.cc'; then $(CYGPATH_W) 'translator_pool_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_pool_unittests.cc'; fi`
+
+run_unittests-translator_pd_pool_unittests.o: translator_pd_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_pd_pool_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_pd_pool_unittests.Tpo -c -o run_unittests-translator_pd_pool_unittests.o `test -f 'translator_pd_pool_unittests.cc' || echo '$(srcdir)/'`translator_pd_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_pd_pool_unittests.Tpo $(DEPDIR)/run_unittests-translator_pd_pool_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_pd_pool_unittests.cc' object='run_unittests-translator_pd_pool_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_pd_pool_unittests.o `test -f 'translator_pd_pool_unittests.cc' || echo '$(srcdir)/'`translator_pd_pool_unittests.cc
+
+run_unittests-translator_pd_pool_unittests.obj: translator_pd_pool_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_pd_pool_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_pd_pool_unittests.Tpo -c -o run_unittests-translator_pd_pool_unittests.obj `if test -f 'translator_pd_pool_unittests.cc'; then $(CYGPATH_W) 'translator_pd_pool_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_pd_pool_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_pd_pool_unittests.Tpo $(DEPDIR)/run_unittests-translator_pd_pool_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_pd_pool_unittests.cc' object='run_unittests-translator_pd_pool_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_pd_pool_unittests.obj `if test -f 'translator_pd_pool_unittests.cc'; then $(CYGPATH_W) 'translator_pd_pool_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_pd_pool_unittests.cc'; fi`
+
+run_unittests-translator_host_unittests.o: translator_host_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_host_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_host_unittests.Tpo -c -o run_unittests-translator_host_unittests.o `test -f 'translator_host_unittests.cc' || echo '$(srcdir)/'`translator_host_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_host_unittests.Tpo $(DEPDIR)/run_unittests-translator_host_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_host_unittests.cc' object='run_unittests-translator_host_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_host_unittests.o `test -f 'translator_host_unittests.cc' || echo '$(srcdir)/'`translator_host_unittests.cc
+
+run_unittests-translator_host_unittests.obj: translator_host_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_host_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_host_unittests.Tpo -c -o run_unittests-translator_host_unittests.obj `if test -f 'translator_host_unittests.cc'; then $(CYGPATH_W) 'translator_host_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_host_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_host_unittests.Tpo $(DEPDIR)/run_unittests-translator_host_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_host_unittests.cc' object='run_unittests-translator_host_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_host_unittests.obj `if test -f 'translator_host_unittests.cc'; then $(CYGPATH_W) 'translator_host_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_host_unittests.cc'; fi`
+
+run_unittests-translator_subnet_unittests.o: translator_subnet_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_subnet_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_subnet_unittests.Tpo -c -o run_unittests-translator_subnet_unittests.o `test -f 'translator_subnet_unittests.cc' || echo '$(srcdir)/'`translator_subnet_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_subnet_unittests.Tpo $(DEPDIR)/run_unittests-translator_subnet_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_subnet_unittests.cc' object='run_unittests-translator_subnet_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_subnet_unittests.o `test -f 'translator_subnet_unittests.cc' || echo '$(srcdir)/'`translator_subnet_unittests.cc
+
+run_unittests-translator_subnet_unittests.obj: translator_subnet_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_subnet_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_subnet_unittests.Tpo -c -o run_unittests-translator_subnet_unittests.obj `if test -f 'translator_subnet_unittests.cc'; then $(CYGPATH_W) 'translator_subnet_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_subnet_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_subnet_unittests.Tpo $(DEPDIR)/run_unittests-translator_subnet_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_subnet_unittests.cc' object='run_unittests-translator_subnet_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_subnet_unittests.obj `if test -f 'translator_subnet_unittests.cc'; then $(CYGPATH_W) 'translator_subnet_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_subnet_unittests.cc'; fi`
+
+run_unittests-translator_shared_network_unittests.o: translator_shared_network_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_shared_network_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_shared_network_unittests.Tpo -c -o run_unittests-translator_shared_network_unittests.o `test -f 'translator_shared_network_unittests.cc' || echo '$(srcdir)/'`translator_shared_network_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_shared_network_unittests.Tpo $(DEPDIR)/run_unittests-translator_shared_network_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_shared_network_unittests.cc' object='run_unittests-translator_shared_network_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_shared_network_unittests.o `test -f 'translator_shared_network_unittests.cc' || echo '$(srcdir)/'`translator_shared_network_unittests.cc
+
+run_unittests-translator_shared_network_unittests.obj: translator_shared_network_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_shared_network_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_shared_network_unittests.Tpo -c -o run_unittests-translator_shared_network_unittests.obj `if test -f 'translator_shared_network_unittests.cc'; then $(CYGPATH_W) 'translator_shared_network_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_shared_network_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_shared_network_unittests.Tpo $(DEPDIR)/run_unittests-translator_shared_network_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_shared_network_unittests.cc' object='run_unittests-translator_shared_network_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_shared_network_unittests.obj `if test -f 'translator_shared_network_unittests.cc'; then $(CYGPATH_W) 'translator_shared_network_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_shared_network_unittests.cc'; fi`
+
+run_unittests-translator_utils_unittests.o: translator_utils_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_utils_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-translator_utils_unittests.Tpo -c -o run_unittests-translator_utils_unittests.o `test -f 'translator_utils_unittests.cc' || echo '$(srcdir)/'`translator_utils_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_utils_unittests.Tpo $(DEPDIR)/run_unittests-translator_utils_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_utils_unittests.cc' object='run_unittests-translator_utils_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_utils_unittests.o `test -f 'translator_utils_unittests.cc' || echo '$(srcdir)/'`translator_utils_unittests.cc
+
+run_unittests-translator_utils_unittests.obj: translator_utils_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-translator_utils_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-translator_utils_unittests.Tpo -c -o run_unittests-translator_utils_unittests.obj `if test -f 'translator_utils_unittests.cc'; then $(CYGPATH_W) 'translator_utils_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_utils_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-translator_utils_unittests.Tpo $(DEPDIR)/run_unittests-translator_utils_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_utils_unittests.cc' object='run_unittests-translator_utils_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-translator_utils_unittests.obj `if test -f 'translator_utils_unittests.cc'; then $(CYGPATH_W) 'translator_utils_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/translator_utils_unittests.cc'; fi`
+
+run_unittests-config_unittests.o: config_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-config_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-config_unittests.Tpo -c -o run_unittests-config_unittests.o `test -f 'config_unittests.cc' || echo '$(srcdir)/'`config_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-config_unittests.Tpo $(DEPDIR)/run_unittests-config_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='config_unittests.cc' object='run_unittests-config_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-config_unittests.o `test -f 'config_unittests.cc' || echo '$(srcdir)/'`config_unittests.cc
+
+run_unittests-config_unittests.obj: config_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-config_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-config_unittests.Tpo -c -o run_unittests-config_unittests.obj `if test -f 'config_unittests.cc'; then $(CYGPATH_W) 'config_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/config_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-config_unittests.Tpo $(DEPDIR)/run_unittests-config_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='config_unittests.cc' object='run_unittests-config_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-config_unittests.obj `if test -f 'config_unittests.cc'; then $(CYGPATH_W) 'config_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/config_unittests.cc'; fi`
+
+run_unittests-run_unittests.o: run_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-run_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-run_unittests.Tpo -c -o run_unittests-run_unittests.o `test -f 'run_unittests.cc' || echo '$(srcdir)/'`run_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-run_unittests.Tpo $(DEPDIR)/run_unittests-run_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='run_unittests.cc' object='run_unittests-run_unittests.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-run_unittests.o `test -f 'run_unittests.cc' || echo '$(srcdir)/'`run_unittests.cc
+
+run_unittests-run_unittests.obj: run_unittests.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-run_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-run_unittests.Tpo -c -o run_unittests-run_unittests.obj `if test -f 'run_unittests.cc'; then $(CYGPATH_W) 'run_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/run_unittests.cc'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/run_unittests-run_unittests.Tpo $(DEPDIR)/run_unittests-run_unittests.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='run_unittests.cc' object='run_unittests-run_unittests.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-run_unittests.obj `if test -f 'run_unittests.cc'; then $(CYGPATH_W) 'run_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/run_unittests.cc'; fi`
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list=' $(TESTS) '; \
+ $(am__tty_colors); \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=XPASS; \
+ ;; \
+ *) \
+ col=$$grn; res=PASS; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xfail=`expr $$xfail + 1`; \
+ col=$$lgn; res=XFAIL; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=FAIL; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ col=$$blu; res=SKIP; \
+ fi; \
+ echo "$${col}$$res$${std}: $$tst"; \
+ done; \
+ if test "$$all" -eq 1; then \
+ tests="test"; \
+ All=""; \
+ else \
+ tests="tests"; \
+ All="All "; \
+ fi; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="$$All$$all $$tests passed"; \
+ else \
+ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all $$tests failed"; \
+ else \
+ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ if test "$$skip" -eq 1; then \
+ skipped="($$skip test was not run)"; \
+ else \
+ skipped="($$skip tests were not run)"; \
+ fi; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ if test "$$failed" -eq 0; then \
+ col="$$grn"; \
+ else \
+ col="$$red"; \
+ fi; \
+ echo "$${col}$$dashes$${std}"; \
+ echo "$${col}$$banner$${std}"; \
+ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
+ test -z "$$report" || echo "$${col}$$report$${std}"; \
+ echo "$${col}$$dashes$${std}"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_config_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_host_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_option_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_pool_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_subnet_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-config_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-run_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_class_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_control_socket_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_database_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_host_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_logger_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_option_data_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_option_def_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_pd_pool_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_pool_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_shared_network_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_subnet_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_utils_unittests.Po
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_config_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_host_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_option_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_pool_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_subnet_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-adaptor_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-config_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-run_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_class_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_control_socket_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_database_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_host_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_logger_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_option_data_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_option_def_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_pd_pool_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_pool_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_shared_network_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_subnet_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_unittests.Po
+ -rm -f ./$(DEPDIR)/run_unittests-translator_utils_unittests.Po
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-TESTS \
+ check-am clean clean-generic clean-libtool \
+ clean-noinstPROGRAMS cscopelist-am ctags ctags-am distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am
+
+.PRECIOUS: Makefile
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/lib/yang/tests/adaptor_config_unittests.cc b/src/lib/yang/tests/adaptor_config_unittests.cc
new file mode 100644
index 0000000..1a5affa
--- /dev/null
+++ b/src/lib/yang/tests/adaptor_config_unittests.cc
@@ -0,0 +1,145 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <testutils/io_utils.h>
+#include <testutils/user_context_utils.h>
+#include <yang/adaptor_config.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::test;
+using namespace isc::yang;
+
+namespace {
+
+
+/// @brief Fixture class that helps testing AdaptorConfig
+class AdaptorConfigTest : public ::testing::Test {
+public:
+
+/// @brief Load an example JSON config
+///
+/// @param fname name of the file (expected to be a valid JSON config)
+/// @param v6 - false=v4, true=v6
+/// @param result - JSON converted by a AdaptorConfig::preprocess[4/6]
+void testFile(const std::string& fname, bool v6, ElementPtr& result) {
+ ElementPtr json;
+ ElementPtr reference_json;
+
+ string decommented = decommentJSONfile(fname);
+
+ EXPECT_NO_THROW(json = Element::fromJSONFile(decommented, true));
+ reference_json = moveComments(json);
+
+ // remove the temporary file
+ EXPECT_NO_THROW(::remove(decommented.c_str()));
+
+ string before = json->str();
+ if (v6) {
+ ASSERT_NO_THROW_LOG(AdaptorConfig::preProcess6(json));
+ } else {
+ ASSERT_NO_THROW_LOG(AdaptorConfig::preProcess4(json));
+ }
+ string after = json->str();
+
+ EXPECT_FALSE(before.empty());
+ EXPECT_FALSE(after.empty());
+
+ result = json;
+}
+
+};
+
+TEST_F(AdaptorConfigTest, loadExamples4) {
+ vector<string> configs = {
+ "advanced.json",
+ "all-keys-netconf.json",
+ "backends.json",
+ "classify.json",
+ "classify2.json",
+ "comments.json",
+ "config-backend.json",
+ "dhcpv4-over-dhcpv6.json",
+ "global-reservations.json",
+ "ha-load-balancing-primary.json",
+ "hooks.json",
+ "hooks-radius.json",
+ "leases-expiration.json",
+ "multiple-options.json",
+ //"mysql-reservations.json", commented for new TLS parameters
+ "pgsql-reservations.json",
+ "reservations.json",
+ "several-subnets.json",
+ "shared-network.json",
+ "single-subnet.json",
+ "with-ddns.json",
+ };
+
+ ElementPtr x;
+
+ for (int i = 0; i<configs.size(); i++) {
+ x.reset();
+ testFile(string(CFG_EXAMPLES) + "/kea4/" + configs[i], false, x);
+ ASSERT_TRUE(x);
+ }
+}
+
+TEST_F(AdaptorConfigTest, loadExamples6) {
+ vector<string> configs = {
+ "advanced.json",
+ "all-keys-netconf.json",
+ "backends.json",
+ "classify.json",
+ "classify2.json",
+ "comments.json",
+ "config-backend.json",
+ "dhcpv4-over-dhcpv6.json",
+ "duid.json",
+ "global-reservations.json",
+ "ha-hot-standby.json",
+ "hooks.json",
+ "iPXE.json",
+ "leases-expiration.json",
+ "multiple-options.json",
+ //"mysql-reservations.json", commented for new TLS parameters
+ "pgsql-reservations.json",
+ "reservations.json",
+ "several-subnets.json",
+ "shared-network.json",
+ "simple.json",
+ "softwire46.json",
+ "stateless.json",
+ "tee-times.json",
+ "with-ddns.json",
+ };
+ ElementPtr x;
+
+ for (int i = 0; i<configs.size(); i++) {
+ x.reset();
+ testFile(string(CFG_EXAMPLES) + "/kea6/" + configs[i], true, x);
+ ASSERT_TRUE(x);
+ }
+}
+
+/// In general, the AdatorConfig class doesn't need very thorough
+/// direct tests, as there will be tests that will process whole
+/// configuration that will in turn use AdaptorConfig calls.
+/// Nevertheless, here are some ideas for tests. We hope to have
+/// them implemented one day.
+///
+/// @todo: Check subnet-id assigned in subnets using any config
+/// @todo: Check shared-networks assign id using kea4/shared-network.json
+/// @todo: Check option classes using kea4/classify2.json
+/// @todo: Check option data using kea6/with-ddns.json
+/// @todo: Check option defs using kea6/dhcpv4-over-dhcpv6.json
+
+}; // end of anonymous namespace
diff --git a/src/lib/yang/tests/adaptor_host_unittests.cc b/src/lib/yang/tests/adaptor_host_unittests.cc
new file mode 100644
index 0000000..95eb3a2
--- /dev/null
+++ b/src/lib/yang/tests/adaptor_host_unittests.cc
@@ -0,0 +1,119 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/adaptor_host.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+
+namespace {
+
+// Verifies that quoteIdentifier does not touch an identifier which
+// has a type different from flex-d.
+TEST(AdaptorHostTest, notFlexId) {
+ string config = "{\n"
+ " \"hw-address\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"ip-address\": \"192.0.2.201\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorHost::quoteIdentifier(json));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies that quoteIdentifier does not touch a flex-id identifier
+// without quotes.
+TEST(AdaptorHostTest, noQuote) {
+ string config = "{\n"
+ " \"flex-id\": \"s0mEVaLue\",\n"
+ " \"ip-address\": \"192.0.2.206\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorHost::quoteIdentifier(json));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies that quoteIdentifier removes quotes from a flex-id identifier.
+TEST(AdaptorHostTest, quotes) {
+ string config = "{\n"
+ " \"flex-id\": \"'somevalue'\",\n"
+ " \"ip-addresses\": \"2001:db8:1:cafe::2\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorHost::quoteIdentifier(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr id = json->get("flex-id");
+ ASSERT_TRUE(id);
+ ASSERT_EQ(Element::string, id->getType());
+ EXPECT_EQ("73:6f:6d:65:76:61:6c:75:65", id->stringValue());
+}
+
+// Verifies that quoteIdentifier removes quotes from a flex-id identifier
+// but does not interpret a quote in the middle.
+TEST(AdaptorHostTest, extraQuote) {
+ string config = "{\n"
+ " \"flex-id\": \"'some'value'\",\n"
+ " \"ip-addresses\": \"2001:db8:1:cafe::2\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorHost::quoteIdentifier(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr id = json->get("flex-id");
+ ASSERT_TRUE(id);
+ ASSERT_EQ(Element::string, id->getType());
+ EXPECT_EQ("73:6f:6d:65:27:76:61:6c:75:65", id->stringValue());
+}
+
+// Verifies that quoteIdentifier works on not standard characters too.
+TEST(AdaptorHostTest, notStandard) {
+ string config = "{\n"
+ " \"flex-id\": \"'some\\\"value'\",\n"
+ " \"ip-addresses\": \"2001:db8:1:cafe::2\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorHost::quoteIdentifier(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr id = json->get("flex-id");
+ ASSERT_TRUE(id);
+ ASSERT_EQ(Element::string, id->getType());
+ EXPECT_EQ("73:6f:6d:65:22:76:61:6c:75:65", id->stringValue());
+}
+
+// Verifies that quoteIdentifier works on not standard characters too
+// even without quotes.
+TEST(AdaptorHostTest, notQuoted) {
+ string config = "{\n"
+ " \"flex-id\": \"some\\\"value\",\n"
+ " \"ip-addresses\": \"2001:db8:1:cafe::2\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorHost::quoteIdentifier(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr id = json->get("flex-id");
+ ASSERT_TRUE(id);
+ ASSERT_EQ(Element::string, id->getType());
+ EXPECT_EQ("73:6f:6d:65:22:76:61:6c:75:65", id->stringValue());
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/adaptor_option_unittests.cc b/src/lib/yang/tests/adaptor_option_unittests.cc
new file mode 100644
index 0000000..1b23f05
--- /dev/null
+++ b/src/lib/yang/tests/adaptor_option_unittests.cc
@@ -0,0 +1,241 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <dhcp/dhcp4.h>
+#include <dhcp/dhcp6.h>
+#include <dhcp/option_data_types.h>
+#include <dhcp/option_space.h>
+#include <testutils/gtest_utils.h>
+#include <yang/adaptor_option.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::yang;
+
+namespace {
+
+// Verifies that setSpace adds a space to an option without this entry.
+TEST(AdaptorOptionTest, setSpaceNoSpace) {
+ string config = "{\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorOption::setSpace(json, "foo"));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr space = json->get("space");
+ ASSERT_TRUE(space);
+ ASSERT_EQ(Element::string, space->getType());
+ EXPECT_EQ("foo", space->stringValue());
+}
+
+// Verifies that setSpace does not change to an option with space.
+TEST(AdaptorOptionTest, setSpace) {
+ string config = "{\n"
+ " \"space\": \"dhcp4\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorOption::setSpace(json, "foo"));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies that checkType accepts an option with type.
+TEST(AdaptorOptionTest, checkType) {
+ string config = "{\n"
+ " \"type\": \"string\"\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ EXPECT_NO_THROW(AdaptorOption::checkType(json));
+}
+
+// Verifies that checkType does not accept an option without type.
+TEST(AdaptorOptionTest, checkTypeNoType) {
+ string config = "{\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ EXPECT_THROW(AdaptorOption::checkType(json), MissingKey);
+}
+
+// Verifies that checkCode accepts an option with code.
+TEST(AdaptorOptionTest, checkCode) {
+ string config = "{\n"
+ " \"code\": 123\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ EXPECT_NO_THROW(AdaptorOption::checkCode(json));
+}
+
+// Verifies that checkCode does not accept an option without code.
+TEST(AdaptorOptionTest, checkCodeNoCode) {
+ string config = "{\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ EXPECT_THROW(AdaptorOption::checkCode(json), MissingKey);
+}
+
+// Verifies that collect works as expected.
+TEST(AdaptorOptionTest, collect) {
+ string config = "{\n"
+ " \"code\": 123,\n"
+ " \"name\": \"foo\",\n"
+ " \"space\": \"bar\"\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ OptionCodes codes;
+ ASSERT_NO_THROW_LOG(AdaptorOption::collect(json, codes));
+ EXPECT_EQ(1, codes.size());
+ EXPECT_EQ(123, codes["bar@foo"]);
+ EXPECT_THROW(codes.at("foo@bar"), out_of_range);
+}
+
+// Verifies that collect skips an already known option definition.
+TEST(AdaptorOptionTest, collectKnown) {
+ string config = "{\n"
+ " \"code\": 123,\n"
+ " \"name\": \"foo\",\n"
+ " \"space\": \"bar\"\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ OptionCodes codes = { { "bar@foo", 111 } };
+ ASSERT_NO_THROW_LOG(AdaptorOption::collect(json, codes));
+ EXPECT_EQ(1, codes.size());
+ EXPECT_EQ(111, codes["bar@foo"]);
+}
+
+// Verifies that setCode adds a code to an option without this entry
+// when the code is available in the map.
+TEST(AdaptorOptionTest, setCodeNoCode) {
+ string config = "{\n"
+ " \"name\": \"foo\",\n"
+ " \"space\": \"bar\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ OptionCodes codes = { { "bar@foo", 123 } };
+ EXPECT_NO_THROW(AdaptorOption::setCode(json, codes));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr code = json->get("code");
+ ASSERT_TRUE(code);
+ ASSERT_EQ(Element::integer, code->getType());
+ EXPECT_EQ(123, code->intValue());
+}
+
+// Verifies that setCode does not change to an option with code.
+TEST(AdaptorOptionTest, setCode) {
+ string config = "{\n"
+ " \"code\": \"dhcp4\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ OptionCodes codes;
+ EXPECT_NO_THROW(AdaptorOption::setCode(json, codes));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies that setCode raises an error on option without name and code.
+TEST(AdaptorOptionTest, setCodeNoName) {
+ string config = "{\n"
+ " \"space\": \"bar\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ OptionCodes codes;
+ EXPECT_THROW(AdaptorOption::setCode(json, codes), MissingKey);
+}
+
+// Note the code assumes there is a space, i.e. setSpace was called.
+
+// Verifies that setCode raises an error on option without code but
+// the code is not available in the map.
+TEST(AdaptorOptionTest, setCodeNotInMap) {
+ string config = "{\n"
+ " \"name\": \"foo\",\n"
+ " \"space\": \"bar\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ OptionCodes codes;
+ EXPECT_THROW(AdaptorOption::setCode(json, codes), MissingKey);
+}
+
+/// @brief Test class to make initCodes public.
+class TestAdaptorOption : public AdaptorOption {
+public:
+ using AdaptorOption::initCodesInternal;
+};
+
+// Verifies that initCodesInternal works as expected.
+TEST(AdaptorOptionTest, initCodesInternal) {
+ const OptionDefParams DEFS[] = {
+ { "subnet-mask", DHO_SUBNET_MASK, DHCP4_OPTION_SPACE,
+ OPT_IPV4_ADDRESS_TYPE, false, 0, 0, "" },
+ { "time-offset", DHO_TIME_OFFSET, DHCP4_OPTION_SPACE, OPT_INT32_TYPE,
+ false, 0, 0, "" }
+ };
+ const size_t DEFS_SIZE = sizeof(DEFS) / sizeof(DEFS[0]);
+ OptionCodes codes;
+ ASSERT_NO_THROW_LOG(TestAdaptorOption::initCodesInternal(codes,
+ DHCP4_OPTION_SPACE,
+ DEFS,
+ DEFS_SIZE));
+ ASSERT_EQ(2, codes.size());
+ EXPECT_EQ(DHO_SUBNET_MASK, codes["dhcp4@subnet-mask"]);
+ EXPECT_EQ(DHO_TIME_OFFSET, codes["dhcp4@time-offset"]);
+}
+
+// Verifies that initCodes works as expected with DHCPv4.
+TEST(AdaptorOptionTest, initCodes4) {
+ OptionCodes codes;
+ ASSERT_NO_THROW_LOG(AdaptorOption::initCodes(codes, DHCP4_OPTION_SPACE));
+ EXPECT_EQ(DHO_SUBNET_MASK, codes["dhcp4@subnet-mask"]);
+ EXPECT_EQ(DHO_TIME_OFFSET, codes["dhcp4@time-offset"]);
+ EXPECT_THROW(codes.at("dhcp6@clientid"), out_of_range);
+
+ // initCodes loads last resort too.
+ EXPECT_EQ(DHO_VENDOR_ENCAPSULATED_OPTIONS,
+ codes["dhcp4@vendor-encapsulated-options"]);
+
+ // and DOCSIS3.
+ EXPECT_EQ(2, codes["vendor-4491@tftp-servers"]);
+}
+
+// Verifies that initCodes works as expected with DHCPv6.
+TEST(AdaptorOptionTest, initCodes6) {
+ OptionCodes codes;
+ ASSERT_NO_THROW_LOG(AdaptorOption::initCodes(codes, DHCP6_OPTION_SPACE));
+ EXPECT_EQ(D6O_CLIENTID, codes["dhcp6@clientid"]);
+ EXPECT_EQ(D6O_SERVERID, codes["dhcp6@serverid"]);
+ EXPECT_THROW(codes.at("dhcp4@subnet-mask"), out_of_range);
+
+ // initCodes loads DOCSIS3 too.
+ EXPECT_EQ(32, codes["vendor-4491@tftp-servers"]);
+
+ // Various MAP suboptions.
+ EXPECT_EQ(D6O_S46_BR, codes["s46-cont-mape-options@s46-br"]);
+ EXPECT_EQ(D6O_S46_V4V6BIND, codes["s46-cont-lw-options@s46-v4v6bind"]);
+ EXPECT_EQ(D6O_S46_PORTPARAMS, codes["s46-v4v6bind-options@s46-portparams"]);
+
+ // And ISC space.
+ EXPECT_EQ(ISC_V6_4O6_INTERFACE, codes["vendor-2495@4o6-interface"]);
+}
+
+} // end of anonymous namespace
diff --git a/src/lib/yang/tests/adaptor_pool_unittests.cc b/src/lib/yang/tests/adaptor_pool_unittests.cc
new file mode 100644
index 0000000..dd70716
--- /dev/null
+++ b/src/lib/yang/tests/adaptor_pool_unittests.cc
@@ -0,0 +1,274 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/adaptor_pool.h>
+#include <yang/yang_models.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+
+namespace {
+
+// Verifies that canonizePool does not touch a prefix without space.
+TEST(AdaptorPoolTest, canonizePoolPrefixNoSpace) {
+ string config = "{\n"
+ " \"pool\": \"192.0.2.128/28\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorPool::canonizePool(json));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies that canonizePool does not touch a canonical range.
+TEST(AdaptorPoolTest, canonizePoolRange) {
+ string config = "{\n"
+ " \"pool\": \"192.0.2.1 - 192.0.2.200\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorPool::canonizePool(json));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies that canonizePool removes spaces from a prefix.
+TEST(AdaptorPoolTest, canonizePoolPrefixSpaces) {
+ string config = "{\n"
+ " \"pool\": \"192.0.2.128 /\t28\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorPool::canonizePool(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr pool = json->get("pool");
+ ASSERT_TRUE(pool);
+ ASSERT_EQ(Element::string, pool->getType());
+ EXPECT_EQ("192.0.2.128/28", pool->stringValue());
+}
+
+// Verifies that canonizePool adds two spaces from a range.
+TEST(AdaptorPoolTest, canonizePoolRangeNoSpace) {
+ string config = "{\n"
+ " \"pool\": \"192.0.2.1-192.0.2.200\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorPool::canonizePool(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr pool = json->get("pool");
+ ASSERT_TRUE(pool);
+ ASSERT_EQ(Element::string, pool->getType());
+ EXPECT_EQ("192.0.2.1 - 192.0.2.200", pool->stringValue());
+}
+
+// Verifies that canonizePool removes extra spaces from a range.
+TEST(AdaptorPoolTest, canonizePoolRangeExtraSpaces) {
+ string config = "{\n"
+ " \"pool\": \"192.0.2.1 - 192.0.2.200\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ EXPECT_NO_THROW(AdaptorPool::canonizePool(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr pool = json->get("pool");
+ ASSERT_TRUE(pool);
+ ASSERT_EQ(Element::string, pool->getType());
+ EXPECT_EQ("192.0.2.1 - 192.0.2.200", pool->stringValue());
+}
+
+// Verifies that fromSubnet is specific to ietf-dhcpv6-server model.
+TEST(AdaptorPoolTest, fromSubnetKea) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"192.0.2.1 - 192.0.2.100\"\n"
+ " },{\n"
+ " \"pool\": \"192.0.2.101 - 192.0.2.200\"\n"
+ " } ],\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ConstElementPtr pools = json->get("pools");
+
+ // This should be no-op for kea-dhcp4-server and kea-dhcp6-server models
+ EXPECT_NO_THROW(AdaptorPool::fromSubnet(KEA_DHCP4_SERVER, json, pools));
+ EXPECT_TRUE(copied->equals(*json));
+ // The model is checked first.
+ EXPECT_NO_THROW(AdaptorPool::fromSubnet(KEA_DHCP6_SERVER, json, pools));
+ EXPECT_TRUE(copied->equals(*json));
+
+ // Check that the model name is actually checked.
+ EXPECT_THROW(AdaptorPool::fromSubnet("non-existent-module", json, pools),
+ NotImplemented);
+}
+
+// Verifies that fromSubnet works as expected.
+TEST(AdaptorPoolTest, fromSubnet) {
+ string config = "{\n"
+ " \"subnet\": \"2001:db8:1::/64\",\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8:1::/80\"\n"
+ " },{\n"
+ " \"pool\": \"2001:db8:1:0:1::/80\"\n"
+ " } ],\n"
+ " \"preferred-lifetime\": 3000,\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ConstElementPtr pools = json->get("pools");
+ EXPECT_NO_THROW(AdaptorPool::fromSubnet(IETF_DHCPV6_SERVER, json, pools));
+ EXPECT_FALSE(copied->equals(*json));
+ pools = json->get("pools");
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(2, pools->size());
+ ConstElementPtr pool = pools->get(0);
+ ASSERT_TRUE(pool);
+ string expected = "{"
+ " \"pool\": \"2001:db8:1::/80\","
+ " \"preferred-lifetime\": 3000,"
+ " \"rebind-timer\": 2000,"
+ " \"renew-timer\": 1000,"
+ " \"valid-lifetime\": 4000 }";
+ EXPECT_EQ(expected, pool->str());
+ pool = pools->get(1);
+ ASSERT_TRUE(pool);
+ expected = "{"
+ " \"pool\": \"2001:db8:1:0:1::/80\","
+ " \"preferred-lifetime\": 3000,"
+ " \"rebind-timer\": 2000,"
+ " \"renew-timer\": 1000,"
+ " \"valid-lifetime\": 4000 }";
+ EXPECT_EQ(expected, pool->str());
+}
+
+// Verifies that toSubnet is specific to ietf-dhcpv6-server model.
+TEST(AdaptorPoolTest, toSubnetKea) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"192.0.2.1 - 192.0.2.100\"\n"
+ " },{\n"
+ " \"pool\": \"192.0.2.101 - 192.0.2.200\"\n"
+ " } ],\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ConstElementPtr pools = json->get("pools");
+ EXPECT_NO_THROW(AdaptorPool::toSubnet(KEA_DHCP4_SERVER, json, pools));
+ EXPECT_TRUE(copied->equals(*json));
+ // The model is checked first.
+ EXPECT_NO_THROW(AdaptorPool::toSubnet(KEA_DHCP6_SERVER, json, pools));
+ EXPECT_TRUE(copied->equals(*json));
+ // Model name is not free: an error is raised if it is not expected.
+ EXPECT_THROW(AdaptorPool::toSubnet("keatest-module", json, pools),
+ NotImplemented);
+}
+
+// Verifies that toSubnet works as expected.
+TEST(AdaptorPoolTest, toSubnet) {
+ string config = "{\n"
+ " \"subnet\": \"2001:db8:1::/64\",\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8:1::/80\",\n"
+ " \"preferred-lifetime\": 3000,\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000\n"
+ " },{\n"
+ " \"pool\": \"2001:db8:1:0:1::/80\",\n"
+ " \"preferred-lifetime\": 3000,\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000\n"
+ " } ]\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ConstElementPtr pools = json->get("pools");
+ EXPECT_NO_THROW(AdaptorPool::toSubnet(IETF_DHCPV6_SERVER, json, pools));
+ EXPECT_FALSE(copied->equals(*json));
+ // Check timers.
+ ConstElementPtr timer = json->get("valid-lifetime");
+ ASSERT_TRUE(timer);
+ EXPECT_EQ("4000", timer->str());
+ timer = json->get("preferred-lifetime");
+ ASSERT_TRUE(timer);
+ EXPECT_EQ("3000", timer->str());
+ timer = json->get("renew-timer");
+ ASSERT_TRUE(timer);
+ EXPECT_EQ("1000", timer->str());
+ timer = json->get("rebind-timer");
+ ASSERT_TRUE(timer);
+ EXPECT_EQ("2000", timer->str());
+ // Timers must be removed as they are not allowed here in Kea.
+ pools = json->get("pools");
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(2, pools->size());
+ ConstElementPtr pool = pools->get(0);
+ ASSERT_TRUE(pool);
+ EXPECT_EQ("{ \"pool\": \"2001:db8:1::/80\" }", pool->str());
+ pool = pools->get(1);
+ ASSERT_TRUE(pool);
+ EXPECT_EQ("{ \"pool\": \"2001:db8:1:0:1::/80\" }", pool->str());
+}
+
+// Verifies that toSubnet fails on inconsistent input.
+TEST(AdaptorPoolTest, toSubnetBad) {
+ // Changed last rebind-timer to a different value.
+ string config = "{\n"
+ " \"subnet\": \"2001:db8:1::/64\",\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8:1::/80\",\n"
+ " \"preferred-lifetime\": 3000,\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000\n"
+ " },{\n"
+ " \"pool\": \"2001:db8:1:0:1::/80\",\n"
+ " \"preferred-lifetime\": 3000,\n"
+ " \"valid-lifetime\": 4000,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 20\n"
+ " } ]\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr pools = json->get("pools");
+ EXPECT_THROW(AdaptorPool::toSubnet(IETF_DHCPV6_SERVER, json, pools),
+ BadValue);
+}
+
+}; // end of anonymous namespace
diff --git a/src/lib/yang/tests/adaptor_subnet_unittests.cc b/src/lib/yang/tests/adaptor_subnet_unittests.cc
new file mode 100644
index 0000000..54ec710
--- /dev/null
+++ b/src/lib/yang/tests/adaptor_subnet_unittests.cc
@@ -0,0 +1,213 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/adaptor_subnet.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::yang;
+
+namespace {
+
+// Verifies how collectID handles a subnet entry without ID.
+TEST(AdaptorSubnetTest, collectNoId) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\"\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ SubnetIDSet set;
+ bool ret = true;
+ ASSERT_NO_THROW_LOG(ret = AdaptorSubnet::collectID(json, set));
+ EXPECT_FALSE(ret);
+ EXPECT_EQ(0, set.size());
+}
+
+// Verifies how collectID handles a subnet entry with an ID.
+TEST(AdaptorSubnetTest, collectId) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"id\": 123\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ SubnetIDSet set;
+ bool ret = false;
+ ASSERT_NO_THROW_LOG(ret = AdaptorSubnet::collectID(json, set));
+ EXPECT_TRUE(ret);
+ EXPECT_EQ(1, set.size());
+ EXPECT_EQ(1, set.count(123));
+}
+
+// Verifies how collectID handles a subnet entry with an ID which is
+// already known: the set is not updated.
+TEST(AdaptorSubnetTest, collectKnownId) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"id\": 123\n"
+ "}";
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ SubnetIDSet set = { 123 };
+ bool ret = false;
+ ASSERT_NO_THROW_LOG(ret = AdaptorSubnet::collectID(json, set));
+ EXPECT_TRUE(ret);
+ EXPECT_EQ(1, set.size());
+ EXPECT_EQ(1, set.count(123));
+}
+
+// Verifies how assignID handles a subnet entry without ID: the next ID
+// is assigned, the set is updated and the next ID is incremented.
+TEST(AdaptorSubnetTest, assignNoId) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ SubnetIDSet set;
+ SubnetID next_id = 123;
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::assignID(json, set, next_id));
+ EXPECT_FALSE(copied->equals(*json));
+ EXPECT_EQ(1, set.size());
+ EXPECT_EQ(1, set.count(123));
+ EXPECT_EQ(124, next_id);
+ ConstElementPtr id = json->get("id");
+ ASSERT_TRUE(id);
+ ASSERT_EQ(Element::integer, id->getType());
+ EXPECT_EQ(123, id->intValue());
+}
+
+// Verifies how assignID handles a subnet entry without ID but with the
+// candidate ID already used: the used value is skipped.
+TEST(AdaptorSubnetTest, assignNoIdUsed) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ SubnetIDSet set = { 123 };
+ SubnetID next_id = 123;
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::assignID(json, set, next_id));
+ EXPECT_FALSE(copied->equals(*json));
+ EXPECT_EQ(2, set.size());
+ EXPECT_EQ(1, set.count(123));
+ EXPECT_EQ(1, set.count(124));
+ EXPECT_EQ(125, next_id);
+ ConstElementPtr id = json->get("id");
+ ASSERT_TRUE(id);
+ ASSERT_EQ(Element::integer, id->getType());
+ EXPECT_EQ(124, id->intValue());
+}
+
+// Verifies how assignID handles a subnet entry with ID: no change.
+TEST(AdaptorSubnetTest, assignId) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"id\": 123\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ SubnetIDSet set; // ignored.
+ SubnetID next_id = 123; // ignored.
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::assignID(json, set, next_id));
+ EXPECT_TRUE(copied->equals(*json));
+ EXPECT_EQ(0, set.size());
+ EXPECT_EQ(123, next_id);
+}
+
+// Verifies how updateRelay handles a subnet entry without relay: no change.
+TEST(AdaptorSubnetTest, updateNoRelay) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\"\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::updateRelay(json));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies how updateRelay handles a subnet entry with empty relay:
+// the relay entry is useless and removed.
+TEST(AdaptorSubnetTest, updateEmptyRelay) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"relay\": { }\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::updateRelay(json));
+ EXPECT_FALSE(copied->equals(*json));
+ EXPECT_FALSE(json->get("relay"));
+}
+
+// Verifies how updateRelay handles a subnet entry with relay which
+// has empty addresses: the relay entry is useless and removed.
+TEST(AdaptorSubnetTest, updateRelayEmptyAddresses) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"relay\": {\n"
+ " \"ip-addresses\": [ ]\n"
+ " }\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::updateRelay(json));
+ EXPECT_FALSE(copied->equals(*json));
+ EXPECT_FALSE(json->get("relay"));
+}
+
+// Verifies how updateRelay handles a subnet entry with relay which
+// has addresses: no change.
+TEST(AdaptorSubnetTest, updateRelayAddresses) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"relay\": {\n"
+ " \"ip-addresses\": [ \"192.168.1.1\" ]\n"
+ " }\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::updateRelay(json));
+ EXPECT_TRUE(copied->equals(*json));
+}
+
+// Verifies how updateRelay handles a subnet entry with relay which
+// has only address: the address is moved to a new list.
+TEST(AdaptorSubnetTest, updateRelayAddress) {
+ string config = "{\n"
+ " \"subnet\": \"192.0.2.0/24\",\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"192.168.1.1\"\n"
+ " }\n"
+ "}";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ ConstElementPtr copied = copy(json);
+ ASSERT_NO_THROW_LOG(AdaptorSubnet::updateRelay(json));
+ EXPECT_FALSE(copied->equals(*json));
+ ConstElementPtr relay = json->get("relay");
+ ASSERT_TRUE(relay);
+ string expected = "{ \"ip-addresses\": [ \"192.168.1.1\" ] }";
+ EXPECT_EQ(expected, relay->str());
+}
+
+// It does not make sense to have both ip-address and ip-addresses...
+
+}; // end of anonymous namespace
diff --git a/src/lib/yang/tests/adaptor_unittests.cc b/src/lib/yang/tests/adaptor_unittests.cc
new file mode 100644
index 0000000..fc75ad1
--- /dev/null
+++ b/src/lib/yang/tests/adaptor_unittests.cc
@@ -0,0 +1,394 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/adaptor.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+
+namespace {
+
+// Test that get context works as expected i.e. moves a comment into
+// the user context creating it if not exists.
+TEST(AdaptorTest, getContext) {
+ // Empty.
+ string config = "{\n"
+ "}\n";
+ ConstElementPtr json = Element::fromJSON(config);
+ ConstElementPtr context;
+ ASSERT_NO_THROW_LOG(context = Adaptor::getContext(json));
+ EXPECT_FALSE(context);
+
+ // No relevant.
+ config = "{\n"
+ " \"foo\": 1\n"
+ "}\n";
+ json = Element::fromJSON(config);
+ ASSERT_NO_THROW_LOG(context = Adaptor::getContext(json));
+ EXPECT_FALSE(context);
+
+ // User context.
+ config = "{\n"
+ " \"foo\": 1,\n"
+ " \"user-context\": { \"bar\": 2 }\n"
+ "}\n";
+ json = Element::fromJSON(config);
+ ASSERT_NO_THROW_LOG(context = Adaptor::getContext(json));
+ ASSERT_TRUE(context);
+ EXPECT_EQ("{ \"bar\": 2 }", context->str());
+
+ // Comment.
+ config = "{\n"
+ " \"foo\": 1,\n"
+ " \"comment\": \"a comment\"\n"
+ "}\n";
+ json = Element::fromJSON(config);
+ ASSERT_NO_THROW_LOG(context = Adaptor::getContext(json));
+ ASSERT_TRUE(context);
+ EXPECT_EQ("{ \"comment\": \"a comment\" }", context->str());
+
+ // User context and comment.
+ config = "{\n"
+ " \"foo\": 1,\n"
+ " \"user-context\": { \"bar\": 2 },\n"
+ " \"comment\": \"a comment\"\n"
+ "}\n";
+ json = Element::fromJSON(config);
+ ASSERT_NO_THROW_LOG(context = Adaptor::getContext(json));
+ ASSERT_TRUE(context);
+ EXPECT_EQ("{ \"bar\": 2, \"comment\": \"a comment\" }", context->str());
+
+ // User context with conflicting comment and comment.
+ config = "{\n"
+ " \"foo\": 1,\n"
+ " \"user-context\": {\n"
+ " \"bar\": 2,\n"
+ " \"comment\": \"conflicting\"\n"
+ " },\n"
+ " \"comment\": \"a comment\"\n"
+ "}\n";
+ json = Element::fromJSON(config);
+ ASSERT_NO_THROW_LOG(context = Adaptor::getContext(json));
+ ASSERT_TRUE(context);
+ EXPECT_EQ("{ \"bar\": 2, \"comment\": \"a comment\" }", context->str());
+}
+
+// Test that fromParent works as expected i.e. moves parameters from the
+// parent to children and not overwrite them.
+TEST(AdaptorTest, fromParent) {
+ string config = "{\n"
+ " \"param1\": 123,\n"
+ " \"param2\": \"foo\",\n"
+ " \"list\": [\n"
+ " {\n"
+ " \"param1\": 234\n"
+ " },{\n"
+ " \"another\": \"entry\"\n"
+ " }\n"
+ " ]\n"
+ "}\n";
+
+ ConstElementPtr json = Element::fromJSON(config);
+ EXPECT_NO_THROW(Adaptor::fromParent("param1", json, json->get("list")));
+ EXPECT_NO_THROW(Adaptor::fromParent("param2", json, json->get("list")));
+ EXPECT_NO_THROW(Adaptor::fromParent("param3", json, json->get("list")));
+
+ string expected = "{\n"
+ " \"param1\": 123,\n"
+ " \"param2\": \"foo\",\n"
+ " \"list\": [\n"
+ " {\n"
+ " \"param1\": 234,\n"
+ " \"param2\": \"foo\"\n"
+ " },{\n"
+ " \"another\": \"entry\",\n"
+ " \"param1\": 123,\n"
+ " \"param2\": \"foo\"\n"
+ " }\n"
+ " ]\n"
+ "}\n";
+ EXPECT_TRUE(json->equals(*Element::fromJSON(expected)));
+}
+
+// Test that toParent works as expected i.e. moves parameters from children
+// to the parent throwing when a value differs between two children.
+TEST(AdaptorTest, toParent) {
+ string config = "{\n"
+ " \"list\": [\n"
+ " {\n"
+ " \"param2\": \"foo\",\n"
+ " \"param3\": 234,\n"
+ " \"param4\": true\n"
+ " },{\n"
+ " \"another\": \"entry\",\n"
+ " \"param2\": \"foo\",\n"
+ " \"param3\": 123,\n"
+ " \"param5\": false\n"
+ " }\n"
+ " ]\n"
+ "}\n";
+
+ ElementPtr json = Element::fromJSON(config);
+ EXPECT_NO_THROW(Adaptor::toParent("param1", json, json->get("list")));
+ EXPECT_TRUE(json->equals(*Element::fromJSON(config)));
+
+ string expected = "{\n"
+ " \"param2\": \"foo\",\n"
+ " \"list\": [\n"
+ " {\n"
+ " \"param3\": 234,\n"
+ " \"param4\": true\n"
+ " },{\n"
+ " \"another\": \"entry\",\n"
+ " \"param3\": 123,\n"
+ " \"param5\": false\n"
+ " }\n"
+ " ]\n"
+ "}\n";
+
+ EXPECT_NO_THROW(Adaptor::toParent("param2",json, json->get("list")));
+ EXPECT_TRUE(json->equals(*Element::fromJSON(expected)));
+
+ // param[345] have different values so it should throw.
+ EXPECT_THROW(Adaptor::toParent("param3",json, json->get("list")),
+ BadValue);
+ EXPECT_THROW(Adaptor::toParent("param4",json, json->get("list")),
+ BadValue);
+ EXPECT_THROW(Adaptor::toParent("param5",json, json->get("list")),
+ BadValue);
+ // And not modify the value.
+ EXPECT_TRUE(json->equals(*Element::fromJSON(expected)));
+}
+
+// Test for modify (maps & insert).
+TEST(AdaptorTest, modifyMapInsert) {
+ string config = "{\n"
+ " \"foo\": {\n"
+ " \"bar\": {\n"
+ "}}}\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ string spath = "[ \"foo\", \"bar\" ]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"insert\",\n"
+ " \"key\": \"test\",\n"
+ " \"value\": 1234\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "{\n"
+ " \"foo\": {\n"
+ " \"bar\": {\n"
+ " \"test\": 1234\n"
+ "}}}\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+// Test for modify (maps & replace).
+TEST(AdaptorTest, modifyMapReplace) {
+ string config = "{\n"
+ " \"foo\": {\n"
+ " \"bar\": {\n"
+ " \"test1\": 1234,\n"
+ " \"test2\": 1234\n"
+ "}}}\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ string spath = "[ \"foo\", \"bar\" ]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"insert\",\n"
+ " \"key\": \"test1\",\n"
+ " \"value\": 5678\n"
+ "},{\n"
+ " \"action\": \"replace\",\n"
+ " \"key\": \"test2\",\n"
+ " \"value\": 5678\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "{\n"
+ " \"foo\": {\n"
+ " \"bar\": {\n"
+ " \"test1\": 1234,\n"
+ " \"test2\": 5678\n"
+ "}}}\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+// Test for modify (maps & delete).
+TEST(AdaptorTest, modifyMapDelete) {
+ string config = "{\n"
+ " \"foo\": {\n"
+ " \"bar\": {\n"
+ " \"test\": 1234\n"
+ "}}}\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ string spath = "[ \"foo\", \"bar\" ]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"delete\",\n"
+ " \"key\": \"test\"\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "{\n"
+ " \"foo\": {\n"
+ " \"bar\": {\n"
+ "}}}\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+// Test for modify (lists & insert).
+TEST(AdaptorTest, modifyListInsert) {
+ string config = "[\n"
+ "[{\n"
+ " \"foo\": \"bar\"\n"
+ "}]]\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ string spath = "[ 0, { \"key\": \"foo\", \"value\": \"bar\" }]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"insert\",\n"
+ " \"key\": \"test\",\n"
+ " \"value\": 1234\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "[\n"
+ "[{\n"
+ " \"foo\": \"bar\",\n"
+ " \"test\": 1234\n"
+ "}]]\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+// Test for modify (list all & insert).
+TEST(AdaptorTest, modifyListAllInsert) {
+ string config = "[\n"
+ "{},\n"
+ "{},\n"
+ "{ \"test\": 1234 },\n"
+ "]\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ string spath = "[ -1 ]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"insert\",\n"
+ " \"key\": \"test\",\n"
+ " \"value\": 5678\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "[\n"
+ "{ \"test\": 5678 },\n"
+ "{ \"test\": 5678 },\n"
+ "{ \"test\": 1234 }\n"
+ "]\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+TEST(AdaptorTest, modifyListDelete) {
+ string config = "[[\n"
+ "{\n"
+ " \"foo\": \"bar\"\n"
+ "},{\n"
+ "},[\n"
+ "0, 1, 2, 3\n"
+ "]]]\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ string spath = "[ 0 ]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ // Put the positional first as it applies after previous actions...
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"delete\",\n"
+ " \"key\": 2\n"
+ "},{\n"
+ " \"action\": \"delete\",\n"
+ " \"key\": { \"key\": \"foo\", \"value\": \"bar\" }\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "[[{}]]\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+TEST(AdaptorTest, modifyListAllDelete) {
+ string config = "[[\n"
+ "{\n"
+ " \"foo\": \"bar\"\n"
+ "},{\n"
+ "},[\n"
+ "0, 1, 2, 3\n"
+ "]]]\n";
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ // The main change from the previous unit test is key 0 -> -1 so
+ // modify() applies the delete to all elements vs only the first one.
+ string spath = "[ -1 ]";
+ ConstElementPtr path;
+ ASSERT_NO_THROW_LOG(path = Element::fromJSON(spath));
+ // Put the positional first as it applies after previous actions...
+ string sactions = "[\n"
+ "{\n"
+ " \"action\": \"delete\",\n"
+ " \"key\": 2\n"
+ "},{\n"
+ " \"action\": \"delete\",\n"
+ " \"key\": { \"key\": \"foo\", \"value\": \"bar\" }\n"
+ "}]\n";
+ ConstElementPtr actions;
+ ASSERT_NO_THROW_LOG(actions = Element::fromJSON(sactions));
+ string result = "[[{}]]\n";
+ ConstElementPtr expected;
+ ASSERT_NO_THROW_LOG(expected = Element::fromJSON(result));
+ ASSERT_NO_THROW_LOG(Adaptor::modify(path, actions, json));
+ EXPECT_TRUE(expected->equals(*json));
+}
+
+}; // end of anonymous namespace
diff --git a/src/lib/yang/tests/config_unittests.cc b/src/lib/yang/tests/config_unittests.cc
new file mode 100644
index 0000000..7a655a7
--- /dev/null
+++ b/src/lib/yang/tests/config_unittests.cc
@@ -0,0 +1,417 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/io_utils.h>
+#include <testutils/user_context_utils.h>
+#include <yang/translator_config.h>
+#include <yang/yang_models.h>
+#include <yang/tests/json_configs.h>
+#include <yang/tests/yang_configs.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <boost/algorithm/string.hpp>
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Return the difference between two strings
+///
+/// Use the gtest >= 1.8.0 tool which builds the difference between
+/// two vectors of lines.
+///
+/// @param left left string
+/// @param right right string
+/// @return the unified diff between left and right
+#ifdef HAVE_CREATE_UNIFIED_DIFF
+std::string generateDiff(std::string left, std::string right) {
+ std::vector<std::string> left_lines;
+ boost::split(left_lines, left, boost::is_any_of("\n"));
+ std::vector<std::string> right_lines;
+ boost::split(right_lines, right, boost::is_any_of("\n"));
+ using namespace testing::internal;
+ return (edit_distance::CreateUnifiedDiff(left_lines, right_lines));
+}
+#else
+std::string generateDiff(std::string, std::string) {
+ return ("");
+}
+#endif
+
+/// @brief Test Fixture class for Yang <-> JSON configs.
+class ConfigTest : public ::testing::Test {
+public:
+ 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();
+ }
+
+ void TearDown() override {
+ cleanModelData();
+ translator_.reset();
+ session_.reset();
+ connection_.reset();
+ SysrepoSetup::cleanSharedMemory();
+ }
+
+ void cleanModelData() {
+ std::string toplevel_node("config");
+ if (model_ == IETF_DHCPV6_SERVER) {
+ toplevel_node = "server";
+ }
+ translator_->delItem("/" + model_ + ":" + toplevel_node);
+ }
+
+ /// @brief Reset session.
+ void resetSession() {
+ SetUp();
+ }
+
+ /// @brief Loads YANG configuration from specified tree.
+ ///
+ /// @param tree The Yang tree to load.
+ void load(const YRTree& tree) {
+ YangRepr repr(model_);
+ repr.set(tree, session_);
+ }
+
+ /// @brief Loads JSON configuration from specified Element tree.
+ ///
+ /// @param json The JSON tree to load.
+ void load(ConstElementPtr json) {
+ TranslatorConfig tc(session_, model_);
+ tc.setConfig(json);
+ }
+
+ /// @brief Load a cofiguration from a string containing JSON.
+ ///
+ /// @param config The JSON tree to load in textual format.
+ void load(const string& config) {
+ ElementPtr json;
+ ASSERT_NO_THROW_LOG(json = Element::fromJSON(config));
+ load(json);
+ }
+
+ /// @brief Load a configuration from JSON file.
+ ///
+ /// @param filename The name of the JSON file to load,
+ ConstElementPtr loadFile(const string& filename) {
+ string decommented = isc::test::decommentJSONfile(filename);
+ ConstElementPtr json = Element::fromJSONFile(decommented, true);
+ ::remove(decommented.c_str());
+ load(json);
+ return (json);
+ }
+
+ /// @brief Returns YANG tree configuration.
+ YRTree getYang() {
+ YangRepr repr(model_);
+ return (repr.get(session_));
+ }
+
+ /// @brief Returns configuration in JSON (translated by TranslatorConfig)
+ ConstElementPtr getJSON() {
+ TranslatorConfig tc(session_, model_);
+ return (tc.getConfig());
+ }
+
+ /// @brief Retrieves configuration as text (in pretty JSON format).
+ string getText() {
+ return (isc::data::prettyPrint(getJSON()));
+ }
+
+ /// @brief Verify Yang.
+ ///
+ /// @param expected The expected Yang tree.
+ bool verify(const YRTree& expected) {
+ YangRepr repr(model_);
+ return (repr.verify(expected, session_, cerr));
+ }
+
+ /// @brief Verify JSON.
+ ///
+ /// @param expected The expected JSON tree.
+ bool verify(ConstElementPtr expected) {
+ TranslatorConfig tc(session_, model_);
+ ConstElementPtr content = tc.getConfig();
+ if (isEquivalent(expected, content)) {
+ return (true);
+ }
+ string wanted = prettyPrint(expected);
+ string got = prettyPrint(content);
+ cerr << "Expected:\n" << wanted << "\n"
+ << "Actual:\n" << got
+#ifdef HAVE_CREATE_UNIFIED_DIFF
+ << "\nDiff:\n" << generateDiff(wanted, got)
+#endif
+ << "\n";
+ return (false);
+ }
+
+ /// @brief Verify JSON.
+ ///
+ /// @param expected The expected JSON tree in textual format.
+ bool verify(const string& config) {
+ ConstElementPtr expected;
+ expected = Element::fromJSON(config);
+ 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_;
+
+ std::unique_ptr<TranslatorBasic> translator_;
+};
+
+struct ConfigTestKeaV4 : ConfigTest {
+ ConfigTestKeaV4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+struct ConfigTestKeaV6 : ConfigTest {
+ ConfigTestKeaV6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+struct ConfigTestIetfV6 : ConfigTest {
+ ConfigTestIetfV6() {
+ model_ = IETF_DHCPV6_SERVER;
+ }
+};
+
+// Check empty config with ietf-dhcpv6-server model.
+TEST_F(ConfigTestIetfV6, emptyIetf6) {
+ YRTree tree;
+ ASSERT_NO_THROW_LOG(load(tree));
+ EXPECT_TRUE(verify(tree));
+
+ ConstElementPtr json = Element::fromJSON(emptyJson6);
+ EXPECT_TRUE(verify(json));
+ ASSERT_NO_THROW_LOG(load(json));
+ EXPECT_TRUE(verify(emptyJson6));
+ EXPECT_TRUE(verify(tree));
+}
+
+// Check empty config with kea-dhcp4-server:config model.
+TEST_F(ConfigTestKeaV4, emptyKeaDhcp4) {
+ YRTree tree;
+ ASSERT_NO_THROW_LOG(load(tree));
+ EXPECT_TRUE(verify(emptyTreeKeaDhcp4));
+
+ ConstElementPtr json = Element::fromJSON(emptyJson4);
+ EXPECT_TRUE(verify(json));
+ ASSERT_NO_THROW_LOG(load(json));
+ EXPECT_TRUE(verify(emptyJson4));
+ EXPECT_TRUE(verify(emptyTreeKeaDhcp4));
+}
+
+// Check empty config with kea-dhcp6-server:config model.
+TEST_F(ConfigTestKeaV6, emptyKeaDhcp6) {
+ YRTree tree;
+ ASSERT_NO_THROW_LOG(load(tree));
+ EXPECT_TRUE(verify(emptyTreeKeaDhcp6));
+
+ ConstElementPtr json = Element::fromJSON(emptyJson6);
+ EXPECT_TRUE(verify(json));
+ ASSERT_NO_THROW_LOG(load(json));
+ EXPECT_TRUE(verify(emptyJson6));
+ EXPECT_TRUE(verify(emptyTreeKeaDhcp6));
+}
+
+// Check subnet with two pools with ietf-dhcpv6-server model.
+// Validation will fail because the current model has a vendor-info
+// container with a mandatory ent-num leaf and no presence flag,
+// and of course the candidate YANG tree has nothing for this.
+TEST_F(ConfigTestIetfV6, subnetTwoPoolsIetf6) {
+ ASSERT_NO_THROW_LOG(load(subnetTwoPoolsTreeIetf6));
+ EXPECT_TRUE(verify(subnetTwoPoolsJson6));
+
+ resetSession();
+
+ ASSERT_NO_THROW_LOG(load(subnetTwoPoolsJson6));
+ EXPECT_TRUE(verify(subnetTwoPoolsTreeIetf6));
+
+ EXPECT_FALSE(validate());
+}
+
+// Check subnet with a pool and option data lists with
+// kea-dhcp4-server:config model.
+TEST_F(ConfigTestKeaV4, subnetOptionsKeaDhcp4) {
+ ASSERT_NO_THROW_LOG(load(subnetOptionsTreeKeaDhcp4));
+ EXPECT_TRUE(verify(subnetOptionsJson4));
+
+ resetSession();
+
+ ASSERT_NO_THROW_LOG(load(subnetOptionsJson4));
+ EXPECT_TRUE(verify(subnetOptionsTreeKeaDhcp4));
+
+ EXPECT_TRUE(validate());
+}
+
+// Check subnet with a pool and option data lists with
+// kea-dhcp6-server:config model.
+TEST_F(ConfigTestKeaV6, subnetOptionsKeaDhcp6) {
+ ASSERT_NO_THROW_LOG(load(subnetOptionsTreeKeaDhcp6));
+ EXPECT_TRUE(verify(subnetOptionsJson6));
+
+ resetSession();
+
+ ASSERT_NO_THROW_LOG(load(subnetOptionsJson6));
+ EXPECT_TRUE(verify(subnetOptionsTreeKeaDhcp6));
+
+ EXPECT_TRUE(validate());
+}
+
+// Check with timers.
+TEST_F(ConfigTestIetfV6, subnetTimersIetf6) {
+ ASSERT_NO_THROW_LOG(load(subnetTimersIetf6));
+ EXPECT_TRUE(verify(subnetTimersJson6));
+
+ resetSession();
+
+ ASSERT_NO_THROW_LOG(load(subnetTimersJson6));
+ EXPECT_TRUE(verify(subnetTimersIetf6));
+}
+
+// Check a ietf-dhcpv6-server configuration which validates.
+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.
+TEST_F(ConfigTestKeaV4, examples4) {
+ vector<string> examples = {
+ "advanced.json",
+ "all-keys-netconf.json",
+ "all-options.json",
+ "backends.json",
+ "classify.json",
+ "classify2.json",
+ "comments.json",
+ "config-backend.json",
+ "dhcpv4-over-dhcpv6.json",
+ "global-reservations.json",
+ "ha-load-balancing-primary.json",
+ "hooks.json",
+ "hooks-radius.json",
+ "leases-expiration.json",
+ "multiple-options.json",
+ "mysql-reservations.json",
+ "pgsql-reservations.json",
+ "reservations.json",
+ "several-subnets.json",
+ "shared-network.json",
+ "single-subnet.json",
+ "vendor-specific.json",
+ "vivso.json",
+ "with-ddns.json",
+ };
+ for (string file : examples) {
+ resetSession();
+ string path = string(CFG_EXAMPLES) + "/kea4/" + file;
+ cout << "Testing file " << path << endl;
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = loadFile(path));
+ json = isc::test::moveComments(json);
+ EXPECT_TRUE(verify(json));
+ EXPECT_TRUE(validate());
+ }
+}
+
+// Check Kea6 example files.
+TEST_F(ConfigTestKeaV6, examples6) {
+ vector<string> examples = {
+ "advanced.json",
+ "all-keys-netconf.json",
+ "all-options.json",
+ "backends.json",
+ "classify.json",
+ "classify2.json",
+ "comments.json",
+ "config-backend.json",
+ "dhcpv4-over-dhcpv6.json",
+ "duid.json",
+ "global-reservations.json",
+ "ha-hot-standby.json",
+ "hooks.json",
+ "iPXE.json",
+ "leases-expiration.json",
+ "multiple-options.json",
+ "mysql-reservations.json",
+ "pgsql-reservations.json",
+ "reservations.json",
+ "several-subnets.json",
+ "shared-network.json",
+ "simple.json",
+ "softwire46.json",
+ "stateless.json",
+ "tee-times.json",
+ "with-ddns.json",
+ };
+ for (string file : examples) {
+ resetSession();
+ string path = string(CFG_EXAMPLES) + "/kea6/" + file;
+ cout << "Testing file " << path << endl;
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = loadFile(path));
+ json = isc::test::moveComments(json);
+ EXPECT_TRUE(verify(json));
+ EXPECT_TRUE(validate());
+ }
+}
+
+// Check the example in the design document.
+TEST_F(ConfigTestIetfV6, designExample) {
+ ASSERT_NO_THROW_LOG(load(designExampleTree));
+ EXPECT_TRUE(verify(designExampleJson));
+
+ resetSession();
+
+ ASSERT_NO_THROW_LOG(load(designExampleJson));
+ EXPECT_TRUE(verify(designExampleTree));
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/json_configs.h b/src/lib/yang/tests/json_configs.h
new file mode 100644
index 0000000..1f7e4a4
--- /dev/null
+++ b/src/lib/yang/tests/json_configs.h
@@ -0,0 +1,174 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_JSON_CONFIGS_H
+#define ISC_JSON_CONFIGS_H
+
+#include <string>
+
+namespace isc {
+namespace yang {
+namespace test {
+
+/// @brief Empty DHCPv4 config.
+const std::string emptyJson4 =
+ "{\n"
+ " \"Dhcp4\": {\n"
+ " }\n"
+ "}";
+
+/// @brief A DHCPv4 config with one subnet with two pools.
+const std::string subnetTwoPoolsJson4 =
+ "{\n"
+ " \"Dhcp4\": {\n"
+ " \"subnet4\": [\n"
+ " {\n"
+ " \"id\": 111,\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"10.0.1.0/24\"\n"
+ " },\n"
+ " {\n"
+ " \"pool\": \"10.0.2.0/24\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"10.0.0.0/8\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
+
+/// @brief A DHCPv6 config with one subnet with two pools and timers.
+const std::string subnetTimersJson6 =
+ "{\n"
+ " \"Dhcp6\": {\n"
+ " \"subnet6\": [\n"
+ " {\n"
+ " \"id\": 111,\n"
+ " \"renew-timer\": 1000,\n"
+ " \"rebind-timer\": 2000,\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8::1:0/112\"\n"
+ " },\n"
+ " {\n"
+ " \"pool\": \"2001:db8::2:0/112\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"2001:db8::/48\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
+
+/// @brief A DHCPv4 subnet with one pool and option data lists.
+const std::string subnetOptionsJson4 =
+ "{\n"
+ " \"Dhcp4\": {\n"
+ " \"subnet4\": [\n"
+ " {\n"
+ " \"id\": 111,\n"
+ " \"option-data\": [\n"
+ " {\n"
+ " \"code\": 100,\n"
+ " \"space\": \"dns\",\n"
+ " \"csv-format\": false,\n"
+ " \"data\": \"12121212\",\n"
+ " \"always-send\": false\n"
+ " }\n"
+ " ],\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"10.0.1.0/24\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"10.0.0.0/8\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
+
+/// @brief Empty DHCPv6 config.
+const std::string emptyJson6 =
+ "{\n"
+ " \"Dhcp6\": {\n"
+ " }\n"
+ "}";
+
+/// @brief A DHCPv6 config with one subnet with one pool and option data lists.
+const std::string subnetOptionsJson6 =
+ "{\n"
+ " \"Dhcp6\": {\n"
+ " \"subnet6\": [\n"
+ " {\n"
+ " \"id\": 111,\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"option-data\": [\n"
+ " {\n"
+ " \"code\": 100,\n"
+ " \"space\": \"dns\",\n"
+ " \"csv-format\": false,\n"
+ " \"data\": \"12121212\",\n"
+ " \"always-send\": false\n"
+ " }\n"
+ " ],\n"
+ " \"pool\": \"2001:db8::1:0/112\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"2001:db8::/48\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
+
+/// @brief A DHCPv6 config with one subnet with two pools.
+const std::string subnetTwoPoolsJson6 =
+ "{\n"
+ " \"Dhcp6\": {\n"
+ " \"subnet6\": [\n"
+ " {\n"
+ " \"id\": 111,\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8::1:0/112\"\n"
+ " },\n"
+ " {\n"
+ " \"pool\": \"2001:db8::2:0/112\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"2001:db8::/48\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
+
+/// @brief Example from the design document.
+const std::string designExampleJson =
+ "{\n"
+ " \"Dhcp6\": {\n"
+ " \"subnet6\": [\n"
+ " {\n"
+ " \"id\": 1,\n"
+ " \"subnet\": \"2001:db8:20:b00::/56\",\n"
+ " \"user-context\": { \"description\": \"example\" },\n"
+ " \"pd-pools\": [\n"
+ " {\n"
+ " \"prefix\": \"2001:db8:20:b00::\",\n"
+ " \"prefix-len\": 57\n"
+// " \"delegated-len\": 57\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
+
+} // namespace test
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_JSON_CONFIGS_H
diff --git a/src/lib/yang/tests/run_unittests.cc b/src/lib/yang/tests/run_unittests.cc
new file mode 100644
index 0000000..c0847ca
--- /dev/null
+++ b/src/lib/yang/tests/run_unittests.cc
@@ -0,0 +1,20 @@
+// Copyright (C) 2018 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <gtest/gtest.h>
+#include <util/unittests/run_all.h>
+#include <log/logger_support.h>
+
+int
+main(int argc, char* argv[]) {
+ ::testing::InitGoogleTest(&argc, argv);
+
+ isc::log::initLogger();
+
+ return (isc::util::unittests::run_all());
+}
diff --git a/src/lib/yang/tests/sysrepo_setup.h b/src/lib/yang/tests/sysrepo_setup.h
new file mode 100644
index 0000000..27cf213
--- /dev/null
+++ b/src/lib/yang/tests/sysrepo_setup.h
@@ -0,0 +1,99 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef SYSREPO_SETUP_H
+#define SYSREPO_SETUP_H
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/translator.h>
+#include <yang/yang_models.h>
+
+#include <gtest/gtest.h>
+
+namespace isc {
+namespace yang {
+namespace test {
+
+/// @brief Wrapper for sysrepo setup actions
+struct SysrepoSetup {
+ /// @brief Cleans shared memory.
+ ///
+ /// If a unit test crashes (mostly when migrating to a new version), it
+ /// leaves behind corrupted shared memory. Let's make sure we can run all
+ /// the following unit tests free of any side effect from said crash. This
+ /// is the equivalent of running "make shm_clean" in sysrepo:
+ /// https://github.com/sysrepo/sysrepo/blob/v1.4.140/CMakeLists.txt#L329-L334
+ static void cleanSharedMemory() {
+ call_system("rm -rf /dev/shm/sr_*");
+ call_system("rm -rf /dev/shm/srsub_*");
+ }
+
+private:
+ /// @brief Wrapper over a system() call that also checks the return value.
+ ///
+ /// @brief command the command to be run
+ static void call_system(char const* command) {
+ int return_value(system(command));
+ if (return_value != 0) {
+ std::cerr << "\"" << command << "\" exited with " << return_value
+ << ". Unit tests may be influenced by previous abnormally "
+ "terminated unit tests or sysrepo uses."
+ << std::endl;
+ }
+ }
+};
+
+/// @brief Test Fixture template for translator tests.
+///
+/// @tparam Name The name of the translator to test.
+/// @tparam Type The type of the translator to test.
+template<char const* Name, typename translator_t>
+class GenericTranslatorTest : public ::testing::Test {
+public:
+ virtual ~GenericTranslatorTest() = default;
+
+ 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_));
+ cleanModelData();
+ }
+
+ void TearDown() override {
+ cleanModelData();
+ t_obj_.reset();
+ sess_.reset();
+ conn_.reset();
+ SysrepoSetup::cleanSharedMemory();
+ }
+
+ void cleanModelData() {
+ std::string toplevel_node("config");
+ if (model_ == IETF_DHCPV6_SERVER) {
+ toplevel_node = "server";
+ }
+ t_obj_->delItem("/" + model_ + ":" + toplevel_node);
+ }
+
+ /// @brief Sysrepo connection.
+ sysrepo::S_Connection conn_;
+
+ /// @brief Sysrepo session.
+ sysrepo::S_Session sess_;
+
+ /// @brief Shared pointer to the transaction object.
+ boost::shared_ptr<translator_t> t_obj_;
+ std::string model_;
+};
+
+} // namespace test
+} // namespace yang
+} // namespace isc
+
+#endif // SYSREPO_SETUP_H
diff --git a/src/lib/yang/tests/translator_class_unittests.cc b/src/lib/yang/tests/translator_class_unittests.cc
new file mode 100644
index 0000000..3dcb518
--- /dev/null
+++ b/src/lib/yang/tests/translator_class_unittests.cc
@@ -0,0 +1,125 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_class.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const client_classes[] = "client classes";
+
+/// @brief Test fixture class for @ref TranslatorClasses.
+class TranslatorClassesTestv4 :
+ public GenericTranslatorTest<client_classes, TranslatorClasses> {
+public:
+
+ /// Constructor.
+ TranslatorClassesTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+class TranslatorClassesTestv6 :
+ public GenericTranslatorTest<client_classes, TranslatorClasses> {
+public:
+
+ /// Constructor.
+ TranslatorClassesTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+
+// This test verifies that an empty client class list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorClassesTestv4, getEmpty) {
+ // Get the client class list and check if it is empty.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr classes;
+ EXPECT_NO_THROW(classes = t_obj_->getClasses(xpath));
+ EXPECT_FALSE(classes);
+}
+
+// This test verifies that one client class can be properly translated
+// from YANG to JSON.
+TEST_F(TranslatorClassesTestv6, get) {
+ // Create the client class.
+ 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));
+
+ // Get the client class.
+ ConstElementPtr cclass;
+ EXPECT_NO_THROW(cclass = t_obj_->getClass(xclass));
+ ASSERT_TRUE(cclass);
+ ElementPtr expected = Element::createMap();
+ expected->set("name", Element::create(string("foo")));
+ expected->set("test", Element::create(string("not member('ALL')")));
+ EXPECT_TRUE(expected->equals(*cclass));
+
+ // Get the client class list and check if the client class is in it.
+ ConstElementPtr classes;
+ EXPECT_NO_THROW(classes = t_obj_->getClasses(xpath));
+ ASSERT_TRUE(classes);
+ ASSERT_EQ(Element::list, classes->getType());
+ ASSERT_EQ(1, classes->size());
+ EXPECT_TRUE(cclass->equals(*classes->get(0)));
+}
+
+// This test verifies that an empty client class list can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorClassesTestv4, setEmpty) {
+ // Set empty list.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr classes = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setClasses(xpath, classes));
+
+ // Get it back.
+ classes.reset();
+ EXPECT_NO_THROW(classes = t_obj_->getClasses(xpath));
+ EXPECT_FALSE(classes);
+}
+
+// This test verifies that one client class can be properly translated
+// from JSON to YANG.
+TEST_F(TranslatorClassesTestv6, set) {
+ // Set one client class.
+ const string& xpath = "/kea-dhcp6-server:config";
+ ElementPtr classes = Element::createList();
+ ElementPtr cclass = Element::createMap();
+ cclass->set("name", Element::create(string("foo")));
+ cclass->set("test", Element::create(string("''==''")));
+ cclass->set("only-if-required", Element::create(false));
+ classes->add(cclass);
+ EXPECT_NO_THROW(t_obj_->setClasses(xpath, classes));
+
+ // Get it back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW(got = t_obj_->getClasses(xpath));
+ ASSERT_TRUE(got);
+ 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
new file mode 100644
index 0000000..3d9d4fe
--- /dev/null
+++ b/src/lib/yang/tests/translator_control_socket_unittests.cc
@@ -0,0 +1,176 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_control_socket.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const control_socket[] = "control socket";
+
+/// @brief Test fixture class for @ref TranslatorControlSocket.
+class TranslatorControlSocketTestv4 :
+ public GenericTranslatorTest<control_socket, TranslatorControlSocket> {
+public:
+
+ /// Constructor.
+ TranslatorControlSocketTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+
+ virtual ~TranslatorControlSocketTestv4() = default;
+};
+class TranslatorControlSocketTestv6 :
+ public GenericTranslatorTest<control_socket, TranslatorControlSocket> {
+public:
+
+ /// Constructor.
+ TranslatorControlSocketTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+
+ virtual ~TranslatorControlSocketTestv6() = default;
+};
+class TranslatorControlSocketTestCtrlAgent :
+ public GenericTranslatorTest<control_socket, TranslatorControlSocket> {
+public:
+
+ /// Constructor.
+ TranslatorControlSocketTestCtrlAgent() {
+ model_ = KEA_CTRL_AGENT;
+ }
+
+ virtual ~TranslatorControlSocketTestCtrlAgent() = default;
+};
+
+// This test verifies that an empty control socket can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorControlSocketTestv4, getEmpty) {
+ // Get empty.
+ const string& xpath = "/kea-dhcp4-server:config/control-socket";
+ ConstElementPtr sock;
+ EXPECT_NO_THROW(sock = t_obj_->getControlSocket(xpath));
+ EXPECT_FALSE(sock);
+}
+
+// This test verifies that a not empty control socket can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorControlSocketTestv6, get) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp6-server:config/control-socket";
+ 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));
+
+ // Get it.
+ ConstElementPtr sock;
+ EXPECT_NO_THROW(sock = t_obj_->getControlSocket(xpath));
+ ASSERT_TRUE(sock);
+ ASSERT_EQ(Element::map, sock->getType());
+ EXPECT_EQ(3, sock->size());
+ ConstElementPtr type = sock->get("socket-type");
+ ASSERT_TRUE(type);
+ ASSERT_EQ(Element::string, type->getType());
+ EXPECT_EQ("unix", type->stringValue());
+ ConstElementPtr name = sock->get("socket-name");
+ ASSERT_TRUE(name);
+ ASSERT_EQ(Element::string, name->getType());
+ EXPECT_EQ("/tmp/kea.sock", name->stringValue());
+ ConstElementPtr context = sock->get("user-context");
+ ASSERT_TRUE(context);
+ EXPECT_EQ("{ \"foo\": 1 }", context->str());
+}
+
+// This test verifies that a not empty control socket can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorControlSocketTestCtrlAgent, set) {
+ // Set a value.
+ const string& xpath =
+ "/kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/control-socket";
+ ElementPtr sock = Element::createMap();
+ sock->set("socket-name", Element::create(string("/tmp/kea.sock")));
+ sock->set("socket-type", Element::create(string("unix")));
+ sock->set("comment", Element::create(string("a comment")));
+ try {
+ t_obj_->setControlSocket(xpath, sock);
+ } catch (const std::exception& ex) {
+ cerr << "setControlSocket fail with " << ex.what() << endl;
+ }
+ ASSERT_NO_THROW_LOG(t_obj_->setControlSocket(xpath, sock));
+
+ // Get it back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW(got = t_obj_->getControlSocket(xpath));
+ ASSERT_TRUE(got);
+ ASSERT_EQ(Element::map, got->getType());
+ EXPECT_EQ(3, got->size());
+ ConstElementPtr name = got->get("socket-name");
+ ASSERT_TRUE(name);
+ ASSERT_EQ(Element::string, name->getType());
+ EXPECT_EQ("/tmp/kea.sock", name->stringValue());
+ ConstElementPtr type = got->get("socket-type");
+ ASSERT_TRUE(type);
+ ASSERT_EQ(Element::string, type->getType());
+ EXPECT_EQ("unix", type->stringValue());
+ 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
+// translated from JSON to YANG.
+TEST_F(TranslatorControlSocketTestv4, setEmpty) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp4-server:config/control-socket";
+ 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();
+
+ // Get it back.
+ ConstElementPtr sock;
+ EXPECT_NO_THROW(sock = t_obj_->getControlSocket(xpath));
+ ASSERT_TRUE(sock);
+ EXPECT_EQ(sock->str(),
+ R"({ "socket-name": "/tmp/kea.sock", "socket-type": "unix", "user-context": { "foo": 1 } })");
+
+ // Reset to empty.
+ EXPECT_NO_THROW(t_obj_->setControlSocket(xpath, ConstElementPtr()));
+
+ // Get it back.
+ EXPECT_NO_THROW(sock = t_obj_->getControlSocket(xpath));
+ EXPECT_FALSE(sock);
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/translator_database_unittests.cc b/src/lib/yang/tests/translator_database_unittests.cc
new file mode 100644
index 0000000..6c4eb29
--- /dev/null
+++ b/src/lib/yang/tests/translator_database_unittests.cc
@@ -0,0 +1,327 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_database.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const database_access[] = "database access";
+
+/// @brief Test fixture class for @ref TranslatorDatabase.
+class TranslatorDatabaseTestv4 :
+ public GenericTranslatorTest<database_access, TranslatorDatabase> {
+public:
+ TranslatorDatabaseTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+
+ virtual ~TranslatorDatabaseTestv4() = default;
+};
+
+class TranslatorDatabaseTestv6 :
+ public GenericTranslatorTest<database_access, TranslatorDatabase> {
+public:
+ TranslatorDatabaseTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+
+ virtual ~TranslatorDatabaseTestv6() = default;
+};
+
+// This test verifies that an empty database can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorDatabaseTestv4, getEmpty) {
+ // Get empty.
+ const string& xpath = "/kea-dhcp4-server:config/lease-database";
+ ConstElementPtr database;
+ EXPECT_NO_THROW(database = t_obj_->getDatabase(xpath));
+ EXPECT_FALSE(database);
+}
+
+// This test verifies that a database can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorDatabaseTestv4, get) {
+ // Set a value.
+ 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));
+ uint32_t li = 3600;
+ S_Val s_interval(new Val(li));
+ EXPECT_NO_THROW(sess_->set_item(xinterval.c_str(), s_interval));
+
+ // Get empty.
+ ConstElementPtr database;
+ EXPECT_NO_THROW(database = t_obj_->getDatabase(xpath));
+ ASSERT_TRUE(database);
+ EXPECT_EQ(2, database->size());
+ ConstElementPtr type = database->get("type");
+ ASSERT_TRUE(type);
+ ASSERT_EQ(Element::string, type->getType());
+ EXPECT_EQ("memfile", type->stringValue());
+ ConstElementPtr interval = database->get("lfc-interval");
+ ASSERT_TRUE(interval);
+ ASSERT_EQ(Element::integer, interval->getType());
+ EXPECT_EQ(li, interval->intValue());
+}
+
+// This test verifies that a database can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorDatabaseTestv4, set) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp4-server:config/lease-database";
+ ElementPtr database = Element::createMap();
+ database->set("type", Element::create(string("memfile")));
+ database->set("lfc-interval", Element::create(3600));
+ ASSERT_NO_THROW_LOG(t_obj_->setDatabase(xpath, database));
+
+ // Get it back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW(got = t_obj_->getDatabase(xpath));
+ ASSERT_TRUE(got);
+ ASSERT_EQ(Element::map, got->getType());
+ EXPECT_EQ(2, got->size());
+ ConstElementPtr type = got->get("type");
+ ASSERT_TRUE(type);
+ ASSERT_EQ(Element::string, type->getType());
+ EXPECT_EQ("memfile", type->stringValue());
+ ConstElementPtr interval = database->get("lfc-interval");
+ ASSERT_TRUE(interval);
+ ASSERT_EQ(Element::integer, interval->getType());
+ EXPECT_EQ(3600, interval->intValue());
+}
+
+// This test verifies that an empty database can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorDatabaseTestv4, setEmpty) {
+ // Set a value.
+ 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));
+ 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();
+
+ // Reset to empty.
+ ASSERT_NO_THROW_LOG(t_obj_->setDatabase(xpath, ConstElementPtr()));
+
+ // Get it back.
+ ConstElementPtr database;
+ EXPECT_NO_THROW(database = t_obj_->getDatabase(xpath));
+ EXPECT_FALSE(database);
+}
+
+/// @brief Translator name.
+extern char const database_accesses[] = "database accesses";
+
+/// @brief Test fixture class for @ref TranslatorDatabases.
+class TranslatorDatabasesTestv4 :
+ public GenericTranslatorTest<database_accesses, TranslatorDatabases> {
+public:
+
+ /// Constructor.
+ TranslatorDatabasesTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+
+class TranslatorDatabasesTestv6 :
+ public GenericTranslatorTest<database_accesses, TranslatorDatabases> {
+public:
+
+ /// Constructor.
+ TranslatorDatabasesTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+
+// This test verifies that an empty database list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorDatabasesTestv6, getEmpty) {
+ // Get empty.
+ const string& xpath = "/kea-dhcp6-server:config/hosts-database";
+ ConstElementPtr databases;
+ EXPECT_NO_THROW(databases = t_obj_->getDatabases(xpath));
+ EXPECT_FALSE(databases);
+}
+
+// This test verifies that a database list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorDatabasesTestv4, get) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp4-server:config/hosts-database";
+ const string& xdatabase = xpath + "[database-type='mysql']";
+ const string& xname = xdatabase + "/name";
+ const string& xuser = xdatabase + "/user";
+ 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));
+ uint16_t mport = 3306;
+ S_Val s_port(new Val(mport));
+ EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port));
+
+ // Get empty.
+ ConstElementPtr databases;
+ EXPECT_NO_THROW(databases = t_obj_->getDatabases(xpath));
+ ASSERT_TRUE(databases);
+ ASSERT_EQ(1, databases->size());
+ ConstElementPtr database = databases->get(0);
+ ASSERT_TRUE(database);
+ EXPECT_EQ(6, database->size());
+ ConstElementPtr type = database->get("type");
+ ASSERT_TRUE(type);
+ ASSERT_EQ(Element::string, type->getType());
+ EXPECT_EQ("mysql", type->stringValue());
+ ConstElementPtr name = database->get("name");
+ ASSERT_TRUE(name);
+ ASSERT_EQ(Element::string, name->getType());
+ EXPECT_EQ("kea", name->stringValue());
+ ConstElementPtr user = database->get("user");
+ ASSERT_TRUE(user);
+ ASSERT_EQ(Element::string, user->getType());
+ EXPECT_EQ("kea", user->stringValue());
+ ConstElementPtr password = database->get("password");
+ ASSERT_TRUE(password);
+ ASSERT_EQ(Element::string, password->getType());
+ EXPECT_EQ("kea", password->stringValue());
+ ConstElementPtr host = database->get("host");
+ ASSERT_TRUE(host);
+ ASSERT_EQ(Element::string, host->getType());
+ EXPECT_EQ("localhost", host->stringValue());
+ ConstElementPtr port = database->get("port");
+ ASSERT_TRUE(port);
+ ASSERT_EQ(Element::integer, port->getType());
+ EXPECT_EQ(mport, port->intValue());
+}
+
+// This test verifies that a database list can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorDatabasesTestv6, set) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp6-server:config/hosts-database";
+ ElementPtr database = Element::createMap();
+ database->set("type", Element::create(string("memfile")));
+ database->set("lfc-interval", Element::create(3600));
+ ElementPtr databases = Element::createList();
+ databases->add(database);
+ ASSERT_NO_THROW_LOG(t_obj_->setDatabases(xpath, databases));
+
+ // Get it back.
+ ConstElementPtr gots;
+ EXPECT_NO_THROW(gots = t_obj_->getDatabases(xpath));
+ ASSERT_TRUE(gots);
+ ASSERT_EQ(Element::list, gots->getType());
+ ASSERT_EQ(1, gots->size());
+ ConstElementPtr got = gots->get(0);
+ ASSERT_TRUE(got);
+ ASSERT_EQ(Element::map, got->getType());
+ EXPECT_EQ(2, got->size());
+ ConstElementPtr type = got->get("type");
+ ASSERT_TRUE(type);
+ ASSERT_EQ(Element::string, type->getType());
+ EXPECT_EQ("memfile", type->stringValue());
+ ConstElementPtr interval = database->get("lfc-interval");
+ 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
+// translated from JSON to YANG.
+TEST_F(TranslatorDatabasesTestv4, setEmpty) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp4-server:config/hosts-database";
+ const string& xdatabase = xpath + "[database-type='mysql']";
+ const string& xname = xdatabase + "/name";
+ const string& xuser = xdatabase + "/user";
+ 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));
+ 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();
+
+ // Reset to empty.
+ EXPECT_NO_THROW(t_obj_->setDatabase(xdatabase, ConstElementPtr()));
+
+ // Get empty.
+ ConstElementPtr databases;
+ EXPECT_NO_THROW(databases = t_obj_->getDatabases(xpath));
+ EXPECT_FALSE(databases);
+}
+
+// This test verifies that an empty database list can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorDatabasesTestv4, setEmpties) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp4-server:config/hosts-database";
+ const string& xdatabase = xpath + "[database-type='mysql']";
+ const string& xname = xdatabase + "/name";
+ const string& xuser = xdatabase + "/user";
+ 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));
+ 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();
+
+ // Reset to empty.
+ EXPECT_NO_THROW(t_obj_->setDatabases(xdatabase, ConstElementPtr()));
+
+ // Get empty.
+ ConstElementPtr databases;
+ EXPECT_NO_THROW(databases = t_obj_->getDatabases(xpath));
+ EXPECT_FALSE(databases);
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/translator_host_unittests.cc b/src/lib/yang/tests/translator_host_unittests.cc
new file mode 100644
index 0000000..26fd202
--- /dev/null
+++ b/src/lib/yang/tests/translator_host_unittests.cc
@@ -0,0 +1,188 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_host.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const host_reservations[] = "host reservations";
+
+/// @brief Test fixture class for @ref TranslatorHosts.
+class TranslatorHostsTestv4 :
+ public GenericTranslatorTest<host_reservations, TranslatorHosts> {
+public:
+
+ /// Constructor.
+ TranslatorHostsTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+
+class TranslatorHostsTestv6 :
+ public GenericTranslatorTest<host_reservations, TranslatorHosts> {
+public:
+
+ /// Constructor.
+ TranslatorHostsTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+
+// This test verifies that an empty host reservation list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorHostsTestv6, getEmpty) {
+ // Get the host reservation list and check if it is empty.
+ const string& xpath =
+ "/kea-dhcp6-server:config/subnet6[id='111']";
+ ConstElementPtr hosts;
+ EXPECT_NO_THROW(hosts = t_obj_->getHosts(xpath));
+ ASSERT_FALSE(hosts);
+}
+
+// This test verifies that one host reservation can be properly
+// translated from YANG to JSON.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // 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));
+
+ // Get the host.
+ ConstElementPtr host;
+ EXPECT_NO_THROW(host = t_obj_->getHost(shost.str()));
+ ASSERT_TRUE(host);
+ ElementPtr expected = Element::createMap();
+ ElementPtr addresses = Element::createList();
+ addresses->add(Element::create(string("2001:db8::1")));
+ expected->set("hw-address", Element::create(string("00:01:02:03:04:05")));
+ expected->set("ip-addresses", addresses);
+ EXPECT_TRUE(expected->equals(*host));
+
+ // Get the host reservation list and check if the host reservation
+ // is in it.
+ ConstElementPtr hosts;
+ EXPECT_NO_THROW(hosts = t_obj_->getHosts(xpath));
+ ASSERT_TRUE(hosts);
+ ASSERT_EQ(Element::list, hosts->getType());
+ ASSERT_EQ(1, hosts->size());
+ EXPECT_TRUE(host->equals(*hosts->get(0)));
+}
+
+// This test verifies that an empty host reservation list can be properly
+// translated from JSON to YANG.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Set empty list.
+ ConstElementPtr hosts = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setHosts(xpath, hosts));
+
+ // Get it back.
+ hosts.reset();
+ EXPECT_NO_THROW(hosts = t_obj_->getHosts(xpath));
+ ASSERT_FALSE(hosts);
+}
+
+// This test verifies that one host reservation can be properly
+// translated from JSON to YANG.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Set one host.
+ ElementPtr hosts = Element::createList();
+ ElementPtr host = Element::createMap();
+ host->set("flex-id", Element::create(string("00:ff")));
+ host->set("ip-address", Element::create(string("10.0.0.1")));
+ host->set("hostname", Element::create(string("foo")));
+ hosts->add(host);
+ EXPECT_NO_THROW(t_obj_->setHosts(xpath, hosts));
+
+ // Get it back.
+ hosts.reset();
+ EXPECT_NO_THROW(hosts = t_obj_->getHosts(xpath));
+ ASSERT_TRUE(hosts);
+ 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
+// translated from YANG to JSON.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // 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));
+
+ // 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));
+
+ // Get the host.
+ ConstElementPtr hosts;
+ EXPECT_NO_THROW(hosts = t_obj_->getHosts(xpath));
+ ASSERT_TRUE(hosts);
+
+ EXPECT_EQ(hosts->str(),
+ "[ { \"hw-address\": \"00:01:02:03:04:05\", "
+ "\"ip-addresses\": [ \"2001:db8::1\" ] }, "
+ "{ \"hw-address\": \"00:01:0a:0b:0c:0d\", "
+ "\"ip-addresses\": [ \"2001:db8::2\" ] } ]");
+}
+
+}; // end of anonymous namespace
diff --git a/src/lib/yang/tests/translator_logger_unittests.cc b/src/lib/yang/tests/translator_logger_unittests.cc
new file mode 100644
index 0000000..2dbfbcc
--- /dev/null
+++ b/src/lib/yang/tests/translator_logger_unittests.cc
@@ -0,0 +1,159 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_logger.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const logger_list[] = "logger list";
+
+/// @brief Test fixture class for @ref TranslatorLoggers.
+class TranslatorLoggersTestv4 :
+ public GenericTranslatorTest<logger_list, TranslatorLoggers> {
+public:
+
+ /// Constructor.
+ TranslatorLoggersTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+class TranslatorLoggersTestv6 :
+ public GenericTranslatorTest<logger_list, TranslatorLoggers> {
+public:
+
+ /// Constructor.
+ TranslatorLoggersTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+
+// This test verifies that an empty logger list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorLoggersTestv4, getEmpty) {
+ // Get empty.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr loggers;
+ EXPECT_NO_THROW(loggers = t_obj_->getLoggers(xpath));
+ ASSERT_FALSE(loggers);
+}
+
+// This test verifies that one logger can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorLoggersTestv6, get) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp6-server:config";
+ const string& xlogger = xpath + "/logger[name='foo']";
+ 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));
+ uint32_t max_ver = 10;
+ S_Val s_maxver(new Val(max_ver));
+ EXPECT_NO_THROW(sess_->set_item(xmaxver.c_str(), s_maxver));
+
+ // Get empty.
+ ConstElementPtr loggers;
+ EXPECT_NO_THROW(loggers = t_obj_->getLoggers(xpath));
+ ASSERT_TRUE(loggers);
+ ASSERT_EQ(1, loggers->size());
+ ConstElementPtr logger = loggers->get(0);
+ ASSERT_TRUE(logger);
+ EXPECT_EQ(3, logger->size());
+ ConstElementPtr name = logger->get("name");
+ ASSERT_TRUE(name);
+ ASSERT_EQ(Element::string, name->getType());
+ EXPECT_EQ("foo", name->stringValue());
+ ConstElementPtr severity = logger->get("severity");
+ ASSERT_TRUE(severity);
+ ASSERT_EQ(Element::string, severity->getType());
+ EXPECT_EQ("WARN", severity->stringValue());
+ ConstElementPtr options = logger->get("output_options");
+ ASSERT_TRUE(options);
+ ASSERT_EQ(1, options->size());
+ ConstElementPtr option = options->get(0);
+ ASSERT_TRUE(option);
+ EXPECT_EQ(2, option->size());
+ ConstElementPtr output = option->get("output");
+ ASSERT_TRUE(output);
+ ASSERT_EQ(Element::string, output->getType());
+ EXPECT_EQ("/bar", output->stringValue());
+ ConstElementPtr maxver = option->get("maxver");
+ ASSERT_TRUE(maxver);
+ ASSERT_EQ(Element::integer, maxver->getType());
+ EXPECT_EQ(max_ver, maxver->intValue());
+}
+
+// This test verifies that one logger can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorLoggersTestv4, set) {
+ // Set a value.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ElementPtr option = Element::createMap();
+ option->set("output", Element::create(string("/bar")));
+ option->set("maxver", Element::create(10));
+ ElementPtr options = Element::createList();
+ options->add(option);
+ ElementPtr logger = Element::createMap();
+ logger->set("name", Element::create(string("foo")));
+ logger->set("severity", Element::create(string("WARN")));
+ logger->set("output_options", options);
+ ElementPtr loggers = Element::createList();
+ loggers->add(logger);
+ ASSERT_NO_THROW_LOG(t_obj_->setLoggers(xpath, loggers));
+
+ // Get it back.
+ ConstElementPtr gots;
+ EXPECT_NO_THROW(gots = t_obj_->getLoggers(xpath));
+ ASSERT_TRUE(gots);
+ ASSERT_EQ(1, gots->size());
+ ConstElementPtr got = gots->get(0);
+ ASSERT_TRUE(got);
+ EXPECT_EQ(3, got->size());
+ ConstElementPtr name = got->get("name");
+ ASSERT_TRUE(name);
+ ASSERT_EQ(Element::string, name->getType());
+ EXPECT_EQ("foo", name->stringValue());
+ ConstElementPtr severity = logger->get("severity");
+ ASSERT_TRUE(severity);
+ ASSERT_EQ(Element::string, severity->getType());
+ EXPECT_EQ("WARN", severity->stringValue());
+ ConstElementPtr got_os = logger->get("output_options");
+ ASSERT_TRUE(got_os);
+ ASSERT_EQ(1, got_os->size());
+ ConstElementPtr got_o = got_os->get(0);
+ ASSERT_TRUE(got_o);
+ EXPECT_EQ(2, got_o->size());
+ ConstElementPtr output = got_o->get("output");
+ ASSERT_TRUE(output);
+ ASSERT_EQ(Element::string, output->getType());
+ EXPECT_EQ("/bar", output->stringValue());
+ ConstElementPtr maxver = got_o->get("maxver");
+ 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.
+
+} // namespace
diff --git a/src/lib/yang/tests/translator_option_data_unittests.cc b/src/lib/yang/tests/translator_option_data_unittests.cc
new file mode 100644
index 0000000..b02284c
--- /dev/null
+++ b/src/lib/yang/tests/translator_option_data_unittests.cc
@@ -0,0 +1,136 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_option_data.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const option_data_list[] = "option data list";
+
+/// @brief Test fixture class for @ref TranslatorOptionDataList.
+class TranslatorOptionDataListTestv4 :
+ public GenericTranslatorTest<option_data_list, TranslatorOptionDataList> {
+public:
+
+ /// Constructor.
+ TranslatorOptionDataListTestv4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+
+class TranslatorOptionDataListTestv6 :
+ public GenericTranslatorTest<option_data_list, TranslatorOptionDataList> {
+public:
+
+ /// Constructor.
+ TranslatorOptionDataListTestv6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+
+// This test verifies that an empty option data list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorOptionDataListTestv4, getEmpty) {
+ // Get the option data list and check if it is empty.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr options;
+ EXPECT_NO_THROW(options = t_obj_->getOptionDataList(xpath));
+ ASSERT_FALSE(options);
+}
+
+// This test verifies that one option data can be properly translated
+// from YANG to JSON.
+TEST_F(TranslatorOptionDataListTestv6, get) {
+ // Create the option code 100.
+ const string& xpath = "/kea-dhcp6-server:config";
+ const string& xoption = xpath + "/option-data[code='100'][space='dns']";
+ 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));
+
+ // Get the option data.
+ ConstElementPtr option;
+ EXPECT_NO_THROW(option = t_obj_->getOptionData(xoption));
+ ASSERT_TRUE(option);
+ EXPECT_EQ("{"
+ " \"always-send\": false,"
+ " \"code\": 100,"
+ " \"csv-format\": false,"
+ " \"data\": \"12121212\","
+ " \"space\": \"dns\""
+ " }",
+ option->str());
+
+ // Get the option data list.
+ ConstElementPtr options;
+ EXPECT_NO_THROW(options = t_obj_->getOptionDataList(xpath));
+ ASSERT_TRUE(options);
+ ASSERT_EQ(Element::list, options->getType());
+ EXPECT_EQ(1, options->size());
+ EXPECT_TRUE(option->equals(*options->get(0)));
+}
+
+// This test verifies that an empty option data list can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorOptionDataListTestv4, setEmpty) {
+ // Set empty list.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr options = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setOptionDataList(xpath, options));
+
+ // Get it back.
+ options.reset();
+ EXPECT_NO_THROW(options = t_obj_->getOptionDataList(xpath));
+ ASSERT_FALSE(options);
+}
+
+// This test verifies that one option data can be properly translated
+// from JSON to YANG.
+TEST_F(TranslatorOptionDataListTestv6, set) {
+ // Set one option data.
+ const string& xpath = "/kea-dhcp6-server:config";
+ ElementPtr options = Element::createList();
+ ElementPtr option = Element::createMap();
+ option->set("code", Element::create(100));
+ option->set("space", Element::create(string("dns")));
+ option->set("csv-format", Element::create(false));
+ option->set("data", Element::create(string("12121212")));
+ option->set("always-send", Element::create(false));
+ options->add(option);
+ EXPECT_NO_THROW(t_obj_->setOptionDataList(xpath, options));
+
+ // Get it back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW(got = t_obj_->getOptionDataList(xpath));
+ 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
new file mode 100644
index 0000000..d6c3cdf
--- /dev/null
+++ b/src/lib/yang/tests/translator_option_def_unittests.cc
@@ -0,0 +1,144 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_option_def.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const option_definition_list[] = "option definition list";
+
+/// @brief Test fixture class for @ref TranslatorOptionDefList.
+class TranslatorOptionDefListTestKeaV4 :
+ public GenericTranslatorTest<option_definition_list, TranslatorOptionDefList> {
+public:
+
+ /// Constructor.
+ TranslatorOptionDefListTestKeaV4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+class TranslatorOptionDefListTestKeaV6 :
+ public GenericTranslatorTest<option_definition_list, TranslatorOptionDefList> {
+public:
+
+ /// Constructor.
+ TranslatorOptionDefListTestKeaV6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+class TranslatorOptionDefListTestIetfV6 :
+ public GenericTranslatorTest<option_definition_list, TranslatorOptionDefList> {
+public:
+
+ /// Constructor.
+ TranslatorOptionDefListTestIetfV6() {
+ model_ = IETF_DHCPV6_SERVER;
+ }
+};
+
+// This test verifies that an empty option definition list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorOptionDefListTestKeaV4, getEmpty) {
+ // Get the option definition list and check if it is empty.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr options;
+ EXPECT_NO_THROW(options = t_obj_->getOptionDefList(xpath));
+ ASSERT_FALSE(options);
+}
+
+// This test verifies that one option definition can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorOptionDefListTestKeaV6, get) {
+ // Create the option code 100.
+ const string& xpath = "/kea-dhcp6-server:config";
+ const string& xdef = xpath + "/option-def[code='100'][space='isc']";
+ 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));
+
+ // Get the option def.
+ ConstElementPtr def;
+ EXPECT_NO_THROW(def = t_obj_->getOptionDef(xdef));
+ ASSERT_TRUE(def);
+ EXPECT_EQ("{ "
+ "\"array\": false, "
+ "\"code\": 100, "
+ "\"name\": \"foo\", "
+ "\"space\": \"isc\", "
+ "\"type\": \"string\" }",
+ def->str());
+
+ // Get the option definition list.
+ ConstElementPtr defs;
+ EXPECT_NO_THROW(defs = t_obj_->getOptionDefList(xpath));
+ ASSERT_TRUE(defs);
+ ASSERT_EQ(Element::list, defs->getType());
+ EXPECT_EQ(1, defs->size());
+ EXPECT_TRUE(def->equals(*defs->get(0)));
+}
+
+// This test verifies that an empty option definition list can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorOptionDefListTestKeaV4, setEmpty) {
+ // Set empty list.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr defs = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setOptionDefList(xpath, defs));
+
+ // Get it back.
+ defs.reset();
+ EXPECT_NO_THROW(defs = t_obj_->getOptionDefList(xpath));
+ ASSERT_FALSE(defs);
+}
+
+// This test verifies that one option definition can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorOptionDefListTestKeaV6, set) {
+ // Set one option def.
+ const string& xpath = "/kea-dhcp6-server:config";
+ ElementPtr defs = Element::createList();
+ ElementPtr def = Element::createMap();
+ def->set("code", Element::create(100));
+ def->set("name", Element::create(string("foo")));
+ def->set("space", Element::create(string("isc")));
+ def->set("type", Element::create(string("string")));
+ def->set("array", Element::create(false));
+ defs->add(def);
+ EXPECT_NO_THROW(t_obj_->setOptionDefList(xpath, defs));
+
+ // Get it back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW(got = t_obj_->getOptionDefList(xpath));
+ 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
new file mode 100644
index 0000000..8d5b3fe
--- /dev/null
+++ b/src/lib/yang/tests/translator_pd_pool_unittests.cc
@@ -0,0 +1,290 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_pd_pool.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const pd_pool_list[] = "pd pool list";
+
+/// @brief Test fixture class for @ref TranslatorPdPools.
+class TranslatorPdPoolsTestKeaV6 :
+ public GenericTranslatorTest<pd_pool_list, TranslatorPdPools> {
+public:
+
+ /// Constructor.
+ TranslatorPdPoolsTestKeaV6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+class TranslatorPdPoolsTestIetfV6 :
+ public GenericTranslatorTest<pd_pool_list, TranslatorPdPools> {
+public:
+
+ /// Constructor.
+ TranslatorPdPoolsTestIetfV6() {
+ model_ = IETF_DHCPV6_SERVER;
+ }
+};
+
+// This test verifies that an empty pd pool list can be properly
+// translated from YANG to JSON using the IETF model.
+TEST_F(TranslatorPdPoolsTestIetfV6, getEmptyIetf) {
+ // Get the pd-pool list and check if it is empty.
+ const string& xpath =
+ "/ietf-dhcpv6-server:server/server-config/network-ranges"
+ "/network-range[network-range-id='111']/pd-pools";
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that an empty pd pool list can be properly
+// translated from YANG to JSON using the Kea ad hoc model.
+TEST_F(TranslatorPdPoolsTestKeaV6, getEmptyKea) {
+ // Get the pd-pool list and check if it is empty.
+ const string& xpath = "/kea-dhcp6-server:config/subnet6[id='111']";
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that one pd pool can be properly
+// translated from YANG to JSON using the IETF model.
+TEST_F(TranslatorPdPoolsTestIetfV6, 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));
+ const string& subnet_subnet = subnet + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+ // 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));
+ 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));
+
+ // Get the pool.
+ ConstElementPtr pool;
+ EXPECT_NO_THROW(pool = t_obj_->getPdPool(xpath));
+ ASSERT_TRUE(pool);
+ ElementPtr expected = Element::createMap();
+ expected->set("prefix", Element::create(string("2001:db8:0:1000::")));
+ expected->set("prefix-len", Element::create(56));
+ EXPECT_TRUE(expected->equals(*pool));
+
+ // Get the pd-pool list and check if the pd-pool is in it.
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(subnet + "/pd-pools"));
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(Element::list, pools->getType());
+ ASSERT_EQ(1, pools->size());
+ EXPECT_TRUE(pool->equals(*pools->get(0)));
+}
+
+// This test verifies that one pd pool can be properly
+// translated from YANG to JSON using the Kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Create the pd-pool 2001:db8:0:1000::/64.
+ const string& prefix = "2001:db8:0:1000::/56";
+ ostringstream spool;
+ 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));
+
+ // Get the pool.
+ ConstElementPtr pool;
+ EXPECT_NO_THROW(pool = t_obj_->getPdPool(spool.str()));
+ ASSERT_TRUE(pool);
+ ElementPtr expected = Element::createMap();
+ expected->set("prefix", Element::create(string("2001:db8:0:1000::")));
+ expected->set("prefix-len", Element::create(56));
+ expected->set("delegated-len", Element::create(64));
+ EXPECT_TRUE(expected->equals(*pool));
+
+ // Get the pd-pool list and check if the pd-pool is in it.
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(Element::list, pools->getType());
+ ASSERT_EQ(1, pools->size());
+ EXPECT_TRUE(pool->equals(*pools->get(0)));
+}
+
+// This test verifies that an empty pd pool list can be properly
+// translated from JSON to YANG using the IETF model.
+TEST_F(TranslatorPdPoolsTestIetfV6, 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));
+ const string& subnet_subnet = subnet + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+ // Set empty list.
+ const string& xpath = subnet + "/pd-pools";
+ ConstElementPtr pools = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setPdPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that an empty pd pool list can be properly
+// translated from JSON to YANG using the Kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Set empty list.
+ ConstElementPtr pools = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setPdPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that one pd pool can be properly
+// translated from JSON to YANG using the IETF model.
+TEST_F(TranslatorPdPoolsTestIetfV6, 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));
+ const string& subnet_subnet = subnet + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+ // Set one pool.
+ const string& xpath = subnet + "/pd-pools";
+ ElementPtr pools = Element::createList();
+ ElementPtr pool = Element::createMap();
+ pool->set("prefix", Element::create(string("2001:db8:0:1000::")));
+ pool->set("prefix-len", Element::create(56));
+ pools->add(pool);
+ EXPECT_NO_THROW(t_obj_->setPdPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(Element::list, pools->getType());
+ ASSERT_EQ(1, pools->size());
+ EXPECT_TRUE(pool->equals(*pools->get(0)));
+}
+
+// This test verifies that one pd pool can be properly
+// translated from JSON to YANG using the kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Set one pool.
+ ElementPtr pools = Element::createList();
+ ElementPtr pool = Element::createMap();
+ pool->set("prefix", Element::create(string("2001:db8:0:1000::")));
+ pool->set("prefix-len", Element::create(56));
+ pool->set("delegated-len", Element::create(64));
+ pools->add(pool);
+ EXPECT_NO_THROW(t_obj_->setPdPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_TRUE(pools);
+ 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
+// translated from YANG to JSON using the Kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Create the first pd-pool 2001:db8:0:1000::/56.
+ const string& prefix = "2001:db8:0:1000::/56";
+ ostringstream spool;
+ 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));
+
+ // Create the second pd-pool 2001:db8:0:2000::/56
+ const string& prefix2 = "2001:db8:0:2000::/56";
+ ostringstream spool2;
+ 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));
+
+
+ // Get the pools list.
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
+ ASSERT_TRUE(pools);
+
+ // Check that both of them are returned properly.
+ EXPECT_EQ(pools->str(),
+ "[ { \"delegated-len\": 64, \"prefix\": \"2001:db8:0:1000::\", "
+ "\"prefix-len\": 56 }, { \"delegated-len\": 60, \"prefix\": "
+ "\"2001:db8:0:2000::\", \"prefix-len\": 56 } ]");
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/translator_pool_unittests.cc b/src/lib/yang/tests/translator_pool_unittests.cc
new file mode 100644
index 0000000..d8386b5
--- /dev/null
+++ b/src/lib/yang/tests/translator_pool_unittests.cc
@@ -0,0 +1,250 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_pool.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const pool_list[] = "pool list";
+
+/// @brief Test fixture class for @ref TranslatorPools.
+class TranslatorPoolsTestKeaV4 :
+ public GenericTranslatorTest<pool_list, TranslatorPools> {
+public:
+
+ /// Constructor.
+ TranslatorPoolsTestKeaV4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+
+class TranslatorPoolsTestKeaV6 :
+ public GenericTranslatorTest<pool_list, TranslatorPools> {
+public:
+
+ /// Constructor.
+ TranslatorPoolsTestKeaV6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+class TranslatorPoolsTestIetfV6 :
+ public GenericTranslatorTest<pool_list, TranslatorPools> {
+public:
+
+ /// Constructor.
+ TranslatorPoolsTestIetfV6() {
+ model_ = IETF_DHCPV6_SERVER;
+ }
+};
+
+// This test verifies that an empty pool list can be properly
+// translated from YANG to JSON using IETF model.
+TEST_F(TranslatorPoolsTestIetfV6, getEmptyIetf) {
+ // Get the pool list and check if it is empty.
+ const string& xpath = "/ietf-dhcpv6-server:server/server-config/"
+ "network-ranges/network-range[network-range-id='111']/address-pools";
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that an empty pool list can be properly
+// translated from YANG to JSON using Kea ad hoc model.
+TEST_F(TranslatorPoolsTestKeaV6, getEmptyKea) {
+ // Get the pool list and check if it is empty.
+ const string& xpath = "/kea-dhcp6-server:config/subnet6[id='111']";
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that one pool can be properly
+// translated from YANG to JSON using IETF model.
+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));
+ const string& subnet_subnet = subnet + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+ // 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));
+
+ // Get the pool.
+ ConstElementPtr pool;
+ EXPECT_NO_THROW(pool = t_obj_->getPool(xpath + "/address-pool[pool-id='222']"));
+ ASSERT_TRUE(pool);
+ EXPECT_EQ("{ \"pool\": \"2001:db8::1:0/112\" }", pool->str());
+
+ // Get the pool list and check if the pool is in it.
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(Element::list, pools->getType());
+ ASSERT_EQ(1, pools->size());
+ EXPECT_TRUE(pool->equals(*pools->get(0)));
+}
+
+// This test verifies that one pool can be properly
+// translated from YANG to JSON using Kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Create the pool 2001:db8::1:0/112.
+ const string& prefix = "2001:db8::1:0/112";
+ string start_addr;
+ string end_addr;
+ ASSERT_NO_THROW_LOG(TranslatorPool::getAddresses(prefix,
+ start_addr, end_addr));
+ EXPECT_EQ("2001:db8::1:0", start_addr);
+ EXPECT_EQ("2001:db8::1:ffff", end_addr);
+ ostringstream spool;
+ 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));
+
+ // Get the pool.
+ ConstElementPtr pool;
+ EXPECT_NO_THROW(pool = t_obj_->getPool(spool.str()));
+ ASSERT_TRUE(pool);
+ ElementPtr expected = Element::createMap();
+ expected->set("pool", Element::create(string("2001:db8::1:0/112")));
+ EXPECT_TRUE(expected->equals(*pool));
+
+ // Get the pool list and check if the pool is in it.
+ ConstElementPtr pools;
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(Element::list, pools->getType());
+ ASSERT_EQ(1, pools->size());
+ EXPECT_TRUE(pool->equals(*pools->get(0)));
+}
+
+// This test verifies that an empty pool list can be properly
+// translated from JSON to YANG using IETF model.
+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));
+ const string& subnet_subnet = subnet + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+ // Set empty list.
+ const string& xpath = subnet + "/address-pools";
+ ConstElementPtr pools = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that an empty pool list can be properly
+// translated from JSON to YANG using Kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Set empty list.
+ ConstElementPtr pools = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_FALSE(pools);
+}
+
+// This test verifies that one pool can be properly
+// translated from JSON to YANG using IETF model.
+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));
+ const string& subnet_subnet = subnet + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+ // Set one pool.
+ const string& xpath = subnet + "/address-pools";
+ ElementPtr pools = Element::createList();
+ ElementPtr pool = Element::createMap();
+ pool->set("pool", Element::create(string("2001:db8::1:0/112")));
+ pools->add(pool);
+ EXPECT_NO_THROW(t_obj_->setPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_TRUE(pools);
+ ASSERT_EQ(Element::list, pools->getType());
+ ASSERT_EQ(1, pools->size());
+ EXPECT_TRUE(pool->equals(*pools->get(0)));
+}
+
+// This test verifies that one pool can be properly
+// translated from JSON to YANG using Kea ad hoc model.
+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));
+ const string& subnet = xpath + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(subnet.c_str(), v_subnet));
+
+ // Set one pool.
+ ElementPtr pools = Element::createList();
+ ElementPtr pool = Element::createMap();
+ pool->set("pool",
+ Element::create(string("2001:db8::1 - 2001:db8::100")));
+ pools->add(pool);
+ EXPECT_NO_THROW(t_obj_->setPools(xpath, pools));
+
+ // Get it back.
+ pools.reset();
+ EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
+ ASSERT_TRUE(pools);
+ 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
new file mode 100644
index 0000000..2534700
--- /dev/null
+++ b/src/lib/yang/tests/translator_shared_network_unittests.cc
@@ -0,0 +1,209 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_shared_network.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const shared_networks[] = "shared networks";
+
+/// @brief Test fixture class for @ref TranslatorSharedNetworks.
+class TranslatorSharedNetworksTestKeaV4 :
+ public GenericTranslatorTest<shared_networks, TranslatorSharedNetworks> {
+public:
+
+ /// Constructor.
+ TranslatorSharedNetworksTestKeaV4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+class TranslatorSharedNetworksTestKeaV6 :
+ public GenericTranslatorTest<shared_networks, TranslatorSharedNetworks> {
+public:
+
+ /// Constructor.
+ TranslatorSharedNetworksTestKeaV6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+
+// This test verifies that an empty shared network list can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorSharedNetworksTestKeaV4, getEmpty) {
+ // Get the shared network list and check if it is empty.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr networks;
+ EXPECT_NO_THROW(networks = t_obj_->getSharedNetworks(xpath));
+ ASSERT_FALSE(networks);
+}
+
+// This test verifies that one shared network can be properly
+// translated from YANG to JSON.
+TEST_F(TranslatorSharedNetworksTestKeaV6, get) {
+ // Create the subnet 2001:db8::/48 #111 in shared network foo.
+ 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));
+
+ // Get the shared network.
+ ConstElementPtr network;
+ EXPECT_NO_THROW(network = t_obj_->getSharedNetwork(xnetwork));
+ ASSERT_TRUE(network);
+ ElementPtr subnet = Element::createMap();
+ subnet->set("id", Element::create(111));
+ subnet->set("subnet", Element::create(string("2001:db8::/48")));
+ ElementPtr subnets = Element::createList();
+ subnets->add(subnet);
+ ElementPtr expected = Element::createMap();
+ expected->set("name", Element::create(string("foo")));
+ expected->set("subnet6", subnets);
+ EXPECT_TRUE(expected->equals(*network));
+
+ // Get the shared network list and check if the shared network is in it.
+ ConstElementPtr networks;
+ EXPECT_NO_THROW(networks = t_obj_->getSharedNetworks(xpath));
+ ASSERT_TRUE(networks);
+ ASSERT_EQ(Element::list, networks->getType());
+ ASSERT_EQ(1, networks->size());
+ EXPECT_TRUE(network->equals(*networks->get(0)));
+}
+
+// This test verifies that an empty shared network list can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorSharedNetworksTestKeaV4, setEmpty) {
+ // Set empty list.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ConstElementPtr networks = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setSharedNetworks(xpath, networks));
+
+ // Get it back.
+ networks.reset();
+ EXPECT_NO_THROW(networks = t_obj_->getSharedNetworks(xpath));
+ ASSERT_FALSE(networks);
+}
+
+// This test verifies that one shared network can be properly
+// translated from JSON to YANG.
+TEST_F(TranslatorSharedNetworksTestKeaV6, set) {
+ // Set one shared network.
+ const string& xpath = "/kea-dhcp6-server:config";
+ ElementPtr networks = Element::createList();
+ ElementPtr share = Element::createMap();
+ ElementPtr subnets = Element::createList();
+ ElementPtr subnet = Element::createMap();
+ subnet->set("subnet", Element::create(string("2001:db8::/48")));
+ subnet->set("id", Element::create(123));
+ subnets->add(subnet);
+ share->set("name", Element::create(string("foo")));
+ share->set("subnet6", subnets);
+ networks->add(share);
+ EXPECT_NO_THROW(t_obj_->setSharedNetworks(xpath, networks));
+
+ // Get it back.
+ networks.reset();
+ EXPECT_NO_THROW(networks = t_obj_->getSharedNetworks(xpath));
+ ASSERT_TRUE(networks);
+ 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
+// translated from YANG to JSON. This test adds the following structure:
+//
+// shared-network "foo":
+// - subnet1: 2001:db8:1::/48 (subnet-id 1)
+// - subnet1: 2001:db8:2::/48 (subnet-id 2)
+// shared-network "bar":
+// - subnet1: 2001:db8:101::/48 (subnet-id 101)
+// - subnet1: 2001:db8:102::/48 (subnet-id 102)
+TEST_F(TranslatorSharedNetworksTestKeaV6, getList) {
+ const string& xpath = "/kea-dhcp6-server:config";
+
+ // Those two networks will be added.
+ const string& xnetwork1 = xpath + "/shared-network[name='foo']";
+ const string& xnetwork2 = xpath + "/shared-network[name='bar']";
+
+ // Non-existent network
+ const string& xnetwork3 = xpath + "/shared-network[name='baz']";
+
+ const string& exp_net1 =
+ "{ \"name\": \"foo\", \"subnet6\": [ { \"id\": 1, "
+ "\"subnet\": \"2001:db8:1::/48\" }, "
+ "{ \"id\": 2, \"subnet\": \"2001:db8:2::/48\" } ] }";
+
+ const string& exp_net2 =
+ "{ \"name\": \"bar\", \"subnet6\": [ { \"id\": 101, "
+ "\"subnet\": \"2001:db8:101::/48\" }, "
+ "{ \"id\": 102, \"subnet\": \"2001:db8:102::/48\" } ] }";
+
+ const string exp_both =
+ "[ " + exp_net1 + ", " + exp_net2 + " ]";
+
+ // 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));
+
+ // 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));
+
+ // 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));
+
+ // 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));
+
+ // Ok, now test the getters. Let's start with the easier ones that
+ // return a single network.
+ ConstElementPtr network;
+
+ // Get the first network.
+ EXPECT_NO_THROW(network = t_obj_->getSharedNetwork(xnetwork1));
+ ASSERT_TRUE(network);
+ EXPECT_EQ(exp_net1, network->str());
+
+ // Get the second network.
+ EXPECT_NO_THROW(network = t_obj_->getSharedNetwork(xnetwork2));
+ ASSERT_TRUE(network);
+ EXPECT_EQ(exp_net2, network->str());
+
+ // Check that networks with non-existent name are not returned.
+ EXPECT_THROW(network = t_obj_->getSharedNetwork(xnetwork3), Unexpected);
+
+ // Now test returns all networks
+ ConstElementPtr networks;
+ EXPECT_NO_THROW(networks = t_obj_->getSharedNetworks(xpath));
+ ASSERT_TRUE(networks);
+ EXPECT_EQ(exp_both, networks->str());
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/translator_subnet_unittests.cc b/src/lib/yang/tests/translator_subnet_unittests.cc
new file mode 100644
index 0000000..cc34596
--- /dev/null
+++ b/src/lib/yang/tests/translator_subnet_unittests.cc
@@ -0,0 +1,379 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_subnet.h>
+#include <yang/yang_models.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+/// @brief Translator name.
+extern char const subnet_list[] = "subnet list";
+
+/// @brief Test fixture class for @ref TranslatorSubnets.
+class TranslatorSubnetsTestKeaV4 :
+ public GenericTranslatorTest<subnet_list, TranslatorSubnets> {
+public:
+
+ /// Constructor.
+ TranslatorSubnetsTestKeaV4() {
+ model_ = KEA_DHCP4_SERVER;
+ }
+};
+class TranslatorSubnetsTestKeaV6 :
+ public GenericTranslatorTest<subnet_list, TranslatorSubnets> {
+public:
+
+ /// Constructor.
+ TranslatorSubnetsTestKeaV6() {
+ model_ = KEA_DHCP6_SERVER;
+ }
+};
+class TranslatorSubnetsTestIetfV6 :
+ public GenericTranslatorTest<subnet_list, TranslatorSubnets> {
+public:
+
+ /// Constructor.
+ TranslatorSubnetsTestIetfV6() {
+ model_ = IETF_DHCPV6_SERVER;
+ }
+};
+
+// This test verifies that an empty subnet list can be properly
+// translated from YANG to JSON using IETF model.
+TEST_F(TranslatorSubnetsTestIetfV6, getEmptyIetf) {
+ // Get the subnet list and check if it is empty.
+ const string& xpath =
+ "/ietf-dhcpv6-server:server/server-config/network-ranges";
+ ConstElementPtr subnets;
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_FALSE(subnets);
+}
+
+// This test verifies that an empty subnet list can be properly
+// translated from YANG to JSON using Kea ad hoc model.
+TEST_F(TranslatorSubnetsTestKeaV6, getEmptyKea) {
+ // Get the subnet list and check if it is empty.
+ const string& xpath = "/kea-dhcp6-server:config";
+ ConstElementPtr subnets;
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_FALSE(subnets);
+}
+
+// This test verifies that one subnet can be properly
+// translated from YANG to JSON using IETF model.
+TEST_F(TranslatorSubnetsTestIetfV6, getIetf) {
+ // Create the subnet 2001:db8::/48 #111.
+ 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));
+ const string& xsubnet = xsub + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+
+ // Get the subnet.
+ ConstElementPtr subnet;
+ EXPECT_NO_THROW(subnet = t_obj_->getSubnet(xsub));
+ ASSERT_TRUE(subnet);
+ EXPECT_EQ("{ \"id\": 111, "
+ "\"subnet\": \"2001:db8::/48\" }",
+ subnet->str());
+
+ // Get the subnet list and check if the subnet is in it.
+ ConstElementPtr subnets;
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ ASSERT_EQ(Element::list, subnets->getType());
+ ASSERT_EQ(1, subnets->size());
+ ASSERT_TRUE(subnets->get(0));
+ EXPECT_TRUE(subnet->equals(*subnets->get(0)));
+}
+
+// This test verifies that one subnet can be properly
+// translated from YANG to JSON using Kea ad hoc model.
+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));
+ const string& xsubnet = xsub + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+
+ // Get the subnet.
+ ConstElementPtr subnet;
+ EXPECT_NO_THROW(subnet = t_obj_->getSubnet(xsub));
+ ASSERT_TRUE(subnet);
+ ElementPtr expected = Element::createMap();
+ expected->set("id", Element::create(111));
+ expected->set("subnet", Element::create(string("2001:db8::/48")));
+ EXPECT_TRUE(expected->equals(*subnet));
+
+ // Get the subnet list and check if the subnet is in it.
+ ConstElementPtr subnets;
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ ASSERT_EQ(Element::list, subnets->getType());
+ ASSERT_EQ(1, subnets->size());
+ EXPECT_TRUE(subnet->equals(*subnets->get(0)));
+}
+
+// This test verifies that one subnet with two pools can be properly
+// translated from YANG to JSON using IETF model.
+TEST_F(TranslatorSubnetsTestIetfV6, getPoolsIetf) {
+ // Create the subnet 2001:db8::/48 #111.
+ 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));
+ const string& xsubnet = xsub + "/network-prefix";
+ EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+
+ // 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));
+
+ // 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));
+
+ // Get the subnet.
+ ConstElementPtr subnet;
+ EXPECT_NO_THROW(subnet = t_obj_->getSubnet(xsub));
+ ASSERT_TRUE(subnet);
+ string expected =
+ "{\n"
+ " \"id\": 111,\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8::1:0/112\"\n"
+ " },\n"
+ " {\n"
+ " \"pool\": \"2001:db8::2:0/112\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"2001:db8::/48\"\n"
+ "}";
+ EXPECT_EQ(expected, prettyPrint(subnet));
+
+ // Get the subnet list and check if the subnet is in it.
+ ConstElementPtr subnets;
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ ASSERT_EQ(Element::list, subnets->getType());
+ ASSERT_EQ(1, subnets->size());
+ EXPECT_TRUE(subnet->equals(*subnets->get(0)));
+}
+
+// This test verifies that one subnet with two pools can be properly
+// translated from YANG to JSON using Kea ad hoc model.
+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));
+ const string& xsubnet = xsub + "/subnet";
+ EXPECT_NO_THROW(sess_->set_item(xsubnet.c_str(), v_subnet));
+
+ // 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));
+
+ // 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));
+
+ // Get the subnet.
+ ConstElementPtr subnet;
+ EXPECT_NO_THROW(subnet = t_obj_->getSubnet(xsub));
+ ASSERT_TRUE(subnet);
+ string expected =
+ "{\n"
+ " \"id\": 111,\n"
+ " \"pools\": [\n"
+ " {\n"
+ " \"pool\": \"2001:db8::1:0/112\"\n"
+ " },\n"
+ " {\n"
+ " \"pool\": \"2001:db8::2:0 - 2001:db8::2:ffff\"\n"
+ " }\n"
+ " ],\n"
+ " \"subnet\": \"2001:db8::/48\"\n"
+ "}";
+ EXPECT_EQ(expected, prettyPrint(subnet));
+
+ // Get the subnet list and check if the subnet is in it.
+ ConstElementPtr subnets;
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ ASSERT_EQ(Element::list, subnets->getType());
+ ASSERT_EQ(1, subnets->size());
+ EXPECT_TRUE(subnet->equals(*subnets->get(0)));
+}
+
+// This test verifies that an empty subnet list can be properly
+// translated from JSON to YANG using IETF model.
+TEST_F(TranslatorSubnetsTestIetfV6, setEmptyIetf) {
+ // Set empty list.
+ const string& xpath =
+ "/ietf-dhcpv6-server:server/server-config/network-ranges";
+ ConstElementPtr subnets = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
+
+ // Get it back.
+ subnets.reset();
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_FALSE(subnets);
+}
+
+// This test verifies that an empty subnet list can be properly
+// translated from JSON to YANG using Kea ad hoc model.
+TEST_F(TranslatorSubnetsTestKeaV4, setEmptyKea) {
+ // Set empty list.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ElementPtr subnets = Element::createList();
+ EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
+
+ // Get it back.
+ subnets.reset();
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_FALSE(subnets);
+}
+
+// This test verifies that one subnet can be properly
+// translated from JSON to YANG using IETF model.
+TEST_F(TranslatorSubnetsTestIetfV6, setIetf) {
+ // Set one subnet.
+ const string& xpath =
+ "/ietf-dhcpv6-server:server/server-config/network-ranges";
+ ElementPtr subnets = Element::createList();
+ ElementPtr subnet = Element::createMap();
+ subnet->set("subnet", Element::create(string("2001:db8::/48")));
+ subnet->set("id", Element::create(123));
+ subnets->add(subnet);
+ EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
+
+ // Get it back.
+ subnets.reset();
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ ASSERT_EQ(Element::list, subnets->getType());
+ ASSERT_EQ(1, subnets->size());
+ EXPECT_TRUE(subnet->equals(*subnets->get(0)));
+}
+
+// This test verifies that one subnet can be properly
+// translated from JSON to YANG using Kea ad hoc model.
+TEST_F(TranslatorSubnetsTestKeaV4, setKea) {
+ // Set one subnet.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ElementPtr subnets = Element::createList();
+ ElementPtr subnet = Element::createMap();
+ subnet->set("subnet", Element::create(string("10.0.1.0/24")));
+ subnet->set("id", Element::create(123));
+ subnets->add(subnet);
+ EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
+
+ // Get it back.
+ subnets.reset();
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ 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
+// translated from JSON to YANG using IETF model.
+TEST_F(TranslatorSubnetsTestIetfV6, setTwoIetf) {
+ // Set one subnet.
+ const string& xpath =
+ "/ietf-dhcpv6-server:server/server-config/network-ranges";
+ ElementPtr subnets = Element::createList();
+ ElementPtr subnet = Element::createMap();
+ subnet->set("subnet", Element::create(string("2001:db8::/48")));
+ subnet->set("id", Element::create(123));
+
+ // Add two pools.
+ ElementPtr pools = Element::createList();
+ ElementPtr pool1 = Element::createMap();
+ pool1->set("pool", Element::create(string("2001:db8::1:0/112")));
+ pools->add(pool1);
+ ElementPtr pool2 = Element::createMap();
+ pool2->set("pool", Element::create(string("2001:db8::2:0/112")));
+ pools->add(pool2);
+ subnet->set("pools", pools);
+
+ // Add the subnet.
+ subnets->add(subnet);
+ EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
+
+ // Get it back.
+ subnets.reset();
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ ASSERT_EQ(Element::list, subnets->getType());
+ ASSERT_EQ(1, subnets->size());
+ EXPECT_TRUE(subnet->equals(*subnets->get(0)));
+}
+
+// This test verifies that one subnet with two pools can be properly
+// translated from JSON to YANG using Kea ad hoc model.
+TEST_F(TranslatorSubnetsTestKeaV4, setTwoKea) {
+ // Set one subnet.
+ const string& xpath = "/kea-dhcp4-server:config";
+ ElementPtr subnets = Element::createList();
+ ElementPtr subnet = Element::createMap();
+ subnet->set("subnet", Element::create(string("10.0.1.0/24")));
+ subnet->set("id", Element::create(123));
+
+ // Add two pools.
+ ElementPtr pools = Element::createList();
+ ElementPtr pool1 = Element::createMap();
+ pool1->set("pool", Element::create(string("10.0.1.0/28")));
+ pools->add(pool1);
+ ElementPtr pool2 = Element::createMap();
+ pool2->set("pool", Element::create(string("10.0.1.200 - 10.0.1.222")));
+ pools->add(pool2);
+ subnet->set("pools", pools);
+
+ // Add the subnet.
+ subnets->add(subnet);
+ EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
+
+ // Get it back.
+ subnets.reset();
+ EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
+ ASSERT_TRUE(subnets);
+ 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
new file mode 100644
index 0000000..a602b28
--- /dev/null
+++ b/src/lib/yang/tests/translator_unittests.cc
@@ -0,0 +1,683 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/translator.h>
+
+#include <boost/scoped_ptr.hpp>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::data;
+using namespace isc::yang;
+using namespace sysrepo;
+
+using libyang::S_Data_Node;
+
+namespace {
+
+// Test constructor.
+TEST(TranslatorBasicTest, constructor) {
+ // Get a connection.
+ S_Connection conn(std::make_shared<Connection>());
+ // Get a session.
+ S_Session sess(new Session(conn, SR_DS_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) {
+ // Get a translator object to play with.
+ S_Connection conn(std::make_shared<Connection>());
+ S_Session sess(new Session(conn, SR_DS_CANDIDATE));
+ boost::scoped_ptr<TranslatorBasic> t_obj;
+ ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, "")));
+ S_Val 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::string, elem->getType());
+ EXPECT_EQ("str", elem->stringValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::boolean, elem->getType());
+ EXPECT_TRUE(elem->boolValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::integer, elem->getType());
+ EXPECT_EQ(8, elem->intValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::integer, elem->getType());
+ EXPECT_EQ(16, elem->intValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::integer, elem->getType());
+ EXPECT_EQ(32, elem->intValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::integer, elem->getType());
+ EXPECT_EQ(8, elem->intValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::integer, elem->getType());
+ EXPECT_EQ(16, elem->intValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::integer, elem->getType());
+ EXPECT_EQ(32, elem->intValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::string, elem->getType());
+ EXPECT_EQ("keatest-module:id_1", elem->stringValue());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::string, elem->getType());
+ EXPECT_EQ("maybe", elem->stringValue());
+ elem.reset();
+
+ // 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(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::string, elem->getType());
+ EXPECT_EQ("foobar", elem->stringValue());
+ elem.reset();
+
+ // Leaf-list: not yet exist.
+ xpath = "/keatest-module:main/numbers";
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ EXPECT_FALSE(elem);
+ elem.reset();
+
+ // No easy way to create it empty.
+
+ // 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));
+ u8 = 2;
+ s_val.reset(new Val(u8));
+ EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ u8 = 3;
+ s_val.reset(new Val(u8));
+ EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val));
+ EXPECT_NO_THROW(elem = t_obj->getItems(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::list, elem->getType());
+ EXPECT_EQ(3, elem->size());
+ EXPECT_EQ("[ 1, 2, 3 ]", elem->str());
+ elem.reset();
+
+ // 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));
+ EXPECT_NO_THROW(elem = t_obj->getItem(xpath));
+ ASSERT_TRUE(elem);
+ ASSERT_EQ(Element::real, elem->getType());
+ EXPECT_EQ("9.85", elem->str());
+ elem.reset();
+
+ // 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(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();
+ }
+}
+
+// Test JSON to basic yang value using the static method.
+TEST(TranslatorBasicTest, valueTo) {
+
+ // Null.
+ ConstElementPtr elem;
+ EXPECT_THROW(TranslatorBasic::value(elem, SR_STRING_T), BadValue);
+
+ // Container.
+ elem = Element::createMap();
+ EXPECT_THROW(TranslatorBasic::value(elem, SR_CONTAINER_T), NotImplemented);
+ EXPECT_THROW(TranslatorBasic::value(elem, SR_CONTAINER_PRESENCE_T), 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();
+
+ // 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();
+
+ // 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();
+
+ // 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());
+ 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());
+ 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());
+ 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());
+ 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());
+ 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());
+ 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();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+}
+
+// Test JSON to basic yang value using sysrepo test models.
+TEST(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));
+ 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);
+
+ // String.
+ S_Val 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_STRING_T, s_val->type());
+ EXPECT_EQ("str", string(s_val->data()->get_string()));
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_BOOL_T, s_val->type());
+ EXPECT_TRUE(s_val->data()->get_bool());
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_UINT8_T, s_val->type());
+ EXPECT_EQ(8, s_val->data()->get_uint8());
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_UINT16_T, s_val->type());
+ EXPECT_EQ(16, s_val->data()->get_uint16());
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_UINT32_T, s_val->type());
+ EXPECT_EQ(32, s_val->data()->get_uint32());
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_INT8_T, s_val->type());
+ EXPECT_EQ(8, s_val->data()->get_int8());
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_INT16_T, s_val->type());
+ EXPECT_EQ(16, s_val->data()->get_int16());
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_INT32_T, s_val->type());
+ EXPECT_EQ(32, s_val->data()->get_int32());
+ s_val.reset();
+
+ // 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()));
+ 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();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_ENUM_T, s_val->type());
+ EXPECT_EQ("maybe", string(s_val->data()->get_enum()));
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_BINARY_T, s_val->type());
+ EXPECT_EQ("Zm9vYmFy", string(s_val->data()->get_binary()));
+ s_val.reset();
+
+ // 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()));
+ ASSERT_TRUE(s_val);
+ ASSERT_EQ(SR_DECIMAL64_T, s_val->type());
+ EXPECT_DOUBLE_EQ(d64, s_val->data()->get_decimal64());
+ s_val.reset();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+ }
+
+ // 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();
+ }
+
+ // 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);
+ EXPECT_EQ(elem->str(), "\"true\"");
+
+ // Delete (twice).
+ xpath = "/keatest-module:main/string";
+ EXPECT_NO_THROW(s_val = sess->get_item(xpath.c_str()));
+ EXPECT_TRUE(s_val);
+ s_val.reset();
+ 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_FALSE(s_val);
+ EXPECT_NO_THROW(t_obj->delItem(xpath));
+}
+
+// Test yang list item retrieval.
+TEST(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));
+ boost::scoped_ptr<TranslatorBasic> t_obj;
+ ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, "")));
+ string xpath;
+
+ // Empty list.
+ ElementPtr element;
+ EXPECT_NO_THROW(element = t_obj->getItem("/keatest-module:container/list"));
+ EXPECT_FALSE(element);
+ element.reset();
+
+ // 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));
+ EXPECT_NO_THROW(element = t_obj->getItem("/keatest-module:container/list"));
+ ASSERT_TRUE(element);
+ EXPECT_NO_THROW(element = t_obj->getItem("/keatest-module:container/list[key1='key1'][key2='key2']"));
+ ASSERT_TRUE(element);
+}
+
+} // anonymous namespace
diff --git a/src/lib/yang/tests/translator_utils_unittests.cc b/src/lib/yang/tests/translator_utils_unittests.cc
new file mode 100644
index 0000000..bc68f12
--- /dev/null
+++ b/src/lib/yang/tests/translator_utils_unittests.cc
@@ -0,0 +1,270 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/gtest_utils.h>
+#include <yang/tests/yang_configs.h>
+#include <yang/tests/sysrepo_setup.h>
+
+#include <gtest/gtest.h>
+
+#include <sstream>
+
+using namespace std;
+using namespace isc;
+using namespace isc::yang;
+using namespace isc::yang::test;
+using namespace sysrepo;
+
+namespace {
+
+// Test sr_type_t print.
+TEST(YangReprTest, type) {
+ ostringstream os;
+
+ // Verify that string is "string" (vs a number).
+ sr_type_t t = SR_STRING_T;
+ os << t;
+ EXPECT_EQ("string", os.str());
+ os.str("");
+
+ // Compiler does not let to create an invalid value...
+}
+
+// Test YangReprItem basic stuff.
+TEST(YangReprTest, item) {
+ // An item.
+ YRItem item1("/foo", "bar", SR_STRING_T, true);
+ EXPECT_EQ("/foo", item1.xpath_);
+ EXPECT_EQ("bar", item1.value_);
+ EXPECT_EQ(SR_STRING_T, item1.type_);
+ EXPECT_TRUE(item1.settable_);
+
+ // Another one.
+ YRItem item2("/foo", "bar", SR_STRING_T, false);
+ EXPECT_EQ("/foo", item2.xpath_);
+ EXPECT_EQ("bar", item2.value_);
+ EXPECT_EQ(SR_STRING_T, item2.type_);
+ EXPECT_FALSE(item2.settable_);
+
+ // Equality.
+ EXPECT_TRUE(item1 == item2);
+ EXPECT_TRUE(item2 == item1);
+ EXPECT_FALSE(item1 != item2);
+ EXPECT_FALSE(item2 != item1);
+ EXPECT_EQ(item1, item2);
+ EXPECT_EQ(item2, item1);
+}
+
+// Test get with test module.
+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));
+
+ // 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());
+
+ // Fill the test module.
+ string xpath;
+ S_Val 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ 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());
+
+ // 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());
+
+ // Get it.
+ YangRepr repr(testModel);
+ YRTree tree;
+ EXPECT_NO_THROW(tree = repr.get(sess));
+
+ // Verify.
+ EXPECT_TRUE(repr.verify(testTree, sess, cerr));
+}
+
+// This test verifies that errors are handled properly.
+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));
+
+ // 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());
+
+ // Get it.
+ YangRepr repr(testModel);
+ YRTree tree;
+ EXPECT_NO_THROW(repr.set(testTree, sess));
+
+ // Verify.
+ EXPECT_TRUE(repr.verify(testTree, sess, cerr));
+
+ // Change a path. Remove final 'm'.
+ YRTree badpath = testTree;
+ string xpath("/keatest-module:main/enum");
+ YRItem node(badpath.at(xpath));
+ node.xpath_ = "/keatest-module:main/enu";
+ badpath.erase(xpath);
+ badpath.emplace(xpath, node);
+ EXPECT_FALSE(repr.verify(badpath, sess, cerr));
+
+ // Change a value from "str" to "Str".
+ YRTree badvalue = testTree;
+ xpath = "/keatest-module:main/string";
+ badvalue.at(xpath).value_ = "Str";
+ EXPECT_FALSE(repr.verify(badvalue, sess, cerr));
+
+ // Change a type from SR_INT32_T to SR_UINT32_T.
+ YRTree badtype = testTree;
+ xpath = "/keatest-module:main/i32";
+ badtype.at(xpath).type_ = SR_UINT32_T;
+ 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");
+ EXPECT_FALSE(repr.verify(badextra, sess, cerr));
+}
+
+// Test set with test module.
+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));
+
+ // 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());
+
+ // Set the module content.
+ YangRepr repr(testModel);
+ EXPECT_NO_THROW(repr.set(testTree, sess));
+
+ // Verify it.
+ EXPECT_TRUE(repr.verify(testTree, sess, cerr));
+}
+
+/// @brief Tests specified configuration.
+///
+/// Configuration is set and then verified using YangRepr object.
+///
+/// @param model name of the model to be verified against.
+/// @param tree tree to be verified.
+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));
+
+ // Cleanup.
+ TranslatorBasic translator(sess, model);
+ std::string toplevel_node("config");
+ if (model == IETF_DHCPV6_SERVER) {
+ toplevel_node = "server";
+ }
+ translator.delItem("/" + model + ":" + toplevel_node);
+
+ // Get it.
+ YangRepr repr(model);
+
+ EXPECT_NO_THROW(repr.set(tree, sess))
+ << " for model " << model;
+ bool result = false;
+ EXPECT_NO_THROW(result = repr.verify(tree, sess, cerr))
+ << " for model " << model;
+ EXPECT_TRUE(result)
+ << " for model " << model;
+}
+
+// This is test environment sanity check. It verifies that all configuration
+// defined in yang_configs.h are sane.
+TEST(YangReprTest, verifyConfigs) {
+ for (auto x : TEST_CONFIGS) {
+ sanityCheckConfig(x.first, x.second);
+ }
+}
+
+} // namespace
diff --git a/src/lib/yang/tests/yang_configs.h b/src/lib/yang/tests/yang_configs.h
new file mode 100644
index 0000000..71a89ea
--- /dev/null
+++ b/src/lib/yang/tests/yang_configs.h
@@ -0,0 +1,591 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_YANG_CONFIGS_H
+#define ISC_YANG_CONFIGS_H
+
+#include <yang/yang_models.h>
+#include <yang/testutils/translator_test.h>
+
+namespace isc {
+namespace yang {
+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 }
+});
+
+/// @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/server-config/network-ranges",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']", "", SR_LIST_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-range-id",
+ "111", SR_UINT32_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-prefix",
+ "2001:db8::/48", SR_STRING_T, 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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
+ "65535", SR_UINT16_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/address-pools",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/pd-pools",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
+ "", SR_CONTAINER_T, 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/server-config/network-ranges",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']", "", SR_LIST_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-range-id",
+ "111", SR_UINT32_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-prefix",
+ "2001:db8::/48", SR_STRING_T, 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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
+ "65535", SR_UINT16_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/address-pools",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/pd-pools",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
+ "", SR_CONTAINER_T, 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/server-config/serv-attributes",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes"
+ "/vendor-info/ent-num", "2495", SR_UINT32_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']", "", SR_LIST_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-range-id",
+ "111", SR_UINT32_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-description",
+ "Subnet#111", SR_STRING_T, true },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/network-prefix",
+ "2001:db8::/48", SR_STRING_T, 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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
+ "65535", SR_UINT16_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/address-pools",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='111']/pd-pools",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
+ "", SR_CONTAINER_T, 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/subnet4[id='111']/id",
+ "111", SR_UINT32_T, false },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/"
+ "option-data[code='100'][space='dns']", "", SR_LIST_T, false },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/"
+ "option-data[code='100'][space='dns']/code",
+ "100", SR_UINT8_T, false },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/"
+ "option-data[code='100'][space='dns']/space",
+ "dns", SR_STRING_T, false },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/"
+ "option-data[code='100'][space='dns']/data",
+ "12121212", SR_STRING_T, true },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/"
+ "option-data[code='100'][space='dns']/csv-format",
+ "false", SR_BOOL_T, true },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/"
+ "option-data[code='100'][space='dns']/always-send",
+ "false", SR_BOOL_T, 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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/subnet",
+ "10.0.0.0/8", SR_STRING_T, true },
+ { "/kea-dhcp4-server:config/expired-leases-processing",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/dhcp-ddns",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/config-control",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/sanity-checks",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/interfaces-config",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/subnet4[id='111']/relay",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/compatibility",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/multi-threading",
+ "", SR_CONTAINER_T, 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/subnet6[id='111']/id",
+ "111", SR_UINT32_T, 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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/kea-dhcp6-server:config/subnet6[id='111']/subnet",
+ "2001:db8::/48", SR_STRING_T, true },
+ { "/kea-dhcp6-server:config/expired-leases-processing",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/dhcp-ddns",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/config-control",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/sanity-checks",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/interfaces-config",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/subnet6[id='111']/relay",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/compatibility",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/multi-threading",
+ "", SR_CONTAINER_T, 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/server-config/network-ranges",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='1']", "", SR_LIST_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='1']/network-range-id",
+ "1", SR_UINT32_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='1']/network-description",
+ "example", SR_STRING_T, true },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='1']/pd-pools",
+ "", SR_CONTAINER_T, 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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/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 },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code",
+ "65535", SR_UINT16_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='1']/host-reservations",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid",
+ "", SR_CONTAINER_T, 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 },
+ { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options",
+ "", SR_CONTAINER_T, false },
+ { "/ietf-dhcpv6-server:server/server-config/network-ranges/"
+ "network-range[network-range-id='1']/address-pools",
+ "", SR_CONTAINER_T, false },
+});
+
+const YRTree emptyTreeKeaDhcp4 = YangRepr::buildTreeFromVector({
+ { "/kea-dhcp4-server:config", "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/expired-leases-processing",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/dhcp-ddns",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/config-control",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/sanity-checks",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/interfaces-config",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/compatibility",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp4-server:config/multi-threading",
+ "", SR_CONTAINER_T, false },
+});
+
+const YRTree emptyTreeKeaDhcp6 = YangRepr::buildTreeFromVector({
+ { "/kea-dhcp6-server:config", "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/expired-leases-processing",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/dhcp-ddns",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/config-control",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/sanity-checks",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/interfaces-config",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/compatibility",
+ "", SR_CONTAINER_T, false },
+ { "/kea-dhcp6-server:config/multi-threading",
+ "", SR_CONTAINER_T, false },
+});
+
+/// @brief Set of example configurations.
+const std::vector<std::pair<std::string, YRTree> > TEST_CONFIGS =
+{
+ { testModel, testTree },
+ { subnetTwoPoolsModelIetf6, subnetTwoPoolsTreeIetf6 },
+ { subnetTimersModel, subnetTimersIetf6 },
+ { validModelIetf6, validTreeIetf6 },
+ { subnetOptionsModelKeaDhcp4, subnetOptionsTreeKeaDhcp4 },
+ { subnetOptionsModelKeaDhcp6, subnetOptionsTreeKeaDhcp6 },
+ { designExampleModel, designExampleTree }
+};
+
+} // namespace test
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_YANG_CONFIGS_H
diff --git a/src/lib/yang/testutils/Makefile.am b/src/lib/yang/testutils/Makefile.am
new file mode 100644
index 0000000..21035d0
--- /dev/null
+++ b/src/lib/yang/testutils/Makefile.am
@@ -0,0 +1,24 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+AM_CPPFLAGS += $(SYSREPO_INCLUDEDIR)
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+if HAVE_GTEST
+
+noinst_LTLIBRARIES = libyangtest.la
+
+libyangtest_la_SOURCES = translator_test.cc translator_test.h
+
+libyangtest_la_CXXFLAGS = $(AM_CXXFLAGS)
+libyangtest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+libyangtest_la_LDFLAGS = $(AM_LDFLAGS)
+
+libyangtest_la_LIBADD = $(top_builddir)/src/lib/yang/libkea-yang.la
+libyangtest_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la
+
+endif
diff --git a/src/lib/yang/testutils/Makefile.in b/src/lib/yang/testutils/Makefile.in
new file mode 100644
index 0000000..97c2fdd
--- /dev/null
+++ b/src/lib/yang/testutils/Makefile.in
@@ -0,0 +1,840 @@
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src/lib/yang/testutils
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \
+ $(top_srcdir)/m4macros/ax_cpp11.m4 \
+ $(top_srcdir)/m4macros/ax_crypto.m4 \
+ $(top_srcdir)/m4macros/ax_find_library.m4 \
+ $(top_srcdir)/m4macros/ax_gssapi.m4 \
+ $(top_srcdir)/m4macros/ax_gtest.m4 \
+ $(top_srcdir)/m4macros/ax_isc_rpath.m4 \
+ $(top_srcdir)/m4macros/ax_sysrepo.m4 \
+ $(top_srcdir)/m4macros/libtool.m4 \
+ $(top_srcdir)/m4macros/ltoptions.m4 \
+ $(top_srcdir)/m4macros/ltsugar.m4 \
+ $(top_srcdir)/m4macros/ltversion.m4 \
+ $(top_srcdir)/m4macros/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+@HAVE_GTEST_TRUE@libyangtest_la_DEPENDENCIES = \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/yang/libkea-yang.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/log/libkea-log.la
+am__libyangtest_la_SOURCES_DIST = translator_test.cc translator_test.h
+@HAVE_GTEST_TRUE@am_libyangtest_la_OBJECTS = \
+@HAVE_GTEST_TRUE@ libyangtest_la-translator_test.lo
+libyangtest_la_OBJECTS = $(am_libyangtest_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+libyangtest_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
+ $(libyangtest_la_CXXFLAGS) $(CXXFLAGS) \
+ $(libyangtest_la_LDFLAGS) $(LDFLAGS) -o $@
+@HAVE_GTEST_TRUE@am_libyangtest_la_rpath =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/libyangtest_la-translator_test.Plo
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(libyangtest_la_SOURCES)
+DIST_SOURCES = $(am__libyangtest_la_SOURCES_DIST)
+RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
+ ctags-recursive dvi-recursive html-recursive info-recursive \
+ install-data-recursive install-dvi-recursive \
+ install-exec-recursive install-html-recursive \
+ install-info-recursive install-pdf-recursive \
+ install-ps-recursive install-recursive installcheck-recursive \
+ installdirs-recursive pdf-recursive ps-recursive \
+ tags-recursive uninstall-recursive
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
+ distclean-recursive maintainer-clean-recursive
+am__recursive_targets = \
+ $(RECURSIVE_TARGETS) \
+ $(RECURSIVE_CLEAN_TARGETS) \
+ $(am__extra_recursive_targets)
+AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
+ distdir distdir-am
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+ dir0=`pwd`; \
+ sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+ sed_rest='s,^[^/]*/*,,'; \
+ sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+ sed_butlast='s,/*[^/]*$$,,'; \
+ while test -n "$$dir1"; do \
+ first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+ if test "$$first" != "."; then \
+ if test "$$first" = ".."; then \
+ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+ else \
+ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+ if test "$$first2" = "$$first"; then \
+ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+ else \
+ dir2="../$$dir2"; \
+ fi; \
+ dir0="$$dir0"/"$$first"; \
+ fi; \
+ fi; \
+ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+ done; \
+ reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+ASCIIDOC = @ASCIIDOC@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BOOST_INCLUDES = @BOOST_INCLUDES@
+BOOST_LIBS = @BOOST_LIBS@
+BOTAN_TOOL = @BOTAN_TOOL@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONTRIB_DIR = @CONTRIB_DIR@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CRYPTO_CFLAGS = @CRYPTO_CFLAGS@
+CRYPTO_INCLUDES = @CRYPTO_INCLUDES@
+CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@
+CRYPTO_LIBS = @CRYPTO_LIBS@
+CRYPTO_PACKAGE = @CRYPTO_PACKAGE@
+CRYPTO_RPATH = @CRYPTO_RPATH@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@
+DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@
+DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@
+DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@
+DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@
+DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@
+DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@
+DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GENHTML = @GENHTML@
+GREP = @GREP@
+GSSAPI_CFLAGS = @GSSAPI_CFLAGS@
+GSSAPI_LIBS = @GSSAPI_LIBS@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_SOURCE = @GTEST_SOURCE@
+HAVE_SYSREPO = @HAVE_SYSREPO@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+KEA_CXXFLAGS = @KEA_CXXFLAGS@
+KEA_SRCID = @KEA_SRCID@
+KRB5_CONFIG = @KRB5_CONFIG@
+LCOV = @LCOV@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@
+LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@
+MYSQL_LIBS = @MYSQL_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PDFLATEX = @PDFLATEX@
+PERL = @PERL@
+PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@
+PGSQL_LIBS = @PGSQL_LIBS@
+PKGPYTHONDIR = @PKGPYTHONDIR@
+PKG_CONFIG = @PKG_CONFIG@
+PLANTUML = @PLANTUML@
+PREMIUM_DIR = @PREMIUM_DIR@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+SED = @SED@
+SEP = @SEP@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SPHINXBUILD = @SPHINXBUILD@
+SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@
+SR_REPO_PATH = @SR_REPO_PATH@
+STRIP = @STRIP@
+SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@
+SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@
+SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@
+SYSREPO_LIBS = @SYSREPO_LIBS@
+SYSREPO_VERSION = @SYSREPO_VERSION@
+USE_LCOV = @USE_LCOV@
+VALGRIND = @VALGRIND@
+VERSION = @VERSION@
+WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@
+YACC = @YACC@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+SUBDIRS = .
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib \
+ $(BOOST_INCLUDES) $(SYSREPO_CPPFLAGS) $(SYSREPO_INCLUDEDIR)
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+CLEANFILES = *.gcno *.gcda
+@HAVE_GTEST_TRUE@noinst_LTLIBRARIES = libyangtest.la
+@HAVE_GTEST_TRUE@libyangtest_la_SOURCES = translator_test.cc translator_test.h
+@HAVE_GTEST_TRUE@libyangtest_la_CXXFLAGS = $(AM_CXXFLAGS)
+@HAVE_GTEST_TRUE@libyangtest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+@HAVE_GTEST_TRUE@libyangtest_la_LDFLAGS = $(AM_LDFLAGS)
+@HAVE_GTEST_TRUE@libyangtest_la_LIBADD = \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/yang/libkea-yang.la \
+@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/log/libkea-log.la
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .cc .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/yang/testutils/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/lib/yang/testutils/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
+libyangtest.la: $(libyangtest_la_OBJECTS) $(libyangtest_la_DEPENDENCIES) $(EXTRA_libyangtest_la_DEPENDENCIES)
+ $(AM_V_CXXLD)$(libyangtest_la_LINK) $(am_libyangtest_la_rpath) $(libyangtest_la_OBJECTS) $(libyangtest_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libyangtest_la-translator_test.Plo@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.cc.o:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cc.lo:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+libyangtest_la-translator_test.lo: translator_test.cc
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libyangtest_la_CPPFLAGS) $(CPPFLAGS) $(libyangtest_la_CXXFLAGS) $(CXXFLAGS) -MT libyangtest_la-translator_test.lo -MD -MP -MF $(DEPDIR)/libyangtest_la-translator_test.Tpo -c -o libyangtest_la-translator_test.lo `test -f 'translator_test.cc' || echo '$(srcdir)/'`translator_test.cc
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libyangtest_la-translator_test.Tpo $(DEPDIR)/libyangtest_la-translator_test.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='translator_test.cc' object='libyangtest_la-translator_test.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libyangtest_la_CPPFLAGS) $(CPPFLAGS) $(libyangtest_la_CXXFLAGS) $(CXXFLAGS) -c -o libyangtest_la-translator_test.lo `test -f 'translator_test.cc' || echo '$(srcdir)/'`translator_test.cc
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run 'make' without going through this Makefile.
+# To change the values of 'make' variables: instead of editing Makefiles,
+# (1) if the variable is set in 'config.status', edit 'config.status'
+# (which will cause the Makefiles to be regenerated when you run 'make');
+# (2) otherwise, pass the desired values on the 'make' command line.
+$(am__recursive_targets):
+ @fail=; \
+ if $(am__make_keepgoing); then \
+ failcom='fail=yes'; \
+ else \
+ failcom='exit 1'; \
+ fi; \
+ dot_seen=no; \
+ target=`echo $@ | sed s/-recursive//`; \
+ case "$@" in \
+ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+ *) list='$(SUBDIRS)' ;; \
+ esac; \
+ for subdir in $$list; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+ fi; test -z "$$fail"
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-recursive
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+ include_option=--etags-include; \
+ empty_fix=.; \
+ else \
+ include_option=--include; \
+ empty_fix=; \
+ fi; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test ! -f $$subdir/TAGS || \
+ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+ fi; \
+ done; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-recursive
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-recursive
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+ @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ $(am__make_dryrun) \
+ || test -d "$(distdir)/$$subdir" \
+ || $(MKDIR_P) "$(distdir)/$$subdir" \
+ || exit 1; \
+ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+ $(am__relativize); \
+ new_distdir=$$reldir; \
+ dir1=$$subdir; dir2="$(top_distdir)"; \
+ $(am__relativize); \
+ new_top_distdir=$$reldir; \
+ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+ ($(am__cd) $$subdir && \
+ $(MAKE) $(AM_MAKEFLAGS) \
+ top_distdir="$$new_top_distdir" \
+ distdir="$$new_distdir" \
+ am__remove_distdir=: \
+ am__skip_length_check=: \
+ am__skip_mode_fix=: \
+ distdir) \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES)
+installdirs: installdirs-recursive
+installdirs-am:
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-recursive
+ -rm -f ./$(DEPDIR)/libyangtest_la-translator_test.Plo
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+ -rm -f ./$(DEPDIR)/libyangtest_la-translator_test.Plo
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: $(am__recursive_targets) install-am install-strip
+
+.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \
+ am--depfiles check check-am clean clean-generic clean-libtool \
+ clean-noinstLTLIBRARIES cscopelist-am ctags ctags-am distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ installdirs-am maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+ uninstall-am
+
+.PRECIOUS: Makefile
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/lib/yang/testutils/translator_test.cc b/src/lib/yang/testutils/translator_test.cc
new file mode 100644
index 0000000..16fa33b
--- /dev/null
+++ b/src/lib/yang/testutils/translator_test.cc
@@ -0,0 +1,421 @@
+// Copyright (C) 2018-2019,2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/testutils/translator_test.h>
+
+#include <boost/lexical_cast.hpp>
+
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+namespace isc {
+namespace yang {
+namespace test {
+
+YangRepr::YangReprItem
+YangRepr::YangReprItem::get(const string& xpath, S_Session session) {
+ string val_xpath = xpath;
+ string value = "";
+ sr_type_t type = SR_UNKNOWN_T;
+ bool settable = true;
+ try {
+ S_Val s_val = session->get_item(xpath.c_str());
+ 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:
+ 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) {
+ isc_throw(SysrepoError,
+ "sysrepo error in YangReprItem: " << ex.what());
+ }
+ return (YangReprItem(val_xpath, value, type, settable));
+}
+
+YangRepr::Tree
+YangRepr::get(S_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());
+ result.emplace(xpath, YangReprItem::get(xpath, session));
+ });
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error in YangRepr::getTree: " << ex.what());
+ }
+ return (result);
+}
+
+bool
+YangRepr::verify(const Tree& expected, S_Session session,
+ ostream& errs) const {
+ bool result(true);
+ const Tree& received = get(session);
+ for (auto const& kv : received) {
+ string const& xpath(kv.first);
+ YangReprItem const& received_node(kv.second);
+
+ auto iterator(expected.find(xpath));
+ if (iterator == expected.end()) {
+ errs << "received " << received_node << ", but was not expected"
+ << endl;
+ result = false;
+ continue;
+ }
+
+ YangReprItem const expected_node(iterator->second);
+ if (expected_node != received_node) {
+ errs << "expected " << expected_node << ", but received "
+ << received_node << endl;
+ result = false;
+ }
+ }
+
+ for (auto const& kv : expected) {
+ string const& xpath(kv.first);
+ YangReprItem const& expected_node(kv.second);
+
+ auto iterator(received.find(xpath));
+ if (iterator == received.end()) {
+ errs << "expected " << expected_node << ", but was not received"
+ << endl;
+ result = false;
+ }
+ }
+
+ return result;
+}
+
+void
+YangRepr::set(const Tree& tree, S_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_);
+ }
+ session->set_item(item.xpath_.c_str(), s_val);
+ } catch (const sysrepo_exception& 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);
+}
+
+ostream&
+operator<<(ostream& os, sr_type_t 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:
+ os << "string";
+ break;
+ case SR_BOOL_T:
+ os << "bool";
+ break;
+ case SR_UINT8_T:
+ os << "uint8";
+ break;
+ case SR_UINT16_T:
+ os << "uint16";
+ break;
+ case SR_UINT32_T:
+ os << "uint32";
+ break;
+ case SR_INT8_T:
+ os << "int8";
+ break;
+ case SR_INT16_T:
+ os << "int16";
+ break;
+ case SR_INT32_T:
+ os << "int32";
+ break;
+ case SR_IDENTITYREF_T:
+ os << "identity ref";
+ break;
+ case SR_ENUM_T:
+ os << "enum";
+ break;
+ case SR_BINARY_T:
+ os << "binary";
+ break;
+ case SR_LEAF_EMPTY_T:
+ os << "leaf empty";
+ break;
+ case SR_BITS_T:
+ os << "bits";
+ break;
+ case SR_DECIMAL64_T:
+ os << "decimal64";
+ break;
+ case SR_INSTANCEID_T:
+ os << "instance id";
+ break;
+ case SR_INT64_T:
+ os << "int64";
+ break;
+ case SR_UINT64_T:
+ os << "uint64";
+ break;
+ case SR_ANYXML_T:
+ os << "any xml";
+ break;
+ case SR_ANYDATA_T:
+ os << "any data";
+ break;
+#ifdef SR_UNION_T
+ case SR_UNION_T:
+ os << "union";
+ break;
+#endif
+ default:
+ os << type;
+ break;
+ }
+ return (os);
+}
+
+ostream& operator<<(ostream& os, const YangRepr::YangReprItem& item) {
+ os << item.xpath_ << " = (" << item.type_ << ") '" << item.value_ << "'";
+ return (os);
+}
+
+ostream& operator<<(ostream& os, const YangRepr::Tree& tree) {
+ for (auto const& kv : tree) {
+ YangRepr::YangReprItem const& item(kv.second);
+ os << item << endl;
+ }
+ return (os);
+}
+
+} // namespace test
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/testutils/translator_test.h b/src/lib/yang/testutils/translator_test.h
new file mode 100644
index 0000000..b334fbd
--- /dev/null
+++ b/src/lib/yang/testutils/translator_test.h
@@ -0,0 +1,159 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_TEST_H
+#define ISC_TRANSLATOR_TEST_H 1
+
+#include <yang/translator.h>
+#include <vector>
+#include <iostream>
+#include <unordered_map>
+
+namespace isc {
+namespace yang {
+namespace test {
+
+/// @brief Yang/sysrepo datastore textual representation class.
+///
+/// This class allows to store a configuration tree in YANG format.
+/// It is used in tests to conduct operations on whole configurations.
+class YangRepr {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param model The model name.
+ YangRepr(const std::string& model) : model_(model) {
+ }
+
+ /// @brief A struct representing a single entry.
+ struct YangReprItem {
+ /// @brief Constructor with content.
+ ///
+ /// @param xpath The xpath.
+ /// @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)
+ : xpath_(xpath), value_(value), type_(type), settable_(settable) {
+ }
+
+ /// @brief Retrieves configuration parameter from sysrepo.
+ ///
+ /// @param xpath The xpath of an element to be retrieved.
+ /// @param session Sysrepo session.
+ /// @return YangReprItem instance representing configuration parameter.
+ static YangReprItem get(const std::string& xpath,
+ sysrepo::S_Session session);
+
+ /// @brief The xpath.
+ std::string xpath_;
+
+ /// @brief The textual value.
+ std::string value_;
+
+ /// @brief The type of the value.
+ sr_type_t type_;
+
+ /// @brief The settable flag.
+ bool settable_;
+
+ /// @brief The equal operator ignoring settable.
+ ///
+ /// @param other the other object to compare with.
+ /// @return true if equal.
+ bool operator==(const YangReprItem& other) const {
+ return ((xpath_ == other.xpath_) &&
+ (value_ == other.value_) &&
+ (type_ == other.type_));
+ }
+
+ /// @brief The unequal operator ignoring settable.
+ ///
+ /// @param other the other object to compare with.
+ /// @return false if equal.
+ bool operator!=(const YangReprItem& other) const {
+ return (!(*this == other));
+ }
+ };
+
+ /// @brief Tree type.
+ ///
+ /// Indexed by xpath so that we can check against an entry received from
+ /// sysrepo which has empirically proven to not come in a certain order
+ /// starting with sysrepo 1.x. Relying on the order would have made a linear
+ /// data structure more fitting.
+ using Tree = std::unordered_map<std::string, YangReprItem>;
+
+ /// @brief Get tree from session.
+ ///
+ /// @param session Sysrepo session.
+ Tree get(sysrepo::S_Session session) const;
+
+ /// @brief Verifies a tree.
+ ///
+ /// @param expected The expected value.
+ /// @param session Sysrepo session.
+ /// @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,
+ std::ostream& errs) const;
+
+ /// @brief Sets specified tree in a sysrepo.
+ ///
+ /// The actual access parameters are specified within session.
+ ///
+ /// @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;
+
+ /// @brief Convenience function that indexes a collection of items by xpath.
+ ///
+ /// @param v the input vector
+ ///
+ /// @return the output map
+ static Tree buildTreeFromVector(std::vector<YangReprItem> const& v) {
+ Tree tree;
+ for (YangReprItem const& item : v) {
+ tree.emplace(item.xpath_, item);
+ }
+ return tree;
+ }
+
+ /// @brief The model name.
+ std::string model_;
+};
+
+/// @brief Alias for Items.
+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 @c YangReprItem object.
+std::ostream& operator<<(std::ostream& os, const YRItem& item);
+
+/// @brief Overrides standard output operator for @c Tree object.
+std::ostream& operator<<(std::ostream& os, const YRTree& tree);
+
+} // namespace test
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_TEST_H
diff --git a/src/lib/yang/translator.cc b/src/lib/yang/translator.cc
new file mode 100644
index 0000000..9e38cfa
--- /dev/null
+++ b/src/lib/yang/translator.cc
@@ -0,0 +1,318 @@
+// Copyright (C) 2018-2019,2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator.h>
+#include <util/encode/base64.h>
+#include <cstring>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::util::encode;
+using namespace sysrepo;
+
+namespace {
+
+string encode64(const string& input) {
+ vector<uint8_t> binary;
+ binary.resize(input.size());
+ memmove(&binary[0], input.c_str(), binary.size());
+ return (encodeBase64(binary));
+}
+
+string decode64(const string& input) {
+ vector<uint8_t> binary;
+ decodeBase64(input, binary);
+ string result;
+ result.resize(binary.size());
+ memmove(&result[0], &binary[0], result.size());
+ return (result);
+}
+
+} // end of anonymous namespace
+
+namespace isc {
+namespace yang {
+
+TranslatorBasic::TranslatorBasic(S_Session session, const string& model)
+ : session_(session), model_(model) {
+}
+
+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());
+ }
+}
+
+ElementPtr
+TranslatorBasic::getItem(const string& xpath) {
+ S_Val s_val;
+ 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;
+ }
+ 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());
+ }
+ 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());
+ }
+ 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;
+
+ 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;
+
+ 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;
+
+ case SR_BINARY_T:
+ if (elem->getType() != Element::string) {
+ isc_throw(BadValue,
+ "value for a base64 called with not a string: "
+ << elem->str());
+ }
+ s_val.reset(new Val(encode64(elem->stringValue()).c_str(), type));
+ break;
+
+ default:
+ isc_throw(NotImplemented,
+ "value called with unsupported type: " << type);
+ }
+
+ return (s_val);
+}
+
+void
+TranslatorBasic::setItem(const string& xpath, ConstElementPtr elem,
+ sr_type_t type) {
+ S_Val s_val = value(elem, type);
+ try {
+ session_->set_item(xpath.c_str(), s_val);
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting item '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+ session_->apply_changes();
+}
+
+void
+TranslatorBasic::checkAndGetLeaf(ElementPtr& storage,
+ const std::string& xpath,
+ const std::string& name) {
+ ConstElementPtr x = getItem(xpath + "/" + name);
+ if (x) {
+ storage->set(name, x);
+ }
+}
+
+void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from,
+ string const& xpath,
+ string const& name,
+ sr_type_t const type) {
+ ConstElementPtr const& x(from->get(name));
+ if (x) {
+ setItem(xpath + "/" + name, x, type);
+ }
+}
+
+void
+TranslatorBasic::delItem(const std::string& xpath) {
+ 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;
+ }
+ 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());
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator.h b/src/lib/yang/translator.h
new file mode 100644
index 0000000..838e2d6
--- /dev/null
+++ b/src/lib/yang/translator.h
@@ -0,0 +1,177 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_H
+#define ISC_TRANSLATOR_H 1
+
+#include <cc/data.h>
+#include <yang/sysrepo_error.h>
+
+#include <sysrepo-cpp/Session.hpp>
+
+namespace isc {
+namespace yang {
+
+/// @brief Between YANG and JSON translator class for basic values.
+class TranslatorBasic {
+public:
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name (used and shared by derived classes).
+ TranslatorBasic(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorBasic();
+
+ /// @brief Translate basic value from YANG to JSON.
+ ///
+ /// @note Please don't use this outside tests.
+ ///
+ /// @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);
+
+ /// @brief Get and translate basic value from YANG to JSON.
+ ///
+ /// @note Should be const as it is read only...
+ ///
+ /// @param xpath The xpath of the basic value.
+ /// @return The Element representing the item at xpath or null
+ /// when not found.
+ /// @throw SysrepoError when sysrepo raises an error.
+ /// @throw NotImplemented when the value type is not supported.
+ isc::data::ElementPtr getItem(const std::string& xpath);
+
+ /// @brief Get and translate a list of basic values from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the list of basic values.
+ /// @return The ListElement representing the leaf-list at xpath or
+ /// null when not found.
+ isc::data::ElementPtr getItems(const std::string& xpath);
+
+ /// @brief Retrieves an item and stores it in the specified storage.
+ ///
+ /// This will attempt to retrieve an item and, if exists, will
+ /// store it in the storage.
+ ///
+ /// @param storage ElementMap where result will be stored
+ /// @param xpath xpath location of data that will be extracted from sysrepo
+ /// @param name name of the parameter
+ void checkAndGetLeaf(isc::data::ElementPtr& storage,
+ 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);
+
+ /// @brief Translate and set basic value from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the basic value.
+ /// @param elem The JSON element.
+ /// @param type The sysrepo type.
+ void setItem(const std::string& xpath, isc::data::ConstElementPtr elem,
+ sr_type_t type);
+
+
+ /// @brief Get an element from given ElementPtr node and set it in sysrepo
+ /// at given xpath.
+ ///
+ /// @param from the parent configuration node from which to take the value
+ /// @param xpath the xpath to the YANG node without the last node
+ /// @param name the name of the YANG node which should also match the map
+ /// key in the JSON configuration
+ /// @param type the sysrepo node type
+ void checkAndSetLeaf(isc::data::ConstElementPtr const& from,
+ std::string const& xpath,
+ std::string const& name,
+ sr_type_t const type);
+
+
+ /// @brief Delete basic value from YANG.
+ ///
+ /// @param xpath The xpath of the basic value.
+ void delItem(const std::string& xpath);
+
+ /// @brief Run a function for a node and all its children.
+ ///
+ /// @tparam functor_t typename of the function to be called
+ ///
+ /// @param xpath the xpath to be travelled
+ /// @param f the function to be called on the node itself and each
+ /// 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()));
+ if (!data_node) {
+ return;
+ }
+
+ for (libyang::S_Data_Node& root : data_node->tree_for()) {
+ for (libyang::S_Data_Node const& n : root->tree_dfs()) {
+ f(n);
+ }
+ }
+ }
+
+ /// @brief Retrieve a list as ElementPtr from sysrepo from a certain xpath.
+ ///
+ /// @tparam T typename of the translator that holds the function that will
+ /// be called on the xpath of each child from the list
+ ///
+ /// @param xpath the xpath to the element to be retrieved from, usually a
+ /// list
+ /// @param t address of a translator instance that holds the function that
+ /// will be called on the xpath of each child from the list
+ /// @param f the function that will be called on the xpath of each child
+ /// from the list
+ template <typename T>
+ 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);
+ }
+ }
+ }
+ return result;
+ }
+
+protected:
+ /// @brief The sysrepo session.
+ sysrepo::S_Session session_;
+
+ /// @brief The model.
+ std::string model_;
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_H
diff --git a/src/lib/yang/translator_class.cc b/src/lib/yang/translator_class.cc
new file mode 100644
index 0000000..0bfddf3
--- /dev/null
+++ b/src/lib/yang/translator_class.cc
@@ -0,0 +1,245 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_class.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorClass::TranslatorClass(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorOptionDef(session, model),
+ TranslatorOptionDefList(session, model) {
+}
+
+TranslatorClass::~TranslatorClass() {
+}
+
+ElementPtr
+TranslatorClass::getClass(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getClassKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting client class at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getClass not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorClass::getClassKea(const string& xpath) {
+ ConstElementPtr name = getItem(xpath + "/name");
+ if (!name) {
+ // Can't happen as the name is the key.
+ isc_throw(Unexpected, "getClassKea requires name: " << xpath);
+ }
+ ElementPtr result = Element::createMap();
+ result->set("name", name);
+ ConstElementPtr test = getItem(xpath + "/test");
+ if (test) {
+ result->set("test", test);
+ }
+ ConstElementPtr required = getItem(xpath + "/only-if-required");
+ if (required) {
+ result->set("only-if-required", required);
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("option-data", options);
+ }
+ checkAndGetLeaf(result, xpath, "valid-lifetime");
+ checkAndGetLeaf(result, xpath, "min-valid-lifetime");
+ checkAndGetLeaf(result, xpath, "max-valid-lifetime");
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr defs = getOptionDefList(xpath);
+ if (defs && (defs->size() > 0)) {
+ result->set("option-def", defs);
+ }
+ ConstElementPtr next = getItem(xpath + "/next-server");
+ if (next) {
+ result->set("next-server", next);
+ }
+ ConstElementPtr hostname = getItem(xpath + "/server-hostname");
+ if (hostname) {
+ result->set("server-hostname", hostname);
+ }
+ ConstElementPtr boot = getItem(xpath + "/boot-file-name");
+ if (boot) {
+ result->set("boot-file-name", boot);
+ }
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ checkAndGetLeaf(result, xpath, "preferred-lifetime");
+ checkAndGetLeaf(result, xpath, "min-preferred-lifetime");
+ checkAndGetLeaf(result, xpath, "max-preferred-lifetime");
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorClass::setClass(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setClassKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setClass not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting client class '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorClass::setClassKea(const string& xpath, ConstElementPtr elem) {
+ bool created = false;
+ // Skip key name.
+ ConstElementPtr test = elem->get("test");
+ if (test) {
+ setItem(xpath + "/test", test, SR_STRING_T);
+ created = true;
+ }
+ ConstElementPtr required = elem->get("only-if-required");
+ if (required) {
+ setItem(xpath + "/only-if-required", required, SR_BOOL_T);
+ created = true;
+ }
+ 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);
+ 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;
+ }
+ ConstElementPtr hostname = elem->get("server-hostname");
+ if (hostname) {
+ setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
+ created = true;
+ }
+ ConstElementPtr boot = elem->get("boot-file-name");
+ if (boot) {
+ setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ created = true;
+ }
+ } 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);
+ }
+ 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);
+ }
+}
+
+TranslatorClasses::TranslatorClasses(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorOptionDef(session, model),
+ TranslatorOptionDefList(session, model),
+ TranslatorClass(session, model) {
+}
+
+TranslatorClasses::~TranslatorClasses() {
+}
+
+ConstElementPtr
+TranslatorClasses::getClasses(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getClassesKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting client classes at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getClasses not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorClasses::getClassesKea(const string& xpath) {
+ return getList<TranslatorClass>(xpath + "/client-class", *this,
+ &TranslatorClass::getClass);
+}
+
+void
+TranslatorClasses::setClasses(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setClassesKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setClasses not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting client classes '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorClasses::setClassesKea(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr cclass = elem->get(i);
+ if (!cclass->contains("name")) {
+ isc_throw(BadValue, "client class without name: " << elem->str());
+ }
+ string name = cclass->get("name")->stringValue();
+ ostringstream key;
+ key << xpath << "/client-class[name='" << name << "']";
+ setClass(key.str(), cclass);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_class.h b/src/lib/yang/translator_class.h
new file mode 100644
index 0000000..ca2f9cb
--- /dev/null
+++ b/src/lib/yang/translator_class.h
@@ -0,0 +1,169 @@
+// Copyright (C) 2018,2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_CLASS_H
+#define ISC_TRANSLATOR_CLASS_H 1
+
+#include <yang/translator_option_data.h>
+#include <yang/translator_option_def.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Client class translation between YANG and JSON
+///
+/// JSON syntax for all Kea servers with client class is:
+/// @code
+/// {
+/// "name": <name>,
+/// "test": <test expression>,
+/// "only-if-required": <only if required flag>,
+/// "option-data": <option data list>,
+/// (DHCPv4 only)
+/// "option-def": <option definition list>,
+/// "next-server": <next server address>,
+/// "server-hostname": <server hostname>,
+/// "boot-file-name": <boot filename>,
+/// "user-context": { <json map> },
+/// "comment": <comment>
+/// }
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46] is with the name as the list key:
+/// @code
+/// +--rw client-class* [name]
+/// +--rw name string
+/// +--rw test? string
+/// +--rw only-if-required? boolean
+/// +--rw option-def* [code space]
+/// +--rw option-data* [code space]
+/// +--rw next-server? inet:ipv4-address
+/// +--rw server-hostname? string
+/// +--rw boot-file-name? string
+/// +--rw valid-lifetime? uint32
+/// +--rw min-valid-lifetime? uint32
+/// +--rw max-valid-lifetime? uint32
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "name": "foo",
+/// "test": "''==''",
+/// "only-if-required": false
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/client-class[name='foo'] (list instance)
+/// /kea-dhcp6-server:config/client-class[name='foo']/name = foo
+/// /kea-dhcp6-server:config/client-class[name='foo']/test = ''==''
+/// /kea-dhcp6-server:config/client-class[name='foo']/only-if-required = false
+/// @endcode
+
+/// @brief A translator class for converting a client class between
+/// YANG and JSON.
+///
+/// Currently supports only kea-dhcp[46]-server. Ietf-dhcpv6-server does
+/// not define client class contents.
+class TranslatorClass : virtual public TranslatorOptionDataList,
+ virtual public TranslatorOptionDefList {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorClass(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorClass();
+
+ /// @brief Get and translate a client class from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the class .
+ /// @return JSON representation of the class .
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getClass(const std::string& xpath);
+
+ /// @brief Translate and set client class from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the client class.
+ /// @param elem The JSON element.
+ void setClass(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getClass JSON for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the class .
+ /// @return JSON representation of the class .
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getClassKea(const std::string& xpath);
+
+ /// @brief setClass for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the client class.
+ /// @param elem The JSON element.
+ void setClassKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting a client class list between
+/// YANG and JSON.
+///
+/// Currently supports only kea-dhcp[46]-server. Ietf-dhcpv6-server does
+/// not define client class contents.
+class TranslatorClasses : virtual public TranslatorClass {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorClasses(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorClasses();
+
+ /// @brief Get and translate client classes from YANG to JSON.
+ ///
+ /// @param xpath The xpath of classes.
+ /// @return JSON representation of classes.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getClasses(const std::string& xpath);
+
+ /// @brief Translate and set client classes from JSON to YANG.
+ ///
+ /// @param xpath The xpath of classes.
+ /// @param elem The JSON element.
+ void setClasses(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getClasses JSON for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of classes.
+ /// @return JSON representation of classes.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getClassesKea(const std::string& xpath);
+
+ /// @brief setClasses for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of classes.
+ /// @param elem The JSON element.
+ /// @throw BadValue on client class without name.
+ void setClassesKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_CLASS_H
diff --git a/src/lib/yang/translator_config.cc b/src/lib/yang/translator_config.cc
new file mode 100644
index 0000000..fcb6054
--- /dev/null
+++ b/src/lib/yang/translator_config.cc
@@ -0,0 +1,770 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_config.h>
+#include <yang/adaptor_config.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorConfig::TranslatorConfig(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorControlSocket(session, model),
+ TranslatorDatabase(session, model),
+ TranslatorDatabases(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorOptionDef(session, model),
+ TranslatorOptionDefList(session, model),
+ TranslatorClass(session, model),
+ TranslatorClasses(session, model),
+ TranslatorPool(session, model),
+ TranslatorPools(session, model),
+ TranslatorPdPool(session, model),
+ TranslatorPdPools(session, model),
+ TranslatorHost(session, model),
+ TranslatorHosts(session, model),
+ TranslatorSubnet(session, model),
+ TranslatorSubnets(session, model),
+ TranslatorSharedNetwork(session, model),
+ TranslatorSharedNetworks(session, model),
+ TranslatorLogger(session, model),
+ TranslatorLoggers(session, model) {
+}
+
+TranslatorConfig::~TranslatorConfig() {
+}
+
+ElementPtr
+TranslatorConfig::getConfig() {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ return (getConfigIetf6());
+ } else if (model_ == KEA_DHCP4_SERVER) {
+ return (getConfigKea4());
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ return (getConfigKea6());
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError, "sysrepo error getting config: " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getConfig not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorConfig::getConfigIetf6() {
+ ElementPtr result = Element::createMap();
+ ElementPtr dhcp6 = Element::createMap();
+ result->set("Dhcp6", dhcp6);
+ string xpath = "/" + model_ + ":server/server-config";
+ ConstElementPtr ranges =
+ getSubnets(xpath + "/network-ranges");
+ if (ranges && !ranges->empty()) {
+ dhcp6->set("subnet6", ranges);
+ }
+ // Skip everything else.
+ return (result);
+}
+
+ElementPtr
+TranslatorConfig::getConfigKea4() {
+ ElementPtr result = Element::createMap();
+ ElementPtr dhcp = getServerKeaDhcp4();
+ result->set("Dhcp4", dhcp);
+ return (result);
+}
+
+ElementPtr
+TranslatorConfig::getConfigKea6() {
+ ElementPtr result = Element::createMap();
+ ElementPtr dhcp = getServerKeaDhcp6();
+ result->set("Dhcp6", dhcp);
+ return (result);
+}
+
+ElementPtr TranslatorConfig::getHook(string const& xpath) {
+ ElementPtr const& hook_library(Element::createMap());
+ ElementPtr const& name(getItem(xpath + "/library"));
+ if (name) {
+ hook_library->set("library", name);
+ ElementPtr const& parameters(getItem(xpath + "/parameters"));
+ if (parameters) {
+ hook_library->set("parameters",
+ Element::fromJSON(parameters->stringValue()));
+ }
+ }
+ return hook_library;
+}
+
+ElementPtr
+TranslatorConfig::getHooksKea(const std::string& xpath) {
+ return getList(xpath + "/hook-library", *this, &TranslatorConfig::getHook);
+}
+
+isc::data::ElementPtr
+TranslatorConfig::getExpiredKea(const std::string& xpath) {
+ ElementPtr expired = Element::createMap();
+
+ checkAndGetLeaf(expired, xpath, "reclaim-timer-wait-time");
+ checkAndGetLeaf(expired, xpath, "flush-reclaimed-timer-wait-time");
+ checkAndGetLeaf(expired, xpath, "hold-reclaimed-time");
+ checkAndGetLeaf(expired, xpath, "max-reclaim-leases");
+ checkAndGetLeaf(expired, xpath, "max-reclaim-time");
+ checkAndGetLeaf(expired, xpath, "unwarned-reclaim-cycles");
+
+ if (!expired->empty()) {
+ return (expired);
+ }
+
+ return (ElementPtr());
+}
+
+isc::data::ElementPtr
+TranslatorConfig::getDdnsKea(const std::string& xpath) {
+ ElementPtr ddns = Element::createMap();
+ checkAndGetLeaf(ddns, xpath, "enable-updates");
+ checkAndGetLeaf(ddns, xpath, "qualifying-suffix");
+ checkAndGetLeaf(ddns, xpath, "server-ip");
+ checkAndGetLeaf(ddns, xpath, "server-port");
+ checkAndGetLeaf(ddns, xpath, "sender-ip");
+ checkAndGetLeaf(ddns, xpath, "sender-port");
+ checkAndGetLeaf(ddns, xpath, "max-queue-size");
+ checkAndGetLeaf(ddns, xpath, "ncr-protocol");
+ checkAndGetLeaf(ddns, xpath, "ncr-format");
+ checkAndGetLeaf(ddns, xpath, "override-no-update");
+ checkAndGetLeaf(ddns, xpath, "override-client-update");
+ checkAndGetLeaf(ddns, xpath, "replace-client-name");
+ checkAndGetLeaf(ddns, xpath, "generated-prefix");
+ checkAndGetLeaf(ddns, xpath, "hostname-char-set");
+ checkAndGetLeaf(ddns, xpath, "hostname-char-replacement");
+
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ ddns->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+
+ if (!ddns->empty()) {
+ // If there's something to return, use it.
+ return (ddns);
+ }
+
+ // If not, return null.
+ return (ElementPtr());
+}
+
+ElementPtr
+TranslatorConfig::getConfigControlKea(const string& xpath) {
+ ElementPtr config_ctrl = Element::createMap();
+ checkAndGetLeaf(config_ctrl, xpath, "config-fetch-wait-time");
+ ConstElementPtr databases = getDatabases(xpath + "/config-database");
+ if (databases && !databases->empty()) {
+ config_ctrl->set("config-databases", databases);
+ }
+ if (!config_ctrl->empty()) {
+ // If there's something to return, use it.
+ return (config_ctrl);
+ }
+
+ // If not, return null.
+ return (ElementPtr());
+}
+
+ElementPtr
+TranslatorConfig::getServerKeaDhcpCommon(const string& xpath) {
+ ElementPtr result = Element::createMap();
+
+ checkAndGetLeaf(result, xpath, "valid-lifetime");
+ checkAndGetLeaf(result, xpath, "min-valid-lifetime");
+ checkAndGetLeaf(result, xpath, "max-valid-lifetime");
+ checkAndGetLeaf(result, xpath, "renew-timer");
+ checkAndGetLeaf(result, xpath, "rebind-timer");
+ checkAndGetLeaf(result, xpath, "calculate-tee-times");
+ checkAndGetLeaf(result, xpath, "t1-percent");
+ checkAndGetLeaf(result, xpath, "t2-percent");
+ checkAndGetLeaf(result, xpath, "decline-probation-period");
+ checkAndGetLeaf(result, xpath, "hostname-char-set");
+ checkAndGetLeaf(result, xpath, "hostname-char-replacement");
+
+ ConstElementPtr networks = getSharedNetworks(xpath);
+ if (networks && !networks->empty()) {
+ result->set("shared-networks", networks);
+ }
+ ConstElementPtr classes = getClasses(xpath);
+ if (classes && !classes->empty()) {
+ result->set("client-classes", classes);
+ }
+ ConstElementPtr database = getDatabase(xpath + "/lease-database");
+ if (database) {
+ result->set("lease-database", database);
+ }
+ ConstElementPtr databases = getDatabases(xpath + "/hosts-database");
+ if (databases && !databases->empty()) {
+ result->set("hosts-databases", databases);
+ }
+ ConstElementPtr host_ids =
+ getItems(xpath + "/host-reservation-identifiers");
+ if (host_ids) {
+ result->set("host-reservation-identifiers", host_ids);
+ }
+ ConstElementPtr defs = getOptionDefList(xpath);
+ if (defs && !defs->empty()) {
+ result->set("option-def", defs);
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && !options->empty()) {
+ result->set("option-data", options);
+ }
+ ConstElementPtr hooks = getHooksKea(xpath);
+ if (hooks && !hooks->empty()) {
+ result->set("hooks-libraries", hooks);
+ }
+ ConstElementPtr expired =
+ getExpiredKea(xpath + "/expired-leases-processing");
+ if (expired) {
+ result->set("expired-leases-processing", expired);
+ }
+ checkAndGetLeaf(result, xpath, "dhcp4o6-port");
+ ConstElementPtr socket = getControlSocket(xpath + "/control-socket");
+ if (socket) {
+ result->set("control-socket", socket);
+ }
+ ConstElementPtr ddns = getDdnsKea(xpath + "/dhcp-ddns");
+ if (ddns) {
+ result->set("dhcp-ddns", ddns);
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ ConstElementPtr checks = getItem(xpath + "/sanity-checks/lease-checks");
+ if (checks) {
+ ElementPtr sanity = Element::createMap();
+ sanity->set("lease-checks", checks);
+ result->set("sanity-checks", sanity);
+ }
+ checkAndGetLeaf(result, xpath, "reservation-mode");
+ ConstElementPtr hosts = getHosts(xpath);
+ if (hosts && !hosts->empty()) {
+ result->set("reservations", hosts);
+ }
+ ConstElementPtr config_ctrl =
+ getConfigControlKea(xpath + "/config-control");
+ if (config_ctrl) {
+ result->set("config-control", config_ctrl);
+ }
+ checkAndGetLeaf(result, xpath, "server-tag");
+ ConstElementPtr queue_ctrl = getItem(xpath + "/dhcp-queue-control");
+ if (queue_ctrl) {
+ result->set("dhcp-queue-control",
+ Element::fromJSON(queue_ctrl->stringValue()));
+ }
+ ConstElementPtr loggers = getLoggers(xpath);
+ if (loggers && !loggers->empty()) {
+ result->set("loggers", loggers);
+ }
+ checkAndGetLeaf(result, xpath, "cache-max-age");
+ checkAndGetLeaf(result, xpath, "cache-threshold");
+ ElementPtr compatibility = Element::createMap();
+ checkAndGetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing");
+ if (!compatibility->empty()) {
+ result->set("compatibility", compatibility);
+ }
+ checkAndGetLeaf(result, xpath, "ddns-generated-prefix");
+ checkAndGetLeaf(result, xpath, "ddns-override-client-update");
+ checkAndGetLeaf(result, xpath, "ddns-override-no-update");
+ checkAndGetLeaf(result, xpath, "ddns-qualifying-suffix");
+ checkAndGetLeaf(result, xpath, "ddns-replace-client-name");
+ checkAndGetLeaf(result, xpath, "ddns-send-updates");
+ checkAndGetLeaf(result, xpath, "ddns-update-on-renew");
+ checkAndGetLeaf(result, xpath, "ddns-use-conflict-resolution");
+ checkAndGetLeaf(result, xpath, "ip-reservations-unique");
+ checkAndGetLeaf(result, xpath, "early-global-reservations-lookup");
+ checkAndGetLeaf(result, xpath, "reservations-lookup-first");
+ ElementPtr multi_threading = Element::createMap();
+ string mt_xpath = xpath + "/multi-threading";
+ checkAndGetLeaf(multi_threading, mt_xpath, "enable-multi-threading");
+ checkAndGetLeaf(multi_threading, mt_xpath, "packet-queue-size");
+ checkAndGetLeaf(multi_threading, mt_xpath, "thread-pool-size");
+ if (!multi_threading->empty()) {
+ result->set("multi-threading", multi_threading);
+ }
+ checkAndGetLeaf(result, xpath, "parked-packet-limit");
+ checkAndGetLeaf(result, xpath, "reservations-global");
+ checkAndGetLeaf(result, xpath, "reservations-in-subnet");
+ checkAndGetLeaf(result, xpath, "reservations-out-of-pool");
+ checkAndGetLeaf(result, xpath, "statistic-default-sample-age");
+ checkAndGetLeaf(result, xpath, "statistic-default-sample-count");
+ checkAndGetLeaf(result, xpath, "store-extended-info");
+ return (result);
+}
+
+ElementPtr
+TranslatorConfig::getServerKeaDhcp4() {
+ string xpath = "/kea-dhcp4-server:config";
+ ElementPtr result = getServerKeaDhcpCommon(xpath);
+ // Handle subnets.
+ ConstElementPtr subnets = getSubnets(xpath);
+ if (subnets && !subnets->empty()) {
+ result->set("subnet4", subnets);
+ }
+ // Handle interfaces.
+ ElementPtr if_config = Element::createMap();
+ ConstElementPtr ifs = getItems(xpath + "/interfaces-config/interfaces");
+ if (ifs && !ifs->empty()) {
+ if_config->set("interfaces", ifs);
+ }
+ string if_cfg_xpath = xpath + "/interfaces-config";
+ checkAndGetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "outbound-interface");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "re-detect");
+ ConstElementPtr context =
+ getItem(xpath + "/interfaces-config/user-context");
+ if (context) {
+ if_config->set("user-context",
+ Element::fromJSON(context->stringValue()));
+ }
+ if (!if_config->empty()) {
+ result->set("interfaces-config", if_config);
+ }
+ // Handle DHCPv4 specific global parameters.
+ checkAndGetLeaf(result, xpath, "echo-client-id");
+ checkAndGetLeaf(result, xpath, "match-client-id");
+ checkAndGetLeaf(result, xpath, "next-server");
+ checkAndGetLeaf(result, xpath, "server-hostname");
+ checkAndGetLeaf(result, xpath, "boot-file-name");
+ checkAndGetLeaf(result, xpath, "authoritative");
+ return (result);
+}
+
+ElementPtr
+TranslatorConfig::getServerKeaDhcp6() {
+ string xpath = "/kea-dhcp6-server:config";
+ ElementPtr result = getServerKeaDhcpCommon(xpath);
+ // Handle DHCPv6 specific global parameters.
+ checkAndGetLeaf(result, xpath, "data-directory");
+ checkAndGetLeaf(result, xpath, "preferred-lifetime");
+ checkAndGetLeaf(result, xpath, "min-preferred-lifetime");
+ checkAndGetLeaf(result, xpath, "max-preferred-lifetime");
+ // Handle subnets.
+ ConstElementPtr subnets = getSubnets(xpath);
+ if (subnets && !subnets->empty()) {
+ result->set("subnet6", subnets);
+ }
+ // Handle interfaces.
+ ElementPtr if_config = Element::createMap();
+ ConstElementPtr ifs = getItems(xpath + "/interfaces-config/interfaces");
+ if (ifs && !ifs->empty()) {
+ if_config->set("interfaces", ifs);
+ }
+ string if_cfg_xpath = xpath + "/interfaces-config";
+ checkAndGetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time");
+ checkAndGetLeaf(if_config, if_cfg_xpath, "re-detect");
+ ConstElementPtr context =
+ getItem(xpath + "/interfaces-config/user-context");
+ if (context) {
+ if_config->set("user-context",
+ Element::fromJSON(context->stringValue()));
+ }
+ if (!if_config->empty()) {
+ result->set("interfaces-config", if_config);
+ }
+ // Handle DHCPv6 specific global entries.
+ ConstElementPtr relay = getItems(xpath + "/relay-supplied-options");
+ if (relay) {
+ result->set("relay-supplied-options", relay);
+ }
+ ConstElementPtr macs = getItems(xpath + "/mac-sources");
+ if (macs) {
+ result->set("mac-sources", macs);
+ }
+ // Handle server-id.
+ // @todo: move to a DUID translator.
+ ElementPtr server_id = Element::createMap();
+ string srv_id_xpath = xpath + "/server-id";
+ checkAndGetLeaf(server_id, srv_id_xpath, "type");
+ checkAndGetLeaf(server_id, srv_id_xpath, "identifier");
+ checkAndGetLeaf(server_id, srv_id_xpath, "time");
+ checkAndGetLeaf(server_id, srv_id_xpath, "htype");
+ checkAndGetLeaf(server_id, srv_id_xpath, "enterprise-id");
+ checkAndGetLeaf(server_id, srv_id_xpath, "persist");
+ context = getItem(xpath + "/server-id/user-context");
+ if (context) {
+ server_id->set("user-context",
+ Element::fromJSON(context->stringValue()));
+ }
+ if (!server_id->empty()) {
+ result->set("server-id", server_id);
+ }
+ return (result);
+}
+
+void
+TranslatorConfig::setConfig(ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ if (elem) {
+ AdaptorConfig::preProcess6(elem);
+ setConfigIetf6(elem);
+ } else {
+ delConfigIetf6();
+ }
+ } else if (model_ == KEA_DHCP4_SERVER) {
+ if (elem) {
+ AdaptorConfig::preProcess4(elem);
+ setConfigKea4(elem);
+ } else {
+ delConfigKea();
+ }
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ if (elem) {
+ AdaptorConfig::preProcess6(elem);
+ setConfigKea6(elem);
+ } else {
+ delConfigKea();
+ }
+ } else {
+ isc_throw(NotImplemented,
+ "setConfig not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting config '" << elem->str()
+ << "': " << ex.what());
+ }
+}
+
+void
+TranslatorConfig::delConfigIetf6() {
+ delItem("/" + model_ + ":server");
+}
+
+void
+TranslatorConfig::setConfigIetf6(ConstElementPtr elem) {
+ string xpath = "/" + model_ + ":server/server-config";
+ ConstElementPtr dhcp6 = elem->get("Dhcp6");
+ if (!dhcp6) {
+ isc_throw(BadValue, "no Dhcp6 entry in " << elem->str());
+ }
+ ConstElementPtr ranges = dhcp6->get("subnet6");
+ if (ranges && !ranges->empty()) {
+ setSubnets(xpath + "/network-ranges", ranges);
+ }
+ // Skip everything else.
+}
+
+void
+TranslatorConfig::delConfigKea() {
+ delItem("/" + model_ + ":config");
+}
+
+void
+TranslatorConfig::setConfigKea4(ConstElementPtr elem) {
+ ConstElementPtr dhcp = elem->get("Dhcp4");
+ if (dhcp) {
+ setServerKeaDhcp4(dhcp);
+ }
+}
+
+void
+TranslatorConfig::setConfigKea6(ConstElementPtr elem) {
+ ConstElementPtr dhcp = elem->get("Dhcp6");
+ if (dhcp) {
+ setServerKeaDhcp6(dhcp);
+ }
+}
+
+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);
+ ConstElementPtr networks = elem->get("shared-networks");
+ if (networks) {
+ setSharedNetworks(xpath, networks);
+ }
+ ConstElementPtr classes = elem->get("client-classes");
+ if (classes && !classes->empty()) {
+ setClasses(xpath, classes);
+ }
+ ConstElementPtr database = elem->get("lease-database");
+ if (database) {
+ setDatabase(xpath + "/lease-database", database);
+ }
+ ConstElementPtr databases = elem->get("hosts-databases");
+ if (databases && !databases->empty()) {
+ setDatabases(xpath + "/hosts-database", databases);
+ } else {
+ // Reuse of database from lease-database.
+ database = elem->get("hosts-database");
+ if (database) {
+ ElementPtr list = Element::createList();
+ list->add(copy(database));
+ setDatabases(xpath + "/hosts-database", list);
+ }
+ }
+ 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);
+ }
+ }
+ ConstElementPtr defs = elem->get("option-def");
+ if (defs && !defs->empty()) {
+ setOptionDefList(xpath, defs);
+ }
+ ConstElementPtr options = elem->get("option-data");
+ if (options && !options->empty()) {
+ setOptionDataList(xpath, options);
+ }
+ ConstElementPtr hook_libs = elem->get("hooks-libraries");
+ if (hook_libs) {
+ for (ConstElementPtr lib : hook_libs->listValue()) {
+ ConstElementPtr name = lib->get("library");
+ if (!name) {
+ continue;
+ }
+ ostringstream hook_lib;
+ hook_lib << xpath << "/hook-library[library='"
+ << name->stringValue() << "']";
+ 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);
+ }
+ }
+ }
+ 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);
+ 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);
+ 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);
+ ConstElementPtr context = Adaptor::getContext(ddns);
+ if (context) {
+ ConstElementPtr repr = Element::create(context->str());
+ setItem(xpath + "/dhcp-ddns/user-context", repr, SR_STRING_T);
+ }
+ }
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ ConstElementPtr repr = Element::create(context->str());
+ setItem(xpath + "/user-context", repr, SR_STRING_T);
+ }
+ ConstElementPtr sanity = elem->get("sanity-checks");
+ if (sanity) {
+ checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", SR_ENUM_T);
+ }
+ checkAndSetLeaf(elem, xpath, "reservation-mode", SR_ENUM_T);
+ 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);
+ 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);
+ 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);
+ }
+ 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);
+ 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);
+ 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);
+}
+
+void
+TranslatorConfig::setServerKeaDhcp4(ConstElementPtr elem) {
+ string xpath = "/kea-dhcp4-server:config";
+ setServerKeaDhcpCommon(xpath, elem);
+ ConstElementPtr subnets = elem->get("subnet4");
+ if (subnets) {
+ setSubnets(xpath, subnets);
+ }
+ ConstElementPtr if_config = elem->get("interfaces-config");
+ if (if_config) {
+ ConstElementPtr ifs = if_config->get("interfaces");
+ if (ifs && !ifs->empty()) {
+ for (ConstElementPtr intf : ifs->listValue()) {
+ setItem(xpath + "/interfaces-config/interfaces",
+ intf, SR_STRING_T);
+ }
+ }
+ 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);
+ ConstElementPtr context = Adaptor::getContext(if_config);
+ if (context) {
+ setItem(xpath + "/interfaces-config/user-context",
+ Element::create(context->str()), SR_STRING_T);
+ }
+ }
+ 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);
+}
+
+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);
+ ConstElementPtr subnets = elem->get("subnet6");
+ if (subnets) {
+ setSubnets(xpath, subnets);
+ }
+ ConstElementPtr if_config = elem->get("interfaces-config");
+ if (if_config) {
+ ConstElementPtr ifs = if_config->get("interfaces");
+ if (ifs && !ifs->empty()) {
+ for (ConstElementPtr intf : ifs->listValue()) {
+ setItem(xpath + "/interfaces-config/interfaces",
+ intf, SR_STRING_T);
+ }
+ }
+ 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);
+ ConstElementPtr context = Adaptor::getContext(if_config);
+ if (context) {
+ setItem(xpath + "/interfaces-config/user-context",
+ Element::create(context->str()), SR_STRING_T);
+ }
+ }
+ ConstElementPtr relay = elem->get("relay-supplied-options");
+ if (relay) {
+ for (ConstElementPtr addr : relay->listValue()) {
+ setItem(xpath + "/relay-supplied-options", addr, SR_STRING_T);
+ }
+ }
+ ConstElementPtr macs = elem->get("mac-sources");
+ if (macs) {
+ for (ConstElementPtr source : macs->listValue()) {
+ setItem(xpath + "/mac-sources", source, SR_STRING_T);
+ }
+ }
+ 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);
+ ConstElementPtr context = Adaptor::getContext(server_id);
+ if (context) {
+ ConstElementPtr repr = Element::create(context->str());
+ setItem(xpath + "/server-id/user-context", repr, SR_STRING_T);
+ }
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_config.h b/src/lib/yang/translator_config.h
new file mode 100644
index 0000000..5a45c65
--- /dev/null
+++ b/src/lib/yang/translator_config.h
@@ -0,0 +1,548 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_CONFIG_H
+#define ISC_TRANSLATOR_CONFIG_H 1
+
+#include <yang/translator.h>
+#include <yang/translator_control_socket.h>
+#include <yang/translator_database.h>
+#include <yang/translator_class.h>
+#include <yang/translator_shared_network.h>
+#include <yang/translator_logger.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// @brief DHCP configuration translation between YANG and JSON
+///
+/// This translator supports kea-dhcp4-server, kea-dhcp6-server and
+/// partially ietf-dhcpv6-server.
+
+/// JSON syntax for kea-dhcp4 is:
+/// @code
+/// "Dhcp4": {
+/// "valid-lifetime": <valid lifetime>,
+/// "min-valid-lifetime": <minimum valid lifetime>,
+/// "max-valid-lifetime": <maximum valid lifetime>,
+/// "renew-timer": <renew timer>,
+/// "rebind-timer": <rebind timer>,
+/// "calculate-tee-times": <calculate T1/T2 times>,
+/// "t1-percent": <T1 percent>,
+/// "t2-percent": <T2 percent>,
+/// "decline-probation-period": <decline probation period>,
+/// "subnet4": [ <list of subnet4> ],
+/// <shared-networks>,
+/// "interfaces-config": {
+/// "interfaces" [ <list of interface names / specs> ],
+/// ...
+/// },
+/// <databases>,
+/// <host-reservation-identifiers>,
+/// <client-classes>,
+/// <option-def>,
+/// <option-data>,
+/// <hooks-libraries>,
+/// <expired-leases-processing>,
+/// <dhcp4o6-port>,
+/// <control-socket>,
+/// <hostname-char-set": <hostname character set>,
+/// <hostname-char-replacement": <hostname character replacement>,
+/// <dhcp-ddns>,
+/// "echo-client-id": <echo client id flag>,
+/// "match-client-id": <match client id flag>,
+/// "next-server": <next server address>,
+/// "server-hostname": <server hostname>,
+/// "boot-file-name": <boot file name>,
+/// "authoritative": <authoritative flag>,
+/// <user-context>,
+/// <comment>,
+/// "sanity-checks": { <sanity checks> },
+/// "reservation-mode": <host reservation mode>,
+/// "reservations": [ <list of host reservations> ],
+/// <config-control>,
+/// "server-tag": <server tag>,
+/// "dhcp-queue-control": { <DHCP queue control> },
+/// "loggers": [ <list of loggers> ]
+/// },
+/// @endcode
+///
+/// YANG syntax for kea-dhcp4-server:config is:
+/// @code
+/// +--rw valid-lifetime? uint32
+/// +--rw min-valid-lifetime? uint32
+/// +--rw max-valid-lifetime? uint32
+/// +--rw renew-timer? uint32
+/// +--rw rebind-timer? uint32
+/// +--rw calculate-tee-times? boolean
+/// +--rw t1-percent? decimal64
+/// +--rw t2-percent? decimal64
+/// +--rw decline-probation-period? uint32
+/// +--rw subnet4* [id]
+/// +--rw shared-network* [name]
+/// +--rw interfaces-config
+/// +--rw lease-database!
+/// +--rw hosts-database* [database-type]
+/// +--rw host-reservation-identifiers* host-identifier-type
+/// +--rw client-class* [name]
+/// +--rw option-def* [code space]
+/// +--rw option-data* [code space]
+/// +--rw hook-library* [library]
+/// +--rw expired-leases-processing
+/// +--rw dhcp4o6-port? uint16
+/// +--rw control-socket!
+/// +--rw hostname-char-set? string
+/// +--rw hostname-char-replacement? string
+/// +--rw dhcp-ddns
+/// +--rw echo-client-id? boolean
+/// +--rw match-client-id? boolean
+/// +--rw next-server? inet:ipv4-address
+/// +--rw server-hostname? string
+/// +--rw boot-file-name? string
+/// +--rw authoritative? boolean
+/// +--rw user-context? user-context
+/// +--rw sanity-checks
+/// +--rw reservation-mode? host-reservation-mode
+/// +--rw host* [identifier-type identifier]
+/// +--rw config-control
+/// +--rw server-tag? string
+/// +--rw dhcp-queue-control? string
+/// +--rw logger* [name]
+/// +--rw cache-max-age? uint32
+/// +--rw cache-threshold? decimal64
+/// +--rw compatibility
+/// +--rw ddns-generated-prefix? string
+/// +--rw ddns-override-client-update? boolean
+/// +--rw ddns-override-no-update? boolean
+/// +--rw ddns-qualifying-suffix? string
+/// +--rw ddns-replace-client-name? string
+/// +--rw ddns-send-updates? boolean
+/// +--rw ddns-update-on-renew? boolean
+/// +--rw ddns-use-conflict-resolution? boolean
+/// +--rw ip-reservations-unique? boolean
+/// +--rw early-global-reservations-lookup? boolean
+/// +--rw reservations-lookup-first? boolean
+/// +--rw multi-threading
+/// +--rw parked-packet-limit? uint32
+/// +--rw reservations-global? boolean
+/// +--rw reservations-in-subnet? boolean
+/// +--rw reservations-out-of-pool? boolean
+/// +--rw statistic-default-sample-age? uint32
+/// +--rw statistic-default-sample-count? uint32
+/// +--rw store-extended-info? boolean
+/// @endcode
+///
+/// Example of kea-dhcp6 simple configuration:
+/// @code
+/// {
+/// "Dhcp4": {
+/// "interfaces-config":
+/// {
+/// "interfaces": [ "eth1" ]
+/// },
+/// "control-socket": {
+/// "socket-type": "unix",
+/// "socket-name": "/tmp/kea4-sock"
+/// },
+/// "subnet4":
+/// [
+/// {
+/// "subnet": "10.0.35.0/24",
+/// "pools":
+/// [
+/// {
+/// "pool": "10.0.35.64/27"
+/// }
+/// ]
+/// }
+/// ]
+/// }
+/// }
+///
+/// @endcode
+///
+/// The same configuration wrote into YANG datastore using @c setConfig()
+/// with the kea-dhcp4-model and exported to XML format:
+/// @code
+/// <config xmlns="urn:ietf:params:xml:ns:yang:kea-dhcp4-server">
+/// <subnet4>
+/// <id>1</id>
+/// <pool>
+/// <start-address>10.0.35.64</start-address>
+/// <end-address>10.0.35.95</end-address>
+/// <prefix>10.0.35.64/27</prefix>
+/// </pool>
+/// <subnet>10.0.35.0/24</subnet>
+/// </subnet4>
+/// <interfaces-config>
+/// <interfaces>eth1</interfaces>
+/// </interfaces-config>
+/// <control-socket>
+/// <socket-name>/tmp/kea4-sock</socket-name>
+/// <socket-type>unix</socket-type>
+/// </control-socket>
+/// </config>
+/// @endcode
+
+/// JSON syntax for kea-dhcp6 is:
+/// @code
+/// "Dhcp6": {
+/// "data-directory": <data directory>,
+/// "preferred-lifetime": <preferred lifetime>,
+/// "min-preferred-lifetime": <minimum preferred lifetime>,
+/// "max-preferred-lifetime": <maximum preferred lifetime>,
+/// "valid-lifetime": <valid lifetime>,
+/// "min-valid-lifetime": <minimum valid lifetime>,
+/// "max-valid-lifetime": <maximum valid lifetime>,
+/// "renew-timer": <renew timer>,
+/// "rebind-timer": <rebind timer>,
+/// "calculate-tee-times": <calculate T1/T2 times>,
+/// "t1-percent": <T1 percent>,
+/// "t2-percent": <T2 percent>,
+/// "decline-probation-period": <decline probation period>,
+/// "subnet6": [ <list of subnet6> ],
+/// <shared-networks>,
+/// "interfaces-config": {
+/// "interfaces" [ <list of interface names / specs> ],
+/// ...
+/// },
+/// <databases>,
+/// <mac-sources>,
+/// <relay-supplied-options>,
+/// <host-reservation-identifiers>,
+/// <client-classes>,
+/// <option-def>,
+/// <option-data>,
+/// <hooks-libraries>,
+/// <expired-leases-processing>,
+/// <server-id>,
+/// <dhcp4o6-port>,
+/// <control-socket>,
+/// <hostname-char-set": <hostname character set>,
+/// <hostname-char-replacement": <hostname character replacement>,
+/// <dhcp-ddns>,
+/// <user-context>,
+/// <comment>
+/// "sanity-checks": { <sanity checks> },
+/// "reservation-mode": <host reservation mode>,
+/// "reservations": [ <list of host reservations> ],
+/// <config-control>,
+/// "server-tag": <server tag>,
+/// "dhcp-queue-control": { <DHCP queue control> },
+/// "loggers": [ <list of loggers> ]
+/// },
+/// @endcode
+///
+/// YANG syntax for kea-dhcp6-server:config is:
+/// @code
+/// +--rw data-directory? string
+/// +--rw preferred-lifetime? uint32
+/// +--rw min-preferred-lifetime? uint32
+/// +--rw max-preferred-lifetime? uint32
+/// +--rw valid-lifetime? uint32
+/// +--rw min-valid-lifetime? uint32
+/// +--rw max-valid-lifetime? uint32
+/// +--rw renew-timer? uint32
+/// +--rw rebind-timer? uint32
+/// +--rw calculate-tee-times? boolean
+/// +--rw t1-percent? decimal64
+/// +--rw t2-percent? decimal64
+/// +--rw decline-probation-period? uint32
+/// +--rw subnet6* [id]
+/// +--rw shared-network* [name]
+/// +--rw interfaces-config
+/// +--rw lease-database!
+/// +--rw hosts-database* [database-type]
+/// +--rw relay-supplied-options* string
+/// +--rw mac-sources* string
+/// +--rw host-reservation-identifiers* host-identifier-type
+/// +--rw client-class* [name]
+/// +--rw option-def* [code space]
+/// +--rw option-data* [code space]
+/// +--rw hook-library* [library]
+/// +--rw expired-leases-processing
+/// +--rw server-id!
+/// +--rw dhcp4o6-port? uint16
+/// +--rw control-socket!
+/// +--rw hostname-char-set? string
+/// +--rw hostname-char-replacement? string
+/// +--rw dhcp-ddns
+/// +--rw user-context? user-context
+/// +--rw sanity-checks
+/// +--rw reservation-mode? host-reservation-mode
+/// +--rw host* [identifier-type identifier]
+/// +--rw config-control
+/// +--rw server-tag? string
+/// +--rw dhcp-queue-control? string
+/// +--rw logger* [name]
+/// +--rw cache-max-age? uint32
+/// +--rw cache-threshold? decimal64
+/// +--rw compatibility
+/// +--rw ddns-generated-prefix? string
+/// +--rw ddns-override-client-update? boolean
+/// +--rw ddns-override-no-update? boolean
+/// +--rw ddns-qualifying-suffix? string
+/// +--rw ddns-replace-client-name? string
+/// +--rw ddns-send-updates? boolean
+/// +--rw ddns-update-on-renew? boolean
+/// +--rw ddns-use-conflict-resolution? boolean
+/// +--rw ip-reservations-unique? boolean
+/// +--rw early-global-reservations-lookup? boolean
+/// +--rw reservations-lookup-first? boolean
+/// +--rw multi-threading
+/// +--rw parked-packet-limit? uint32
+/// +--rw reservations-global? boolean
+/// +--rw reservations-in-subnet? boolean
+/// +--rw reservations-out-of-pool? boolean
+/// +--rw statistic-default-sample-age? uint32
+/// +--rw statistic-default-sample-count? uint32
+/// +--rw store-extended-info? boolean
+/// @endcode
+///
+/// Example of kea-dhcp6 simple configuration:
+/// @code
+/// {
+/// "Dhcp6": {
+/// "interfaces-config":
+/// {
+/// "interfaces": [ "eth1" ]
+/// },
+/// "control-socket": {
+/// "socket-type": "unix",
+/// "socket-name": "/tmp/kea6-sock"
+/// },
+/// "subnet6":
+/// [
+/// {
+/// "subnet": "2001:db8::/64",
+/// "pools":
+/// [
+/// {
+/// "pool": "2001:db8::1:0/112"
+/// }
+/// ]
+/// }
+/// ]
+/// }
+/// }
+/// @endcode
+///
+/// The same configuration wrote into YANG datastore using @c setConfig()
+/// with the kea-dhcp6-model and exported to XML format:
+/// @code
+/// <config xmlns="urn:ietf:params:xml:ns:yang:kea-dhcp6-server">
+/// <subnet6>
+/// <id>1</id>
+/// <pool>
+/// <start-address>2001:db8::1:0</start-address>
+/// <end-address>2001:db8::1:ffff</end-address>
+/// <prefix>2001:db8::1:0/112</prefix>
+/// </pool>
+/// <subnet>2001:db8::/64</subnet>
+/// </subnet6>
+/// <interfaces-config>
+/// <interfaces>eth1</interfaces>
+/// </interfaces-config>
+/// <control-socket>
+/// <socket-name>/tmp/kea6-sock</socket-name>
+/// <socket-type>unix</socket-type>
+/// </control-socket>
+/// </config>
+/// @endcode
+
+/// Inheritance graph between translators is:
+///
+/// +-----------------------------------------+
+/// | |
+/// +------------------------------+ |
+/// | | |
+/// +----------+-------------------+----------+
+/// | | | |
+/// | | +---------+----------+
+/// | | | | |
+/// config +- shared +- subnet +- pool --+- option -+ basic
+/// | network (list) | (list) | data |
+/// | (list) | | (list) |
+/// | | | |
+/// | +- pd ----+ |
+/// | | pool | |
+/// | | (list) | |
+/// | | | |
+/// +--------------------+- host --+ |
+/// | (liat) | |
+/// | | |
+/// | +--------------------+----------+
+/// | | |
+/// +- class -+- option ----------------------+
+/// | (list) | def |
+/// | | (list) |
+/// +---------+ |
+/// | |
+/// + control --------------------------------+
+/// | socket |
+/// | |
+/// +------------+ |
+/// | | |
+/// +- database -+- database -----------------+
+/// | list |
+/// | |
+/// +- logger --------------------------------+
+/// (list)
+///
+/// 'XXX (list)' stands for 'XXX list --- XXX' which is a common motif
+/// (only database shows direct dependencies on both the list and the element)
+
+/// @brief A translator class for converting the config between YANG and JSON.
+///
+/// Currently supports the following models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+/// - ietf-dhcpv6-server (partial)
+class TranslatorConfig : virtual public TranslatorControlSocket,
+ virtual public TranslatorDatabases,
+ virtual public TranslatorClasses,
+ virtual public TranslatorSharedNetworks,
+ virtual public TranslatorLoggers {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorConfig(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorConfig();
+
+ /// @brief Get and translate the whole DHCP server configuration
+ /// from YANG to JSON.
+ ///
+ /// @return JSON representation of the config.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getConfig();
+
+ /// @brief Translate and sets the DHCP server configuration
+ /// from JSON to YANG.
+ ///
+ /// Null elem argument removes the config containers.
+ ///
+ /// @param elem The JSON element.
+ void setConfig(isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getConfig for ietf-dhcpv6-server.
+ ///
+ /// This implementation is very preliminary. It handles network-ranges
+ /// only partially and nothing else.
+ ///
+ /// @return JSON representation of the config.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getConfigIetf6();
+
+ /// @brief delConfig for ietf-dhcpv6-server.
+ void delConfigIetf6();
+
+ /// @brief setConfig for ietf-dhcpv6-server.
+ ///
+ /// This implementation is very preliminary. It handles network-ranges
+ /// only partially and nothing else.
+ ///
+ /// @param elem The JSON element.
+ /// @throw BadValue on config without Dhcp6.
+ void setConfigIetf6(isc::data::ConstElementPtr elem);
+
+ /// @brief getConfig for kea-dhcp4-server.
+ ///
+ /// @return JSON representation of the config.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getConfigKea4();
+
+ /// @brief getConfig for kea-dhcp6-server.
+ ///
+ /// @return JSON representation of the config.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getConfigKea6();
+
+ /// @brief getServer common part for kea-dhcp[46]-server:config.
+ ///
+ /// @param xpath The xpath of the server.
+ /// @return JSON representation of the server.
+ isc::data::ElementPtr getServerKeaDhcpCommon(const std::string& xpath);
+
+ /// @brief getServer for kea-dhcp4-server:config.
+ ///
+ /// @return JSON representation of the config.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getServerKeaDhcp4();
+
+ /// @brief getServer for kea-dhcp6-server:config.
+ ///
+ /// @return JSON representation of the config.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getServerKeaDhcp6();
+
+ /// @brief delConfig for kea-dhcp[46]-server.
+ void delConfigKea();
+
+ /// @brief setConfig for kea-dhcp[46]-server.
+ ///
+ /// @param elem The JSON element.
+ void setConfigKea4(isc::data::ConstElementPtr elem);
+
+ /// @brief setConfig for kea-dhcp6-server.
+ ///
+ /// @param elem The JSON element.
+ void setConfigKea6(isc::data::ConstElementPtr elem);
+
+ /// @brief setServer common part for kea-dhcp[46]-server:config.
+ ///
+ /// @param xpath The xpath of the server.
+ /// @param elem The JSON element.
+ void setServerKeaDhcpCommon(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ isc::data::ElementPtr getHook(const std::string& xpath);
+
+ /// @brief Retrieves hooks configuration from sysrepo.
+ ///
+ /// @param xpath path to hooks configuration.
+ /// @return ElementList with hooks configuration.
+ isc::data::ElementPtr getHooksKea(const std::string& xpath);
+
+ /// @brief Retrieves expired leases processing parameters from sysrepo.
+ ///
+ /// @param xpath path to expired leases configuration.
+ /// @return ElementList with expired leases configuration.
+ isc::data::ElementPtr getExpiredKea(const std::string& xpath);
+
+ /// @brief Retrieves DDNS configuration from sysrepo
+ ///
+ /// @param xpath path to dhcp-ddns configuration.
+ /// @return ElementList with dhcp-ddns configuration.
+ isc::data::ElementPtr getDdnsKea(const std::string& xpath);
+
+ /// @brief Retrieves configuration control from sysrepo.
+ ///
+ /// @param xpath path to configuration control.
+ /// @return ElementMap with configuration control.
+ isc::data::ElementPtr getConfigControlKea(const std::string& xpath);
+
+ /// @brief setServer for kea-dhcp4-server:config.
+ ///
+ /// @param elem The JSON element.
+ void setServerKeaDhcp4(isc::data::ConstElementPtr elem);
+
+ /// @brief setServer for kea-dhcp6-server:config.
+ ///
+ /// @param elem The JSON element.
+ void setServerKeaDhcp6(isc::data::ConstElementPtr elem);
+};
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_TRANSLATOR_CONFIG_H
diff --git a/src/lib/yang/translator_control_socket.cc b/src/lib/yang/translator_control_socket.cc
new file mode 100644
index 0000000..4a685ce
--- /dev/null
+++ b/src/lib/yang/translator_control_socket.cc
@@ -0,0 +1,111 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_control_socket.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorControlSocket::TranslatorControlSocket(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model) {
+}
+
+TranslatorControlSocket::~TranslatorControlSocket() {
+}
+
+ConstElementPtr
+TranslatorControlSocket::getControlSocket(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER) ||
+ (model_ == KEA_DHCP_DDNS) ||
+ (model_ == KEA_CTRL_AGENT)) {
+ return (getControlSocketKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting control socket at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getControlSocket not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorControlSocket::getControlSocketKea(const string& xpath) {
+ ConstElementPtr name = getItem(xpath + "/socket-name");
+ ConstElementPtr type = getItem(xpath + "/socket-type");
+ if (name && type) {
+ ElementPtr result = Element::createMap();
+ result->set("socket-name", name);
+ result->set("socket-type", type);
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context",
+ Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+ }
+ return (ElementPtr());
+}
+
+void
+TranslatorControlSocket::setControlSocket(const string& xpath,
+ ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER) ||
+ (model_ == KEA_DHCP_DDNS) ||
+ (model_ == KEA_CTRL_AGENT)) {
+ setControlSocketKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setControlSocket not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting control socket '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorControlSocket::setControlSocketKea(const string& xpath,
+ ConstElementPtr elem) {
+ if (!elem) {
+ delItem(xpath);
+ return;
+ }
+ ConstElementPtr name = elem->get("socket-name");
+ if (!name) {
+ isc_throw(BadValue, "setControlSocket missing socket name");
+ }
+ ConstElementPtr type = elem->get("socket-type");
+ if (!type) {
+ isc_throw(BadValue, "setControlSocket missing socket type");
+ }
+ setItem(xpath + "/socket-name", name, SR_STRING_T);
+ setItem(xpath + "/socket-type", type, SR_ENUM_T);
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ setItem(xpath + "/user-context", Element::create(context->str()),
+ SR_STRING_T);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_control_socket.h b/src/lib/yang/translator_control_socket.h
new file mode 100644
index 0000000..6af0430
--- /dev/null
+++ b/src/lib/yang/translator_control_socket.h
@@ -0,0 +1,120 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_CONTROL_SOCKET_H
+#define ISC_TRANSLATOR_CONTROL_SOCKET_H 1
+
+#include <yang/translator.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Control socket translation between YANG and JSON
+///
+/// JSON syntax for all Kea servers with command channel is:
+/// @code
+/// "control-socket": {
+/// "socket-type": "<socket type>",
+/// "socket-name": "<socket name>",
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax is:
+/// @code
+/// +--rw control-socket!
+/// +--rw socket-name string
+/// +--rw socket-type enumeration
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// {
+/// "socket-name": "/tmp/kea.sock",
+/// "socket-type": "unix",
+/// "user-context": { "foo": 1 }
+/// }
+/// @endcode
+/// @code
+/// /kea-ctrl-agent:config (container)
+/// /kea-ctrl-agent:config/control-sockets (container)
+/// /kea-ctrl-agent:config/control-sockets/
+/// socket[server-type='dhcp4'] (list instance)
+/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
+/// server-type = dhcp4
+/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
+/// control-socket (container)
+/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
+/// control-socket/socket-name = /tmp/kea.sock
+/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
+/// control-socket/socket-type = unix
+/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
+/// control-socket/user-context = { \"foo\": 1 }
+/// @endcode
+
+/// @brief A translator class for converting a control socket between
+/// YANG and JSON.
+///
+/// Supports the following models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+/// - kea-dhcp-ddns
+/// - kea-ctrl-agent
+class TranslatorControlSocket : virtual public TranslatorBasic {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorControlSocket(sysrepo::S_Session session,
+ const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorControlSocket();
+
+ /// @brief Get and translate a control socket from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the control socket.
+ /// @return JSON representation of the control socket or null.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getControlSocket(const std::string& xpath);
+
+ /// @brief Translate and set control socket from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the control socket.
+ /// @param elem The JSON element.
+ void setControlSocket(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getControlSocket JSON for kea models.
+ ///
+ /// @param xpath The xpath of the control socket.
+ /// @return JSON representation of the control socket.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getControlSocketKea(const std::string& xpath);
+
+ /// @brief setControlSocket for kea models.
+ ///
+ /// Null elem argument removes the container.
+ /// Required parameters passed in elem are: socket-name, socket-type.
+ /// Optional parameters are: user-context.
+ ///
+ /// @param xpath The xpath of the control socket.
+ /// @param elem The JSON element.
+ /// @throw BadValue on control socket without socket type or name.
+ void setControlSocketKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_CONTROL_SOCKET_H
diff --git a/src/lib/yang/translator_database.cc b/src/lib/yang/translator_database.cc
new file mode 100644
index 0000000..1536dd7
--- /dev/null
+++ b/src/lib/yang/translator_database.cc
@@ -0,0 +1,204 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_database.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorDatabase::TranslatorDatabase(S_Session session, const string& model)
+ : TranslatorBasic(session, model) {
+}
+
+TranslatorDatabase::~TranslatorDatabase() {
+}
+
+ElementPtr
+TranslatorDatabase::getDatabase(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getDatabaseKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting database access at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getDatabase not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorDatabase::getDatabaseKea(const string& xpath) {
+ ConstElementPtr type = getItem(xpath + "/database-type");
+ if (!type) {
+ return (ElementPtr());
+ }
+ ElementPtr result = Element::createMap();
+ result->set("type", type);
+ checkAndGetLeaf(result, xpath, "user");
+ checkAndGetLeaf(result, xpath, "password");
+ checkAndGetLeaf(result, xpath, "host");
+ checkAndGetLeaf(result, xpath, "name");
+ checkAndGetLeaf(result, xpath, "persist");
+ checkAndGetLeaf(result, xpath, "port");
+ checkAndGetLeaf(result, xpath, "lfc-interval");
+ checkAndGetLeaf(result, xpath, "readonly");
+ checkAndGetLeaf(result, xpath, "trust-anchor");
+ checkAndGetLeaf(result, xpath, "cert-file");
+ checkAndGetLeaf(result, xpath, "key-file");
+ checkAndGetLeaf(result, xpath, "cipher-list");
+ checkAndGetLeaf(result, xpath, "connect-timeout");
+ checkAndGetLeaf(result, xpath, "max-reconnect-tries");
+ checkAndGetLeaf(result, xpath, "reconnect-wait-time");
+ checkAndGetLeaf(result, xpath, "max-row-errors");
+ checkAndGetLeaf(result, xpath, "on-fail");
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorDatabase::setDatabase(const string& xpath,
+ ConstElementPtr elem,
+ bool skip) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setDatabaseKea(xpath, elem, skip);
+ } else {
+ isc_throw(NotImplemented,
+ "setDatabase not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting database access '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorDatabase::setDatabaseKea(const string& xpath,
+ ConstElementPtr elem,
+ bool skip) {
+ if (!elem) {
+ delItem(xpath);
+ return;
+ }
+ if (!skip) {
+ ConstElementPtr type = elem->get("type");
+ if (!type) {
+ isc_throw(BadValue, "setDatabase requires database type: "
+ << elem->str());
+ }
+ setItem(xpath + "/database-type", type, SR_STRING_T);
+ }
+ 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);
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ setItem(xpath + "/user-context", Element::create(context->str()),
+ SR_STRING_T);
+ }
+}
+
+TranslatorDatabases::TranslatorDatabases(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorDatabase(session, model) {
+}
+
+TranslatorDatabases::~TranslatorDatabases() {
+}
+
+ConstElementPtr
+TranslatorDatabases::getDatabases(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getDatabasesKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting database accesses at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getDatabases not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorDatabases::getDatabasesKea(const string& xpath) {
+ return getList<TranslatorDatabase>(xpath, *this,
+ &TranslatorDatabase::getDatabase);
+}
+
+void
+TranslatorDatabases::setDatabases(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setDatabasesKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setDatabases not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting database accesses '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorDatabases::setDatabasesKea(const string& xpath,
+ ConstElementPtr elem) {
+ if (!elem) {
+ delItem(xpath);
+ return;
+ }
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr database = elem->get(i);
+ if (!database->contains("type")) {
+ isc_throw(BadValue, "database without type: " << database->str());
+ }
+ string type = database->get("type")->stringValue();
+ ostringstream key;
+ key << xpath << "[database-type='" << type << "']";
+ setDatabase(key.str(), database, true);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_database.h b/src/lib/yang/translator_database.h
new file mode 100644
index 0000000..f1aa566
--- /dev/null
+++ b/src/lib/yang/translator_database.h
@@ -0,0 +1,205 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_DATABASE_H
+#define ISC_TRANSLATOR_DATABASE_H 1
+
+#include <yang/translator.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Database access translation between YANG and JSON
+///
+/// JSON syntax for all Kea servers with database access is:
+/// @code
+/// {
+/// "type": <type>, /// required
+/// "user": <user>,
+/// "password": <password>,
+/// "host": <host>,
+/// "name": <name>,
+/// "persist": <persist flag>,
+/// "port": <port>,
+/// "lfc-interval": <lfc interval>,
+/// "readonly": <readonly flag>,
+/// "trust-anchor": <trust anchor>,
+/// "cert-file": <cert file>,
+/// "key-file": <key file>,
+/// "cipher-list": <cipher list>,
+/// "connect-timeout": <connect timeout>,
+/// "max-reconnect-tries": <maximum reconnect tries>,
+/// "reconnect-wait-time": <reconnect wait time>,
+/// "max-row-errors": <maximum row errors>,
+/// "user-context": { <json map> },
+/// "comment": <comment>
+/// }
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46] is using database-type as the list key:
+/// @code
+/// +--rw database
+/// +--rw database-type string
+/// +--rw user? string
+/// +--rw password? string
+/// +--rw host? string
+/// +--rw name? string
+/// +--rw persist? boolean
+/// +--rw port? uint16
+/// +--rw lfc-interval? uint32
+/// +--rw readonly? boolean
+/// +--rw trust-anchor? string
+/// +--rw cert-file? string
+/// +--rw key-file? string
+/// +--rw cipher-list? string
+/// +--rw connect-timeout? uint32
+/// +--rw max-reconnect-tries? uint32
+/// +--rw reconnect-wait-time? uint32
+/// +--rw max-row-errors? uint32
+/// +--rw on-fail? string
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "type": "mysql",
+/// "name": "kea",
+/// "user": "kea",
+/// "password": "kea",
+/// "host": "localhost",
+/// "port": 3306
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql'] (list instance)
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql']/type = mysql
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql']/name = kea
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql']/user = kea
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql']/password = kea
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql']/host = localhost
+/// /kea-dhcp6-server:config/
+/// hosts-database[database-type='mysql']/port = 3306
+/// @endcode
+
+/// @brief A translator class for converting a database access parameters
+/// between YANG and JSON.
+///
+/// Supports the following models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+class TranslatorDatabase : virtual public TranslatorBasic {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorDatabase(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorDatabase();
+
+ /// @brief Get and translate a database access from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the database.
+ /// @return JSON representation of the database.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getDatabase(const std::string& xpath);
+
+ /// @brief Translate and set database access from JSON to YANG.
+ ///
+ /// Null elem argument removes the database entry.
+ ///
+ /// @param xpath The xpath of the database access.
+ /// @param elem The JSON element.
+ /// @param skip The skip type field flag.
+ void setDatabase(const std::string& xpath,
+ isc::data::ConstElementPtr elem,
+ bool skip = false);
+
+protected:
+ /// @brief getDatabase JSON for kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of the database.
+ /// @return JSON representation of the database or null if none.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getDatabaseKea(const std::string& xpath);
+
+ /// @brief setDatabase for kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of the database access.
+ /// @param elem The JSON element.
+ /// @param skip The skip type field flag.
+ /// @throw BadValue on database without type,
+ void setDatabaseKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem,
+ bool skip);
+};
+
+/// @brief A translator class for converting a database access list between
+/// YANG and JSON.
+///
+/// Supports kea-dhcp[46]-server, does not exist in ietf-dhcpv6-server.
+class TranslatorDatabases : virtual public TranslatorDatabase {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorDatabases(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorDatabases();
+
+ /// @brief Get and translate database accesses from YANG to JSON.
+ ///
+ /// @param xpath The xpath of databases including the list name.
+ /// @return JSON representation of databases.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getDatabases(const std::string& xpath);
+
+ /// @brief Translate and set database accesses from JSON to YANG.
+ ///
+ /// Null elem argument removes the database list.
+ ///
+ /// @param xpath The xpath of databases including the list name.
+ /// @param elem The JSON element.
+ void setDatabases(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+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.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getDatabasesKea(const std::string& xpath);
+
+ /// @brief setDatabases for kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of databases including the list name.
+ /// @param elem The JSON element.
+ /// @throw BadValue on database without type,
+ void setDatabasesKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_DATABASE_H
diff --git a/src/lib/yang/translator_host.cc b/src/lib/yang/translator_host.cc
new file mode 100644
index 0000000..fd4dc40
--- /dev/null
+++ b/src/lib/yang/translator_host.cc
@@ -0,0 +1,261 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_host.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorHost::TranslatorHost(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model) {
+}
+
+TranslatorHost::~TranslatorHost() {
+}
+
+ElementPtr
+ TranslatorHost::getHost(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getHostKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting host reservation at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getHost not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorHost::getHostKea(const string& xpath) {
+ ConstElementPtr id_type = getItem(xpath + "/identifier-type");
+ ConstElementPtr id = getItem(xpath + "/identifier");
+ if (!id_type || !id) {
+ isc_throw(Unexpected, "getHostKea requires both identifier and "
+ "identifier-type");
+ }
+ ElementPtr result = Element::createMap();
+ result->set(id_type->stringValue(), id);
+ ConstElementPtr hostname = getItem(xpath + "/hostname");
+ if (hostname) {
+ result->set("hostname", hostname);
+ }
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr address = getItem(xpath + "/ip-address");
+ if (address) {
+ result->set("ip-address", address);
+ }
+ } else {
+ ConstElementPtr addresses = getItems(xpath + "/ip-addresses");
+ if (addresses && (addresses->size() > 0)) {
+ result->set("ip-addresses", addresses);
+ }
+ ConstElementPtr prefixes = getItems(xpath + "/prefixes");
+ if (prefixes && (prefixes->size() > 0)) {
+ result->set("prefixes", prefixes);
+ }
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("option-data", options);
+ }
+ ConstElementPtr classes = getItems(xpath + "/client-classes");
+ if (classes) {
+ result->set("client-classes", classes);
+ }
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr next = getItem(xpath + "/next-server");
+ if (next) {
+ result->set("next-server", next);
+ }
+ ConstElementPtr hostname = getItem(xpath + "/server-hostname");
+ if (hostname) {
+ result->set("server-hostname", hostname);
+ }
+ ConstElementPtr boot = getItem(xpath + "/boot-file-name");
+ if (boot) {
+ result->set("boot-file-name", boot);
+ }
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorHost::setHost(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setHostKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setHost not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting host reservation '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+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);
+ }
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr address = elem->get("ip-address");
+ if (address) {
+ setItem(xpath + "/ip-address", address, SR_STRING_T);
+ }
+ } 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);
+ }
+ }
+ ConstElementPtr prefixes = elem->get("prefixes");
+ if (prefixes && (prefixes->size() > 0)) {
+ for (ConstElementPtr prefix : prefixes->listValue()) {
+ setItem(xpath + "/prefixes", prefix, SR_STRING_T);
+ }
+ }
+ }
+ ConstElementPtr options = elem->get("option-data");
+ if (options && (options->size() > 0)) {
+ setOptionDataList(xpath, options);
+ }
+ ConstElementPtr classes = elem->get("client-classes");
+ if (classes && (classes->size() > 0)) {
+ for (ConstElementPtr cclass : classes->listValue()) {
+ setItem(xpath + "/client-classes", cclass, SR_STRING_T);
+ }
+ }
+
+ // These are DHCPv4-specific parameters.
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr next = elem->get("next-server");
+ if (next) {
+ setItem(xpath + "/next-server", next, SR_STRING_T);
+ }
+ ConstElementPtr hostname = elem->get("server-hostname");
+ if (hostname) {
+ setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
+ }
+ ConstElementPtr boot = elem->get("boot-file-name");
+ if (boot) {
+ setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ }
+ }
+
+ // User context is supported in both kea-dhcp4-server and kea-dhcp6-server.
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ setItem(xpath + "/user-context", Element::create(context->str()),
+ SR_STRING_T);
+ }
+}
+
+TranslatorHosts::TranslatorHosts(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorHost(session, model) {
+}
+
+TranslatorHosts::~TranslatorHosts() {
+}
+
+ElementPtr
+TranslatorHosts::getHosts(const string& xpath) {
+ return getList<TranslatorHost>(xpath + "/host", *this,
+ &TranslatorHost::getHost);
+}
+
+void
+TranslatorHosts::setHosts(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setHostsKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setHosts not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting host reservations '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorHosts::setHostsKea(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ string id_type = "unknown";
+ ConstElementPtr host = elem->get(i);
+ ConstElementPtr id = host->get("hw-address");
+ if (id) {
+ id_type = "hw-address";
+ goto found;
+ }
+ id = host->get("duid");
+ if (id) {
+ id_type = "duid";
+ goto found;
+ }
+ if (model_ == KEA_DHCP4_SERVER) {
+ id = host->get("circuit-id");
+ if (id) {
+ id_type = "circuit-id";
+ goto found;
+ }
+ id = host->get("client-id");
+ if (id) {
+ id_type = "client-id";
+ goto found;
+ }
+ }
+ id = host->get("flex-id");
+ if (id) {
+ id_type = "flex-id";
+ goto found;
+ }
+
+ found:
+ if (id_type == "unknown") {
+ isc_throw(BadValue, "getHosts: can't find the identifier type in "
+ << host->str());
+ }
+ ostringstream key;
+ key << xpath << "/host[identifier-type='" << id_type
+ << "'][identifier='" << id->stringValue() << "']";
+ setHost(key.str(), host);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_host.h b/src/lib/yang/translator_host.h
new file mode 100644
index 0000000..b67880a
--- /dev/null
+++ b/src/lib/yang/translator_host.h
@@ -0,0 +1,198 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_HOST_H
+#define ISC_TRANSLATOR_HOST_H 1
+
+#include <yang/translator_option_data.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Translation between YANG and JSON for a single host reservation.
+///
+/// JSON syntax for kea-dhcp4 is:
+/// @code
+/// {
+/// "hw-address": <hardware address>,
+/// "duid": <duid>,
+/// "circuit-id": <circuit id>,
+/// "client-id": <client id>,
+/// "flex-id": <flex id>,
+/// "ip-address": <ipv4 reserved address>,
+/// "hostname": <hostname>,
+/// "next-server": "<next server>",
+/// "server-hostname": "<server hostname>",
+/// "boot-file-name": "<boot file name>",
+/// "client-classes": "<client class names>",
+/// "option-data": [ <list of option data> ],
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// JSON syntax for kea-dhcp6 is:
+/// @code
+/// {
+/// "hw-address": <hardware address>,
+/// "duid": <duid>,
+/// "flex-id": <flex id>,
+/// "ip-addresses": <ipv6 reserved addresses>,
+/// "prefixes": <ipv6 reserved prefixes>,
+/// "hostname": <hostname>,
+/// "client-classes": "<client class names>",
+/// "option-data": [ <list of option data> ],
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46] is with identifier-type and identifier
+/// as the list keys:
+/// @code
+/// +--rw identifier-type host-identifier-type
+/// +--rw identifier string
+/// +--rw hostname? string
+/// +--rw client-classes* string
+/// +--rw option-data* [code space]
+/// +--rw user-context? user-context
+///
+/// DHCPv4 only:
+/// +--rw ip-address? inet:ipv4-address
+/// +--rw next-server? inet:ipv4-address
+/// +--rw server-hostname? string
+/// +--rw boot-file-name? string
+///
+/// DHCPv6 only:
+/// +--rw ip-addresses* inet:ipv6-address
+/// +--rw prefixes* inet:ipv6-prefix
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "flex-id": "00:ff",
+/// "ip-address": "10.0.0.1",
+/// "hostname": "foo"
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp4-server:config (container)
+/// /kea-dhcp4-server:config/subnet4[id='111'] (list instance)
+/// /kea-dhcp4-server:config/subnet4[id='111']/id = 111
+/// /kea-dhcp4-server:config/subnet4[id='111']/subnet = 10.0.0.0/24
+/// /kea-dhcp4-server:config/subnet4[id='111']/
+/// host[identifier-type='flex-id'][identifier='00:ff'] (list instance)
+/// /kea-dhcp4-server:config/subnet4[id='111']/
+/// host[identifier-type='flex-id'][identifier='00:ff']/
+/// identifier-type = flex-id
+/// /kea-dhcp4-server:config/subnet4[id='111']/
+/// host[identifier-type='flex-id'][identifier='00:ff']/
+/// identifier = 00:ff
+/// /kea-dhcp4-server:config/subnet4[id='111']/
+/// host[identifier-type='flex-id'][identifier='00:ff']/
+/// hostname = foo
+/// /kea-dhcp4-server:config/subnet4[id='111']/
+/// host[identifier-type='flex-id'][identifier='00:ff']/
+/// ip-address = 10.0.0.1
+/// @endcode
+
+/// @brief A translator class for converting a host reservation between
+/// YANG and JSON.
+///
+/// Currently supported models are:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+///
+/// ietf-dhcpv6-server is not supported yet.
+class TranslatorHost : virtual public TranslatorOptionDataList {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorHost(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorHost();
+
+ /// @brief Get and translate a host reservation from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the host reservation.
+ /// @return JSON representation of the host reservation.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getHost(const std::string& xpath);
+
+ /// @brief Translate and set host reservation from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the host reservation.
+ /// @param elem The JSON element.
+ void setHost(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getHost for kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of the host reservation.
+ /// @return JSON representation of the host reservation.
+ isc::data::ElementPtr getHostKea(const std::string& xpath);
+
+ /// @brief setHost for kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of the host reservation.
+ /// @param elem The JSON element.
+ void setHostKea(const std::string& xpath, isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting host reservations list between
+/// YANG and JSON.
+///
+/// Currently supports the following models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+///
+/// The ietf-dhcpv6-server model is not yet supported.
+class TranslatorHosts : virtual public TranslatorHost {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorHosts(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorHosts();
+
+ /// @brief Get and translate host reservations from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the host reservation list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getHosts(const std::string& xpath);
+
+ /// @brief Translate and set (address) host reservations from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the host reservation list.
+ /// @param elem The JSON element.
+ void setHosts(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief setHosts for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the host reservation list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on host reservation without known identifier type.
+ void setHostsKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_HOST_H
diff --git a/src/lib/yang/translator_logger.cc b/src/lib/yang/translator_logger.cc
new file mode 100644
index 0000000..de04428
--- /dev/null
+++ b/src/lib/yang/translator_logger.cc
@@ -0,0 +1,261 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_logger.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorLogger::TranslatorLogger(S_Session session, const string& model)
+ : TranslatorBasic(session, model) {
+}
+
+TranslatorLogger::~TranslatorLogger() {
+}
+
+ElementPtr
+TranslatorLogger::getLogger(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER) ||
+ (model_ == KEA_DHCP_DDNS) ||
+ (model_ == KEA_CTRL_AGENT)) {
+ return (getLoggerKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting logger at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getLogger not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorLogger::getLoggerKea(const string& xpath) {
+ ConstElementPtr name = getItem(xpath + "/name");
+ if (!name) {
+ // Can't happen as name is the key.
+ isc_throw(Unexpected, "getLoggerKea requires name: " << xpath);
+ }
+ ElementPtr result = Element::createMap();
+ result->set("name", name);
+ ConstElementPtr options = getOutputOptions(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("output_options", options);
+ }
+ ConstElementPtr severity = getItem(xpath + "/severity");
+ if (severity) {
+ result->set("severity", severity);
+ }
+ ConstElementPtr debuglevel = getItem(xpath + "/debuglevel");
+ if (debuglevel) {
+ result->set("debuglevel", debuglevel);
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+ElementPtr
+TranslatorLogger::getOutputOption(const string& xpath) {
+ ConstElementPtr output = getItem(xpath + "/output");
+ if (!output) {
+ // Can't happen as output is the key.
+ isc_throw(Unexpected, "getOutputOption requires (!output): " << xpath);
+ }
+ ElementPtr result = Element::createMap();
+ result->set("output", output);
+ ConstElementPtr maxver = getItem(xpath + "/maxver");
+ if (maxver) {
+ result->set("maxver", maxver);
+ }
+ ConstElementPtr maxsize = getItem(xpath + "/maxsize");
+ if (maxsize) {
+ result->set("maxsize", maxsize);
+ }
+ ConstElementPtr flush = getItem(xpath + "/flush");
+ if (flush) {
+ result->set("flush", flush);
+ }
+ ConstElementPtr pattern = getItem(xpath + "/pattern");
+ if (pattern) {
+ result->set("pattern", pattern);
+ }
+ return (result);
+}
+
+ElementPtr
+TranslatorLogger::getOutputOptions(const string& xpath) {
+ return getList(xpath + "/output-option", *this,
+ &TranslatorLogger::getOutputOption);
+}
+
+void
+TranslatorLogger::setLogger(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER) ||
+ (model_ == KEA_DHCP_DDNS) ||
+ (model_ == KEA_CTRL_AGENT)) {
+ setLoggerKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setLogger not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting logger '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorLogger::setLoggerKea(const string& xpath, ConstElementPtr elem) {
+ // Skip name as it is the key.
+ ConstElementPtr options = elem->get("output_options");
+ if (options && (options->size() > 0)) {
+ setOutputOptions(xpath, options);
+ }
+ ConstElementPtr debuglevel = elem->get("debuglevel");
+ if (debuglevel) {
+ setItem(xpath + "/debuglevel", debuglevel, SR_UINT8_T);
+ }
+ ConstElementPtr severity = elem->get("severity");
+ if (severity) {
+ setItem(xpath + "/severity", severity, SR_ENUM_T);
+ }
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ setItem(xpath + "/user-context", Element::create(context->str()),
+ SR_STRING_T);
+ }
+}
+
+void
+TranslatorLogger::setOutputOption(const string& xpath, ConstElementPtr elem) {
+ bool created = false;
+ // Skip output as it is the key.
+ ConstElementPtr maxver = elem->get("maxver");
+ if (maxver) {
+ setItem(xpath + "/maxver", maxver, SR_UINT32_T);
+ created = true;
+ }
+ ConstElementPtr maxsize = elem->get("maxsize");
+ if (maxsize) {
+ setItem(xpath + "/maxsize", maxsize, SR_UINT32_T);
+ created = true;
+ }
+ ConstElementPtr flush = elem->get("flush");
+ if (flush) {
+ setItem(xpath + "/flush", flush, SR_BOOL_T);
+ created = true;
+ }
+ 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);
+ }
+}
+
+void
+TranslatorLogger::setOutputOptions(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr option = elem->get(i);
+ if (!option->contains("output")) {
+ isc_throw(BadValue, "output-option without output: "
+ << option->str());
+ }
+ string output = option->get("output")->stringValue();
+ ostringstream key;
+ key << xpath << "/output-option[output='" << output << "']";
+ setOutputOption(key.str(), option);
+ }
+}
+
+TranslatorLoggers::TranslatorLoggers(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorLogger(session, model) {
+}
+
+TranslatorLoggers::~TranslatorLoggers() {
+}
+
+ConstElementPtr
+TranslatorLoggers::getLoggers(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER) ||
+ (model_ == KEA_DHCP_DDNS) ||
+ (model_ == KEA_CTRL_AGENT)) {
+ return (getLoggersKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting loggeres at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getLoggers not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorLoggers::getLoggersKea(const string& xpath) {
+ return getList<TranslatorLogger>(xpath + "/logger", *this,
+ &TranslatorLogger::getLogger);
+}
+
+void
+TranslatorLoggers::setLoggers(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER) ||
+ (model_ == KEA_DHCP_DDNS) ||
+ (model_ == KEA_CTRL_AGENT)) {
+ setLoggersKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setLoggers not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting loggeres '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorLoggers::setLoggersKea(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr logger = elem->get(i);
+ if (!logger->contains("name")) {
+ isc_throw(BadValue, "logger without name: " << logger->str());
+ }
+ string name = logger->get("name")->stringValue();
+ ostringstream key;
+ key << xpath << "/logger[name='" << name << "']";
+ setLogger(key.str(), logger);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_logger.h b/src/lib/yang/translator_logger.h
new file mode 100644
index 0000000..6939414
--- /dev/null
+++ b/src/lib/yang/translator_logger.h
@@ -0,0 +1,214 @@
+// Copyright (C) 2018-2019,2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_LOGGER_H
+#define ISC_TRANSLATOR_LOGGER_H 1
+
+#include <yang/translator.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Logger translation between YANG and JSON
+///
+/// JSON syntax for all Kea servers with loggers is:
+/// @code
+/// {
+/// "name": <name>,
+/// "output_options": [ <output options> ],
+/// "severity": <severity>,
+/// "debuglevel": <debug level>,
+/// "user-context": { <json map> },
+/// "comment": <comment>
+/// }
+/// @endcode
+///
+/// JSON syntax for all Kea server for output options is:
+/// @code
+/// {
+/// "output": <output, e.g. log file name>,
+/// "maxver": <maximum file version>,
+/// "maxsize": <maximum file size>,
+/// "flush": <flush flag>,
+/// "pattern": <custom layout>
+/// }
+/// @endcode
+///
+/// YANG syntax for loggers is:
+/// @code
+/// +--rw logger* [name]
+/// +--rw name string
+/// +--rw output-option* [output]
+/// | +--rw output string
+/// | +--rw flush? boolean
+/// | +--rw maxsize? uint32
+/// | +--rw maxver? uint32
+/// | +--rw pattern? string
+/// +--rw debuglevel? uint8
+/// +--rw severity? enumeration
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "name": "foo",
+/// "severity": "WARN",
+/// "output_options":
+/// [
+/// {
+/// "output": "/bar",
+/// "maxver": 10
+/// }
+/// ]
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp4-server:config (container)
+/// /kea-dhcp4-server:config/...
+/// /kea-dhcp4-server:config/logger[name='foo'] (list instance)
+/// /kea-dhcp4-server:config/logger[name='foo']/name = foo
+/// /kea-dhcp4-server:config/logger[name='foo']/
+/// option[output='/bar'] (list instance)
+/// /kea-dhcp4-server:config/logger[name='foo']/
+/// option[output='/bar']/option = /bar
+/// /kea-dhcp4-server:config/logger[name='foo']/
+/// option[output='/bar']/maxver = 10
+/// /kea-dhcp4-server:config/logger[name='foo']/severity = WARN
+/// @endcode
+
+/// @brief A translator class for converting a logger between
+/// YANG and JSON.
+///
+/// Currently supports all kea models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+/// - kea-dhcp-ddns
+/// - kea-ctrl-agent
+class TranslatorLogger : virtual public TranslatorBasic {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorLogger(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorLogger();
+
+ /// @brief Get and translate a logger from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the logger.
+ /// @return JSON representation of the logger.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getLogger(const std::string& xpath);
+
+ /// @brief Translate and set logger from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the logger.
+ /// @param elem The JSON element.
+ void setLogger(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief Get and translate an output option from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the output option.
+ /// @return JSON representation of the output option.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getOutputOption(const std::string& xpath);
+
+ /// @brief Get and translate output options from YANG to JSON.
+ ///
+ /// @param xpath The xpath of output options.
+ /// @return JSON representation of output options.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getOutputOptions(const std::string& xpath);
+
+ /// @brief Translate and set an output option from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the output option.
+ /// @param elem The JSON element.
+ void setOutputOption(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief Translate and set output options from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the output options.
+ /// @param elem The JSON element.
+ /// @throw BadValue on an output option without output.
+ void setOutputOptions(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief getLogger JSON for loggers.
+ ///
+ /// @param xpath The xpath of the logger.
+ /// @return JSON representation of the logger.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getLoggerKea(const std::string& xpath);
+
+ /// @brief setLogger for loggers.
+ ///
+ /// @param xpath The xpath of the logger.
+ /// @param elem The JSON element.
+ void setLoggerKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting a logger list between
+/// YANG and JSON.
+///
+/// Currently supports all kea servers and agents. Specific to Kea.
+class TranslatorLoggers : virtual public TranslatorLogger {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorLoggers(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorLoggers();
+
+ /// @brief Get and translate loggeres from YANG to JSON.
+ ///
+ /// @param xpath The xpath of loggers.
+ /// @return JSON representation of loggers.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getLoggers(const std::string& xpath);
+
+ /// @brief Translate and set loggeres from JSON to YANG.
+ ///
+ /// @param xpath The xpath of loggers.
+ /// @param elem The JSON element.
+ void setLoggers(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getLoggers JSON for loggers.
+ ///
+ /// @param xpath The xpath of loggers.
+ /// @return JSON representation of loggers.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getLoggersKea(const std::string& xpath);
+
+ /// @brief setLoggers for loggers.
+ ///
+ /// @param xpath The xpath of loggers.
+ /// @param elem The JSON element.
+ /// @throw BadValue on a logger without name.
+ void setLoggersKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_LOGGER_H
diff --git a/src/lib/yang/translator_option_data.cc b/src/lib/yang/translator_option_data.cc
new file mode 100644
index 0000000..9947fdc
--- /dev/null
+++ b/src/lib/yang/translator_option_data.cc
@@ -0,0 +1,197 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_option_data.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorOptionData::TranslatorOptionData(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model) {
+}
+
+TranslatorOptionData::~TranslatorOptionData() {
+}
+
+ElementPtr
+TranslatorOptionData::getOptionData(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getOptionDataKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting option data at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getOptionData not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorOptionData::getOptionDataKea(const string& xpath) {
+ ConstElementPtr code = getItem(xpath + "/code");
+ ConstElementPtr space = getItem(xpath + "/space");
+ if (!code || !space) {
+ // Can't happen as code and space are the keys.
+ isc_throw(Unexpected, "getOptionDataKea requires code and space: "
+ << xpath);
+ }
+ ElementPtr result = Element::createMap();
+ result->set("code", code);
+ result->set("space", space);
+ ConstElementPtr name = getItem(xpath + "/name");
+ if (name) {
+ result->set("name", name);
+ }
+ ConstElementPtr data = getItem(xpath + "/data");
+ if (data) {
+ result->set("data", data);
+ }
+ ConstElementPtr format = getItem(xpath + "/csv-format");
+ if (format) {
+ result->set("csv-format", format);
+ }
+ ConstElementPtr send = getItem(xpath + "/always-send");
+ if (send) {
+ result->set("always-send", send);
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorOptionData::setOptionData(const string& xpath,
+ ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setOptionDataKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setOptionData not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting option data '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorOptionData::setOptionDataKea(const string& xpath,
+ ConstElementPtr elem) {
+ // Skip keys code and space.
+ ConstElementPtr name = elem->get("name");
+ if (name) {
+ setItem(xpath + "/name", name, SR_STRING_T);
+ }
+ ConstElementPtr data = elem->get("data");
+ if (data) {
+ setItem(xpath + "/data", data, SR_STRING_T);
+ }
+ ConstElementPtr format = elem->get("csv-format");
+ if (format) {
+ setItem(xpath + "/csv-format", format, SR_BOOL_T);
+ }
+ ConstElementPtr send = elem->get("always-send");
+ if (send) {
+ setItem(xpath + "/always-send", send, SR_BOOL_T);
+ }
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ setItem(xpath + "/user-context", Element::create(context->str()),
+ SR_STRING_T);
+ }
+}
+
+TranslatorOptionDataList::TranslatorOptionDataList(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model) {
+}
+
+TranslatorOptionDataList::~TranslatorOptionDataList() {
+}
+
+ConstElementPtr
+TranslatorOptionDataList::getOptionDataList(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getOptionDataListKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting option data list at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getOptionDataList not implemented for the model: " << model_);
+}
+
+ConstElementPtr
+TranslatorOptionDataList::getOptionDataListKea(const string& xpath) {
+ return getList<TranslatorOptionData>(xpath + "/option-data", *this,
+ &TranslatorOptionData::getOptionData);
+}
+
+void
+TranslatorOptionDataList::setOptionDataList(const string& xpath,
+ ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setOptionDataListKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setOptionDataList not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting option data list '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorOptionDataList::setOptionDataListKea(const string& xpath,
+ ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr option = elem->get(i);
+ if (!option->contains("code")) {
+ isc_throw(BadValue, "option data without code: " << option->str());
+ }
+ unsigned code = static_cast<unsigned>(option->get("code")->intValue());
+ if (!option->contains("space")) {
+ isc_throw(BadValue, "option data without space: " <<option->str());
+ }
+ string space = option->get("space")->stringValue();
+ ostringstream keys;
+ keys << xpath << "/option-data[code='" << code
+ << "'][space='" << space << "']";
+ setOptionData(keys.str(), option);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_option_data.h b/src/lib/yang/translator_option_data.h
new file mode 100644
index 0000000..868109b
--- /dev/null
+++ b/src/lib/yang/translator_option_data.h
@@ -0,0 +1,168 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_OPTION_DATA_H
+#define ISC_TRANSLATOR_OPTION_DATA_H 1
+
+#include <yang/translator.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Option data translation between YANG and JSON
+///
+/// JSON syntax for Kea DHCP with command channel is:
+/// @code
+/// {
+/// "code": <code>,
+/// "name": <name>,
+/// "space": <space>,
+/// "csv-format": <csv format flag>,
+/// "data": <value>,
+/// "always-send": <always send flag>,
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46] with code and space as keys is:
+/// @code
+/// +--rw option-data* [code space]
+/// +--rw code uint8
+/// +--rw space string
+/// +--rw name? string
+/// +--rw data? string
+/// +--rw csv-format? boolean
+/// +--rw always-send? boolean
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "code": 100,
+/// "space": "dns",
+/// "csv-format": false,
+/// "data": "12121212",
+/// "always-send": false
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/
+/// option-data[code='100'][space='dns'] (list instance)
+/// /kea-dhcp6-server:config/
+/// option-data[code='100'][space='dns']/code = 100
+/// /kea-dhcp6-server:config/
+/// option-data[code='100'][space='dns']/space = dns
+/// /kea-dhcp6-server:config/
+/// option-data[code='100'][space='dns']/data = 12121212
+/// /kea-dhcp6-server:config/
+/// option-data[code='100'][space='dns']/csv-format = false
+/// /kea-dhcp6-server:config/
+/// option-data[code='100'][space='dns']/always-send = false
+/// @endcode
+
+/// @brief A translator class for converting an option data between
+/// YANG and JSON.
+///
+/// Currently supports on kea-dhcp[46]-server, not yet ietf-dhcpv6-server.
+class TranslatorOptionData : virtual public TranslatorBasic {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorOptionData(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorOptionData();
+
+ /// @brief Get and translate an option data from YANG to JSON.
+ ///
+ ///
+ /// @param xpath The xpath of the option data.
+ /// @return JSON representation of the option data.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getOptionData(const std::string& xpath);
+
+ /// @brief Translate and set option data from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the option data.
+ /// @param elem The JSON element.
+ void setOptionData(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getOptionData JSON for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the option data.
+ /// @return JSON representation of the option data.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getOptionDataKea(const std::string& xpath);
+
+ /// @brief setOptionData for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the option data.
+ /// @param elem The JSON element.
+ void setOptionDataKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting an option data list between
+/// YANG and JSON.
+///
+/// Currently supports on kea-dhcp[46]-server, not yet ietf-dhcpv6-server.
+class TranslatorOptionDataList : virtual public TranslatorOptionData {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorOptionDataList(sysrepo::S_Session session,
+ const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorOptionDataList();
+
+ /// @brief Get and translate option data list from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the option data list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getOptionDataList(const std::string& xpath);
+
+ /// @brief Translate and set option data list from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the option data list.
+ /// @param elem The JSON element.
+ void setOptionDataList(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getOptionDataList for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the option data list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getOptionDataListKea(const std::string& xpath);
+
+ /// @brief setOptionDataList for kea-dhcp[46].
+ ///
+ /// @param xpath The xpath of the option data list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on option data without code or space.
+ void setOptionDataListKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_OPTION_DATA_H
diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc
new file mode 100644
index 0000000..a552191
--- /dev/null
+++ b/src/lib/yang/translator_option_def.cc
@@ -0,0 +1,208 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_option_def.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorOptionDef::TranslatorOptionDef(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model) {
+}
+
+TranslatorOptionDef::~TranslatorOptionDef() {
+}
+
+ElementPtr
+TranslatorOptionDef::getOptionDef(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getOptionDefKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting option definition at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getOptionDef not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorOptionDef::getOptionDefKea(const string& xpath) {
+ ConstElementPtr code = getItem(xpath + "/code");
+ ConstElementPtr name = getItem(xpath + "/name");
+ ConstElementPtr type = getItem(xpath + "/type");
+ ConstElementPtr space = getItem(xpath + "/space");
+ if (!code || !space) {
+ // Can't happen as code and space are the keys.
+ isc_throw(Unexpected, "getOptionDefKea requires code and space: "
+ << xpath);
+ }
+ if (!name || !type) {
+ isc_throw(BadValue, "getOptionDefKea requires name and type: "
+ << xpath);
+ }
+ ElementPtr result = Element::createMap();
+ result->set("code", code);
+ result->set("name", name);
+ result->set("type", type);
+ result->set("space", getItem(xpath + "/space"));
+ ConstElementPtr record = getItem(xpath + "/record-types");
+ if (record) {
+ result->set("record-types", record);
+ }
+ ConstElementPtr array = getItem(xpath + "/array");
+ if (array) {
+ result->set("array", array);
+ }
+ ConstElementPtr encapsulate = getItem(xpath + "/encapsulate");
+ if (encapsulate) {
+ result->set("encapsulate", encapsulate);
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorOptionDef::setOptionDef(const string& xpath, ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setOptionDefKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setOptionDef not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting option definition '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorOptionDef::setOptionDefKea(const string& xpath,
+ ConstElementPtr elem) {
+ // Skip code and space as they are the keys.
+ ConstElementPtr name = elem->get("name");
+ if (!name) {
+ isc_throw(BadValue, "option definition with name: " << elem->str());
+ }
+ setItem(xpath + "/name", name, SR_STRING_T);
+ ConstElementPtr type = elem->get("type");
+ if (!type) {
+ isc_throw(BadValue, "option definition with type: " << elem->str());
+ }
+ setItem(xpath + "/type", type, SR_STRING_T);
+ ConstElementPtr record = elem->get("record-types");
+ if (record) {
+ setItem(xpath + "/record-types", record, SR_STRING_T);
+ }
+ ConstElementPtr array = elem->get("array");
+ if (array) {
+ setItem(xpath + "/array", array, SR_BOOL_T);
+ }
+ ConstElementPtr encapsulate = elem->get("encapsulate");
+ if (encapsulate) {
+ setItem(xpath + "/encapsulate", encapsulate, SR_STRING_T);
+ }
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ setItem(xpath + "/user-context", Element::create(context->str()),
+ SR_STRING_T);
+ }
+}
+
+TranslatorOptionDefList::TranslatorOptionDefList(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionDef(session, model) {
+}
+
+TranslatorOptionDefList::~TranslatorOptionDefList() {
+}
+
+ConstElementPtr
+TranslatorOptionDefList::getOptionDefList(const string& xpath) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getOptionDefListKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting option definition list at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getOptionDefList not implemented for the model: " << model_);
+}
+
+ConstElementPtr
+TranslatorOptionDefList::getOptionDefListKea(const string& xpath) {
+ return getList<TranslatorOptionDef>(xpath + "/option-def", *this,
+ &TranslatorOptionDefList::getOptionDef);
+}
+
+void
+TranslatorOptionDefList::setOptionDefList(const string& xpath,
+ ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setOptionDefListKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setOptionDefList not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting option definition list '"
+ << elem->str() << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorOptionDefList::setOptionDefListKea(const string& xpath,
+ ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr def = elem->get(i);
+ if (!def->contains("code")) {
+ isc_throw(BadValue,
+ "option definition without code: " << def->str());
+ }
+ unsigned code = static_cast<unsigned>(def->get("code")->intValue());
+ if (!def->contains("space")) {
+ isc_throw(BadValue,
+ "option definition without space: " << def->str());
+ }
+ string space = def->get("space")->stringValue();
+ ostringstream keys;
+ keys << xpath << "/option-def[code='" << code
+ << "'][space='" << space << "']";
+ setOptionDef(keys.str(), def);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_option_def.h b/src/lib/yang/translator_option_def.h
new file mode 100644
index 0000000..b8b0827
--- /dev/null
+++ b/src/lib/yang/translator_option_def.h
@@ -0,0 +1,175 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_OPTION_DEF_H
+#define ISC_TRANSLATOR_OPTION_DEF_H 1
+
+#include <yang/translator.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// @brief Option definition translation between YANG and JSON
+///
+/// JSON syntax for Kea DHCP servers is:
+/// @code
+/// {
+/// "code": <code>,
+/// "name": <name>,
+/// "space": <space>,
+/// "type": <type>,
+/// "array": <array flag>,
+/// "encapsulate": <encapsulated space>,
+/// "record-types": <record types>,
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46] with code and space as keys is:
+/// @code
+/// +--rw option-def* [code space]
+/// +--rw code uint8
+/// +--rw space string
+/// +--rw name string
+/// +--rw type string
+/// +--rw record-types? string
+/// +--rw encapsulate? string
+/// +--rw array? boolean
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "code": 100,
+/// "name": "foo",
+/// "space": "isc",
+/// "type": "string",
+/// "array": false
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/
+/// option-def[code='100'][space='isc'] (list instance)
+/// /kea-dhcp6-server:config/
+/// option-def[code='100'][space='isc']/code = 100
+/// /kea-dhcp6-server:config/
+/// option-def[code='100'][space='isc']/space = isc
+/// /kea-dhcp6-server:config/
+/// option-def[code='100'][space='isc']/name = foo
+/// /kea-dhcp6-server:config/
+/// option-def[code='100'][space='isc']/type = string
+/// /kea-dhcp6-server:config/
+/// option-def[code='100'][space='isc']/array = false
+/// @endcode
+
+/// @brief A translator class for converting an option definition between
+/// YANG and JSON.
+///
+/// Currently supports kea-dhcp[46]-server models.
+/// @todo: Support for ietf-dhcpv6-server model.
+class TranslatorOptionDef : virtual public TranslatorBasic {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorOptionDef(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorOptionDef();
+
+ /// @brief Get and translate an option definition from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the option definition.
+ /// @return JSON representation of the option definition.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getOptionDef(const std::string& xpath);
+
+ /// @brief Translate and set option definition from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the option definition..
+ /// @param elem The JSON element.
+ void setOptionDef(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getOptionDef implementation specific to kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of the option definition.
+ /// @return JSON representation of the option definition.
+ /// @throw SysrepoError when sysrepo raises an error.
+ /// @throw BadValue on option definition without name or type.
+ isc::data::ElementPtr getOptionDefKea(const std::string& xpath);
+
+ /// @brief setOptionDef implementation specific to kea-dhcp[46]-server models.
+ ///
+ /// @param xpath The xpath of the option definition.
+ /// @param elem The JSON element.
+ /// @throw BadValue on option definition without name or type.
+ void setOptionDefKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+// @brief A translator class for converting an option definition list
+// between YANG and JSON.
+//
+/// Currently supports kea-dhcp[46]-server models.
+/// @todo: Support for ietf-dhcpv6-server model.
+class TranslatorOptionDefList : virtual public TranslatorOptionDef {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorOptionDefList(sysrepo::S_Session session,
+ const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorOptionDefList();
+
+ /// @brief Get and translate option definition list from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the option definition list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getOptionDefList(const std::string& xpath);
+
+ /// @brief Translate and set option definition list from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the option definition list.
+ /// @param elem The JSON element.
+ void setOptionDefList(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getOptionDefList implementation specific to kea-dhcp[46]-server
+ /// models.
+ ///
+ /// @param xpath The xpath of the option definition list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ConstElementPtr getOptionDefListKea(const std::string& xpath);
+
+ /// @brief setOptionDefList implementation specific to kea-dhcp[46]-server
+ /// models.
+ ///
+ /// @param xpath The xpath of the option definition list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on option definition without code or space.
+ void setOptionDefListKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_OPTION_DEF_H
diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc
new file mode 100644
index 0000000..f6ffe71
--- /dev/null
+++ b/src/lib/yang/translator_pd_pool.cc
@@ -0,0 +1,365 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor.h>
+#include <yang/translator_pd_pool.h>
+#include <yang/yang_models.h>
+#include <boost/lexical_cast.hpp>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorPdPool::TranslatorPdPool(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model) {
+}
+
+TranslatorPdPool::~TranslatorPdPool() {
+}
+
+ElementPtr
+TranslatorPdPool::getPdPool(const string& xpath) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ return (getPdPoolIetf6(xpath));
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ return (getPdPoolKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting pd-pool at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getPdPool not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorPdPool::getPdPoolIetf6(const string& xpath) {
+ ElementPtr result = Element::createMap();
+ ConstElementPtr pref = getItem(xpath + "/prefix");
+ if (!pref) {
+ isc_throw(BadValue, "getPdPoolIetf6: prefix is required");
+ }
+ const string& prefix = pref->stringValue();
+ size_t slash = prefix.find("/");
+ if (slash == string::npos) {
+ isc_throw(BadValue,
+ "getPdPoolIetf6: no '/' in prefix '" << prefix << "'");
+ }
+ const string& address = prefix.substr(0, slash);
+ if (address.empty()) {
+ isc_throw(BadValue,
+ "getPdPoolIetf6: malformed prefix '" << prefix << "'");
+ }
+ result->set("prefix", Element::create(address));
+ // Silly: the prefix length is specified twice...
+ ConstElementPtr preflen = getItem(xpath + "/prefix-length");
+ if (!preflen) {
+ isc_throw(BadValue, "getPdPoolIetf6: prefix length is required");
+ }
+ result->set("prefix-len", preflen);
+ ConstElementPtr valid_lifetime = getItem(xpath + "/valid-lifetime");
+ if (valid_lifetime) {
+ result->set("valid-lifetime", valid_lifetime);
+ }
+ ConstElementPtr preferred_lifetime =
+ getItem(xpath + "/preferred-lifetime");
+ if (preferred_lifetime) {
+ result->set("preferred-lifetime", preferred_lifetime);
+ }
+ ConstElementPtr renew_time = getItem(xpath + "/renew-time");
+ if (renew_time) {
+ result->set("renew-timer", renew_time);
+ }
+ ConstElementPtr rebind_time = getItem(xpath + "/rebind-time");
+ if (rebind_time) {
+ result->set("rebind-timer", rebind_time);
+ }
+ // Skip rapid-commit.
+ ConstElementPtr guard = getItem(xpath + "/client-class");
+ if (guard) {
+ result->set("client-class", guard);
+ }
+ // no require-client-classes nor user-context.
+ // Skip max-pd-space-utilization.
+ // @todo option-data.
+ return (result);
+}
+
+ElementPtr
+TranslatorPdPool::getPdPoolKea(const string& xpath) {
+ ElementPtr result = Element::createMap();
+ ConstElementPtr pref = getItem(xpath + "/prefix");
+ if (!pref) {
+ isc_throw(BadValue, "getPdPoolKea: no prefix defined at " << xpath);
+ }
+ const string& prefix = pref->stringValue();
+ size_t slash = prefix.find("/");
+ if (slash == string::npos) {
+ isc_throw(BadValue,
+ "getPdPoolKea: no '/' in prefix '" << prefix << "'");
+ }
+ const string& address = prefix.substr(0, slash);
+ const string& length = prefix.substr(slash + 1, string::npos);
+ if (address.empty() || length.empty()) {
+ isc_throw(BadValue,
+ "getPdPoolKea: malformed prefix '" << prefix << "'");
+ }
+ result->set("prefix", Element::create(address));
+ try {
+ unsigned len = boost::lexical_cast<unsigned>(length);
+ result->set("prefix-len", Element::create(static_cast<int>(len)));
+ } catch (const boost::bad_lexical_cast&) {
+ isc_throw(BadValue,
+ "getPdPoolKea: bad prefix length in '" << prefix << "'");
+ }
+
+ ConstElementPtr xpref = getItem(xpath + "/excluded-prefix");
+ if (xpref) {
+ const string& xprefix = xpref->stringValue();
+ size_t xslash = xprefix.find("/");
+ if (xslash == string::npos) {
+ isc_throw(BadValue,
+ "getPdPoolKea: no '/' in excluded prefix '"
+ << xprefix << "'");
+ }
+ const string& xaddress = xprefix.substr(0, xslash);
+ const string& xlength = xprefix.substr(xslash + 1, string::npos);
+ if (xaddress.empty() || xlength.empty()) {
+ isc_throw(BadValue,
+ "getPdPoolKea: malformed excluded prefix '"
+ << xprefix << "'");
+ }
+ result->set("excluded-prefix", Element::create(xaddress));
+ try {
+ unsigned xlen = boost::lexical_cast<unsigned>(xlength);
+ result->set("excluded-prefix-len",
+ Element::create(static_cast<int>(xlen)));
+ } catch (const boost::bad_lexical_cast&) {
+ isc_throw(BadValue,
+ "getPdPoolKea: bad excluded prefix length in '"
+ << xprefix << "'");
+ }
+ }
+
+ ConstElementPtr delegated = getItem(xpath + "/delegated-len");
+ if (delegated) {
+ result->set("delegated-len", delegated);
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("option-data", options);
+ }
+ ConstElementPtr guard = getItem(xpath + "/client-class");
+ if (guard) {
+ result->set("client-class", guard);
+ }
+ ConstElementPtr required = getItems(xpath + "/require-client-classes");
+ if (required && (required->size() > 0)) {
+ result->set("require-client-classes", required);
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorPdPool::setPdPool(const string& xpath, ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ setPdPoolIetf6(xpath, elem);
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ setPdPoolKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setPdPool not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting pd-pool '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorPdPool::setPdPoolIetf6(const string& xpath, ConstElementPtr elem) {
+ ConstElementPtr base = elem->get("prefix");
+ ConstElementPtr length = elem->get("prefix-len");
+ if (!base || !length) {
+ isc_throw(BadValue,
+ "setPdPoolIetf6 requires prefix and prefix length: "
+ << elem->str());
+ }
+ 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);
+ ConstElementPtr valid_lifetime = elem->get("valid-lifetime");
+ if (valid_lifetime) {
+ setItem(xpath + "/valid-lifetime", valid_lifetime, SR_UINT32_T);
+ }
+ ConstElementPtr preferred_lifetime = elem->get("preferred-lifetime");
+ if (preferred_lifetime) {
+ setItem(xpath + "/preferred-lifetime",
+ preferred_lifetime, SR_UINT32_T);
+ }
+ ConstElementPtr renew_timer = elem->get("renew-timer");
+ if (renew_timer) {
+ setItem(xpath + "/renew-time", renew_timer, SR_UINT32_T);
+ }
+ ConstElementPtr rebind_timer = elem->get("rebind-timer");
+ if (rebind_timer) {
+ setItem(xpath + "/rebind-time", rebind_timer, SR_UINT32_T);
+ }
+ // Skip rapid-commit.
+ ConstElementPtr guard = elem->get("client-class");
+ if (guard) {
+ setItem(xpath + "/client-class", guard, SR_STRING_T);
+ }
+ // Set max pd space utilization to disabled.
+ setItem(xpath + "/max-pd-space-utilization",
+ Element::create(string("disabled")),
+ SR_ENUM_T);
+ // @todo option-data.
+}
+
+void
+TranslatorPdPool::setPdPoolKea(const string& xpath, ConstElementPtr elem) {
+ // Skip prefix as it is the key.
+ bool created = false;
+ ConstElementPtr delegated = elem->get("delegated-len");
+ if (delegated) {
+ setItem(xpath + "/delegated-len", delegated, SR_UINT8_T);
+ }
+ ConstElementPtr xprefix = elem->get("excluded-prefix");
+ ConstElementPtr xlen = elem->get("excluded-prefix-len");
+ if (xprefix && xlen) {
+ ostringstream xpref;
+ xpref << xprefix->stringValue() << "/" << xlen->intValue();
+ setItem(xpath + "/excluded-prefix", Element::create(xpref.str()),
+ SR_STRING_T);
+ created = true;
+ }
+ 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;
+ }
+ 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;
+ }
+ }
+ 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);
+ }
+}
+
+TranslatorPdPools::TranslatorPdPools(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorPdPool(session, model) {
+}
+
+TranslatorPdPools::~TranslatorPdPools() {
+}
+
+ElementPtr
+TranslatorPdPools::getPdPools(const string& xpath) {
+ try {
+ if ((model_ == IETF_DHCPV6_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getPdPoolsCommon(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting pd-pools at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getPdPools not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorPdPools::getPdPoolsCommon(const string& xpath) {
+ return getList<TranslatorPdPool>(xpath + "/pd-pool", *this,
+ &TranslatorPdPool::getPdPool);
+}
+
+void
+TranslatorPdPools::setPdPools(const string& xpath, ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ setPdPoolsId(xpath, elem);
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ setPdPoolsPrefix(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setPdPools not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting pools '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorPdPools::setPdPoolsId(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr pool = elem->get(i);
+ ostringstream prefix;
+ prefix << xpath << "/pd-pool[pool-id='" << i << "']";
+ setPdPool(prefix.str(), pool);
+ }
+}
+
+void
+TranslatorPdPools::setPdPoolsPrefix(const string& xpath,
+ ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr pool = elem->get(i);
+ if (!pool->contains("prefix") || !pool->contains("prefix-len")) {
+ isc_throw(BadValue, "pd-pool requires prefix and prefix length: "
+ << pool->str());
+ }
+ ostringstream prefix;
+ prefix << xpath << "/pd-pool[prefix='"
+ << pool->get("prefix")->stringValue() << "/"
+ << pool->get("prefix-len")->intValue() << "']";
+ setPdPool(prefix.str(), pool);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_pd_pool.h b/src/lib/yang/translator_pd_pool.h
new file mode 100644
index 0000000..6431b3f
--- /dev/null
+++ b/src/lib/yang/translator_pd_pool.h
@@ -0,0 +1,230 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_PD_POOL_H
+#define ISC_TRANSLATOR_PD_POOL_H 1
+
+#include <yang/translator_option_data.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Prefix delegation pool translation between YANG and JSON
+///
+/// JSON syntax for kea-dhcp6-server is:
+/// @code
+/// {
+/// "prefix": <prefix base>,
+/// "prefix-len": <prefix length>,
+/// "delegated-len": <delegated length>,
+/// "excluded-prefix": <excluded prefix>,
+/// "excluded-prefix-len": <excluded prefix length>,
+/// "option-data": [ <list of option data> ],
+/// "client-class": "<guard class name>",
+/// "require-client-classes": [ <list of required class names> ],
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax for ietf-dhcpv6-server is with pool-id as the key.
+/// @code
+/// +--rw pool-id uint32
+/// +--rw prefix inet:ipv6-prefix
+/// +--rw prefix-length uint8
+/// +--rw valid-lifetime yang:timeticks
+/// +--rw renew-time yang:timeticks
+/// +--rw rebind-time yang:timeticks
+/// +--rw preferred-lifetime yang:timeticks
+/// +--rw rapid-commit? boolean
+/// +--rw client-class? string
+/// +--rw max-pd-space-utilization? threshold
+/// +--rw option-set-id?
+/// /server/server-config/option-sets/option-set/option-set-id
+/// @endcode
+///
+/// YANG syntax for kea-dhcp6-server is with prefix as the key.
+/// @code
+/// +--rw pd-pool* [prefix]
+/// +--rw prefix inet:ipv6-prefix
+/// +--rw delegated-len? uint8
+/// +--rw option-data* [code space]
+/// +--rw client-class? string
+/// +--rw require-client-classes* string
+/// +--rw excluded-prefix? inet:ipv6-prefix
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "prefix": "2001:db8:0:1000::",
+/// "prefix-len": 56,
+/// "delegated-len": 64
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /ietf-dhcpv6-server:server (container)
+/// /ietf-dhcpv6-server:server/server-config (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges
+/// network-range[network-range-id='111'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges
+/// network-range[network-range-id='111']/network-range-id = 111
+/// /ietf-dhcpv6-server:server/server-config/network-ranges
+/// network-range[network-range-id='111']/network-prefix = 2001:db8::/48
+/// /ietf-dhcpv6-server:server/server-config/network-ranges
+/// network-range[network-range-id='111']/pd-pools (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges
+/// network-range[network-range-id='111']/pd-pools/
+/// pd-pool[pool-id='0'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// pd-pool[pool-id='0']/pool-id = 0
+/// network-range[network-range-id='111']/pd-pools/
+/// pd-pool[pool-id='0']/prefix = 2001:db8:0:1000::/56
+/// /ietf-dhcpv6-server:server/server-config/network-ranges
+/// network-range[network-range-id='111']/pd-pools/
+/// pd-pool[pool-id='0']/prefix-length = 56
+/// /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
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/subnet6[id='111'] (list instance)
+/// /kea-dhcp6-server:config/subnet6[id='111']/id = 111
+/// /kea-dhcp6-server:config/subnet6[id='111']/subnet = 2001:db8::/48
+/// /kea-dhcp6-server:config/subnet6[id='111']/
+/// pd-pool[prefix='2001:db8:0:1000::/56' (list instance)
+/// /kea-dhcp6-server:config/subnet6[id='111']/
+/// pd-pool[prefix='2001:db8:0:1000::/56'/prefix = 2001:db8:0:1000::/56
+/// /kea-dhcp6-server:config/subnet6[id='111']/
+/// pd-pool[prefix='2001:db8:0:1000::/56'/delegated-len = 64
+/// @endcode
+
+/// @brief A translator class for converting a pd-pool between
+/// YANG and JSON.
+///
+/// Currently supported models:
+/// - kea-dhcp6-server
+/// - ietf-dhcpv6-server (partial support)
+class TranslatorPdPool : virtual public TranslatorOptionDataList {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorPdPool(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorPdPool();
+
+ /// @brief Get and translate a pd-pool from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the pd-pool.
+ /// @return JSON representation of the pd-pool.
+ /// @throw SysrepoError when sysrepo raises an error.
+ /// @throw BadValue on pd-pool without well formed prefix.
+ isc::data::ElementPtr getPdPool(const std::string& xpath);
+
+ /// @brief Translate and set pd-pool from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the pd-pool.
+ /// @param elem The JSON element.
+ void setPdPool(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getPdPool for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the pd-pool.
+ /// @return JSON representation of the pd-pool.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getPdPoolIetf6(const std::string& xpath);
+
+ /// @brief setPdPool for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the pd-pool.
+ /// @param elem The JSON element.
+ /// @throw BadValue on pd-pool without prefix or prefix length.
+ void setPdPoolIetf6(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief getPdPool for kea-dhcp6-server.
+ ///
+ /// @param xpath The xpath of the pd-pool.
+ /// @return JSON representation of the pd-pool.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getPdPoolKea(const std::string& xpath);
+
+ /// @brief setPdPool for kea-dhcp6-server.
+ ///
+ /// @param xpath The xpath of the pd-pool.
+ /// @param elem The JSON element.
+ void setPdPoolKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting a pd-pool list between
+/// YANG and JSON.
+///
+/// Currently supports the following models:
+/// - kea-dhcp6-server
+/// - ietf-dhcpv6-server (partial support)
+class TranslatorPdPools : virtual public TranslatorPdPool {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorPdPools(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorPdPools();
+
+ /// @brief Get and translate pd-pools from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the pd-pool list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getPdPools(const std::string& xpath);
+
+ /// @brief Translate and set pd-pools from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the pd-pool list.
+ /// @param elem The JSON element.
+ void setPdPools(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getPdPools common part.
+ ///
+ /// @param xpath The xpath of the pd-pool list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getPdPoolsCommon(const std::string& xpath);
+
+ /// @brief setPdPools using pool-id.
+ ///
+ /// @param xpath The xpath of the pd-pool list.
+ /// @param elem The JSON element.
+ void setPdPoolsId(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief setPdPools using prefix.
+ ///
+ /// @param xpath The xpath of the pd-pool list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on pd-pool without prefix or prefix length.
+ void setPdPoolsPrefix(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_PD_POOL_H
diff --git a/src/lib/yang/translator_pool.cc b/src/lib/yang/translator_pool.cc
new file mode 100644
index 0000000..d459385
--- /dev/null
+++ b/src/lib/yang/translator_pool.cc
@@ -0,0 +1,359 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <asiolink/io_address.h>
+#include <asiolink/addr_utilities.h>
+#include <yang/adaptor.h>
+#include <yang/translator_pool.h>
+#include <yang/yang_models.h>
+#include <boost/lexical_cast.hpp>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::asiolink;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorPool::TranslatorPool(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model) {
+}
+
+TranslatorPool::~TranslatorPool() {
+}
+
+ElementPtr
+TranslatorPool::getPool(const string& xpath) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ return (getPoolIetf6(xpath));
+ } else if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getPoolKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting pool at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getPool not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorPool::getPoolIetf6(const string& xpath) {
+ ElementPtr result = Element::createMap();
+ // Skip pool-id which exists but is not used.
+ ConstElementPtr pool = getItem(xpath + "/pool-prefix");
+ if (!pool) {
+ isc_throw(BadValue, "getPoolIetf6 requires pool prefix at " << xpath);
+ }
+ result->set("pool", pool);
+ // Ignore start-address - end-address as prefix form is mandatory?
+ ConstElementPtr guard = getItem(xpath + "/client-class");
+ if (guard) {
+ result->set("client-class", guard);
+ }
+ ConstElementPtr valid_lifetime = getItem(xpath + "/valid-lifetime");
+ if (valid_lifetime) {
+ result->set("valid-lifetime", valid_lifetime);
+ }
+ ConstElementPtr preferred_lifetime =
+ getItem(xpath + "/preferred-lifetime");
+ if (preferred_lifetime) {
+ result->set("preferred-lifetime", preferred_lifetime);
+ }
+ ConstElementPtr renew_time = getItem(xpath + "/renew-time");
+ if (renew_time) {
+ result->set("renew-timer", renew_time);
+ }
+ ConstElementPtr rebind_time = getItem(xpath + "/rebind-time");
+ if (rebind_time) {
+ result->set("rebind-timer", rebind_time);
+ }
+ // Skip max-addr-count
+ // @todo: option-data
+ /// no require-client-classes nor user-context.
+ // Skip rapid-commit.
+ if (result->empty()) {
+ return ElementPtr();
+ }
+ return (result);
+}
+
+ElementPtr
+TranslatorPool::getPoolKea(const string& xpath) {
+ ElementPtr result = Element::createMap();
+ ConstElementPtr prefix = getItem(xpath + "/prefix");
+ if (prefix) {
+ result->set("pool", prefix);
+ } else {
+ ConstElementPtr start_addr = getItem(xpath + "/start-address");
+ ConstElementPtr end_addr = getItem(xpath + "/end-address");
+ if (!start_addr || !end_addr) {
+ isc_throw(BadValue, "getPoolKea requires either prefix or "
+ "both start and end addresses at " << xpath);
+ }
+ ostringstream range;
+ range << start_addr->stringValue() << " - "
+ << end_addr->stringValue();
+ result->set("pool", Element::create(range.str()));
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("option-data", options);
+ }
+ ConstElementPtr guard = getItem(xpath + "/client-class");
+ if (guard) {
+ result->set("client-class", guard);
+ }
+ ConstElementPtr required = getItems(xpath + "/require-client-classes");
+ if (required && (required->size() > 0)) {
+ result->set("require-client-classes", required);
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ return (result);
+}
+
+void
+TranslatorPool::setPool(const string& xpath, ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ setPoolIetf6(xpath, elem);
+ } else if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setPoolKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setPool not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting pool '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorPool::setPoolIetf6(const string& xpath, ConstElementPtr elem) {
+ ConstElementPtr pool = elem->get("pool");
+ if (!pool) {
+ isc_throw(BadValue, "setPoolIetf6 requires pool: " << elem->str());
+ }
+ string prefix = pool->stringValue();
+ if (prefix.find("/") == string::npos) {
+ isc_throw(BadValue,
+ "setPoolIetf only supports pools in prefix (vs range) "
+ "format and was called with '" << prefix << "'");
+ }
+ setItem(xpath + "/pool-prefix", pool, SR_STRING_T);
+ 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);
+ setItem(xpath + "/end-address",
+ Element::create(lastAddrInPrefix(base, plen).toText()),
+ SR_STRING_T);
+ ConstElementPtr valid_lifetime = elem->get("valid-lifetime");
+ if (valid_lifetime) {
+ setItem(xpath + "/valid-lifetime", valid_lifetime, SR_UINT32_T);
+ }
+ ConstElementPtr preferred_lifetime = elem->get("preferred-lifetime");
+ if (preferred_lifetime) {
+ setItem(xpath + "/preferred-lifetime",
+ preferred_lifetime, SR_UINT32_T);
+ }
+ ConstElementPtr renew_timer = elem->get("renew-timer");
+ if (renew_timer) {
+ setItem(xpath + "/renew-time", renew_timer, SR_UINT32_T);
+ }
+ ConstElementPtr rebind_timer = elem->get("rebind-timer");
+ if (rebind_timer) {
+ setItem(xpath + "/rebind-time", rebind_timer, SR_UINT32_T);
+ }
+ // skip rapid-commit
+ ConstElementPtr guard = elem->get("client-class");
+ if (guard) {
+ setItem(xpath + "/client-class", guard, SR_STRING_T);
+ }
+ // 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);
+}
+
+void
+TranslatorPool::setPoolKea(const string& xpath, ConstElementPtr elem) {
+ ConstElementPtr pool = elem->get("pool");
+ if (!pool) {
+ isc_throw(BadValue, "setPoolKea requires pool: " << elem->str());
+ }
+ bool created = false;
+ 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;
+ }
+ // 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;
+ }
+ 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;
+ }
+ }
+ 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);
+ }
+}
+
+void
+TranslatorPool::getAddresses(const string& prefix,
+ string& start_address, string& end_address) {
+ size_t slash = prefix.find("/");
+ if (slash != string::npos) {
+ 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));
+ start_address = firstAddrInPrefix(IOAddress(addr), plen).toText();
+ end_address = lastAddrInPrefix(IOAddress(addr), plen).toText();
+ return;
+ }
+ size_t dash = prefix.find("-");
+ if (dash == string::npos) {
+ isc_throw(BadValue,
+ "getAddresses called with invalid prefix: " << prefix);
+ }
+ start_address = prefix.substr(0, prefix.find_first_of(" -"));
+ end_address = prefix.substr(prefix.find_last_of(" -") + 1, string::npos);
+}
+
+TranslatorPools::TranslatorPools(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorPool(session, model) {
+}
+
+TranslatorPools::~TranslatorPools() {
+}
+
+ElementPtr
+TranslatorPools::getPools(const string& xpath) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ return (getPoolsIetf(xpath));
+ } else if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getPoolsKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting pools at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getPools not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorPools::getPoolsIetf(const string& xpath) {
+ return getList<TranslatorPool>(xpath + "/address-pool", *this,
+ &TranslatorPool::getPool);
+}
+
+ElementPtr
+TranslatorPools::getPoolsKea(const string& xpath) {
+ return getList<TranslatorPool>(xpath + "/pool", *this,
+ &TranslatorPool::getPool);
+}
+
+void
+TranslatorPools::setPools(const string& xpath, ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ setPoolsById(xpath, elem);
+ } else if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setPoolsByAddresses(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setPools not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting pools '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorPools::setPoolsById(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr pool = elem->get(i);
+ ostringstream prefix;
+ prefix << xpath << "/address-pool[pool-id='" << i << "']";
+ setPool(prefix.str(), pool);
+ }
+}
+
+void
+TranslatorPools::setPoolsByAddresses(const string& xpath,
+ ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr pool = elem->get(i);
+ if (!pool->contains("pool")) {
+ isc_throw(BadValue, "setPoolsByAddresses: missing required pool: "
+ << pool->str());
+ }
+ string pref = pool->get("pool")->stringValue();
+ string start_addr;
+ string end_addr;
+ getAddresses(pref, start_addr, end_addr);
+ ostringstream prefix;
+ prefix << xpath << "/pool[start-address='" << start_addr
+ << "'][end-address='" << end_addr << "']";
+ setPool(prefix.str(), pool);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_pool.h b/src/lib/yang/translator_pool.h
new file mode 100644
index 0000000..f9a9bc7
--- /dev/null
+++ b/src/lib/yang/translator_pool.h
@@ -0,0 +1,249 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_POOL_H
+#define ISC_TRANSLATOR_POOL_H 1
+
+#include <yang/translator_option_data.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// @brief A translator class for converting a pool between YANG and JSON.
+///
+/// Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.
+///
+/// JSON syntax for both kea-dhcp4 and kea-dhcp6 is:
+/// @code
+/// {
+/// "pool": "<pool prefix or start - end addresses>",
+/// "option-data": [ <list of option data> ],
+/// "client-class": "<guard class name>",
+/// "require-client-classes": [ <list of required class names> ],
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax is for ietf-dhcpv6-server is with pool-id as the key:
+/// @code
+/// +--rw pool-id uint32
+/// +--rw pool-prefix inet:ipv6-prefix
+/// +--rw start-address inet:ipv6-address-no-zone
+/// +--rw end-address inet:ipv6-address-no-zone
+/// +--rw valid-lifetime yang:timeticks
+/// +--rw renew-time yang:timeticks
+/// +--rw rebind-time yang:timeticks
+/// +--rw preferred-lifetime yang:timeticks
+/// +--rw rapid-commit? boolean
+/// +--rw client-class? string
+/// +--rw max-address-count threshold
+/// +--rw option-set-id
+/// /server/server-config/option-sets/option-set/option-set-id
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46] is with start-address and end-address
+/// as the keys:
+/// @code
+/// +--rw pool* [start-address end-address]
+/// +--rw prefix? inet:ipv[46]-prefix
+/// +--rw start-address inet:ipv[46]-address
+/// +--rw end-address inet:ipv[46]-address
+/// +--rw option-data* [code space]
+/// +--rw client-class? string
+/// +--rw require-client-classes* string
+/// +--rw user-context? user-context
+/// @endcode
+///
+/// An example in JSON and YANG formats for the IETF model:
+/// @code
+/// [
+/// {
+/// "pool": "2001:db8::/112"
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /ietf-dhcpv6-server:server (container)
+/// /ietf-dhcpv6-server:server/server-config (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='111'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='111']/network-range-id = 111
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='111']/network-prefix = 2001:db8::/48
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='111']/address-pools (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='111']/address-pools/
+/// address-pool[pool-id='0'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='111']/address-pools/
+/// address-pool[pool-id='0']/pool-id = 0
+/// /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
+/// /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
+/// /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
+/// /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
+/// @endcode
+///
+/// An example in JSON and YANG formats for the Kea model:
+/// @code
+/// [
+/// {
+/// "pool": "2001:db8::1 - 2001:db8::100"
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/subnet6[id='111'] (list instance)
+/// /kea-dhcp6-server:config/subnet6[id='111']/id = 111
+/// /kea-dhcp6-server:config/subnet6[id='111']/subnet = 2001:db8::/48
+/// /kea-dhcp6-server:config/subnet6[id='111']/
+/// pool[start-address='2001:db8::1'][end-address='2001:db8::100']
+/// (list instance)
+/// /kea-dhcp6-server:config/subnet6[id='111']/
+/// pool[start-address='2001:db8::1'][end-address='2001:db8::100']/
+/// start-address = 2001:db8::1
+/// /kea-dhcp6-server:config/subnet6[id='111']/
+/// pool[start-address='2001:db8::1'][end-address='2001:db8::100']/
+/// end-address = 2001:db8::100
+/// @endcode
+class TranslatorPool : virtual public TranslatorOptionDataList {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorPool(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorPool();
+
+ /// @brief Get and translate a pool from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the pool.
+ /// @return JSON representation of the pool.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getPool(const std::string& xpath);
+
+ /// @brief Translate and set (address) pool from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the pool.
+ /// @param elem The JSON element.
+ void setPool(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+ /// @brief Get start and end addresses from prefix.
+ ///
+ /// @param prefix The prefix string.
+ /// @param start_address The reference to the start_address.
+ /// @param end_address The reference to the end_address.
+ /// @throw BadValue when the prefix is not correctly formed.
+ static void getAddresses(const std::string& prefix,
+ std::string& start_address,
+ std::string& end_address);
+
+protected:
+ /// @brief getPool for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the pool.
+ /// @return JSON representation of the pool.
+ /// @throw BadValue on pool without prefix.
+ isc::data::ElementPtr getPoolIetf6(const std::string& xpath);
+
+ /// @brief setPool for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the pool.
+ /// @param elem The JSON element.
+ /// @throw BadValue on pool without prefix and with a range which is
+ /// not a prefix.
+ void setPoolIetf6(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief getPool for kea-dhcp[46]-server.
+ ///
+ /// @param xpath The xpath of the pool.
+ /// @return JSON representation of the pool.
+ /// @throw BadValue on a pool without prefix and start or end address.
+ isc::data::ElementPtr getPoolKea(const std::string& xpath);
+
+ /// @brief setPool for kea-dhcp[46]-server.
+ ///
+ /// @param xpath The xpath of the pool.
+ /// @param elem The JSON element.
+ /// @throw BadValue on a pool without a well formed prefix.
+ void setPoolKea(const std::string& xpath, isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting pools between YANG and JSON.
+///
+/// Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.
+class TranslatorPools : virtual public TranslatorPool {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorPools(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorPools();
+
+ /// @brief Get and translate pools from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the pool list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getPools(const std::string& xpath);
+
+ /// @brief Translate and set (address) pools from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the pool list.
+ /// @param elem The JSON element.
+ void setPools(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getPools for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the pool list.
+ isc::data::ElementPtr getPoolsIetf(const std::string& xpath);
+
+ /// @brief getPools for kea-dhcp[46]-server.
+ ///
+ /// @param xpath The xpath of the pool list.
+ isc::data::ElementPtr getPoolsKea(const std::string& xpath);
+
+ /// @brief setPools using pool-id.
+ ///
+ /// @param xpath The xpath of the pool list.
+ /// @param elem The JSON element.
+ void setPoolsById(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief setPools using address pair.
+ ///
+ /// @param xpath The xpath of the pool list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on a pool without a prefix.
+ void setPoolsByAddresses(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_POOL_H
diff --git a/src/lib/yang/translator_shared_network.cc b/src/lib/yang/translator_shared_network.cc
new file mode 100644
index 0000000..4f4622a
--- /dev/null
+++ b/src/lib/yang/translator_shared_network.cc
@@ -0,0 +1,422 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/translator_shared_network.h>
+#include <yang/adaptor.h>
+#include <yang/yang_models.h>
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorSharedNetwork::TranslatorSharedNetwork(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorPool(session, model),
+ TranslatorPools(session, model),
+ TranslatorPdPool(session, model),
+ TranslatorPdPools(session, model),
+ TranslatorHost(session, model),
+ TranslatorHosts(session, model),
+ TranslatorSubnet(session, model),
+ TranslatorSubnets(session, model) {
+}
+
+TranslatorSharedNetwork::~TranslatorSharedNetwork() {
+}
+
+ElementPtr
+TranslatorSharedNetwork::getSharedNetwork(const string& xpath) {
+ try {
+ if (model_ == KEA_DHCP4_SERVER) {
+ return (getSharedNetworkKea(xpath, "subnet4"));
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ return (getSharedNetworkKea(xpath, "subnet6"));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting shared network at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getSharedNetwork not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorSharedNetwork::getSharedNetworkKea(const string& xpath,
+ const std::string& subsel) {
+ ElementPtr result = Element::createMap();
+ ConstElementPtr name = getItem(xpath + "/name");
+ if (!name) {
+ // Can't happen as the name is the key.
+ isc_throw(Unexpected, "getSharedNetworkKea requires name: " << xpath);
+ }
+ result->set("name", name);
+ ConstElementPtr subnets = getSubnets(xpath);
+ if (subnets && (subnets->size() > 0)) {
+ result->set(subsel, subnets);
+ }
+ if (subsel == "subnet6") {
+ ConstElementPtr preferred = getItem(xpath + "/preferred-lifetime");
+ if (preferred) {
+ result->set("preferred-lifetime", preferred);
+ }
+ ConstElementPtr min_pref = getItem(xpath + "/min-preferred-lifetime");
+ if (min_pref) {
+ result->set("min-preferred-lifetime", min_pref);
+ }
+ ConstElementPtr max_pref = getItem(xpath + "/max-preferred-lifetime");
+ if (max_pref) {
+ result->set("max-preferred-lifetime", max_pref);
+ }
+ }
+ ConstElementPtr valid = getItem(xpath + "/valid-lifetime");
+ if (valid) {
+ result->set("valid-lifetime", valid);
+ }
+ ConstElementPtr min_valid = getItem(xpath + "/min-valid-lifetime");
+ if (min_valid) {
+ result->set("min-valid-lifetime", min_valid);
+ }
+ ConstElementPtr max_valid = getItem(xpath + "/max-valid-lifetime");
+ if (max_valid) {
+ result->set("max-valid-lifetime", max_valid);
+ }
+ ConstElementPtr renew = getItem(xpath + "/renew-timer");
+ if (renew) {
+ result->set("renew-timer", renew);
+ }
+ ConstElementPtr rebind = getItem(xpath + "/rebind-timer");
+ if (rebind) {
+ result->set("rebind-timer", rebind);
+ }
+ ConstElementPtr calculate = getItem(xpath + "/calculate-tee-times");
+ if (calculate) {
+ result->set("calculate-tee-times", calculate);
+ }
+ ConstElementPtr t1_percent = getItem(xpath + "/t1-percent");
+ if (t1_percent) {
+ result->set("t1-percent", t1_percent);
+ }
+ ConstElementPtr t2_percent = getItem(xpath + "/t2-percent");
+ if (t2_percent) {
+ result->set("t2-percent", t2_percent);
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("option-data", options);
+ }
+ ConstElementPtr interface = getItem(xpath + "/interface");
+ if (interface) {
+ result->set("interface", interface);
+ }
+ if (subsel == "subnet6") {
+ ConstElementPtr interface_id = getItem(xpath + "/interface-id");
+ if (interface_id) {
+ result->set("interface-id", interface_id);
+ }
+ ConstElementPtr rapid_commit = getItem(xpath + "/rapid-commit");
+ if (rapid_commit) {
+ result->set("rapid-commit", rapid_commit);
+ }
+ }
+ ConstElementPtr guard = getItem(xpath + "/client-class");
+ if (guard) {
+ result->set("client-class", guard);
+ }
+ ConstElementPtr required = getItems(xpath + "/require-client-classes");
+ if (required && (required->size() > 0)) {
+ result->set("require-client-classes", required);
+ }
+ ConstElementPtr mode = getItem(xpath + "/reservation-mode");
+ if (mode) {
+ result->set("reservation-mode", mode);
+ }
+ ConstElementPtr relay = getItems(xpath + "/relay/ip-addresses");
+ if (relay && (relay->size() > 0)) {
+ ElementPtr relay_map = Element::createMap();
+ relay_map->set("ip-addresses", relay);
+ result->set("relay", relay_map);
+ }
+ if (subsel == "subnet4") {
+ ConstElementPtr match = getItem(xpath + "/match-client-id");
+ if (match) {
+ result->set("match-client-id", match);
+ }
+ ConstElementPtr auth = getItem(xpath + "/authoritative");
+ if (auth) {
+ result->set("authoritative", auth);
+ }
+ ConstElementPtr next = getItem(xpath + "/next-server");
+ if (next) {
+ result->set("next-server", next);
+ }
+ ConstElementPtr hostname = getItem(xpath + "/server-hostname");
+ if (hostname) {
+ result->set("server-hostname", hostname);
+ }
+ ConstElementPtr boot = getItem(xpath + "/boot-file-name");
+ if (boot) {
+ result->set("boot-file-name", boot);
+ }
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ checkAndGetLeaf(result, xpath, "cache-max-age");
+ checkAndGetLeaf(result, xpath, "cache-threshold");
+ checkAndGetLeaf(result, xpath, "ddns-generated-prefix");
+ checkAndGetLeaf(result, xpath, "ddns-override-client-update");
+ checkAndGetLeaf(result, xpath, "ddns-override-no-update");
+ checkAndGetLeaf(result, xpath, "ddns-qualifying-suffix");
+ checkAndGetLeaf(result, xpath, "ddns-replace-client-name");
+ checkAndGetLeaf(result, xpath, "ddns-send-updates");
+ checkAndGetLeaf(result, xpath, "ddns-update-on-renew");
+ checkAndGetLeaf(result, xpath, "ddns-use-conflict-resolution");
+ checkAndGetLeaf(result, xpath, "hostname-char-replacement");
+ checkAndGetLeaf(result, xpath, "hostname-char-set");
+ checkAndGetLeaf(result, xpath, "reservations-global");
+ checkAndGetLeaf(result, xpath, "reservations-in-subnet");
+ checkAndGetLeaf(result, xpath, "reservations-out-of-pool");
+ checkAndGetLeaf(result, xpath, "store-extended-info");
+ return (result);
+}
+
+void
+TranslatorSharedNetwork::setSharedNetwork(const string& xpath,
+ ConstElementPtr elem) {
+ try {
+ if (model_ == KEA_DHCP4_SERVER) {
+ setSharedNetworkKea(xpath, elem, "subnet4");
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ setSharedNetworkKea(xpath, elem, "subnet6");
+ } else {
+ isc_throw(NotImplemented,
+ "setSharedNetwork not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting shared network '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorSharedNetwork::setSharedNetworkKea(const string& xpath,
+ ConstElementPtr elem,
+ const std::string& subsel) {
+ // Skip name which is the key.
+ ConstElementPtr subnets = elem->get(subsel);
+ if (subnets && (subnets->size() > 0)) {
+ setSubnets(xpath, subnets);
+ }
+ if (subsel == "subnet6") {
+ ConstElementPtr preferred = elem->get("preferred-lifetime");
+ if (preferred) {
+ setItem(xpath + "/preferred-lifetime", preferred, SR_UINT32_T);
+ }
+ ConstElementPtr min_pref = elem->get("min-preferred-lifetime");
+ if (min_pref) {
+ setItem(xpath + "/min-preferred-lifetime", min_pref, SR_UINT32_T);
+ }
+ ConstElementPtr max_pref = elem->get("max-preferred-lifetime");
+ if (max_pref) {
+ setItem(xpath + "/max-preferred-lifetime", max_pref, SR_UINT32_T);
+ }
+ }
+ ConstElementPtr valid = elem->get("valid-lifetime");
+ if (valid) {
+ setItem(xpath + "/valid-lifetime", valid, SR_UINT32_T);
+ }
+ ConstElementPtr min_valid = elem->get("min-valid-lifetime");
+ if (min_valid) {
+ setItem(xpath + "/min-valid-lifetime", min_valid, SR_UINT32_T);
+ }
+ ConstElementPtr max_valid = elem->get("max-valid-lifetime");
+ if (max_valid) {
+ setItem(xpath + "/max-valid-lifetime", max_valid, SR_UINT32_T);
+ }
+ ConstElementPtr renew = elem->get("renew-timer");
+ if (renew) {
+ setItem(xpath + "/renew-timer", renew, SR_UINT32_T);
+ }
+ ConstElementPtr rebind = elem->get("rebind-timer");
+ if (rebind) {
+ setItem(xpath + "/rebind-timer", rebind, SR_UINT32_T);
+ }
+ ConstElementPtr calculate = elem->get("calculate-tee-times");
+ if (calculate) {
+ setItem(xpath + "/calculate-tee-times", calculate, SR_BOOL_T);
+ }
+ ConstElementPtr t1_percent = elem->get("t1-percent");
+ if (t1_percent) {
+ setItem(xpath + "/t1-percent", t1_percent, SR_DECIMAL64_T);
+ }
+ ConstElementPtr t2_percent = elem->get("t2-percent");
+ if (t2_percent) {
+ setItem(xpath + "/t2-percent", t2_percent, SR_DECIMAL64_T);
+ }
+ ConstElementPtr options = elem->get("option-data");
+ if (options && (options->size() > 0)) {
+ setOptionDataList(xpath, options);
+ }
+ ConstElementPtr interface = elem->get("interface");
+ if (interface) {
+ setItem(xpath + "/interface", interface, SR_STRING_T);
+ }
+ if (subsel == "subnet6") {
+ ConstElementPtr interface_id = elem->get("interface-id");
+ if (interface_id) {
+ setItem(xpath + "/interface-id", interface_id, SR_STRING_T);
+ }
+ ConstElementPtr rapid_commit = elem->get("rapid-commit");
+ if (rapid_commit) {
+ setItem(xpath + "/rapid-commit", rapid_commit, SR_BOOL_T);
+ }
+ }
+ ConstElementPtr guard = elem->get("client-class");
+ if (guard) {
+ setItem(xpath + "/client-class", guard, SR_STRING_T);
+ }
+ 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);
+ }
+ }
+ ConstElementPtr mode = elem->get("reservation-mode");
+ if (mode) {
+ setItem(xpath + "/reservation-mode", mode, SR_ENUM_T);
+ }
+ 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);
+ } else if (addresses && (addresses->size() > 0)) {
+ for (ConstElementPtr addr : addresses->listValue()) {
+ setItem(xpath + "/relay/ip-addresses", addr, SR_STRING_T);
+ }
+ }
+ }
+ if (subsel == "subnet4") {
+ ConstElementPtr match = elem->get("match-client-id");
+ if (match) {
+ setItem(xpath + "/match-client-id", match, SR_BOOL_T);
+ }
+ ConstElementPtr auth = elem->get("authoritative");
+ if (auth) {
+ setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+ }
+ ConstElementPtr next = elem->get("next-server");
+ if (next) {
+ setItem(xpath + "/next-server", next, SR_STRING_T);
+ }
+ ConstElementPtr hostname = elem->get("server-hostname");
+ if (hostname) {
+ setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
+ }
+ ConstElementPtr boot = elem->get("boot-file-name");
+ if (boot) {
+ setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ }
+ }
+ 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);
+}
+
+TranslatorSharedNetworks::TranslatorSharedNetworks(S_Session session,
+ const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorPool(session, model),
+ TranslatorPools(session, model),
+ TranslatorPdPool(session, model),
+ TranslatorPdPools(session, model),
+ TranslatorHost(session, model),
+ TranslatorHosts(session, model),
+ TranslatorSubnet(session, model),
+ TranslatorSubnets(session, model),
+ TranslatorSharedNetwork(session, model) {
+}
+
+TranslatorSharedNetworks::~TranslatorSharedNetworks() {
+}
+
+ElementPtr
+TranslatorSharedNetworks::getSharedNetworks(const string& xpath) {
+ return getList<TranslatorSharedNetwork>(xpath + "/shared-network", *this,
+ &TranslatorSharedNetwork::getSharedNetwork);
+}
+
+void
+TranslatorSharedNetworks::setSharedNetworks(const string& xpath,
+ ConstElementPtr elem) {
+ try {
+ if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setSharedNetworksKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setSharedNetworks not implemented for the model: "
+ << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting shared networks '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorSharedNetworks::setSharedNetworksKea(const string& xpath,
+ ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr network = elem->get(i);
+ if (!network->contains("name")) {
+ isc_throw(BadValue, "setSharedNetworksKea requires name: "
+ << network->str());
+ }
+ string name = network->get("name")->stringValue();
+ ostringstream key;
+ key<< xpath << "/shared-network[name='" << name << "']";
+ setSharedNetwork(key.str(), network);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_shared_network.h b/src/lib/yang/translator_shared_network.h
new file mode 100644
index 0000000..799af4b
--- /dev/null
+++ b/src/lib/yang/translator_shared_network.h
@@ -0,0 +1,260 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_SHARED_NETWORK_H
+#define ISC_TRANSLATOR_SHARED_NETWORK_H 1
+
+#include <yang/translator.h>
+#include <yang/translator_subnet.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Shared network translation between YANG and JSON
+///
+/// JSON syntax for kea-dhcp4 is:
+/// @code
+/// {
+/// "name": <name>,
+/// "subnet4": <subnet list>,
+/// "valid-lifetime": <valid lifetime>,
+/// "min-valid-lifetime": <minimum valid lifetime>,
+/// "max-valid-lifetime": <maximum valid lifetime>,
+/// "renew-timer": <renew timer>,
+/// "rebind-timer": <rebind timer>,
+/// "calculate-tee-times": <calculate T1/T2 times>,
+/// "t1-percent": <T1 percent>,
+/// "t2-percent": <T2 percent>,
+/// "option-data": [ <list of option data> ],
+/// "interface": "<interface>",
+/// "client-class": "<guard class name>",
+/// "require-client-classes": [ <list of required class names> ],
+/// "reservation-mode": <host reservation mode>,
+/// "relay": <relay ip address(es)>,
+/// "match-client-id": <match client id flag>,
+/// "next-server": "<next server>",
+/// "server-hostname": "<server hostname>",
+/// "boot-file-name": "<boot file name>",
+/// "authoritative": <authoritative flag>,
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// JSON syntax for kea-dhcp6 is:
+/// @code
+/// {
+/// "name": <name>,
+/// "subnet6": <subnet list>,
+/// "preferred-lifetime": <preferred lifetime>,
+/// "min-preferred-lifetime": <minimum preferred lifetime>,
+/// "max-preferred-lifetime": <maximum preferred lifetime>,
+/// "valid-lifetime": <valid lifetime>,
+/// "min-valid-lifetime": <minimum valid lifetime>,
+/// "max-valid-lifetime": <maximum valid lifetime>,
+/// "renew-timer": <renew timer>,
+/// "rebind-timer": <rebind timer>,
+/// "calculate-tee-times": <calculate T1/T2 times>,
+/// "t1-percent": <T1 percent>,
+/// "t2-percent": <T2 percent>,
+/// "option-data": [ <list of option data> ],
+/// "interface": "<interface>",
+/// "interface-id": "<interface id>",
+/// "rapid-commit": <rapid commit flag>,
+/// "client-class": "<guard class name>",
+/// "require-client-classes": [ <list of required class names> ],
+/// "reservation-mode": <host reservation mode>,
+/// "relay": <relay ip address(es)>,
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46]-server is with name as the list key:
+/// @code
+/// +--rw shared-network* [name]
+/// +--rw name string
+/// +--rw interface? string
+/// +--rw renew-timer? uint32
+/// +--rw rebind-timer? uint32
+/// +--rw option-data* [code space]
+/// +--rw reservation-mode? host-reservation-mode
+/// +--rw client-class? string
+/// +--rw require-client-classes* string
+/// +--rw valid-lifetime? uint32
+/// +--rw min-valid-lifetime? uint32
+/// +--rw max-valid-lifetime? uint32
+/// +--rw calculate-tee-times? boolean
+/// +--rw t1-percent? decimal64
+/// +--rw t2-percent? decimal64
+/// +--rw cache-max-age? uint32
+/// +--rw cache-threshold? decimal64
+/// +--rw ddns-generated-prefix? string
+/// +--rw ddns-override-client-update? boolean
+/// +--rw ddns-override-no-update? boolean
+/// +--rw ddns-qualifying-suffix? string
+/// +--rw ddns-replace-client-name? string
+/// +--rw ddns-send-updates? boolean
+/// +--rw ddns-update-on-renew? boolean
+/// +--rw ddns-use-conflict-resolution? boolean
+/// +--rw store-extended-info? boolean
+/// +--rw hostname-char-replacement? string
+/// +--rw hostname-char-set? string
+/// +--rw reservations-global? boolean
+/// +--rw reservations-in-subnet? boolean
+/// +--rw reservations-out-of-pool? boolean
+/// +--rw user-context? user-context
+///
+/// DHCPv4 only:
+/// +--rw subnet4*
+/// +--rw match-client-id? boolean
+/// +--rw next-server? inet:ipv4-address
+/// +--rw server-hostname? string
+/// +--rw boot-file-name? string
+/// +--rw authoritative? boolean
+/// +--rw relay
+/// | +--rw ip-addresses* inet:ipv4-address
+///
+/// DHCPv6 only:
+/// +--rw subnet6*
+/// +--rw preferred-lifetime? uint32
+/// +--rw min-preferred-lifetime? uint32
+/// +--rw max-preferred-lifetime? uint32
+/// +--rw interface-id? string
+/// +--rw rapid-commit? boolean
+/// +--rw relay
+/// | +--rw ip-addresses* inet:ipv6-address
+/// @endcode
+///
+/// An example in JSON and YANG formats:
+/// @code
+/// [
+/// {
+/// "name": "foo",
+/// "subnet6":
+/// [
+/// {
+/// "subnet": "2001:db8::/48",
+/// "id": 123
+/// }
+/// ]
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp6-server:config (container)
+/// /kea-dhcp6-server:config/shared-network[name='foo'] (list instance)
+/// /kea-dhcp6-server:config/shared-network[name='foo']/name = foo
+/// /kea-dhcp6-server:config/shared-network[name='foo']/
+/// subnet6[id='123'] (list instance)
+/// /kea-dhcp6-server:config/shared-network[name='foo']/
+/// subnet6[id='123']/id = 123
+/// /kea-dhcp6-server:config/shared-network[name='foo']/
+/// subnet6[id='123']/subnet = 2001:db8::/48
+/// @endcode
+
+/// @brief A translator class for converting a shared network between
+/// YANG and JSON.
+///
+/// Currently supports the following models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+class TranslatorSharedNetwork : virtual public TranslatorSubnets {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorSharedNetwork(sysrepo::S_Session session,
+ const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorSharedNetwork();
+
+ /// @brief Get and translate a shared network from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the shared network.
+ /// @return JSON representation of the shared network.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getSharedNetwork(const std::string& xpath);
+
+ /// @brief Translate and set shared network from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the shared network.
+ /// @param elem The JSON element.
+ void setSharedNetwork(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getSharedNetwork for kea-dhcp4-server and
+ /// kea-dhcp6-server models
+ ///
+ /// @param xpath The xpath of the shared network.
+ /// @param subsel The subnet list name (either "subnet4" or "subnet6").
+ /// @return JSON representation of the shared network.
+ isc::data::ElementPtr getSharedNetworkKea(const std::string& xpath,
+ const std::string& subsel);
+
+ /// @brief setSharedNetwork for kea-dhcp4-server and
+ /// kea-dhcp6-server models
+ ///
+ /// @param xpath The xpath of the shared network.
+ /// @param elem The JSON element.
+ /// @param subsel The subnet list name (either "subnet4" or "subnet6").
+ void setSharedNetworkKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem,
+ const std::string& subsel);
+};
+
+/// @brief A translator class for converting a shared network list between
+/// YANG and JSON.
+///
+/// Currently supports the following models:
+/// - kea-dhcp4-server
+/// - kea-dhcp6-server
+class TranslatorSharedNetworks : virtual public TranslatorSharedNetwork {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorSharedNetworks(sysrepo::S_Session session,
+ const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorSharedNetworks();
+
+ /// @brief Get and translate shared networks from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the shared network list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getSharedNetworks(const std::string& xpath);
+
+ /// @brief Translate and set shared networks from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the shared network list.
+ /// @param elem The JSON element.
+ void setSharedNetworks(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief setSharedNetworks for kea-dhcp4-server and
+ /// kea-dhcp6-server
+ ///
+ /// @param xpath The xpath of the shared network list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on a shared network without name.
+ void setSharedNetworksKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_SHARED_NETWORK_H
diff --git a/src/lib/yang/translator_subnet.cc b/src/lib/yang/translator_subnet.cc
new file mode 100644
index 0000000..126b04d
--- /dev/null
+++ b/src/lib/yang/translator_subnet.cc
@@ -0,0 +1,575 @@
+// Copyright (C) 2018-2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor_pool.h>
+#include <yang/translator_subnet.h>
+#include <yang/yang_models.h>
+
+#include <sstream>
+
+using namespace std;
+using namespace isc::data;
+using namespace sysrepo;
+
+namespace isc {
+namespace yang {
+
+TranslatorSubnet::TranslatorSubnet(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorPool(session, model),
+ TranslatorPools(session, model),
+ TranslatorPdPool(session, model),
+ TranslatorPdPools(session, model),
+ TranslatorHost(session, model),
+ TranslatorHosts(session, model) {
+}
+
+TranslatorSubnet::~TranslatorSubnet() {
+}
+
+ElementPtr
+TranslatorSubnet::getSubnet(const string& xpath) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ return (getSubnetIetf6(xpath));
+ } else if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ return (getSubnetKea(xpath));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting subnet at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getSubnet not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorSubnet::getSubnetIetf6(const string& xpath) {
+ ElementPtr result = Element::createMap();
+ /// @todo timers
+ /// @todo: option-data
+ ConstElementPtr pools = getPools(xpath + "/address-pools");
+ if (pools) {
+ /// Set empty list too.
+ result->set("pools", pools);
+ }
+ pools = getPdPools(xpath + "/pd-pools");
+ if (pools && (pools->size() > 0)) {
+ result->set("pd-pools", pools);
+ }
+ ConstElementPtr subnet = getItem(xpath + "/network-prefix");
+ if (!subnet) {
+ isc_throw(BadValue, "getSubnetIetf6 requires network prefix");
+ }
+ result->set("subnet", subnet);
+ ConstElementPtr id = getItem(xpath + "/network-range-id");
+ if (!id) {
+ isc_throw(BadValue, "getSubnetIetf6 requires network range id");
+ }
+ result->set("id", id);
+ /// @todo: reservations
+ /// missing a lot of things
+ ConstElementPtr description = getItem(xpath + "/network-description");
+ /// Adding description if exists.
+ if (description) {
+ ElementPtr context = Element::createMap();
+ context->set("description", description);
+ result->set("user-context", context);
+ }
+ /// missing a lot of things
+ if (result->get("pools")) {
+ AdaptorPool::toSubnet(model_, result, result->get("pools"));
+ }
+ return (result);
+}
+
+ElementPtr
+TranslatorSubnet::getSubnetKea(const string& xpath) {
+ ElementPtr result = Element::createMap();
+ if (model_ == KEA_DHCP6_SERVER) {
+ ConstElementPtr preferred = getItem(xpath + "/preferred-lifetime");
+ if (preferred) {
+ result->set("preferred-lifetime", preferred);
+ }
+ ConstElementPtr min_pref = getItem(xpath + "/min-preferred-lifetime");
+ if (min_pref) {
+ result->set("min-preferred-lifetime", min_pref);
+ }
+ ConstElementPtr max_pref = getItem(xpath + "/max-preferred-lifetime");
+ if (max_pref) {
+ result->set("max-preferred-lifetime", max_pref);
+ }
+ }
+ ConstElementPtr valid = getItem(xpath + "/valid-lifetime");
+ if (valid) {
+ result->set("valid-lifetime", valid);
+ }
+ ConstElementPtr min_valid = getItem(xpath + "/min-valid-lifetime");
+ if (min_valid) {
+ result->set("min-valid-lifetime", min_valid);
+ }
+ ConstElementPtr max_valid = getItem(xpath + "/max-valid-lifetime");
+ if (max_valid) {
+ result->set("max-valid-lifetime", max_valid);
+ }
+ ConstElementPtr renew = getItem(xpath + "/renew-timer");
+
+ if (renew) {
+ result->set("renew-timer", renew);
+ }
+ ConstElementPtr rebind = getItem(xpath + "/rebind-timer");
+ if (rebind) {
+ result->set("rebind-timer", rebind);
+ }
+ ConstElementPtr calculate = getItem(xpath + "/calculate-tee-times");
+ if (calculate) {
+ result->set("calculate-tee-times", calculate);
+ }
+ ConstElementPtr t1_percent = getItem(xpath + "/t1-percent");
+ if (t1_percent) {
+ result->set("t1-percent", t1_percent);
+ }
+ ConstElementPtr t2_percent = getItem(xpath + "/t2-percent");
+ if (t2_percent) {
+ result->set("t2-percent", t2_percent);
+ }
+ ConstElementPtr options = getOptionDataList(xpath);
+ if (options && (options->size() > 0)) {
+ result->set("option-data", options);
+ }
+ ConstElementPtr pools = getPools(xpath);
+ if (pools && (pools->size() > 0)) {
+ result->set("pools", pools);
+ }
+ if (model_ == KEA_DHCP6_SERVER) {
+ pools = getPdPools(xpath);
+ if (pools && (pools->size() > 0)) {
+ result->set("pd-pools", pools);
+ }
+ }
+ ConstElementPtr subnet = getItem(xpath + "/subnet");
+ if (!subnet) {
+ isc_throw(BadValue, "getSubnetKea requires subnet");
+ }
+ result->set("subnet", subnet);
+ ConstElementPtr interface = getItem(xpath + "/interface");
+ if (interface) {
+ result->set("interface", interface);
+ }
+ if (model_ == KEA_DHCP6_SERVER) {
+ ConstElementPtr interface_id = getItem(xpath + "/interface-id");
+ if (interface_id) {
+ result->set("interface-id", interface_id);
+ }
+ }
+ ConstElementPtr id = getItem(xpath + "/id");
+ if (!id) {
+ isc_throw(BadValue, "getSubnetKea requires id");
+ }
+ result->set("id", id);
+ if (model_ == KEA_DHCP6_SERVER) {
+ ConstElementPtr rapid_commit = getItem(xpath + "/rapid-commit");
+ if (rapid_commit) {
+ result->set("rapid-commit", rapid_commit);
+ }
+ }
+ ConstElementPtr guard = getItem(xpath + "/client-class");
+ if (guard) {
+ result->set("client-class", guard);
+ }
+ ConstElementPtr required = getItems(xpath + "/require-client-classes");
+ if (required && (required->size() > 0)) {
+ result->set("require-client-classes", required);
+ }
+ ConstElementPtr hosts = getHosts(xpath);
+ if (hosts && (hosts->size() > 0)) {
+ result->set("reservations", hosts);
+ }
+ ConstElementPtr mode = getItem(xpath + "/reservation-mode");
+ if (mode) {
+ result->set("reservation-mode", mode);
+ }
+ ConstElementPtr relay = getItems(xpath + "/relay/ip-addresses");
+ if (relay && (relay->size() > 0)) {
+ ElementPtr relay_map = Element::createMap();
+ relay_map->set("ip-addresses", relay);
+ result->set("relay", relay_map);
+ }
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr match = getItem(xpath + "/match-client-id");
+ if (match) {
+ result->set("match-client-id", match);
+ }
+ ConstElementPtr auth = getItem(xpath + "/authoritative");
+ if (auth) {
+ result->set("authoritative", auth);
+ }
+ ConstElementPtr next = getItem(xpath + "/next-server");
+ if (next) {
+ result->set("next-server", next);
+ }
+ ConstElementPtr hostname = getItem(xpath + "/server-hostname");
+ if (hostname) {
+ result->set("server-hostname", hostname);
+ }
+ ConstElementPtr boot = getItem(xpath + "/boot-file-name");
+ if (boot) {
+ result->set("boot-file-name", boot);
+ }
+ ConstElementPtr s4o6_if = getItem(xpath + "/subnet-4o6-interface");
+ if (s4o6_if) {
+ result->set("4o6-interface", s4o6_if);
+ }
+ ConstElementPtr s4o6_id = getItem(xpath + "/subnet-4o6-interface-id");
+ if (s4o6_id) {
+ result->set("4o6-interface-id", s4o6_id);
+ }
+ ConstElementPtr s4o6_sub = getItem(xpath + "/subnet-4o6-subnet");
+ if (s4o6_sub) {
+ result->set("4o6-subnet", s4o6_sub);
+ }
+ }
+ ConstElementPtr context = getItem(xpath + "/user-context");
+ if (context) {
+ result->set("user-context", Element::fromJSON(context->stringValue()));
+ }
+ checkAndGetLeaf(result, xpath, "cache-max-age");
+ checkAndGetLeaf(result, xpath, "cache-threshold");
+ checkAndGetLeaf(result, xpath, "ddns-generated-prefix");
+ checkAndGetLeaf(result, xpath, "ddns-override-client-update");
+ checkAndGetLeaf(result, xpath, "ddns-override-no-update");
+ checkAndGetLeaf(result, xpath, "ddns-qualifying-suffix");
+ checkAndGetLeaf(result, xpath, "ddns-replace-client-name");
+ checkAndGetLeaf(result, xpath, "ddns-send-updates");
+ checkAndGetLeaf(result, xpath, "ddns-update-on-renew");
+ checkAndGetLeaf(result, xpath, "ddns-use-conflict-resolution");
+ checkAndGetLeaf(result, xpath, "hostname-char-replacement");
+ checkAndGetLeaf(result, xpath, "hostname-char-set");
+ checkAndGetLeaf(result, xpath, "reservations-global");
+ checkAndGetLeaf(result, xpath, "reservations-in-subnet");
+ checkAndGetLeaf(result, xpath, "reservations-out-of-pool");
+ checkAndGetLeaf(result, xpath, "store-extended-info");
+ return (result);
+}
+
+void
+TranslatorSubnet::setSubnet(const string& xpath, ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ setSubnetIetf6(xpath, elem);
+ } else if ((model_ == KEA_DHCP4_SERVER) ||
+ (model_ == KEA_DHCP6_SERVER)) {
+ setSubnetKea(xpath, elem);
+ } else {
+ isc_throw(NotImplemented,
+ "setSubnet not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting subnet '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorSubnet::setSubnetIetf6(const string& xpath, ConstElementPtr elem) {
+ /// Skip id as it is the key.
+ AdaptorPool::fromSubnet(model_, elem, elem->get("pools"));
+ ConstElementPtr context = elem->get("user-context");
+ if (context && context->contains("description")) {
+ ConstElementPtr description = context->get("description");
+ if (description->getType() == Element::string) {
+ setItem(xpath + "/network-description", description, SR_STRING_T);
+ }
+ }
+ ConstElementPtr subnet = elem->get("subnet");
+ if (!subnet) {
+ isc_throw(BadValue, "setSubnetIetf6 requires subnet: " << elem->str());
+ }
+ setItem(xpath + "/network-prefix", subnet, SR_STRING_T);
+ /// @todo option-data
+ ConstElementPtr pools = elem->get("pools");
+ if (pools && (pools->size() > 0)) {
+ setPools(xpath + "/address-pools", pools);
+ }
+ pools = elem->get("pd-pools");
+ if (pools && (pools->size() > 0)) {
+ setPdPools(xpath + "/pd-pools", pools);
+ }
+ /// @todo reservations
+}
+
+void
+TranslatorSubnet::setSubnetKea(const string& xpath, ConstElementPtr elem) {
+ /// Skip id as it is the key.
+ if (model_ == KEA_DHCP6_SERVER) {
+ ConstElementPtr preferred = elem->get("preferred-lifetime");
+ if (preferred) {
+ setItem(xpath + "/preferred-lifetime", preferred, SR_UINT32_T);
+ }
+ ConstElementPtr min_pref = elem->get("min-preferred-lifetime");
+ if (min_pref) {
+ setItem(xpath + "/min-preferred-lifetime", min_pref, SR_UINT32_T);
+ }
+ ConstElementPtr max_pref = elem->get("max-preferred-lifetime");
+ if (max_pref) {
+ setItem(xpath + "/max-preferred-lifetime", max_pref, SR_UINT32_T);
+ }
+ }
+ ConstElementPtr valid = elem->get("valid-lifetime");
+ if (valid) {
+ setItem(xpath + "/valid-lifetime", valid, SR_UINT32_T);
+ }
+ ConstElementPtr min_valid = elem->get("min-valid-lifetime");
+ if (min_valid) {
+ setItem(xpath + "/min-valid-lifetime", min_valid, SR_UINT32_T);
+ }
+ ConstElementPtr max_valid = elem->get("max-valid-lifetime");
+ if (max_valid) {
+ setItem(xpath + "/max-valid-lifetime", max_valid, SR_UINT32_T);
+ }
+ ConstElementPtr renew = elem->get("renew-timer");
+ if (renew) {
+ setItem(xpath + "/renew-timer", renew, SR_UINT32_T);
+ }
+ ConstElementPtr rebind = elem->get("rebind-timer");
+ if (rebind) {
+ setItem(xpath + "/rebind-timer", rebind, SR_UINT32_T);
+ }
+ ConstElementPtr calculate = elem->get("calculate-tee-times");
+ if (calculate) {
+ setItem(xpath + "/calculate-tee-times", calculate, SR_BOOL_T);
+ }
+ ConstElementPtr t1_percent = elem->get("t1-percent");
+ if (t1_percent) {
+ setItem(xpath + "/t1-percent", t1_percent, SR_DECIMAL64_T);
+ }
+ ConstElementPtr t2_percent = elem->get("t2-percent");
+ if (t2_percent) {
+ setItem(xpath + "/t2-percent", t2_percent, SR_DECIMAL64_T);
+ }
+ ConstElementPtr options = elem->get("option-data");
+ if (options && (options->size() > 0)) {
+ setOptionDataList(xpath, options);
+ }
+ ConstElementPtr pools = elem->get("pools");
+ if (pools && (pools->size() > 0)) {
+ setPools(xpath, pools);
+ }
+ if (model_ == KEA_DHCP6_SERVER) {
+ pools = elem->get("pd-pools");
+ if (pools && (pools->size() > 0)) {
+ setPdPools(xpath, pools);
+ }
+ }
+ ConstElementPtr subnet = elem->get("subnet");
+ if (!subnet) {
+ isc_throw(BadValue, "setSubnetKea requires subnet: " << elem->str());
+ }
+ setItem(xpath + "/subnet", subnet, SR_STRING_T);
+ ConstElementPtr interface = elem->get("interface");
+ if (interface) {
+ setItem(xpath + "/interface", interface, SR_STRING_T);
+ }
+ if (model_ == KEA_DHCP6_SERVER) {
+ ConstElementPtr interface_id = elem->get("interface-id");
+ if (interface_id) {
+ setItem(xpath + "/interface-id", interface_id, SR_STRING_T);
+ }
+ }
+ if (model_ == KEA_DHCP6_SERVER) {
+ ConstElementPtr rapid_commit = elem->get("rapid-commit");
+ if (rapid_commit) {
+ setItem(xpath + "/rapid-commit", rapid_commit, SR_BOOL_T);
+ }
+ }
+ ConstElementPtr guard = elem->get("client-class");
+ if (guard) {
+ setItem(xpath + "/client-class", guard, SR_STRING_T);
+ }
+ 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);
+ }
+ }
+ ConstElementPtr hosts = elem->get("reservations");
+ if (hosts && (hosts->size() > 0)) {
+ setHosts(xpath, hosts);
+ }
+ ConstElementPtr mode = elem->get("reservation-mode");
+ if (mode) {
+ setItem(xpath + "/reservation-mode", mode, SR_ENUM_T);
+ }
+ 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);
+ } else if (addresses && (addresses->size() > 0)) {
+ for (ConstElementPtr addr : addresses->listValue()) {
+ setItem(xpath + "/relay/ip-addresses", addr, 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);
+ if (model_ == KEA_DHCP4_SERVER) {
+ ConstElementPtr match = elem->get("match-client-id");
+ if (match) {
+ setItem(xpath + "/match-client-id", match, SR_BOOL_T);
+ }
+ ConstElementPtr auth = elem->get("authoritative");
+ if (auth) {
+ setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+ }
+ ConstElementPtr next = elem->get("next-server");
+ if (next) {
+ setItem(xpath + "/next-server", next, SR_STRING_T);
+ }
+ ConstElementPtr hostname = elem->get("server-hostname");
+ if (hostname) {
+ setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
+ }
+ ConstElementPtr boot = elem->get("boot-file-name");
+ if (boot) {
+ setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
+ }
+ ConstElementPtr s4o6_if = elem->get("4o6-interface");
+ if (s4o6_if) {
+ setItem(xpath + "/subnet-4o6-interface", s4o6_if, SR_STRING_T);
+ }
+ ConstElementPtr s4o6_id = elem->get("4o6-interface-id");
+ if (s4o6_id) {
+ setItem(xpath + "/subnet-4o6-interface-id", s4o6_id, SR_STRING_T);
+ }
+ ConstElementPtr s4o6_subnet = elem->get("4o6-subnet");
+ if (s4o6_subnet) {
+ setItem(xpath + "/subnet-4o6-subnet", s4o6_subnet, SR_STRING_T);
+ }
+ }
+ ConstElementPtr context = Adaptor::getContext(elem);
+ if (context) {
+ ConstElementPtr repr = Element::create(context->str());
+ setItem(xpath + "/user-context", repr, SR_STRING_T);
+ }
+}
+
+TranslatorSubnets::TranslatorSubnets(S_Session session, const string& model)
+ : TranslatorBasic(session, model),
+ TranslatorOptionData(session, model),
+ TranslatorOptionDataList(session, model),
+ TranslatorPool(session, model),
+ TranslatorPools(session, model),
+ TranslatorPdPool(session, model),
+ TranslatorPdPools(session, model),
+ TranslatorHost(session, model),
+ TranslatorHosts(session, model),
+ TranslatorSubnet(session, model) {
+}
+
+TranslatorSubnets::~TranslatorSubnets() {
+}
+
+ElementPtr
+TranslatorSubnets::getSubnets(const string& xpath) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ return (getSubnetsCommon(xpath, "network-range"));
+ } else if (model_ == KEA_DHCP4_SERVER) {
+ return (getSubnetsCommon(xpath, "subnet4"));
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ return (getSubnetsCommon(xpath, "subnet6"));
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error getting subnets at '" << xpath
+ << "': " << ex.what());
+ }
+ isc_throw(NotImplemented,
+ "getSubnets not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorSubnets::getSubnetsCommon(const string& xpath,
+ const std::string& subsel) {
+ return getList<TranslatorSubnet>(xpath + "/" + subsel, *this,
+ &TranslatorSubnet::getSubnet);
+}
+
+void
+TranslatorSubnets::setSubnets(const string& xpath, ConstElementPtr elem) {
+ try {
+ if (model_ == IETF_DHCPV6_SERVER) {
+ setSubnetsIetf6(xpath, elem);
+ } else if (model_ == KEA_DHCP4_SERVER) {
+ setSubnetsKea(xpath, elem, "subnet4");
+ } else if (model_ == KEA_DHCP6_SERVER) {
+ setSubnetsKea(xpath, elem, "subnet6");
+ } else {
+ isc_throw(NotImplemented,
+ "setSubnets not implemented for the model: " << model_);
+ }
+ } catch (const sysrepo_exception& ex) {
+ isc_throw(SysrepoError,
+ "sysrepo error setting subnets '" << elem->str()
+ << "' at '" << xpath << "': " << ex.what());
+ }
+}
+
+void
+TranslatorSubnets::setSubnetsIetf6(const string& xpath, ConstElementPtr elem) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr subnet = elem->get(i);
+ ostringstream range;
+ range << xpath << "/network-range[network-range-id='";
+ ConstElementPtr id = subnet->get("id");
+ if (!id) {
+ isc_throw(BadValue, "subnet without id: " << elem->str());
+ }
+ range << id->intValue() << "']";
+ setSubnet(range.str().c_str(), subnet);
+ }
+}
+
+void
+TranslatorSubnets::setSubnetsKea(const string& xpath, ConstElementPtr elem,
+ const std::string& subsel) {
+ for (size_t i = 0; i < elem->size(); ++i) {
+ ConstElementPtr subnet = elem->get(i);
+ if (!subnet->contains("id")) {
+ isc_throw(BadValue, "subnet without id: " << subnet->str());
+ }
+ ostringstream prefix;
+ prefix << xpath << "/" << subsel << "[id='"
+ << subnet->get("id")->intValue() << "']";
+ setSubnet(prefix.str(), subnet);
+ }
+}
+
+} // namespace yang
+} // namespace isc
diff --git a/src/lib/yang/translator_subnet.h b/src/lib/yang/translator_subnet.h
new file mode 100644
index 0000000..2584047
--- /dev/null
+++ b/src/lib/yang/translator_subnet.h
@@ -0,0 +1,386 @@
+// Copyright (C) 2018-2019,2021 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TRANSLATOR_SUBNET_H
+#define ISC_TRANSLATOR_SUBNET_H 1
+
+#include <yang/translator.h>
+#include <yang/translator_pool.h>
+#include <yang/translator_pd_pool.h>
+#include <yang/translator_host.h>
+#include <list>
+
+namespace isc {
+namespace yang {
+
+/// Subnet (aka network range) translation between YANG and JSON
+///
+/// JSON syntax for kea-dhcp4 is:
+/// @code
+/// {
+/// "valid-lifetime": <valid lifetime>,
+/// "min-valid-lifetime": <minimum valid lifetime>,
+/// "max-valid-lifetime": <maximum valid lifetime>,
+/// "renew-timer": <renew timer>,
+/// "rebind-timer": <rebind timer>,
+/// "calculate-tee-times": <calculate T1/T2 times>,
+/// "t1-percent": <T1 percent>,
+/// "t2-percent": <T2 percent>,
+/// "option-data": [ <list of option data> ],
+/// "pools": [ <list of pools> ],
+/// "subnet": "<subnet prefix>",
+/// "interface": "<interface>",
+/// "id": <id>,
+/// "client-class": "<guard class name>",
+/// "require-client-classes": [ <list of required class names> ],
+/// "reservations": [ <list of host reservations> ],
+/// "reservation-mode": <host reservation mode>,
+/// "relay": <relay ip address(es)>,
+/// "match-client-id": <match client id flag>,
+/// "next-server": "<next server>",
+/// "server-hostname": "<server hostname>",
+/// "boot-file-name": "<boot file name>",
+/// "4o6-interface": "<dhcpv4-over-dhcpv6 interface>",
+/// "4o6-interface-id": "<dhcpv4-over-dhcpv6 interface id>",
+/// "4o6-subnet": "<dhcpv4-over-dhcpv6 subnet>",
+/// "authoritative": <authoritative flag>,
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// JSON syntax for kea-dhcp6 is:
+/// @code
+/// {
+/// "preferred-lifetime": <preferred lifetime>,
+/// "min-preferred-lifetime": <minimum preferred lifetime>,
+/// "max-preferred-lifetime": <maximum preferred lifetime>,
+/// "valid-lifetime": <valid lifetime>,
+/// "min-valid-lifetime": <minimum valid lifetime>,
+/// "max-valid-lifetime": <maximum valid lifetime>,
+/// "renew-timer": <renew timer>,
+/// "rebind-timer": <rebind timer>,
+/// "calculate-tee-times": <calculate T1/T2 times>,
+/// "t1-percent": <T1 percent>,
+/// "t2-percent": <T2 percent>,
+/// "option-data": [ <list of option data> ],
+/// "pools": [ <list of pools> ],
+/// "pd-pools": [ <list of prefix delegation pools> ],
+/// "subnet": "<subnet prefix>",
+/// "interface": "<interface>",
+/// "interface-id": "<interface id>",
+/// "id": <id>,
+/// "rapid-commit": <rapid commit flag>,
+/// "client-class": "<guard class name>",
+/// "require-client-classes": [ <list of required class names> ],
+/// "reservations": [ <list of host reservations> ],
+/// "reservation-mode": <host reservation mode>,
+/// "relay": <relay ip address(es)>,
+/// "user-context": { <json map> },
+/// "comment": "<comment>"
+/// }
+/// @endcode
+///
+/// YANG syntax for ietf-dhcpv6-server is with network-range-id as the key:
+/// @code
+/// +--rw network-range-id uint32
+/// +--rw network-description string
+/// +--rw network-prefix inet:ipv4-prefix
+/// +--rw option-set-id?
+/// /server/server-config/option-sets/option-set/option-set-id
+/// +--rw address-pool* [pool-id]
+/// +--rw pd-pool* [pool-id]
+/// +--rw host-reservations host-reservation* [cli-id]
+/// @endcode
+///
+/// YANG syntax for kea-dhcp[46]-server is with id as the key:
+/// @code
+/// +--rw subnet[46]* [id]
+/// +--rw valid-lifetime? uint32
+/// +--rw min-valid-lifetime? uint32
+/// +--rw max-valid-lifetime? uint32
+/// +--rw renew-timer? uint32
+/// +--rw rebind-timer? uint32
+/// +--rw calculate-tee-times? boolean
+/// +--rw t1-percent? decimal64
+/// +--rw t2-percent? decimal64
+/// +--rw option-data* [code space]
+/// +--rw pool* [start-address end-address]
+/// +--rw subnet inet:ipv4-prefix
+/// +--rw interface? string
+/// +--rw id uint32
+/// +--rw client-class? string
+/// +--rw require-client-classes* string
+/// +--rw host* [identifier-type identifier]
+/// +--rw reservation-mode? host-reservation-mode
+/// +--rw relay
+/// +--rw cache-max-age? uint32
+/// +--rw cache-threshold? decimal64
+/// +--rw ddns-generated-prefix? string
+/// +--rw ddns-override-client-update? boolean
+/// +--rw ddns-override-no-update? boolean
+/// +--rw ddns-qualifying-suffix? string
+/// +--rw ddns-replace-client-name? string
+/// +--rw ddns-send-updates? boolean
+/// +--rw ddns-update-on-renew? boolean
+/// +--rw ddns-use-conflict-resolution? boolean
+/// +--rw hostname-char-replacement? string
+/// +--rw hostname-char-set? string
+/// +--rw reservations-global? boolean
+/// +--rw reservations-in-subnet? boolean
+/// +--rw reservations-out-of-pool? boolean
+/// +--rw store-extended-info? boolean
+/// +--rw user-context? user-context
+///
+/// DHCPv4 only:
+/// +--rw match-client-id? boolean
+/// +--rw next-server? inet:ipv4-address
+/// +--rw server-hostname? string
+/// +--rw boot-file-name? string
+/// +--rw subnet-4o6-interface? string
+/// +--rw subnet-4o6-interface-id? string
+/// +--rw subnet-4o6-subnet? inet:ipv6-prefix
+/// +--rw authoritative? boolean
+///
+/// DHCPv6 only:
+/// +--rw preferred-lifetime? uint32
+/// +--rw min-preferred-lifetime? uint32
+/// +--rw max-preferred-lifetime? uint32
+/// +--rw pd-pool*
+/// +--rw interface-id? string
+/// +--rw rapid-commit? boolean
+/// @endcode
+///
+/// An example in JSON and YANG formats for the IETF model:
+/// @code
+/// [
+/// {
+/// "subnet": "2001:db8::/48",
+/// "id": 123,
+/// "pools":
+/// [
+/// {
+/// "pool": "2001:db8::1:0/112"
+/// },
+/// {
+/// "pool": "2001:db8::2:0/112"
+/// }
+/// ]
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /ietf-dhcpv6-server:server (container)
+/// /ietf-dhcpv6-server:server/server-config (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/network-range-id = 123
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/network-prefix = 2001:db8::/48
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools (container)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='0'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='0']/pool-id = 0
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='0']/pool-prefix = 2001:db8::1:0/112
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='0']/start-address = 2001:db8::1:0
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='0']/end-address = 2001:db8::1:ffff
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='0']/max-address-count = disabled
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='1'] (list instance)
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='1']/pool-id = 1
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='1']/pool-prefix = 2001:db8::2:0/112
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='1']/start-address = 2001:db8::2:0
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='1']/end-address = 2001:db8::2:ffff
+/// /ietf-dhcpv6-server:server/server-config/network-ranges/
+/// network-range[network-range-id='123']/address-pools/
+/// address-pool[pool-id='1']/max-address-count = disabled
+/// @endcode
+///
+/// An example in JSON and YANG formats for the Kea model:
+/// @code
+/// [
+/// {
+/// "subnet": "10.0.1.0/24",
+/// "id": 123,
+/// "pools":
+/// [
+/// {
+/// "pool": "10.0.1.0/28",
+/// },
+/// {
+/// "pool": "10.0.1.200 - 10.0.1.222"
+/// }
+/// ]
+/// }
+/// ]
+/// @endcode
+/// @code
+/// /kea-dhcp4-server:config (container)
+/// /kea-dhcp4-server:config/subnet4[id='123'] (list instance)
+/// /kea-dhcp4-server:config/subnet4[id='123']/id = 123
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.0'][end-address='10.0.1.15'] (list instance)
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.0'][end-address='10.0.1.15']/
+/// start-address = 10.0.1.0
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.0'][end-address='10.0.1.15']/
+/// end-address = 10.0.1.15
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.0'][end-address='10.0.1.15']/
+/// prefix = 10.0.1.0/28
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.200'][end-address='10.0.1.222']
+/// (list instance)
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.200'][end-address='10.0.1.222']/
+/// start-address = 10.0.1.200
+/// /kea-dhcp4-server:config/subnet4[id='123']/
+/// pool[start-address='10.0.1.200'][end-address='10.0.1.222']/
+/// end-address = 10.0.1.222
+/// /kea-dhcp4-server:config/subnet4[id='123']/subnet = 10.0.1.0/24
+/// @endcode
+
+/// @brief A translator class for converting a subnet between YANG and JSON.
+///
+/// Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.
+class TranslatorSubnet : virtual public TranslatorPools,
+ virtual public TranslatorPdPools, virtual public TranslatorHosts {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorSubnet(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorSubnet();
+
+ /// @brief Get and translate a subnet from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the subnet.
+ /// @return JSON representation of the subnet.
+ /// @throw SysrepoError when sysrepo raises an error.
+ /// @throw BadValue on a subnet without prefix or id.
+ isc::data::ElementPtr getSubnet(const std::string& xpath);
+
+ /// @brief Translate and set subnet from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the subnet.
+ /// @param elem The JSON element.
+ /// @throw BadValue on a subnet without prefix.
+ void setSubnet(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getSubnet for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the subnet.
+ /// @return JSON representation of the subnet.
+ isc::data::ElementPtr getSubnetIetf6(const std::string& xpath);
+
+ /// @brief setSubnet for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the subnet.
+ /// @param elem The JSON element.
+ void setSubnetIetf6(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief getSubnet for kea-dhcp[46]-server.
+ ///
+ /// @param xpath The xpath of the subnet.
+ /// @return JSON representation of the subnet.
+ isc::data::ElementPtr getSubnetKea(const std::string& xpath);
+
+ /// @brief setSubnet for kea-dhcp[46]-server.
+ ///
+ /// @param xpath The xpath of the subnet.
+ /// @param elem The JSON element.
+ void setSubnetKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+};
+
+/// @brief A translator class for converting a subnet list between
+/// YANG and JSON.
+///
+/// Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.
+class TranslatorSubnets : virtual public TranslatorSubnet {
+public:
+
+ /// @brief Constructor.
+ ///
+ /// @param session Sysrepo session.
+ /// @param model Model name.
+ TranslatorSubnets(sysrepo::S_Session session, const std::string& model);
+
+ /// @brief Destructor.
+ virtual ~TranslatorSubnets();
+
+ /// @brief Get and translate subnets from YANG to JSON.
+ ///
+ /// @param xpath The xpath of the subnet list.
+ /// @throw SysrepoError when sysrepo raises an error.
+ isc::data::ElementPtr getSubnets(const std::string& xpath);
+
+ /// @brief Translate and set subnets from JSON to YANG.
+ ///
+ /// @param xpath The xpath of the subnet list.
+ /// @param elem The JSON element.
+ /// @throw BadValue on a subnet without id.
+ void setSubnets(const std::string& xpath, isc::data::ConstElementPtr elem);
+
+protected:
+ /// @brief getSubnets common part.
+ ///
+ /// @param xpath The xpath of the subnet list.
+ /// @param subsel The subnet list name.
+ isc::data::ElementPtr getSubnetsCommon(const std::string& xpath,
+ const std::string& subsel);
+
+ /// @brief setSubnets for ietf-dhcpv6-server.
+ ///
+ /// @param xpath The xpath of the subnet list.
+ /// @param elem The JSON element.
+ void setSubnetsIetf6(const std::string& xpath,
+ isc::data::ConstElementPtr elem);
+
+ /// @brief setSubnets for kea-dhcp[46]-server.
+ ///
+ /// @param xpath The xpath of the subnet list.
+ /// @param elem The JSON element.
+ /// @param subsel The subnet list name.
+ void setSubnetsKea(const std::string& xpath,
+ isc::data::ConstElementPtr elem,
+ const std::string& subsel);
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_TRANSLATOR_SUBNET_H
diff --git a/src/lib/yang/yang.dox b/src/lib/yang/yang.dox
new file mode 100644
index 0000000..d364bae
--- /dev/null
+++ b/src/lib/yang/yang.dox
@@ -0,0 +1,204 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/**
+ @page libyang libkea-yang - Kea YANG Utilities Library
+
+The libkea-yang library was developed to handle base YANG operations,
+such as retrieving YANG schema and configuration and translating
+data between YANG data and JSON that is understandable by Kea.
+
+@section yangTranslator Translator between YANG and JSON
+
+An essential concept is the idea of translator. It is a primitive that is able
+to convert certain data structure between YANG and JSON. It is envisaged
+that more complex translators will use other translators to handle more
+complex data structures. For details, see @ref isc::yang::TranslatorBasic.
+It is also envisioned that translators could do the translation automatically by
+relying on capabilities of iterating through data, retrieving data type
+information and value information from nodes through the libyang and sysrepo
+APIs.
+
+Note that although the initial focus is on translation from YANG to JSON (so
+Kea can retrieve its configuration), the opposite translation direction -
+from JSON to YANG - is also very useful, for at least three reasons. First,
+in many cases we can use it in tests to check that conversion back and forth
+doesn't lose anything: yang = toYang(toJson(yang)). Second, YANG modules
+cover two major types of data: configuration and run-time state. While
+we're initially focusing on getting the configuration, the run-time state
+is something that Kea is expected to provide. Kea uses JSON internally in many
+places and that data will have to be exported in YANG format. Thirdly, the
+SR_EV_UPDATE callback allows mid-flight configuration changes before data is
+committed to the sysrepo datastore. If it ever will be used in the future,
+changes applied during this step will most likely come from Kea's current JSON
+configuration. As such, JSON to YANG translation will be necessary. One
+application for this is reverting stuff that is necessary for Kea - Sysrepo
+communication like the unix socket.
+
+All translators take a Session pointer (a structure provided by Sysrepo that
+is responsible for maintaining a connection) in constructors and derive from
+the basic / base class and recursively from translators for embedded parts.
+
+@c isc::yang::TranslatorBasic provides some methods:
+ - getItem() retrieves and translates basic value from YANG to JSON
+ - getItems() retrieves and translates a leaf-list from YANG to JSON
+ - getList() retrieves and translates a list from YANG to JSON
+ - setItem() translates and sets a basic value from JSON to YANG
+ - delItem() deletes a value
+ - forAll() iterates over the top node and its descendants and calls a function
+
+@section yangTranslatorPool Pool translator
+
+@c isc::yang::TranslatorPool is the standard example of a translator
+for a structured value. Its constructor takes a module name: the code
+implements some variants to accommodate the module with shared code
+moved into a common private routine. When called with an unsupported
+module, generic methods of all structure translators throw
+@c isc::NotImplemented.
+
+Note pools show two shortcomings in IETF modules:
+ - option sets make to track changes nearly impossible: the only easy
+ code is to translate the whole configuration.
+ - prefix and start - end forms of pool ranges are both mandatory.
+ (reported to authors' so should be fixed in the next version).
+
+All structure translators depend on @c isc::yang::TranslatorBasic and
+some of them depend on other structures, for instance
+@c isc::yang::TranslatorPool depends on
+@c isc::yang::TranslatorOptionDataList which itself as all list translators
+depends on the corresponding list item translator
+@c isc::yang::TranslatorOptionData. This multiple inheritance forms
+a graph with the basic and the configuration translators at the two ends.
+Multiple inheritance and its "diamond" issue are handled by C++ with
+the "virtual" inheritance: depending classes must be virtually inherited
+and explicitly constructed.
+
+@section yangTranslatorSubnet Subnet translator
+
+The new thing here is the use of adaptors to move timers from subnets
+to pools and back.
+
+@section yangAdaptor Adapting JSON configuration
+
+Adaptors are tools which adapts JSON complete or partial configuration
+before translation to YANG to ease this translation or after translation
+from YANG to follow the Kea syntax, for instance by adding static
+components which are not in the module.
+
+Methods provided by adaptors are class methods (i.e. declared static).
+Specific adaptors can be derived from the isc::yang::Adaptor base class.
+
+There are a few basic adaptors and per structure adaptors. The second
+category of adaptors are divided into:
+ - from JSON to YANG adaptors or pre-processing which adapt a JSON
+ configuration to make it acceptable by a from JSON to YANG (setXXX)
+ translators. For a Kea module this kind of adaptors fill some required
+ but missing fields, or only transform a configuration into a canonical
+ form. Note for a Kea module and a configuration taken from config-get
+ or config-write it likely does nearly nothing but the code must
+ handle any hand written configuration so these adaptors are always
+ applied.
+
+ - from YANG to JSON adaptors or post-processing which adapt translated
+ YANG configuration (by getXXX) to make it acceptable by a Kea server.
+ By definition, they are not defined for Kea modules.
+
+@section unitTestsSysrepo Running unit tests with Sysrepo
+
+To run YANG/NETCONF/Sysrepo tests you need to compile Kea with Sysrepo support:
+
+@verbatim
+./configure --with-sysrepo
+@endverbatim
+
+For details, see Section "YANG/NETCONF support" in the Kea Administrator
+Reference Manual: https://kea.readthedocs.io/en/latest/arm/integrations.html#yang-netconf.
+
+You also need to install YANG modules, so the unit tests are able to
+retrieve, add, update and generally interact with the sysrepo information.
+There are several Kea modules (*.yang in src/share/yang/modules/), mostly usable in
+production, but one called keatest-module is only used in unit tests. To be able
+to run unit tests as a non-root user, which is the recommended way, make sure
+the sysrepo repository and /dev/shm/sr* are owned by said user. One way to
+prevent sporadic chown-ing is to install sysrepo and the Kea modules as non-root.
+
+To install all the modules, run the following script:
+
+@verbatim
+./src/share/yang/modules/utils/reinstall.sh
+@endverbatim
+
+Alternatively to install each module, issue the following command:
+
+@verbatim
+sysrepoctl -i "src/share/yang/modules/${module}.yang"
+@endverbatim
+
+To verify that you have the schemas installed, do this:
+@verbatim
+sysrepoctl -l
+@endverbatim
+
+Make sure that keatest-module and other necessary modules are on the list.
+
+As DHCP modules are still being developed, if the revision has been bumped,
+reinstalling it will update the module automatically . Otherwise, it can be
+useful to uninstall them before reinstalling a more recent version:
+
+@verbatim
+sysrepoctl -u <module-name>
+@endverbatim
+
+Tests use these modules which you can find in src/share/yang/modules in addition
+to keatest-module:
+ - ietf-dhcpv6-server
+ - kea-ctrl-agent
+ - kea-dhcp-ddns
+ - kea-dhcp4-server
+ - kea-dhcp6-server
+
+Those modules depend on the following modules:
+ - ietf-inet-types
+ - ietf-yang-types
+ - ietf-interfaces
+ - kea-types
+ - kea-dhcp-types
+
+The following modules are extracted from the IETF DHCPv6 YANG draft:
+ - ietf-dhcpv6-client
+ - ietf-dhcpv6-options
+ - ietf-dhcpv6-relay
+ - ietf-dhcpv6-types
+
+All are available in the src/share/yang/modules directory using the
+<module-name>[@<revision>].yang syntax for file names.
+src/share/yang/modules/utils provides a few utilities for developers:
+ - check-revisions.sh which verifies if the revision in the file name
+ and in the file content matches
+ - check-hashes.sh which detects updates in the file content without
+ a revision change using the SHA-256 hash of the to YIN translation.
+ Updates hashes automatically if -a is passed to the script.
+ - gen-revisions.sh which produces the module / revision table of
+ the yang_revisions.h header file.
+ - reinstall.sh which installs all the modules.
+
+You can run this tool:
+
+@verbatim
+src/lib/yang/pretests/sysrepo_setup_tests
+@endverbatim
+
+to verify that your environment is ready. If there is anything
+wrong, it will enumerate the problems and will suggest how to solve
+them.
+
+@section yangMTConsiderations Multi-Threading Consideration for YANG Utilities
+
+The YANG utilities are not thread safe. Note as they are used only in a
+configuration context it is not a problem, and the yang / sysrepo libraries
+are multi-threaded so their APIs are thread safe.
+
+*/
diff --git a/src/lib/yang/yang_models.h b/src/lib/yang/yang_models.h
new file mode 100644
index 0000000..d5b6d1f
--- /dev/null
+++ b/src/lib/yang/yang_models.h
@@ -0,0 +1,37 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_YANG_MODELS_H
+#define ISC_YANG_MODELS_H 1
+
+#include <string>
+
+namespace isc {
+namespace yang {
+
+/// This model is being developed at DHC working group in IETF.
+/// For details, see draft-ietf-dhc-dhcpv6-yang Internet Draft.
+/// It is a generic model that is somewhat applicable to Kea.
+static const std::string IETF_DHCPV6_SERVER = "ietf-dhcpv6-server";
+
+/// This model is being developed by ISC and is dedicated to Kea.
+static const std::string KEA_DHCP4_SERVER = "kea-dhcp4-server";
+
+/// This model is being developed by ISC and is dedicated to Kea.
+static const std::string KEA_DHCP6_SERVER = "kea-dhcp6-server";
+
+/// This model is currently in prototype phase. It will be developed
+/// by ISC in the near future.
+static const std::string KEA_DHCP_DDNS = "kea-dhcp-ddns";
+
+/// This model is currently in prototype phase. It will be developed
+/// by ISC in the near future.
+static const std::string KEA_CTRL_AGENT = "kea-ctrl-agent";
+
+} // end of namespace isc::yang
+} // end of namespace isc
+
+#endif // ISC_YANG_MODELS_H
diff --git a/src/lib/yang/yang_revisions.h b/src/lib/yang/yang_revisions.h
new file mode 100644
index 0000000..1c2f353
--- /dev/null
+++ b/src/lib/yang/yang_revisions.h
@@ -0,0 +1,35 @@
+// 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_YANG_REVISIONS_H
+#define ISC_YANG_REVISIONS_H 1
+
+#include <map>
+#include <string>
+
+namespace isc {
+namespace yang {
+
+// Table of module name / revision.
+static const std::map<std::string, std::string> YANG_REVISIONS = {
+#ifdef KEATEST_MODULE
+ { "keatest-module", "2018-11-20" },
+#endif // KEATEST_MODULE
+ { "ietf-dhcpv6-types", "2018-09-04" },
+ { "ietf-dhcpv6-options", "2018-09-04" },
+ { "ietf-dhcpv6-server", "2018-09-04" },
+ { "kea-types", "2019-08-12" },
+ { "kea-dhcp-types", "2022-07-27" },
+ { "kea-dhcp4-server", "2022-07-27" },
+ { "kea-dhcp6-server", "2022-07-27" },
+ { "kea-ctrl-agent", "2019-08-12" },
+ { "kea-dhcp-ddns", "2022-07-27" }
+};
+
+} // namespace yang
+} // namespace isc
+
+#endif // ISC_YANG_REVISIONS_H
diff --git a/src/lib/yang/yang_revisions.h.skel b/src/lib/yang/yang_revisions.h.skel
new file mode 100644
index 0000000..200b0bb
--- /dev/null
+++ b/src/lib/yang/yang_revisions.h.skel
@@ -0,0 +1,27 @@
+// Copyright (C) 2018 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_YANG_REVISIONS_H
+#define ISC_YANG_REVISIONS_H 1
+
+#include <map>
+#include <string>
+
+namespace isc {
+namespace yang {
+
+// Table of module name / revision.
+static const std::map<std::string, std::string> YANG_REVISIONS = {
+// Fill this by:
+// cd .../src/share/yang/modules
+// sh utils/gen-revisions.sh > r
+// insert the r file here
+};
+
+}; // end of namespace isc::yang
+}; // end of namespace isc
+
+#endif // ISC_YANG_REVISIONS_H