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