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 | */ |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 15 | /** |
| 16 | * A Delagate is a means to implement the Delagation design pattern; |
| 17 | * the extension of an object's functionality through the composition of, |
| 18 | * and delgation to, other objects. |
| 19 | * These 'other' objects are delegates. Delagates are thus attached to |
| 20 | * ADJ objects to extend their functionality. |
| 21 | */ |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 22 | |
| 23 | #ifndef __ADJ_DELEGATE_T__ |
| 24 | #define __ADJ_DELEGATE_T__ |
| 25 | |
| 26 | #include <vnet/adj/adj.h> |
| 27 | |
| 28 | /** |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 29 | * Built-in delegate types. |
| 30 | * When adding new types, if your code is within the vnet subsystem, then add a |
| 31 | * new type here. If not then use the adj_delegate_register_new_type API to |
| 32 | * register a new type. |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 33 | */ |
| 34 | typedef enum adj_delegate_type_t_ { |
| 35 | /** |
| 36 | * BFD session state |
| 37 | */ |
| 38 | ADJ_DELEGATE_BFD, |
Neale Ranns | 4c3ba81 | 2019-03-26 07:02:58 +0000 | [diff] [blame] | 39 | /** |
| 40 | * Stacking of a midchain's nexthop |
| 41 | */ |
| 42 | ADJ_DELEGATE_MIDCHAIN, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 43 | } adj_delegate_type_t; |
| 44 | |
Neale Ranns | 4c3ba81 | 2019-03-26 07:02:58 +0000 | [diff] [blame] | 45 | #define ADJ_DELEGATE_LAST (ADJ_DELEGATE_MIDCHAIN) |
| 46 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 47 | /** |
Neale Ranns | 76447a7 | 2018-02-20 06:25:02 -0800 | [diff] [blame] | 48 | * Adj delegate. This object is attached to the adjacency. |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 49 | */ |
| 50 | typedef struct adj_delegate_t_ |
| 51 | { |
| 52 | /** |
| 53 | * The ADJ entry object to which the delagate is attached |
| 54 | */ |
| 55 | adj_index_t ad_adj_index; |
| 56 | |
| 57 | /** |
| 58 | * The delagate type |
| 59 | */ |
| 60 | adj_delegate_type_t ad_type; |
Neale Ranns | 76447a7 | 2018-02-20 06:25:02 -0800 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * The index passed by the provider to identify its delegate instance. |
| 64 | * As with all things VPP this is a pool index. |
| 65 | */ |
| 66 | index_t ad_index; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 67 | } adj_delegate_t; |
| 68 | |
Ole Troan | 793c7fe | 2018-02-15 16:14:56 +0100 | [diff] [blame] | 69 | /** |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 70 | * Indication that the adjacency has been deleted. The delegate provider should free |
| 71 | * the delegate. |
| 72 | */ |
| 73 | typedef void (*adj_delegate_adj_deleted_t)(adj_delegate_t *aed); |
| 74 | |
| 75 | /** |
| 76 | * Format function for the delegate |
| 77 | */ |
| 78 | typedef u8 * (*adj_delegate_format_t)(const adj_delegate_t *aed, u8 *s); |
| 79 | |
| 80 | /** |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 81 | * Notification that an adjacency has been created |
| 82 | */ |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 83 | typedef void (*adj_delegate_adj_created_t)(adj_index_t ai); |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 84 | |
| 85 | /** |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 86 | * Indication that the adjacency has been modified. |
| 87 | * the delegate. |
| 88 | */ |
| 89 | typedef void (*adj_delegate_adj_modified_t)(adj_delegate_t *aed); |
| 90 | |
| 91 | /** |
Ole Troan | 793c7fe | 2018-02-15 16:14:56 +0100 | [diff] [blame] | 92 | * An ADJ delegate virtual function table |
| 93 | */ |
Ole Troan | 793c7fe | 2018-02-15 16:14:56 +0100 | [diff] [blame] | 94 | typedef struct adj_delegate_vft_t_ { |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 95 | adj_delegate_format_t adv_format; |
| 96 | adj_delegate_adj_deleted_t adv_adj_deleted; |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 97 | adj_delegate_adj_modified_t adv_adj_modified; |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 98 | adj_delegate_adj_created_t adv_adj_created; |
Ole Troan | 793c7fe | 2018-02-15 16:14:56 +0100 | [diff] [blame] | 99 | } adj_delegate_vft_t; |
| 100 | |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 101 | /** |
| 102 | * @brief Remove a delegate from an adjacency |
| 103 | * |
| 104 | * @param ai The adjacency to remove the delegate from |
| 105 | * @param type The type of delegate being removed |
| 106 | */ |
| 107 | extern void adj_delegate_remove(adj_index_t ai, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 108 | adj_delegate_type_t type); |
| 109 | |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 110 | /** |
| 111 | * @brief Add a delegate to an adjacency |
| 112 | * |
| 113 | * @param ai The adjacency to add the delegate to |
| 114 | * @param type The type of delegate being added |
Neale Ranns | 76447a7 | 2018-02-20 06:25:02 -0800 | [diff] [blame] | 115 | * @param adi The provider's [pool] index of its attached objet |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 116 | */ |
| 117 | extern int adj_delegate_add(ip_adjacency_t *adj, |
| 118 | adj_delegate_type_t fdt, |
Neale Ranns | 76447a7 | 2018-02-20 06:25:02 -0800 | [diff] [blame] | 119 | index_t adi); |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 120 | |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 121 | /** |
| 122 | * @brief Get a delegate from an adjacency |
| 123 | * |
| 124 | * @param ai The adjacency to get the delegate from |
| 125 | * @param type The type of delegate being sought |
| 126 | */ |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 127 | extern adj_delegate_t *adj_delegate_get(const ip_adjacency_t *adj, |
| 128 | adj_delegate_type_t type); |
| 129 | |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 130 | /** |
| 131 | * @brief Register a VFT for one of the built-in types |
| 132 | */ |
| 133 | extern void adj_delegate_register_type(adj_delegate_type_t type, |
| 134 | const adj_delegate_vft_t *vft); |
| 135 | |
| 136 | /** |
| 137 | * @brief create a new delegate type and register a new VFT |
| 138 | */ |
| 139 | extern adj_delegate_type_t adj_delegate_register_new_type( |
| 140 | const adj_delegate_vft_t *vft); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 141 | |
| 142 | #endif |