Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [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 __ADJ_DELEGATE_T__ |
| 17 | #define __ADJ_DELEGATE_T__ |
| 18 | |
| 19 | #include <vnet/adj/adj.h> |
| 20 | |
| 21 | /** |
| 22 | * Delegate types |
| 23 | */ |
| 24 | typedef enum adj_delegate_type_t_ { |
| 25 | /** |
| 26 | * BFD session state |
| 27 | */ |
| 28 | ADJ_DELEGATE_BFD, |
| 29 | } adj_delegate_type_t; |
| 30 | |
| 31 | #define FOR_EACH_ADJ_DELEGATE(_adj, _adt, _aed, _body) \ |
| 32 | { \ |
| 33 | for (_adt = ADJ_DELEGATE_BFD; \ |
| 34 | _adt <= ADJ_DELEGATE_BFD; \ |
| 35 | _adt++) \ |
| 36 | { \ |
| 37 | _aed = adj_delegate_get(_adj, _adt); \ |
| 38 | if (NULL != _aed) { \ |
| 39 | _body; \ |
| 40 | } \ |
| 41 | } \ |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Distillation of the BFD session states into a go/no-go for using |
| 46 | * the associated tracked adjacency |
| 47 | */ |
| 48 | typedef enum adj_bfd_state_t_ |
| 49 | { |
| 50 | ADJ_BFD_STATE_DOWN, |
| 51 | ADJ_BFD_STATE_UP, |
| 52 | } adj_bfd_state_t; |
| 53 | |
| 54 | /** |
| 55 | * A Delagate is a means to implement the Delagation design pattern; |
| 56 | * the extension of an object's functionality through the composition of, |
| 57 | * and delgation to, other objects. |
| 58 | * These 'other' objects are delegates. Delagates are thus attached to |
| 59 | * ADJ objects to extend their functionality. |
| 60 | */ |
| 61 | typedef struct adj_delegate_t_ |
| 62 | { |
| 63 | /** |
| 64 | * The ADJ entry object to which the delagate is attached |
| 65 | */ |
| 66 | adj_index_t ad_adj_index; |
| 67 | |
| 68 | /** |
| 69 | * The delagate type |
| 70 | */ |
| 71 | adj_delegate_type_t ad_type; |
| 72 | |
| 73 | /** |
| 74 | * A union of data for the different delegate types |
| 75 | */ |
| 76 | union |
| 77 | { |
| 78 | /** |
| 79 | * BFD delegate daa |
| 80 | */ |
| 81 | struct { |
| 82 | /** |
| 83 | * BFD session state |
| 84 | */ |
| 85 | adj_bfd_state_t ad_bfd_state; |
| 86 | /** |
| 87 | * BFD session index |
| 88 | */ |
| 89 | u32 ad_bfd_index; |
| 90 | }; |
| 91 | }; |
| 92 | } adj_delegate_t; |
| 93 | |
| 94 | extern void adj_delegate_remove(ip_adjacency_t *adj, |
| 95 | adj_delegate_type_t type); |
| 96 | |
| 97 | extern adj_delegate_t *adj_delegate_find_or_add(ip_adjacency_t *adj, |
| 98 | adj_delegate_type_t fdt); |
| 99 | extern adj_delegate_t *adj_delegate_get(const ip_adjacency_t *adj, |
| 100 | adj_delegate_type_t type); |
| 101 | |
| 102 | extern u8 *format_adj_deletegate(u8 * s, va_list * args); |
| 103 | |
| 104 | #endif |