-
Notifications
You must be signed in to change notification settings - Fork 29
/
ofconfig-transapi.c
165 lines (143 loc) · 4.34 KB
/
ofconfig-transapi.c
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
153
154
155
156
157
158
159
160
161
162
163
164
165
/* Copyright (c) 2015 Open Networking Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <config.h>
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <libxml/tree.h>
#include <libnetconf_xml.h>
#include <libnetconf_ssh.h>
#include "data.h"
#ifdef __GNUC__
# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
#else
# define UNUSED(x) UNUSED_ ## x
#endif
/* transAPI version which must be compatible with libnetconf */
/* int transapi_version = 6; */
/* Signal to libnetconf that configuration data were modified by any callback.
* 0 - data not modified
* 1 - data have been modified
*/
int ofc_config_modified = 0;
/* Do not modify or set! This variable is set by libnetconf to announce
* edit-config's error-option. Feel free to use it to distinguish module
* behavior for different error-option values.
* Possible values:
* NC_EDIT_ERROPT_STOP - Following callback after failure are not executed, all
* successful callbacks executed till failure point must be applied to the
* device.
* NC_EDIT_ERROPT_CONT - Failed callbacks are skipped, but all callbacks needed
* to apply configuration changes are executed
* NC_EDIT_ERROPT_ROLLBACK - After failure, following callbacks are not
* executed, but previous successful callbacks are executed again with
* previous configuration data to roll it back.
*/
NC_EDIT_ERROPT_TYPE ofc_erropt = NC_EDIT_ERROPT_NOTSET;
/* Retrieve state data from device and return them as XML document
*
*/
xmlDocPtr
ofc_status_clb(xmlDocPtr UNUSED(model), xmlDocPtr UNUSED(running),
struct nc_err **UNUSED(err))
{
char *state_data;
xmlDocPtr d;
state_data = ofc_get_state_data();
if (state_data != NULL) {
d = xmlReadMemory(state_data, strlen(state_data), NULL, NULL, 0);
free(state_data);
return d;
}
return (NULL);
}
/* Mapping between prefixes and namespaces. */
struct ns_pair ofc_namespace_mapping[] = {
{"of", "urn:onf:config:yang"},
{NULL, NULL}
};
/*
* CONFIGURATION callbacks
*/
/* Initialize of-config module
*
* When the running is returned untouched, the device must follow the default
* values defined in the data model.
*/
int
ofc_transapi_init(xmlDocPtr * UNUSED(running))
{
return EXIT_SUCCESS;
}
/* Free all resources allocated on plugin runtime and prepare plugin for
* removal.
*/
void
ofc_transapi_close(void)
{
return;
}
int
callback_top(void **UNUSED(data), XMLDIFF_OP UNUSED(op),
xmlNodePtr UNUSED(old), xmlNodePtr UNUSED(new),
struct nc_err **UNUSED(error))
{
nc_verb_verbose("OF-CONFIG data affected.");
return (EXIT_SUCCESS);
}
/*
* Structure transapi_config_callbacks provide mapping between callback and path
* in configuration datastore.
*/
struct transapi_data_callbacks ofc_clbks = {
.callbacks_count = 1,
.data = NULL,
.callbacks = {
{.path = "/of:capable-switch",
.func = callback_top},
}
};
/*
* RPC callbacks - in this module we don't have any RPC
*/
/*
* Structure transapi_rpc_callbacks provide mapping between callbacks and RPC
* messages.
*/
struct transapi_rpc_callbacks ofc_rpc_clbks = {
.callbacks_count = 0,
.callbacks = {}
};
/* overall structure providing content of this module to the libnetconf */
struct transapi ofc_transapi = {
.version = 6,
.init = ofc_transapi_init,
.close = ofc_transapi_close,
.get_state = ofc_status_clb,
.clbks_order = TRANSAPI_CLBCKS_ORDER_DEFAULT,
.data_clbks = &ofc_clbks,
.rpc_clbks = &ofc_rpc_clbks,
.ns_mapping = ofc_namespace_mapping,
.config_modified = &ofc_config_modified,
.erropt = &ofc_erropt,
.file_clbks = NULL,
};