FD.io VPP  v17.04.2-2-ga8f93f8
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>
18 
19 static fib_entry_delegate_t *
22  u32 *index)
23 {
24  fib_entry_delegate_t *delegate;
25  int ii;
26 
27  ii = 0;
28  vec_foreach(delegate, fib_entry->fe_delegates)
29  {
30  if (delegate->fd_type == type)
31  {
32  if (NULL != index)
33  *index = ii;
34 
35  return (delegate);
36  }
37  else
38  {
39  ii++;
40  }
41  }
42 
43  return (NULL);
44 }
45 
49 {
50  return (fib_entry_delegate_find_i(fib_entry, type, NULL));
51 }
52 
53 void
56 {
58  u32 index = ~0;
59 
60  fed = fib_entry_delegate_find_i(fib_entry, type, &index);
61 
62  ASSERT(NULL != fed);
63 
64  vec_del1(fib_entry->fe_delegates, index);
65 }
66 
67 static int
69  void * v2)
70 {
71  fib_entry_delegate_t *delegate1 = v1, *delegate2 = v2;
72 
73  return (delegate1->fd_type - delegate2->fd_type);
74 }
75 
76 static void
79 
80 {
81  fib_entry_delegate_t delegate = {
82  .fd_entry_index = fib_entry_get_index(fib_entry),
83  .fd_type = type,
84  };
85 
86  vec_add1(fib_entry->fe_delegates, delegate);
89 }
90 
94 {
95  fib_entry_delegate_t *delegate;
96 
97  delegate = fib_entry_delegate_get(fib_entry, fdt);
98 
99  if (NULL == delegate)
100  {
101  fib_entry_delegate_init(fib_entry, fdt);
102  }
103 
104  return (fib_entry_delegate_get(fib_entry, fdt));
105 }
106 
109 {
110  switch (fct)
111  {
124  break;
127  }
128  ASSERT(0);
130 }
131 
134 {
135  switch (fdt)
136  {
148  return (FIB_FORW_CHAIN_TYPE_NSH);
152  break;
153  }
154  ASSERT(0);
156 }
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:373
#define NULL
Definition: clib.h:55
enum fib_entry_delegate_type_t_ fib_entry_delegate_type_t
Delegate types.
#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
static void fib_entry_delegate_init(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
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)
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
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_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
fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type(fib_forward_chain_type_t fct)
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.
fib_entry_delegate_t * fe_delegates
A vector of delegates.
Definition: fib_entry.h:421
#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...
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)