blob: a19fae10a1ccc33b12ac1a3d8b473f3c29c351ea [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __FIB_ENTRY_SRC_H__
17#define __FIB_ENTRY_SRC_H__
18
19#include "fib_entry.h"
20#include "fib_path_list.h"
21#include "fib_internal.h"
22
23/**
24 * Debug macro
25 */
26#ifdef FIB_DEBUG
27#define FIB_ENTRY_DBG(_e, _fmt, _args...) \
28{ \
29 u8*__tmp = NULL; \
30 __tmp = format(__tmp, "e:[%d:%U", \
31 fib_entry_get_index(_e), \
32 format_ip46_address, \
33 &_e->fe_prefix.fp_addr, \
34 IP46_TYPE_ANY); \
35 __tmp = format(__tmp, "/%d]:", \
36 _e->fe_prefix.fp_len); \
37 __tmp = format(__tmp, _fmt, ##_args); \
38 clib_warning("%s", __tmp); \
39 vec_free(__tmp); \
40}
41#else
42#define FIB_ENTRY_DBG(_e, _fmt, _args...)
43#endif
44
45/**
46 * Source initialisation Function
47 */
48typedef void (*fib_entry_src_init_t)(fib_entry_src_t *src);
49
50/**
51 * Source deinitialisation Function
52 */
53typedef void (*fib_entry_src_deinit_t)(fib_entry_src_t *src);
54
55/**
56 * Source activation. Called when the source is the new best source on the entry.
57 * Return non-zero if the entry can now install, 0 otherwise
58 */
59typedef int (*fib_entry_src_activate_t)(fib_entry_src_t *src,
60 const fib_entry_t *fib_entry);
61
62/**
63 * Source Deactivate.
64 * Called when the source is no longer best source on the entry
65 */
66typedef void (*fib_entry_src_deactivate_t)(fib_entry_src_t *src,
67 const fib_entry_t *fib_entry);
68
69/**
70 * Source Add.
71 * Called when the source is added to the entry
72 */
73typedef void (*fib_entry_src_add_t)(fib_entry_src_t *src,
74 const fib_entry_t *entry,
75 fib_entry_flag_t flags,
Neale Rannsda78f952017-05-24 09:15:43 -070076 dpo_proto_t proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010077 const dpo_id_t *dpo);
78
79/**
80 * Source Remove.
81 */
82typedef void (*fib_entry_src_remove_t)(fib_entry_src_t *src);
83
84/**
85 * Result from a cover update/change
86 */
87typedef struct fib_entry_src_cover_res_t_ {
88 u16 install;
89 fib_node_bw_reason_flag_t bw_reason;
90} fib_entry_src_cover_res_t;
91
92/**
93 * Cover changed. the source should re-evaluate its cover.
94 */
95typedef fib_entry_src_cover_res_t (*fib_entry_src_cover_change_t)(
96 fib_entry_src_t *src,
97 const fib_entry_t *fib_entry);
98
99/**
100 * Cover updated. The cover the source has, has updated (i.e. its forwarding)
101 * the source may need to re-evaluate.
102 */
103typedef fib_entry_src_cover_res_t (*fib_entry_src_cover_update_t)(
104 fib_entry_src_t *src,
105 const fib_entry_t *fib_entry);
106
107/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100108 * Installed. Notification that the source is now installed as
109 * the entry's forwarding source.
110 */
111typedef void (*fib_entry_src_installed_t)(fib_entry_src_t *src,
112 const fib_entry_t *fib_entry);
113
114/**
115 * format.
116 */
117typedef u8* (*fib_entry_src_format_t)(fib_entry_src_t *src,
118 u8* s);
119
120/**
121 * Source path add
122 * the source is adding a new path
123 */
124typedef void (*fib_entry_src_path_add_t)(fib_entry_src_t *src,
125 const fib_entry_t *fib_entry,
126 fib_path_list_flags_t pl_flags,
127 const fib_route_path_t *path);
128
129/**
130 * Source path remove
131 * the source is remoinvg a path
132 */
133typedef void (*fib_entry_src_path_remove_t)(fib_entry_src_t *src,
134 fib_path_list_flags_t pl_flags,
135 const fib_route_path_t *path);
136
137/**
138 * Source path replace/swap
139 * the source is providing a new set of paths
140 */
141typedef void (*fib_entry_src_path_swap_t)(fib_entry_src_t *src,
142 const fib_entry_t *fib_entry,
143 fib_path_list_flags_t pl_flags,
144 const fib_route_path_t *path);
145
146/**
147 * Set source specific opaque data
148 */
149typedef void (*fib_entry_src_set_data_t)(fib_entry_src_t *src,
150 const fib_entry_t *fib_entry,
151 const void *data);
152
153/**
154 * Get source specific opaque data
155 */
156typedef const void* (*fib_entry_src_get_data_t)(fib_entry_src_t *src,
157 const fib_entry_t *fib_entry);
158
159/**
160 * Virtual function table each FIB entry source will register
161 */
162typedef struct fib_entry_src_vft_t_ {
163 fib_entry_src_init_t fesv_init;
164 fib_entry_src_deinit_t fesv_deinit;
165 fib_entry_src_activate_t fesv_activate;
166 fib_entry_src_deactivate_t fesv_deactivate;
167 fib_entry_src_add_t fesv_add;
168 fib_entry_src_remove_t fesv_remove;
169 fib_entry_src_path_swap_t fesv_path_swap;
170 fib_entry_src_path_add_t fesv_path_add;
171 fib_entry_src_path_remove_t fesv_path_remove;
172 fib_entry_src_cover_change_t fesv_cover_change;
173 fib_entry_src_cover_update_t fesv_cover_update;
174 fib_entry_src_format_t fesv_format;
175 fib_entry_src_installed_t fesv_installed;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100176 fib_entry_src_get_data_t fesv_get_data;
177 fib_entry_src_set_data_t fesv_set_data;
178} fib_entry_src_vft_t;
179
Neale Ranns84517cf2017-11-25 15:20:26 -0800180#define FOR_EACH_SRC_ADDED(_entry, _src, _source, action) \
181{ \
182 if (fib_entry_has_multiple_srcs(_entry)) \
183 { \
184 vec_foreach(_src, _entry->fe_u_src.fe_srcs) \
185 { \
186 if (_src->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED) { \
187 _source = _src->fes_src; \
188 do { \
189 action; \
190 } while(0); \
191 } \
192 } \
193 } \
194 else \
195 { \
196 _src = &_entry->fe_u_src.fe_src; \
197 if (_src->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED) { \
198 _source = _src->fes_src; \
199 do { \
200 action; \
201 } while(0); \
202 } \
203 } \
204}
205
206#define FOR_EACH_SRC(_entry, _src, _source, action) \
207{ \
208 if (fib_entry_has_multiple_srcs(_entry)) \
209 { \
210 vec_foreach(_src, _entry->fe_u_src.fe_srcs) \
211 { \
212 _source = _src->fes_src; \
213 do { \
214 action; \
215 } while(0); \
216 } \
217 } \
218 else \
219 { \
220 _src = &_entry->fe_u_src.fe_src; \
221 _source = _src->fes_src; \
222 do { \
223 action; \
224 } while(0); \
225 } \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100226}
227
228extern u8* fib_entry_src_format(fib_entry_t *entry,
229 fib_source_t source,
230 u8* s);
231
232extern void fib_entry_src_register(fib_source_t source,
233 const fib_entry_src_vft_t *vft);
234
235extern void fib_entry_src_action_init(fib_entry_t *entry,
236 fib_source_t source);
237
238extern void fib_entry_src_action_deinit(fib_entry_t *fib_entry,
239 fib_source_t source);
240
241extern fib_entry_src_cover_res_t fib_entry_src_action_cover_change(
242 fib_entry_t *entry,
243 fib_source_t source);
244
245extern fib_entry_src_cover_res_t fib_entry_src_action_cover_update(
246 fib_entry_t *fib_entry,
247 fib_source_t source);
248
249extern void fib_entry_src_action_activate(fib_entry_t *fib_entry,
250 fib_source_t source);
251
252extern void fib_entry_src_action_deactivate(fib_entry_t *fib_entry,
253 fib_source_t source);
254extern void fib_entry_src_action_reactivate(fib_entry_t *fib_entry,
255 fib_source_t source);
256
257extern fib_entry_t* fib_entry_src_action_add(fib_entry_t *fib_entry,
258 fib_source_t source,
259 fib_entry_flag_t flags,
260 const dpo_id_t *dpo);
Neale Ranns948e00f2016-10-20 13:39:34 +0100261extern fib_entry_t* fib_entry_src_action_update(fib_entry_t *fib_entry,
262 fib_source_t source,
263 fib_entry_flag_t flags,
264 const dpo_id_t *dpo);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100265
266extern fib_entry_src_flag_t fib_entry_src_action_remove(fib_entry_t *fib_entry,
267 fib_source_t source);
268
269extern void fib_entry_src_action_install(fib_entry_t *fib_entry,
270 fib_source_t source);
271
272extern void fib_entry_src_action_uninstall(fib_entry_t *fib_entry);
273
274extern fib_entry_t* fib_entry_src_action_path_add(fib_entry_t *fib_entry,
275 fib_source_t source,
276 fib_entry_flag_t flags,
277 const fib_route_path_t *path);
278
279extern fib_entry_t* fib_entry_src_action_path_swap(fib_entry_t *fib_entry,
280 fib_source_t source,
281 fib_entry_flag_t flags,
282 const fib_route_path_t *path);
283
284extern fib_entry_src_flag_t fib_entry_src_action_path_remove(fib_entry_t *fib_entry,
285 fib_source_t source,
286 const fib_route_path_t *path);
287
Neale Ranns84517cf2017-11-25 15:20:26 -0800288extern void fib_entry_src_action_installed(fib_entry_t *fib_entry,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100289 fib_source_t source);
290
291extern fib_forward_chain_type_t fib_entry_get_default_chain_type(
292 const fib_entry_t *fib_entry);
293extern fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry);
294extern fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags(
295 fib_entry_flag_t eflags);
296
Neale Rannsad422ed2016-11-02 14:20:04 +0000297extern fib_forward_chain_type_t fib_entry_chain_type_fixup(const fib_entry_t *entry,
298 fib_forward_chain_type_t fct);
299
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100300extern void fib_entry_src_mk_lb (fib_entry_t *fib_entry,
301 const fib_entry_src_t *esrc,
302 fib_forward_chain_type_t fct,
303 dpo_id_t *dpo_lb);
304
Neale Rannsda78f952017-05-24 09:15:43 -0700305extern fib_protocol_t fib_entry_get_proto(const fib_entry_t * fib_entry);
306extern dpo_proto_t fib_entry_get_dpo_proto(const fib_entry_t * fib_entry);
Neale Ranns84517cf2017-11-25 15:20:26 -0800307extern u32 fib_entry_has_multiple_srcs(const fib_entry_t * fib_entry);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100308
309/*
310 * Per-source registration. declared here so we save a separate .h file for each
311 */
312extern void fib_entry_src_default_register(void);
313extern void fib_entry_src_rr_register(void);
314extern void fib_entry_src_interface_register(void);
315extern void fib_entry_src_default_route_register(void);
316extern void fib_entry_src_special_register(void);
317extern void fib_entry_src_api_register(void);
318extern void fib_entry_src_adj_register(void);
319extern void fib_entry_src_mpls_register(void);
320extern void fib_entry_src_lisp_register(void);
321
322extern void fib_entry_src_module_init(void);
323
324#endif