Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 48 | typedef void (*fib_entry_src_init_t)(fib_entry_src_t *src); |
| 49 | |
| 50 | /** |
| 51 | * Source deinitialisation Function |
| 52 | */ |
| 53 | typedef 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 | */ |
| 59 | typedef int (*fib_entry_src_activate_t)(fib_entry_src_t *src, |
| 60 | const fib_entry_t *fib_entry); |
| 61 | |
| 62 | /** |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame^] | 63 | * Source re-activation. Called when the source is updated and remains |
| 64 | * the best source. |
| 65 | */ |
| 66 | typedef int (*fib_entry_src_reactivate_t)(fib_entry_src_t *src, |
| 67 | const fib_entry_t *fib_entry); |
| 68 | |
| 69 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 70 | * Source Deactivate. |
| 71 | * Called when the source is no longer best source on the entry |
| 72 | */ |
| 73 | typedef void (*fib_entry_src_deactivate_t)(fib_entry_src_t *src, |
| 74 | const fib_entry_t *fib_entry); |
| 75 | |
| 76 | /** |
| 77 | * Source Add. |
| 78 | * Called when the source is added to the entry |
| 79 | */ |
| 80 | typedef void (*fib_entry_src_add_t)(fib_entry_src_t *src, |
| 81 | const fib_entry_t *entry, |
| 82 | fib_entry_flag_t flags, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 83 | dpo_proto_t proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 84 | const dpo_id_t *dpo); |
| 85 | |
| 86 | /** |
| 87 | * Source Remove. |
| 88 | */ |
| 89 | typedef void (*fib_entry_src_remove_t)(fib_entry_src_t *src); |
| 90 | |
| 91 | /** |
| 92 | * Result from a cover update/change |
| 93 | */ |
| 94 | typedef struct fib_entry_src_cover_res_t_ { |
| 95 | u16 install; |
| 96 | fib_node_bw_reason_flag_t bw_reason; |
| 97 | } fib_entry_src_cover_res_t; |
| 98 | |
| 99 | /** |
| 100 | * Cover changed. the source should re-evaluate its cover. |
| 101 | */ |
| 102 | typedef fib_entry_src_cover_res_t (*fib_entry_src_cover_change_t)( |
| 103 | fib_entry_src_t *src, |
| 104 | const fib_entry_t *fib_entry); |
| 105 | |
| 106 | /** |
| 107 | * Cover updated. The cover the source has, has updated (i.e. its forwarding) |
| 108 | * the source may need to re-evaluate. |
| 109 | */ |
| 110 | typedef fib_entry_src_cover_res_t (*fib_entry_src_cover_update_t)( |
| 111 | fib_entry_src_t *src, |
| 112 | const fib_entry_t *fib_entry); |
| 113 | |
| 114 | /** |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 115 | * Forwarding updated. Notification that the forwarding information for the |
| 116 | * entry has been updated. This notification is sent to all sources, not just |
| 117 | * the active best. |
| 118 | */ |
| 119 | typedef void (*fib_entry_src_fwd_update_t)(fib_entry_src_t *src, |
| 120 | const fib_entry_t *fib_entry, |
| 121 | fib_source_t best_source); |
| 122 | |
| 123 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 124 | * Installed. Notification that the source is now installed as |
| 125 | * the entry's forwarding source. |
| 126 | */ |
| 127 | typedef void (*fib_entry_src_installed_t)(fib_entry_src_t *src, |
| 128 | const fib_entry_t *fib_entry); |
| 129 | |
| 130 | /** |
| 131 | * format. |
| 132 | */ |
| 133 | typedef u8* (*fib_entry_src_format_t)(fib_entry_src_t *src, |
| 134 | u8* s); |
| 135 | |
| 136 | /** |
| 137 | * Source path add |
| 138 | * the source is adding a new path |
| 139 | */ |
| 140 | typedef void (*fib_entry_src_path_add_t)(fib_entry_src_t *src, |
| 141 | const fib_entry_t *fib_entry, |
| 142 | fib_path_list_flags_t pl_flags, |
| 143 | const fib_route_path_t *path); |
| 144 | |
| 145 | /** |
| 146 | * Source path remove |
| 147 | * the source is remoinvg a path |
| 148 | */ |
| 149 | typedef void (*fib_entry_src_path_remove_t)(fib_entry_src_t *src, |
| 150 | fib_path_list_flags_t pl_flags, |
| 151 | const fib_route_path_t *path); |
| 152 | |
| 153 | /** |
| 154 | * Source path replace/swap |
| 155 | * the source is providing a new set of paths |
| 156 | */ |
| 157 | typedef void (*fib_entry_src_path_swap_t)(fib_entry_src_t *src, |
| 158 | const fib_entry_t *fib_entry, |
| 159 | fib_path_list_flags_t pl_flags, |
| 160 | const fib_route_path_t *path); |
| 161 | |
| 162 | /** |
| 163 | * Set source specific opaque data |
| 164 | */ |
| 165 | typedef void (*fib_entry_src_set_data_t)(fib_entry_src_t *src, |
| 166 | const fib_entry_t *fib_entry, |
| 167 | const void *data); |
| 168 | |
| 169 | /** |
| 170 | * Get source specific opaque data |
| 171 | */ |
| 172 | typedef const void* (*fib_entry_src_get_data_t)(fib_entry_src_t *src, |
| 173 | const fib_entry_t *fib_entry); |
| 174 | |
| 175 | /** |
| 176 | * Virtual function table each FIB entry source will register |
| 177 | */ |
| 178 | typedef struct fib_entry_src_vft_t_ { |
| 179 | fib_entry_src_init_t fesv_init; |
| 180 | fib_entry_src_deinit_t fesv_deinit; |
| 181 | fib_entry_src_activate_t fesv_activate; |
| 182 | fib_entry_src_deactivate_t fesv_deactivate; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame^] | 183 | fib_entry_src_reactivate_t fesv_reactivate; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 184 | fib_entry_src_add_t fesv_add; |
| 185 | fib_entry_src_remove_t fesv_remove; |
| 186 | fib_entry_src_path_swap_t fesv_path_swap; |
| 187 | fib_entry_src_path_add_t fesv_path_add; |
| 188 | fib_entry_src_path_remove_t fesv_path_remove; |
| 189 | fib_entry_src_cover_change_t fesv_cover_change; |
| 190 | fib_entry_src_cover_update_t fesv_cover_update; |
| 191 | fib_entry_src_format_t fesv_format; |
| 192 | fib_entry_src_installed_t fesv_installed; |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 193 | fib_entry_src_fwd_update_t fesv_fwd_update; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 194 | fib_entry_src_get_data_t fesv_get_data; |
| 195 | fib_entry_src_set_data_t fesv_set_data; |
| 196 | } fib_entry_src_vft_t; |
| 197 | |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 198 | #define FOR_EACH_SRC_ADDED(_entry, _src, _source, action) \ |
| 199 | { \ |
| 200 | vec_foreach(_src, _entry->fe_srcs) \ |
| 201 | { \ |
| 202 | if (_src->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED) { \ |
| 203 | _source = _src->fes_src; \ |
| 204 | do { \ |
| 205 | action; \ |
| 206 | } while(0); \ |
| 207 | } \ |
| 208 | } \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | extern u8* fib_entry_src_format(fib_entry_t *entry, |
| 212 | fib_source_t source, |
| 213 | u8* s); |
| 214 | |
| 215 | extern void fib_entry_src_register(fib_source_t source, |
| 216 | const fib_entry_src_vft_t *vft); |
| 217 | |
| 218 | extern void fib_entry_src_action_init(fib_entry_t *entry, |
| 219 | fib_source_t source); |
| 220 | |
| 221 | extern void fib_entry_src_action_deinit(fib_entry_t *fib_entry, |
| 222 | fib_source_t source); |
| 223 | |
| 224 | extern fib_entry_src_cover_res_t fib_entry_src_action_cover_change( |
| 225 | fib_entry_t *entry, |
| 226 | fib_source_t source); |
| 227 | |
| 228 | extern fib_entry_src_cover_res_t fib_entry_src_action_cover_update( |
| 229 | fib_entry_t *fib_entry, |
| 230 | fib_source_t source); |
| 231 | |
| 232 | extern void fib_entry_src_action_activate(fib_entry_t *fib_entry, |
| 233 | fib_source_t source); |
| 234 | |
| 235 | extern void fib_entry_src_action_deactivate(fib_entry_t *fib_entry, |
| 236 | fib_source_t source); |
| 237 | extern void fib_entry_src_action_reactivate(fib_entry_t *fib_entry, |
| 238 | fib_source_t source); |
| 239 | |
| 240 | extern fib_entry_t* fib_entry_src_action_add(fib_entry_t *fib_entry, |
| 241 | fib_source_t source, |
| 242 | fib_entry_flag_t flags, |
| 243 | const dpo_id_t *dpo); |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 244 | extern fib_entry_t* fib_entry_src_action_update(fib_entry_t *fib_entry, |
| 245 | fib_source_t source, |
| 246 | fib_entry_flag_t flags, |
| 247 | const dpo_id_t *dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 248 | |
| 249 | extern fib_entry_src_flag_t fib_entry_src_action_remove(fib_entry_t *fib_entry, |
| 250 | fib_source_t source); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame^] | 251 | extern fib_entry_src_flag_t |
| 252 | fib_entry_src_action_remove_or_update_inherit(fib_entry_t *fib_entry, |
| 253 | fib_source_t source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 254 | |
| 255 | extern void fib_entry_src_action_install(fib_entry_t *fib_entry, |
| 256 | fib_source_t source); |
| 257 | |
| 258 | extern void fib_entry_src_action_uninstall(fib_entry_t *fib_entry); |
| 259 | |
| 260 | extern fib_entry_t* fib_entry_src_action_path_add(fib_entry_t *fib_entry, |
| 261 | fib_source_t source, |
| 262 | fib_entry_flag_t flags, |
| 263 | const fib_route_path_t *path); |
| 264 | |
| 265 | extern fib_entry_t* fib_entry_src_action_path_swap(fib_entry_t *fib_entry, |
| 266 | fib_source_t source, |
| 267 | fib_entry_flag_t flags, |
| 268 | const fib_route_path_t *path); |
| 269 | |
| 270 | extern fib_entry_src_flag_t fib_entry_src_action_path_remove(fib_entry_t *fib_entry, |
| 271 | fib_source_t source, |
| 272 | const fib_route_path_t *path); |
| 273 | |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 274 | extern void fib_entry_src_action_installed(const fib_entry_t *fib_entry, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 275 | fib_source_t source); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame^] | 276 | extern void fib_entry_src_inherit (const fib_entry_t *cover, |
| 277 | fib_entry_t *covered); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 278 | |
| 279 | extern fib_forward_chain_type_t fib_entry_get_default_chain_type( |
| 280 | const fib_entry_t *fib_entry); |
| 281 | extern fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame^] | 282 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 283 | extern fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags( |
| 284 | fib_entry_flag_t eflags); |
| 285 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 286 | extern fib_forward_chain_type_t fib_entry_chain_type_fixup(const fib_entry_t *entry, |
| 287 | fib_forward_chain_type_t fct); |
| 288 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 289 | extern void fib_entry_src_mk_lb (fib_entry_t *fib_entry, |
| 290 | const fib_entry_src_t *esrc, |
| 291 | fib_forward_chain_type_t fct, |
| 292 | dpo_id_t *dpo_lb); |
| 293 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 294 | extern fib_protocol_t fib_entry_get_proto(const fib_entry_t * fib_entry); |
| 295 | extern dpo_proto_t fib_entry_get_dpo_proto(const fib_entry_t * fib_entry); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 296 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame^] | 297 | extern void fib_entry_source_change(fib_entry_t *fib_entry, |
| 298 | fib_source_t old_source, |
| 299 | fib_source_t new_source); |
| 300 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 301 | /* |
| 302 | * Per-source registration. declared here so we save a separate .h file for each |
| 303 | */ |
| 304 | extern void fib_entry_src_default_register(void); |
| 305 | extern void fib_entry_src_rr_register(void); |
| 306 | extern void fib_entry_src_interface_register(void); |
| 307 | extern void fib_entry_src_default_route_register(void); |
| 308 | extern void fib_entry_src_special_register(void); |
| 309 | extern void fib_entry_src_api_register(void); |
| 310 | extern void fib_entry_src_adj_register(void); |
| 311 | extern void fib_entry_src_mpls_register(void); |
| 312 | extern void fib_entry_src_lisp_register(void); |
| 313 | |
| 314 | extern void fib_entry_src_module_init(void); |
| 315 | |
| 316 | #endif |