]>
Commit | Line | Data |
---|---|---|
65efcfce LB |
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 | * | |
896014f4 DL |
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 | |
65efcfce LB |
19 | */ |
20 | ||
21 | /* stub rfp */ | |
22 | #include "rfp_internal.h" | |
f8b6f499 LB |
23 | #include "bgpd/rfapi/rfapi.h" |
24 | #include "lib/command.h" | |
65efcfce LB |
25 | |
26 | struct rfp_instance_t | |
27 | { | |
28 | struct rfapi_rfp_cfg rfapi_config; | |
29 | struct rfapi_rfp_cb_methods rfapi_callbacks; | |
30 | struct thread_master *master; | |
31 | uint32_t config_var; | |
32 | }; | |
33 | ||
34 | struct rfp_instance_t 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", | |
034d2de2 DS |
43 | RFP_SHOW_STR |
44 | "Example value to be configured\n" | |
45 | "Value to display") | |
65efcfce LB |
46 | { |
47 | uint32_t value = 0; | |
48 | struct rfp_instance_t *rfi = NULL; | |
52c6b0e2 | 49 | rfi = rfapi_get_rfp_start_val (VTY_GET_CONTEXT (bgp)); /* BGP_NODE */ |
65efcfce LB |
50 | assert (rfi != NULL); |
51 | ||
facfee22 | 52 | value = strtoul(argv[2]->arg, NULL, 10); |
65efcfce LB |
53 | if (rfi) |
54 | rfi->config_var = value; | |
55 | return CMD_SUCCESS; | |
56 | } | |
57 | ||
58 | static void | |
59 | rfp_vty_install () | |
60 | { | |
61 | static int installed = 0; | |
62 | if (installed) /* do this only once */ | |
63 | return; | |
64 | installed = 1; | |
65 | /* example of new cli command */ | |
66 | install_element (BGP_NODE, &rfp_example_config_value_cmd); | |
67 | } | |
68 | ||
69 | /*********************************************************************** | |
70 | * RFAPI Callbacks | |
71 | **********************************************************************/ | |
72 | ||
73 | /*------------------------------------------ | |
74 | * rfp_response_cb | |
75 | * | |
76 | * Callbacks of this type are used to provide asynchronous | |
77 | * route updates from RFAPI to the RFP client. | |
78 | * | |
79 | * response_cb | |
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. | |
84 | * | |
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 | |
88 | * flag is set. | |
89 | * | |
90 | * input: | |
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. | |
96 | * | |
97 | * userdata value (cookie) originally specified in call to | |
98 | * rfapi_open() | |
99 | * | |
100 | *------------------------------------------*/ | |
101 | static void | |
102 | rfp_response_cb (struct rfapi_next_hop_entry *next_hops, void *userdata) | |
103 | { | |
104 | /* | |
105 | * Identify NVE based on userdata, which is a value passed | |
106 | * to RFAPI in the rfapi_open call | |
107 | */ | |
108 | ||
109 | /* process list of next_hops */ | |
110 | ||
111 | /* free next hops */ | |
112 | rfapi_free_next_hop_list (next_hops); | |
113 | return; | |
114 | } | |
115 | ||
116 | /*------------------------------------------ | |
117 | * rfp_local_cb | |
118 | * | |
119 | * Callbacks of this type are used to provide asynchronous | |
120 | * route updates from RFAPI to the RFP client. | |
121 | * | |
122 | * local_cb | |
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. | |
126 | * | |
127 | * input: | |
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. | |
133 | * | |
134 | * userdata value (cookie) originally specified in call to | |
135 | * rfapi_open() | |
136 | * | |
137 | *------------------------------------------*/ | |
138 | static void | |
139 | rfp_local_cb (struct rfapi_next_hop_entry *next_hops, void *userdata) | |
140 | { | |
141 | /* | |
142 | * Identify NVE based on userdata, which is a value passed | |
143 | * to RFAPI in the rfapi_open call | |
144 | */ | |
145 | ||
146 | /* process list of local next_hops */ | |
147 | ||
148 | /* free next hops */ | |
149 | rfapi_free_next_hop_list (next_hops); | |
150 | return; | |
151 | } | |
152 | ||
153 | /*------------------------------------------ | |
154 | * rfp_close_cb | |
155 | * | |
156 | * Callbacks used to provide asynchronous | |
157 | * notification that an rfapi_handle was invalidated | |
158 | * | |
159 | * input: | |
160 | * pHandle Firmerly valid rfapi_handle returned to | |
161 | * client via rfapi_open(). | |
162 | * | |
163 | * reason EIDRM handle administratively closed (clear nve ...) | |
164 | * ESTALE handle invalidated by configuration change | |
165 | * | |
166 | *------------------------------------------*/ | |
167 | static void | |
168 | rfp_close_cb (rfapi_handle pHandle, int reason) | |
169 | { | |
170 | /* close / invalidate NVE with the pHandle returned by the rfapi_open call */ | |
171 | return; | |
172 | } | |
173 | ||
174 | /*------------------------------------------ | |
175 | * rfp_cfg_write_cb | |
176 | * | |
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. | |
180 | * | |
181 | * input: | |
182 | * vty -- quagga vty context | |
183 | * rfp_start_val -- value returned by rfp_start | |
184 | * | |
185 | * output: | |
186 | * to vty, rfp related configuration | |
187 | * | |
188 | * return value: | |
189 | * lines written | |
190 | --------------------------------------------*/ | |
191 | static int | |
192 | rfp_cfg_write_cb (struct vty *vty, void *rfp_start_val) | |
193 | { | |
194 | struct rfp_instance_t *rfi = rfp_start_val; | |
195 | int write = 0; | |
196 | assert (rfp_start_val != NULL); | |
197 | if (rfi->config_var != 0) | |
198 | { | |
199 | vty_out (vty, " rfp example-config-value %u", rfi->config_var); | |
200 | vty_out (vty, "%s", VTY_NEWLINE); | |
201 | write++; | |
202 | } | |
203 | ||
204 | return write; | |
205 | } | |
206 | ||
207 | /*********************************************************************** | |
208 | * RFAPI required functions | |
209 | **********************************************************************/ | |
210 | ||
211 | /*------------------------------------------ | |
212 | * rfp_start | |
213 | * | |
214 | * This function will start the RFP code | |
215 | * | |
216 | * input: | |
217 | * master quagga thread_master to tie into bgpd threads | |
218 | * | |
219 | * output: | |
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 | |
224 | * | |
225 | * return value: | |
226 | * rfp_start_val rfp returned value passed on rfp_stop and rfp_cfg_write | |
227 | * | |
228 | --------------------------------------------*/ | |
229 | void * | |
230 | rfp_start (struct thread_master *master, | |
231 | struct rfapi_rfp_cfg **cfgp, struct rfapi_rfp_cb_methods **cbmp) | |
232 | { | |
233 | memset (&global_rfi, 0, sizeof (struct rfp_instance_t)); | |
234 | global_rfi.master = master; /* for BGPD threads */ | |
235 | ||
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 */ | |
243 | ||
244 | ||
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; | |
251 | ||
252 | if (cfgp != NULL) | |
253 | *cfgp = &global_rfi.rfapi_config; | |
254 | if (cbmp != NULL) | |
255 | *cbmp = &global_rfi.rfapi_callbacks; | |
256 | ||
257 | rfp_vty_install (); | |
258 | ||
259 | return &global_rfi; | |
260 | } | |
261 | ||
262 | /*------------------------------------------ | |
263 | * rfp_stop | |
264 | * | |
265 | * This function is called on shutdown to trigger RFP cleanup | |
266 | * | |
267 | * input: | |
268 | * none | |
269 | * | |
270 | * output: | |
271 | * none | |
272 | * | |
273 | * return value: | |
274 | * rfp_start_val | |
275 | --------------------------------------------*/ | |
276 | void | |
277 | rfp_stop (void *rfp_start_val) | |
278 | { | |
279 | assert (rfp_start_val != NULL); | |
280 | } | |
281 | ||
282 | /* TO BE REMOVED */ | |
283 | void | |
284 | rfp_clear_vnc_nve_all (void) | |
285 | { | |
286 | return; | |
287 | } |