blob: 333d357c12070ffe40228f194cb9f74c2a0a1019 [file] [log] [blame]
Neale Rannsad422ed2016-11-02 14:20:04 +00001/*
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 __FIB_ENTRY_DELEGATE_T__
17#define __FIB_ENTRY_DELEGATE_T__
18
19#include <vnet/fib/fib_node.h>
20
21/**
22 * Delegate types
23 */
24typedef enum fib_entry_delegate_type_t_ {
25 /**
26 * Forwarding chain types:
27 * for the vast majority of FIB entries only one chain is required - the
28 * one that forwards traffic matching the fib_entry_t's fib_prefix_t. For those
29 * fib_entry_t that are a resolution target for other fib_entry_t's they will also
30 * need the chain to provide forwarding for those children. We store these additional
31 * chains in delegates to save memory in the common case.
32 */
33 FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4 = FIB_FORW_CHAIN_TYPE_UNICAST_IP4,
34 FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6 = FIB_FORW_CHAIN_TYPE_UNICAST_IP6,
35 FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS = FIB_FORW_CHAIN_TYPE_MPLS_EOS,
36 FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS = FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
37 FIB_ENTRY_DELEGATE_CHAIN_ETHERNET = FIB_FORW_CHAIN_TYPE_ETHERNET,
Florin Corasce1b4c72017-01-26 14:25:34 -080038 FIB_ENTRY_DELEGATE_CHAIN_NSH = FIB_FORW_CHAIN_TYPE_NSH,
Neale Rannsad422ed2016-11-02 14:20:04 +000039 /**
40 * Dependency list of covered entries.
41 * these are more specific entries that are interested in changes
42 * to their respective cover
43 */
44 FIB_ENTRY_DELEGATE_COVERED,
45 /**
Neale Ranns88fc83e2017-04-05 08:11:14 -070046 * BFD session state
47 */
48 FIB_ENTRY_DELEGATE_BFD,
49 /**
Neale Rannsad422ed2016-11-02 14:20:04 +000050 * Attached import/export functionality
51 */
52 FIB_ENTRY_DELEGATE_ATTACHED_IMPORT,
53 FIB_ENTRY_DELEGATE_ATTACHED_EXPORT,
54} fib_entry_delegate_type_t;
55
56#define FOR_EACH_DELEGATE_CHAIN(_entry, _fdt, _fed, _body) \
57{ \
58 for (_fdt = FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4; \
Florin Corasce1b4c72017-01-26 14:25:34 -080059 _fdt <= FIB_ENTRY_DELEGATE_CHAIN_NSH; \
Neale Rannsad422ed2016-11-02 14:20:04 +000060 _fdt++) \
61 { \
62 _fed = fib_entry_delegate_get(_entry, _fdt); \
63 if (NULL != _fed) { \
64 _body; \
65 } \
66 } \
67}
Neale Ranns88fc83e2017-04-05 08:11:14 -070068#define FOR_EACH_DELEGATE(_entry, _fdt, _fed, _body) \
69{ \
70 for (_fdt = FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4; \
71 _fdt <= FIB_ENTRY_DELEGATE_ATTACHED_EXPORT; \
72 _fdt++) \
73 { \
74 _fed = fib_entry_delegate_get(_entry, _fdt); \
75 if (NULL != _fed) { \
76 _body; \
77 } \
78 } \
79}
80
81/**
82 * Distillation of the BFD session states into a go/no-go for using
83 * the associated tracked FIB entry
84 */
85typedef enum fib_bfd_state_t_
86{
87 FIB_BFD_STATE_UP,
88 FIB_BFD_STATE_DOWN,
89} fib_bfd_state_t;
Neale Rannsad422ed2016-11-02 14:20:04 +000090
91/**
92 * A Delagate is a means to implmenet the Delagation design pattern; the extension of an
93 * objects functionality through the composition of, and delgation to, other objects.
94 * These 'other' objects are delegates. Delagates are thus attached to other FIB objects
95 * to extend their functionality.
96 */
97typedef struct fib_entry_delegate_t_
98{
99 /**
100 * The FIB entry object to which the delagate is attached
101 */
102 fib_node_index_t fd_entry_index;
103
104 /**
105 * The delagate type
106 */
107 fib_entry_delegate_type_t fd_type;
108
109 /**
110 * A union of data for the different delegate types
111 * These delegates are stored in a sparse vector on the entry, so they
112 * must all be of the same size. We could use indirection here for all types,
113 * i.e. store an index, that's ok for large delegates, like the attached export
114 * but for the chain delegates it's excessive
115 */
116 union
117 {
118 /**
119 * Valid for the forwarding chain delegates. The LB that is built.
120 */
121 dpo_id_t fd_dpo;
122
123 /**
124 * Valid for the attached import cases. An index of the importer/exporter
125 */
126 fib_node_index_t fd_index;
127
128 /**
129 * For the cover tracking. The node list;
130 */
131 fib_node_list_t fd_list;
Neale Ranns88fc83e2017-04-05 08:11:14 -0700132
133 /**
134 * BFD state
135 */
136 fib_bfd_state_t fd_bfd_state;
Neale Rannsad422ed2016-11-02 14:20:04 +0000137 };
138} fib_entry_delegate_t;
139
140struct fib_entry_t_;
141
142extern void fib_entry_delegate_remove(struct fib_entry_t_ *fib_entry,
143 fib_entry_delegate_type_t type);
144
145extern fib_entry_delegate_t *fib_entry_delegate_find_or_add(struct fib_entry_t_ *fib_entry,
146 fib_entry_delegate_type_t fdt);
147extern fib_entry_delegate_t *fib_entry_delegate_get(const struct fib_entry_t_ *fib_entry,
148 fib_entry_delegate_type_t type);
149
150extern fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type(
151 fib_entry_delegate_type_t type);
152
153extern fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type(
154 fib_forward_chain_type_t type);
155
Neale Ranns88fc83e2017-04-05 08:11:14 -0700156extern u8 *format_fib_entry_deletegate(u8 * s, va_list * args);
157
Neale Rannsad422ed2016-11-02 14:20:04 +0000158#endif