]>
Commit | Line | Data |
---|---|---|
1 | // SPDX-License-Identifier: GPL-2.0-or-later | |
2 | /* | |
3 | * Copyright (C) 2018 NetDEF, Inc. | |
4 | * Renato Westphal | |
5 | */ | |
6 | ||
7 | #ifndef _FRR_YANG_TRANSLATOR_H_ | |
8 | #define _FRR_YANG_TRANSLATOR_H_ | |
9 | ||
10 | #ifdef __cplusplus | |
11 | extern "C" { | |
12 | #endif | |
13 | ||
14 | #define YANG_TRANSLATE_TO_NATIVE 0 | |
15 | #define YANG_TRANSLATE_FROM_NATIVE 1 | |
16 | #define YANG_TRANSLATE_MAX 2 | |
17 | ||
18 | struct yang_tmodule { | |
19 | const struct lys_module *module; | |
20 | const struct lys_module *deviations; | |
21 | uint32_t nodes_before_deviations; | |
22 | uint32_t nodes_after_deviations; | |
23 | double coverage; | |
24 | }; | |
25 | ||
26 | struct yang_translator { | |
27 | RB_ENTRY(yang_translator) entry; | |
28 | char family[32]; | |
29 | struct ly_ctx *ly_ctx; | |
30 | struct list *modules; | |
31 | struct hash *mappings[YANG_TRANSLATE_MAX]; | |
32 | }; | |
33 | RB_HEAD(yang_translators, yang_translator); | |
34 | RB_PROTOTYPE(yang_translators, yang_translator, entry, yang_translator_compare); | |
35 | ||
36 | enum yang_translate_result { | |
37 | YANG_TRANSLATE_SUCCESS, | |
38 | YANG_TRANSLATE_NOTFOUND, | |
39 | YANG_TRANSLATE_FAILURE, | |
40 | }; | |
41 | ||
42 | /* Tree of all loaded YANG module translators. */ | |
43 | extern struct yang_translators yang_translators; | |
44 | ||
45 | /* | |
46 | * Load a YANG module translator from a JSON file. | |
47 | * | |
48 | * path | |
49 | * Absolute path to the module translator file. | |
50 | * | |
51 | * Returns: | |
52 | * Pointer to newly created YANG module translator, or NULL in the case of an | |
53 | * error. | |
54 | */ | |
55 | extern struct yang_translator *yang_translator_load(const char *path); | |
56 | ||
57 | /* | |
58 | * Unload a YANG module translator. | |
59 | * | |
60 | * translator | |
61 | * Pointer to the YANG module translator. | |
62 | */ | |
63 | extern void yang_translator_unload(struct yang_translator *translator); | |
64 | ||
65 | /* | |
66 | * Find a YANG module translator by its family name. | |
67 | * | |
68 | * family | |
69 | * Family of the YANG module translator (e.g. ietf, openconfig). | |
70 | * | |
71 | * Returns: | |
72 | * Pointer to the YANG module translator if found, NULL otherwise. | |
73 | */ | |
74 | extern struct yang_translator *yang_translator_find(const char *family); | |
75 | ||
76 | /* | |
77 | * Translate an XPath expression. | |
78 | * | |
79 | * translator | |
80 | * Pointer to YANG module translator. | |
81 | * | |
82 | * dir | |
83 | * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or | |
84 | * YANG_TRANSLATE_FROM_NATIVE). | |
85 | * | |
86 | * xpath | |
87 | * Pointer to previously allocated buffer containing the xpath expression to | |
88 | * be translated. | |
89 | * | |
90 | * xpath_len | |
91 | * Size of the xpath buffer. | |
92 | * | |
93 | * Returns: | |
94 | * - YANG_TRANSLATE_SUCCESS on success. | |
95 | * - YANG_TRANSLATE_NOTFOUND when there's no available mapping to perform | |
96 | * the translation. | |
97 | * - YANG_TRANSLATE_FAILURE when an error occurred during the translation. | |
98 | */ | |
99 | extern enum yang_translate_result | |
100 | yang_translate_xpath(const struct yang_translator *translator, int dir, | |
101 | char *xpath, size_t xpath_len); | |
102 | ||
103 | /* | |
104 | * Translate an entire libyang data node. | |
105 | * | |
106 | * translator | |
107 | * Pointer to YANG module translator. | |
108 | * | |
109 | * dir | |
110 | * Direction of the translation (either YANG_TRANSLATE_TO_NATIVE or | |
111 | * YANG_TRANSLATE_FROM_NATIVE). | |
112 | * | |
113 | * dnode | |
114 | * libyang schema node we want to translate. | |
115 | * | |
116 | * Returns: | |
117 | * - YANG_TRANSLATE_SUCCESS on success. | |
118 | * - YANG_TRANSLATE_FAILURE when an error occurred during the translation. | |
119 | */ | |
120 | extern int yang_translate_dnode(const struct yang_translator *translator, | |
121 | int dir, struct lyd_node **dnode); | |
122 | ||
123 | /* | |
124 | * Initialize the YANG module translator subsystem. Should be called only once | |
125 | * during the daemon initialization process. | |
126 | */ | |
127 | extern void yang_translator_init(void); | |
128 | ||
129 | /* | |
130 | * Finish the YANG module translator subsystem gracefully. Should be called only | |
131 | * when the daemon is exiting. | |
132 | */ | |
133 | extern void yang_translator_terminate(void); | |
134 | ||
135 | #ifdef __cplusplus | |
136 | } | |
137 | #endif | |
138 | ||
139 | #endif /* _FRR_YANG_TRANSLATOR_H_ */ |