blob: ab3cb3ebda7c231eed07427feb48482888dc6bca [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_SRC_H__
17#define __MFIB_ENTRY_SRC_H__
18
19#include <vnet/mfib/mfib_entry.h>
20
21/**
22 * MFIB extensions to each path
23 */
24typedef struct mfib_path_ext_t_
25{
26 mfib_itf_flags_t mfpe_flags;
27 fib_node_index_t mfpe_path;
28} mfib_path_ext_t;
29
30/**
Neale Ranns9db6ada2019-11-08 12:42:31 +000031 * Flags for the source data
32 */
33typedef enum mfib_entry_src_attribute_t_ {
34 /**
35 * Marker. Add new values after this one.
36 */
37 MFIB_ENTRY_SRC_ATTRIBUTE_FIRST,
38 /**
39 * the source has been added to the entry
40 */
41 MFIB_ENTRY_SRC_ATTRIBUTE_STALE = MFIB_ENTRY_SRC_ATTRIBUTE_FIRST,
42 /**
43 * Marker. add new entries before this one.
44 */
45 MFIB_ENTRY_SRC_ATTRIBUTE_LAST = MFIB_ENTRY_SRC_ATTRIBUTE_STALE,
46} mfib_entry_src_attribute_t;
47
48
49#define MFIB_ENTRY_SRC_ATTRIBUTES { \
50 [MFIB_ENTRY_SRC_ATTRIBUTE_STALE] = "stale", \
51}
52
53#define FOR_EACH_MFIB_SRC_ATTRIBUTE(_item) \
54 for (_item = MFIB_ENTRY_SRC_ATTRIBUTE_FIRST; \
55 _item <= MFIB_ENTRY_SRC_ATTRIBUTE_LAST; \
56 _item++)
57
58typedef enum mfib_entry_src_flag_t_ {
59 MFIB_ENTRY_SRC_FLAG_NONE = 0,
60 MFIB_ENTRY_SRC_FLAG_STALE = (1 << MFIB_ENTRY_SRC_ATTRIBUTE_STALE),
61} __attribute__ ((packed)) mfib_entry_src_flags_t;
62
63extern u8 * format_mfib_entry_src_flags(u8 *s, va_list *args);
64
65/*
66 * Keep the size of the flags field to 2 bytes, so it
67 * can be placed next to the 2 bytes reference count
68 */
69STATIC_ASSERT (sizeof(mfib_entry_src_flags_t) <= 2,
70 "FIB entry flags field size too big");
71
72/**
Neale Ranns9e829a82018-12-17 05:50:32 -080073 * The source of an MFIB entry
74 */
75typedef struct mfib_entry_src_t_
76{
77 /**
78 * Which source this is
79 */
80 mfib_source_t mfes_src;
81
82 /**
83 * Route flags
84 */
Neale Ranns9db6ada2019-11-08 12:42:31 +000085 mfib_entry_flags_t mfes_route_flags;
86
87 /**
88 * Source flags
89 */
90 mfib_entry_src_flags_t mfes_flags;
Neale Ranns9e829a82018-12-17 05:50:32 -080091
92 /**
93 * The reference count on the entry. this is a u32
94 * since there is no path-list sharing in mfib, so the number
95 * os children could be high.
96 */
97 u32 mfes_ref_count;
98
99 /**
100 * The path-list of forwarding interfaces
101 */
102 fib_node_index_t mfes_pl;
103
104 /**
105 * RPF-ID
106 */
107 fib_rpf_id_t mfes_rpf_id;
108
109 /**
110 * Hash table of path extensions
111 */
Neale Ranns60bb4532022-03-23 14:51:57 +0000112 uword *mfes_exts;
Neale Ranns9e829a82018-12-17 05:50:32 -0800113
114 /**
115 * Covering entry (if needed)
116 */
117 struct {
118 fib_node_index_t mfes_cover;
119 u32 mfes_sibling;
120 };
121
122 /**
123 * The hash table of all interfaces.
124 * This is forwarding time information derived from the paths
125 * and their extensions.
126 */
127 mfib_itf_t *mfes_itfs;
128} mfib_entry_src_t;
129
130/**
131 * signals from the sources to the caller
132 */
133typedef enum mfib_src_res_t_
134{
135 MFIB_SRC_OK,
136 MFIB_SRC_REEVALUATE,
137} mfib_src_res_t;
138
139/**
140 * A function provided by each source to be invoked when it is activated
141 */
142typedef void (*mfib_entry_src_activiate_t) (mfib_entry_t*, mfib_entry_src_t*);
143
144/**
145 * A function provided by each source to be invoked when it is deactivated
146 */
147typedef void (*mfib_entry_src_deactiviate_t) (mfib_entry_t*, mfib_entry_src_t*);
148
149/**
150 * A function provided by each source to be invoked when the cover changes
151 */
152typedef mfib_src_res_t (*mfib_entry_src_cover_change_t) (mfib_entry_t*, mfib_entry_src_t*);
153
154/**
155 * A function provided by each source to be invoked when the cover is updated
156 */
157typedef mfib_src_res_t (*mfib_entry_src_cover_update_t) (mfib_entry_t*, mfib_entry_src_t*);
158
159/**
160 * Virtual function table provided by each_source
161 */
162typedef struct mfib_entry_src_vft_t_
163{
164 mfib_entry_src_activiate_t mev_activate;
165 mfib_entry_src_deactiviate_t mev_deactivate;
166 mfib_entry_src_cover_change_t mev_cover_change;
167 mfib_entry_src_cover_update_t mev_cover_update;
168} mfib_entry_src_vft;
169
170extern void mfib_entry_src_register(mfib_source_t, const mfib_entry_src_vft*);
171
172extern void mfib_entry_src_deactivate(mfib_entry_t *mfib_entry,
173 mfib_entry_src_t *bsrc);
174
175extern void mfib_entry_src_activate(mfib_entry_t *mfib_entry,
176 mfib_entry_src_t *bsrc);
177
178extern mfib_src_res_t mfib_entry_src_cover_change(mfib_entry_t *mfib_entry,
179 mfib_entry_src_t *bsrc);
180
181extern mfib_src_res_t mfib_entry_src_cover_update(mfib_entry_t *mfib_entry,
182 mfib_entry_src_t *bsrc);
183
184extern mfib_entry_src_t* mfib_entry_get_best_src(const mfib_entry_t *mfib_entry);
185
186extern void mfib_entry_src_module_init(void);
187extern void mfib_entry_src_rr_module_init(void);
188
189#endif