Neale Ranns | ad422ed | 2016-11-02 14:20:04 +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 __FIB_ENTRY_DELEGATE_T__ |
| 17 | #define __FIB_ENTRY_DELEGATE_T__ |
| 18 | |
| 19 | #include <vnet/fib/fib_node.h> |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 20 | #include <vnet/fib/fib_entry.h> |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Delegate types |
| 24 | */ |
| 25 | typedef enum fib_entry_delegate_type_t_ { |
| 26 | /** |
| 27 | * Forwarding chain types: |
| 28 | * for the vast majority of FIB entries only one chain is required - the |
| 29 | * one that forwards traffic matching the fib_entry_t's fib_prefix_t. For those |
| 30 | * fib_entry_t that are a resolution target for other fib_entry_t's they will also |
| 31 | * need the chain to provide forwarding for those children. We store these additional |
| 32 | * chains in delegates to save memory in the common case. |
| 33 | */ |
| 34 | FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4 = FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 35 | FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6 = FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 36 | FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS = FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 37 | FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS = FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 38 | FIB_ENTRY_DELEGATE_CHAIN_ETHERNET = FIB_FORW_CHAIN_TYPE_ETHERNET, |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 39 | FIB_ENTRY_DELEGATE_CHAIN_NSH = FIB_FORW_CHAIN_TYPE_NSH, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 40 | /** |
| 41 | * Dependency list of covered entries. |
| 42 | * these are more specific entries that are interested in changes |
| 43 | * to their respective cover |
| 44 | */ |
| 45 | FIB_ENTRY_DELEGATE_COVERED, |
| 46 | /** |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 47 | * BFD session state |
| 48 | */ |
| 49 | FIB_ENTRY_DELEGATE_BFD, |
| 50 | /** |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 51 | * Tracker |
| 52 | */ |
| 53 | FIB_ENTRY_DELEGATE_TRACK, |
| 54 | /** |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 55 | * Attached import/export functionality |
| 56 | */ |
| 57 | FIB_ENTRY_DELEGATE_ATTACHED_IMPORT, |
| 58 | FIB_ENTRY_DELEGATE_ATTACHED_EXPORT, |
| 59 | } fib_entry_delegate_type_t; |
| 60 | |
| 61 | #define FOR_EACH_DELEGATE_CHAIN(_entry, _fdt, _fed, _body) \ |
| 62 | { \ |
| 63 | for (_fdt = FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4; \ |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 64 | _fdt <= FIB_ENTRY_DELEGATE_CHAIN_NSH; \ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 65 | _fdt++) \ |
| 66 | { \ |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 67 | _fed = fib_entry_delegate_find(_entry, _fdt); \ |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 68 | if (NULL != _fed) { \ |
| 69 | _body; \ |
| 70 | } \ |
| 71 | } \ |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Distillation of the BFD session states into a go/no-go for using |
| 76 | * the associated tracked FIB entry |
| 77 | */ |
| 78 | typedef enum fib_bfd_state_t_ |
| 79 | { |
| 80 | FIB_BFD_STATE_UP, |
| 81 | FIB_BFD_STATE_DOWN, |
| 82 | } fib_bfd_state_t; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 83 | |
| 84 | /** |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 85 | * State for FIB entry tracking |
| 86 | */ |
| 87 | typedef struct fib_entry_delegate_track_t_ |
| 88 | { |
| 89 | fib_node_t fedt_node; |
| 90 | u32 fedt_sibling; |
| 91 | } fib_entry_delegate_track_t; |
| 92 | |
| 93 | /** |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 94 | * A Delagate is a means to implmenet the Delagation design pattern; the extension of an |
| 95 | * objects functionality through the composition of, and delgation to, other objects. |
| 96 | * These 'other' objects are delegates. Delagates are thus attached to other FIB objects |
| 97 | * to extend their functionality. |
| 98 | */ |
| 99 | typedef struct fib_entry_delegate_t_ |
| 100 | { |
| 101 | /** |
| 102 | * The FIB entry object to which the delagate is attached |
| 103 | */ |
| 104 | fib_node_index_t fd_entry_index; |
| 105 | |
| 106 | /** |
| 107 | * The delagate type |
| 108 | */ |
| 109 | fib_entry_delegate_type_t fd_type; |
| 110 | |
| 111 | /** |
| 112 | * A union of data for the different delegate types |
| 113 | * These delegates are stored in a sparse vector on the entry, so they |
| 114 | * must all be of the same size. We could use indirection here for all types, |
| 115 | * i.e. store an index, that's ok for large delegates, like the attached export |
| 116 | * but for the chain delegates it's excessive |
| 117 | */ |
| 118 | union |
| 119 | { |
| 120 | /** |
| 121 | * Valid for the forwarding chain delegates. The LB that is built. |
| 122 | */ |
| 123 | dpo_id_t fd_dpo; |
| 124 | |
| 125 | /** |
| 126 | * Valid for the attached import cases. An index of the importer/exporter |
| 127 | */ |
| 128 | fib_node_index_t fd_index; |
| 129 | |
| 130 | /** |
| 131 | * For the cover tracking. The node list; |
| 132 | */ |
| 133 | fib_node_list_t fd_list; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * BFD state |
| 137 | */ |
| 138 | fib_bfd_state_t fd_bfd_state; |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * tracker state |
| 142 | */ |
| 143 | fib_entry_delegate_track_t fd_track; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 144 | }; |
| 145 | } fib_entry_delegate_t; |
| 146 | |
| 147 | struct fib_entry_t_; |
| 148 | |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 149 | extern void fib_entry_delegate_remove(fib_entry_t *fib_entry, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 150 | fib_entry_delegate_type_t type); |
| 151 | |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 152 | extern fib_entry_delegate_t *fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 153 | fib_entry_delegate_type_t fdt); |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 154 | extern fib_entry_delegate_t *fib_entry_delegate_find(const fib_entry_t *fib_entry, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 155 | fib_entry_delegate_type_t type); |
| 156 | |
| 157 | extern fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type( |
| 158 | fib_entry_delegate_type_t type); |
| 159 | |
| 160 | extern fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type( |
| 161 | fib_forward_chain_type_t type); |
| 162 | |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 163 | extern u8 *format_fib_entry_delegate(u8 * s, va_list * args); |
| 164 | |
| 165 | extern fib_node_index_t fib_entry_delegate_get_index (const fib_entry_delegate_t *fed); |
| 166 | extern fib_entry_delegate_t * fib_entry_delegate_get (fib_node_index_t fedi); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 167 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 168 | #endif |