2 * Copyright (C) 2018 NetDEF, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef _FRR_YANG_TRANSLATOR_H_
21 #define _FRR_YANG_TRANSLATOR_H_
27 #define YANG_TRANSLATE_TO_NATIVE 0
28 #define YANG_TRANSLATE_FROM_NATIVE 1
29 #define YANG_TRANSLATE_MAX 2
32 const struct lys_module
*module
;
33 const struct lys_module
*deviations
;
34 uint32_t nodes_before_deviations
;
35 uint32_t nodes_after_deviations
;
39 struct yang_translator
{
40 RB_ENTRY(yang_translator
) entry
;
42 struct ly_ctx
*ly_ctx
;
44 struct hash
*mappings
[YANG_TRANSLATE_MAX
];
46 RB_HEAD(yang_translators
, yang_translator
);
47 RB_PROTOTYPE(yang_translators
, yang_translator
, entry
, yang_translator_compare
);
49 enum yang_translate_result
{
50 YANG_TRANSLATE_SUCCESS
,
51 YANG_TRANSLATE_NOTFOUND
,
52 YANG_TRANSLATE_FAILURE
,
55 /* Tree of all loaded YANG module translators. */
56 extern struct yang_translators yang_translators
;
59 * Load a YANG module translator from a JSON file.
62 * Absolute path to the module translator file.
65 * Pointer to newly created YANG module translator, or NULL in the case of an
68 extern struct yang_translator
*yang_translator_load(const char *path
);
71 * Unload a YANG module translator.
74 * Pointer to the YANG module translator.
76 extern void yang_translator_unload(struct yang_translator
*translator
);
79 * Find a YANG module translator by its family name.
82 * Family of the YANG module translator (e.g. ietf, openconfig).
85 * Pointer to the YANG module translator if found, NULL otherwise.
87 extern struct yang_translator
*yang_translator_find(const char *family
);
90 * Translate an XPath expression.
93 * Pointer to YANG module translator.
96 * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or
97 * YANG_TRANSLATE_FROM_NATIVE).
100 * Pointer to previously allocated buffer containing the xpath expression to
104 * Size of the xpath buffer.
107 * - YANG_TRANSLATE_SUCCESS on success.
108 * - YANG_TRANSLATE_NOTFOUND when there's no available mapping to perform
110 * - YANG_TRANSLATE_FAILURE when an error occurred during the translation.
112 extern enum yang_translate_result
113 yang_translate_xpath(const struct yang_translator
*translator
, int dir
,
114 char *xpath
, size_t xpath_len
);
117 * Translate an entire libyang data node.
120 * Pointer to YANG module translator.
123 * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or
124 * YANG_TRANSLATE_FROM_NATIVE).
127 * libyang schema node we want to translate.
130 * - YANG_TRANSLATE_SUCCESS on success.
131 * - YANG_TRANSLATE_FAILURE when an error occurred during the translation.
133 extern int yang_translate_dnode(const struct yang_translator
*translator
,
134 int dir
, struct lyd_node
**dnode
);
137 * Initialize the YANG module translator subsystem. Should be called only once
138 * during the daemon initialization process.
140 extern void yang_translator_init(void);
143 * Finish the YANG module translator subsystem gracefully. Should be called only
144 * when the daemon is exiting.
146 extern void yang_translator_terminate(void);
152 #endif /* _FRR_YANG_TRANSLATOR_H_ */