1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018 NetDEF, Inc.
7 #ifndef _FRR_YANG_TRANSLATOR_H_
8 #define _FRR_YANG_TRANSLATOR_H_
14 #define YANG_TRANSLATE_TO_NATIVE 0
15 #define YANG_TRANSLATE_FROM_NATIVE 1
16 #define YANG_TRANSLATE_MAX 2
19 const struct lys_module
*module
;
20 const struct lys_module
*deviations
;
21 uint32_t nodes_before_deviations
;
22 uint32_t nodes_after_deviations
;
26 struct yang_translator
{
27 RB_ENTRY(yang_translator
) entry
;
29 struct ly_ctx
*ly_ctx
;
31 struct hash
*mappings
[YANG_TRANSLATE_MAX
];
33 RB_HEAD(yang_translators
, yang_translator
);
34 RB_PROTOTYPE(yang_translators
, yang_translator
, entry
, yang_translator_compare
);
36 enum yang_translate_result
{
37 YANG_TRANSLATE_SUCCESS
,
38 YANG_TRANSLATE_NOTFOUND
,
39 YANG_TRANSLATE_FAILURE
,
42 /* Tree of all loaded YANG module translators. */
43 extern struct yang_translators yang_translators
;
46 * Load a YANG module translator from a JSON file.
49 * Absolute path to the module translator file.
52 * Pointer to newly created YANG module translator, or NULL in the case of an
55 extern struct yang_translator
*yang_translator_load(const char *path
);
58 * Unload a YANG module translator.
61 * Pointer to the YANG module translator.
63 extern void yang_translator_unload(struct yang_translator
*translator
);
66 * Find a YANG module translator by its family name.
69 * Family of the YANG module translator (e.g. ietf, openconfig).
72 * Pointer to the YANG module translator if found, NULL otherwise.
74 extern struct yang_translator
*yang_translator_find(const char *family
);
77 * Translate an XPath expression.
80 * Pointer to YANG module translator.
83 * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or
84 * YANG_TRANSLATE_FROM_NATIVE).
87 * Pointer to previously allocated buffer containing the xpath expression to
91 * Size of the xpath buffer.
94 * - YANG_TRANSLATE_SUCCESS on success.
95 * - YANG_TRANSLATE_NOTFOUND when there's no available mapping to perform
97 * - YANG_TRANSLATE_FAILURE when an error occurred during the translation.
99 extern enum yang_translate_result
100 yang_translate_xpath(const struct yang_translator
*translator
, int dir
,
101 char *xpath
, size_t xpath_len
);
104 * Translate an entire libyang data node.
107 * Pointer to YANG module translator.
110 * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or
111 * YANG_TRANSLATE_FROM_NATIVE).
114 * libyang schema node we want to translate.
117 * - YANG_TRANSLATE_SUCCESS on success.
118 * - YANG_TRANSLATE_FAILURE when an error occurred during the translation.
120 extern int yang_translate_dnode(const struct yang_translator
*translator
,
121 int dir
, struct lyd_node
**dnode
);
124 * Initialize the YANG module translator subsystem. Should be called only once
125 * during the daemon initialization process.
127 extern void yang_translator_init(void);
130 * Finish the YANG module translator subsystem gracefully. Should be called only
131 * when the daemon is exiting.
133 extern void yang_translator_terminate(void);
139 #endif /* _FRR_YANG_TRANSLATOR_H_ */