blob: 13bf911c5a69942e45407dab586b867588fd3a60 [file] [log] [blame]
Neale Ranns88fc83e2017-04-05 08:11:14 -07001/*
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 Rannsd79a43c2018-02-19 02:36:19 -080015/**
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 Ranns88fc83e2017-04-05 08:11:14 -070022
23#ifndef __ADJ_DELEGATE_T__
24#define __ADJ_DELEGATE_T__
25
26#include <vnet/adj/adj.h>
27
28/**
Neale Rannsd79a43c2018-02-19 02:36:19 -080029 * 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 Ranns88fc83e2017-04-05 08:11:14 -070033 */
34typedef enum adj_delegate_type_t_ {
35 /**
36 * BFD session state
37 */
38 ADJ_DELEGATE_BFD,
39} adj_delegate_type_t;
40
Neale Ranns88fc83e2017-04-05 08:11:14 -070041/**
Neale Ranns76447a72018-02-20 06:25:02 -080042 * Adj delegate. This object is attached to the adjacency.
Neale Ranns88fc83e2017-04-05 08:11:14 -070043 */
44typedef struct adj_delegate_t_
45{
46 /**
47 * The ADJ entry object to which the delagate is attached
48 */
49 adj_index_t ad_adj_index;
50
51 /**
52 * The delagate type
53 */
54 adj_delegate_type_t ad_type;
Neale Ranns76447a72018-02-20 06:25:02 -080055
56 /**
57 * The index passed by the provider to identify its delegate instance.
58 * As with all things VPP this is a pool index.
59 */
60 index_t ad_index;
Neale Ranns88fc83e2017-04-05 08:11:14 -070061} adj_delegate_t;
62
Ole Troan793c7fe2018-02-15 16:14:56 +010063/**
Neale Rannsd79a43c2018-02-19 02:36:19 -080064 * Indication that the adjacency has been deleted. The delegate provider should free
65 * the delegate.
66 */
67typedef void (*adj_delegate_adj_deleted_t)(adj_delegate_t *aed);
68
69/**
70 * Format function for the delegate
71 */
72typedef u8 * (*adj_delegate_format_t)(const adj_delegate_t *aed, u8 *s);
73
74/**
Ole Troan793c7fe2018-02-15 16:14:56 +010075 * An ADJ delegate virtual function table
76 */
Ole Troan793c7fe2018-02-15 16:14:56 +010077typedef struct adj_delegate_vft_t_ {
Neale Rannsd79a43c2018-02-19 02:36:19 -080078 adj_delegate_format_t adv_format;
79 adj_delegate_adj_deleted_t adv_adj_deleted;
Ole Troan793c7fe2018-02-15 16:14:56 +010080} adj_delegate_vft_t;
81
Neale Rannsd79a43c2018-02-19 02:36:19 -080082/**
83 * @brief Remove a delegate from an adjacency
84 *
85 * @param ai The adjacency to remove the delegate from
86 * @param type The type of delegate being removed
87 */
88extern void adj_delegate_remove(adj_index_t ai,
Neale Ranns88fc83e2017-04-05 08:11:14 -070089 adj_delegate_type_t type);
90
Neale Rannsd79a43c2018-02-19 02:36:19 -080091/**
92 * @brief Add a delegate to an adjacency
93 *
94 * @param ai The adjacency to add the delegate to
95 * @param type The type of delegate being added
Neale Ranns76447a72018-02-20 06:25:02 -080096 * @param adi The provider's [pool] index of its attached objet
Neale Rannsd79a43c2018-02-19 02:36:19 -080097 */
98extern int adj_delegate_add(ip_adjacency_t *adj,
99 adj_delegate_type_t fdt,
Neale Ranns76447a72018-02-20 06:25:02 -0800100 index_t adi);
Neale Rannsd79a43c2018-02-19 02:36:19 -0800101
Neale Rannsd79a43c2018-02-19 02:36:19 -0800102/**
103 * @brief Get a delegate from an adjacency
104 *
105 * @param ai The adjacency to get the delegate from
106 * @param type The type of delegate being sought
107 */
Neale Ranns88fc83e2017-04-05 08:11:14 -0700108extern adj_delegate_t *adj_delegate_get(const ip_adjacency_t *adj,
109 adj_delegate_type_t type);
110
Neale Rannsd79a43c2018-02-19 02:36:19 -0800111/**
112 * @brief Register a VFT for one of the built-in types
113 */
114extern void adj_delegate_register_type(adj_delegate_type_t type,
115 const adj_delegate_vft_t *vft);
116
117/**
118 * @brief create a new delegate type and register a new VFT
119 */
120extern adj_delegate_type_t adj_delegate_register_new_type(
121 const adj_delegate_vft_t *vft);
Neale Ranns88fc83e2017-04-05 08:11:14 -0700122
123#endif