FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
fib_entry_delegate.c
Go to the documentation of this file.
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 
17 #include <vnet/fib/fib_entry.h>
19 
21 
24 {
26 }
27 
30 {
31  return (fed - fib_entry_delegate_pool);
32 }
33 
34 static fib_entry_delegate_t *
37  u32 *index)
38 {
39  fib_entry_delegate_t *delegate;
40  index_t *fedi;
41  int ii;
42 
43  ii = 0;
44  vec_foreach(fedi, fib_entry->fe_delegates)
45  {
46  delegate = fib_entry_delegate_get(*fedi);
47 
48  if (delegate->fd_type == type)
49  {
50  if (NULL != index)
51  *index = ii;
52 
53  return (delegate);
54  }
55  else
56  {
57  ii++;
58  }
59  }
60 
61  return (NULL);
62 }
63 
67 {
68  return (fib_entry_delegate_find_i(fib_entry, type, NULL));
69 }
70 
71 void
74 {
76  u32 index = ~0;
77 
78  fed = fib_entry_delegate_find_i(fib_entry, type, &index);
79 
80  ASSERT(NULL != fed);
81 
82  vec_del1(fib_entry->fe_delegates, index);
83 
85 }
86 
87 static int
89  void * v2)
90 {
91  fib_entry_delegate_t *delegate1, *delegate2;
92  index_t *fedi1 = v1, *fedi2 = v2;
93 
94  delegate1 = fib_entry_delegate_get(*fedi1);
95  delegate2 = fib_entry_delegate_get(*fedi2);
96 
97  return (delegate1->fd_type - delegate2->fd_type);
98 }
99 
100 static void
103 
104 {
105  fib_entry_delegate_t *delegate;
106 
108 
109  delegate->fd_entry_index = fib_entry_get_index(fib_entry);
110  delegate->fd_type = type;
111 
112  vec_add1(fib_entry->fe_delegates, delegate - fib_entry_delegate_pool);
115 }
116 
120 {
121  fib_entry_delegate_t *delegate;
122 
123  delegate = fib_entry_delegate_find(fib_entry, fdt);
124 
125  if (NULL == delegate)
126  {
127  fib_entry_delegate_init(fib_entry, fdt);
128  }
129 
130  return (fib_entry_delegate_find(fib_entry, fdt));
131 }
132 
135 {
136  switch (fct)
137  {
151  break;
154  }
155  ASSERT(0);
157 }
158 
161 {
162  switch (fdt)
163  {
175  return (FIB_FORW_CHAIN_TYPE_NSH);
181  break;
182  }
183  ASSERT(0);
185 }
186 
187 /**
188  * typedef for printing a delegate
189  */
190 typedef u8 * (*fib_entry_delegate_format_t)(const fib_entry_delegate_t *fed,
191  u8 *s);
192 
193 /**
194  * Print a delegate that represents a forwarding chain
195  */
196 static u8 *
198  u8 *s)
199 {
200  s = format(s, "%U-chain\n %U",
203  format_dpo_id, &fed->fd_dpo, 2);
204 
205  return (s);
206 }
207 
208 /**
209  * Print a delegate that represents cover tracking
210  */
211 static u8 *
213  u8 *s)
214 {
215  s = format(s, "covered:[");
216  s = fib_node_children_format(fed->fd_list, s);
217  s = format(s, "]");
218 
219  return (s);
220 }
221 
222 /**
223  * Print a delegate that represents attached-import tracking
224  */
225 static u8 *
227  u8 *s)
228 {
229  s = format(s, "import:");
230  s = fib_ae_import_format(fed->fd_index, s);
231 
232  return (s);
233 }
234 
235 /**
236  * Print a delegate that represents attached-export tracking
237  */
238 static u8 *
240  u8 *s)
241 {
242  s = format(s, "export:");
243  s = fib_ae_export_format(fed->fd_index, s);
244 
245  return (s);
246 }
247 
248 /**
249  * Print a delegate that represents BFD tracking
250  */
251 static u8 *
253  u8 *s)
254 {
255  s = format(s, "BFD:%d", fed->fd_bfd_state);
256 
257  return (s);
258 }
259 
260 /**
261  * Print a delegate that represents tracking
262  */
263 static u8 *
265  u8 *s)
266 {
267  u32 indent = format_get_indent (s);
268 
269  s = format(s, "track: sibling:%d", fed->fd_track.fedt_sibling);
270 
271  s = format(s, "\n%UChildren:", format_white_space, indent);
273 
274  return (s);
275 }
276 
277 /**
278  * A delegate type to formatter map
279  */
281 {
293 };
294 
295 u8 *
296 format_fib_entry_delegate (u8 * s, va_list * args)
297 {
299  index_t fedi;
300 
301  fedi = va_arg (*args, index_t);
302  fed = fib_entry_delegate_get(fedi);
303 
304  return (fed_formatters[fed->fd_type](fed, s));
305 }
306 
307 static clib_error_t *
309  unformat_input_t * input,
310  vlib_cli_command_t * cmd)
311 {
312  fib_node_index_t fedi;
313 
314  if (unformat (input, "%d", &fedi))
315  {
316  /*
317  * show one in detail
318  */
320  {
321  vlib_cli_output (vm, "%d@%U",
322  fedi,
324  }
325  else
326  {
327  vlib_cli_output (vm, "entry %d invalid", fedi);
328  }
329  }
330  else
331  {
332  /*
333  * show all
334  */
335  vlib_cli_output (vm, "FIB Entry Delegates:");
337  {
338  vlib_cli_output (vm, "%d@%U",
339  fedi,
341  }
342  }
343 
344  return (NULL);
345 }
346 
348  .path = "show fib entry-delegate",
350  .short_help = "show fib entry delegate",
351 };
fib_entry_delegate_find_i
static fib_entry_delegate_t * fib_entry_delegate_find_i(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type, u32 *index)
Definition: fib_entry_delegate.c:35
fib_ae_export_format
u8 * fib_ae_export_format(fib_node_index_t expi, u8 *s)
Definition: fib_attached_export.c:540
FIB_ENTRY_DELEGATE_ATTACHED_EXPORT
@ FIB_ENTRY_DELEGATE_ATTACHED_EXPORT
Definition: fib_entry_delegate.h:58
fib_entry.h
FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6
@ FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6
Definition: fib_entry_delegate.h:35
FIB_ENTRY_DELEGATE_ATTACHED_IMPORT
@ FIB_ENTRY_DELEGATE_ATTACHED_IMPORT
Attached import/export functionality.
Definition: fib_entry_delegate.h:57
fib_entry_delegate_get_index
fib_node_index_t fib_entry_delegate_get_index(const fib_entry_delegate_t *fed)
Definition: fib_entry_delegate.c:29
fib_entry_delegate_remove
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:72
fib_entry_delegate_track_t_::fedt_node
fib_node_t fedt_node
Definition: fib_entry_delegate.h:89
fib_entry_delegate_type_to_chain_type
fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type(fib_entry_delegate_type_t fdt)
Definition: fib_entry_delegate.c:160
fib_ae_import_format
u8 * fib_ae_import_format(fib_node_index_t impi, u8 *s)
Definition: fib_attached_export.c:511
fib_entry_t_
An entry in a FIB table.
Definition: fib_entry.h:305
format_fib_forw_chain_type
u8 * format_fib_forw_chain_type(u8 *s, va_list *args)
Definition: fib_types.c:49
fib_entry_delegate_track_t_::fedt_sibling
u32 fedt_sibling
Definition: fib_entry_delegate.h:90
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
fib_entry_delegate_get
fib_entry_delegate_t * fib_entry_delegate_get(index_t fedi)
Definition: fib_entry_delegate.c:23
FIB_ENTRY_DELEGATE_CHAIN_ETHERNET
@ FIB_ENTRY_DELEGATE_CHAIN_ETHERNET
Definition: fib_entry_delegate.h:38
FIB_FORW_CHAIN_TYPE_MPLS_EOS
@ FIB_FORW_CHAIN_TYPE_MPLS_EOS
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:128
show_fib_entry_delegate_command
static clib_error_t * show_fib_entry_delegate_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: fib_entry_delegate.c:308
fib_node_t_::fn_children
fib_node_list_t fn_children
Vector of nodes that depend upon/use/share this node.
Definition: fib_node.h:315
vlib_cli_command_t::path
char * path
Definition: cli.h:96
FIB_FORW_CHAIN_TYPE_MCAST_IP4
@ FIB_FORW_CHAIN_TYPE_MCAST_IP4
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:132
fib_entry_delegate.h
FIB_FORW_CHAIN_TYPE_ETHERNET
@ FIB_FORW_CHAIN_TYPE_ETHERNET
Contribute an object that is to be used to forward Ethernet packets.
Definition: fib_types.h:140
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
fib_node_children_format
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:176
unformat_input_t
struct _unformat_input_t unformat_input_t
fib_entry_delegate_find
fib_entry_delegate_t * fib_entry_delegate_find(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:65
fed_formatters
static fib_entry_delegate_format_t fed_formatters[]
A delegate type to formatter map.
Definition: fib_entry_delegate.c:280
FIB_FORW_CHAIN_TYPE_NSH
@ FIB_FORW_CHAIN_TYPE_NSH
Contribute an object that is to be used to forward NSH packets.
Definition: fib_types.h:146
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
FIB_FORW_CHAIN_TYPE_UNICAST_IP4
@ FIB_FORW_CHAIN_TYPE_UNICAST_IP4
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:108
fib_entry_chain_type_to_delegate_type
fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type(fib_forward_chain_type_t fct)
Definition: fib_entry_delegate.c:134
fib_entry_delegate_init
static void fib_entry_delegate_init(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:101
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
show_fib_entry
static vlib_cli_command_t show_fib_entry
(constructor) VLIB_CLI_COMMAND (show_fib_entry)
Definition: fib_entry_delegate.c:347
fib_forward_chain_type_t
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
fib_entry_get_index
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:63
fib_entry_delegate_fmt_export
static u8 * fib_entry_delegate_fmt_export(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents attached-export tracking.
Definition: fib_entry_delegate.c:239
fib_entry_t_::fe_delegates
index_t * fe_delegates
A vector of delegate indices.
Definition: fib_entry.h:353
fib_entry_delegate_fmt_covered
static u8 * fib_entry_delegate_fmt_covered(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents cover tracking.
Definition: fib_entry_delegate.c:212
fib_entry_delegate_find_or_add
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)
Definition: fib_entry_delegate.c:118
fib_entry_delegate_t_::fd_entry_index
fib_node_index_t fd_entry_index
The FIB entry object to which the delagate is attached.
Definition: fib_entry_delegate.h:104
fib_entry_delegate_t_::fd_index
fib_node_index_t fd_index
Valid for the attached import cases.
Definition: fib_entry_delegate.h:128
fib_entry_delegate_t_::fd_bfd_state
fib_bfd_state_t fd_bfd_state
BFD state.
Definition: fib_entry_delegate.h:138
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
FIB_ENTRY_DELEGATE_CHAIN_NSH
@ FIB_ENTRY_DELEGATE_CHAIN_NSH
Definition: fib_entry_delegate.h:39
fib_entry_delegate_pool
static fib_entry_delegate_t * fib_entry_delegate_pool
Definition: fib_entry_delegate.c:20
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
format_dpo_id
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject.
Definition: dpo.c:150
FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS
@ FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS
Definition: fib_entry_delegate.h:36
FIB_ENTRY_DELEGATE_BFD
@ FIB_ENTRY_DELEGATE_BFD
BFD session state.
Definition: fib_entry_delegate.h:49
fib_entry_delegate_cmp_for_sort
static int fib_entry_delegate_cmp_for_sort(void *v1, void *v2)
Definition: fib_entry_delegate.c:88
fib_entry_delegate_type_t
enum fib_entry_delegate_type_t_ fib_entry_delegate_type_t
Delegate types.
fib_entry_delegate_fmt_track
static u8 * fib_entry_delegate_fmt_track(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents tracking.
Definition: fib_entry_delegate.c:264
index
u32 index
Definition: flow_types.api:221
FIB_ENTRY_DELEGATE_COVERED
@ FIB_ENTRY_DELEGATE_COVERED
Dependency list of covered entries.
Definition: fib_entry_delegate.h:45
FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS
@ FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS
Contribute an object that is to be used to forward non-end-of-stack MPLS packets.
Definition: fib_types.h:117
fib_entry_delegate_t_::fd_list
fib_node_list_t fd_list
For the cover tracking.
Definition: fib_entry_delegate.h:133
pool_foreach_index
#define pool_foreach_index(i, v)
Definition: pool.h:572
fib_entry_delegate_t_::fd_track
fib_entry_delegate_track_t fd_track
tracker state
Definition: fib_entry_delegate.h:143
FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS
@ FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS
Definition: fib_entry_delegate.h:37
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u32
unsigned int u32
Definition: types.h:88
fib_entry_delegate_fmt_import
static u8 * fib_entry_delegate_fmt_import(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents attached-import tracking.
Definition: fib_entry_delegate.c:226
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4
@ FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4
Forwarding chain types: for the vast majority of FIB entries only one chain is required - the one tha...
Definition: fib_entry_delegate.h:34
FIB_FORW_CHAIN_TYPE_BIER
@ FIB_FORW_CHAIN_TYPE_BIER
Contribute an object that is to be used to forward BIER packets.
Definition: fib_types.h:121
FIB_FORW_CHAIN_TYPE_MCAST_IP6
@ FIB_FORW_CHAIN_TYPE_MCAST_IP6
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:136
vec_sort_with_function
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1097
vlib_main_t
Definition: main.h:102
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
fib_entry_delegate_format_t
u8 *(* fib_entry_delegate_format_t)(const fib_entry_delegate_t *fed, u8 *s)
typedef for printing a delegate
Definition: fib_entry_delegate.c:190
format_fib_entry_delegate
u8 * format_fib_entry_delegate(u8 *s, va_list *args)
Definition: fib_entry_delegate.c:296
fib_entry_delegate_fmt_fwd_chain
static u8 * fib_entry_delegate_fmt_fwd_chain(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents a forwarding chain.
Definition: fib_entry_delegate.c:197
fib_entry_delegate_t_::fd_type
fib_entry_delegate_type_t fd_type
The delagate type.
Definition: fib_entry_delegate.h:109
FIB_FORW_CHAIN_TYPE_UNICAST_IP6
@ FIB_FORW_CHAIN_TYPE_UNICAST_IP6
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:112
fib_entry_delegate_t_
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
Definition: fib_entry_delegate.h:99
fib_entry_delegate_fmt_bfd
static u8 * fib_entry_delegate_fmt_bfd(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents BFD tracking.
Definition: fib_entry_delegate.c:252
vlib_cli_command_t
Definition: cli.h:92
FIB_ENTRY_DELEGATE_TRACK
@ FIB_ENTRY_DELEGATE_TRACK
Tracker.
Definition: fib_entry_delegate.h:53
fib_attached_export.h
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
fib_entry_delegate_t_::fd_dpo
dpo_id_t fd_dpo
Valid for the forwarding chain delegates.
Definition: fib_entry_delegate.h:123
vec_del1
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:896
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129