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"
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
;
34 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 value
= strtoul(argv
[2]->arg
, NULL
, 10);
54 rfi
->config_var
= value
;
58 static void rfp_vty_install()
60 static int installed
= 0;
61 if (installed
) /* do this only once */
64 /* example of new cli command */
65 install_element(BGP_NODE
, &rfp_example_config_value_cmd
);
68 /***********************************************************************
70 **********************************************************************/
72 /*------------------------------------------
75 * Callbacks of this type are used to provide asynchronous
76 * route updates from RFAPI to the RFP client.
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.
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
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.
96 * userdata value (cookie) originally specified in call to
99 *------------------------------------------*/
100 static void rfp_response_cb(struct rfapi_next_hop_entry
*next_hops
,
104 * Identify NVE based on userdata, which is a value passed
105 * to RFAPI in the rfapi_open call
108 /* process list of next_hops */
111 rfapi_free_next_hop_list(next_hops
);
115 /*------------------------------------------
118 * Callbacks of this type are used to provide asynchronous
119 * route updates from RFAPI to the RFP client.
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.
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.
133 * userdata value (cookie) originally specified in call to
136 *------------------------------------------*/
137 static void rfp_local_cb(struct rfapi_next_hop_entry
*next_hops
, void *userdata
)
140 * Identify NVE based on userdata, which is a value passed
141 * to RFAPI in the rfapi_open call
144 /* process list of local next_hops */
147 rfapi_free_next_hop_list(next_hops
);
151 /*------------------------------------------
154 * Callbacks used to provide asynchronous
155 * notification that an rfapi_handle was invalidated
158 * pHandle Firmerly valid rfapi_handle returned to
159 * client via rfapi_open().
161 * reason EIDRM handle administratively closed (clear nve ...)
162 * ESTALE handle invalidated by configuration change
164 *------------------------------------------*/
165 static void rfp_close_cb(rfapi_handle pHandle
, int reason
)
167 /* close / invalidate NVE with the pHandle returned by the rfapi_open
172 /*------------------------------------------
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.
180 * vty -- quagga vty context
181 * rfp_start_val -- value returned by rfp_start
184 * to vty, rfp related configuration
188 --------------------------------------------*/
189 static int rfp_cfg_write_cb(struct vty
*vty
, void *rfp_start_val
)
191 struct rfp_instance_t
*rfi
= rfp_start_val
;
193 assert(rfp_start_val
!= NULL
);
194 if (rfi
->config_var
!= 0) {
195 vty_out(vty
, " rfp example-config-value %u", rfi
->config_var
);
203 /***********************************************************************
204 * RFAPI required functions
205 **********************************************************************/
207 /*------------------------------------------
210 * This function will start the RFP code
213 * master quagga thread_master to tie into bgpd threads
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
222 * rfp_start_val rfp returned value passed on rfp_stop and rfp_cfg_write
224 --------------------------------------------*/
225 void *rfp_start(struct thread_master
*master
, struct rfapi_rfp_cfg
**cfgp
,
226 struct rfapi_rfp_cb_methods
**cbmp
)
228 memset(&global_rfi
, 0, sizeof(struct rfp_instance_t
));
229 global_rfi
.master
= master
; /* for BGPD threads */
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 */
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
;
250 *cfgp
= &global_rfi
.rfapi_config
;
252 *cbmp
= &global_rfi
.rfapi_callbacks
;
259 /*------------------------------------------
262 * This function is called on shutdown to trigger RFP cleanup
272 --------------------------------------------*/
273 void rfp_stop(void *rfp_start_val
)
275 assert(rfp_start_val
!= NULL
);
279 void rfp_clear_vnc_nve_all(void)