summaryrefslogtreecommitdiff
path: root/tools/gen_yang_deviations.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2017-12-07 17:31:48 -0200
committerRenato Westphal <renato@opensourcerouting.org>2018-10-27 16:16:12 -0200
commit1c2facd12df7bc27758d7ea674b1e57e401fc234 (patch)
treeb82aeb06586c2c7b380420ddd484964af915aee1 /tools/gen_yang_deviations.c
parent75082dafb5a929b99d89c8f55e6b2da3f4d90100 (diff)
lib: introduce new northbound API
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'tools/gen_yang_deviations.c')
-rw-r--r--tools/gen_yang_deviations.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/tools/gen_yang_deviations.c b/tools/gen_yang_deviations.c
new file mode 100644
index 0000000000..121969c6fe
--- /dev/null
+++ b/tools/gen_yang_deviations.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2018 NetDEF, Inc.
+ * Renato Westphal
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define REALLY_NEED_PLAIN_GETOPT 1
+
+#include <zebra.h>
+
+#include <unistd.h>
+
+#include "yang.h"
+#include "northbound.h"
+
+static void __attribute__((noreturn)) usage(int status)
+{
+ fprintf(stderr, "usage: gen_yang_deviations [-h] MODULE\n");
+ exit(status);
+}
+
+static void generate_yang_deviation(const struct lys_node *snode, void *arg1,
+ void *arg2)
+{
+ char xpath[XPATH_MAXLEN];
+
+ yang_snode_get_path(snode, YANG_PATH_SCHEMA, xpath, sizeof(xpath));
+
+ printf(" deviation \"%s\" {\n", xpath);
+ printf(" deviate not-supported;\n");
+ printf(" }\n\n");
+}
+
+int main(int argc, char *argv[])
+{
+ struct yang_module *module;
+ int opt;
+
+ while ((opt = getopt(argc, argv, "h")) != -1) {
+ switch (opt) {
+ case 'h':
+ usage(EXIT_SUCCESS);
+ /* NOTREACHED */
+ default:
+ usage(EXIT_FAILURE);
+ /* NOTREACHED */
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc != 1)
+ usage(EXIT_FAILURE);
+
+ yang_init();
+
+ /* Load YANG module. */
+ module = yang_module_load(argv[0]);
+
+ /* Generate deviations. */
+ yang_module_snodes_iterate(module->info, generate_yang_deviation,
+ YANG_ITER_FILTER_IMPLICIT, NULL, NULL);
+
+ /* Cleanup and exit. */
+ yang_terminate();
+
+ return 0;
+}