diff options
Diffstat (limited to '')
78 files changed, 21075 insertions, 0 deletions
diff --git a/src/lib/yang/Makefile.am b/src/lib/yang/Makefile.am new file mode 100644 index 0000000..123f004 --- /dev/null +++ b/src/lib/yang/Makefile.am @@ -0,0 +1,83 @@ +SUBDIRS = . testutils pretests tests + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += $(LIBYANG_CPPFLAGS) +AM_CPPFLAGS += $(LIBYANG_INCLUDEDIR) +AM_CPPFLAGS += $(LIBYANGCPP_CPPFLAGS) +AM_CPPFLAGS += $(LIBYANGCPP_INCLUDEDIR) +AM_CPPFLAGS += $(SYSREPO_CPPFLAGS) +AM_CPPFLAGS += $(SYSREPO_INCLUDEDIR) +AM_CPPFLAGS += $(SYSREPOCPP_CPPFLAGS) +AM_CPPFLAGS += $(SYSREPOCPP_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 += netconf_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/cc/libkea-cc.la +libkea_yang_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.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) +libkea_yang_la_LIBADD += $(LIBYANG_LIBS) +libkea_yang_la_LIBADD += $(LIBYANGCPP_LIBS) +libkea_yang_la_LIBADD += $(SYSREPO_LIBS) +libkea_yang_la_LIBADD += $(SYSREPOCPP_LIBS) + +libkea_yang_la_LDFLAGS = -no-undefined -version-info 46: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 \ + netconf_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..a398af4 --- /dev/null +++ b/src/lib/yang/Makefile.in @@ -0,0 +1,1067 @@ +# 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_cpp20.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_netconf.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/cc/libkea-cc.la \ + $(top_builddir)/src/lib/asiolink/libkea-asiolink.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__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_GSSAPI_CONFIGURE_FLAG = @DISTCHECK_GSSAPI_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG = @DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG@ +DISTCHECK_LIBYANG_CONFIGURE_FLAG = @DISTCHECK_LIBYANG_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_MYSQL_CONFIGURE_FLAG = @DISTCHECK_MYSQL_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PGSQL_CONFIGURE_FLAG = @DISTCHECK_PGSQL_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG = @DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG@ +DISTCHECK_SYSREPO_CONFIGURE_FLAG = @DISTCHECK_SYSREPO_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_NETCONF = @HAVE_NETCONF@ +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@ +LIBYANGCPP_CPPFLAGS = @LIBYANGCPP_CPPFLAGS@ +LIBYANGCPP_INCLUDEDIR = @LIBYANGCPP_INCLUDEDIR@ +LIBYANGCPP_LIBS = @LIBYANGCPP_LIBS@ +LIBYANGCPP_PREFIX = @LIBYANGCPP_PREFIX@ +LIBYANGCPP_VERSION = @LIBYANGCPP_VERSION@ +LIBYANG_CPPFLAGS = @LIBYANG_CPPFLAGS@ +LIBYANG_INCLUDEDIR = @LIBYANG_INCLUDEDIR@ +LIBYANG_LIBS = @LIBYANG_LIBS@ +LIBYANG_PREFIX = @LIBYANG_PREFIX@ +LIBYANG_VERSION = @LIBYANG_VERSION@ +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_PLUGINS_PATH = @SR_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_CPPFLAGS = @SYSREPOCPP_CPPFLAGS@ +SYSREPOCPP_INCLUDEDIR = @SYSREPOCPP_INCLUDEDIR@ +SYSREPOCPP_LIBS = @SYSREPOCPP_LIBS@ +SYSREPOCPP_PREFIX = @SYSREPOCPP_PREFIX@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_PREFIX = @SYSREPO_PREFIX@ +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) $(LIBYANG_CPPFLAGS) $(LIBYANG_INCLUDEDIR) \ + $(LIBYANGCPP_CPPFLAGS) $(LIBYANGCPP_INCLUDEDIR) \ + $(SYSREPO_CPPFLAGS) $(SYSREPO_INCLUDEDIR) \ + $(SYSREPOCPP_CPPFLAGS) $(SYSREPOCPP_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 \ + netconf_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/cc/libkea-cc.la \ + $(top_builddir)/src/lib/asiolink/libkea-asiolink.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) $(LIBYANG_LIBS) \ + $(LIBYANGCPP_LIBS) $(SYSREPO_LIBS) $(SYSREPOCPP_LIBS) +libkea_yang_la_LDFLAGS = -no-undefined -version-info 46: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 \ + netconf_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..5e2de98 --- /dev/null +++ b/src/lib/yang/adaptor.cc @@ -0,0 +1,302 @@ +// 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 <iostream> + +using namespace std; +using namespace isc::data; + +namespace isc { +namespace yang { + +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; + } + for (ElementPtr const& 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; + for (ElementPtr const& 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) { + for (ElementPtr const& 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) { + ElementPtr item = scope->getNonConst(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; + } + ConstElementPtr down(scope->get(name)); + if (down) { + ElementPtr mutable_down(copy(down, 0)); + applyDown(path, actions, mutable_down, next); + scope->set(name, mutable_down); + } + } 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); + } + } +} + +} //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); +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/adaptor.h b/src/lib/yang/adaptor.h new file mode 100644 index 0000000..d4909fb --- /dev/null +++ b/src/lib/yang/adaptor.h @@ -0,0 +1,121 @@ +// 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 <cc/data.h> +#include <exceptions/exceptions.h> + +namespace isc { +namespace yang { + +/// @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 Destructor. + virtual ~Adaptor() = default; + + /// @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 an ElementPtr received from YANG. + /// + /// 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); + +}; // Adaptor + +} // namespace yang +} // 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..a97bf09 --- /dev/null +++ b/src/lib/yang/adaptor_config.cc @@ -0,0 +1,653 @@ +// 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 <dhcpsrv/subnet_id.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 { + +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 (ElementPtr const& 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 (ElementPtr const& 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 (ElementPtr const& 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 (ElementPtr const& 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 pd_pools = subnet->get("pd-pools"); + if (pd_pools) { + if (!pd_pools->empty()) { + sanitizeOptionPools(pd_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 require = pool->get("require-client-classes"); + if (require && require->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 require = subnet->get("require-client-classes"); + if (require && require->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 require = network->get("require-client-classes"); + if (require && require->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 (ElementPtr const& 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 (ElementPtr const& 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(ElementPtr dhcp) { + ConstElementPtr database = dhcp->get("hosts-database"); + if (!database) { + // nothing to do here. + return; + } + + dhcp->remove("hosts-database"); + ElementPtr list = Element::createList(); + list->add(copy(database, 0)); + dhcp->set("hosts-databases", list); +} + +void +AdaptorConfig::sanitizeRelaySuppliedOptions(ElementPtr dhcp) { + ConstElementPtr options = dhcp->get("relay-supplied-options"); + if (!options || !options->empty()) { + // nothing to do here. + return; + } + 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(ElementPtr 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(copy(dhcp, 0)); + preProcess(mutable_dhcp, "subnet4", DHCP4_SPACE); + config->set("Dhcp4", mutable_dhcp); +} + +void +AdaptorConfig::preProcess6(ElementPtr 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(copy(dhcp, 0)); + preProcess(mutable_dhcp, "subnet6", DHCP6_SPACE); + config->set("Dhcp6", mutable_dhcp); +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/adaptor_config.h b/src/lib/yang/adaptor_config.h new file mode 100644 index 0000000..4848250 --- /dev/null +++ b/src/lib/yang/adaptor_config.h @@ -0,0 +1,286 @@ +// 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 <dhcpsrv/subnet_id.h> +#include <yang/adaptor_host.h> +#include <yang/adaptor_option.h> +#include <yang/adaptor_pool.h> +#include <yang/adaptor_subnet.h> + +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 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::ElementPtr 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::ElementPtr 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, + isc::dhcp::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, + isc::dhcp::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, + isc::dhcp::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, + isc::dhcp::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::ElementPtr dhcp); + + /// @brief Update relay supplied options. + /// + /// Remove empty relay supplied option list. + /// + /// @param dhcp The DHCPv6 server. + static void sanitizeRelaySuppliedOptions(isc::data::ElementPtr 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); +}; // AdaptorConfig + +} // namespace yang +} // 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..990a103 --- /dev/null +++ b/src/lib/yang/adaptor_host.cc @@ -0,0 +1,64 @@ +// 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> +#include <vector> + +using namespace std; +using namespace isc::data; +using namespace isc::util; + +namespace isc { +namespace yang { + +const string +AdaptorHost::STD_CHARACTERS = + "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.@_"; + +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())); +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/adaptor_host.h b/src/lib/yang/adaptor_host.h new file mode 100644 index 0000000..75dee52 --- /dev/null +++ b/src/lib/yang/adaptor_host.h @@ -0,0 +1,44 @@ +// 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 Destructor. + virtual ~AdaptorHost() = default; + + /// @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); +}; // AdaptorHost + +} // namespace yang +} // 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..e0405c1 --- /dev/null +++ b/src/lib/yang/adaptor_option.cc @@ -0,0 +1,123 @@ +// 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 <dhcp/docsis3_option_defs.h> +#include <dhcp/std_option_defs.h> +#include <yang/adaptor_option.h> +#include <yang/netconf_error.h> + +using namespace std; +using namespace isc::data; +using namespace isc::dhcp; + +namespace isc { +namespace yang { + +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(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(pair<string, uint16_t>(index, params[i].code)); + } +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/adaptor_option.h b/src/lib/yang/adaptor_option.h new file mode 100644 index 0000000..6acbeef --- /dev/null +++ b/src/lib/yang/adaptor_option.h @@ -0,0 +1,102 @@ +// 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 <dhcp/option_data_types.h> +#include <yang/adaptor.h> + +#include <unordered_map> + +namespace isc { +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. +using OptionCodes = std::unordered_map<std::string, uint16_t>; + +/// @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 Destructor. + virtual ~AdaptorOption() = default; + + /// @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); +}; // AdaptorOption + +} // namespace yang +} // 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..6d9aeae --- /dev/null +++ b/src/lib/yang/adaptor_pool.cc @@ -0,0 +1,83 @@ +// 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> + +#include <vector> + +using namespace std; +using namespace isc::data; + +namespace isc { +namespace yang { + +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); +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/adaptor_pool.h b/src/lib/yang/adaptor_pool.h new file mode 100644 index 0000000..b82458b --- /dev/null +++ b/src/lib/yang/adaptor_pool.h @@ -0,0 +1,93 @@ +// 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> + +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 Destructor. + virtual ~AdaptorPool() = default; + + /// @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); +}; // AdaptorPool + +} // namespace yang +} // 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..0beba82 --- /dev/null +++ b/src/lib/yang/adaptor_subnet.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 <dhcpsrv/subnet_id.h> +#include <yang/adaptor_subnet.h> + +using namespace std; +using namespace isc::data; +using namespace isc::dhcp; + +namespace isc { +namespace yang { + +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"); + } +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/adaptor_subnet.h b/src/lib/yang/adaptor_subnet.h new file mode 100644 index 0000000..f357eb9 --- /dev/null +++ b/src/lib/yang/adaptor_subnet.h @@ -0,0 +1,60 @@ +// 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 <dhcpsrv/subnet_id.h> +#include <yang/adaptor.h> + +namespace isc { +namespace yang { + +/// @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 Destructor. + virtual ~AdaptorSubnet() = default; + + /// @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, + isc::dhcp::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, + isc::dhcp::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); +}; // AdaptorSubnet + +} // namespace yang +} // namespace isc + +#endif // ISC_ADAPTOR_SUBNET_H diff --git a/src/lib/yang/netconf_error.h b/src/lib/yang/netconf_error.h new file mode 100644 index 0000000..17aed1b --- /dev/null +++ b/src/lib/yang/netconf_error.h @@ -0,0 +1,39 @@ +// 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 Missing node error +struct MissingNode : public Exception { + MissingNode(const char* file, size_t line, const char* what) : + Exception(file, line, what) + {} +}; // MissingNode + +/// @brief Missing key error +struct MissingKey : public MissingNode { + MissingKey(const char* file, size_t line, const char* what) : + MissingNode(file, line, what) + {} +}; // MissingKey + +/// @brief Generic NETCONF error +struct NetconfError : public Exception { + NetconfError(const char* file, size_t line, const char* what) : + Exception(file, line, what) + {} +}; // NetconfError + +} // namespace yang +} // namespace isc + +#endif // ISC_SYSREPO_ERROR_H diff --git a/src/lib/yang/pretests/Makefile.am b/src/lib/yang/pretests/Makefile.am new file mode 100644 index 0000000..17c9b20 --- /dev/null +++ b/src/lib/yang/pretests/Makefile.am @@ -0,0 +1,25 @@ +CLEANFILES = *.gcno *.gcda + +TESTS = sysrepo_setup_tests + +sysrepo_setup_tests_SOURCES = sysrepo_setup_tests.cc +sysrepo_setup_tests_CPPFLAGS = +sysrepo_setup_tests_CPPFLAGS += -I$(top_builddir)/src/lib +sysrepo_setup_tests_CPPFLAGS += -I$(top_srcdir)/src/lib +sysrepo_setup_tests_CPPFLAGS += -DKEATEST_MODULE +sysrepo_setup_tests_CPPFLAGS += $(LIBYANG_CPPFLAGS) +sysrepo_setup_tests_CPPFLAGS += $(LIBYANG_INCLUDEDIR) +sysrepo_setup_tests_CPPFLAGS += $(LIBYANGCPP_CPPFLAGS) +sysrepo_setup_tests_CPPFLAGS += $(LIBYANGCPP_INCLUDEDIR) +sysrepo_setup_tests_CPPFLAGS += $(SYSREPO_CPPFLAGS) +sysrepo_setup_tests_CPPFLAGS += $(SYSREPO_INCLUDEDIR) +sysrepo_setup_tests_CPPFLAGS += $(SYSREPOCPP_CPPFLAGS) +sysrepo_setup_tests_CPPFLAGS += $(SYSREPOCPP_INCLUDEDIR) +sysrepo_setup_tests_LDFLAGS = $(AM_LDFLAGS) +sysrepo_setup_tests_LDADD = +sysrepo_setup_tests_LDADD += $(LIBYANG_LIBS) +sysrepo_setup_tests_LDADD += $(LIBYANGCPP_LIBS) +sysrepo_setup_tests_LDADD += $(SYSREPO_LIBS) +sysrepo_setup_tests_LDADD += $(SYSREPOCPP_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..4b6ea52 --- /dev/null +++ b/src/lib/yang/pretests/Makefile.in @@ -0,0 +1,853 @@ +# 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_cpp20.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_netconf.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__DEPENDENCIES_1) $(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 = +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='[0;31m'; \ + grn='[0;32m'; \ + lgn='[1;32m'; \ + blu='[1;34m'; \ + mgn='[0;35m'; \ + brg='[1m'; \ + std='[m'; \ + 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_GSSAPI_CONFIGURE_FLAG = @DISTCHECK_GSSAPI_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG = @DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG@ +DISTCHECK_LIBYANG_CONFIGURE_FLAG = @DISTCHECK_LIBYANG_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_MYSQL_CONFIGURE_FLAG = @DISTCHECK_MYSQL_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PGSQL_CONFIGURE_FLAG = @DISTCHECK_PGSQL_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG = @DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG@ +DISTCHECK_SYSREPO_CONFIGURE_FLAG = @DISTCHECK_SYSREPO_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_NETCONF = @HAVE_NETCONF@ +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@ +LIBYANGCPP_CPPFLAGS = @LIBYANGCPP_CPPFLAGS@ +LIBYANGCPP_INCLUDEDIR = @LIBYANGCPP_INCLUDEDIR@ +LIBYANGCPP_LIBS = @LIBYANGCPP_LIBS@ +LIBYANGCPP_PREFIX = @LIBYANGCPP_PREFIX@ +LIBYANGCPP_VERSION = @LIBYANGCPP_VERSION@ +LIBYANG_CPPFLAGS = @LIBYANG_CPPFLAGS@ +LIBYANG_INCLUDEDIR = @LIBYANG_INCLUDEDIR@ +LIBYANG_LIBS = @LIBYANG_LIBS@ +LIBYANG_PREFIX = @LIBYANG_PREFIX@ +LIBYANG_VERSION = @LIBYANG_VERSION@ +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_PLUGINS_PATH = @SR_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_CPPFLAGS = @SYSREPOCPP_CPPFLAGS@ +SYSREPOCPP_INCLUDEDIR = @SYSREPOCPP_INCLUDEDIR@ +SYSREPOCPP_LIBS = @SYSREPOCPP_LIBS@ +SYSREPOCPP_PREFIX = @SYSREPOCPP_PREFIX@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_PREFIX = @SYSREPO_PREFIX@ +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 -DKEATEST_MODULE $(LIBYANG_CPPFLAGS) \ + $(LIBYANG_INCLUDEDIR) $(LIBYANGCPP_CPPFLAGS) \ + $(LIBYANGCPP_INCLUDEDIR) $(SYSREPO_CPPFLAGS) \ + $(SYSREPO_INCLUDEDIR) $(SYSREPOCPP_CPPFLAGS) \ + $(SYSREPOCPP_INCLUDEDIR) +sysrepo_setup_tests_LDFLAGS = $(AM_LDFLAGS) +sysrepo_setup_tests_LDADD = $(LIBYANG_LIBS) $(LIBYANGCPP_LIBS) \ + $(SYSREPO_LIBS) $(SYSREPOCPP_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..9af2386 --- /dev/null +++ b/src/lib/yang/pretests/sysrepo_setup_tests.cc @@ -0,0 +1,119 @@ +// 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/yang_revisions.h> + +#include <sysrepo-cpp/Connection.hpp> +#include <sysrepo-cpp/Session.hpp> + +#include <iostream> +#include <unordered_map> +#include <sstream> +#include <vector> + +using namespace std; +using namespace libyang; +using namespace sysrepo; +using namespace isc::yang; + +using libyang::Context; +using libyang::Module; + +/// @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 + << "Or reinstall all modules:" << endl + << "$ ./src/share/yang/modules/utils/reinstall.sh -u" << 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 + << "Or reinstall all modules:" << endl + << "$ ./src/share/yang/modules/utils/reinstall.sh -u" << 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() { + optional<Session> sess; + try { + sess = Connection{}.sessionStart(); + sess->switchDatastore(sysrepo::Datastore::Candidate); + } catch (Error const& ex) { + cerr << "ERROR: Can't establish a sysrepo session: " + << ex.what() << endl; + return (2); + } + + vector<Module> modules; + try { + Context const& context(sess->getContext()); + modules = context.modules(); + } catch (Error const& ex) { + cerr << "ERROR: Can't retrieve available modules: " << ex.what() << endl; + return (3); + } + + std::unordered_map<std::string, std::string> installed_modules; + for (Module const& module : modules) { + string const name(module.name()); + if (!module.revision()) { + cerr << "ERROR: module " << name << " has no revision." << endl; + return (5); + } + string const revision(*module.revision()); + 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/tests/Makefile.am b/src/lib/yang/tests/Makefile.am new file mode 100644 index 0000000..028f3d9 --- /dev/null +++ b/src/lib/yang/tests/Makefile.am @@ -0,0 +1,70 @@ +AM_CPPFLAGS = +AM_CPPFLAGS += -DKEATEST_MODULE +AM_CPPFLAGS += -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += $(LIBYANG_CPPFLAGS) +AM_CPPFLAGS += $(LIBYANG_INCLUDEDIR) +AM_CPPFLAGS += $(LIBYANGCPP_CPPFLAGS) +AM_CPPFLAGS += $(LIBYANGCPP_INCLUDEDIR) +AM_CPPFLAGS += $(SYSREPO_CPPFLAGS) +AM_CPPFLAGS += $(SYSREPO_INCLUDEDIR) +AM_CPPFLAGS += $(SYSREPOCPP_CPPFLAGS) +AM_CPPFLAGS += $(SYSREPOCPP_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) $(GTEST_LDADD) +run_unittests_LDADD += $(LIBYANG_LIBS) +run_unittests_LDADD += $(LIBYANGCPP_LIBS) +run_unittests_LDADD += $(SYSREPO_LIBS) +run_unittests_LDADD += $(SYSREPOCPP_LIBS) + +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..6c5989a --- /dev/null +++ b/src/lib/yang/tests/Makefile.in @@ -0,0 +1,1315 @@ +# 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_cpp20.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_netconf.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) \ +@HAVE_GTEST_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ +@HAVE_GTEST_TRUE@ $(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='[0;31m'; \ + grn='[0;32m'; \ + lgn='[1;32m'; \ + blu='[1;34m'; \ + mgn='[0;35m'; \ + brg='[1m'; \ + std='[m'; \ + 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_GSSAPI_CONFIGURE_FLAG = @DISTCHECK_GSSAPI_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG = @DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG@ +DISTCHECK_LIBYANG_CONFIGURE_FLAG = @DISTCHECK_LIBYANG_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_MYSQL_CONFIGURE_FLAG = @DISTCHECK_MYSQL_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PGSQL_CONFIGURE_FLAG = @DISTCHECK_PGSQL_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG = @DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG@ +DISTCHECK_SYSREPO_CONFIGURE_FLAG = @DISTCHECK_SYSREPO_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_NETCONF = @HAVE_NETCONF@ +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@ +LIBYANGCPP_CPPFLAGS = @LIBYANGCPP_CPPFLAGS@ +LIBYANGCPP_INCLUDEDIR = @LIBYANGCPP_INCLUDEDIR@ +LIBYANGCPP_LIBS = @LIBYANGCPP_LIBS@ +LIBYANGCPP_PREFIX = @LIBYANGCPP_PREFIX@ +LIBYANGCPP_VERSION = @LIBYANGCPP_VERSION@ +LIBYANG_CPPFLAGS = @LIBYANG_CPPFLAGS@ +LIBYANG_INCLUDEDIR = @LIBYANG_INCLUDEDIR@ +LIBYANG_LIBS = @LIBYANG_LIBS@ +LIBYANG_PREFIX = @LIBYANG_PREFIX@ +LIBYANG_VERSION = @LIBYANG_VERSION@ +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_PLUGINS_PATH = @SR_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_CPPFLAGS = @SYSREPOCPP_CPPFLAGS@ +SYSREPOCPP_INCLUDEDIR = @SYSREPOCPP_INCLUDEDIR@ +SYSREPOCPP_LIBS = @SYSREPOCPP_LIBS@ +SYSREPOCPP_PREFIX = @SYSREPOCPP_PREFIX@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_PREFIX = @SYSREPO_PREFIX@ +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 = -DKEATEST_MODULE -I$(top_builddir)/src/lib \ + -I$(top_srcdir)/src/lib $(BOOST_INCLUDES) $(LIBYANG_CPPFLAGS) \ + $(LIBYANG_INCLUDEDIR) $(LIBYANGCPP_CPPFLAGS) \ + $(LIBYANGCPP_INCLUDEDIR) $(SYSREPO_CPPFLAGS) \ + $(SYSREPO_INCLUDEDIR) $(SYSREPOCPP_CPPFLAGS) \ + $(SYSREPOCPP_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@ $(GTEST_LDADD) $(LIBYANG_LIBS) \ +@HAVE_GTEST_TRUE@ $(LIBYANGCPP_LIBS) $(SYSREPO_LIBS) \ +@HAVE_GTEST_TRUE@ $(SYSREPOCPP_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/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..2109890 --- /dev/null +++ b/src/lib/yang/tests/adaptor_config_unittests.cc @@ -0,0 +1,154 @@ +// Copyright (C) 2018-2023 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 <testutils/gtest_utils.h> +#include <testutils/io_utils.h> +#include <testutils/user_context_utils.h> +#include <yang/adaptor_config.h> + +#include <vector> + +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 string& fname, bool v6, ElementPtr& result) { + ElementPtr json; + ElementPtr reference_json; + + string decommented = decommentJSONfile(fname); + + EXPECT_NO_THROW_LOG(json = Element::fromJSONFile(decommented, true)); + reference_json = moveComments(json); + + // remove the temporary file + EXPECT_NO_THROW_LOG(::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; +} + +}; // AdaptorConfigTest + +TEST_F(AdaptorConfigTest, loadExamples4) { + vector<string> configs = { + "advanced.json", + "all-keys-netconf.json", + "all-options.json", + "backends.json", + "classify.json", + "classify2.json", + "comments.json", + "config-backend.json", + "dhcpv4-over-dhcpv6.json", + "dnr.json", + "global-reservations.json", + "ha-load-balancing-server1-mt-with-tls.json", + "ha-load-balancing-server2-mt.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", + }; + + 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", + "all-options.json", + "backends.json", + "classify.json", + "classify2.json", + "comments.json", + "config-backend.json", + "dhcpv4-over-dhcpv6.json", + "dnr.json", + "duid.json", + "global-reservations.json", + "ha-hot-standby-server1-with-tls.json", + "ha-hot-standby-server2.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", + }; + 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 + +} // 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..0d50632 --- /dev/null +++ b/src/lib/yang/tests/adaptor_host_unittests.cc @@ -0,0 +1,119 @@ +// 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 <gtest/gtest.h> + +#include <testutils/gtest_utils.h> +#include <yang/adaptor_host.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_LOG(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_LOG(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_LOG(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_LOG(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_LOG(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_LOG(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..9fdcb9c --- /dev/null +++ b/src/lib/yang/tests/adaptor_option_unittests.cc @@ -0,0 +1,245 @@ +// 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 <gtest/gtest.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 <yang/netconf_error.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_LOG(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_LOG(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_LOG(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_MSG(AdaptorOption::checkType(json), MissingKey, + "missing type in option definition { }"); +} + +// 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_LOG(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_MSG(AdaptorOption::checkCode(json), MissingKey, "missing code in option { }"); +} + +// 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_FALSE(codes.contains("foo@bar")); +} + +// 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_LOG(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_LOG(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_MSG(AdaptorOption::setCode(json, codes), MissingKey, + "missing name and code in option { \"space\": \"bar\" }"); +} + +// 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_MSG(AdaptorOption::setCode(json, codes), MissingKey, + "can't get code from option { \"name\": \"foo\", \"space\": \"bar\" }"); +} + +/// @brief Test class to make initCodes public. +class TestAdaptorOption : public AdaptorOption { +public: + using AdaptorOption::initCodesInternal; +}; // TestAdaptorOption + +// 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_FALSE(codes.contains("dhcp6@clientid")); + + // 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_FALSE(codes.contains("dhcp4@subnet-mask")); + + // 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"]); +} + +} //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..6152834 --- /dev/null +++ b/src/lib/yang/tests/adaptor_pool_unittests.cc @@ -0,0 +1,276 @@ +// 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 <gtest/gtest.h> + +#include <testutils/gtest_utils.h> +#include <yang/adaptor_pool.h> +#include <yang/yang_models.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_LOG(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_LOG(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_LOG(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_LOG(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_LOG(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_LOG(AdaptorPool::fromSubnet(KEA_DHCP4_SERVER, json, pools)); + EXPECT_TRUE(copied->equals(*json)); + // The model is checked first. + EXPECT_NO_THROW_LOG(AdaptorPool::fromSubnet(KEA_DHCP6_SERVER, json, pools)); + EXPECT_TRUE(copied->equals(*json)); + + // Check that the model name is actually checked. + EXPECT_THROW_MSG(AdaptorPool::fromSubnet("non-existent-module", json, pools), NotImplemented, + "fromSubnet not implemented for the model: non-existent-module"); +} + +// 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_LOG(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_LOG(AdaptorPool::toSubnet(KEA_DHCP4_SERVER, json, pools)); + EXPECT_TRUE(copied->equals(*json)); + // The model is checked first. + EXPECT_NO_THROW_LOG(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_MSG(AdaptorPool::toSubnet("keatest-module", json, pools), NotImplemented, + "toSubnet not implemented for the model: keatest-module"); +} + +// 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_LOG(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_MSG(AdaptorPool::toSubnet(IETF_DHCPV6_SERVER, json, pools), BadValue, + "inconsistent value of rebind-timer in [ { \"pool\": \"2001:db8:1::/80\", " + "\"rebind-timer\": 2000 }, { \"pool\": \"2001:db8:1:0:1::/80\", " + "\"rebind-timer\": 20 } ]"); +} + +} // 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..4b744b4 --- /dev/null +++ b/src/lib/yang/tests/adaptor_subnet_unittests.cc @@ -0,0 +1,214 @@ +// 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 <gtest/gtest.h> + +#include <dhcpsrv/subnet_id.h> +#include <testutils/gtest_utils.h> +#include <yang/adaptor_subnet.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... + +} // 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..f95d5d3 --- /dev/null +++ b/src/lib/yang/tests/adaptor_unittests.cc @@ -0,0 +1,398 @@ +// 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 <gtest/gtest.h> + +#include <testutils/gtest_utils.h> +#include <yang/adaptor.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"; + ElementPtr 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"; + + ElementPtr json = Element::fromJSON(config); + EXPECT_NO_THROW_LOG(Adaptor::fromParent("param1", json, json->get("list"))); + EXPECT_NO_THROW_LOG(Adaptor::fromParent("param2", json, json->get("list"))); + EXPECT_NO_THROW_LOG(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_LOG(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_LOG(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_MSG(Adaptor::toParent("param3", json, json->get("list")), BadValue, + "inconsistent value of param3 in [ { \"param3\": 234, \"param4\": true }, { " + "\"another\": \"entry\", \"param3\": 123, \"param5\": false } ]"); + EXPECT_THROW_MSG(Adaptor::toParent("param4", json, json->get("list")), BadValue, + "inconsistent value of param4 in [ { \"param3\": 234, \"param4\": true }, { " + "\"another\": \"entry\", \"param3\": 123, \"param5\": false } ]"); + EXPECT_THROW_MSG(Adaptor::toParent("param5", json, json->get("list")), BadValue, + "inconsistent value of param5 in [ { \"param3\": 234, \"param4\": true }, { " + "\"another\": \"entry\", \"param3\": 123, \"param5\": false } ]"); + + // 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)); +} + +} // 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..46b591d --- /dev/null +++ b/src/lib/yang/tests/config_unittests.cc @@ -0,0 +1,392 @@ +// Copyright (C) 2018-2023 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 <testutils/io_utils.h> +#include <testutils/user_context_utils.h> +#include <yang/tests/json_configs.h> +#include <yang/tests/sysrepo_setup.h> +#include <yang/tests/yang_configs.h> +#include <yang/translator_config.h> +#include <yang/yang_models.h> + +#include <iostream> +#include <vector> + +#include <boost/algorithm/string.hpp> + +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 +string generateDiff(string left, string right) { + vector<string> left_lines; + boost::split(left_lines, left, boost::is_any_of("\n")); + vector<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 +string generateDiff(string, string) { + return (""); +} +#endif + +/// @brief Test Fixture class for Yang <-> JSON configs. +class ConfigTest : public ::testing::Test { +public: + ConfigTest() : session_(Connection{}.sessionStart()) { + session_.switchDatastore(Datastore::Candidate); + } + virtual ~ConfigTest() = default; + + void SetUp() override { + translator_.reset(new Translator(session_, model_)); + cleanModelData(); + } + + void TearDown() override { + cleanModelData(); + translator_.reset(); + SysrepoSetup::cleanSharedMemory(); + } + + void cleanModelData() { + string toplevel_node("config"); + if (model_ == IETF_DHCPV6_SERVER) { + toplevel_node = "server"; + } + translator_->deleteItem("/" + 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(ElementPtr 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); + ElementPtr 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 The model. + string model_; + + /// @brief The sysrepo session. + Session session_; + + unique_ptr<Translator> translator_; +}; // ConfigTest + +struct ConfigTestKeaV4 : ConfigTest { + ConfigTestKeaV4() { + model_ = KEA_DHCP4_SERVER; + } +}; // ConfigTestKeaV4 +struct ConfigTestKeaV6 : ConfigTest { + ConfigTestKeaV6() { + model_ = KEA_DHCP6_SERVER; + } +}; // ConfigTestKeaV6 +struct ConfigTestIetfV6 : ConfigTest { + ConfigTestIetfV6() { + model_ = IETF_DHCPV6_SERVER; + } +}; // ConfigTestIetfV6 + +// Check empty config with ietf-dhcpv6-server model. +TEST_F(ConfigTestIetfV6, emptyIetf6) { + YRTree tree; + ASSERT_NO_THROW_LOG(load(tree)); + EXPECT_TRUE(verify(tree)); + + ElementPtr 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)); + + ElementPtr 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)); + + ElementPtr 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)); +} + +// 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)); +} + +// 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)); +} + +// 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)); +} + +// 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", + "dnr.json", + "global-reservations.json", + "ha-load-balancing-server1-mt-with-tls.json", + "ha-load-balancing-server2-mt.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; + SCOPED_TRACE("\n* Tested file: " + path); + ConstElementPtr json; + ASSERT_NO_THROW_LOG(json = loadFile(path)); + json = isc::test::moveComments(json); + EXPECT_TRUE(verify(json)); + } +} + +// 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", + "dnr.json", + "duid.json", + "global-reservations.json", + "ha-hot-standby-server1-with-tls.json", + "ha-hot-standby-server2.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; + SCOPED_TRACE("\n* Tested file: " + path); + ConstElementPtr json; + ASSERT_NO_THROW_LOG(json = loadFile(path)); + json = isc::test::moveComments(json); + EXPECT_TRUE(verify(json)); + } +} + +// 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..147cbc7 --- /dev/null +++ b/src/lib/yang/tests/json_configs.h @@ -0,0 +1,176 @@ +// Copyright (C) 2018-2023 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" + " \"never-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" + " \"never-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..24870d1 --- /dev/null +++ b/src/lib/yang/tests/run_unittests.cc @@ -0,0 +1,21 @@ +// 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 <gtest/gtest.h> + +#include <log/logger_support.h> +#include <util/unittests/run_all.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..4e315dd --- /dev/null +++ b/src/lib/yang/tests/sysrepo_setup.h @@ -0,0 +1,96 @@ +// 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 SYSREPO_SETUP_H +#define SYSREPO_SETUP_H + +#include <config.h> + +#include <gtest/gtest.h> + +#include <testutils/gtest_utils.h> +#include <yang/translator.h> +#include <yang/yang_models.h> + +#include <sysrepo-cpp/Connection.hpp> + +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; + } + } +}; // SysrepoSetup + +/// @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(); + sess_ = sysrepo::Connection{}.sessionStart(); + sess_->switchDatastore(sysrepo::Datastore::Candidate); + translator_.reset(new translator_t(*sess_, model_)); + cleanModelData(); + } + + void TearDown() override { + cleanModelData(); + translator_.reset(); + SysrepoSetup::cleanSharedMemory(); + } + + void cleanModelData() { + std::string toplevel_node("config"); + if (model_ == IETF_DHCPV6_SERVER) { + toplevel_node = "server"; + } + translator_->deleteItem("/" + model_ + ":" + toplevel_node); + } + + /// @brief Sysrepo session. + std::optional<sysrepo::Session> sess_; + + /// @brief Shared pointer to the transaction object. + std::shared_ptr<translator_t> translator_; + std::string model_; +}; // GenericTranslatorTest + +} // 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..02405c5 --- /dev/null +++ b/src/lib/yang/tests/translator_class_unittests.cc @@ -0,0 +1,123 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_class.h> +#include <yang/yang_models.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: + /// @brief Constructor + TranslatorClassesTestv4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorClassesTestv4 + +class TranslatorClassesTestv6 : + public GenericTranslatorTest<client_classes, TranslatorClasses> { +public: + /// @brief Constructor + TranslatorClassesTestv6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorClassesTestv6 + +// 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_LOG(classes = translator_->getClassesFromAbsoluteXpath(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"; + string const v_test("not member('ALL')"); + EXPECT_NO_THROW_LOG(sess_->setItem(xtest, v_test)); + sess_->applyChanges(); + + // Get the client class. + ConstElementPtr cclass; + EXPECT_NO_THROW_LOG(cclass = translator_->getClassFromAbsoluteXpath(xclass)); + ASSERT_TRUE(cclass); + ElementPtr expected = Element::createMap(); + expected->set("name", Element::create("foo")); + expected->set("test", Element::create("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_LOG(classes = translator_->getClassesFromAbsoluteXpath(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_LOG(translator_->setClasses(xpath, classes)); + + // Get it back. + classes.reset(); + EXPECT_NO_THROW_LOG(classes = translator_->getClassesFromAbsoluteXpath(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("foo")); + cclass->set("test", Element::create("''==''")); + cclass->set("only-if-required", Element::create(false)); + classes->add(cclass); + EXPECT_NO_THROW_LOG(translator_->setClasses(xpath, classes)); + + // Get it back. + ConstElementPtr got; + EXPECT_NO_THROW_LOG(got = translator_->getClassesFromAbsoluteXpath(xpath)); + ASSERT_TRUE(got); + ASSERT_EQ(Element::list, got->getType()); + ASSERT_EQ(1, got->size()); + EXPECT_TRUE(cclass->equals(*got->get(0))); +} + +} // 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..f9174db --- /dev/null +++ b/src/lib/yang/tests/translator_control_socket_unittests.cc @@ -0,0 +1,174 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_control_socket.h> +#include <yang/yang_models.h> + +using namespace std; +using namespace isc; +using namespace isc::data; +using namespace isc::yang; +using namespace isc::yang::test; +using namespace libyang; +using namespace sysrepo; + +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: + /// @brief Constructor + TranslatorControlSocketTestv4() { + model_ = KEA_DHCP4_SERVER; + } + + virtual ~TranslatorControlSocketTestv4() = default; +}; // TranslatorControlSocketTestv4 + +class TranslatorControlSocketTestv6 : + public GenericTranslatorTest<control_socket, TranslatorControlSocket> { +public: + /// @brief Constructor + TranslatorControlSocketTestv6() { + model_ = KEA_DHCP6_SERVER; + } + + virtual ~TranslatorControlSocketTestv6() = default; +}; // TranslatorControlSocketTestv6 + +class TranslatorControlSocketTestCtrlAgent : + public GenericTranslatorTest<control_socket, TranslatorControlSocket> { +public: + /// @brief Constructor + TranslatorControlSocketTestCtrlAgent() { + model_ = KEA_CTRL_AGENT; + } + + virtual ~TranslatorControlSocketTestCtrlAgent() = default; +}; // TranslatorControlSocketTestCtrlAgent + +// 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_LOG(sock = translator_->getControlSocketFromAbsoluteXpath(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"; + string const s_name("/tmp/kea.sock"); + EXPECT_NO_THROW_LOG(sess_->setItem(xname, s_name)); + string const s_type("unix"); + EXPECT_NO_THROW_LOG(sess_->setItem(xtype, s_type)); + string const s_context("{ \"foo\": 1 }"); + EXPECT_NO_THROW_LOG(sess_->setItem(xcontext, s_context)); + sess_->applyChanges(); + + // Get it. + ConstElementPtr sock; + EXPECT_NO_THROW_LOG(sock = translator_->getControlSocketFromAbsoluteXpath(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("/tmp/kea.sock")); + sock->set("socket-type", Element::create("unix")); + sock->set("comment", Element::create("a comment")); + try { + translator_->setControlSocket(xpath, sock); + } catch (exception const& ex) { + cerr << "setControlSocket fail with " << ex.what() << endl; + } + ASSERT_NO_THROW_LOG(translator_->setControlSocket(xpath, sock)); + + // Get it back. + ConstElementPtr got; + EXPECT_NO_THROW_LOG(got = translator_->getControlSocketFromAbsoluteXpath(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()); +} + +// 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"; + string const s_name("/tmp/kea.sock"); + EXPECT_NO_THROW_LOG(sess_->setItem(xname, s_name)); + string const s_type("unix"); + EXPECT_NO_THROW_LOG(sess_->setItem(xtype, s_type)); + string const s_context("{ \"foo\": 1 }"); + EXPECT_NO_THROW_LOG(sess_->setItem(xcontext, s_context)); + sess_->applyChanges(); + + // Get it back. + ConstElementPtr sock; + EXPECT_NO_THROW_LOG(sock = translator_->getControlSocketFromAbsoluteXpath(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_LOG(translator_->setControlSocket(xpath, ConstElementPtr())); + + // Get it back. + EXPECT_NO_THROW_LOG(sock = translator_->getControlSocketFromAbsoluteXpath(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..4203bcb --- /dev/null +++ b/src/lib/yang/tests/translator_database_unittests.cc @@ -0,0 +1,324 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_database.h> +#include <yang/yang_models.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; +}; // TranslatorDatabaseTestv4 + +class TranslatorDatabaseTestv6 : + public GenericTranslatorTest<database_access, TranslatorDatabase> { +public: + TranslatorDatabaseTestv6() { + model_ = KEA_DHCP6_SERVER; + } + + virtual ~TranslatorDatabaseTestv6() = default; +}; // TranslatorDatabaseTestv6 + +// 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_LOG(database = translator_->getDatabaseFromAbsoluteXpath(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"; + string const s_type("memfile"); + EXPECT_NO_THROW_LOG(sess_->setItem(xtype, s_type)); + uint32_t li = 3600; + string const s_interval(to_string(li)); + EXPECT_NO_THROW_LOG(sess_->setItem(xinterval, s_interval)); + sess_->applyChanges(); + + // Get empty. + ConstElementPtr database; + EXPECT_NO_THROW_LOG(database = translator_->getDatabaseFromAbsoluteXpath(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("memfile")); + database->set("lfc-interval", Element::create(3600)); + ASSERT_NO_THROW_LOG(translator_->setDatabase(xpath, database)); + + // Get it back. + ConstElementPtr got; + EXPECT_NO_THROW_LOG(got = translator_->getDatabaseFromAbsoluteXpath(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"; + string const s_type("memfile"); + EXPECT_NO_THROW_LOG(sess_->setItem(xtype, s_type)); + uint32_t li = 3600; + string const s_interval(to_string(li)); + EXPECT_NO_THROW_LOG(sess_->setItem(xinterval, s_interval)); + sess_->applyChanges(); + + // Reset to empty. + ASSERT_NO_THROW_LOG(translator_->setDatabase(xpath, ConstElementPtr())); + + // Get it back. + ConstElementPtr database; + EXPECT_NO_THROW_LOG(database = translator_->getDatabaseFromAbsoluteXpath(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: + /// @brief Constructor + TranslatorDatabasesTestv4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorDatabasesTestv4 + +class TranslatorDatabasesTestv6 : + public GenericTranslatorTest<database_accesses, TranslatorDatabases> { +public: + /// @brief Constructor + TranslatorDatabasesTestv6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorDatabasesTestv6 + +// 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_LOG(databases = translator_->getDatabasesFromAbsoluteXpath(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"; + string const s_name("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xname, s_name)); + string const s_user("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xuser, s_user)); + string const s_password("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xpassword, s_password)); + string const s_host("localhost"); + EXPECT_NO_THROW_LOG(sess_->setItem(xhost, s_host)); + uint16_t mport = 3306; + string const s_port(to_string(mport)); + EXPECT_NO_THROW_LOG(sess_->setItem(xport, s_port)); + sess_->applyChanges(); + + // Get empty. + ConstElementPtr databases; + EXPECT_NO_THROW_LOG(databases = translator_->getDatabasesFromAbsoluteXpath(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("memfile")); + database->set("lfc-interval", Element::create(3600)); + ElementPtr databases = Element::createList(); + databases->add(database); + ASSERT_NO_THROW_LOG(translator_->setDatabases(xpath, databases)); + + // Get it back. + ConstElementPtr gots; + EXPECT_NO_THROW_LOG(gots = translator_->getDatabasesFromAbsoluteXpath(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()); +} + +// 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"; + string const s_name("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xname, s_name)); + string const s_user("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xuser, s_user)); + string const s_password("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xpassword, s_password)); + string const s_host("localhost"); + EXPECT_NO_THROW_LOG(sess_->setItem(xhost, s_host)); + uint16_t mport = 3306; + string const s_port(to_string(mport)); + EXPECT_NO_THROW_LOG(sess_->setItem(xport, s_port)); + sess_->applyChanges(); + + // Reset to empty. + EXPECT_NO_THROW_LOG(translator_->setDatabase(xdatabase, ConstElementPtr())); + + // Get empty. + ConstElementPtr databases; + EXPECT_NO_THROW_LOG(databases = translator_->getDatabasesFromAbsoluteXpath(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"; + string const s_name("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xname, s_name)); + string const s_user("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xuser, s_user)); + string const s_password("kea"); + EXPECT_NO_THROW_LOG(sess_->setItem(xpassword, s_password)); + string const s_host("localhost"); + EXPECT_NO_THROW_LOG(sess_->setItem(xhost, s_host)); + uint16_t mport = 3306; + string const s_port(to_string(mport)); + EXPECT_NO_THROW_LOG(sess_->setItem(xport, s_port)); + sess_->applyChanges(); + + // Reset to empty. + EXPECT_NO_THROW_LOG(translator_->setDatabases(xdatabase, ConstElementPtr())); + + // Get empty. + ConstElementPtr databases; + EXPECT_NO_THROW_LOG(databases = translator_->getDatabasesFromAbsoluteXpath(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..d51c235 --- /dev/null +++ b/src/lib/yang/tests/translator_host_unittests.cc @@ -0,0 +1,192 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_host.h> +#include <yang/yang_models.h> + +#include <sstream> + +using namespace std; +using namespace isc; +using namespace isc::data; +using namespace isc::yang; +using namespace isc::yang::test; +using namespace libyang; +using namespace sysrepo; + +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: + /// @brief Constructor + TranslatorHostsTestv4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorHostsTestv4 + +class TranslatorHostsTestv6 : + public GenericTranslatorTest<host_reservations, TranslatorHosts> { +public: + /// @brief Constructor + TranslatorHostsTestv6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorHostsTestv6 + +// 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_LOG(hosts = translator_->getHostsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Create the host reservation for 2001:db8::1. + ostringstream shost; + shost << xpath + "/host[identifier-type='hw-address']" + << "[identifier='00:01:02:03:04:05']"; + const string& xaddr = shost.str() + "/ip-addresses"; + string const s_addr("2001:db8::1"); + EXPECT_NO_THROW_LOG(sess_->setItem(xaddr, s_addr)); + sess_->applyChanges(); + + // Get the host. + ConstElementPtr host; + EXPECT_NO_THROW_LOG(host = translator_->getHostFromAbsoluteXpath(shost.str())); + ASSERT_TRUE(host); + ElementPtr expected = Element::createMap(); + ElementPtr addresses = Element::createList(); + addresses->add(Element::create("2001:db8::1")); + expected->set("hw-address", Element::create("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_LOG(hosts = translator_->getHostsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Set empty list. + ConstElementPtr hosts = Element::createList(); + EXPECT_NO_THROW_LOG(translator_->setHosts(xpath, hosts)); + + // Get it back. + hosts.reset(); + EXPECT_NO_THROW_LOG(hosts = translator_->getHostsFromAbsoluteXpath(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']"; + string const v_subnet("10.0.0.0/24"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Set one host. + ElementPtr hosts = Element::createList(); + ElementPtr host = Element::createMap(); + host->set("flex-id", Element::create("00:ff")); + host->set("ip-address", Element::create("10.0.0.1")); + host->set("hostname", Element::create("foo")); + hosts->add(host); + EXPECT_NO_THROW_LOG(translator_->setHosts(xpath, hosts)); + + // Get it back. + hosts.reset(); + EXPECT_NO_THROW_LOG(hosts = translator_->getHostsFromAbsoluteXpath(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 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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Create the host reservation for 2001:db8::1. + ostringstream shost; + shost << xpath + "/host[identifier-type='hw-address']" + << "[identifier='00:01:02:03:04:05']"; + const string& xaddr = shost.str() + "/ip-addresses"; + string const s_addr("2001:db8::1"); + EXPECT_NO_THROW_LOG(sess_->setItem(xaddr, s_addr)); + sess_->applyChanges(); + + // Create another reservation for 2001:db8::2 + ostringstream shost2; + shost2 << xpath + "/host[identifier-type='hw-address']" + << "[identifier='00:01:0a:0b:0c:0d']"; + const string xaddr2 = shost2.str() + "/ip-addresses"; + string const s_addr2("2001:db8::2"); + EXPECT_NO_THROW_LOG(sess_->setItem(xaddr2, s_addr2)); + sess_->applyChanges(); + + // Get the host. + ConstElementPtr hosts; + EXPECT_NO_THROW_LOG(hosts = translator_->getHostsFromAbsoluteXpath(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\" ] } ]"); +} + +} // 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..365e4bd --- /dev/null +++ b/src/lib/yang/tests/translator_logger_unittests.cc @@ -0,0 +1,156 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_logger.h> +#include <yang/yang_models.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: + /// @brief Constructor + TranslatorLoggersTestv4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorLoggersTestv4 + +class TranslatorLoggersTestv6 : + public GenericTranslatorTest<logger_list, TranslatorLoggers> { +public: + /// @brief Constructor + TranslatorLoggersTestv6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorLoggersTestv6 + +// 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_LOG(loggers = translator_->getLoggersFromAbsoluteXpath(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"; + string const s_severity("WARN"); + EXPECT_NO_THROW_LOG(sess_->setItem(xseverity, s_severity)); + uint32_t max_ver = 10; + string const s_maxver(to_string(max_ver)); + EXPECT_NO_THROW_LOG(sess_->setItem(xmaxver, s_maxver)); + sess_->applyChanges(); + + // Get empty. + ConstElementPtr loggers; + EXPECT_NO_THROW_LOG(loggers = translator_->getLoggersFromAbsoluteXpath(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("/bar")); + option->set("maxver", Element::create(10)); + ElementPtr options = Element::createList(); + options->add(option); + ElementPtr logger = Element::createMap(); + logger->set("name", Element::create("foo")); + logger->set("severity", Element::create("WARN")); + logger->set("output_options", options); + ElementPtr loggers = Element::createList(); + loggers->add(logger); + ASSERT_NO_THROW_LOG(translator_->setLoggers(xpath, loggers)); + + // Get it back. + ConstElementPtr gots; + EXPECT_NO_THROW_LOG(gots = translator_->getLoggersFromAbsoluteXpath(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()); +} + +/// @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..3917e26 --- /dev/null +++ b/src/lib/yang/tests/translator_option_data_unittests.cc @@ -0,0 +1,135 @@ +// Copyright (C) 2018-2023 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 <yang/tests/sysrepo_setup.h> +#include <yang/translator_option_data.h> +#include <yang/yang_models.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 option_data_list[] = "option data list"; + +/// @brief Test fixture class for @ref TranslatorOptionDataList. +class TranslatorOptionDataListTestv4 : + public GenericTranslatorTest<option_data_list, TranslatorOptionDataList> { +public: + /// @brief Constructor + TranslatorOptionDataListTestv4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorOptionDataListTestv4 + +class TranslatorOptionDataListTestv6 : + public GenericTranslatorTest<option_data_list, TranslatorOptionDataList> { +public: + /// @brief Constructor + TranslatorOptionDataListTestv6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorOptionDataListTestv6 + +// 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_LOG(options = translator_->getOptionDataListFromAbsoluteXpath(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& xalways = xoption + "/always-send"; + const string& xnever = xoption + "/never-send"; + string const s_false("false"); + ASSERT_NO_THROW_LOG(sess_->setItem(xformat, s_false)); + string const s_data("12121212"); + ASSERT_NO_THROW_LOG(sess_->setItem(xdata, s_data)); + ASSERT_NO_THROW_LOG(sess_->setItem(xalways, s_false)); + ASSERT_NO_THROW_LOG(sess_->setItem(xnever, s_false)); + sess_->applyChanges(); + + // Get the option data. + ConstElementPtr option; + EXPECT_NO_THROW_LOG(option = translator_->getOptionDataFromAbsoluteXpath(xoption)); + ASSERT_TRUE(option); + EXPECT_EQ("{" + " \"always-send\": false," + " \"code\": 100," + " \"csv-format\": false," + " \"data\": \"12121212\"," + " \"never-send\": false," + " \"space\": \"dns\"" + " }", + option->str()); + + // Get the option data list. + ConstElementPtr options; + EXPECT_NO_THROW_LOG(options = translator_->getOptionDataListFromAbsoluteXpath(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_LOG(translator_->setOptionDataList(xpath, options)); + + // Get it back. + options.reset(); + EXPECT_NO_THROW_LOG(options = translator_->getOptionDataListFromAbsoluteXpath(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("dns")); + option->set("csv-format", Element::create(false)); + option->set("data", Element::create("12121212")); + option->set("always-send", Element::create(false)); + option->set("never-send", Element::create(false)); + options->add(option); + EXPECT_NO_THROW_LOG(translator_->setOptionDataList(xpath, options)); + + // Get it back. + ConstElementPtr got; + EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath)); + ASSERT_TRUE(got); + ASSERT_EQ(1, got->size()); + EXPECT_TRUE(option->equals(*got->get(0))); +} + +} // 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..8482b93 --- /dev/null +++ b/src/lib/yang/tests/translator_option_def_unittests.cc @@ -0,0 +1,138 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_option_def.h> +#include <yang/yang_models.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 option_definition_list[] = "option definition list"; + +/// @brief Test fixture class for @ref TranslatorOptionDefList. +class TranslatorOptionDefListTestKeaV4 : + public GenericTranslatorTest<option_definition_list, TranslatorOptionDefList> { +public: + /// @brief Constructor + TranslatorOptionDefListTestKeaV4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorOptionDefListTestKeaV4 +class TranslatorOptionDefListTestKeaV6 : + public GenericTranslatorTest<option_definition_list, TranslatorOptionDefList> { +public: + /// @brief Constructor + TranslatorOptionDefListTestKeaV6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorOptionDefListTestKeaV6 +class TranslatorOptionDefListTestIetfV6 : + public GenericTranslatorTest<option_definition_list, TranslatorOptionDefList> { +public: + /// @brief Constructor + TranslatorOptionDefListTestIetfV6() { + model_ = IETF_DHCPV6_SERVER; + } +}; // TranslatorOptionDefListTestIetfV6 + +// 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_LOG(options = translator_->getOptionDefListFromAbsoluteXpath(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"; + string const s_name("foo"); + ASSERT_NO_THROW_LOG(sess_->setItem(xname, s_name)); + string const s_type("string"); + ASSERT_NO_THROW_LOG(sess_->setItem(xtype, s_type)); + string const s_array("false"); + ASSERT_NO_THROW_LOG(sess_->setItem(xarray, s_array)); + sess_->applyChanges(); + + // Get the option def. + ConstElementPtr def; + EXPECT_NO_THROW_LOG(def = translator_->getOptionDefFromAbsoluteXpath(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_LOG(defs = translator_->getOptionDefListFromAbsoluteXpath(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_LOG(translator_->setOptionDefList(xpath, defs)); + + // Get it back. + defs.reset(); + EXPECT_NO_THROW_LOG(defs = translator_->getOptionDefListFromAbsoluteXpath(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("foo")); + def->set("space", Element::create("isc")); + def->set("type", Element::create("string")); + def->set("array", Element::create(false)); + defs->add(def); + EXPECT_NO_THROW_LOG(translator_->setOptionDefList(xpath, defs)); + + // Get it back. + ConstElementPtr got; + EXPECT_NO_THROW_LOG(got = translator_->getOptionDefListFromAbsoluteXpath(xpath)); + ASSERT_TRUE(got); + ASSERT_EQ(1, got->size()); + EXPECT_TRUE(def->equals(*got->get(0))); +} + +} // 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..f8c9388 --- /dev/null +++ b/src/lib/yang/tests/translator_pd_pool_unittests.cc @@ -0,0 +1,296 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_pd_pool.h> +#include <yang/yang_models.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: + /// @brief Constructor + TranslatorPdPoolsTestKeaV6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorPdPoolsTestKeaV6 +class TranslatorPdPoolsTestIetfV6 : + public GenericTranslatorTest<pd_pool_list, TranslatorPdPools> { +public: + /// @brief Constructor + TranslatorPdPoolsTestIetfV6() { + model_ = IETF_DHCPV6_SERVER; + } +}; // TranslatorPdPoolsTestIetfV6 + +// 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_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet_subnet = subnet + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet_subnet, v_subnet)); + sess_->applyChanges(); + + // Create the pd-pool 2001:db8:0:1000::/64 #222. + const string& xpath = subnet + "/pd-pools/pd-pool[pool-id='222']"; + const string& prefix = xpath + "/prefix"; + string const s_prefix("2001:db8:0:1000::/56"); + EXPECT_NO_THROW_LOG(sess_->setItem(prefix, s_prefix)); + const string& length = xpath + "/prefix-length"; + uint8_t len = 56; + string const s_length(to_string(len)); + EXPECT_NO_THROW_LOG(sess_->setItem(length, s_length)); + sess_->applyChanges(); + + // Get the pool. + ConstElementPtr pool; + EXPECT_NO_THROW_LOG(pool = translator_->getPdPoolFromAbsoluteXpath(xpath)); + ASSERT_TRUE(pool); + ElementPtr expected = Element::createMap(); + expected->set("prefix", Element::create("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_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // 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; + string const s_delegated(to_string(dl)); + EXPECT_NO_THROW_LOG(sess_->setItem(x_delegated, s_delegated)); + sess_->applyChanges(); + + // Get the pool. + ConstElementPtr pool; + EXPECT_NO_THROW_LOG(pool = translator_->getPdPoolFromAbsoluteXpath(spool.str())); + ASSERT_TRUE(pool); + ElementPtr expected = Element::createMap(); + expected->set("prefix", Element::create("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_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet_subnet = subnet + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet_subnet, v_subnet)); + sess_->applyChanges(); + + // Set empty list. + const string& xpath = subnet + "/pd-pools"; + ConstElementPtr pools = Element::createList(); + EXPECT_NO_THROW_LOG(translator_->setPdPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Set empty list. + ConstElementPtr pools = Element::createList(); + EXPECT_NO_THROW_LOG(translator_->setPdPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet_subnet = subnet + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet_subnet, v_subnet)); + sess_->applyChanges(); + + // Set one pool. + const string& xpath = subnet + "/pd-pools"; + ElementPtr pools = Element::createList(); + ElementPtr pool = Element::createMap(); + pool->set("prefix", Element::create("2001:db8:0:1000::")); + pool->set("prefix-len", Element::create(56)); + pools->add(pool); + EXPECT_NO_THROW_LOG(translator_->setPdPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Set one pool. + ElementPtr pools = Element::createList(); + ElementPtr pool = Element::createMap(); + pool->set("prefix", Element::create("2001:db8:0:1000::")); + pool->set("prefix-len", Element::create(56)); + pool->set("delegated-len", Element::create(64)); + pools->add(pool); + EXPECT_NO_THROW_LOG(translator_->setPdPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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 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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Create the first pd-pool 2001:db8:0:1000::/56. + const string& prefix = "2001:db8:0:1000::/56"; + ostringstream spool; + spool << xpath + "/pd-pool[prefix='" << prefix << "']"; + const string& x_delegated = spool.str() + "/delegated-len"; + uint8_t dl = 64; + string const s_delegated(to_string(dl)); + EXPECT_NO_THROW_LOG(sess_->setItem(x_delegated, s_delegated)); + sess_->applyChanges(); + + // Create the second pd-pool 2001:db8:0:2000::/56 + const string& prefix2 = "2001:db8:0:2000::/56"; + ostringstream spool2; + spool2 << xpath + "/pd-pool[prefix='" << prefix2 << "']"; + const string& x_delegated2 = spool2.str() + "/delegated-len"; + uint8_t dl2 = 60; + string const s_delegated2(to_string(dl2)); + EXPECT_NO_THROW_LOG(sess_->setItem(x_delegated2, s_delegated2)); + sess_->applyChanges(); + + // Get the pools list. + ConstElementPtr pools; + EXPECT_NO_THROW_LOG(pools = translator_->getPdPoolsFromAbsoluteXpath(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..ad0d25f --- /dev/null +++ b/src/lib/yang/tests/translator_pool_unittests.cc @@ -0,0 +1,252 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_pool.h> +#include <yang/yang_models.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: + /// @brief Constructor + TranslatorPoolsTestKeaV4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorPoolsTestKeaV4 +class TranslatorPoolsTestKeaV6 : + public GenericTranslatorTest<pool_list, TranslatorPools> { +public: + /// @brief Constructor + TranslatorPoolsTestKeaV6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorPoolsTestKeaV6 +class TranslatorPoolsTestIetfV6 : + public GenericTranslatorTest<pool_list, TranslatorPools> { +public: + /// @brief Constructor + TranslatorPoolsTestIetfV6() { + model_ = IETF_DHCPV6_SERVER; + } +}; // TranslatorPoolsTestIetfV6 + +// 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_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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']"; + string const subnet_value("2001:db8::/48"); + string const& network_prefix_path = subnet + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(network_prefix_path, subnet_value)); + sess_->applyChanges(); + + // Create the pool 2001:db8::1:0/112 #222. + const string& xpath = subnet + "/address-pools"; + const string& prefix = xpath + "/address-pool[pool-id='222']/pool-prefix"; + string const value("2001:db8::1:0/112"); + EXPECT_NO_THROW_LOG(sess_->setItem(prefix, value)); + sess_->applyChanges(); + + // Get the pool. + ConstElementPtr pool; + EXPECT_NO_THROW_LOG(pool = translator_->getPoolFromAbsoluteXpath(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_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // 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"; + string const s_prefix("2001:db8::1:0/112"); + EXPECT_NO_THROW_LOG(sess_->setItem(x_prefix, s_prefix)); + sess_->applyChanges(); + + // Get the pool. + ConstElementPtr pool; + EXPECT_NO_THROW_LOG(pool = translator_->getPoolFromAbsoluteXpath(spool.str())); + ASSERT_TRUE(pool); + ElementPtr expected = Element::createMap(); + expected->set("pool", Element::create("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_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet_subnet = subnet + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet_subnet, v_subnet)); + sess_->applyChanges(); + + // Set empty list. + const string& xpath = subnet + "/address-pools"; + ConstElementPtr pools = Element::createList(); + EXPECT_NO_THROW_LOG(translator_->setPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Set empty list. + ConstElementPtr pools = Element::createList(); + EXPECT_NO_THROW_LOG(translator_->setPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet_subnet = subnet + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet_subnet, v_subnet)); + sess_->applyChanges(); + + // Set one pool. + const string& xpath = subnet + "/address-pools"; + ElementPtr pools = Element::createList(); + ElementPtr pool = Element::createMap(); + pool->set("pool", Element::create("2001:db8::1:0/112")); + pools->add(pool); + EXPECT_NO_THROW_LOG(translator_->setPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPoolsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& subnet = xpath + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(subnet, v_subnet)); + sess_->applyChanges(); + + // Set one pool. + ElementPtr pools = Element::createList(); + ElementPtr pool = Element::createMap(); + pool->set("pool", + Element::create("2001:db8::1 - 2001:db8::100")); + pools->add(pool); + EXPECT_NO_THROW_LOG(translator_->setPools(xpath, pools)); + + // Get it back. + pools.reset(); + EXPECT_NO_THROW_LOG(pools = translator_->getPoolsFromAbsoluteXpath(xpath)); + ASSERT_TRUE(pools); + ASSERT_EQ(Element::list, pools->getType()); + ASSERT_EQ(1, pools->size()); + EXPECT_TRUE(pool->equals(*pools->get(0))); +} + +} // 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..e897713 --- /dev/null +++ b/src/lib/yang/tests/translator_shared_network_unittests.cc @@ -0,0 +1,210 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_shared_network.h> +#include <yang/yang_models.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: + /// @brief Constructor + TranslatorSharedNetworksTestKeaV4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorSharedNetworksTestKeaV4 +class TranslatorSharedNetworksTestKeaV6 : + public GenericTranslatorTest<shared_networks, TranslatorSharedNetworks> { +public: + /// @brief Constructor + TranslatorSharedNetworksTestKeaV6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorSharedNetworksTestKeaV6 + +// 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_LOG(networks = translator_->getSharedNetworksFromAbsoluteXpath(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"; + string const v_subnet("2001:db8::/48"); + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet, v_subnet)); + sess_->applyChanges(); + + // Get the shared network. + ConstElementPtr network; + EXPECT_NO_THROW_LOG(network = translator_->getSharedNetworkFromAbsoluteXpath(xnetwork)); + ASSERT_TRUE(network); + ElementPtr subnet = Element::createMap(); + subnet->set("id", Element::create(111)); + subnet->set("subnet", Element::create("2001:db8::/48")); + ElementPtr subnets = Element::createList(); + subnets->add(subnet); + ElementPtr expected = Element::createMap(); + expected->set("name", Element::create("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_LOG(networks = translator_->getSharedNetworksFromAbsoluteXpath(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_LOG(translator_->setSharedNetworks(xpath, networks)); + + // Get it back. + networks.reset(); + EXPECT_NO_THROW_LOG(networks = translator_->getSharedNetworksFromAbsoluteXpath(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("2001:db8::/48")); + subnet->set("id", Element::create(123)); + subnets->add(subnet); + share->set("name", Element::create("foo")); + share->set("subnet6", subnets); + networks->add(share); + EXPECT_NO_THROW_LOG(translator_->setSharedNetworks(xpath, networks)); + + // Get it back. + networks.reset(); + EXPECT_NO_THROW_LOG(networks = translator_->getSharedNetworksFromAbsoluteXpath(xpath)); + ASSERT_TRUE(networks); + ASSERT_EQ(Element::list, networks->getType()); + ASSERT_EQ(1, networks->size()); + EXPECT_TRUE(share->equals(*networks->get(0))); +} + +// 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"; + string const v_subnet1("2001:db8:1::/48"); + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet1, v_subnet1)); + sess_->applyChanges(); + + // Create the subnet2: 2001:db8:2::/48 #2 in shared network foo. + const string& xsubnet2 = xnetwork1 + "/subnet6[id='2']/subnet"; + string const v_subnet2("2001:db8:2::/48"); + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet2, v_subnet2)); + sess_->applyChanges(); + + // Create the subnet1: 2001:db8:101::/48 #101 in shared network foo. + const string& xsubnet3 = xnetwork2 + "/subnet6[id='101']/subnet"; + string const v_subnet("2001:db8:101::/48"); + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet3, v_subnet)); + sess_->applyChanges(); + + // Create the subnet2: 2001:db8:2::/48 #2 in shared network foo. + const string& xsubnet4 = xnetwork2 + "/subnet6[id='102']/subnet"; + string const v_subnet4("2001:db8:102::/48"); + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet4, v_subnet4)); + sess_->applyChanges(); + + // 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_LOG(network = translator_->getSharedNetworkFromAbsoluteXpath(xnetwork1)); + ASSERT_TRUE(network); + EXPECT_EQ(exp_net1, network->str()); + + // Get the second network. + EXPECT_NO_THROW_LOG(network = translator_->getSharedNetworkFromAbsoluteXpath(xnetwork2)); + ASSERT_TRUE(network); + EXPECT_EQ(exp_net2, network->str()); + + // Check that networks with non-existent name are not returned. + EXPECT_NO_THROW_LOG(network = translator_->getSharedNetworkFromAbsoluteXpath(xnetwork3)); + EXPECT_FALSE(network); + + // Now test returns all networks + ConstElementPtr networks; + EXPECT_NO_THROW_LOG(networks = translator_->getSharedNetworksFromAbsoluteXpath(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..d9a8104 --- /dev/null +++ b/src/lib/yang/tests/translator_subnet_unittests.cc @@ -0,0 +1,379 @@ +// 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 <gtest/gtest.h> + +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator_subnet.h> +#include <yang/yang_models.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: + /// @brief Constructor + TranslatorSubnetsTestKeaV4() { + model_ = KEA_DHCP4_SERVER; + } +}; // TranslatorSubnetsTestKeaV4 + +class TranslatorSubnetsTestKeaV6 : + public GenericTranslatorTest<subnet_list, TranslatorSubnets> { +public: + /// @brief Constructor + TranslatorSubnetsTestKeaV6() { + model_ = KEA_DHCP6_SERVER; + } +}; // TranslatorSubnetsTestKeaV6 + +class TranslatorSubnetsTestIetfV6 : + public GenericTranslatorTest<subnet_list, TranslatorSubnets> { +public: + /// @brief Constructor + TranslatorSubnetsTestIetfV6() { + model_ = IETF_DHCPV6_SERVER; + } +}; // TranslatorSubnetsTestIetfV6 + +// 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_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& xsubnet = xsub + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet, v_subnet)); + sess_->applyChanges(); + + // Get the subnet. + ConstElementPtr subnet; + EXPECT_NO_THROW_LOG(subnet = translator_->getSubnetFromAbsoluteXpath(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_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& xsubnet = xsub + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet, v_subnet)); + sess_->applyChanges(); + + // Get the subnet. + ConstElementPtr subnet; + EXPECT_NO_THROW_LOG(subnet = translator_->getSubnetFromAbsoluteXpath(xsub)); + ASSERT_TRUE(subnet); + ElementPtr expected = Element::createMap(); + expected->set("id", Element::create(111)); + expected->set("subnet", Element::create("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_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& xsubnet = xsub + "/network-prefix"; + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet, v_subnet)); + sess_->applyChanges(); + + // Create the pool 2001:db8::1:0/112 #1. + const string& xpool = xsub + "/address-pools"; + const string& prefix1 = xpool + "/address-pool[pool-id='1']/pool-prefix"; + string const s_pool1("2001:db8::1:0/112"); + EXPECT_NO_THROW_LOG(sess_->setItem(prefix1, s_pool1)); + sess_->applyChanges(); + + // Create the pool 2001:db8::2:0/112 #2. + const string& prefix2 = xpool + "/address-pool[pool-id='2']/pool-prefix"; + string const s_pool2("2001:db8::2:0/112"); + EXPECT_NO_THROW_LOG(sess_->setItem(prefix2, s_pool2)); + sess_->applyChanges(); + + // Get the subnet. + ConstElementPtr subnet; + EXPECT_NO_THROW_LOG(subnet = translator_->getSubnetFromAbsoluteXpath(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_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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']"; + string const v_subnet("2001:db8::/48"); + const string& xsubnet = xsub + "/subnet"; + EXPECT_NO_THROW_LOG(sess_->setItem(xsubnet, v_subnet)); + sess_->applyChanges(); + + // Create the pool 2001:db8::1:0/112. + const string& prefix1 = xsub + "/pool[start-address='2001:db8::1:0']" + + "[end-address='2001:db8::1:ffff']/prefix"; + string const s_pool1("2001:db8::1:0/112"); + EXPECT_NO_THROW_LOG(sess_->setItem(prefix1, s_pool1)); + sess_->applyChanges(); + + // Create the pool 2001:db8::2:0/112. + const string& prefix2 = xsub + "/pool[start-address='2001:db8::2:0']" + + "[end-address='2001:db8::2:ffff']"; + EXPECT_NO_THROW_LOG(sess_->setItem(prefix2, nullopt)); + sess_->applyChanges(); + + // Get the subnet. + ConstElementPtr subnet; + EXPECT_NO_THROW_LOG(subnet = translator_->getSubnetFromAbsoluteXpath(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_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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_LOG(translator_->setSubnets(xpath, subnets)); + + // Get it back. + subnets.reset(); + EXPECT_NO_THROW_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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_LOG(translator_->setSubnets(xpath, subnets)); + + // Get it back. + subnets.reset(); + EXPECT_NO_THROW_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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("2001:db8::/48")); + subnet->set("id", Element::create(123)); + subnets->add(subnet); + EXPECT_NO_THROW_LOG(translator_->setSubnets(xpath, subnets)); + + // Get it back. + subnets.reset(); + EXPECT_NO_THROW_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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("10.0.1.0/24")); + subnet->set("id", Element::create(123)); + subnets->add(subnet); + EXPECT_NO_THROW_LOG(translator_->setSubnets(xpath, subnets)); + + // Get it back. + subnets.reset(); + EXPECT_NO_THROW_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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 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("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("2001:db8::1:0/112")); + pools->add(pool1); + ElementPtr pool2 = Element::createMap(); + pool2->set("pool", Element::create("2001:db8::2:0/112")); + pools->add(pool2); + subnet->set("pools", pools); + + // Add the subnet. + subnets->add(subnet); + EXPECT_NO_THROW_LOG(translator_->setSubnets(xpath, subnets)); + + // Get it back. + subnets.reset(); + EXPECT_NO_THROW_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(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("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("10.0.1.0/28")); + pools->add(pool1); + ElementPtr pool2 = Element::createMap(); + pool2->set("pool", Element::create("10.0.1.200 - 10.0.1.222")); + pools->add(pool2); + subnet->set("pools", pools); + + // Add the subnet. + subnets->add(subnet); + EXPECT_NO_THROW_LOG(translator_->setSubnets(xpath, subnets)); + + // Get it back. + subnets.reset(); + EXPECT_NO_THROW_LOG(subnets = translator_->getSubnetsFromAbsoluteXpath(xpath)); + ASSERT_TRUE(subnets); + ASSERT_EQ(Element::list, subnets->getType()); + ASSERT_EQ(1, subnets->size()); + EXPECT_TRUE(subnet->equals(*subnets->get(0))); +} + +} // 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..8532419 --- /dev/null +++ b/src/lib/yang/tests/translator_unittests.cc @@ -0,0 +1,892 @@ +// 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 <gtest/gtest.h> + +#include <testutils/gtest_utils.h> +#include <yang/tests/sysrepo_setup.h> +#include <yang/translator.h> + +using namespace std; +using namespace isc; +using namespace isc::data; +using namespace isc::yang; +using namespace isc::yang::test; +using namespace libyang; +using namespace sysrepo; + +struct TranslatorTest : ::testing::Test { + void SetUp() override { + SysrepoSetup::cleanSharedMemory(); + cleanUp(); + } + + void TearDown() override { + cleanUp(); + SysrepoSetup::cleanSharedMemory(); + } + +private: + void cleanUp() { + Session session(sysrepo::Connection{}.sessionStart()); + session.switchDatastore(sysrepo::Datastore::Candidate); + session.deleteItem("/keatest-module:container"); + session.deleteItem("/keatest-module:kernel-modules"); + session.deleteItem("/keatest-module:list"); + session.deleteItem("/keatest-module:main"); + session.deleteItem("/keatest-module:presence-container"); + session.applyChanges(); + } +}; // TranslatorTest + +namespace { + +// Test constructor. +TEST_F(TranslatorTest, constructor) { + // Get a session. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + // Get a translator object. + unique_ptr<Translator> translator; + EXPECT_NO_THROW_LOG(translator.reset(new Translator(sess, ""))); +} + +// Test basic YANG to JSON value conversion using sysrepo test models. +TEST_F(TranslatorTest, getItem) { + // Get a translator object to play with. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + unique_ptr<Translator> translator; + ASSERT_NO_THROW_LOG(translator.reset(new Translator(sess, ""))); + string value; + ConstElementPtr element; + string xpath; + + // String. + xpath = "/keatest-module:main/string"; + value = "str"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ("str", element->stringValue()); + element.reset(); + + // Bool. + xpath = "/keatest-module:main/boolean"; + value = "true"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::boolean, element->getType()); + EXPECT_TRUE(element->boolValue()); + element.reset(); + + // Unsigned 8 bit integer. + xpath = "/keatest-module:main/ui8"; + uint8_t u8(8); + value = to_string(u8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(8, element->intValue()); + element.reset(); + + // Unsigned 16 bit integer. + xpath = "/keatest-module:main/ui16"; + uint16_t u16(16); + value = to_string(u16); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(16, element->intValue()); + element.reset(); + + // Unsigned 32 bit integer. + xpath = "/keatest-module:main/ui32"; + uint32_t u32(32); + value = to_string(u32); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(32, element->intValue()); + element.reset(); + + // Unsigned 64 bit integer. + xpath = "/keatest-module:main/ui64"; + uint64_t u64(64); + value = to_string(u64); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(64, element->intValue()); + element.reset(); + + // Empty. + xpath = "/keatest-module:main/empty"; + value = string(); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(string(), element->stringValue()); + element.reset(); + + // Signed 8 bit integer. + xpath = "/keatest-module:main/i8"; + int8_t s8(8); + value = to_string(s8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(8, element->intValue()); + element.reset(); + + // Signed 16 bit integer. + xpath = "/keatest-module:main/i16"; + int16_t s16(16); + value = to_string(s16); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(16, element->intValue()); + element.reset(); + + // Signed 32 bit integer. + xpath = "/keatest-module:main/i32"; + int32_t s32(32); + value = to_string(s32); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(32, element->intValue()); + element.reset(); + + // Signed 64 bit integer. + xpath = "/keatest-module:main/i64"; + int64_t s64(64); + value = to_string(s64); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::integer, element->getType()); + EXPECT_EQ(64, element->intValue()); + element.reset(); + + // Identity reference. + xpath = "/keatest-module:main/id_ref"; + value = "keatest-module:id_1"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ("keatest-module:id_1", element->stringValue()); + element.reset(); + + // Enumeration item. + xpath = "/keatest-module:main/enum"; + value = "maybe"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ("maybe", element->stringValue()); + element.reset(); + + // Bits. + xpath = "/keatest-module:main/options"; + value = "strict recursive logging"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ("strict recursive logging", element->stringValue()); + element.reset(); + + // Binary. + xpath = "/keatest-module:main/raw"; + value = "Zm9vYmFy"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ("foobar", element->stringValue()); + element.reset(); + + // Leaf-list: not yet exist. + xpath = "/keatest-module:main/numbers"; + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(element); + element.reset(); + + // No easy way to create it empty. + + // Leaf-list: 1, 2 and 3. + u8 = 1; + value = to_string(u8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + u8 = 2; + value = to_string(u8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + u8 = 3; + value = to_string(u8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::list, element->getType()); + EXPECT_EQ(3, element->size()); + EXPECT_EQ("[ 1, 2, 3 ]", element->str()); + element.reset(); + + // Instance identifier. + xpath = "/keatest-module:main/instance_id"; + value = "/keatest-module:main/numbers[.='1']"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(value, element->stringValue()); + element.reset(); + + // Union. + xpath = "/keatest-module:main/union"; + value = "8"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(value, element->stringValue()); + element.reset(); + value = "infinity"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(value, element->stringValue()); + element.reset(); + + // Leafref. + xpath = "/keatest-module:main/leafref-i8"; + value = "9"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(value, element->stringValue()); + element.reset(); + + // Leafref. + xpath = "/keatest-module:main/leafref-raw"; + value = "ff012345"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(value, element->stringValue()); + element.reset(); + + // Leafref. + xpath = "/keatest-module:main/leafref-string"; + value = "string through leafref"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::string, element->getType()); + EXPECT_EQ(value, element->stringValue()); + element.reset(); + + // Decimal 64. + xpath = "/keatest-module:main/dec64"; + value = to_string(9.85); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + sess.applyChanges(); + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_TRUE(element); + ASSERT_EQ(Element::real, element->getType()); + EXPECT_EQ("9.85", element->str()); + element.reset(); + + // Not existing. + xpath = "/keatest-module:main/no_such_node"; + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(element); + element.reset(); + + // Check error. + xpath = "null"; + EXPECT_NO_THROW_LOG(element = translator->getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(element); +} + +// Check the Translator::deleteItem function. +TEST_F(TranslatorTest, deleteItem) { + ElementPtr got; + string xpath; + + // Get a translator object to play with. + Translator translator(Connection{}.sessionStart(), "keatest-module"); + + // Missing schema node + EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main/no_such_node")); + + // Existing schema node, but no data + xpath = "/keatest-module:main/string"; + EXPECT_NO_THROW_LOG(translator.deleteItem(xpath)); + EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(got); + got.reset(); + + // Existing schema node, existing data + translator.setItem(xpath, Element::create("value"), LeafBaseType::String); + EXPECT_NO_THROW_LOG(translator.deleteItem(xpath)); + EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(got); + got.reset(); + + // Container schema node, no data + EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(got); + got.reset(); + + // Container schema node, existing data + translator.setItem(xpath, Element::create("value"), LeafBaseType::String); + EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); + EXPECT_FALSE(got); + got.reset(); +} + +// Test JSON to basic YANG value conversion using the static method. +TEST_F(TranslatorTest, valueTo) { + optional<string> value; + + // Null. + ConstElementPtr element; + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::String)); + EXPECT_EQ(nullopt, value); + EXPECT_FALSE(element); + + // Container. + element = Element::createMap(); + EXPECT_THROW_MSG(Translator::translateToYang(element, LeafBaseType::Unknown), NotImplemented, + "Translator::value(): map element"); + + // List. + element = Element::createList(); + EXPECT_THROW_MSG(Translator::translateToYang(element, LeafBaseType::Unknown), NotImplemented, + "Translator::value(): list element"); + + // String. + string str("foo"); + element = Element::create(str); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::String)); + EXPECT_EQ(element->stringValue(), value); + + // Bool. + element = Element::create(false); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Bool)); + EXPECT_EQ(element->str(), value); + + // Unsigned 8 bit integer. + element = Element::create(123); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Uint8)); + EXPECT_EQ(element->str(), value); + element.reset(); + + // Unsigned 16 bit integer. + element = Element::create(12345); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Uint16)); + EXPECT_EQ(element->str(), value); + element.reset(); + + // Unsigned 32 bit integer. + element = Element::create(123456789); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Uint32)); + EXPECT_EQ(element->str(), value); + element.reset(); + + // Unsigned 64 bit integer. + element = Element::create(int64_t(1234567890123456)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Uint64)); + EXPECT_EQ("1234567890123456", value); + element.reset(); + + // Signed 8 bit integer. + element = Element::create(-123); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Int8)); + EXPECT_EQ(element->str(), value); + element.reset(); + + // Signed 16 bit integer. + element = Element::create(-12345); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Int16)); + EXPECT_EQ(element->str(), value); + element.reset(); + + // Signed 32 bit integer. + element = Element::create(-123456789); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Int32)); + EXPECT_EQ(element->str(), value); + element.reset(); + + // Signed 64 bit integer. + element = Element::create(int64_t(-1234567890123456)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Int64)); + EXPECT_EQ("-1234567890123456", value); + element.reset(); + + // Identity reference. + element = Element::create(str); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::IdentityRef)); + EXPECT_EQ(element->stringValue(), value); + + // Enumeration item. + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Enum)); + EXPECT_EQ(element->stringValue(), value); + + // Binary. + element = Element::create("foobar"); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Binary)); + EXPECT_EQ("Zm9vYmFy", value); + + // Bits. + element = Element::create("foobar"); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Bits)); + EXPECT_EQ(element->stringValue(), value); + + // Decimal 64. + double d64(.1234); + element = Element::create(d64); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Dec64)); + EXPECT_EQ(element->str(), value); + + // Empty. + element = Element::create(string()); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Empty)); + EXPECT_EQ(element->stringValue(), value); + + // Leafref. + element = Element::create("leafref"); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Leafref)); + EXPECT_EQ(element->stringValue(), value); + + // Union. + element = Element::create("union"); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Union)); + EXPECT_EQ(element->stringValue(), value); +} + +// Test JSON to basic YANG value conversion using sysrepo test models. +TEST_F(TranslatorTest, setItem) { + // Get a translator object to play with. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + unique_ptr<Translator> translator; + ASSERT_NO_THROW_LOG(translator.reset(new Translator(sess, "keatest-module"))); + + ElementPtr element; + string xpath; + + // String. + optional<DataNode> data_node; + xpath = "/keatest-module:main/string"; + element = Element::create("str"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::String)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::String, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Bool. + xpath = "/keatest-module:main/boolean"; + element = Element::create(true); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Bool)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Bool, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Unsigned 8 bit integer. + xpath = "/keatest-module:main/ui8"; + element = Element::create(8); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Uint8)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Uint8, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Unsigned 16 bit integer. + xpath = "/keatest-module:main/ui16"; + element = Element::create(16); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Uint16)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Uint16, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Unsigned 32 bit integer. + xpath = "/keatest-module:main/ui32"; + element = Element::create(32); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Uint32)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Uint32, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Unsigned 64 bit integer. + xpath = "/keatest-module:main/ui64"; + element = Element::create(64); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Uint64)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Uint64, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Empty. + xpath = "/keatest-module:main/empty"; + element = Element::create(string()); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Empty)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Empty, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Signed 8 bit integer. + xpath = "/keatest-module:main/i8"; + element = Element::create(8); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Int8)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Int8, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Signed 16 bit integer. + xpath = "/keatest-module:main/i16"; + element = Element::create(16); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Int16)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Int16, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Signed 32 bit integer. + xpath = "/keatest-module:main/i32"; + element = Element::create(32); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Int32)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Int32, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Signed 64 bit integer. + xpath = "/keatest-module:main/i64"; + element = Element::create(64); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Int64)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Int64, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Identity reference. + xpath = "/keatest-module:main/id_ref"; + element = Element::create("keatest-module:id_1"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::IdentityRef)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::IdentityRef, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Enumeration item. + xpath = "/keatest-module:main/enum"; + element = Element::create("maybe"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Enum)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Enum, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Binary. + xpath = "/keatest-module:main/raw"; + element = Element::create("foobar"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Binary)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Binary, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ("Zm9vYmFy", string(data_node->asTerm().valueStr())); + + // Bits. + xpath = "/keatest-module:main/options"; + element = Element::create("strict recursive logging"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Bits)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Bits, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Decimal 64. + xpath = "/keatest-module:main/dec64"; + double d64(9.85); + element = Element::create(d64); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Dec64)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Dec64, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->str(), string(data_node->asTerm().valueStr())); + + // Leaf-list. + xpath = "/keatest-module:main/numbers"; + EXPECT_NO_THROW_LOG(translator->setItem(xpath, Element::fromJSON("1"), LeafBaseType::Uint8)); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, Element::fromJSON("2"), LeafBaseType::Uint8)); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, Element::fromJSON("3"), LeafBaseType::Uint8)); + ElementPtr got(translator->getItemFromAbsoluteXpath(xpath)); + ASSERT_EQ(LeafBaseType::Dec64, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ("[ 1, 2, 3 ]", got->str()); + + // Clean the leaf-list. + EXPECT_NO_THROW_LOG(translator->deleteItem(xpath)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + EXPECT_FALSE(data_node); + data_node.reset(); + + // Instance identifier. + xpath = "/keatest-module:main/instance_id"; + element = Element::create("/keatest-module:main/numbers[.='1']"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::InstanceIdentifier)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::InstanceIdentifier, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Union. + xpath = "/keatest-module:main/union"; + element = Element::create("8"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Union)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Union, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + element = Element::create("infinity"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Union)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Union, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Leafref. + xpath = "/keatest-module:main/leafref-i8"; + element = Element::create("9"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Leafref)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Leafref, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Leafref. + xpath = "/keatest-module:main/leafref-raw"; + element = Element::create("ff012345"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Leafref)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Leafref, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Leafref. + xpath = "/keatest-module:main/leafref-string"; + element = Element::create("string through"); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Leafref)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + ASSERT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + ASSERT_TRUE(data_node); + ASSERT_EQ(LeafBaseType::Leafref, data_node->schema().asLeaf().valueType().base()); + EXPECT_EQ(element->stringValue(), string(data_node->asTerm().valueStr())); + + // Bad xpath. + xpath = "/keatest-module:main/no_such_node"; + element = Element::create("str"); + EXPECT_THROW_MSG(translator->setItem(xpath, element, LeafBaseType::String), NetconfError, + "setting item '\"str\"' at '" + xpath + + "': Session::setItem: Couldn't set " + "'/keatest-module:main/no_such_node' to 'str': SR_ERR_INVAL_ARG"); + + // Bad type. + xpath = "/keatest-module:main/string"; + element = Element::create(true); + EXPECT_NO_THROW_LOG(translator->setItem(xpath, element, LeafBaseType::Bool)); + + element = translator->getItemFromAbsoluteXpath(xpath); + ASSERT_TRUE(element); + EXPECT_EQ(element->getType(), Element::string); + EXPECT_EQ(element->str(), "\"true\""); + + // Delete (twice). + xpath = "/keatest-module:main/string"; + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + EXPECT_TRUE(data_node); + EXPECT_NO_THROW_LOG(data_node = data_node->findPath(xpath)); + EXPECT_TRUE(data_node); + ASSERT_TRUE(NodeType::Leaf == data_node->schema().nodeType()); + EXPECT_EQ("true", data_node->asTerm().valueStr()); + EXPECT_NO_THROW_LOG(translator->deleteItem(xpath)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + EXPECT_FALSE(data_node); + EXPECT_NO_THROW_LOG(translator->deleteItem(xpath)); + EXPECT_NO_THROW_LOG(data_node = sess.getData(xpath)); + EXPECT_FALSE(data_node); +} + +// Test YANG container retrieval. +TEST_F(TranslatorTest, container) { + ElementPtr element; + + // Get a translator object to play with. + Translator translator(Connection{}.sessionStart(), "keatest-module"); + + // Container with no data apparently throws. + EXPECT_THROW_MSG(element = translator.getItemFromAbsoluteXpath("/keatest-module:container"), NotImplemented, + "getting node of type 1 not supported, xpath is '/keatest-module:container'"); + EXPECT_FALSE(element); + element.reset(); + + EXPECT_NO_THROW_LOG( + translator.setItem("/keatest-module:container", + ElementPtr(), LeafBaseType::Unknown)); + + // Container with data filled in throws when retrieving the container itself. + element = Element::create("Leaf value"); + EXPECT_NO_THROW_LOG( + translator.setItem("/keatest-module:container/list[key1='key1'][key2='key2']/leaf", + element, LeafBaseType::String)); + element.reset(); + EXPECT_THROW_MSG( + element = translator.getItemFromAbsoluteXpath("/keatest-module:container"), NotImplemented, + "getting node of type 1 not supported, xpath is '/keatest-module:container'"); + EXPECT_FALSE(element); + element.reset(); + EXPECT_NO_THROW_LOG( + element = translator.getItemFromAbsoluteXpath("/keatest-module:container[key1='key1'][key2='key2']")); + EXPECT_FALSE(element); +} + +// Test YANG list retrieval. +TEST_F(TranslatorTest, list) { + ElementPtr element; + + // Get a translator to play with. + Translator translator(Connection{}.sessionStart(), "keatest-module"); + + // List with no data does not throw and returns a null ElementPtr by default. + EXPECT_NO_THROW_LOG( + element = translator.getItemFromAbsoluteXpath("/keatest-module:container/list")); + EXPECT_FALSE(element); + element.reset(); + + // List with data filled in throws when retrieving the list itself. + element = Element::create("Leaf value"); + EXPECT_NO_THROW_LOG( + translator.setItem("/keatest-module:container/list[key1='key1'][key2='key2']/leaf", element, + LeafBaseType::String)); + element.reset(); + EXPECT_THROW_MSG( + element = translator.getItemFromAbsoluteXpath("/keatest-module:container/list"), NotImplemented, + "getting node of type 16 not supported, xpath is '/keatest-module:container/list'"); + EXPECT_FALSE(element); + element.reset(); + EXPECT_THROW_MSG(element = translator.getItemFromAbsoluteXpath( + "/keatest-module:container/list[key1='key1'][key2='key2']"), NotImplemented, + "getting node of type 16 not supported, xpath is " + "'/keatest-module:container/list[key1='key1'][key2='key2']'"); + EXPECT_FALSE(element); +} + +// Test that we can check if a schema node exists. +TEST_F(TranslatorTest, schemaNodeExists) { + // Get a translator to play with. + Translator translator(Connection{}.sessionStart(), "keatest-module"); + + EXPECT_FALSE(translator.schemaNodeExists("/keatest-module:main/no_such_node")); + EXPECT_TRUE(translator.schemaNodeExists("/keatest-module:main")); + EXPECT_TRUE(translator.schemaNodeExists("/keatest-module:main/string")); + EXPECT_TRUE(translator.schemaNodeExists("/keatest-module:container/list")); +} + +} // 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..ddd4cb9 --- /dev/null +++ b/src/lib/yang/tests/translator_utils_unittests.cc @@ -0,0 +1,288 @@ +// 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 <gtest/gtest.h> + +#include <testutils/gtest_utils.h> +#include <yang/testutils/translator_test.h> +#include <yang/tests/sysrepo_setup.h> +#include <yang/tests/yang_configs.h> + +#include <sstream> + +using namespace std; +using namespace isc; +using namespace isc::yang; +using namespace isc::yang::test; +using namespace libyang; +using namespace sysrepo; + +namespace { + +// Test LeafBaseType print. +TEST(YangReprTest, type) { + ostringstream os; + + // Verify that string is "string" (vs a number). + LeafBaseType t(LeafBaseType::String); + 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", LeafBaseType::String, true); + EXPECT_EQ("/foo", item1.xpath_); + EXPECT_EQ("bar", item1.value_); + EXPECT_TRUE(item1.settable_); + + // EXPECT_EQ doesn't work. Tries to << into a stringstream. + EXPECT_TRUE(LeafBaseType::String == item1.type_); + + // Another one. + YRItem item2("/foo", "bar", LeafBaseType::String, false); + EXPECT_EQ("/foo", item2.xpath_); + EXPECT_EQ("bar", item2.value_); + EXPECT_FALSE(item2.settable_); + + // EXPECT_EQ doesn't work. Tries to << into a stringstream. + EXPECT_TRUE(LeafBaseType::String == item2.type_); + + // Equality. + EXPECT_TRUE(item1 == item2); + EXPECT_TRUE(item2 == item1); + 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. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + + // Cleanup. + EXPECT_NO_THROW_LOG(sess.deleteItem("/keatest-module:container")); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + EXPECT_NO_THROW_LOG(sess.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + // Fill the test module. + string xpath; + string value; + + xpath = "/keatest-module:main/string"; + value = "str"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/boolean"; + value = "true"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/ui8"; + uint8_t u8(8); + value = to_string(u8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/ui16"; + uint16_t u16(16); + value = to_string(u16); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/ui32"; + uint32_t u32(32); + value = to_string(u32); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/ui64"; + uint64_t u64(64); + value = to_string(u64); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/i8"; + int8_t s8(8); + value = to_string(s8); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/i16"; + int16_t s16(16); + value = to_string(s16); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/i32"; + int32_t s32(32); + value = to_string(s32); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/i64"; + int64_t s64(64); + value = to_string(s64); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/id_ref"; + value = "keatest-module:id_1"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + xpath = "/keatest-module:main/enum"; + value = "maybe"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + // Binary. + xpath = "/keatest-module:main/raw"; + value = "Zm9vYmFy"; + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + // Get it. + YangRepr repr(testModel); + YRTree tree; + EXPECT_NO_THROW_LOG(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. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + + // Cleanup. + EXPECT_NO_THROW_LOG(sess.deleteItem("/keatest-module:container")); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + EXPECT_NO_THROW_LOG(sess.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + // Get it. + YangRepr repr(testModel); + YRTree tree; + EXPECT_NO_THROW_LOG(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 LeafBaseType::Int32 to LeafBaseType::Uint32. + YRTree badtype = testTree; + xpath = "/keatest-module:main/i32"; + badtype.at(xpath).type_ = LeafBaseType::Uint32; + EXPECT_FALSE(repr.verify(badtype, 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. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + + // Cleanup. + EXPECT_NO_THROW_LOG(sess.deleteItem("/keatest-module:container")); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + EXPECT_NO_THROW_LOG(sess.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + + // Set the module content. + YangRepr repr(testModel); + EXPECT_NO_THROW_LOG(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 string& model, const YRTree& tree) { + SCOPED_TRACE("\n* Tested model: " + model); + SysrepoSetup::cleanSharedMemory(); + + // Get a translator object to play with. + Session sess(Connection{}.sessionStart()); + sess.switchDatastore(sysrepo::Datastore::Candidate); + + // Cleanup. + Translator translator(sess, model); + if (model == "keatest-module") { + translator.deleteItem("/keatest-module:container"); + translator.deleteItem("/keatest-module:kernel-modules"); + translator.deleteItem("/keatest-module:list"); + translator.deleteItem("/keatest-module:main"); + translator.deleteItem("/keatest-module:presence-container"); + } else { + string toplevel_node("config"); + if (model == IETF_DHCPV6_SERVER) { + toplevel_node = "server"; + } + EXPECT_NO_THROW_LOG(translator.deleteItem("/" + model + ":" + toplevel_node)); + } + + // Get it. + YangRepr repr(model); + + EXPECT_NO_THROW_LOG(repr.set(tree, sess)); + bool result = false; + EXPECT_NO_THROW_LOG(result = repr.verify(tree, sess, cerr)); + EXPECT_TRUE(result); +} + +// 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..d3825c9 --- /dev/null +++ b/src/lib/yang/tests/yang_configs.h @@ -0,0 +1,655 @@ +// Copyright (C) 2018-2023 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/testutils/translator_test.h> +#include <yang/yang_models.h> + +#include <vector> + +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", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/keatest-module:main", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/keatest-module:main/string", + "str", libyang::LeafBaseType::String, true }, + { "/keatest-module:main/boolean", + "true", libyang::LeafBaseType::Bool, true }, + { "/keatest-module:main/ui8", + "8", libyang::LeafBaseType::Uint8, true }, + { "/keatest-module:main/ui16", + "16", libyang::LeafBaseType::Uint16, true }, + { "/keatest-module:main/ui32", + "32", libyang::LeafBaseType::Uint32, true }, + { "/keatest-module:main/ui64", + "64", libyang::LeafBaseType::Uint64, true }, + { "/keatest-module:main/i8", + "8", libyang::LeafBaseType::Int8, true }, + { "/keatest-module:main/i16", + "16", libyang::LeafBaseType::Int16, true }, + { "/keatest-module:main/i32", + "32", libyang::LeafBaseType::Int32, true }, + { "/keatest-module:main/i64", + "64", libyang::LeafBaseType::Int64, true }, + { "/keatest-module:main/id_ref", + "keatest-module:id_1", libyang::LeafBaseType::IdentityRef, true }, + { "/keatest-module:main/enum", + "maybe", libyang::LeafBaseType::Enum, true }, + { "/keatest-module:main/raw", + "Zm9vYmFy", libyang::LeafBaseType::Binary, true }, + { "/keatest-module:kernel-modules", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +/// @brief A subnet with two pools with ietf-dhcpv6-server model. +const std::string subnetTwoPoolsModelIetf6 = IETF_DHCPV6_SERVER; +const YRTree subnetTwoPoolsTreeIetf6 = YangRepr::buildTreeFromVector({ + { "/ietf-dhcpv6-server:server", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-range-id", + "111", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-prefix", + "2001:db8::/48", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/pool-id", + "0", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/pool-prefix", + "2001:db8::1:0/112", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/start-address", + "2001:db8::1:0", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/end-address", + "2001:db8::1:ffff", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/max-address-count", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/pool-id", + "1", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/pool-prefix", + "2001:db8::2:0/112", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/start-address", + "2001:db8::2:0", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/end-address", + "2001:db8::2:ffff", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/max-address-count", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code", + "65535", libyang::LeafBaseType::Uint16, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/host-reservations", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/option-sets", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +/// @brief A subnet with timers with ietf-dhcpv6-server model. +const std::string subnetTimersModel = IETF_DHCPV6_SERVER; +const YRTree subnetTimersIetf6 = YangRepr::buildTreeFromVector({ + { "/ietf-dhcpv6-server:server", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-range-id", + "111", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-prefix", + "2001:db8::/48", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/pool-id", + "0", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/pool-prefix", + "2001:db8::1:0/112", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/start-address", + "2001:db8::1:0", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/end-address", + "2001:db8::1:ffff", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/renew-time", + "1000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/rebind-time", + "2000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='0']/max-address-count", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/pool-id", + "1", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/pool-prefix", + "2001:db8::2:0/112", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/start-address", + "2001:db8::2:0", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/end-address", + "2001:db8::2:ffff", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/renew-time", + "1000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/rebind-time", + "2000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools/" + "address-pool[pool-id='1']/max-address-count", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code", + "65535", libyang::LeafBaseType::Uint16, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/host-reservations", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/option-sets", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +/// @brief A subnet with two pools with ietf-dhcpv6-server model +/// which validates. +const std::string validModelIetf6 = IETF_DHCPV6_SERVER; +const YRTree validTreeIetf6 = YangRepr::buildTreeFromVector({ + { "/ietf-dhcpv6-server:server", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes" + "/vendor-info/ent-num", + "2495", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/option-sets", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-range-id", + "111", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-description", + "Subnet#111", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/network-prefix", + "2001:db8::/48", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/pool-id", + "0", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/prefix", + "2001:db8:1::/48", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/prefix-length", + "48", libyang::LeafBaseType::Uint8, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/valid-lifetime", + "4000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/preferred-lifetime", + "3000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/renew-time", + "1000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/rebind-time", + "2000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/rapid-commit", + "false", libyang::LeafBaseType::Bool, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/option-set-id", + "0", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='0']/max-pd-space-utilization", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/pool-id", + "1", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/prefix", + "2001:db8:2::/48", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/prefix-length", + "48", libyang::LeafBaseType::Uint8, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/valid-lifetime", + "4000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/preferred-lifetime", + "3000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/renew-time", + "1000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/rebind-time", + "2000", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/rapid-commit", + "false", libyang::LeafBaseType::Bool, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/option-set-id", + "0", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools/" + "pd-pool[pool-id='1']/max-pd-space-utilization", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code", + "65535", libyang::LeafBaseType::Uint16, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/address-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/pd-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='111']/host-reservations", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +/// @brief A subnet with a pool and option data lists with +/// kea-dhcp4-server:config model. +const std::string subnetOptionsModelKeaDhcp4 = KEA_DHCP4_SERVER; +const YRTree subnetOptionsTreeKeaDhcp4 = YangRepr::buildTreeFromVector({ + { "/kea-dhcp4-server:config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/id", + "111", libyang::LeafBaseType::Uint32, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']/code", + "100", libyang::LeafBaseType::Uint8, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']/space", + "dns", libyang::LeafBaseType::String, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']/data", + "12121212", libyang::LeafBaseType::String, true }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']/csv-format", + "false", libyang::LeafBaseType::Bool, true }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']/always-send", + "false", libyang::LeafBaseType::Bool, true }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "option-data[code='100'][space='dns']/never-send", + "false", libyang::LeafBaseType::Bool, true }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "pool[start-address='10.0.1.0'][end-address='10.0.1.255']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "pool[start-address='10.0.1.0'][end-address='10.0.1.255']/start-address", + "10.0.1.0", libyang::LeafBaseType::String, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "pool[start-address='10.0.1.0'][end-address='10.0.1.255']/end-address", + "10.0.1.255", libyang::LeafBaseType::String, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/" + "pool[start-address='10.0.1.0'][end-address='10.0.1.255']/prefix", + "10.0.1.0/24", libyang::LeafBaseType::String, true }, + { "/kea-dhcp4-server:config/subnet4[id='111']/subnet", + "10.0.0.0/8", libyang::LeafBaseType::String, true }, + { "/kea-dhcp4-server:config/expired-leases-processing", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/dhcp-ddns", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/config-control", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/sanity-checks", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/interfaces-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/subnet4[id='111']/relay", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/compatibility", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/multi-threading", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +/// @brief A subnet with a pool and option data lists with +/// kea-dhcp6-server:config model. +const std::string subnetOptionsModelKeaDhcp6 = KEA_DHCP6_SERVER; +const YRTree subnetOptionsTreeKeaDhcp6 = YangRepr::buildTreeFromVector({ + { "/kea-dhcp6-server:config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/id", + "111", libyang::LeafBaseType::Uint32, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "start-address", + "2001:db8::1:0", libyang::LeafBaseType::String, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "end-address", + "2001:db8::1:ffff", libyang::LeafBaseType::String, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "prefix", + "2001:db8::1:0/112", libyang::LeafBaseType::String, true }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']/code", + "100", libyang::LeafBaseType::Uint16, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']/space", + "dns", libyang::LeafBaseType::String, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']/data", + "12121212", libyang::LeafBaseType::String, true }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']/csv-format", + "false", libyang::LeafBaseType::Bool, true }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']/always-send", + "false", libyang::LeafBaseType::Bool, true }, + { "/kea-dhcp6-server:config/subnet6[id='111']/" + "pool[start-address='2001:db8::1:0'][end-address='2001:db8::1:ffff']/" + "option-data[code='100'][space='dns']/never-send", + "false", libyang::LeafBaseType::Bool, true }, + { "/kea-dhcp6-server:config/subnet6[id='111']/subnet", + "2001:db8::/48", libyang::LeafBaseType::String, true }, + { "/kea-dhcp6-server:config/expired-leases-processing", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/dhcp-ddns", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/config-control", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/sanity-checks", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/interfaces-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/subnet6[id='111']/relay", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/compatibility", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/multi-threading", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +/// @brief Example from the design document. +const std::string designExampleModel = IETF_DHCPV6_SERVER; +const YRTree designExampleTree = YangRepr::buildTreeFromVector({ + { "/ietf-dhcpv6-server:server", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/network-range-id", + "1", libyang::LeafBaseType::Uint32, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/network-description", + "example", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/pd-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']" + "/pool-id", + "0", libyang::LeafBaseType::Uint32, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']" + "/prefix", + "2001:db8:20:b00::/57", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/pd-pools/pd-pool[pool-id='0']" + "/prefix-length", + "57", libyang::LeafBaseType::Uint8, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/pd-pools/" + "pd-pool[pool-id='0']/max-pd-space-utilization", + "disabled", libyang::LeafBaseType::Enum, true }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/network-prefix", + "2001:db8:20:b00::/56", libyang::LeafBaseType::String, true }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid/type-code", + "65535", libyang::LeafBaseType::Uint16, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/host-reservations", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/duid", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/lease-storage", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/serv-attributes/vendor-info", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/option-sets", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/relay-opaque-paras", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/rsoo-enabled-options", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/ietf-dhcpv6-server:server/server-config/network-ranges/" + "network-range[network-range-id='1']/address-pools", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +const YRTree emptyTreeKeaDhcp4 = YangRepr::buildTreeFromVector({ + { "/kea-dhcp4-server:config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/expired-leases-processing", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/dhcp-ddns", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/config-control", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/sanity-checks", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/interfaces-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/compatibility", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp4-server:config/multi-threading", + std::nullopt, libyang::LeafBaseType::Unknown, false }, +}); + +const YRTree emptyTreeKeaDhcp6 = YangRepr::buildTreeFromVector({ + { "/kea-dhcp6-server:config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/expired-leases-processing", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/dhcp-ddns", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/config-control", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/sanity-checks", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/interfaces-config", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/compatibility", + std::nullopt, libyang::LeafBaseType::Unknown, false }, + { "/kea-dhcp6-server:config/multi-threading", + std::nullopt, libyang::LeafBaseType::Unknown, 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 } +}; // TEST_CONFIGS + +} // 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..408d555 --- /dev/null +++ b/src/lib/yang/testutils/Makefile.am @@ -0,0 +1,30 @@ +SUBDIRS = . + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += $(LIBYANG_CPPFLAGS) +AM_CPPFLAGS += $(LIBYANG_INCLUDEDIR) +AM_CPPFLAGS += $(LIBYANGCPP_CPPFLAGS) +AM_CPPFLAGS += $(LIBYANGCPP_INCLUDEDIR) +AM_CPPFLAGS += $(SYSREPO_CPPFLAGS) +AM_CPPFLAGS += $(SYSREPO_INCLUDEDIR) +AM_CPPFLAGS += $(SYSREPOCPP_CPPFLAGS) +AM_CPPFLAGS += $(SYSREPOCPP_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..56435fc --- /dev/null +++ b/src/lib/yang/testutils/Makefile.in @@ -0,0 +1,867 @@ +# 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_cpp20.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_netconf.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_GSSAPI_CONFIGURE_FLAG = @DISTCHECK_GSSAPI_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG = @DISTCHECK_LIBYANGCPP_CONFIGURE_FLAG@ +DISTCHECK_LIBYANG_CONFIGURE_FLAG = @DISTCHECK_LIBYANG_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_MYSQL_CONFIGURE_FLAG = @DISTCHECK_MYSQL_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PGSQL_CONFIGURE_FLAG = @DISTCHECK_PGSQL_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG = @DISTCHECK_SYSREPOCPP_CONFIGURE_FLAG@ +DISTCHECK_SYSREPO_CONFIGURE_FLAG = @DISTCHECK_SYSREPO_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_NETCONF = @HAVE_NETCONF@ +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@ +LIBYANGCPP_CPPFLAGS = @LIBYANGCPP_CPPFLAGS@ +LIBYANGCPP_INCLUDEDIR = @LIBYANGCPP_INCLUDEDIR@ +LIBYANGCPP_LIBS = @LIBYANGCPP_LIBS@ +LIBYANGCPP_PREFIX = @LIBYANGCPP_PREFIX@ +LIBYANGCPP_VERSION = @LIBYANGCPP_VERSION@ +LIBYANG_CPPFLAGS = @LIBYANG_CPPFLAGS@ +LIBYANG_INCLUDEDIR = @LIBYANG_INCLUDEDIR@ +LIBYANG_LIBS = @LIBYANG_LIBS@ +LIBYANG_PREFIX = @LIBYANG_PREFIX@ +LIBYANG_VERSION = @LIBYANG_VERSION@ +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_PLUGINS_PATH = @SR_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_CPPFLAGS = @SYSREPOCPP_CPPFLAGS@ +SYSREPOCPP_INCLUDEDIR = @SYSREPOCPP_INCLUDEDIR@ +SYSREPOCPP_LIBS = @SYSREPOCPP_LIBS@ +SYSREPOCPP_PREFIX = @SYSREPOCPP_PREFIX@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_PREFIX = @SYSREPO_PREFIX@ +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) $(LIBYANG_CPPFLAGS) $(LIBYANG_INCLUDEDIR) \ + $(LIBYANGCPP_CPPFLAGS) $(LIBYANGCPP_INCLUDEDIR) \ + $(SYSREPO_CPPFLAGS) $(SYSREPO_INCLUDEDIR) \ + $(SYSREPOCPP_CPPFLAGS) $(SYSREPOCPP_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..36012db --- /dev/null +++ b/src/lib/yang/testutils/translator_test.cc @@ -0,0 +1,276 @@ +// 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/testutils/translator_test.h> + +#include <boost/lexical_cast.hpp> + +#include <variant> +#include <vector> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { +namespace test { + +LeafBaseType +YangRepr::YangReprItem::getUnionType(Value const& value) { + static_assert( + std::is_same< + Value, std::variant<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, + uint64_t, bool, Empty, Binary, string, optional<DataNode>, + Decimal64, vector<Bit>, Enum, IdentityRef>>::value, + "Value type has changed. The if statement needs to be adjusted to include all alternatives " + "of the std::variant."); + + if (holds_alternative<int8_t>(value)) { + return LeafBaseType::Int8; + } else if (holds_alternative<int16_t>(value)) { + return LeafBaseType::Int16; + } else if (holds_alternative<int32_t>(value)) { + return LeafBaseType::Int32; + } else if (holds_alternative<int64_t>(value)) { + return LeafBaseType::Int64; + } else if (holds_alternative<uint8_t>(value)) { + return LeafBaseType::Uint8; + } else if (holds_alternative<uint16_t>(value)) { + return LeafBaseType::Uint16; + } else if (holds_alternative<uint32_t>(value)) { + return LeafBaseType::Uint32; + } else if (holds_alternative<uint64_t>(value)) { + return LeafBaseType::Uint64; + } else if (holds_alternative<bool>(value)) { + return LeafBaseType::Bool; + } else if (holds_alternative<Empty>(value)) { + return LeafBaseType::Empty; + } else if (holds_alternative<Binary>(value)) { + return LeafBaseType::Binary; + } else if (holds_alternative<string>(value)) { + return LeafBaseType::String; + } else if (holds_alternative<optional<DataNode>>(value)) { + return LeafBaseType::InstanceIdentifier; + } else if (holds_alternative<Decimal64>(value)) { + return LeafBaseType::Dec64; + } else if (holds_alternative<vector<Bit>>(value)) { + return LeafBaseType::Bits; + } else if (holds_alternative<Enum>(value)) { + return LeafBaseType::Enum; + } else if (holds_alternative<IdentityRef>(value)) { + return LeafBaseType::IdentityRef; + } + return LeafBaseType::Unknown; +} + +YangRepr::YangReprItem +YangRepr::YangReprItem::get(const string& xpath, Session session) { + string val_xpath; + optional<string> value; + LeafBaseType type(LeafBaseType::Unknown); + bool settable = true; + try { + optional<DataNode> data_node(session.getData(xpath)); + if (!data_node) { + isc_throw(BadValue, "YangReprItem failed at '" << xpath << "'"); + } + data_node = data_node->findPath(xpath); + SchemaNode const& schema(data_node->schema()); + NodeType const node_type(schema.nodeType()); + if (node_type == NodeType::Leaf) { + type = schema.asLeaf().valueType().base(); + } else if (node_type == NodeType::Leaflist) { + type = schema.asLeafList().valueType().base(); + } else { + settable = false; + } + if (type == LeafBaseType::Union) { + // Get the underlying type. + type = getUnionType(data_node->asTerm().value()); + } + if (type == LeafBaseType::Leafref) { + // Get the underlying type. + type = data_node->schema().asLeaf().valueType().asLeafRef().resolvedType().base(); + } + value = Translator::translateToYang(Translator::translateFromYang(data_node), type); + val_xpath = string(data_node->path()); + } catch (Error const& ex) { + isc_throw(NetconfError, "in YangReprItem: " << ex.what()); + } + return (YangReprItem(val_xpath, value, type, settable)); +} + +YangRepr::Tree +YangRepr::get(Session session) const { + Tree result; + try { + Translator tb(session, model_); + string const xpath0("/" + model_ + ":*//."); + tb.forAll(xpath0, [&](libyang::DataNode const& node) { + string const& xpath(node.path()); + result.emplace(xpath, YangReprItem::get(xpath, session)); + }); + } catch (Error const& ex) { + isc_throw(NetconfError, + "in YangRepr::getTree: " << ex.what()); + } + return (result); +} + +bool +YangRepr::verify(const Tree& expected, 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, Session session) const { + for (auto const& kv : tree) { + YangReprItem const& item(kv.second); + if (!item.settable_) { + continue; + } + try { + Context const& context(session.getContext()); + SchemaNode const& schema(context.findPath(item.xpath_)); + NodeType const node_type(schema.nodeType()); + bool is_key(false); + if (node_type == NodeType::Leaf) { + is_key = schema.asLeaf().isKey(); + } + if (!is_key) { + session.setItem(item.xpath_, item.value_); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "in YangRepr::set for " << item + << ", error: " << ex.what()); + } + } + session.applyChanges(); +} + +ostream& +operator<<(ostream& os, LeafBaseType type) { + switch (type) { + case LeafBaseType::String: + os << "string"; + break; + case LeafBaseType::Bool: + os << "bool"; + break; + case LeafBaseType::Uint8: + os << "uint8"; + break; + case LeafBaseType::Uint16: + os << "uint16"; + break; + case LeafBaseType::Uint32: + os << "uint32"; + break; + case LeafBaseType::Int8: + os << "int8"; + break; + case LeafBaseType::Int16: + os << "int16"; + break; + case LeafBaseType::Int32: + os << "int32"; + break; + case LeafBaseType::IdentityRef: + os << "identity ref"; + break; + case LeafBaseType::Enum: + os << "enum"; + break; + case LeafBaseType::Binary: + os << "binary"; + break; + case LeafBaseType::Bits: + os << "bits"; + break; + case LeafBaseType::Dec64: + os << "decimal64"; + break; + case LeafBaseType::InstanceIdentifier: + os << "instance id"; + break; + case LeafBaseType::Int64: + os << "int64"; + break; + case LeafBaseType::Uint64: + os << "uint64"; + break; + case LeafBaseType::Union: + os << "union"; + break; + case LeafBaseType::Leafref: + os << "leafref"; + break; + case LeafBaseType::Unknown: + os << "unknown"; + break; + default: + isc_throw(BadValue, "unsupported type " << int(type)); + } + return (os); +} + +ostream& operator<<(ostream& os, const YangRepr::YangReprItem& item) { + os << item.xpath_ << " = (" << item.type_ << ") '" << (item.value_ ? *item.value_ : "nullopt") + << "'"; + 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..bb11d92 --- /dev/null +++ b/src/lib/yang/testutils/translator_test.h @@ -0,0 +1,162 @@ +// 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_TEST_H +#define ISC_TRANSLATOR_TEST_H 1 + +#include <yang/translator.h> + +#include <vector> +#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::optional<std::string> value, + libyang::LeafBaseType 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::Session session); + + /// @brief The xpath. + std::string xpath_; + + /// @brief The textual value. + std::optional<std::string> value_; + + /// @brief The type of the value. + libyang::LeafBaseType 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)); + } + + private: + /// @brief Gets the underlying type behind a union node. + /// + /// @param value the value obtained from the union node with ->asTerm().value() + /// + /// @return the underlying type + static libyang::LeafBaseType getUnionType(libyang::Value const& value); + }; // YangReprItem + + /// @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::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::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::Session session) 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) { + if (tree.contains(item.xpath_)) { + isc_throw(BadValue, "YangRepr::buildTreeFromVector(): duplicate " << item.xpath_); + } + tree.emplace(item.xpath_, item); + } + return tree; + } + +private: + /// @brief The model name. + std::string model_; +}; // YangRepr + +/// @brief Alias for Items. +using YRItem = YangRepr::YangReprItem; + +/// @brief Alias for Trees. +using YRTree = YangRepr::Tree; + +/// @brief Overrides standard output operator for LeafBaseType. +std::ostream& operator<<(std::ostream& os, libyang::LeafBaseType type); + +/// @brief Overrides standard output operator for @c YangReprItem object. +std::ostream& operator<<(std::ostream& os, const YRItem& item); + +/// @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..9c5ed9c --- /dev/null +++ b/src/lib/yang/translator.cc @@ -0,0 +1,382 @@ +// 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/base64.h> +#include <yang/adaptor.h> +#include <yang/translator.h> + +#include <sysrepo-cpp/utils/exception.hpp> + +#include <cstring> +#include <vector> + +using namespace std; +using namespace isc::data; +using namespace isc::util::encode; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +Translator::Translator(Session session, const string& model) + : session_(session), model_(model) { +} + +void +Translator::checkAndGetLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name) const { + ElementPtr const& x(getItem(data_node, name)); + if (x) { + storage->set(name, x); + } +} + +void +Translator::checkAndGetDivergingLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name, + string const& yang_name) const { + ElementPtr const& x(getItem(data_node, yang_name)); + if (x) { + storage->set(name, x); + } +} + +void +Translator::checkAndGetAndJsonifyLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name) const { + ElementPtr const& x(getItem(data_node, name)); + if (x) { + storage->set(name, Element::fromJSON(x->stringValue())); + } +} + +void +Translator::checkAndSetLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + LeafBaseType const type) { + ConstElementPtr const& x(from->get(name)); + if (x) { + setItem(xpath + "/" + name, x, type); + } +} + +void +Translator::checkAndSetDivergingLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + string const& yang_name, + LeafBaseType const type) { + ConstElementPtr const& x(from->get(name)); + if (x) { + setItem(xpath + "/" + yang_name, x, type); + } +} + +void +Translator::checkAndSetLeafList(ConstElementPtr const& from, + string const& xpath, + string const& name, + LeafBaseType const type) { + ConstElementPtr const& leaf_list(from->get(name)); + if (leaf_list && !leaf_list->empty()) { + for (ElementPtr const& leaf : leaf_list->listValue()) { + setItem(xpath + "/" + name, leaf, type); + } + } +} + +void +Translator::checkAndSetUserContext(ConstElementPtr const& from, + string const& xpath) { + ConstElementPtr const& user_context(Adaptor::getContext(from)); + if (user_context) { + setItem(xpath + "/user-context", Element::create(user_context->str()), + LeafBaseType::String); + } +} + +void +Translator::checkAndStringifyAndSetLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name) { + ConstElementPtr const& x(from->get(name)); + if (x) { + ElementPtr const& json(Element::create(x->str())); + setItem(xpath + "/" + name, json, LeafBaseType::String); + } +} + +void +Translator::deleteItem(string const& xpath) { + try { + if (session_.getData(xpath)) { + session_.deleteItem(xpath); + } + } catch (sysrepo::Error const& ex) { + isc_throw(NetconfError, "deleting item at '" << xpath << "': " << ex.what()); + } + session_.applyChanges(); +} + +DataNode +Translator::findXPath(string const& xpath) const { + optional<DataNode> const& data_node(getData(xpath)); + if (!data_node) { + isc_throw(NetconfError, "no data at xpath " << xpath); + } + Set<DataNode> at_path(data_node->findXPath(xpath)); + if (at_path.empty()) { + isc_throw(NetconfError, "no data at xpath " << xpath); + } + return at_path.front(); +} + +optional<DataNode> +Translator::getData(string const& xpath) const { + optional<DataNode> data_node; + try { + data_node = session_.getData(xpath); + } catch (sysrepo::Error const& ex) { + isc_throw(NetconfError, "getting item at '" << xpath << "': " << ex.what()); + } + + return data_node; +} + +ElementPtr +Translator::getItem(DataNode const& data_node, + string const& xpath) const { + try { + Set<DataNode> const& nodes(data_node.findXPath(xpath)); + if (nodes.empty()) { + return ElementPtr(); + } + DataNode const& front(nodes.front()); + NodeType const node_type(front.schema().nodeType()); + + // Leaf + if (node_type == NodeType::Leaf) { + return translateFromYang(front); + } else if (node_type == NodeType::Leaflist) { + ElementPtr result(Element::createList()); + for (DataNode const& i : nodes) { + result->add(translateFromYang(i)); + } + return result; + } else { + isc_throw(NotImplemented, "getting node of type " + << int(node_type) << " not supported, xpath is '" << xpath + << "'"); + } + + } catch (sysrepo::Error const& ex) { + isc_throw(NetconfError, "getting item at '" << xpath << "': " << ex.what()); + } +} + +ElementPtr +Translator::getItemFromAbsoluteXpath(string const& xpath) const { + optional<DataNode> const& data_node(getData(xpath)); + if (!data_node) { + return ElementPtr(); + } + return getItem(*data_node, xpath); +} + +void +Translator::getMandatoryLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name) const { + ElementPtr const& x(getItem(data_node, name)); + if (!x) { + isc_throw(MissingNode, name); + } + storage->set(name, x); +} + +void +Translator::getMandatoryDivergingLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name, + string const& yang_name) const { + ElementPtr const& x(getItem(data_node, yang_name)); + if (!x) { + isc_throw(MissingNode, yang_name); + } + storage->set(name, x); +} + +bool +Translator::schemaNodeExists(string const& xpath) const { + Context const& context(session_.getContext()); + try { + context.findPath(xpath); + } catch (libyang::Error const& ex) { + return false; + } + return true; +} + +void +Translator::setItem(const string& xpath, ConstElementPtr elem, LeafBaseType type) { + optional<string> const value(translateToYang(elem, type)); + try { + session_.setItem(xpath, value); + } catch (sysrepo::Error const& ex) { + isc_throw(NetconfError, "setting item '" << (elem ? elem->str() : "nullopt") + << "' at '" << xpath << "': " << ex.what()); + } + session_.applyChanges(); +} + +void +Translator::setMandatoryLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + LeafBaseType const type) { + ConstElementPtr const& x(from->get(name)); + if (!x) { + isc_throw(MissingNode, "xpath: " << xpath << ", name: " << name); + } + setItem(xpath + "/" + name, x, type); +} + +void +Translator::setMandatoryDivergingLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + string const& yang_name, + LeafBaseType const type) { + ConstElementPtr const& x(from->get(name)); + if (!x) { + isc_throw(MissingNode, "xpath: " << xpath << ", name: " << name); + } + setItem(xpath + "/" + yang_name, x, type); +} + +ElementPtr +Translator::translateFromYang(optional<DataNode> data_node) { + NodeType const node_type(data_node->schema().nodeType()); + if (node_type == NodeType::Leaf || node_type == NodeType::Leaflist) { + DataNodeTerm const& leaf(data_node->asTerm()); + LeafBaseType type; + if (node_type == NodeType::Leaf) { + type = leaf.schema().asLeaf().valueType().base(); + } else { + type = leaf.schema().asLeafList().valueType().base(); + } + + static Deserializer deserializer(initializeDeserializer()); + return deserializer.at(type)(string(leaf.valueStr())); + } + return ElementPtr(); +} + +optional<string> +Translator::translateToYang(ConstElementPtr const& element, + libyang::LeafBaseType const type) { + string string_representation; + if (!element) { + // A null ElementPtr is how we signal that this item requires no value. + // Useful when setting YANG lists which is the only way to set their + // keys in sysrepo since setting the key itself results in an error. + return nullopt; + } else if (element->getType() == Element::map) { + isc_throw(NotImplemented, "Translator::value(): map element"); + } else if (element->getType() == Element::list) { + isc_throw(NotImplemented, "Translator::value(): list element"); + } else if (element->getType() == Element::string) { + // If it's a string, get the variant without quotes. + string_representation = element->stringValue(); + } else { + // If it's not a string, also get the variant without quotes, but it's a different method. + string_representation = element->str(); + } + + static Serializer serializer(initializeSerializer()); + return serializer.at(type)(string_representation); +} + +string +Translator::decode64(string const& input) { + vector<uint8_t> binary; + decodeBase64(input, binary); + string result; + result.resize(binary.size()); + memcpy(&result[0], &binary[0], result.size()); + return (result); +} + +string +Translator::encode64(string const& input) { + vector<uint8_t> binary; + binary.resize(input.size()); + memcpy(&binary[0], input.c_str(), binary.size()); + return (encodeBase64(binary)); +} + +Translator::Deserializer +Translator::initializeDeserializer() { + Deserializer result; + + result.emplace(LeafBaseType::Binary, [](string const& value) -> ElementPtr const { + return Element::create(decode64(value)); + }); + + for (LeafBaseType const& i : + {LeafBaseType::Bool, LeafBaseType::Dec64, LeafBaseType::Int8, LeafBaseType::Int16, + LeafBaseType::Int32, LeafBaseType::Int64, LeafBaseType::Uint8, LeafBaseType::Uint16, + LeafBaseType::Uint32, LeafBaseType::Uint64}) { + result.emplace(i, [](string const& value) -> ElementPtr const { + return Element::fromJSON(value); + }); + } + + // The rest of YANG values can be expressed as strings. + for (LeafBaseType const& i : + {LeafBaseType::Bits, LeafBaseType::Empty, LeafBaseType::Enum, LeafBaseType::IdentityRef, + LeafBaseType::InstanceIdentifier, LeafBaseType::Leafref, LeafBaseType::String, + LeafBaseType::Union, LeafBaseType::Unknown}) { + result.emplace(i, [](string const& value) -> ElementPtr const { + return Element::create(value); + }); + } + + return result; +} + +Translator::Serializer +Translator::initializeSerializer() { + Serializer result; + + result.emplace(LeafBaseType::Binary, [](string const& value) -> string const { + return encode64(value); + }); + + // The rest of YANG values can be expressed directly. + for (LeafBaseType const& i : + {LeafBaseType::Bits, LeafBaseType::Bool, LeafBaseType::Dec64, LeafBaseType::Empty, + LeafBaseType::Enum, LeafBaseType::IdentityRef, LeafBaseType::InstanceIdentifier, + LeafBaseType::Int8, LeafBaseType::Int16, LeafBaseType::Int32, LeafBaseType::Int64, + LeafBaseType::Leafref, LeafBaseType::String, LeafBaseType::Uint8, LeafBaseType::Uint16, + LeafBaseType::Uint32, LeafBaseType::Uint64, LeafBaseType::Union, LeafBaseType::Unknown}) { + result.emplace(i, [](string const& value) -> string const { + return value; + }); + } + + return result; +} + +} // namespace yang +} // namespace isc diff --git a/src/lib/yang/translator.h b/src/lib/yang/translator.h new file mode 100644 index 0000000..5bbaa7d --- /dev/null +++ b/src/lib/yang/translator.h @@ -0,0 +1,432 @@ +// 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_H +#define ISC_TRANSLATOR_H 1 + +#include <cc/data.h> +#include <yang/netconf_error.h> + +#include <sysrepo-cpp/Connection.hpp> +#include <sysrepo-cpp/Session.hpp> + +#include <unordered_map> + +namespace isc { +namespace yang { + +/// @brief Between YANG and JSON translator class for basic values. +class Translator { +public: + /// @brief Constructor. + /// + /// @param session Sysrepo session. + /// @param model Model name (used and shared by derived classes). + Translator(sysrepo::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~Translator() = default; + + /// @brief Calls {translate} for the element found at {xpath} relative to + /// {data_node} and sets the result in {storage} with the {xpath} key. + /// + /// @tparam T typename of the function to be called + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param xpath relative xpath to search by + /// @param translate function to be called to translate a data node to an element pointer + template <typename T> + void checkAndGet(isc::data::ElementPtr const& storage, + libyang::DataNode const& data_node, + std::string const& xpath, + T translate) const { + libyang::Set<libyang::DataNode> const& nodes(data_node.findXPath(xpath)); + if (!nodes.empty()) { + isc::data::ElementPtr const& element(translate(nodes.front())); + if (element && !element->empty()) { + storage->set(xpath, element); + } + } + } + + /// @brief Calls {translate} for the element found at {xpath} relative to + /// {data_node} and sets the result in {storage} with the {key} key. + /// + /// It's the counterpart for @ref checkAndGet, but when the YANG xpath + /// and the JSON key diverge. + /// + /// @tparam T typename of the function to be called + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param key where to set the result in the {storage} map + /// @param xpath relative xpath to search by + /// @param translate function to be called to translate a data node to an element pointer + template <typename T> + void checkAndGetDiverging(isc::data::ElementPtr const& storage, + libyang::DataNode const& data_node, + std::string const& key, + std::string const& xpath, + T translate) const { + libyang::Set<libyang::DataNode> const& nodes(data_node.findXPath(xpath)); + if (!nodes.empty()) { + isc::data::ElementPtr const& element(translate(nodes.front())); + if (element && !element->empty()) { + storage->set(key, element); + } + } + } + + /// @brief Retrieves a child YANG data node identified by name from the + /// given parent YANG container node and stores it in the specified storage. + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param name the name of the parameter to be set in storage + void checkAndGetLeaf(isc::data::ElementPtr& storage, + libyang::DataNode const& data_node, + std::string const& name) const; + + /// @brief Retrieves a child YANG data node identified by name from the + /// given parent YANG container node and stores it in the specified storage. + /// + /// It's the counterpart for @ref checkAndGetLeaf, but when the YANG xpath + /// and the JSON key diverge. + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param name the name of the parameter to be set in storage + /// @param yang_name the name by which to find the parameter in the YANG data node + void checkAndGetDivergingLeaf(isc::data::ElementPtr& storage, + libyang::DataNode const& data_node, + std::string const& name, + std::string const& yang_name) const; + + /// @brief Retrieves a child YANG data node identified by name from the given parent YANG + /// container node, converts it from string to JSON and stores it in the specified storage. + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param name the name of the parameter to be set in storage + void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr& storage, + libyang::DataNode const& data_node, + const std::string& name) const; + + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath. + /// + /// @param from the parent configuration node from which to take the value + /// @param xpath the xpath to the YANG node without the last node + /// @param name the name of the YANG node which should also match the key + /// under which data is set in the MapElement {from} + /// @param type the YANG node type + void checkAndSetLeaf(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name, + libyang::LeafBaseType const type); + + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath. + /// + /// It's the counterpart for @ref checkAndSetLeaf, but when the YANG xpath + /// and the JSON key diverge. + /// + /// @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 key under which data is set in the MapElement {from} + /// @param yang_name the name of the YANG node + /// @param type the YANG node type + void checkAndSetDivergingLeaf(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name, + std::string const& yang_name, + libyang::LeafBaseType const type); + + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath as a leaf-list. + /// + /// @param from the parent configuration node from which to take the values + /// @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 key + /// under which data is set in the MapElement {from} + /// @param type the YANG node type of the underlying leaf-list nodes + void checkAndSetLeafList(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name, + libyang::LeafBaseType const type); + + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath. + /// + /// @param from the parent configuration node from which to take the value + /// @param xpath the xpath to the YANG node without the last node + void checkAndSetUserContext(isc::data::ConstElementPtr const& from, + std::string const& xpath); + + /// @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 key + /// under which data is set in the MapElement {from} + void checkAndStringifyAndSetLeaf(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name); + + /// @brief Delete basic value from YANG. + /// + /// @param xpath The xpath of the basic value. + void deleteItem(const std::string& xpath); + + /// @brief Retrieves a YANG data node by xpath. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// + /// @param xpath the xpath of the requested node + /// + /// @return the requested YANG data node + /// + /// @throw NetconfError if no YANG data node was found + libyang::DataNode findXPath(std::string const& xpath) const; + + /// @brief Run a function for a node and all its children. + /// + /// @tparam functor_t typename of the function to be called + /// + /// @note This is a computationally expensive operation that makes a lookup + /// in the sysrepo datastore by calling Session::getData(). It should be + /// used sparingly in production code. It is primarily meant for unit tests. + /// + /// @param xpath the xpath of the root node belonging to the the tree being traversed + /// @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) const { + std::optional<libyang::DataNode> const& data_node(session_.getData(xpath)); + if (!data_node) { + return; + } + + for (libyang::DataNode const& sibling : data_node->siblings()) { + for (libyang::DataNode const& n : sibling.childrenDfs()) { + f(n); + } + } + } + + /// @brief Get a YANG data node found at the given absolute xpath. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// + /// @param xpath the xpath at which the YANG data node is to be found + /// + /// @return a DataNode if found, or nullopt otherwise + /// + /// @throw NetconfError when the used sysrepo API throws an error + std::optional<libyang::DataNode> getData(std::string const& xpath) const; + + /// @brief Translate a basic value from YANG to JSON for + /// a given xpath that is relative to the given source node. + /// + /// @param data_node the source data node + /// @param xpath the relative xpath + /// + /// @return The Element representing the item at xpath or null + /// when not found. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getItem(libyang::DataNode const& data_node, + std::string const& xpath) const; + + /// @brief Translate a basic value from YANG to JSON for a given absolute xpath. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// + /// @param xpath The xpath of the basic value. + /// @return The Element representing the item at xpath or null + /// when not found. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getItemFromAbsoluteXpath(std::string const& xpath) const; + + /// @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 data_node the YANG data node to retrieve data from + /// @param xpath the xpath to the element to be retrieved from, relative to {data_node} + /// @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(libyang::DataNode const& data_node, + std::string const& xpath, + T& t, + isc::data::ElementPtr (T::*f)(libyang::DataNode const&)) const { + try { + libyang::Set<libyang::DataNode> const& nodes(data_node.findXPath(xpath)); + if (nodes.empty()) { + return (isc::data::ElementPtr()); + } + isc::data::ElementPtr const result(isc::data::Element::createList()); + for (libyang::DataNode const& i : nodes) { + result->add((t.*f)(i)); + } + return result; + } catch (libyang::Error const& ex) { + isc_throw(NetconfError, "getting item: " << ex.what()); + } + } + + /// @brief Retrieves a child YANG data node identified by name from the + /// given parent YANG container node and stores it in the specified storage. + /// + /// Unlike @ref checkAndGetLeaf, the leaf is expected to be present. + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param name the name of the YANG node which should also match the map + /// key in the JSON configuration + /// + /// @throw MissingNode if leaf is not found + void getMandatoryLeaf(isc::data::ElementPtr& storage, + libyang::DataNode const& data_node, + std::string const& name) const; + + /// @brief Retrieves a child YANG data node identified by one name from the + /// given parent YANG container node and stores it in the specified storage + /// under a different name. + /// + /// Unlike @ref checkAndGetLeaf, the leaf is expected to be present. + /// + /// @param storage ElementMap where result will be stored + /// @param data_node parent data node of container type + /// @param name the map key in the JSON configuration + /// @param yang_name the name by which to find the parameter in the YANG data node + /// + + /// @throw MissingNode if leaf is not found + void getMandatoryDivergingLeaf(isc::data::ElementPtr& storage, + libyang::DataNode const& data_node, + std::string const& name, + std::string const& yang_name) const; + + /// @brief Checks whether a YANG node exists in the schema. + /// + /// @param xpath the xpath to be checked + /// + /// @return true if the YANG node exists in the schema, false otherwise + bool schemaNodeExists(std::string const& xpath) const; + + /// @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, + libyang::LeafBaseType type); + + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath. + /// + /// @param from the parent configuration node from which to take the value + /// @param xpath the xpath to the YANG node without the last node + /// @param name the name of the YANG node which should also match the map + /// key in the JSON configuration + /// @param type the YANG node type + void setMandatoryLeaf(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name, + libyang::LeafBaseType const type); + + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath. + /// + /// @param from the parent configuration node from which to take the value + /// @param xpath the xpath to the YANG node without the last node + /// @param name the map key in the JSON configuration + /// @param yang_name the name by which to find the parameter in the YANG data node + /// @param type the YANG node type + void setMandatoryDivergingLeaf(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name, + std::string const& yang_name, + libyang::LeafBaseType const type); + + /// @brief Translate basic value from the given YANG data node to JSON element. + /// + /// @param data_node the YANG data node + /// + /// @return the translated JSON element + static isc::data::ElementPtr translateFromYang(std::optional<libyang::DataNode> data_node); + + /// @brief Translate basic value from JSON to YANG. + /// + /// @param elem The JSON element. + /// @param type The sysrepo type. + /// + /// @return string representation of {elem}, or nullopt if {elem} is null + static std::optional<std::string> translateToYang(isc::data::ConstElementPtr const& elem, + libyang::LeafBaseType const type); + +protected: + /// @brief Decode a YANG element of binary type to a string that + /// can be stored in an Element::string JSON. + /// + /// @param input string to be decoded + /// + /// @return the decoded string + static std::string decode64(std::string const& input); + + /// @brief Encode a string such that it can be stored in a YANG element of binary type. + /// + /// @param input string to be encoded + /// + /// @return the encoded string + static std::string encode64(std::string const& input); + + /// @brief Maps YANG types to functions that transform a YANG type into an ElementPtr. + using Deserializer = + std::unordered_map<libyang::LeafBaseType, + std::function<isc::data::ElementPtr const(std::string const&)>>; + + /// @brief Initializes the deserializer which is used to translate a YANG node to an ElementPtr. + /// + /// @return a copy of the deserializer + static Deserializer initializeDeserializer(); + + /// @brief Maps YANG types to functions that transform the string representation of an + /// Element into a string that can be passed into Session::setItem(). + using Serializer = + std::unordered_map<libyang::LeafBaseType, + std::function<std::string const(std::string const&)>>; + + /// @brief Initializes the serializer which is used to translate the string value of an Element + /// to a string that can be passed into Session::setItem(). + /// + /// @return a copy of the serializer + static Serializer initializeSerializer(); + + /// @brief The sysrepo session. + sysrepo::Session session_; + + /// @brief The model. + std::string model_; +}; // Translator + +} // 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..5553ced --- /dev/null +++ b/src/lib/yang/translator_class.cc @@ -0,0 +1,219 @@ +// Copyright (C) 2018-2023 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 <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorClass::TranslatorClass(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model), + TranslatorOptionDef(session, model), + TranslatorOptionDefList(session, model) { +} + +ElementPtr +TranslatorClass::getClass(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getClassKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting client class:" + << ex.what()); + } + isc_throw(NotImplemented, + "getClass not implemented for the model: " << model_); +} + +ElementPtr +TranslatorClass::getClassFromAbsoluteXpath(string const& xpath) { + try { + return getClass(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorClass::getClassKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "name"); + + checkAndGetLeaf(result, data_node, "max-valid-lifetime"); + checkAndGetLeaf(result, data_node, "min-valid-lifetime"); + checkAndGetLeaf(result, data_node, "only-if-required"); + checkAndGetLeaf(result, data_node, "template-test"); + checkAndGetLeaf(result, data_node, "test"); + checkAndGetLeaf(result, data_node, "valid-lifetime"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + if (model_ == KEA_DHCP4_SERVER) { + checkAndGetLeaf(result, data_node, "boot-file-name"); + checkAndGetLeaf(result, data_node, "next-server"); + checkAndGetLeaf(result, data_node, "offer-lifetime"); + checkAndGetLeaf(result, data_node, "server-hostname"); + + ConstElementPtr defs = getOptionDefList(data_node); + if (defs) { + result->set("option-def", defs); + } + } else if (model_ == KEA_DHCP6_SERVER) { + checkAndGetLeaf(result, data_node, "max-preferred-lifetime"); + checkAndGetLeaf(result, data_node, "min-preferred-lifetime"); + checkAndGetLeaf(result, data_node, "preferred-lifetime"); + } + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorClass::setClass(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting client class '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorClass::setClassKea(string const& xpath, ConstElementPtr elem) { + // Keys are set by setting the list itself. + setItem(xpath, ElementPtr(), LeafBaseType::Unknown); + + checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "only-if-required", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "template-test", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "test", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32); + + ConstElementPtr options = elem->get("option-data"); + if (options) { + setOptionDataList(xpath, options); + } + + if (model_ == KEA_DHCP4_SERVER) { + checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String); + + ConstElementPtr defs = elem->get("option-def"); + if (defs) { + setOptionDefList(xpath, defs); + } + } else if (model_ == KEA_DHCP6_SERVER) { + checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); + } + + checkAndSetUserContext(elem, xpath); +} + +TranslatorClasses::TranslatorClasses(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model), + TranslatorOptionDef(session, model), + TranslatorOptionDefList(session, model), + TranslatorClass(session, model) { +} + +ElementPtr +TranslatorClasses::getClasses(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getClassesKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting client classes:" + << ex.what()); + } + isc_throw(NotImplemented, + "getClasses not implemented for the model: " << model_); +} + +ElementPtr +TranslatorClasses::getClassesFromAbsoluteXpath(string const& xpath) { + try { + return getClasses(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorClasses::getClassesKea(DataNode const& data_node) { + return getList<TranslatorClass>(data_node, "client-class", *this, + &TranslatorClass::getClass); +} + +void +TranslatorClasses::setClasses(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting client classes '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorClasses::setClassesKea(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr cclass = elem->getNonConst(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..5b2b7f6 --- /dev/null +++ b/src/lib/yang/translator_class.h @@ -0,0 +1,203 @@ +// 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_CLASS_H +#define ISC_TRANSLATOR_CLASS_H 1 + +#include <yang/translator_option_data.h> +#include <yang/translator_option_def.h> + +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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorClass() = default; + + /// @brief Translate a client class from YANG to JSON. + /// + /// @param data_node the YANG node representing the class + /// + /// @return the JSON representation of the class + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getClass(libyang::DataNode const& data_node); + + /// @brief Translate a client class from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getClass(libyang::DataNode) as a scalable alternative. + /// + /// @param xpath the xpath of the class + /// + /// @return JSON representation of the class + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getClassFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the client class + /// + /// @return JSON representation of the class + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getClassKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorClass + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorClasses() = default; + + /// @brief Translate client classes from YANG to JSON. + /// + /// @param data_node the YANG node representing the class + /// + /// @return the JSON representation of the list of classes + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getClasses(libyang::DataNode const& data_node); + + /// @brief Translate client classes from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getClasses(libyang::DataNode) as a scalable alternative. + /// + /// @param xpath The xpath of classes. + /// + /// @return JSON representation of classes. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getClassesFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the classes + /// + /// @return JSON representation of classes. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getClassesKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorClasses + +} // 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..4c2c6b8 --- /dev/null +++ b/src/lib/yang/translator_config.cc @@ -0,0 +1,759 @@ +// Copyright (C) 2018-2023 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> +#include <yang/translator_config.h> +#include <yang/yang_models.h> + +#include <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorConfig::TranslatorConfig(Session session, const string& model) + : Translator(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) { +} + +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 (Error const& ex) { + isc_throw(NetconfError, "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 const xpath("/ietf-dhcpv6-server:server"); + optional<DataNode> config; + try { + config = findXPath(xpath); + } catch (NetconfError const&) { + return result; + } + + checkAndGetDiverging(dhcp6, *config, "subnet6", "server-config/network-ranges", + [&](DataNode const& data_node) -> ElementPtr const { + return getSubnets(data_node); + }); + + // 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(DataNode const& data_node) { + ElementPtr hook_library(Element::createMap()); + checkAndGetLeaf(hook_library, data_node, "library"); + checkAndGetAndJsonifyLeaf(hook_library, data_node, "parameters"); + return hook_library; +} + +ElementPtr +TranslatorConfig::getHooksKea(DataNode const& data_node) { + return getList(data_node, "hook-library", *this, &TranslatorConfig::getHook); +} + +isc::data::ElementPtr +TranslatorConfig::getExpiredKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + checkAndGetLeaf(result, data_node, "flush-reclaimed-timer-wait-time"); + checkAndGetLeaf(result, data_node, "hold-reclaimed-time"); + checkAndGetLeaf(result, data_node, "max-reclaim-leases"); + checkAndGetLeaf(result, data_node, "max-reclaim-time"); + checkAndGetLeaf(result, data_node, "reclaim-timer-wait-time"); + checkAndGetLeaf(result, data_node, "unwarned-reclaim-cycles"); + + return (result->empty() ? ElementPtr() : result); +} + +isc::data::ElementPtr +TranslatorConfig::getDdnsKea(DataNode const& data_node) { + ElementPtr result(Element::createMap()); + + checkAndGetLeaf(result, data_node, "enable-updates"); + checkAndGetLeaf(result, data_node, "generated-prefix"); + checkAndGetLeaf(result, data_node, "hostname-char-replacement"); + checkAndGetLeaf(result, data_node, "hostname-char-set"); + checkAndGetLeaf(result, data_node, "max-queue-size"); + checkAndGetLeaf(result, data_node, "ncr-format"); + checkAndGetLeaf(result, data_node, "ncr-protocol"); + checkAndGetLeaf(result, data_node, "qualifying-suffix"); + checkAndGetLeaf(result, data_node, "override-client-update"); + checkAndGetLeaf(result, data_node, "override-no-update"); + checkAndGetLeaf(result, data_node, "replace-client-name"); + checkAndGetLeaf(result, data_node, "sender-ip"); + checkAndGetLeaf(result, data_node, "sender-port"); + checkAndGetLeaf(result, data_node, "server-ip"); + checkAndGetLeaf(result, data_node, "server-port"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorConfig::getConfigControlKea(DataNode const& data_node) { + ElementPtr result(Element::createMap()); + checkAndGetLeaf(result, data_node, "config-fetch-wait-time"); + ConstElementPtr databases = getDatabases(data_node, "config-database"); + if (databases && !databases->empty()) { + result->set("config-databases", databases); + } + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorConfig::getInterfacesKea(DataNode const& config) { + ElementPtr result; + optional<DataNode> const& interfaces_config_optional(config.findPath("interfaces-config")); + if (interfaces_config_optional) { + DataNode const interfaces_config(*interfaces_config_optional); + result = Element::createMap(); + + checkAndGetLeaf(result, interfaces_config, "dhcp-socket-type"); + checkAndGetLeaf(result, interfaces_config, "interfaces"); + checkAndGetLeaf(result, interfaces_config, "outbound-interface"); + checkAndGetLeaf(result, interfaces_config, "re-detect"); + checkAndGetLeaf(result, interfaces_config, "service-sockets-max-retries"); + checkAndGetLeaf(result, interfaces_config, "service-sockets-require-all"); + checkAndGetLeaf(result, interfaces_config, "service-sockets-retry-wait-time"); + + checkAndGetAndJsonifyLeaf(result, interfaces_config, "user-context"); + } + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorConfig::getServerKeaDhcpCommon(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + checkAndGetLeaf(result, data_node, "allocator"); + checkAndGetLeaf(result, data_node, "cache-max-age"); + checkAndGetLeaf(result, data_node, "cache-threshold"); + checkAndGetLeaf(result, data_node, "calculate-tee-times"); + checkAndGetLeaf(result, data_node, "dhcp4o6-port"); + checkAndGetLeaf(result, data_node, "ddns-generated-prefix"); + checkAndGetLeaf(result, data_node, "ddns-override-client-update"); + checkAndGetLeaf(result, data_node, "ddns-override-no-update"); + checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix"); + checkAndGetLeaf(result, data_node, "ddns-replace-client-name"); + checkAndGetLeaf(result, data_node, "ddns-send-updates"); + checkAndGetLeaf(result, data_node, "ddns-ttl-percent"); + checkAndGetLeaf(result, data_node, "ddns-update-on-renew"); + checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution"); + checkAndGetLeaf(result, data_node, "decline-probation-period"); + checkAndGetLeaf(result, data_node, "early-global-reservations-lookup"); + checkAndGetLeaf(result, data_node, "host-reservation-identifiers"); + checkAndGetLeaf(result, data_node, "hostname-char-replacement"); + checkAndGetLeaf(result, data_node, "hostname-char-set"); + checkAndGetLeaf(result, data_node, "ip-reservations-unique"); + checkAndGetLeaf(result, data_node, "max-valid-lifetime"); + checkAndGetLeaf(result, data_node, "min-valid-lifetime"); + checkAndGetLeaf(result, data_node, "parked-packet-limit"); + checkAndGetLeaf(result, data_node, "rebind-timer"); + checkAndGetLeaf(result, data_node, "renew-timer"); + checkAndGetLeaf(result, data_node, "reservation-mode"); + checkAndGetLeaf(result, data_node, "reservations-global"); + checkAndGetLeaf(result, data_node, "reservations-in-subnet"); + checkAndGetLeaf(result, data_node, "reservations-lookup-first"); + checkAndGetLeaf(result, data_node, "reservations-out-of-pool"); + checkAndGetLeaf(result, data_node, "server-tag"); + checkAndGetLeaf(result, data_node, "statistic-default-sample-age"); + checkAndGetLeaf(result, data_node, "statistic-default-sample-count"); + checkAndGetLeaf(result, data_node, "store-extended-info"); + checkAndGetLeaf(result, data_node, "t1-percent"); + checkAndGetLeaf(result, data_node, "t2-percent"); + checkAndGetLeaf(result, data_node, "valid-lifetime"); + + checkAndGetAndJsonifyLeaf(result, data_node, "dhcp-queue-control"); + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr classes = getClasses(data_node); + if (classes && !classes->empty()) { + result->set("client-classes", classes); + } + + checkAndGet(result, data_node, "compatibility", + [&](DataNode const& node) -> ElementPtr const { + ElementPtr compatibility(Element::createMap()); + checkAndGetLeaf(compatibility, node, "ignore-rai-link-selection"); + checkAndGetLeaf(compatibility, node, "lenient-option-parsing"); + return compatibility; + }); + + checkAndGet(result, data_node, "config-control", + [&](DataNode const& node) -> ElementPtr const { + return getConfigControlKea(node); + }); + + checkAndGet(result, data_node, "control-socket", + [&](DataNode const& node) -> ElementPtr const { + return getControlSocket(node); + }); + + checkAndGet(result, data_node, "dhcp-ddns", + [&](DataNode const& node) -> ElementPtr const { + return getDdnsKea(node); + }); + + checkAndGet(result, data_node, "expired-leases-processing", + [&](DataNode const& node) -> ElementPtr const { + return getExpiredKea(node); + }); + + ConstElementPtr hooks = getHooksKea(data_node); + if (hooks && !hooks->empty()) { + result->set("hooks-libraries", hooks); + } + + ConstElementPtr const& hosts_databases(getDatabases(data_node, "hosts-database")); + if (hosts_databases && !hosts_databases->empty()) { + result->set("hosts-databases", hosts_databases); + } + + checkAndGet(result, data_node, "lease-database", + [&](DataNode const& node) -> ElementPtr const { + return getDatabase(node); + }); + + ConstElementPtr loggers = getLoggers(data_node); + if (loggers && !loggers->empty()) { + result->set("loggers", loggers); + } + + checkAndGet(result, data_node, "multi-threading", + [&](DataNode const& node) -> ElementPtr const { + ElementPtr multi_threading(Element::createMap()); + checkAndGetLeaf(multi_threading, node, "enable-multi-threading"); + checkAndGetLeaf(multi_threading, node, "packet-queue-size"); + checkAndGetLeaf(multi_threading, node, "thread-pool-size"); + return multi_threading; + }); + + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + ConstElementPtr defs = getOptionDefList(data_node); + if (defs) { + result->set("option-def", defs); + } + + ConstElementPtr hosts = getHosts(data_node); + if (hosts) { + result->set("reservations", hosts); + } + + ConstElementPtr networks = getSharedNetworks(data_node); + if (networks) { + result->set("shared-networks", networks); + } + + checkAndGet(result, data_node, "sanity-checks", + [&](DataNode const& node) -> ElementPtr const { + ElementPtr sanity_checks = Element::createMap(); + checkAndGetLeaf(sanity_checks, node, "extended-info-checks"); + checkAndGetLeaf(sanity_checks, node, "lease-checks"); + return sanity_checks; + }); + + return (result); +} + +ElementPtr +TranslatorConfig::getServerKeaDhcp4() { + string xpath = "/kea-dhcp4-server:config"; + optional<DataNode> config_optional; + try { + config_optional = findXPath(xpath); + } catch (NetconfError const&) { + return ElementPtr(); + } + DataNode const config(*config_optional); + ElementPtr result = getServerKeaDhcpCommon(config); + + // Handle DHCPv4 specific global parameters. + checkAndGetLeaf(result, config, "authoritative"); + checkAndGetLeaf(result, config, "boot-file-name"); + checkAndGetLeaf(result, config, "echo-client-id"); + checkAndGetLeaf(result, config, "match-client-id"); + checkAndGetLeaf(result, config, "next-server"); + checkAndGetLeaf(result, config, "offer-lifetime"); + checkAndGetLeaf(result, config, "server-hostname"); + + checkAndGet(result, config, "compatibility", + [&](DataNode const& node) -> ElementPtr const { + // If it exists, add to the existing compatibility map created in getServerKeaDhcpCommon. + ConstElementPtr const_compatibility(result->get("compatibility")); + ElementPtr compatibility; + if (const_compatibility) { + compatibility = copy(const_compatibility); + } else { + compatibility = Element::createMap(); + } + + checkAndGetLeaf(compatibility, node, "exclude-first-last-24"); + checkAndGetLeaf(compatibility, node, "ignore-dhcp-server-identifier"); + return compatibility; + }); + + // Handle interfaces. + ElementPtr interfaces_config(getInterfacesKea(config)); + if (interfaces_config) { + result->set("interfaces-config", interfaces_config); + } + + // Handle subnets. + ConstElementPtr subnets = getSubnets(config); + if (subnets) { + result->set("subnet4", subnets); + } + + return (result); +} + +ElementPtr +TranslatorConfig::getServerKeaDhcp6() { + string xpath = "/kea-dhcp6-server:config"; + optional<DataNode> config_optional; + try { + config_optional = findXPath(xpath); + } catch (NetconfError const&) { + return ElementPtr(); + } + DataNode const config(*config_optional); + ElementPtr result = getServerKeaDhcpCommon(config); + + // Handle DHCPv6 specific global parameters. + checkAndGetLeaf(result, config, "data-directory"); + checkAndGetLeaf(result, config, "mac-sources"); + checkAndGetLeaf(result, config, "max-preferred-lifetime"); + checkAndGetLeaf(result, config, "min-preferred-lifetime"); + checkAndGetLeaf(result, config, "pd-allocator"); + checkAndGetLeaf(result, config, "preferred-lifetime"); + checkAndGetLeaf(result, config, "relay-supplied-options"); + + // Handle interfaces. + ElementPtr interfaces_config(getInterfacesKea(config)); + if (interfaces_config) { + result->set("interfaces-config", interfaces_config); + } + + // Handle server-id. + optional<DataNode> const& server_id_optional(config.findPath("server-id")); + if (server_id_optional) { + DataNode const server_id(*server_id_optional); + ElementPtr server_id_map(Element::createMap()); + checkAndGetLeaf(server_id_map, server_id, "type"); + checkAndGetLeaf(server_id_map, server_id, "identifier"); + checkAndGetLeaf(server_id_map, server_id, "time"); + checkAndGetLeaf(server_id_map, server_id, "htype"); + checkAndGetLeaf(server_id_map, server_id, "enterprise-id"); + checkAndGetLeaf(server_id_map, server_id, "persist"); + checkAndGetAndJsonifyLeaf(server_id_map, server_id, "user-context"); + if (!server_id_map->empty()) { + result->set("server-id", server_id_map); + } + } + + // Handle subnets. + ConstElementPtr subnets = getSubnets(config); + if (subnets) { + result->set("subnet6", subnets); + } + + return (result); +} + +void +TranslatorConfig::setConfig(ElementPtr 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 (Error const& ex) { + isc_throw(NetconfError, + "setting config '" << elem->str() + << "': " << ex.what()); + } +} + +void +TranslatorConfig::delConfigIetf6() { + deleteItem("/" + 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() { + deleteItem("/" + 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(string const& xpath, + ConstElementPtr elem) { + checkAndSetLeaf(elem, xpath, "allocator", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-ttl-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "dhcp4o6-port", LeafBaseType::Uint16); + checkAndSetLeaf(elem, xpath, "decline-probation-period", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ip-reservations-unique", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "parked-packet-limit", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum); + checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-lookup-first", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "server-tag", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32); + + checkAndSetLeafList(elem, xpath, "host-reservation-identifiers", LeafBaseType::Enum); + + checkAndStringifyAndSetLeaf(elem, xpath, "dhcp-queue-control"); + + checkAndSetUserContext(elem, xpath); + + ConstElementPtr classes = elem->get("client-classes"); + if (classes && !classes->empty()) { + setClasses(xpath, classes); + } + + ConstElementPtr compatibility(elem->get("compatibility")); + if (compatibility) { + checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-rai-link-selection", LeafBaseType::Bool); + checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", LeafBaseType::Bool); + } + + ConstElementPtr config_ctrl = elem->get("config-control"); + if (config_ctrl && !config_ctrl->empty()) { + checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32); + ConstElementPtr config_databases = config_ctrl->get("config-databases"); + if (config_databases && !config_databases->empty()) { + setDatabases(xpath + "/config-control/config-database", config_databases); + } + } + + ConstElementPtr socket = elem->get("control-socket"); + if (socket && !socket->empty()) { + setControlSocket(xpath + "/control-socket", socket); + } + + ConstElementPtr ddns = elem->get("dhcp-ddns"); + if (ddns) { + string const ddns_xpath(xpath + "/dhcp-ddns"); + checkAndSetLeaf(ddns, ddns_xpath, "enable-updates", LeafBaseType::Bool); + checkAndSetLeaf(ddns, ddns_xpath, "generated-prefix", LeafBaseType::String); + checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-replacement", LeafBaseType::String); + checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-set", LeafBaseType::String); + checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", LeafBaseType::Uint32); + checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", LeafBaseType::Enum); + checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", LeafBaseType::Enum); + checkAndSetLeaf(ddns, ddns_xpath, "override-client-update", LeafBaseType::Bool); + checkAndSetLeaf(ddns, ddns_xpath, "override-no-update", LeafBaseType::Bool); + checkAndSetLeaf(ddns, ddns_xpath, "qualifying-suffix", LeafBaseType::String); + checkAndSetLeaf(ddns, ddns_xpath, "replace-client-name", LeafBaseType::Enum); + checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", LeafBaseType::String); + checkAndSetLeaf(ddns, ddns_xpath, "sender-port", LeafBaseType::Uint16); + checkAndSetLeaf(ddns, ddns_xpath, "server-ip", LeafBaseType::String); + checkAndSetLeaf(ddns, ddns_xpath, "server-port", LeafBaseType::Uint16); + checkAndSetUserContext(ddns, ddns_xpath); + } + + ConstElementPtr expired = elem->get("expired-leases-processing"); + if (expired) { + string const expired_xpath(xpath + "/expired-leases-processing"); + checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", LeafBaseType::Uint32); + checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", LeafBaseType::Uint32); + checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", LeafBaseType::Uint32); + checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", LeafBaseType::Uint32); + checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", LeafBaseType::Uint32); + checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", LeafBaseType::Uint32); + } + + ConstElementPtr hook_libs = elem->get("hooks-libraries"); + if (hook_libs) { + for (ElementPtr const& lib : hook_libs->listValue()) { + ConstElementPtr name = lib->get("library"); + if (!name) { + continue; + } + ostringstream hook_lib; + hook_lib << xpath << "/hook-library[library='" + << name->stringValue() << "']"; + string const hook_xpath(hook_lib.str()); + setItem(hook_xpath, ElementPtr(), LeafBaseType::Unknown); + checkAndStringifyAndSetLeaf(lib, hook_xpath, "parameters"); + } + } + + ConstElementPtr hosts_databases = elem->get("hosts-databases"); + if (hosts_databases && !hosts_databases->empty()) { + setDatabases(xpath + "/hosts-database", hosts_databases); + } + + ConstElementPtr database = elem->get("lease-database"); + if (database && !database->empty()) { + setDatabase(xpath + "/lease-database", database); + } + + ConstElementPtr loggers = elem->get("loggers"); + if (loggers) { + setLoggers(xpath, loggers); + } + + ConstElementPtr multi_threading(elem->get("multi-threading")); + if (multi_threading) { + string const mt_xpath(xpath + "/multi-threading"); + checkAndSetLeaf(multi_threading, mt_xpath, "enable-multi-threading", LeafBaseType::Bool); + checkAndSetLeaf(multi_threading, mt_xpath, "packet-queue-size", LeafBaseType::Uint32); + checkAndSetLeaf(multi_threading, mt_xpath, "thread-pool-size", LeafBaseType::Uint32); + } + + ConstElementPtr options = elem->get("option-data"); + if (options && !options->empty()) { + setOptionDataList(xpath, options); + } + + ConstElementPtr defs = elem->get("option-def"); + if (defs && !defs->empty()) { + setOptionDefList(xpath, defs); + } + + ConstElementPtr hosts = elem->get("reservations"); + if (hosts && !hosts->empty()) { + setHosts(xpath, hosts); + } + + ConstElementPtr sanity = elem->get("sanity-checks"); + if (sanity) { + checkAndSetLeaf(sanity, xpath + "/sanity-checks", "extended-info-checks", LeafBaseType::Enum); + checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum); + } + + ConstElementPtr networks = elem->get("shared-networks"); + if (networks && !networks->empty()) { + setSharedNetworks(xpath, networks); + } +} + +void +TranslatorConfig::setServerKeaDhcp4(ConstElementPtr elem) { + string xpath = "/kea-dhcp4-server:config"; + + setServerKeaDhcpCommon(xpath, elem); + + checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "echo-client-id", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String); + + ConstElementPtr compatibility(elem->get("compatibility")); + if (compatibility) { + checkAndSetLeaf(compatibility, xpath + "/compatibility", "exclude-first-last-24", LeafBaseType::Bool); + checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-dhcp-server-identifier", LeafBaseType::Bool); + } + + ConstElementPtr if_config = elem->get("interfaces-config"); + if (if_config) { + string const if_cfg_xpath(xpath + "/interfaces-config"); + checkAndSetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type", LeafBaseType::Enum); + checkAndSetLeaf(if_config, if_cfg_xpath, "outbound-interface", LeafBaseType::Enum); + checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32); + checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool); + checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32); + checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool); + checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String); + checkAndSetUserContext(if_config, if_cfg_xpath); + } + + ConstElementPtr subnets = elem->get("subnet4"); + if (subnets) { + setSubnets(xpath, subnets); + } +} + +void +TranslatorConfig::setServerKeaDhcp6(ConstElementPtr elem) { + string xpath = "/kea-dhcp6-server:config"; + + setServerKeaDhcpCommon(xpath, elem); + + checkAndSetLeaf(elem, xpath, "data-directory", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "pd-allocator", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); + + checkAndSetLeafList(elem, xpath, "mac-sources", LeafBaseType::String); + checkAndSetLeafList(elem, xpath, "relay-supplied-options", LeafBaseType::String); + + ConstElementPtr if_config = elem->get("interfaces-config"); + if (if_config) { + string const if_cfg_xpath(xpath + "/interfaces-config"); + checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32); + checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool); + checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32); + checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool); + checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String); + checkAndSetUserContext(if_config, if_cfg_xpath); + } + + ConstElementPtr server_id = elem->get("server-id"); + if (server_id) { + string const srv_id_xpath(xpath + "/server-id"); + checkAndSetLeaf(server_id, srv_id_xpath, "type", LeafBaseType::Enum); + checkAndSetLeaf(server_id, srv_id_xpath, "identifier", LeafBaseType::String); + checkAndSetLeaf(server_id, srv_id_xpath, "time", LeafBaseType::Uint32); + checkAndSetLeaf(server_id, srv_id_xpath, "htype", LeafBaseType::Uint16); + checkAndSetLeaf(server_id, srv_id_xpath, "enterprise-id", LeafBaseType::Uint32); + checkAndSetLeaf(server_id, srv_id_xpath, "persist", LeafBaseType::Bool); + checkAndSetUserContext(server_id, srv_id_xpath); + } + + ConstElementPtr subnets = elem->get("subnet6"); + if (subnets) { + setSubnets(xpath, subnets); + } +} + +} // 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..cbdff25 --- /dev/null +++ b/src/lib/yang/translator_config.h @@ -0,0 +1,556 @@ +// 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_class.h> +#include <yang/translator_control_socket.h> +#include <yang/translator_database.h> +#include <yang/translator_logger.h> +#include <yang/translator_shared_network.h> + +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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorConfig() = default; + + /// @brief Translate the whole DHCP server configuration from YANG to JSON. + /// + /// @return JSON representation of the config. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getConfig(); + + /// @brief Translate and set the DHCP server configuration from JSON to YANG. + /// + /// Null elem argument removes the config containers. + /// + /// @param elem The JSON element. + void setConfig(isc::data::ElementPtr 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 NetconfError 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 NetconfError when sysrepo raises an error. + isc::data::ElementPtr getConfigKea4(); + + /// @brief getConfig for kea-dhcp6-server. + /// + /// @return JSON representation of the config. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getConfigKea6(); + + /// @brief getServer common part for kea-dhcp[46]-server:config. + /// + /// @param data_node the YANG node representing the server configuration + /// + /// @return JSON representation of the server. + isc::data::ElementPtr getServerKeaDhcpCommon(libyang::DataNode const& data_node); + + /// @brief getServer for kea-dhcp4-server:config. + /// + /// @return JSON representation of the config. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getServerKeaDhcp4(); + + /// @brief getServer for kea-dhcp6-server:config. + /// + /// @return JSON representation of the config. + /// @throw NetconfError 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(libyang::DataNode const& data_node); + + /// @brief Retrieves hooks configuration from sysrepo. + /// + /// @param data_node the YANG node representing the hook libraries + /// + /// @return ElementList with hooks configuration. + isc::data::ElementPtr getHooksKea(libyang::DataNode const& data_node); + + /// @brief Retrieves expired leases processing parameters from sysrepo. + /// + /// @param data_node the YANG node representing the configuration for expired lease processing + /// + /// @return ElementList with expired leases configuration. + isc::data::ElementPtr getExpiredKea(libyang::DataNode const& data_node); + + /// @brief Retrieves DDNS configuration from sysrepo + /// + /// @param data_node the YANG node representing dhcp-ddns configuration + /// + /// @return ElementList with dhcp-ddns configuration. + isc::data::ElementPtr getDdnsKea(libyang::DataNode const& data_node); + + /// @brief Retrieves configuration control from sysrepo. + /// + /// @param data_node the YANG node representing configuration control + /// + /// @return ElementMap with configuration control. + isc::data::ElementPtr getConfigControlKea(libyang::DataNode const& data_node); + + /// @brief Retrieves interfaces configuration from sysrepo. + /// + /// @param data_node the YANG node representing the interfaces configuration + /// + /// @return ElementMap with configuration control. + isc::data::ElementPtr getInterfacesKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorConfig + +} // namespace yang +} // 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..2d44b2f --- /dev/null +++ b/src/lib/yang/translator_control_socket.cc @@ -0,0 +1,97 @@ +// 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_control_socket.h> +#include <yang/yang_models.h> + +#include <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorControlSocket::TranslatorControlSocket(Session session, + const string& model) + : Translator(session, model) { +} + +ElementPtr +TranslatorControlSocket::getControlSocket(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER) || + (model_ == KEA_DHCP_DDNS) || + (model_ == KEA_CTRL_AGENT)) { + return (getControlSocketKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting control socket: " << ex.what()); + } + isc_throw(NotImplemented, + "getControlSocket not implemented for the model: " << model_); +} + +ElementPtr +TranslatorControlSocket::getControlSocketKea(DataNode const& data_node) { + ElementPtr result(Element::createMap()); + getMandatoryLeaf(result, data_node, "socket-name"); + getMandatoryLeaf(result, data_node, "socket-type"); + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorControlSocket::getControlSocketFromAbsoluteXpath(string const& xpath) { + try { + return getControlSocket(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +void +TranslatorControlSocket::setControlSocket(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting control socket '" << elem->str() + << "' at '" << xpath << "': " << ex.what()); + } +} + +void +TranslatorControlSocket::setControlSocketKea(string const& xpath, + ConstElementPtr elem) { + if (!elem) { + deleteItem(xpath); + return; + } + + setMandatoryLeaf(elem, xpath, "socket-name", LeafBaseType::String); + setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum); + checkAndSetUserContext(elem, xpath); +} + +} // 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..f2602c7 --- /dev/null +++ b/src/lib/yang/translator_control_socket.h @@ -0,0 +1,134 @@ +// 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_CONTROL_SOCKET_H +#define ISC_TRANSLATOR_CONTROL_SOCKET_H 1 + +#include <yang/translator.h> + +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 Translator { +public: + /// @brief Constructor. + /// + /// @param session Sysrepo session. + /// @param model Model name. + TranslatorControlSocket(sysrepo::Session session, + const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorControlSocket() = default; + + /// @brief Translate a control socket from YANG to JSON. + /// + /// @param data_node the YANG node representing the control socket + /// + /// @return the JSON representation of the control socket + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getControlSocket(libyang::DataNode const& data_node); + + /// @brief Translate a control socket from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getControlSocket(libyang::DataNode) as a scalable alternative. + /// + /// @param xpath The xpath of the control socket. + /// + /// @return JSON representation of the control socket + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getControlSocketFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the control socket + /// @return JSON representation of the control socket. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getControlSocketKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorControlSocket + +} // 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..e92f2ff --- /dev/null +++ b/src/lib/yang/translator_database.cc @@ -0,0 +1,213 @@ +// Copyright (C) 2018-2023 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 <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorDatabase::TranslatorDatabase(Session session, const string& model) + : Translator(session, model) { +} + +ElementPtr +TranslatorDatabase::getDatabase(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getDatabaseKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting database access: " << ex.what()); + } + isc_throw(NotImplemented, + "getDatabase not implemented for the model: " << model_); +} + +ElementPtr +TranslatorDatabase::getDatabaseFromAbsoluteXpath(string const& xpath) { + try { + return getDatabase(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorDatabase::getDatabaseKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryDivergingLeaf(result, data_node, "type", "database-type"); + + checkAndGetLeaf(result, data_node, "cert-file"); + checkAndGetLeaf(result, data_node, "cipher-list"); + checkAndGetLeaf(result, data_node, "connect-timeout"); + checkAndGetLeaf(result, data_node, "host"); + checkAndGetLeaf(result, data_node, "key-file"); + checkAndGetLeaf(result, data_node, "lfc-interval"); + checkAndGetLeaf(result, data_node, "max-reconnect-tries"); + checkAndGetLeaf(result, data_node, "max-row-errors"); + checkAndGetLeaf(result, data_node, "name"); + checkAndGetLeaf(result, data_node, "on-fail"); + checkAndGetLeaf(result, data_node, "password"); + checkAndGetLeaf(result, data_node, "persist"); + checkAndGetLeaf(result, data_node, "port"); + checkAndGetLeaf(result, data_node, "read-timeout"); + checkAndGetLeaf(result, data_node, "readonly"); + checkAndGetLeaf(result, data_node, "reconnect-wait-time"); + checkAndGetLeaf(result, data_node, "tcp-user-timeout"); + checkAndGetLeaf(result, data_node, "trust-anchor"); + checkAndGetLeaf(result, data_node, "user"); + checkAndGetLeaf(result, data_node, "write-timeout"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorDatabase::setDatabase(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting database access '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorDatabase::setDatabaseKea(string const& xpath, + ConstElementPtr elem, + bool skip) { + if (!elem) { + deleteItem(xpath); + return; + } + + checkAndSetLeaf(elem, xpath, "connect-timeout", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "cert-file", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "cipher-list", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "host", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "key-file", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "lfc-interval", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "max-reconnect-tries", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "max-row-errors", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "on-fail", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "password", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "persist", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "port", LeafBaseType::Uint16); + checkAndSetLeaf(elem, xpath, "readonly", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "read-timeout", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "reconnect-wait-time", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "tcp-user-timeout", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "trust-anchor", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "user", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "write-timeout", LeafBaseType::Uint32); + + checkAndSetUserContext(elem, xpath); + + if (!skip) { + setMandatoryDivergingLeaf(elem, xpath, "type", "database-type", LeafBaseType::String); + } +} + +TranslatorDatabases::TranslatorDatabases(Session session, + const string& model) + : Translator(session, model), + TranslatorDatabase(session, model) { +} + +ElementPtr +TranslatorDatabases::getDatabases(DataNode const& data_node, + string const& xpath) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getDatabasesKea(data_node, xpath)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting database accesses: " << ex.what()); + } + isc_throw(NotImplemented, + "getDatabases not implemented for the model: " << model_); +} + +ElementPtr +TranslatorDatabases::getDatabasesFromAbsoluteXpath(string const& xpath) { + try { + return getDatabases(findXPath(xpath), xpath); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorDatabases::getDatabasesKea(DataNode const& data_node, string const& xpath) { + return getList<TranslatorDatabase>(data_node, xpath, *this, + &TranslatorDatabase::getDatabase); +} + +void +TranslatorDatabases::setDatabases(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting database accesses '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorDatabases::setDatabasesKea(string const& xpath, + ConstElementPtr elem) { + if (!elem) { + deleteItem(xpath); + return; + } + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr database = elem->getNonConst(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..7480fa7 --- /dev/null +++ b/src/lib/yang/translator_database.h @@ -0,0 +1,243 @@ +// 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> + +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 Translator { +public: + /// @brief Constructor. + /// + /// @param session Sysrepo session. + /// @param model Model name. + TranslatorDatabase(sysrepo::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorDatabase() = default; + + /// @brief Translate a database access from YANG to JSON. + /// + /// @param data_node the YANG node representing the control socket + /// + /// @return the JSON representation of the database + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getDatabase(libyang::DataNode const& data_node); + + /// @brief Translate a database access from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getDatabase(libyang::DataNode) as a scalable alternative. + /// + /// @param xpath The xpath of the database. + /// + /// @return JSON representation of the database. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getDatabaseFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the database configuration + /// + /// @return JSON representation of the database + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getDatabaseKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorDatabase + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorDatabases() = default; + + /// @brief Translate database accesses from YANG to JSON. + /// + /// @param data_node the YANG node representing the databases + /// @param xpath the xpath of databases relative to {data_node} + /// + /// @return the JSON representation of the list of databases + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getDatabases(libyang::DataNode const& data_node, + std::string const& xpath); + + /// @brief Translate database accesses from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getDatabases(libyang::DataNode, std::string) as a scalable alternative. + /// + /// @param xpath The xpath of databases including the list name. + /// + /// @return JSON representation of databases. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getDatabasesFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the databases + /// @param xpath the xpath of databases relative to {data_node} + /// + /// @return JSON representation of databases. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getDatabasesKea(libyang::DataNode const& data_node, + std::string const& 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); +}; // TranslatorDatabases + +} // 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..7aa6fa4 --- /dev/null +++ b/src/lib/yang/translator_host.cc @@ -0,0 +1,215 @@ +// 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_host.h> +#include <yang/yang_models.h> + +#include <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorHost::TranslatorHost(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model) { +} + +ElementPtr +TranslatorHost::getHost(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getHostKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting host reservation:" + << ex.what()); + } + isc_throw(NotImplemented, + "getHost not implemented for the model: " << model_); +} + +ElementPtr +TranslatorHost::getHostFromAbsoluteXpath(string const& xpath) { + try { + return getHost(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorHost::getHostKea(DataNode const& data_node) { + ConstElementPtr id_type = getItem(data_node, "identifier-type"); + ConstElementPtr id = getItem(data_node, "identifier"); + if (!id_type || !id) { + isc_throw(MissingNode, "getHostKea requires both identifier and identifier-type"); + } + ElementPtr result = Element::createMap(); + result->set(id_type->stringValue(), id); + + checkAndGetLeaf(result, data_node, "client-classes"); + checkAndGetLeaf(result, data_node, "hostname"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + if (model_ == KEA_DHCP4_SERVER) { + checkAndGetLeaf(result, data_node, "boot-file-name"); + checkAndGetLeaf(result, data_node, "ip-address"); + checkAndGetLeaf(result, data_node, "next-server"); + checkAndGetLeaf(result, data_node, "server-hostname"); + } else { + checkAndGetLeaf(result, data_node, "ip-addresses"); + checkAndGetLeaf(result, data_node, "prefixes"); + } + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorHost::setHost(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting host reservation '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorHost::setHostKea(string const& xpath, ConstElementPtr elem) { + // Skip keys "identifier" and "identifier-type". + + checkAndSetLeaf(elem, xpath, "hostname", LeafBaseType::String); + + checkAndSetLeafList(elem, xpath, "client-classes", LeafBaseType::String); + + ConstElementPtr options = elem->get("option-data"); + if (options && !options->empty()) { + setOptionDataList(xpath, options); + } + + if (model_ == KEA_DHCP4_SERVER) { + checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ip-address", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String); + } else { + checkAndSetLeafList(elem, xpath, "ip-addresses", LeafBaseType::String); + checkAndSetLeafList(elem, xpath, "prefixes", LeafBaseType::String); + } + + // User context is supported in both kea-dhcp4-server and kea-dhcp6-server. + checkAndSetUserContext(elem, xpath); +} + +TranslatorHosts::TranslatorHosts(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model), + TranslatorHost(session, model) { +} + +ElementPtr +TranslatorHosts::getHosts(DataNode const& data_node) { + return getList<TranslatorHost>(data_node, "host", *this, + &TranslatorHost::getHost); +} + +ElementPtr +TranslatorHosts::getHostsFromAbsoluteXpath(string const& xpath) { + try { + return getHosts(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +void +TranslatorHosts::setHosts(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting host reservations '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorHosts::setHostsKea(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + string id_type = "unknown"; + ElementPtr host = elem->getNonConst(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..2236b14 --- /dev/null +++ b/src/lib/yang/translator_host.h @@ -0,0 +1,229 @@ +// 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_HOST_H +#define ISC_TRANSLATOR_HOST_H 1 + +#include <yang/translator_option_data.h> + +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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorHost() = default; + + /// @brief Translate a host reservation from YANG to JSON. + /// + /// @param data_node the YANG node representing the host reservation + /// + /// @return the JSON representation of the host reservation + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getHost(libyang::DataNode const& data_node); + + /// @brief Translate a host reservation from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getHost(libyang::DataNode) as a scalable alternative. + /// + /// @param xpath The xpath of the host reservation. + /// + /// @return JSON representation of the host reservation. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getHostFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the host reservation + /// + /// @return JSON representation of the host reservation. + isc::data::ElementPtr getHostKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorHost + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorHosts() = default; + + /// @brief Translate host reservations from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of host reservations + /// + /// @return the JSON representation of the list of host reservations + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getHosts(libyang::DataNode const& data_node); + + /// @brief Translate host reservations from YANG to JSON. + /// + /// @note This is a computationally expensive operation that makes a lookup in the sysrepo + /// datastore by calling Session::getData(). It should be used sparingly in production code, + /// mainly to get an initial data node to work with. It may be used at will in unit tests. + /// Use getHosts(libyang::DataNode) as a scalable alternative. + /// + /// @param xpath The xpath of the host reservation list. + /// + /// @return JSON representation of the host reservation list. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getHostsFromAbsoluteXpath(std::string const& 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); +}; // TranslatorHosts + +} // 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..bff43db --- /dev/null +++ b/src/lib/yang/translator_logger.cc @@ -0,0 +1,212 @@ +// 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_logger.h> +#include <yang/yang_models.h> + +#include <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorLogger::TranslatorLogger(Session session, const string& model) + : Translator(session, model) { +} + +ElementPtr +TranslatorLogger::getLogger(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER) || + (model_ == KEA_DHCP_DDNS) || + (model_ == KEA_CTRL_AGENT)) { + return (getLoggerKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting logger: " << ex.what()); + } + isc_throw(NotImplemented, + "getLogger not implemented for the model: " << model_); +} + +ElementPtr +TranslatorLogger::getLoggerKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "name"); + + checkAndGetLeaf(result, data_node, "debuglevel"); + checkAndGetLeaf(result, data_node, "severity"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr options = getOutputOptions(data_node); + if (options) { + result->set("output_options", options); + } + + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorLogger::getOutputOption(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "output"); + + checkAndGetLeaf(result, data_node, "flush"); + checkAndGetLeaf(result, data_node, "maxsize"); + checkAndGetLeaf(result, data_node, "maxver"); + checkAndGetLeaf(result, data_node, "pattern"); + + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorLogger::getOutputOptions(DataNode const& data_node) { + return getList(data_node, "output-option", *this, + &TranslatorLogger::getOutputOption); +} + +void +TranslatorLogger::setLogger(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting logger '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorLogger::setLoggerKea(string const& xpath, ConstElementPtr elem) { + // Skip key "name". + + checkAndSetLeaf(elem, xpath, "debuglevel", LeafBaseType::Uint8); + checkAndSetLeaf(elem, xpath, "severity", LeafBaseType::Enum); + checkAndSetUserContext(elem, xpath); + + ConstElementPtr options = elem->get("output_options"); + if (options && !options->empty()) { + setOutputOptions(xpath, options); + } +} + +void +TranslatorLogger::setOutputOption(string const& xpath, ConstElementPtr elem) { + // Keys are set by setting the list itself. + setItem(xpath, ElementPtr(), LeafBaseType::Unknown); + + checkAndSetLeaf(elem, xpath, "flush", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "maxsize", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "maxver", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "pattern", LeafBaseType::String); +} + +void +TranslatorLogger::setOutputOptions(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr option = elem->getNonConst(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(Session session, const string& model) + : Translator(session, model), + TranslatorLogger(session, model) { +} + +ConstElementPtr +TranslatorLoggers::getLoggers(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER) || + (model_ == KEA_DHCP_DDNS) || + (model_ == KEA_CTRL_AGENT)) { + return (getLoggersKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting loggers: " << ex.what()); + } + isc_throw(NotImplemented, + "getLoggers not implemented for the model: " << model_); +} + +ConstElementPtr +TranslatorLoggers::getLoggersFromAbsoluteXpath(string const& xpath) { + try { + return getLoggers(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorLoggers::getLoggersKea(DataNode const& data_node) { + return getList<TranslatorLogger>(data_node, "logger", *this, + &TranslatorLogger::getLogger); +} + +void +TranslatorLoggers::setLoggers(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting loggers '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorLoggers::setLoggersKea(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr logger = elem->getNonConst(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..6d54dc4 --- /dev/null +++ b/src/lib/yang/translator_logger.h @@ -0,0 +1,233 @@ +// 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_LOGGER_H +#define ISC_TRANSLATOR_LOGGER_H 1 + +#include <yang/translator.h> + +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 Translator { +public: + /// @brief Constructor. + /// + /// @param session Sysrepo session. + /// @param model Model name. + TranslatorLogger(sysrepo::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorLogger() = default; + + /// @brief Translate a logger from YANG to JSON. + /// + /// @param data_node the YANG node representing the logger configuration + /// + /// @return JSON representation of the logger. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getLogger(libyang::DataNode const& data_node); + + /// @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 Translate an output option from YANG to JSON. + /// + /// @param data_node the YANG node representing the output option + /// + /// @return JSON representation of the output option. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOutputOption(libyang::DataNode const& data_node); + + /// @brief Translate output options from YANG to JSON. + /// + /// @param data_node the YANG node representing output options + /// + /// @return JSON representation of output options. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOutputOptions(libyang::DataNode const& data_node); + + /// @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 data_node the YANG node representing the logger configuration + /// + /// @return JSON representation of the logger. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getLoggerKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorLogger + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorLoggers() = default; + + /// @brief Translate loggers from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of loggers + /// + /// @return the JSON representation of the list of loggers + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getLoggers(libyang::DataNode const& data_node); + + /// @brief Translate loggers from YANG to JSON. + /// + /// @param xpath The xpath of loggers. + /// + /// @return JSON representation of loggers. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getLoggersFromAbsoluteXpath(std::string const& xpath); + + /// @brief Translate and set loggers 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 data_node the YANG node representing loggers configuration + /// + /// @return JSON representation of loggers. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getLoggersKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorLoggers + +} // 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..5826869 --- /dev/null +++ b/src/lib/yang/translator_option_data.cc @@ -0,0 +1,180 @@ +// Copyright (C) 2018-2023 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 <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorOptionData::TranslatorOptionData(Session session, + const string& model) + : Translator(session, model) { +} + +ElementPtr +TranslatorOptionData::getOptionData(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getOptionDataKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting option data:" + << ex.what()); + } + isc_throw(NotImplemented, + "getOptionData not implemented for the model: " << model_); +} + +ElementPtr +TranslatorOptionData::getOptionDataFromAbsoluteXpath(string const& xpath) { + try { + return getOptionData(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorOptionData::getOptionDataKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "code"); + getMandatoryLeaf(result, data_node, "space"); + + checkAndGetLeaf(result, data_node, "always-send"); + checkAndGetLeaf(result, data_node, "csv-format"); + checkAndGetLeaf(result, data_node, "data"); + checkAndGetLeaf(result, data_node, "name"); + checkAndGetLeaf(result, data_node, "never-send"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorOptionData::setOptionData(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting option data '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorOptionData::setOptionDataKea(string const& xpath, + ConstElementPtr elem) { + // Skip keys "code" and "space". + + checkAndSetLeaf(elem, xpath, "always-send", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "csv-format", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "data", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "never-send", LeafBaseType::Bool); + + checkAndSetUserContext(elem, xpath); +} + +TranslatorOptionDataList::TranslatorOptionDataList(Session session, + const string& model) + : Translator(session, model), + TranslatorOptionData(session, model) { +} + +ConstElementPtr +TranslatorOptionDataList::getOptionDataList(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getOptionDataListKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting option data list:" + << ex.what()); + } + isc_throw(NotImplemented, + "getOptionDataList not implemented for the model: " << model_); +} + +ConstElementPtr +TranslatorOptionDataList::getOptionDataListFromAbsoluteXpath(string const& xpath) { + try { + return getOptionDataList(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ConstElementPtr +TranslatorOptionDataList::getOptionDataListKea(DataNode const& data_node) { + return getList<TranslatorOptionData>(data_node, "option-data", *this, + &TranslatorOptionData::getOptionData); +} + +void +TranslatorOptionDataList::setOptionDataList(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting option data list '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorOptionDataList::setOptionDataListKea(string const& xpath, + ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr option = elem->getNonConst(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..d8d4f60 --- /dev/null +++ b/src/lib/yang/translator_option_data.h @@ -0,0 +1,195 @@ +// Copyright (C) 2018-2023 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> + +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>, +/// "never-send": <never 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 never-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, +/// "never-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 +/// /kea-dhcp6-server:config/ +/// option-data[code='100'][space='dns']/never-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 Translator { +public: + /// @brief Constructor. + /// + /// @param session Sysrepo session. + /// @param model Model name. + TranslatorOptionData(sysrepo::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorOptionData() = default; + + /// @brief Translate an option data from YANG to JSON. + /// + /// @param data_node the YANG node representing the option data + /// + /// @return the JSON representation of the option data + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOptionData(libyang::DataNode const& data_node); + + /// @brief Translate an option data from YANG to JSON. + /// + /// @param xpath The xpath of the option data. + /// + /// @return JSON representation of the option data. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOptionDataFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the option data + /// + /// @return JSON representation of the option data. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOptionDataKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorOptionData + +/// @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::Session session, + const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorOptionDataList() = default; + + /// @brief Translate option data list from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of option data + /// + /// @return the JSON representation of the list of option data + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const& data_node); + + /// @brief Translate option data list from YANG to JSON. + /// + /// @param xpath The xpath of the option data list. + /// + /// @return the JSON representation of the list of option data + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getOptionDataListFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the list of option data + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getOptionDataListKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorOptionDataList + +} // 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..70bdd9f --- /dev/null +++ b/src/lib/yang/translator_option_def.cc @@ -0,0 +1,182 @@ +// 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_option_def.h> +#include <yang/yang_models.h> + +#include <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorOptionDef::TranslatorOptionDef(Session session, + const string& model) + : Translator(session, model) { +} + +ElementPtr +TranslatorOptionDef::getOptionDef(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getOptionDefKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting option definition:" + << ex.what()); + } + isc_throw(NotImplemented, + "getOptionDef not implemented for the model: " << model_); +} + +ElementPtr +TranslatorOptionDef::getOptionDefFromAbsoluteXpath(string const& xpath) { + try { + return getOptionDef(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorOptionDef::getOptionDefKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "code"); + getMandatoryLeaf(result, data_node, "name"); + getMandatoryLeaf(result, data_node, "space"); + getMandatoryLeaf(result, data_node, "type"); + + checkAndGetLeaf(result, data_node, "array"); + checkAndGetLeaf(result, data_node, "encapsulate"); + checkAndGetLeaf(result, data_node, "record-types"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorOptionDef::setOptionDef(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting option definition '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorOptionDef::setOptionDefKea(string const& xpath, + ConstElementPtr elem) { + // Skip keys "code" and "space". + + setMandatoryLeaf(elem, xpath, "name", LeafBaseType::String); + setMandatoryLeaf(elem, xpath, "type", LeafBaseType::String); + + checkAndSetLeaf(elem, xpath, "array", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "encapsulate", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "record-types", LeafBaseType::String); + + checkAndSetUserContext(elem, xpath); +} + +TranslatorOptionDefList::TranslatorOptionDefList(Session session, + const string& model) + : Translator(session, model), + TranslatorOptionDef(session, model) { +} + +ConstElementPtr +TranslatorOptionDefList::getOptionDefList(DataNode const& data_node) { + try { + if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getOptionDefListKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting option definition list:" + << ex.what()); + } + isc_throw(NotImplemented, + "getOptionDefList not implemented for the model: " << model_); +} + +ConstElementPtr +TranslatorOptionDefList::getOptionDefListFromAbsoluteXpath(string const& xpath) { + try { + return getOptionDefList(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ConstElementPtr +TranslatorOptionDefList::getOptionDefListKea(DataNode const& data_node) { + return getList<TranslatorOptionDef>(data_node, "option-def", *this, + &TranslatorOptionDefList::getOptionDef); +} + +void +TranslatorOptionDefList::setOptionDefList(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting option definition list '" + << elem->str() << "' : " << ex.what()); + } +} + +void +TranslatorOptionDefList::setOptionDefListKea(string const& xpath, + ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr def = elem->getNonConst(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..b36ba47 --- /dev/null +++ b/src/lib/yang/translator_option_def.h @@ -0,0 +1,198 @@ +// 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_OPTION_DEF_H +#define ISC_TRANSLATOR_OPTION_DEF_H 1 + +#include <yang/translator.h> + +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 Translator { +public: + /// @brief Constructor. + /// + /// @param session Sysrepo session. + /// @param model Model name. + TranslatorOptionDef(sysrepo::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorOptionDef() = default; + + /// @brief Translate an option definition from YANG to JSON. + /// + /// @param data_node the YANG node representing the option definition + /// + /// @return the JSON representation of the option definition + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOptionDef(libyang::DataNode const& data_node); + + /// @brief Translate an option definition from YANG to JSON. + /// + /// @param xpath The xpath of the option definition. + /// + /// @return JSON representation of the option definition. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getOptionDefFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the option definition + /// + /// @return JSON representation of the option definition. + /// + /// @throw NetconfError when sysrepo raises an error. + /// @throw BadValue on option definition without name or type. + isc::data::ElementPtr getOptionDefKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorOptionDef + +// @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::Session session, + const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorOptionDefList() = default; + + /// @brief Translate option definition list from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of option definitions + /// + /// @return the JSON representation of the list of option definitions + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getOptionDefList(libyang::DataNode const& data_node); + + /// @brief Translate option definition list from YANG to JSON. + /// + /// @param xpath The xpath of the option definition list. + /// + /// @return JSON representation of the list of option definitions + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getOptionDefListFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the list of option definitions + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ConstElementPtr getOptionDefListKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorOptionDefList + +} // 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..d0f8880 --- /dev/null +++ b/src/lib/yang/translator_pd_pool.cc @@ -0,0 +1,320 @@ +// 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_pd_pool.h> +#include <yang/yang_models.h> + +#include <boost/lexical_cast.hpp> + +#include <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorPdPool::TranslatorPdPool(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model) { +} + +ElementPtr +TranslatorPdPool::getPdPool(DataNode const& data_node) { + try { + if (model_ == IETF_DHCPV6_SERVER) { + return (getPdPoolIetf6(data_node)); + } else if (model_ == KEA_DHCP6_SERVER) { + return (getPdPoolKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting pd-pool:" + << ex.what()); + } + isc_throw(NotImplemented, + "getPdPool not implemented for the model: " << model_); +} + +ElementPtr +TranslatorPdPool::getPdPoolFromAbsoluteXpath(string const& xpath) { + try { + return getPdPool(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorPdPool::getPdPoolIetf6(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + ConstElementPtr pref = getItem(data_node, "prefix"); + if (!pref) { + isc_throw(MissingNode, "getPdPoolIetf6: prefix is required"); + } + const string& prefix = pref->stringValue(); + size_t slash = prefix.find("/"); + if (slash == string::npos) { + isc_throw(MissingNode, + "getPdPoolIetf6: no '/' in prefix '" << prefix << "'"); + } + const string& address = prefix.substr(0, slash); + if (address.empty()) { + isc_throw(MissingNode, + "getPdPoolIetf6: malformed prefix '" << prefix << "'"); + } + result->set("prefix", Element::create(address)); + + // Silly: the prefix length is specified twice... + getMandatoryDivergingLeaf(result, data_node, "prefix-len", "prefix-length"); + + checkAndGetLeaf(result, data_node, "preferred-lifetime"); + checkAndGetLeaf(result, data_node, "client-class"); + checkAndGetLeaf(result, data_node, "valid-lifetime"); + + checkAndGetDivergingLeaf(result, data_node, "rebind-timer", "rebind-time"); + checkAndGetDivergingLeaf(result, data_node, "renew-timer", "renew-time"); + + // no require-client-classes nor user-context. + // Skip max-pd-space-utilization. + // Skip rapid-commit. + // @todo: option-data + + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorPdPool::getPdPoolKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + ConstElementPtr pref = getItem(data_node, "prefix"); + if (!pref) { + isc_throw(MissingNode, "getPdPoolKea: no prefix defined"); + } + 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(data_node, "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 << "'"); + } + } + + checkAndGetLeaf(result, data_node, "client-class"); + checkAndGetLeaf(result, data_node, "delegated-len"); + checkAndGetLeaf(result, data_node, "require-client-classes"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorPdPool::setPdPool(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting pd-pool '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorPdPool::setPdPoolIetf6(string const& 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()), LeafBaseType::String); + setItem(xpath + "/prefix-length", length, LeafBaseType::Uint8); + + checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32); + + checkAndSetDivergingLeaf(elem, xpath, "rebind-timer", "rebind-time", LeafBaseType::Uint32); + checkAndSetDivergingLeaf(elem, xpath, "renew-timer", "renew-time", LeafBaseType::Uint32); + + // Set max pd space utilization to disabled. + setItem(xpath + "/max-pd-space-utilization", Element::create("disabled"), + LeafBaseType::Enum); + + // Skip rapid-commit. + // @todo: option-data +} + +void +TranslatorPdPool::setPdPoolKea(string const& xpath, ConstElementPtr elem) { + // Keys are set by setting the list itself. + setItem(xpath, ElementPtr(), LeafBaseType::Unknown); + + checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "delegated-len", LeafBaseType::Uint8); + + checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String); + + checkAndSetUserContext(elem, xpath); + + ConstElementPtr xprefix = elem->get("excluded-prefix"); + ConstElementPtr xlen = elem->get("excluded-prefix-len"); + if (xprefix && xlen) { + ostringstream xpref; + xpref << xprefix->stringValue() << "/" << xlen->intValue(); + setItem(xpath + "/excluded-prefix", Element::create(xpref.str()), LeafBaseType::String); + } + ConstElementPtr options = elem->get("option-data"); + if (options && !options->empty()) { + setOptionDataList(xpath, options); + } +} + +TranslatorPdPools::TranslatorPdPools(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model), + TranslatorPdPool(session, model) { +} + +ElementPtr +TranslatorPdPools::getPdPools(DataNode const& data_node) { + try { + if ((model_ == IETF_DHCPV6_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getPdPoolsCommon(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting pd-pools:" + << ex.what()); + } + isc_throw(NotImplemented, + "getPdPools not implemented for the model: " << model_); +} + +ElementPtr +TranslatorPdPools::getPdPoolsFromAbsoluteXpath(string const& xpath) { + try { + return getPdPools(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorPdPools::getPdPoolsCommon(DataNode const& data_node) { + return getList<TranslatorPdPool>(data_node, "pd-pool", *this, + &TranslatorPdPool::getPdPool); +} + +void +TranslatorPdPools::setPdPools(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting pools '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorPdPools::setPdPoolsId(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr pool = elem->getNonConst(i); + ostringstream prefix; + prefix << xpath << "/pd-pool[pool-id='" << i << "']"; + setPdPool(prefix.str(), pool); + } +} + +void +TranslatorPdPools::setPdPoolsPrefix(string const& xpath, + ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr pool = elem->getNonConst(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..a7d0ec0 --- /dev/null +++ b/src/lib/yang/translator_pd_pool.h @@ -0,0 +1,256 @@ +// 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_PD_POOL_H +#define ISC_TRANSLATOR_PD_POOL_H 1 + +#include <yang/translator_option_data.h> + +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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorPdPool() = default; + + /// @brief Translate a pd-pool from YANG to JSON. + /// + /// @param data_node the YANG node representing the PD pool + /// + /// @return the JSON representation of the PD pool + /// + /// @throw BadValue on pd-pool without well formed prefix. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPool(libyang::DataNode const& data_node); + + /// @brief Translate a pd-pool from YANG to JSON. + /// + /// @param xpath The xpath of the pd-pool. + /// + /// @return JSON representation of the pd-pool. + /// + /// @throw BadValue on pd-pool without well formed prefix. + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPoolFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the PD pool + /// + /// @return JSON representation of the pd-pool. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPoolIetf6(libyang::DataNode const& data_node); + + /// @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 data_node the YANG node representing the PD pool + /// + /// @return JSON representation of the pd-pool. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPoolKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorPdPool + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorPdPools() = default; + + /// @brief Translate pd-pools from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of PD pools + /// + /// @return the JSON representation of the list of PD pools + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPools(libyang::DataNode const& data_node); + + /// @brief Translate pd-pools from YANG to JSON. + /// + /// @param xpath The xpath of the pd-pool list. + /// + /// @return the JSON representation of the list of PD pools + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPoolsFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the list of PD pools + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPdPoolsCommon(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorPdPools + +} // 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..f1bb8a3 --- /dev/null +++ b/src/lib/yang/translator_pool.cc @@ -0,0 +1,327 @@ +// Copyright (C) 2018-2023 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/addr_utilities.h> +#include <asiolink/io_address.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 libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorPool::TranslatorPool(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model) { +} + +ElementPtr +TranslatorPool::getPool(DataNode const& data_node) { + try { + if (model_ == IETF_DHCPV6_SERVER) { + return (getPoolIetf6(data_node)); + } else if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getPoolKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting pool:" + << ex.what()); + } + isc_throw(NotImplemented, + "getPool not implemented for the model: " << model_); +} + +ElementPtr +TranslatorPool::getPoolFromAbsoluteXpath(string const& xpath) { + try { + return getPool(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorPool::getPoolIetf6(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryDivergingLeaf(result, data_node, "pool", "pool-prefix"); + + checkAndGetLeaf(result, data_node, "client-class"); + checkAndGetLeaf(result, data_node, "preferred-lifetime"); + checkAndGetLeaf(result, data_node, "valid-lifetime"); + + checkAndGetDivergingLeaf(result, data_node, "rebind-timer", "rebind-time"); + checkAndGetDivergingLeaf(result, data_node, "renew-timer", "renew-time"); + + // Skip max-addr-count. + // Skip pool-id which exists but is not used. + // Skip rapid-commit. + // Skip start-address - end-address as prefix form is mandatory? + // @todo: option-data + // No require-client-classes. + // No user-context. + + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorPool::getPoolKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + ConstElementPtr prefix = getItem(data_node, "prefix"); + if (prefix) { + result->set("pool", prefix); + } else { + ConstElementPtr start_addr = getItem(data_node, "start-address"); + ConstElementPtr end_addr = getItem(data_node, "end-address"); + if (!start_addr || !end_addr) { + isc_throw(MissingNode, "getPoolKea requires either prefix or " + "both start and end addresses"); + } + ostringstream range; + range << start_addr->stringValue() << " - " + << end_addr->stringValue(); + result->set("pool", Element::create(range.str())); + } + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + checkAndGetLeaf(result, data_node, "client-class"); + checkAndGetLeaf(result, data_node, "require-client-classes"); + + checkAndGetLeaf(result, data_node, "pool-id"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorPool::setPool(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting pool '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorPool::setPoolIetf6(string const& 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, LeafBaseType::String); + string addr = prefix.substr(0, prefix.find_first_of(" /")); + uint8_t plen = boost::lexical_cast<unsigned> + (prefix.substr(prefix.find_last_of(" /") + 1, string::npos)); + const IOAddress& base(addr); + setItem(xpath + "/start-address", + Element::create(firstAddrInPrefix(base, plen).toText()), + LeafBaseType::String); + setItem(xpath + "/end-address", + Element::create(lastAddrInPrefix(base, plen).toText()), + LeafBaseType::String); + + checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32); + + checkAndSetDivergingLeaf(elem, xpath, "rebind-timer", "rebind-time", LeafBaseType::Uint32); + checkAndSetDivergingLeaf(elem, xpath, "renew-timer", "renew-time", LeafBaseType::Uint32); + + // Set max address count to disabled. + setItem(xpath + "/max-address-count", + Element::create("disabled"), + LeafBaseType::Enum); + + // Skip max-addr-count. + // Skip rapid-commit. + // @todo: option-data +} + +void +TranslatorPool::setPoolKea(string const& xpath, ConstElementPtr elem) { + // Skip keys "start-address" and "end-address". + + ConstElementPtr pool = elem->get("pool"); + if (!pool) { + isc_throw(BadValue, "setPoolKea requires pool: " << elem->str()); + } + + // Keys are set by setting the list itself. + setItem(xpath, ElementPtr(), LeafBaseType::Unknown); + + checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String); + + checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String); + + checkAndSetLeaf(elem, xpath, "pool-id", LeafBaseType::Dec64); + + checkAndSetUserContext(elem, xpath); + + 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, LeafBaseType::String); + } + ConstElementPtr options = elem->get("option-data"); + if (options && !options->empty()) { + setOptionDataList(xpath, options); + } +} + +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(Session session, const string& model) + : Translator(session, model), + TranslatorOptionData(session, model), + TranslatorOptionDataList(session, model), + TranslatorPool(session, model) { +} + +ElementPtr +TranslatorPools::getPools(DataNode const& data_node) { + try { + if (model_ == IETF_DHCPV6_SERVER) { + return (getPoolsIetf(data_node)); + } else if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getPoolsKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting pools:" + << ex.what()); + } + isc_throw(NotImplemented, + "getPools not implemented for the model: " << model_); +} + +ElementPtr +TranslatorPools::getPoolsFromAbsoluteXpath(string const& xpath) { + try { + return getPools(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorPools::getPoolsIetf(DataNode const& data_node) { + return getList<TranslatorPool>(data_node, "address-pool", *this, + &TranslatorPool::getPool); +} + +ElementPtr +TranslatorPools::getPoolsKea(DataNode const& data_node) { + return getList<TranslatorPool>(data_node, "pool", *this, + &TranslatorPool::getPool); +} + +void +TranslatorPools::setPools(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting pools '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorPools::setPoolsById(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr pool = elem->getNonConst(i); + ostringstream prefix; + prefix << xpath << "/address-pool[pool-id='" << i << "']"; + setPool(prefix.str(), pool); + } +} + +void +TranslatorPools::setPoolsByAddresses(string const& xpath, + ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr pool = elem->getNonConst(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..90b9f35 --- /dev/null +++ b/src/lib/yang/translator_pool.h @@ -0,0 +1,277 @@ +// 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_POOL_H +#define ISC_TRANSLATOR_POOL_H 1 + +#include <yang/translator_option_data.h> + +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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorPool() = default; + + /// @brief Translate a pool from YANG to JSON. + /// + /// @param data_node the YANG node representing the pool + /// + /// @return the JSON representation of the pool + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPool(libyang::DataNode const& data_node); + + /// @brief Translate a pool from YANG to JSON. + /// + /// @param xpath The xpath of the pool. + /// + /// @return JSON representation of the pool. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPoolFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the pool configuration + /// + /// @return JSON representation of the pool. + /// + /// @throw BadValue on pool without prefix. + isc::data::ElementPtr getPoolIetf6(libyang::DataNode const& data_node); + + /// @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 data_node the YANG node representing the pool configuration + /// + /// @return JSON representation of the pool. + /// + /// @throw BadValue on a pool without prefix and start or end address. + isc::data::ElementPtr getPoolKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorPool + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorPools() = default; + + /// @brief Translate pools from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of pools + /// + /// @return the JSON representation of the list of pools + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPools(libyang::DataNode const& data_node); + + /// @brief Translate pools from YANG to JSON. + /// + /// @param xpath The xpath of the pool list. + /// + /// @return the JSON representation of the list of pools + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getPoolsFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the list of pools + /// + /// @return the JSON representation of the list of pools + isc::data::ElementPtr getPoolsIetf(libyang::DataNode const& data_node); + + /// @brief getPools for kea-dhcp[46]-server. + /// + /// @param data_node the YANG node representing the list of pools + /// + /// @return the JSON representation of the list of pools + isc::data::ElementPtr getPoolsKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorPools + +} // 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..0004496 --- /dev/null +++ b/src/lib/yang/translator_shared_network.cc @@ -0,0 +1,306 @@ +// Copyright (C) 2018-2023 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 <sstream> + +using namespace std; +using namespace isc::data; +using namespace libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorSharedNetwork::TranslatorSharedNetwork(Session session, + const string& model) + : Translator(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) { +} + +ElementPtr +TranslatorSharedNetwork::getSharedNetwork(DataNode const& data_node) { + try { + if (model_ == KEA_DHCP4_SERVER) { + return (getSharedNetworkKea(data_node, "subnet4")); + } else if (model_ == KEA_DHCP6_SERVER) { + return (getSharedNetworkKea(data_node, "subnet6")); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting shared network:" + << ex.what()); + } + isc_throw(NotImplemented, + "getSharedNetwork not implemented for the model: " << model_); +} + +ElementPtr +TranslatorSharedNetwork::getSharedNetworkFromAbsoluteXpath(string const& xpath) { + try { + return getSharedNetwork(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorSharedNetwork::getSharedNetworkKea(DataNode const& data_node, + string const& subsel) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "name"); + + checkAndGetLeaf(result, data_node, "allocator"); + checkAndGetLeaf(result, data_node, "cache-max-age"); + checkAndGetLeaf(result, data_node, "cache-threshold"); + checkAndGetLeaf(result, data_node, "calculate-tee-times"); + checkAndGetLeaf(result, data_node, "client-class"); + checkAndGetLeaf(result, data_node, "ddns-generated-prefix"); + checkAndGetLeaf(result, data_node, "ddns-override-client-update"); + checkAndGetLeaf(result, data_node, "ddns-override-no-update"); + checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix"); + checkAndGetLeaf(result, data_node, "ddns-replace-client-name"); + checkAndGetLeaf(result, data_node, "ddns-send-updates"); + checkAndGetLeaf(result, data_node, "ddns-ttl-percent"); + checkAndGetLeaf(result, data_node, "ddns-update-on-renew"); + checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution"); + checkAndGetLeaf(result, data_node, "hostname-char-replacement"); + checkAndGetLeaf(result, data_node, "hostname-char-set"); + checkAndGetLeaf(result, data_node, "interface"); + checkAndGetLeaf(result, data_node, "max-valid-lifetime"); + checkAndGetLeaf(result, data_node, "min-valid-lifetime"); + checkAndGetLeaf(result, data_node, "rebind-timer"); + checkAndGetLeaf(result, data_node, "renew-timer"); + checkAndGetLeaf(result, data_node, "require-client-classes"); + checkAndGetLeaf(result, data_node, "reservation-mode"); + checkAndGetLeaf(result, data_node, "reservations-global"); + checkAndGetLeaf(result, data_node, "reservations-in-subnet"); + checkAndGetLeaf(result, data_node, "reservations-out-of-pool"); + checkAndGetLeaf(result, data_node, "store-extended-info"); + checkAndGetLeaf(result, data_node, "t1-percent"); + checkAndGetLeaf(result, data_node, "t2-percent"); + checkAndGetLeaf(result, data_node, "valid-lifetime"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + ConstElementPtr subnets = getSubnets(data_node); + if (subnets) { + result->set(subsel, subnets); + } + + checkAndGet(result, data_node, "relay", + [&](DataNode const& node) -> ElementPtr const { + ElementPtr relay(Element::createMap()); + checkAndGetLeaf(relay, node, "ip-addresses"); + return relay; + }); + + if (subsel == "subnet6") { + checkAndGetLeaf(result, data_node, "interface-id"); + checkAndGetLeaf(result, data_node, "max-preferred-lifetime"); + checkAndGetLeaf(result, data_node, "min-preferred-lifetime"); + checkAndGetLeaf(result, data_node, "pd-allocator"); + checkAndGetLeaf(result, data_node, "preferred-lifetime"); + checkAndGetLeaf(result, data_node, "rapid-commit"); + } else if (subsel == "subnet4") { + checkAndGetLeaf(result, data_node, "authoritative"); + checkAndGetLeaf(result, data_node, "boot-file-name"); + checkAndGetLeaf(result, data_node, "match-client-id"); + checkAndGetLeaf(result, data_node, "next-server"); + checkAndGetLeaf(result, data_node, "offer-lifetime"); + checkAndGetLeaf(result, data_node, "server-hostname"); + } + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorSharedNetwork::setSharedNetwork(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting shared network '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorSharedNetwork::setSharedNetworkKea(string const& xpath, + ConstElementPtr elem, + string const& subsel) { + // Skip key "name". + + checkAndSetLeaf(elem, xpath, "allocator", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-ttl-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "interface", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum); + checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32); + + checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String); + + checkAndSetUserContext(elem, xpath); + + ConstElementPtr relay = elem->get("relay"); + if (relay) { + ConstElementPtr address = relay->get("ip-address"); + ConstElementPtr addresses = relay->get("ip-addresses"); + if (address) { + setItem(xpath + "/relay/ip-addresses", address, LeafBaseType::String); + } else if (addresses && !addresses->empty()) { + for (ElementPtr const& addr : addresses->listValue()) { + setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String); + } + } + } + + ConstElementPtr options = elem->get("option-data"); + if (options && !options->empty()) { + setOptionDataList(xpath, options); + } + + ConstElementPtr subnets = elem->get(subsel); + if (subnets && !subnets->empty()) { + setSubnets(xpath, subnets); + } + + if (subsel == "subnet6") { + checkAndSetLeaf(elem, xpath, "interface-id", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "pd-allocator", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "rapid-commit", LeafBaseType::Bool); + } else { + checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String); + } +} + +TranslatorSharedNetworks::TranslatorSharedNetworks(Session session, + const string& model) + : Translator(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) { +} + +ElementPtr +TranslatorSharedNetworks::getSharedNetworks(DataNode const& data_node) { + return getList<TranslatorSharedNetwork>(data_node, "shared-network", *this, + &TranslatorSharedNetwork::getSharedNetwork); +} + +ElementPtr +TranslatorSharedNetworks::getSharedNetworksFromAbsoluteXpath(string const& xpath) { + try { + return getSharedNetworks(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +void +TranslatorSharedNetworks::setSharedNetworks(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting shared networks '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorSharedNetworks::setSharedNetworksKea(string const& xpath, + ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr network = elem->getNonConst(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..04f8335 --- /dev/null +++ b/src/lib/yang/translator_shared_network.h @@ -0,0 +1,281 @@ +// 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_SHARED_NETWORK_H +#define ISC_TRANSLATOR_SHARED_NETWORK_H 1 + +#include <yang/translator.h> +#include <yang/translator_subnet.h> + +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::Session session, + const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorSharedNetwork() = default; + + /// @brief Translate a shared network from YANG to JSON. + /// + /// @param data_node the YANG node representing the shared network + /// + /// @return the JSON representation of the shared network + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getSharedNetwork(libyang::DataNode const& data_node); + + /// @brief Translate a shared network from YANG to JSON. + /// + /// @param xpath The xpath of the shared network. + /// + /// @return JSON representation of the shared network. + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getSharedNetworkFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the shared nework + /// @param subsel The subnet list name (either "subnet4" or "subnet6"). + /// + /// @return JSON representation of the shared network. + isc::data::ElementPtr getSharedNetworkKea(libyang::DataNode const& data_node, + 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); +}; // TranslatorSharedNetwork + +/// @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::Session session, + const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorSharedNetworks() = default; + + /// @brief Translate shared networks from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of shared networks + /// + /// @return the JSON representation of the list of shared networks + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getSharedNetworks(libyang::DataNode const& data_node); + + /// @brief Translate shared networks from YANG to JSON. + /// + /// @param xpath The xpath of the shared network list. + /// + /// @return the JSON representation of the list of shared networks + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getSharedNetworksFromAbsoluteXpath(std::string const& 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); +}; // TranslatorSharedNetworks + +} // 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..438895a --- /dev/null +++ b/src/lib/yang/translator_subnet.cc @@ -0,0 +1,430 @@ +// Copyright (C) 2018-2023 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 libyang; +using namespace sysrepo; + +namespace isc { +namespace yang { + +TranslatorSubnet::TranslatorSubnet(Session session, const string& model) + : Translator(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) { +} + +ElementPtr +TranslatorSubnet::getSubnet(DataNode const& data_node) { + try { + if (model_ == IETF_DHCPV6_SERVER) { + return (getSubnetIetf6(data_node)); + } else if ((model_ == KEA_DHCP4_SERVER) || + (model_ == KEA_DHCP6_SERVER)) { + return (getSubnetKea(data_node)); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting subnet:" + << ex.what()); + } + isc_throw(NotImplemented, + "getSubnet not implemented for the model: " << model_); +} + +ElementPtr +TranslatorSubnet::getSubnetFromAbsoluteXpath(string const& xpath) { + try { + return getSubnet(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorSubnet::getSubnetIetf6(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + getMandatoryDivergingLeaf(result, data_node, "subnet", "network-prefix"); + getMandatoryDivergingLeaf(result, data_node, "id", "network-range-id"); + + checkAndGetDiverging(result, data_node, "pools", "address-pools", + [&](DataNode const& node) -> ElementPtr const { + return getPools(node); + }); + + checkAndGet(result, data_node, "pd-pools", + [&](DataNode const& node) -> ElementPtr const { + return getPdPools(node); + }); + + ConstElementPtr description = getItem(data_node, "network-description"); + if (description) { + ElementPtr context = Element::createMap(); + context->set("description", description); + result->set("user-context", context); + } + + if (result->get("pools")) { + AdaptorPool::toSubnet(model_, result, result->get("pools")); + } + + /// @todo: timers + /// @todo: option-data + /// @todo: reservations + + return (result->empty() ? ElementPtr() : result); +} + +ElementPtr +TranslatorSubnet::getSubnetKea(DataNode const& data_node) { + ElementPtr result = Element::createMap(); + + getMandatoryLeaf(result, data_node, "id"); + getMandatoryLeaf(result, data_node, "subnet"); + + checkAndGetLeaf(result, data_node, "allocator"); + checkAndGetLeaf(result, data_node, "cache-max-age"); + checkAndGetLeaf(result, data_node, "cache-threshold"); + checkAndGetLeaf(result, data_node, "calculate-tee-times"); + checkAndGetLeaf(result, data_node, "client-class"); + checkAndGetLeaf(result, data_node, "ddns-generated-prefix"); + checkAndGetLeaf(result, data_node, "ddns-override-client-update"); + checkAndGetLeaf(result, data_node, "ddns-override-no-update"); + checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix"); + checkAndGetLeaf(result, data_node, "ddns-replace-client-name"); + checkAndGetLeaf(result, data_node, "ddns-send-updates"); + checkAndGetLeaf(result, data_node, "ddns-ttl-percent"); + checkAndGetLeaf(result, data_node, "ddns-update-on-renew"); + checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution"); + checkAndGetLeaf(result, data_node, "hostname-char-replacement"); + checkAndGetLeaf(result, data_node, "hostname-char-set"); + checkAndGetLeaf(result, data_node, "interface"); + checkAndGetLeaf(result, data_node, "max-valid-lifetime"); + checkAndGetLeaf(result, data_node, "min-valid-lifetime"); + checkAndGetLeaf(result, data_node, "rebind-timer"); + checkAndGetLeaf(result, data_node, "renew-timer"); + checkAndGetLeaf(result, data_node, "require-client-classes"); + checkAndGetLeaf(result, data_node, "reservation-mode"); + checkAndGetLeaf(result, data_node, "reservations-global"); + checkAndGetLeaf(result, data_node, "reservations-in-subnet"); + checkAndGetLeaf(result, data_node, "reservations-out-of-pool"); + checkAndGetLeaf(result, data_node, "store-extended-info"); + checkAndGetLeaf(result, data_node, "t1-percent"); + checkAndGetLeaf(result, data_node, "t2-percent"); + checkAndGetLeaf(result, data_node, "valid-lifetime"); + + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); + + ConstElementPtr options = getOptionDataList(data_node); + if (options) { + result->set("option-data", options); + } + + ConstElementPtr pools = getPools(data_node); + if (pools) { + result->set("pools", pools); + } + + checkAndGet(result, data_node, "relay", + [&](DataNode const& node) -> ElementPtr const { + ElementPtr relay(Element::createMap()); + checkAndGetLeaf(relay, node, "ip-addresses"); + return relay; + }); + + ConstElementPtr hosts = getHosts(data_node); + if (hosts) { + result->set("reservations", hosts); + } + + if (model_ == KEA_DHCP6_SERVER) { + checkAndGetLeaf(result, data_node, "interface-id"); + checkAndGetLeaf(result, data_node, "max-preferred-lifetime"); + checkAndGetLeaf(result, data_node, "min-preferred-lifetime"); + checkAndGetLeaf(result, data_node, "pd-allocator"); + checkAndGetLeaf(result, data_node, "preferred-lifetime"); + checkAndGetLeaf(result, data_node, "rapid-commit"); + + ElementPtr pd_pools = getPdPools(data_node); + if (pd_pools) { + result->set("pd-pools", pd_pools); + } + } else if (model_ == KEA_DHCP4_SERVER) { + checkAndGetLeaf(result, data_node, "authoritative"); + checkAndGetLeaf(result, data_node, "boot-file-name"); + checkAndGetLeaf(result, data_node, "match-client-id"); + checkAndGetLeaf(result, data_node, "next-server"); + checkAndGetLeaf(result, data_node, "offer-lifetime"); + checkAndGetLeaf(result, data_node, "server-hostname"); + + checkAndGetDivergingLeaf(result, data_node, "4o6-interface", "subnet-4o6-interface"); + checkAndGetDivergingLeaf(result, data_node, "4o6-interface-id", "subnet-4o6-interface-id"); + checkAndGetDivergingLeaf(result, data_node, "4o6-subnet", "subnet-4o6-subnet"); + } + + return (result->empty() ? ElementPtr() : result); +} + +void +TranslatorSubnet::setSubnet(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting subnet '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorSubnet::setSubnetIetf6(string const& xpath, ConstElementPtr elem) { + /// Skip key "id". + + setMandatoryDivergingLeaf(elem, xpath, "subnet", "network-prefix", LeafBaseType::String); + + AdaptorPool::fromSubnet(model_, elem, elem->get("pools")); + ConstElementPtr context = elem->get("user-context"); + if (context && context->contains("description")) { + ConstElementPtr description = context->get("description"); + if (description->getType() == Element::string) { + setItem(xpath + "/network-description", description, LeafBaseType::String); + } + } + ConstElementPtr subnet = elem->get("subnet"); + if (!subnet) { + isc_throw(BadValue, "setSubnetIetf6 requires subnet: " << elem->str()); + } + setItem(xpath + "/network-prefix", subnet, LeafBaseType::String); + ConstElementPtr pools = elem->get("pools"); + if (pools && !pools->empty()) { + setPools(xpath + "/address-pools", pools); + } + pools = elem->get("pd-pools"); + if (pools && !pools->empty()) { + setPdPools(xpath + "/pd-pools", pools); + } + + /// @todo: option-data + /// @todo: reservations +} + +void +TranslatorSubnet::setSubnetKea(string const& xpath, ConstElementPtr elem) { + /// Skip key "id". + + ConstElementPtr subnet = elem->get("subnet"); + if (!subnet) { + isc_throw(BadValue, "setSubnetKea requires subnet: " << elem->str()); + } + setItem(xpath + "/subnet", subnet, LeafBaseType::String); + + checkAndSetLeaf(elem, xpath, "allocator", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "client-class", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-ttl-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "interface", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum); + checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64); + checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32); + + checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String); + + ConstElementPtr options = elem->get("option-data"); + if (options && !options->empty()) { + setOptionDataList(xpath, options); + } + ConstElementPtr pools = elem->get("pools"); + if (pools && !pools->empty()) { + setPools(xpath, pools); + } + ConstElementPtr relay = elem->get("relay"); + if (relay) { + ConstElementPtr address = relay->get("ip-address"); + ConstElementPtr addresses = relay->get("ip-addresses"); + if (address) { + setItem(xpath + "/relay/ip-addresses", address, LeafBaseType::String); + } else if (addresses && !addresses->empty()) { + for (ElementPtr const& addr : addresses->listValue()) { + setItem(xpath + "/relay/ip-addresses", addr, LeafBaseType::String); + } + } + } + ConstElementPtr hosts = elem->get("reservations"); + if (hosts && !hosts->empty()) { + setHosts(xpath, hosts); + } + + if (model_ == KEA_DHCP6_SERVER) { + checkAndSetLeaf(elem, xpath, "interface-id", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "pd-allocator", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "rapid-commit", LeafBaseType::Bool); + + pools = elem->get("pd-pools"); + if (pools && !pools->empty()) { + setPdPools(xpath, pools); + } + } else { + checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool); + checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32); + checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String); + + checkAndSetDivergingLeaf(elem, xpath, "4o6-interface", "subnet-4o6-interface", LeafBaseType::String); + checkAndSetDivergingLeaf(elem, xpath, "4o6-interface-id", "subnet-4o6-interface-id", LeafBaseType::String); + checkAndSetDivergingLeaf(elem, xpath, "4o6-subnet", "subnet-4o6-subnet", LeafBaseType::String); + } + checkAndSetUserContext(elem, xpath); +} + +TranslatorSubnets::TranslatorSubnets(Session session, const string& model) + : Translator(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) { +} + +ElementPtr +TranslatorSubnets::getSubnets(DataNode const& data_node) { + try { + if (model_ == IETF_DHCPV6_SERVER) { + return (getSubnetsCommon(data_node, "network-range")); + } else if (model_ == KEA_DHCP4_SERVER) { + return (getSubnetsCommon(data_node, "subnet4")); + } else if (model_ == KEA_DHCP6_SERVER) { + return (getSubnetsCommon(data_node, "subnet6")); + } + } catch (Error const& ex) { + isc_throw(NetconfError, + "getting subnets:" + << ex.what()); + } + isc_throw(NotImplemented, + "getSubnets not implemented for the model: " << model_); +} + +ElementPtr +TranslatorSubnets::getSubnetsFromAbsoluteXpath(string const& xpath) { + try { + return getSubnets(findXPath(xpath)); + } catch (NetconfError const&) { + return ElementPtr(); + } +} + +ElementPtr +TranslatorSubnets::getSubnetsCommon(DataNode const& data_node, + string const& subsel) { + return getList<TranslatorSubnet>(data_node, subsel, *this, + &TranslatorSubnet::getSubnet); +} + +void +TranslatorSubnets::setSubnets(string const& 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 (Error const& ex) { + isc_throw(NetconfError, + "setting subnets '" << elem->str() + << "' : " << ex.what()); + } +} + +void +TranslatorSubnets::setSubnetsIetf6(string const& xpath, ConstElementPtr elem) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr subnet = elem->getNonConst(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(), subnet); + } +} + +void +TranslatorSubnets::setSubnetsKea(string const& xpath, ConstElementPtr elem, + string const& subsel) { + for (size_t i = 0; i < elem->size(); ++i) { + ElementPtr subnet = elem->getNonConst(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..b5e48d7 --- /dev/null +++ b/src/lib/yang/translator_subnet.h @@ -0,0 +1,411 @@ +// 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_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> + +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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorSubnet() = default; + + /// @brief Get and translate a subnet from YANG to JSON. + /// + /// @param data_node the YANG node representing the subnet configuration + /// + /// @return the JSON representation of the subnet + /// + /// @throw NetconfError when sysrepo raises an error. + /// @throw BadValue on a subnet without prefix or id. + isc::data::ElementPtr getSubnet(libyang::DataNode const& data_node); + + /// @brief Get and translate a subnet from YANG to JSON. + /// + /// @param xpath The xpath of the subnet. + /// + /// @return JSON representation of the subnet. + /// + /// @throw NetconfError when sysrepo raises an error. + /// @throw BadValue on a subnet without prefix or id. + isc::data::ElementPtr getSubnetFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the subnet configuration + /// + /// @return JSON representation of the subnet. + isc::data::ElementPtr getSubnetIetf6(libyang::DataNode const& data_node); + + /// @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 data_node the YANG node representing the subnet configuration + /// + /// @return JSON representation of the subnet. + isc::data::ElementPtr getSubnetKea(libyang::DataNode const& data_node); + + /// @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); +}; // TranslatorSubnets + +/// @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::Session session, const std::string& model); + + /// @brief Destructor. + virtual ~TranslatorSubnets() = default; + + /// @brief Get and translate subnets from YANG to JSON. + /// + /// @param data_node the YANG node representing the list of subnets + /// + /// @return the JSON representation of the list of subnets + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getSubnets(libyang::DataNode const& data_node); + + /// @brief Get and translate subnets from YANG to JSON. + /// + /// @param xpath The xpath of the subnet list. + /// + /// @return the JSON representation of the list of subnets + /// + /// @throw NetconfError when sysrepo raises an error. + isc::data::ElementPtr getSubnetsFromAbsoluteXpath(std::string const& 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 data_node the YANG node representing the list of subnets + /// @param subsel The subnet list name. + /// + /// @return the JSON representation of the list of subnets + isc::data::ElementPtr getSubnetsCommon(libyang::DataNode const& data_node, + 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); +}; // TranslatorSubnets + +} // 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..e0fcab0 --- /dev/null +++ b/src/lib/yang/yang.dox @@ -0,0 +1,276 @@ +// 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 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::Translator. +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)). Secondly, 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 +Event::Update (SR_EV_UPDATE prior to sysrepo v2) 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::Translator provides several public methods: + + - @c isc::yang::Translator::checkAndGet() is able to retrieve a YANG node that + can be retrieved through complex logic which is abstracted through a lambda. + + - @c isc::yang::Translator::checkAndGetLeaf() is a convenience wrapper + over @c isc::yang::Translator::getItem(). + + - @c isc::yang::Translator::checkAndGetAndJsonifyLeaf() retrieves elements + that are strings in the YANG schema, but that require passing through + @c isc::data::Element::fromJSON() when translating to ElementPtr. + + - @c isc::yang::Translator::checkAndStringifyAndSetLeaf() does the opposite of + @c isc::yang::Translator::checkAndGetAndJsonifyLeaf(). It takes an arbitrary + Element and sets it as a YANG string in sysrepo. + + - @c isc::yang::Translator::checkAndSetLeaf() is a convenience wrapper + over @c isc::yang::Translator::setItem(). + + - @c isc::yang::Translator::checkAndSetLeafList() is able to push multiple + leaf list nodes to the same xpath to form a leaf list. + + - @c isc::yang::Translator::checkAndSetUserContext() is specifically tailored + for setting user context in sysrepo. It's use is frequent enough to have + earned its own function. + + - @c isc::yang::Translator::deleteItem() deletes the data node found at + given xpath. + + - @c isc::yang::Translator::findXPath() retrieves any data node found at any + xpath. It is computationally intensive. Use sparingly. + + - @c isc::yang::Translator::forAll() iterates over the node found at + given xpath and all its descendants and calls the given function. + + - @c isc::yang::Translator::getData() retrieves any data node found at any + xpath. The difference from @c isc::yang::Translator::findXPath() is that it + does not throw if the data node is not found and instead returns nullopt. + + - @c isc::yang::Translator::getItem() retrieves and translates a leaf + from YANG to Element. + + - @c isc::yang::Translator::getList() retrieves a list from sysrepo and + translates it from YANG to Element. + + - @c isc::yang::Translator::getMandatoryLeaf() fetches a leaf that is expected + to be present in the YANG data node, most of the time a YANG key. + + - @c isc::yang::Translator::schemaNodeExists() checks if an xpath is valid + from the YANG schema point of view. Not used anywhere, but it's here to + substitute logic that had been previously removed. + + - @c isc::yang::Translator::setItem() translates a leaf from Element to + YANG and sets it in sysrepo. + + - @c isc::yang::Translator::setMandatoryLeaf() sets a leaf that is expected + to be present in the Element node, most of the time a YANG key. + + - @c isc::yang::Translator::translateFromYang(optional<DataNode>, string) + translates a YANG leaf to an Element node based on YANG type. + All YANG types are explicitly handled. + + - @c isc::yang::Translator::translateToYang(ConstElementPtr, LeafBaseType) + translates an Element leaf to a string based on the YANG type. + All YANG types are explicitly handled. + +Some of these methods have a counterpart that have "Diverging" in their name. +They are exceptionally used in the case where YANG xpath and Element map key are +different. This facilitates identifying these diverging nodes. + +@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::Translator 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 adapt 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-libyang --with-sysrepo --with-libyang-cpp --with-sysrepo-cpp +@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 + +If the YANG modules are already installed, they will be upgraded. +To avoid any upgrade hastle, the -u flag may be passed to uninstall the modules +before installing again. + +@verbatim +./src/share/yang/modules/utils/reinstall.sh -u +@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 libyang and 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..8055d5d --- /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"; + +} // namespace yang +} // 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..91fee57 --- /dev/null +++ b/src/lib/yang/yang_revisions.h @@ -0,0 +1,35 @@ +// Copyright (C) 2018-2023 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 <string> +#include <unordered_map> + +namespace isc { +namespace yang { + +// Table of module name / revision. +static const std::unordered_map<std::string, std::string> YANG_REVISIONS = { +#ifdef KEATEST_MODULE + { "keatest-module", "2022-11-30" }, +#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", "2023-06-28" }, + { "kea-dhcp4-server", "2023-06-28" }, + { "kea-dhcp6-server", "2023-06-28" }, + { "kea-ctrl-agent", "2019-08-12" }, + { "kea-dhcp-ddns", "2022-07-27" } +}; // YANG_REVISIONS + +} // 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..826f26e --- /dev/null +++ b/src/lib/yang/yang_revisions.h.skel @@ -0,0 +1,27 @@ +// 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 <string> +#include <unordered_map> + +namespace isc { +namespace yang { + +// Table of module name / revision. +static const std::unordered_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 +}; // YANG_REVISIONS + +} // namespace yang +} // namespace isc + +#endif // ISC_YANG_REVISIONS_H |