FD.io VPP  v18.07.1-19-g511ce25
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 
20 static fib_entry_delegate_t *
23  u32 *index)
24 {
25  fib_entry_delegate_t *delegate;
26  int ii;
27 
28  ii = 0;
29  vec_foreach(delegate, fib_entry->fe_delegates)
30  {
31  if (delegate->fd_type == type)
32  {
33  if (NULL != index)
34  *index = ii;
35 
36  return (delegate);
37  }
38  else
39  {
40  ii++;
41  }
42  }
43 
44  return (NULL);
45 }
46 
50 {
51  return (fib_entry_delegate_find_i(fib_entry, type, NULL));
52 }
53 
54 void
57 {
59  u32 index = ~0;
60 
61  fed = fib_entry_delegate_find_i(fib_entry, type, &index);
62 
63  ASSERT(NULL != fed);
64 
65  vec_del1(fib_entry->fe_delegates, index);
66 }
67 
68 static int
70  void * v2)
71 {
72  fib_entry_delegate_t *delegate1 = v1, *delegate2 = v2;
73 
74  return (delegate1->fd_type - delegate2->fd_type);
75 }
76 
77 static void
80 
81 {
82  fib_entry_delegate_t delegate = {
83  .fd_entry_index = fib_entry_get_index(fib_entry),
84  .fd_type = type,
85  };
86 
87  vec_add1(fib_entry->fe_delegates, delegate);
90 }
91 
95 {
96  fib_entry_delegate_t *delegate;
97 
98  delegate = fib_entry_delegate_get(fib_entry, fdt);
99 
100  if (NULL == delegate)
101  {
102  fib_entry_delegate_init(fib_entry, fdt);
103  }
104 
105  return (fib_entry_delegate_get(fib_entry, fdt));
106 }
107 
110 {
111  switch (fct)
112  {
126  break;
129  }
130  ASSERT(0);
132 }
133 
136 {
137  switch (fdt)
138  {
150  return (FIB_FORW_CHAIN_TYPE_NSH);
155  break;
156  }
157  ASSERT(0);
159 }
160 
161 /**
162  * typedef for printing a delegate
163  */
164 typedef u8 * (*fib_entry_delegate_format_t)(const fib_entry_delegate_t *fed,
165  u8 *s);
166 
167 /**
168  * Print a delegate that represents a forwarding chain
169  */
170 static u8 *
172  u8 *s)
173 {
174  s = format(s, "%U-chain\n %U",
177  format_dpo_id, &fed->fd_dpo, 2);
178 
179  return (s);
180 }
181 
182 /**
183  * Print a delegate that represents cover tracking
184  */
185 static u8 *
187  u8 *s)
188 {
189  s = format(s, "covered:[");
190  s = fib_node_children_format(fed->fd_list, s);
191  s = format(s, "]");
192 
193  return (s);
194 }
195 
196 /**
197  * Print a delegate that represents attached-import tracking
198  */
199 static u8 *
201  u8 *s)
202 {
203  s = format(s, "import:%U", fib_ae_import_format, fed->fd_index);
204 
205  return (s);
206 }
207 
208 /**
209  * Print a delegate that represents attached-export tracking
210  */
211 static u8 *
213  u8 *s)
214 {
215  s = format(s, "export:%U", fib_ae_export_format, fed->fd_index);
216 
217  return (s);
218 }
219 
220 /**
221  * Print a delegate that represents BFD tracking
222  */
223 static u8 *
225  u8 *s)
226 {
227  s = format(s, "BFD:%d", fed->fd_bfd_state);
228 
229  return (s);
230 }
231 
232 /**
233  * A delegate type to formatter map
234  */
236 {
247 };
248 
249 u8 *
250 format_fib_entry_deletegate (u8 * s, va_list * args)
251 {
253 
254  fed = va_arg (*args, fib_entry_delegate_t *);
255 
256  return (fed_formatters[fed->fd_type](fed, s));
257 }
Contribute an object that is to be used to forward BIER packets.
Definition: fib_types.h:112
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:127
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:103
An entry in a FIB table.
Definition: fib_entry.h:458
BFD session state.
static u8 * fib_entry_delegate_fmt_bfd(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents BFD tracking.
fib_node_index_t fd_index
Valid for the attached import cases.
#define NULL
Definition: clib.h:55
enum fib_entry_delegate_type_t_ fib_entry_delegate_type_t
Delegate types.
static u8 * fib_entry_delegate_fmt_import(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents attached-import tracking.
fib_bfd_state_t fd_bfd_state
BFD state.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:99
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static void fib_entry_delegate_init(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
dpo_id_t fd_dpo
Valid for the forwarding chain delegates.
unsigned char u8
Definition: types.h:56
fib_node_index_t fd_entry_index
The FIB entry object to which the delagate is attached.
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
u8 * fib_ae_export_format(fib_node_index_t expi, u8 *s)
static int fib_entry_delegate_cmp_for_sort(void *v1, void *v2)
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:57
static u8 * fib_entry_delegate_fmt_covered(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents cover tracking.
unsigned int u32
Definition: types.h:88
Contribute an object that is to be used to forward Ethernet packets.
Definition: fib_types.h:131
fib_entry_delegate_t * fib_entry_delegate_get(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
fib_node_list_t fd_list
For the cover tracking.
static u8 * fib_entry_delegate_fmt_fwd_chain(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents a forwarding chain.
fib_entry_delegate_type_t fd_type
The delagate type.
Attached import/export functionality.
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:119
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:806
u8 * format_fib_entry_deletegate(u8 *s, va_list *args)
fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type(fib_forward_chain_type_t fct)
u8 * fib_ae_import_format(fib_node_index_t impi, u8 *s)
Contribute an object that is to be used to forward NSH packets.
Definition: fib_types.h:137
fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type(fib_entry_delegate_type_t fdt)
#define ASSERT(truth)
Forwarding chain types: for the vast majority of FIB entries only one chain is required - the one tha...
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
u8 * format_fib_forw_chain_type(u8 *s, va_list *args)
Definition: fib_types.c:48
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:147
fib_entry_delegate_t * fe_delegates
A vector of delegates.
Definition: fib_entry.h:506
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:982
#define vec_foreach(var, vec)
Vector iterator.
static fib_entry_delegate_t * fib_entry_delegate_find_i(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type, u32 *index)
Contribute an object that is to be used to forward non-end-of-stack MPLS packets. ...
Definition: fib_types.h:108
Dependency list of covered entries.
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
static fib_entry_delegate_format_t fed_formatters[]
A delegate type to formatter map.
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:176
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:123
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)
u8 *(* fib_entry_delegate_format_t)(const fib_entry_delegate_t *fed, u8 *s)
typedef for printing a delegate
static u8 * fib_entry_delegate_fmt_export(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents attached-export tracking.