blob: 0454a0f157aae239cb0816bf43398802c52b6d2b [file] [log] [blame]
Neale Ranns9e829a82018-12-17 05:50:32 -08001/*
2 * Copyright (c) 2018 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 __MFIB_ENTRY_DELEGATE_T__
17#define __MFIB_ENTRY_DELEGATE_T__
18
19#include <vnet/fib/fib_node.h>
20
21/**
22 * Delegate types
23 */
24typedef enum mfib_entry_delegate_type_t_ {
25 /**
26 * Dependency list of covered entries.
27 * these are more specific entries that are interested in changes
28 * to their respective cover
29 */
30 MFIB_ENTRY_DELEGATE_COVERED,
31} mfib_entry_delegate_type_t;
32
33#define FOR_EACH_MFIB_DELEGATE(_entry, _fdt, _fed, _body) \
34{ \
35 for (_fdt = MFIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4; \
36 _fdt <= MFIB_ENTRY_DELEGATE_ATTACHED_EXPORT; \
37 _fdt++) \
38 { \
39 _fed = mfib_entry_delegate_get(_entry, _fdt); \
40 if (NULL != _fed) { \
41 _body; \
42 } \
43 } \
44}
45
46/**
47 * A Delagate is a means to implmenet the Delagation design pattern; the extension of an
48 * objects functionality through the composition of, and delgation to, other objects.
49 * These 'other' objects are delegates. Delagates are thus attached to other MFIB objects
50 * to extend their functionality.
51 */
52typedef struct mfib_entry_delegate_t_
53{
54 /**
55 * The MFIB entry object to which the delagate is attached
56 */
57 fib_node_index_t mfd_entry_index;
58
59 /**
60 * The delagate type
61 */
62 mfib_entry_delegate_type_t mfd_type;
63
64 /**
65 * A union of data for the different delegate types
66 * These delegates are stored in a sparse vector on the entry, so they
67 * must all be of the same size.
68 */
69 union
70 {
71 /**
72 * For the cover tracking. The node list;
73 */
74 fib_node_list_t mfd_list;
75 };
76} mfib_entry_delegate_t;
77
78struct mfib_entry_t_;
79
80extern void mfib_entry_delegate_remove(struct mfib_entry_t_ *mfib_entry,
81 mfib_entry_delegate_type_t type);
82
83extern mfib_entry_delegate_t *mfib_entry_delegate_find_or_add(struct mfib_entry_t_ *mfib_entry,
84 mfib_entry_delegate_type_t fdt);
85extern mfib_entry_delegate_t *mfib_entry_delegate_get(const struct mfib_entry_t_ *mfib_entry,
86 mfib_entry_delegate_type_t type);
87
88extern u8 *format_mfib_entry_deletegate(u8 * s, va_list * args);
89
90#endif