FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
fib_entry_cover.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_src.h>
18 #include <vnet/fib/fib_node_list.h>
19 
20 u32
22  fib_node_index_t covered)
23 {
25 
26  FIB_ENTRY_DBG(cover, "cover-track %d", covered);
27 
28  ASSERT(fib_entry_get_index(cover) != covered);
29 
31 
32  if (NULL == fed)
33  {
36  }
37 
38  return (fib_node_list_push_front(fed->fd_list,
40  covered));
41 }
42 
43 void
45  u32 tracked_index)
46 {
48 
49  FIB_ENTRY_DBG(cover, "cover-untrack @ %d", tracked_index);
50 
52 
53  if (NULL == fed)
54  return;
55 
56  fib_node_list_remove(fed->fd_list, tracked_index);
57 
58  if (0 == fib_node_list_get_size(fed->fd_list))
59  {
62  }
63 }
64 
65 /**
66  * Internal struct to hold user supplied paraneters for the cover walk
67  */
71  void *ctx;
73 
74 static int
76  void *args)
77 {
79 
80  ctx->walk(ctx->cover, depend->fnp_index, ctx->ctx);
81 
82  /* continue */
83  return (1);
84 }
85 
86 void
89  void *args)
90 {
92 
94 
95  if (NULL == fed)
96  return;
97 
99  .cover = cover,
100  .walk = walk,
101  .ctx = args,
102  };
103 
106  &ctx);
107 }
108 
109 u32
111 {
113 
115 
116  if (NULL == fed)
117  return (0);
118 
119  return (fib_node_list_get_size(fed->fd_list));
120 }
121 
123  u8 *s;
125 
126 static int
128  fib_node_index_t covered,
129  void *args)
130 {
132 
133  ctx->s = format(ctx->s, "%d, ", covered);
134 
135  /* continue */
136  return (1);
137 }
138 
139 u8*
141  u8 *s)
142 {
144  .s = s,
145  };
146 
147  fib_entry_cover_walk(fib_entry,
149  &ctx);
150 
151  return (ctx.s);
152 }
153 
154 static int
156  fib_node_index_t covered,
157  void *args)
158 {
159  fib_node_index_t new_cover;
160 
161  /*
162  * The 3 entries involved here are:
163  * cover - the least specific. It will cover both the others
164  * new_cover - the enty just inserted below the cover
165  * covered - the entry that was tracking the cover.
166  *
167  * The checks below are to determine if new_cover is a cover for covered.
168  */
169  new_cover = pointer_to_uword(args);
170 
171  if (FIB_NODE_INDEX_INVALID == new_cover)
172  {
173  /*
174  * nothing has been inserted, which implies the cover was removed.
175  * 'cover' is thus the new cover.
176  */
177  fib_entry_cover_changed(covered);
178  }
179  else if (new_cover != covered)
180  {
181  fib_prefix_t pfx_covered, pfx_new_cover;
182 
183  fib_entry_get_prefix(covered, &pfx_covered);
184  fib_entry_get_prefix(new_cover, &pfx_new_cover);
185 
186  if (fib_prefix_is_cover(&pfx_new_cover, &pfx_covered))
187  {
188  fib_entry_cover_changed(covered);
189  }
190  }
191  /* continue */
192  return (1);
193 }
194 
195 void
197  fib_node_index_t covered)
198 {
200 
201  cover = fib_entry_get(cover_index);
202 
203  fib_entry_cover_walk(cover,
205  uword_to_pointer(covered, void*));
206 }
207 
208 static int
210  fib_node_index_t covered,
211  void *args)
212 {
213  fib_entry_cover_updated(covered);
214 
215  /* continue */
216  return (1);
217 }
218 
219 void
221 {
222  fib_entry_cover_walk(fib_entry,
224  NULL);
225 }
static int fib_entry_cover_change_one(fib_entry_t *cover, fib_node_index_t covered, void *args)
static int fib_entry_cover_update_one(fib_entry_t *cover, fib_node_index_t covered, void *args)
#define FIB_ENTRY_DBG(_e, _fmt, _args...)
Debug macro.
Definition: fib_entry_src.h:42
An entry in a FIB table.
Definition: fib_entry.h:373
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
int(* fib_entry_covered_walk_t)(fib_entry_t *cover, fib_node_index_t covered, void *ctx)
callback function used when walking the covered entries
void fib_entry_get_prefix(fib_node_index_t fib_entry_index, fib_prefix_t *pfx)
Definition: fib_entry.c:1456
#define NULL
Definition: clib.h:55
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
void fib_node_list_walk(fib_node_list_t list, fib_node_list_walk_cb_t fn, void *args)
Walk the list of node.
struct fib_entry_cover_list_format_ctx_t_ fib_entry_cover_list_format_ctx_t
u32 fib_entry_cover_track(fib_entry_t *cover, fib_node_index_t covered)
fib_node_index_t fnp_index
node&#39;s index
Definition: fib_node.h:179
void fib_node_list_remove(fib_node_list_t list, u32 sibling)
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Aggregrate type for a prefix.
Definition: fib_types.h:160
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:56
int fib_prefix_is_cover(const fib_prefix_t *p1, const fib_prefix_t *p2)
Compare two prefixes for covering relationship.
Definition: fib_types.c:113
A representation of one pointer to another node.
Definition: fib_node.h:171
struct fib_enty_cover_walk_ctx_t_ fib_enty_cover_walk_ctx_t
Internal struct to hold user supplied paraneters for the cover walk.
fib_entry_delegate_t * fib_entry_delegate_get(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
fib_node_list_t fd_list
For the cover tracking.
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static int fib_entry_covered_list_format_one(fib_entry_t *cover, fib_node_index_t covered, void *args)
u32 fib_entry_cover_get_size(fib_entry_t *cover)
u32 fib_node_list_push_front(fib_node_list_t list, int owner_id, fib_node_type_t type, fib_node_index_t index)
Insert an element at the from of the list.
#define uword_to_pointer(u, type)
Definition: types.h:136
void fib_entry_cover_change_notify(fib_node_index_t cover_index, fib_node_index_t covered)
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:44
u32 fib_node_list_get_size(fib_node_list_t list)
#define ASSERT(truth)
fib_node_list_t fib_node_list_create(void)
Create a new node list.
unsigned int u32
Definition: types.h:88
fib_entry_covered_walk_t walk
void fib_node_list_destroy(fib_node_list_t *list)
void fib_entry_cover_changed(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1132
u8 * s
void fib_entry_cover_walk(fib_entry_t *cover, fib_entry_covered_walk_t walk, void *args)
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
unsigned char u8
Definition: types.h:56
void fib_entry_cover_updated(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1204
static int fib_entry_cover_walk_node_ptr(fib_node_ptr_t *depend, void *args)
Dependency list of covered entries.
void fib_entry_cover_update_notify(fib_entry_t *fib_entry)
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)
Internal struct to hold user supplied paraneters for the cover walk.
u8 * fib_entry_cover_list_format(fib_entry_t *fib_entry, u8 *s)