FD.io VPP  v17.07.01-10-g3be13f0
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  {
125  break;
128  }
129  ASSERT(0);
131 }
132 
135 {
136  switch (fdt)
137  {
149  return (FIB_FORW_CHAIN_TYPE_NSH);
154  break;
155  }
156  ASSERT(0);
158 }
159 
160 /**
161  * typedef for printing a delegate
162  */
163 typedef u8 * (*fib_entry_delegate_format_t)(const fib_entry_delegate_t *fed,
164  u8 *s);
165 
166 /**
167  * Print a delegate that represents a forwarding chain
168  */
169 static u8 *
171  u8 *s)
172 {
173  s = format(s, "%U-chain\n %U",
176  format_dpo_id, &fed->fd_dpo, 2);
177 
178  return (s);
179 }
180 
181 /**
182  * Print a delegate that represents cover tracking
183  */
184 static u8 *
186  u8 *s)
187 {
188  s = format(s, "covered:[");
189  s = fib_node_children_format(fed->fd_list, s);
190  s = format(s, "]");
191 
192  return (s);
193 }
194 
195 /**
196  * Print a delegate that represents attached-import tracking
197  */
198 static u8 *
200  u8 *s)
201 {
202  s = format(s, "import:%U", fib_ae_import_format, fed->fd_index);
203 
204  return (s);
205 }
206 
207 /**
208  * Print a delegate that represents attached-export tracking
209  */
210 static u8 *
212  u8 *s)
213 {
214  s = format(s, "export:%U", fib_ae_export_format, fed->fd_index);
215 
216  return (s);
217 }
218 
219 /**
220  * Print a delegate that represents BFD tracking
221  */
222 static u8 *
224  u8 *s)
225 {
226  s = format(s, "BFD:%d", fed->fd_bfd_state);
227 
228  return (s);
229 }
230 
231 /**
232  * A delegate type to formatter map
233  */
235 {
246 };
247 
248 u8 *
249 format_fib_entry_deletegate (u8 * s, va_list * args)
250 {
252 
253  fed = va_arg (*args, fib_entry_delegate_t *);
254 
255  return (fed_formatters[fed->fd_type](fed, s));
256 }
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:105
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:85
An entry in a FIB table.
Definition: fib_entry.h:380
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:522
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:81
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.
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:56
static u8 * fib_entry_delegate_fmt_covered(const fib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents cover tracking.
Contribute an object that is to be used to forward Ethernet packets.
Definition: fib_types.h:109
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:97
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:805
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:115
fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type(fib_entry_delegate_type_t fdt)
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
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:46
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:123
fib_entry_delegate_t * fe_delegates
A vector of delegates.
Definition: fib_entry.h:428
unsigned char u8
Definition: types.h:56
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:960
#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:90
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:174
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:101
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.