FD.io VPP  v21.06-3-gbb25fbf28
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 }
mfib_entry_delegate_init
static void mfib_entry_delegate_init(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
Definition: mfib_entry_delegate.c:77
mfib_entry_delegate_get
mfib_entry_delegate_t * mfib_entry_delegate_get(const mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
Definition: mfib_entry_delegate.c:47
mfib_entry_delegate_find_or_add
mfib_entry_delegate_t * mfib_entry_delegate_find_or_add(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t fdt)
Definition: mfib_entry_delegate.c:92
mfib_entry.h
mfib_entry_get_index
static fib_node_index_t mfib_entry_get_index(const mfib_entry_t *mfe)
Definition: mfib_entry.h:205
fib_node_children_format
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:176
mfib_entry_delegate_cmp_for_sort
static int mfib_entry_delegate_cmp_for_sort(void *v1, void *v2)
Definition: mfib_entry_delegate.c:68
MFIB_ENTRY_DELEGATE_COVERED
@ MFIB_ENTRY_DELEGATE_COVERED
Dependency list of covered entries.
Definition: mfib_entry_delegate.h:30
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
mfib_entry_delegate_find_i
static mfib_entry_delegate_t * mfib_entry_delegate_find_i(const mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type, u32 *index)
Definition: mfib_entry_delegate.c:20
mfib_entry_delegate_remove
void mfib_entry_delegate_remove(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
Definition: mfib_entry_delegate.c:54
index
u32 index
Definition: flow_types.api:221
mfib_entry_delegate_t_::mfd_list
fib_node_list_t mfd_list
For the cover tracking.
Definition: mfib_entry_delegate.h:74
mfib_entry_t_::fe_delegates
mfib_entry_delegate_t * fe_delegates
A vector of delegates.
Definition: mfib_entry.h:92
mfib_entry_delegate.h
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
mfib_entry_delegate_t_::mfd_entry_index
fib_node_index_t mfd_entry_index
The MFIB entry object to which the delagate is attached.
Definition: mfib_entry_delegate.h:57
fed_formatters
static mfib_entry_delegate_format_t fed_formatters[]
A delegate type to formatter map.
Definition: mfib_entry_delegate.c:130
u32
unsigned int u32
Definition: types.h:88
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
mfib_entry_t_
An entry in a FIB table.
Definition: mfib_entry.h:32
vec_sort_with_function
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1097
u8
unsigned char u8
Definition: types.h:56
mfib_entry_delegate_format_t
u8 *(* mfib_entry_delegate_format_t)(const mfib_entry_delegate_t *fed, u8 *s)
typedef for printing a delegate
Definition: mfib_entry_delegate.c:110
mfib_entry_delegate_fmt_covered
static u8 * mfib_entry_delegate_fmt_covered(const mfib_entry_delegate_t *fed, u8 *s)
Print a delegate that represents cover tracking.
Definition: mfib_entry_delegate.c:117
mfib_entry_delegate_t_
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
Definition: mfib_entry_delegate.h:52
mfib_entry_delegate_t_::mfd_type
mfib_entry_delegate_type_t mfd_type
The delagate type.
Definition: mfib_entry_delegate.h:62
mfib_entry_delegate_type_t
enum mfib_entry_delegate_type_t_ mfib_entry_delegate_type_t
Delegate types.
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vec_del1
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:896
format_mfib_entry_deletegate
u8 * format_mfib_entry_deletegate(u8 *s, va_list *args)
Definition: mfib_entry_delegate.c:136