]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfp-example/librfp/rfp_example.c
Merge branch 'stable/3.0' into tmp-3.0-master-merge
[mirror_frr.git] / bgpd / rfp-example / librfp / rfp_example.c
1 /*
2 *
3 * Copyright 2015-2016, LabN Consulting, L.L.C.
4 *
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /* stub rfp */
22 #include "rfp_internal.h"
23 #include "bgpd/rfapi/rfapi.h"
24 #include "lib/command.h"
25
26 struct rfp_instance_t {
27 struct rfapi_rfp_cfg rfapi_config;
28 struct rfapi_rfp_cb_methods rfapi_callbacks;
29 struct thread_master *master;
30 uint32_t config_var;
31 };
32
33 struct rfp_instance_t
34 global_rfi; /* dynamically allocate in full implementation */
35
36 /***********************************************************************
37 * Sample VTY / internal function
38 **********************************************************************/
39 #define RFP_SHOW_STR "RFP information\n"
40 DEFUN (rfp_example_config_value,
41 rfp_example_config_value_cmd,
42 "rfp example-config-value VALUE",
43 RFP_SHOW_STR
44 "Example value to be configured\n"
45 "Value to display")
46 {
47 uint32_t value = 0;
48 struct rfp_instance_t *rfi = NULL;
49 rfi = rfapi_get_rfp_start_val(VTY_GET_CONTEXT(bgp)); /* BGP_NODE */
50 assert(rfi != NULL);
51
52 value = strtoul(argv[2]->arg, NULL, 10);
53 if (rfi)
54 rfi->config_var = value;
55 return CMD_SUCCESS;
56 }
57
58 static void rfp_vty_install()
59 {
60 static int installed = 0;
61 if (installed) /* do this only once */
62 return;
63 installed = 1;
64 /* example of new cli command */
65 install_element(BGP_NODE, &rfp_example_config_value_cmd);
66 }
67
68 /***********************************************************************
69 * RFAPI Callbacks
70 **********************************************************************/
71
72 /*------------------------------------------
73 * rfp_response_cb
74 *
75 * Callbacks of this type are used to provide asynchronous
76 * route updates from RFAPI to the RFP client.
77 *
78 * response_cb
79 * called to notify the rfp client that a next hop list
80 * that has previously been provided in response to an
81 * rfapi_query call has been updated. Deleted routes are indicated
82 * with lifetime==RFAPI_REMOVE_RESPONSE_LIFETIME.
83 *
84 * By default, the routes an NVE receives via this callback include
85 * its own routes (that it has registered). However, these may be
86 * filtered out if the global BGP_VNC_CONFIG_FILTER_SELF_FROM_RSP
87 * flag is set.
88 *
89 * input:
90 * next_hops a list of possible next hops.
91 * This is a linked list allocated within the
92 * rfapi. The response_cb callback function is responsible
93 * for freeing this memory via rfapi_free_next_hop_list()
94 * in order to avoid memory leaks.
95 *
96 * userdata value (cookie) originally specified in call to
97 * rfapi_open()
98 *
99 *------------------------------------------*/
100 static void rfp_response_cb(struct rfapi_next_hop_entry *next_hops,
101 void *userdata)
102 {
103 /*
104 * Identify NVE based on userdata, which is a value passed
105 * to RFAPI in the rfapi_open call
106 */
107
108 /* process list of next_hops */
109
110 /* free next hops */
111 rfapi_free_next_hop_list(next_hops);
112 return;
113 }
114
115 /*------------------------------------------
116 * rfp_local_cb
117 *
118 * Callbacks of this type are used to provide asynchronous
119 * route updates from RFAPI to the RFP client.
120 *
121 * local_cb
122 * called to notify the rfp client that a local route
123 * has been added or deleted. Deleted routes are indicated
124 * with lifetime==RFAPI_REMOVE_RESPONSE_LIFETIME.
125 *
126 * input:
127 * next_hops a list of possible next hops.
128 * This is a linked list allocated within the
129 * rfapi. The local_cb callback function is responsible
130 * for freeing this memory via rfapi_free_next_hop_list()
131 * in order to avoid memory leaks.
132 *
133 * userdata value (cookie) originally specified in call to
134 * rfapi_open()
135 *
136 *------------------------------------------*/
137 static void rfp_local_cb(struct rfapi_next_hop_entry *next_hops, void *userdata)
138 {
139 /*
140 * Identify NVE based on userdata, which is a value passed
141 * to RFAPI in the rfapi_open call
142 */
143
144 /* process list of local next_hops */
145
146 /* free next hops */
147 rfapi_free_next_hop_list(next_hops);
148 return;
149 }
150
151 /*------------------------------------------
152 * rfp_close_cb
153 *
154 * Callbacks used to provide asynchronous
155 * notification that an rfapi_handle was invalidated
156 *
157 * input:
158 * pHandle Firmerly valid rfapi_handle returned to
159 * client via rfapi_open().
160 *
161 * reason EIDRM handle administratively closed (clear nve ...)
162 * ESTALE handle invalidated by configuration change
163 *
164 *------------------------------------------*/
165 static void rfp_close_cb(rfapi_handle pHandle, int reason)
166 {
167 /* close / invalidate NVE with the pHandle returned by the rfapi_open
168 * call */
169 return;
170 }
171
172 /*------------------------------------------
173 * rfp_cfg_write_cb
174 *
175 * This callback is used to generate output for any config parameters
176 * that may supported by RFP via RFP defined vty commands at the bgp
177 * level. See loglevel as an example.
178 *
179 * input:
180 * vty -- quagga vty context
181 * rfp_start_val -- value returned by rfp_start
182 *
183 * output:
184 * to vty, rfp related configuration
185 *
186 * return value:
187 * lines written
188 --------------------------------------------*/
189 static int rfp_cfg_write_cb(struct vty *vty, void *rfp_start_val)
190 {
191 struct rfp_instance_t *rfi = rfp_start_val;
192 int write = 0;
193 assert(rfp_start_val != NULL);
194 if (rfi->config_var != 0) {
195 vty_out(vty, " rfp example-config-value %u", rfi->config_var);
196 vty_out(vty, "\n");
197 write++;
198 }
199
200 return write;
201 }
202
203 /***********************************************************************
204 * RFAPI required functions
205 **********************************************************************/
206
207 /*------------------------------------------
208 * rfp_start
209 *
210 * This function will start the RFP code
211 *
212 * input:
213 * master quagga thread_master to tie into bgpd threads
214 *
215 * output:
216 * cfgp Pointer to rfapi_rfp_cfg (null = use defaults),
217 * copied by caller, updated via rfp_set_configuration
218 * cbmp Pointer to rfapi_rfp_cb_methods, may be null
219 * copied by caller, updated via rfapi_rfp_set_cb_methods
220 *
221 * return value:
222 * rfp_start_val rfp returned value passed on rfp_stop and rfp_cfg_write
223 *
224 --------------------------------------------*/
225 void *rfp_start(struct thread_master *master, struct rfapi_rfp_cfg **cfgp,
226 struct rfapi_rfp_cb_methods **cbmp)
227 {
228 memset(&global_rfi, 0, sizeof(struct rfp_instance_t));
229 global_rfi.master = master; /* for BGPD threads */
230
231 /* initilize struct rfapi_rfp_cfg, see rfapi.h */
232 global_rfi.rfapi_config.download_type =
233 RFAPI_RFP_DOWNLOAD_FULL; /* default=partial */
234 global_rfi.rfapi_config.ftd_advertisement_interval =
235 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL;
236 global_rfi.rfapi_config.holddown_factor =
237 0; /* default: RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR */
238 global_rfi.rfapi_config.use_updated_response = 1; /* 0=no */
239 global_rfi.rfapi_config.use_removes = 1; /* 0=no */
240
241
242 /* initilize structrfapi_rfp_cb_methods , see rfapi.h */
243 global_rfi.rfapi_callbacks.cfg_cb = rfp_cfg_write_cb;
244 /* no group config */
245 global_rfi.rfapi_callbacks.response_cb = rfp_response_cb;
246 global_rfi.rfapi_callbacks.local_cb = rfp_local_cb;
247 global_rfi.rfapi_callbacks.close_cb = rfp_close_cb;
248
249 if (cfgp != NULL)
250 *cfgp = &global_rfi.rfapi_config;
251 if (cbmp != NULL)
252 *cbmp = &global_rfi.rfapi_callbacks;
253
254 rfp_vty_install();
255
256 return &global_rfi;
257 }
258
259 /*------------------------------------------
260 * rfp_stop
261 *
262 * This function is called on shutdown to trigger RFP cleanup
263 *
264 * input:
265 * none
266 *
267 * output:
268 * none
269 *
270 * return value:
271 * rfp_start_val
272 --------------------------------------------*/
273 void rfp_stop(void *rfp_start_val)
274 {
275 assert(rfp_start_val != NULL);
276 }
277
278 /* TO BE REMOVED */
279 void rfp_clear_vnc_nve_all(void)
280 {
281 return;
282 }