FD.io VPP  v21.06-3-gbb25fbf28
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 
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  */
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 {
178 }
fib_entry_track_vft
static const fib_node_vft_t fib_entry_track_vft
Definition: fib_entry_track.c:167
fib_entry_delegate_get_index
fib_node_index_t fib_entry_delegate_get_index(const fib_entry_delegate_t *fed)
Definition: fib_entry_delegate.c:29
fib_entry_delegate_remove
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:72
fib_entry_delegate_track_t_::fedt_node
fib_node_t fedt_node
Definition: fib_entry_delegate.h:89
fib_node_back_walk_rc_t
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
fib_entry_delegate_track_t_::fedt_sibling
u32 fedt_sibling
Definition: fib_entry_delegate.h:90
fib_entry_untrack
void fib_entry_untrack(fib_node_index_t fei, u32 sibling)
Stop tracking a FIB entry.
Definition: fib_entry_track.c:79
fib_entry_delegate_get
fib_entry_delegate_t * fib_entry_delegate_get(index_t fedi)
Definition: fib_entry_delegate.c:23
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
fib_node_vft_t_
A FIB graph nodes virtual function table.
Definition: fib_node.h:288
fib_table.h
fib_entry_delegate.h
fib_entry_delegate_find
fib_entry_delegate_t * fib_entry_delegate_find(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:65
fib_node_type_t
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
fib_entry_track_show_memory
static void fib_entry_track_show_memory(void)
Definition: fib_entry_track.c:160
fib_entry_track
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.
Definition: fib_entry_track.c:49
STRUCT_OFFSET_OF
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:73
fib_entry_child_add
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
fib_walk.h
fib_entry_track_module_init
void fib_entry_track_module_init(void)
Definition: fib_entry_track.c:175
FIB_ENTRY_FLAG_NONE
@ FIB_ENTRY_FLAG_NONE
Definition: fib_entry.h:112
index_t
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:43
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
fib_entry_track_delegate_add
static fib_entry_delegate_t * fib_entry_track_delegate_add(u32 fib_index, const fib_prefix_t *prefix)
Definition: fib_entry_track.c:22
fib_entry_delegate_find_or_add
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)
Definition: fib_entry_delegate.c:118
fib_entry_delegate_t_::fd_entry_index
fib_node_index_t fd_entry_index
The FIB entry object to which the delagate is attached.
Definition: fib_entry_delegate.h:104
fib_entry_track_last_lock_gone
static void fib_entry_track_last_lock_gone(fib_node_t *node)
Definition: fib_entry_track.c:116
fib_entry_track_back_walk_notify
static fib_node_back_walk_rc_t fib_entry_track_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Definition: fib_entry_track.c:141
fib_node_register_type
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_NODE_BACK_WALK_CONTINUE
@ FIB_NODE_BACK_WALK_CONTINUE
Definition: fib_node.h:259
fib_entry_track.h
fib_table_lookup_exact_match
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
fib_walk_sync
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
index
u32 index
Definition: flow_types.api:221
fib_entry_delegate_t_::fd_track
fib_entry_delegate_track_t fd_track
tracker state
Definition: fib_entry_delegate.h:143
fib_entry_get
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
fib_node_t_
An node in the FIB graph.
Definition: fib_node.h:301
fib_node_init
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
fib_entry_track_get_node
static fib_node_t * fib_entry_track_get_node(fib_node_index_t index)
Definition: fib_entry_track.c:98
fib_entry_delegate_from_fib_node
static fib_entry_delegate_t * fib_entry_delegate_from_fib_node(fib_node_t *node)
Definition: fib_entry_track.c:107
fib_node_back_walk_ctx_t_
Context passed between object during a back walk.
Definition: fib_node.h:214
FIB_SOURCE_RR
@ FIB_SOURCE_RR
Recursive resolution source.
Definition: fib_source.h:122
fib_node_vft_t_::fnv_get
fib_node_get_t fnv_get
Definition: fib_node.h:289
fib_node_child_remove
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_TYPE_ENTRY_TRACK
@ FIB_NODE_TYPE_ENTRY_TRACK
Definition: fib_node.h:52
fib_table_entry_delete_index
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_entry_delegate_t_
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
Definition: fib_entry_delegate.h:99
fib_table_entry_special_add
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 'special' entry to the FIB.
Definition: fib_table.c:405
fib_entry_child_remove
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
Definition: fib_entry.c:566
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
FIB_ENTRY_DELEGATE_TRACK
@ FIB_ENTRY_DELEGATE_TRACK
Tracker.
Definition: fib_entry_delegate.h:53
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
fib_node_child_add
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
prefix
vl_api_prefix_t prefix
Definition: ip.api:146