Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [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 __MFIB_ENTRY_H__ |
| 17 | #define __MFIB_ENTRY_H__ |
| 18 | |
| 19 | #include <vnet/fib/fib_node.h> |
| 20 | #include <vnet/mfib/mfib_types.h> |
| 21 | #include <vnet/mfib/mfib_itf.h> |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 22 | #include <vnet/mfib/mfib_entry_delegate.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 23 | #include <vnet/ip/ip.h> |
| 24 | #include <vnet/dpo/dpo.h> |
| 25 | |
| 26 | /** |
| 27 | * An entry in a FIB table. |
| 28 | * |
| 29 | * This entry represents a route added to the FIB that is stored |
| 30 | * in one of the FIB tables. |
| 31 | */ |
| 32 | typedef struct mfib_entry_t_ { |
| 33 | CLIB_CACHE_LINE_ALIGN_MARK(cacheline0); |
| 34 | /** |
| 35 | * Base class. The entry's node representation in the graph. |
| 36 | */ |
| 37 | fib_node_t mfe_node; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 38 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 39 | /** |
| 40 | * The prefix of the route |
| 41 | */ |
| 42 | mfib_prefix_t mfe_prefix; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 43 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 44 | /** |
| 45 | * The index of the FIB table this entry is in |
| 46 | */ |
| 47 | u32 mfe_fib_index; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * A vector of sources contributing forwarding |
| 51 | */ |
| 52 | struct mfib_entry_src_t_ *mfe_srcs; |
| 53 | |
| 54 | /** |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 55 | * The path-list of which this entry is a child |
| 56 | */ |
| 57 | fib_node_index_t mfe_pl; |
| 58 | |
| 59 | /** |
| 60 | * The sibling index on the path-list |
| 61 | */ |
| 62 | u32 mfe_sibling; |
| 63 | |
| 64 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 65 | * 2nd cache line has the members used in the data plane |
| 66 | */ |
| 67 | CLIB_CACHE_LINE_ALIGN_MARK(cacheline1); |
| 68 | |
| 69 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 70 | * The DPO used for forwarding; replicate, drop, etc.. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 71 | */ |
| 72 | dpo_id_t mfe_rep; |
| 73 | |
| 74 | /** |
| 75 | * Route flags |
| 76 | */ |
| 77 | mfib_entry_flags_t mfe_flags; |
| 78 | |
| 79 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 80 | * RPF-ID used when the packets ingress not from an interface |
| 81 | */ |
| 82 | fib_rpf_id_t mfe_rpf_id; |
| 83 | |
| 84 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 85 | * A hash table of interfaces |
| 86 | */ |
| 87 | mfib_itf_t *mfe_itfs; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * A vector of delegates. |
| 91 | */ |
| 92 | mfib_entry_delegate_t *fe_delegates; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 93 | } mfib_entry_t; |
| 94 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 95 | /** |
| 96 | * Debug macro |
| 97 | */ |
| 98 | extern vlib_log_class_t mfib_entry_logger; |
| 99 | |
| 100 | #define MFIB_ENTRY_DBG(_e, _fmt, _args...) \ |
| 101 | { \ |
| 102 | vlib_log_debug(mfib_entry_logger, \ |
| 103 | "e:[%d:%U]: " _fmt, \ |
| 104 | mfib_entry_get_index(_e), \ |
| 105 | format_mfib_prefix, \ |
| 106 | &_e->mfe_prefix, \ |
| 107 | ##_args); \ |
| 108 | } |
| 109 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 110 | #define MFIB_ENTRY_FORMAT_BRIEF (0x0) |
| 111 | #define MFIB_ENTRY_FORMAT_DETAIL (0x1) |
| 112 | #define MFIB_ENTRY_FORMAT_DETAIL2 (0x2) |
| 113 | |
| 114 | extern u8 *format_mfib_entry(u8 * s, va_list * args); |
| 115 | |
| 116 | |
| 117 | extern fib_node_index_t mfib_entry_create(u32 fib_index, |
| 118 | mfib_source_t source, |
| 119 | const mfib_prefix_t *prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 120 | fib_rpf_id_t rpf_id, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 121 | mfib_entry_flags_t entry_flags, |
| 122 | index_t repi); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 123 | |
| 124 | extern int mfib_entry_update(fib_node_index_t fib_entry_index, |
| 125 | mfib_source_t source, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 126 | mfib_entry_flags_t entry_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 127 | fib_rpf_id_t rpf_id, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 128 | index_t rep_dpo); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 129 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 130 | extern int mfib_entry_special_add(fib_node_index_t fib_entry_index, |
| 131 | mfib_source_t source, |
| 132 | mfib_entry_flags_t entry_flags, |
| 133 | fib_rpf_id_t rpf_id, |
| 134 | index_t rep_dpo); |
| 135 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 136 | extern void mfib_entry_path_update(fib_node_index_t fib_entry_index, |
| 137 | mfib_source_t source, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame^] | 138 | const fib_route_path_t *rpath); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 139 | |
| 140 | |
| 141 | extern int mfib_entry_path_remove(fib_node_index_t fib_entry_index, |
| 142 | mfib_source_t source, |
| 143 | const fib_route_path_t *rpath); |
| 144 | |
| 145 | extern int mfib_entry_delete(fib_node_index_t mfib_entry_index, |
| 146 | mfib_source_t source); |
| 147 | |
| 148 | extern int mfib_entry_cmp_for_sort(void *i1, void *i2); |
| 149 | |
| 150 | extern u32 mfib_entry_child_add(fib_node_index_t mfib_entry_index, |
| 151 | fib_node_type_t type, |
| 152 | fib_node_index_t child_index); |
| 153 | extern void mfib_entry_child_remove(fib_node_index_t mfib_entry_index, |
| 154 | u32 sibling_index); |
| 155 | |
| 156 | extern void mfib_entry_lock(fib_node_index_t fib_entry_index); |
| 157 | extern void mfib_entry_unlock(fib_node_index_t fib_entry_index); |
| 158 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 159 | extern const mfib_prefix_t *mfib_entry_get_prefix(fib_node_index_t fib_entry_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 160 | extern u32 mfib_entry_get_fib_index(fib_node_index_t fib_entry_index); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 161 | extern int mfib_entry_is_sourced(fib_node_index_t fib_entry_index, |
| 162 | mfib_source_t source); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 163 | extern int mfib_entry_is_host(fib_node_index_t fib_entry_index); |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 164 | extern u32 mfib_entry_get_stats_index(fib_node_index_t fib_entry_index); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 165 | extern void mfib_entry_cover_changed(fib_node_index_t fib_entry_index); |
| 166 | extern void mfib_entry_cover_updated(fib_node_index_t fib_entry_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 167 | |
Neale Ranns | ff23389 | 2017-12-12 00:21:19 -0800 | [diff] [blame] | 168 | extern const dpo_id_t*mfib_entry_contribute_ip_forwarding( |
| 169 | fib_node_index_t mfib_entry_index); |
| 170 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Flags to control what is present in the replicate DPO returned when |
| 173 | * the entry contributes forwarding |
| 174 | */ |
| 175 | typedef enum mfib_entry_fwd_flags_t_ |
| 176 | { |
| 177 | MFIB_ENTRY_FWD_FLAG_NONE, |
| 178 | /** |
| 179 | * Do not reutrn any local replications in the set |
| 180 | */ |
| 181 | MFIB_ENTRY_FWD_FLAG_NO_LOCAL, |
| 182 | } mfib_entry_fwd_flags_t; |
| 183 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 184 | extern void mfib_entry_contribute_forwarding( |
| 185 | fib_node_index_t mfib_entry_index, |
| 186 | fib_forward_chain_type_t type, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 187 | mfib_entry_fwd_flags_t flags, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 188 | dpo_id_t *dpo); |
| 189 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame^] | 190 | extern fib_route_path_t* mfib_entry_encode(fib_node_index_t fib_entry_index); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 191 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 192 | extern void mfib_entry_module_init(void); |
| 193 | |
| 194 | |
| 195 | extern mfib_entry_t *mfib_entry_pool; |
| 196 | |
| 197 | static inline mfib_entry_t * |
| 198 | mfib_entry_get (fib_node_index_t index) |
| 199 | { |
| 200 | return (pool_elt_at_index(mfib_entry_pool, index)); |
| 201 | } |
| 202 | static inline fib_node_index_t |
| 203 | mfib_entry_get_index (const mfib_entry_t *mfe) |
| 204 | { |
| 205 | return (mfe - mfib_entry_pool); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | static inline mfib_itf_t * |
| 210 | mfib_entry_itf_find (mfib_itf_t *itfs, |
| 211 | u32 sw_if_index) |
| 212 | { |
| 213 | uword *p; |
| 214 | |
| 215 | p = hash_get(itfs, sw_if_index); |
| 216 | |
| 217 | if (NULL != p) |
| 218 | { |
| 219 | return (mfib_itf_get(p[0])); |
| 220 | } |
| 221 | |
| 222 | return (NULL); |
| 223 | } |
| 224 | |
| 225 | static inline mfib_itf_t * |
| 226 | mfib_entry_get_itf (const mfib_entry_t *mfe, |
| 227 | u32 sw_if_index) |
| 228 | { |
| 229 | return (mfib_entry_itf_find(mfe->mfe_itfs, sw_if_index)); |
| 230 | } |
| 231 | |
| 232 | #endif |