FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
mfib_entry_delegate.c
Go to the documentation of this file.
1 /*
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 
17 #include <vnet/mfib/mfib_entry.h>
18 
19 static mfib_entry_delegate_t *
22  u32 *index)
23 {
24  mfib_entry_delegate_t *delegate;
25  int ii;
26 
27  ii = 0;
28  vec_foreach(delegate, mfib_entry->fe_delegates)
29  {
30  if (delegate->mfd_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 (mfib_entry_delegate_find_i(mfib_entry, type, NULL));
51 }
52 
53 void
56 {
58  u32 index = ~0;
59 
60  fed = mfib_entry_delegate_find_i(mfib_entry, type, &index);
61 
62  ASSERT(NULL != fed);
63 
64  vec_del1(mfib_entry->fe_delegates, index);
65 }
66 
67 static int
69  void * v2)
70 {
71  mfib_entry_delegate_t *delegate1 = v1, *delegate2 = v2;
72 
73  return (delegate1->mfd_type - delegate2->mfd_type);
74 }
75 
76 static void
79 
80 {
81  mfib_entry_delegate_t delegate = {
83  .mfd_type = type,
84  };
85 
86  vec_add1(mfib_entry->fe_delegates, delegate);
89 }
90 
94 {
95  mfib_entry_delegate_t *delegate;
96 
97  delegate = mfib_entry_delegate_get(mfib_entry, fdt);
98 
99  if (NULL == delegate)
100  {
101  mfib_entry_delegate_init(mfib_entry, fdt);
102  }
103 
104  return (mfib_entry_delegate_get(mfib_entry, fdt));
105 }
106 
107 /**
108  * typedef for printing a delegate
109  */
110 typedef u8 * (*mfib_entry_delegate_format_t)(const mfib_entry_delegate_t *fed,
111  u8 *s);
112 
113 /**
114  * Print a delegate that represents cover tracking
115  */
116 static u8 *
118  u8 *s)
119 {
120  s = format(s, "covered:[");
121  s = fib_node_children_format(fed->mfd_list, s);
122  s = format(s, "]");
123 
124  return (s);
125 }
126 
127 /**
128  * A delegate type to formatter map
129  */
131 {
133 };
134 
135 u8 *
136 format_mfib_entry_deletegate (u8 * s, va_list * args)
137 {
139 
140  fed = va_arg (*args, mfib_entry_delegate_t *);
141 
142  return (fed_formatters[fed->mfd_type](fed, s));
143 }
void mfib_entry_delegate_remove(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
fib_node_index_t mfd_entry_index
The MFIB entry object to which the delagate is attached.
An entry in a FIB table.
Definition: mfib_entry.h:32
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
u8 *(* mfib_entry_delegate_format_t)(const mfib_entry_delegate_t *fed, u8 *s)
typedef for printing a delegate
static fib_node_index_t mfib_entry_get_index(const mfib_entry_t *mfe)
Definition: mfib_entry.h:205
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
u8 * format_mfib_entry_deletegate(u8 *s, va_list *args)
static void mfib_entry_delegate_init(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
static int mfib_entry_delegate_cmp_for_sort(void *v1, void *v2)
mfib_entry_delegate_type_t mfd_type
The delagate type.
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:875
static mfib_entry_delegate_t * mfib_entry_delegate_find_i(const mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type, u32 *index)
fib_node_list_t mfd_list
For the cover tracking.
enum mfib_entry_delegate_type_t_ mfib_entry_delegate_type_t
Delegate types.
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
mfib_entry_delegate_t * mfib_entry_delegate_get(const mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
mfib_entry_delegate_t * mfib_entry_delegate_find_or_add(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t fdt)
#define ASSERT(truth)
static u8 * mfib_entry_delegate_fmt_covered(const mfib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents cover tracking.
Dependency list of covered entries.
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1055
u32 index
Definition: flow_types.api:221
#define vec_foreach(var, vec)
Vector iterator.
mfib_entry_delegate_t * fe_delegates
A vector of delegates.
Definition: mfib_entry.h:92
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:176
static mfib_entry_delegate_format_t fed_formatters[]
A delegate type to formatter map.