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