Adjacency Delegate updates
[vpp.git] / src / vnet / adj / adj_delegate.h
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  * 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  */
22
23 #ifndef __ADJ_DELEGATE_T__
24 #define __ADJ_DELEGATE_T__
25
26 #include <vnet/adj/adj.h>
27
28 /**
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.
33  */
34 typedef enum adj_delegate_type_t_ {
35     /**
36      * BFD session state
37      */
38     ADJ_DELEGATE_BFD,
39 } adj_delegate_type_t;
40
41 /**
42  * Adj delegate. This object should be contained within all type specific
43  * delegates.  i.e. this is the base class to all type specific derived classes.
44  * With this model the delegate provider is free to manage the memory of the
45  * delegate in the way it chooses. Specifically it can assign them from its own
46  * pools and thus, for example, add the delegates to the FIB node graph.
47  */
48 typedef struct adj_delegate_t_
49 {
50     /**
51      * The ADJ entry object to which the delagate is attached
52      */
53     adj_index_t ad_adj_index;
54
55     /**
56      * The delagate type
57      */
58     adj_delegate_type_t ad_type;
59 } adj_delegate_t;
60
61 /**
62  * Indication that the adjacency has been deleted. The delegate provider should free
63  * the delegate.
64  */
65 typedef void (*adj_delegate_adj_deleted_t)(adj_delegate_t *aed);
66
67 /**
68  * Format function for the delegate
69  */
70 typedef u8 * (*adj_delegate_format_t)(const adj_delegate_t *aed, u8 *s);
71
72 /**
73  * An ADJ delegate virtual function table
74  */
75 typedef struct adj_delegate_vft_t_ {
76     adj_delegate_format_t adv_format;
77     adj_delegate_adj_deleted_t adv_adj_deleted;
78 } adj_delegate_vft_t;
79
80 /**
81  * @brief Remove a delegate from an adjacency
82  *
83  * @param ai The adjacency to remove the delegate from
84  * @param type The type of delegate being removed
85  */
86 extern void adj_delegate_remove(adj_index_t ai,
87                                 adj_delegate_type_t type);
88
89 /**
90  * @brief Add a delegate to an adjacency
91  *
92  * @param ai The adjacency to add the delegate to
93  * @param type The type of delegate being added
94  * @param ad The delegate. The provider should allocate memory for this object
95  *                         Typically this is a 'derived' class with the
96  *                         adj_delegate_t struct embedded within.
97  */
98 extern int adj_delegate_add(ip_adjacency_t *adj,
99                             adj_delegate_type_t fdt,
100                             adj_delegate_t *ad);
101
102
103 /**
104  * @brief Get a delegate from an adjacency
105  *
106  * @param ai The adjacency to get the delegate from
107  * @param type The type of delegate being sought
108  */
109 extern adj_delegate_t *adj_delegate_get(const ip_adjacency_t *adj,
110                                         adj_delegate_type_t type);
111
112 /**
113  * @brief Register a VFT for one of the built-in types
114  */
115 extern void adj_delegate_register_type(adj_delegate_type_t type,
116                                        const adj_delegate_vft_t *vft);
117
118 /**
119  * @brief create a new delegate type and register a new VFT
120  */
121 extern adj_delegate_type_t adj_delegate_register_new_type(
122     const adj_delegate_vft_t *vft);
123
124 #endif