FD.io VPP  v21.01.1
Vector Packet Processing
fib_entry_track.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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_table.h>
19 #include <vnet/fib/fib_walk.h>
20 
21 static fib_entry_delegate_t *
23  const fib_prefix_t *prefix)
24 {
26  fib_node_index_t fei;
27 
28  fei = fib_table_entry_special_add(fib_index,
29  prefix,
32 
35 
38 
39  fed->fd_entry_index = fei;
40  fed->fd_track.fedt_sibling =
44 
45  return (fed);
46 }
47 
49 fib_entry_track (u32 fib_index,
50  const fib_prefix_t *prefix,
51  fib_node_type_t child_type,
52  index_t child_index,
53  u32 *sibling)
54 {
56  fib_node_index_t fei;
57 
58  fei = fib_table_lookup_exact_match(fib_index, prefix);
59 
60  if (INDEX_INVALID == fei ||
61  NULL == (fed = fib_entry_delegate_find(fib_entry_get(fei),
63  {
64  fed = fib_entry_track_delegate_add(fib_index, prefix);
65  }
66 
67  /*
68  * add this child to the entry's delegate
69  */
72  child_type,
73  child_index);
74 
75  return (fed->fd_entry_index);
76 }
77 
78 void
80  u32 sibling)
81 {
83 
86 
87  if (NULL != fed)
88  {
91  sibling);
92  /* if this is the last child the delegate will be removed. */
93  }
94  /* else untracked */
95 }
96 
97 static fib_node_t *
99 {
101 
102  fed = fib_entry_delegate_get(index);
103  return (&fed->fd_track.fedt_node);
104 }
105 
106 static fib_entry_delegate_t*
108 {
110  return ((fib_entry_delegate_t *) (((char *) node) -
112  fd_track.fedt_node)));
113 }
114 
115 static void
117 {
119  fib_node_index_t fei;
120  u32 sibling;
121 
123  fei = fed->fd_entry_index;
124  sibling = fed->fd_track.fedt_sibling;
125 
126  /*
127  * the tracker has no more children so it can be removed,
128  * and the FIB entry unsourced.
129  * remove the delegate first, then unlock the fib entry,
130  * since the delegate may be holding the last lock
131  */
134  /* having removed the deletegate the fed object is now toast */
135  fib_entry_child_remove(fei, sibling);
136 
138 }
139 
143 {
145 
147 
148  /*
149  * propagate the walk to the delgate's children
150  */
151 
154  ctx);
155 
157 }
158 
159 static void
161 {
162 }
163 
164 /*
165  * The FIB entry tracker's graph node virtual function table
166  */
167 static const fib_node_vft_t fib_entry_track_vft = {
169  .fnv_last_lock = fib_entry_track_last_lock_gone,
170  .fnv_back_walk = fib_entry_track_back_walk_notify,
171  .fnv_mem_show = fib_entry_track_show_memory,
172 };
173 
174 void
176 {
177  fib_node_register_type(FIB_NODE_TYPE_ENTRY_TRACK, &fib_entry_track_vft);
178 }
Tracker.
fib_node_index_t fib_entry_track(u32 fib_index, const fib_prefix_t *prefix, fib_node_type_t child_type, index_t child_index, u32 *sibling)
Trackers are used on FIB entries by objects that which to track the changing state of the entry...
fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: fib_table.c:97
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_entry.c:555
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
Definition: fib_entry.c:566
fib_entry_delegate_t * fib_entry_delegate_find(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:70
vl_api_prefix_t prefix
Definition: ip.api:144
fib_node_index_t fd_entry_index
The FIB entry object to which the delagate is attached.
u32 fib_node_child_add(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_type_t type, fib_node_index_t index)
Definition: fib_node.c:98
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:60
fib_entry_delegate_t * fib_entry_delegate_get(index_t fedi)
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
void fib_walk_sync(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_back_walk_ctx_t *ctx)
Back walk all the children of a FIB node.
Definition: fib_walk.c:745
Recursive resolution source.
Definition: fib_source.h:119
Aggregate type for a prefix.
Definition: fib_types.h:202
unsigned int u32
Definition: types.h:88
static fib_entry_delegate_t * fib_entry_delegate_from_fib_node(fib_node_t *node)
fib_entry_delegate_track_t fd_track
tracker state
Definition: fib_entry.h:112
static void fib_entry_track_last_lock_gone(fib_node_t *node)
static fib_entry_delegate_t * fib_entry_track_delegate_add(u32 fib_index, const fib_prefix_t *prefix)
static void fib_entry_track_show_memory(void)
static fib_node_back_walk_rc_t fib_entry_track_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
long ctx[MAX_CONNS]
Definition: main.c:144
u32 fedt_sibling
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:299
An node in the FIB graph.
Definition: fib_node.h:295
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:405
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:919
fib_node_get_t fnv_get
Definition: fib_node.h:283
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1580
Context passed between object during a back walk.
Definition: fib_node.h:208
#define ASSERT(truth)
void fib_entry_untrack(fib_node_index_t fei, u32 sibling)
Stop tracking a FIB entry.
static fib_node_t * fib_entry_track_get_node(fib_node_index_t index)
void fib_entry_track_module_init(void)
void fib_node_child_remove(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_index_t sibling_index)
Definition: fib_node.c:123
fib_node_index_t fib_entry_delegate_get_index(const fib_entry_delegate_t *fed)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
u32 index
Definition: flow_types.api:221
fib_node_t fedt_node
A FIB graph nodes virtual function table.
Definition: fib_node.h:282
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)