3 * Copyright 2015-2016, LabN Consulting, L.L.C.
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.
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.
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
22 #include "rfp_internal.h"
23 #include "bgpd/rfapi/rfapi.h"
24 #include "lib/command.h"
28 struct rfapi_rfp_cfg rfapi_config
;
29 struct rfapi_rfp_cb_methods rfapi_callbacks
;
30 struct thread_master
*master
;
34 struct rfp_instance_t global_rfi
; /* dynamically allocate in full implementation */
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",
44 "Example value to be configured\n"
48 struct rfp_instance_t
*rfi
= NULL
;
49 rfi
= rfapi_get_rfp_start_val (VTY_GET_CONTEXT (bgp
)); /* BGP_NODE */
52 VTY_GET_INTEGER ("Example value", value
, argv
[2]->arg
);
54 rfi
->config_var
= value
;
61 static int installed
= 0;
62 if (installed
) /* do this only once */
65 /* example of new cli command */
66 install_element (BGP_NODE
, &rfp_example_config_value_cmd
);
69 /***********************************************************************
71 **********************************************************************/
73 /*------------------------------------------
76 * Callbacks of this type are used to provide asynchronous
77 * route updates from RFAPI to the RFP client.
80 * called to notify the rfp client that a next hop list
81 * that has previously been provided in response to an
82 * rfapi_query call has been updated. Deleted routes are indicated
83 * with lifetime==RFAPI_REMOVE_RESPONSE_LIFETIME.
85 * By default, the routes an NVE receives via this callback include
86 * its own routes (that it has registered). However, these may be
87 * filtered out if the global BGP_VNC_CONFIG_FILTER_SELF_FROM_RSP
91 * next_hops a list of possible next hops.
92 * This is a linked list allocated within the
93 * rfapi. The response_cb callback function is responsible
94 * for freeing this memory via rfapi_free_next_hop_list()
95 * in order to avoid memory leaks.
97 * userdata value (cookie) originally specified in call to
100 *------------------------------------------*/
102 rfp_response_cb (struct rfapi_next_hop_entry
*next_hops
, void *userdata
)
105 * Identify NVE based on userdata, which is a value passed
106 * to RFAPI in the rfapi_open call
109 /* process list of next_hops */
112 rfapi_free_next_hop_list (next_hops
);
116 /*------------------------------------------
119 * Callbacks of this type are used to provide asynchronous
120 * route updates from RFAPI to the RFP client.
123 * called to notify the rfp client that a local route
124 * has been added or deleted. Deleted routes are indicated
125 * with lifetime==RFAPI_REMOVE_RESPONSE_LIFETIME.
128 * next_hops a list of possible next hops.
129 * This is a linked list allocated within the
130 * rfapi. The local_cb callback function is responsible
131 * for freeing this memory via rfapi_free_next_hop_list()
132 * in order to avoid memory leaks.
134 * userdata value (cookie) originally specified in call to
137 *------------------------------------------*/
139 rfp_local_cb (struct rfapi_next_hop_entry
*next_hops
, void *userdata
)
142 * Identify NVE based on userdata, which is a value passed
143 * to RFAPI in the rfapi_open call
146 /* process list of local next_hops */
149 rfapi_free_next_hop_list (next_hops
);
153 /*------------------------------------------
156 * Callbacks used to provide asynchronous
157 * notification that an rfapi_handle was invalidated
160 * pHandle Firmerly valid rfapi_handle returned to
161 * client via rfapi_open().
163 * reason EIDRM handle administratively closed (clear nve ...)
164 * ESTALE handle invalidated by configuration change
166 *------------------------------------------*/
168 rfp_close_cb (rfapi_handle pHandle
, int reason
)
170 /* close / invalidate NVE with the pHandle returned by the rfapi_open call */
174 /*------------------------------------------
177 * This callback is used to generate output for any config parameters
178 * that may supported by RFP via RFP defined vty commands at the bgp
179 * level. See loglevel as an example.
182 * vty -- quagga vty context
183 * rfp_start_val -- value returned by rfp_start
186 * to vty, rfp related configuration
190 --------------------------------------------*/
192 rfp_cfg_write_cb (struct vty
*vty
, void *rfp_start_val
)
194 struct rfp_instance_t
*rfi
= rfp_start_val
;
196 assert (rfp_start_val
!= NULL
);
197 if (rfi
->config_var
!= 0)
199 vty_out (vty
, " rfp example-config-value %u", rfi
->config_var
);
200 vty_out (vty
, "%s", VTY_NEWLINE
);
207 /***********************************************************************
208 * RFAPI required functions
209 **********************************************************************/
211 /*------------------------------------------
214 * This function will start the RFP code
217 * master quagga thread_master to tie into bgpd threads
220 * cfgp Pointer to rfapi_rfp_cfg (null = use defaults),
221 * copied by caller, updated via rfp_set_configuration
222 * cbmp Pointer to rfapi_rfp_cb_methods, may be null
223 * copied by caller, updated via rfapi_rfp_set_cb_methods
226 * rfp_start_val rfp returned value passed on rfp_stop and rfp_cfg_write
228 --------------------------------------------*/
230 rfp_start (struct thread_master
*master
,
231 struct rfapi_rfp_cfg
**cfgp
, struct rfapi_rfp_cb_methods
**cbmp
)
233 memset (&global_rfi
, 0, sizeof (struct rfp_instance_t
));
234 global_rfi
.master
= master
; /* for BGPD threads */
236 /* initilize struct rfapi_rfp_cfg, see rfapi.h */
237 global_rfi
.rfapi_config
.download_type
= RFAPI_RFP_DOWNLOAD_FULL
; /* default=partial */
238 global_rfi
.rfapi_config
.ftd_advertisement_interval
=
239 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
240 global_rfi
.rfapi_config
.holddown_factor
= 0; /* default: RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR */
241 global_rfi
.rfapi_config
.use_updated_response
= 1; /* 0=no */
242 global_rfi
.rfapi_config
.use_removes
= 1; /* 0=no */
245 /* initilize structrfapi_rfp_cb_methods , see rfapi.h */
246 global_rfi
.rfapi_callbacks
.cfg_cb
= rfp_cfg_write_cb
;
247 /* no group config */
248 global_rfi
.rfapi_callbacks
.response_cb
= rfp_response_cb
;
249 global_rfi
.rfapi_callbacks
.local_cb
= rfp_local_cb
;
250 global_rfi
.rfapi_callbacks
.close_cb
= rfp_close_cb
;
253 *cfgp
= &global_rfi
.rfapi_config
;
255 *cbmp
= &global_rfi
.rfapi_callbacks
;
262 /*------------------------------------------
265 * This function is called on shutdown to trigger RFP cleanup
275 --------------------------------------------*/
277 rfp_stop (void *rfp_start_val
)
279 assert (rfp_start_val
!= NULL
);
284 rfp_clear_vnc_nve_all (void)