FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
mfib_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 
18 #include <vnet/fib/fib_node_list.h>
19 
20 u32
22  fib_node_index_t covered)
23 {
25 
26  MFIB_ENTRY_DBG(cover, "cover-track %d", covered);
27 
28  ASSERT(mfib_entry_get_index(cover) != covered);
29 
31 
32  if (NULL == mfed)
33  {
36  }
37 
38  return (fib_node_list_push_front(mfed->mfd_list,
40  covered));
41 }
42 
43 void
45  u32 tracked_index)
46 {
48 
49  MFIB_ENTRY_DBG(cover, "cover-untrack @ %d", tracked_index);
50 
52 
53  if (NULL == mfed)
54  return;
55 
56  fib_node_list_remove(mfed->mfd_list, tracked_index);
57 
58  if (0 == fib_node_list_get_size(mfed->mfd_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 == mfed)
96  return;
97 
99  .cover = cover,
100  .walk = walk,
101  .ctx = args,
102  };
103 
106  &ctx);
107 }
108 
109 static int
111  fib_node_index_t covered,
112  void *args)
113 {
114  fib_node_index_t new_cover;
115 
116  /*
117  * The 3 entries involved here are:
118  * cover - the least specific. It will cover both the others
119  * new_cover - the enty just inserted below the cover
120  * covered - the entry that was tracking the cover.
121  *
122  * The checks below are to determine if new_cover is a cover for covered.
123  */
124  new_cover = pointer_to_uword(args);
125 
126  if (FIB_NODE_INDEX_INVALID == new_cover)
127  {
128  /*
129  * nothing has been inserted, which implies the cover was removed.
130  * 'cover' is thus the new cover.
131  */
132  mfib_entry_cover_changed(covered);
133  }
134  else if (new_cover != covered)
135  {
136  const mfib_prefix_t *pfx_covered, *pfx_new_cover;
137 
138  pfx_covered = mfib_entry_get_prefix(covered);
139  pfx_new_cover = mfib_entry_get_prefix(new_cover);
140 
141  if (mfib_prefix_is_cover(pfx_new_cover, pfx_covered))
142  {
143  mfib_entry_cover_changed(covered);
144  }
145  }
146  /* continue */
147  return (1);
148 }
149 
150 void
152  fib_node_index_t covered)
153 {
155 
156  cover = mfib_entry_get(cover_index);
157 
158  mfib_entry_cover_walk(cover,
160  uword_to_pointer(covered, void*));
161 }
162 
163 static int
165  fib_node_index_t covered,
166  void *args)
167 {
168  mfib_entry_cover_updated(covered);
169 
170  /* continue */
171  return (1);
172 }
173 
174 void
176 {
177  mfib_entry_cover_walk(mfib_entry,
179  NULL);
180 }
static int mfib_entry_cover_update_one(mfib_entry_t *cover, fib_node_index_t covered, void *args)
void mfib_entry_delegate_remove(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
#define NULL
Definition: clib.h:58
An entry in a FIB table.
Definition: mfib_entry.h:32
static fib_node_index_t mfib_entry_get_index(const mfib_entry_t *mfe)
Definition: mfib_entry.h:205
void fib_node_list_walk(fib_node_list_t list, fib_node_list_walk_cb_t fn, void *args)
Walk the list of node.
void mfib_entry_cover_changed(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1437
static int mfib_entry_cover_change_one(mfib_entry_t *cover, fib_node_index_t covered, void *args)
fib_node_index_t fnp_index
node&#39;s index
Definition: fib_node.h:193
void fib_node_list_remove(fib_node_list_t list, u32 sibling)
int(* mfib_entry_covered_walk_t)(mfib_entry_t *cover, fib_node_index_t covered, void *ctx)
callback function used when walking the covered entries
u32 mfib_entry_cover_track(mfib_entry_t *cover, fib_node_index_t covered)
unsigned int u32
Definition: types.h:88
A representation of one pointer to another node.
Definition: fib_node.h:185
void mfib_entry_cover_walk(mfib_entry_t *cover, mfib_entry_covered_walk_t walk, void *args)
struct mfib_enty_cover_walk_ctx_t_ mfib_enty_cover_walk_ctx_t
Internal struct to hold user supplied paraneters for the cover walk.
int mfib_prefix_is_cover(const mfib_prefix_t *p1, const mfib_prefix_t *p2)
Compare two prefixes for covering relationship.
Definition: mfib_types.c:30
void mfib_entry_cover_change_notify(fib_node_index_t cover_index, fib_node_index_t covered)
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.
mfib_entry_covered_walk_t walk
Internal struct to hold user supplied paraneters for the cover walk.
fib_node_list_t mfd_list
For the cover tracking.
static mfib_entry_t * mfib_entry_get(fib_node_index_t index)
Definition: mfib_entry.h:200
static int mfib_entry_cover_walk_node_ptr(fib_node_ptr_t *depend, void *args)
#define MFIB_ENTRY_DBG(_e, _fmt, _args...)
Definition: mfib_entry.h:100
void mfib_entry_cover_untrack(mfib_entry_t *cover, u32 tracked_index)
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
mfib_entry_delegate_t * mfib_entry_delegate_get(const mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
Aggregrate type for a prefix.
Definition: mfib_types.h:24
mfib_entry_delegate_t * mfib_entry_delegate_find_or_add(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t fdt)
#define uword_to_pointer(u, type)
Definition: types.h:136
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.
void mfib_entry_cover_updated(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1462
void fib_node_list_destroy(fib_node_list_t *list)
static uword pointer_to_uword(const void *p)
Definition: types.h:131
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
Dependency list of covered entries.
const mfib_prefix_t * mfib_entry_get_prefix(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1357
void mfib_entry_cover_update_notify(mfib_entry_t *mfib_entry)