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_
23 #define YANG_TRANSLATE_TO_NATIVE 0
24 #define YANG_TRANSLATE_FROM_NATIVE 1
25 #define YANG_TRANSLATE_MAX 2
28 const struct lys_module
*module
;
29 const struct lys_module
*deviations
;
30 uint32_t nodes_before_deviations
;
31 uint32_t nodes_after_deviations
;
35 struct yang_translator
{
36 RB_ENTRY(yang_translator
) entry
;
38 struct ly_ctx
*ly_ctx
;
40 struct hash
*mappings
[YANG_TRANSLATE_MAX
];
42 RB_HEAD(yang_translators
, yang_translator
);
43 RB_PROTOTYPE(yang_translators
, yang_translator
, entry
, yang_translator_compare
);
45 enum yang_translate_result
{
46 YANG_TRANSLATE_SUCCESS
,
47 YANG_TRANSLATE_NOTFOUND
,
48 YANG_TRANSLATE_FAILURE
,
51 /* Tree of all loaded YANG module translators. */
52 extern struct yang_translators yang_translators
;
55 * Load a YANG module translator from a JSON file.
58 * Absolute path to the module translator file.
61 * Pointer to newly created YANG module translator, or NULL in the case of an
64 extern struct yang_translator
*yang_translator_load(const char *path
);
67 * Unload a YANG module translator.
70 * Pointer to the YANG module translator.
72 extern void yang_translator_unload(struct yang_translator
*translator
);
75 * Find a YANG module translator by its family name.
78 * Family of the YANG module translator (e.g. ietf, openconfig).
81 * Pointer to the YANG module translator if found, NULL otherwise.
83 extern struct yang_translator
*yang_translator_find(const char *family
);
86 * Translate an XPath expression.
89 * Pointer to YANG module translator.
92 * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or
93 * YANG_TRANSLATE_FROM_NATIVE).
96 * Pointer to previously allocated buffer containing the xpath expression to
100 * Size of the xpath buffer.
103 * - YANG_TRANSLATE_SUCCESS on success.
104 * - YANG_TRANSLATE_NOTFOUND when there's no available mapping to perform
106 * - YANG_TRANSLATE_FAILURE when an error occurred during the translation.
108 extern enum yang_translate_result
109 yang_translate_xpath(const struct yang_translator
*translator
, int dir
,
110 char *xpath
, size_t xpath_len
);
113 * Translate an entire libyang data node.
116 * Pointer to YANG module translator.
119 * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or
120 * YANG_TRANSLATE_FROM_NATIVE).
123 * libyang schema node we want to translate.
126 * - YANG_TRANSLATE_SUCCESS on success.
127 * - YANG_TRANSLATE_FAILURE when an error occurred during the translation.
129 extern int yang_translate_dnode(const struct yang_translator
*translator
,
130 int dir
, struct lyd_node
**dnode
);
133 * Initialize the YANG module translator subsystem. Should be called only once
134 * during the daemon initialization process.
136 extern void yang_translator_init(void);
139 * Finish the YANG module translator subsystem gracefully. Should be called only
140 * when the daemon is exiting.
142 extern void yang_translator_terminate(void);
144 #endif /* _FRR_YANG_TRANSLATOR_H_ */