FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
mfib_itf.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 
16 #include <vnet/vnet.h>
17 
18 #include <vnet/mfib/mfib_itf.h>
19 #include <vnet/mfib/mfib_signal.h>
20 #include <vnet/fib/fib_path.h>
21 
23 
24 index_t
26  mfib_itf_flags_t mfi_flags)
27 {
28  mfib_itf_t *mfib_itf;
29 
30  pool_get_aligned(mfib_itf_pool, mfib_itf,
32 
33  mfib_itf->mfi_sw_if_index = fib_path_get_resolving_interface(path_index);
34  mfib_itf->mfi_si = INDEX_INVALID;
35 
36  /*
37  * add the path index to the per-path hash
38  */
39  mfib_itf->mfi_hash = hash_set(mfib_itf->mfi_hash, path_index, mfi_flags);
40 
41  /*
42  * the combined flags from all the paths is from just the one contributor
43  */
44  mfib_itf->mfi_flags = mfi_flags;
45 
46  return (mfib_itf - mfib_itf_pool);
47 }
48 
49 static mfib_itf_flags_t
50 mfib_itf_mk_flags (const mfib_itf_t *mfib_itf)
51 {
52  mfib_itf_flags_t combined_flags, flags;
53  fib_node_index_t *path_index;
54 
55  combined_flags = MFIB_ITF_FLAG_NONE;
56 
57  hash_foreach(path_index, flags, mfib_itf->mfi_hash,
58  {
59  combined_flags |= flags;
60  });
61 
62  return (combined_flags);
63 }
64 
65 int
67  fib_node_index_t path_index,
68  mfib_itf_flags_t mfi_flags)
69 {
70  /*
71  * add or remove the path index to the per-path hash
72  */
73  if (MFIB_ITF_FLAG_NONE == mfi_flags)
74  {
75  hash_unset(mfib_itf->mfi_hash, path_index);
76  }
77  else
78  {
79  mfib_itf->mfi_hash = hash_set(mfib_itf->mfi_hash,
80  path_index,
81  mfi_flags);
82  }
83 
84  /*
85  * re-generate the combined flags from all the paths.
86  */
87  mfib_itf->mfi_flags = mfib_itf_mk_flags(mfib_itf);
88 
89  /*
90  * The interface can be removed if there are no more flags
91  */
92  return (MFIB_ITF_FLAG_NONE == mfib_itf->mfi_flags);
93 }
94 
95 static void
97 {
98  fib_node_index_t path_index, *path_indexp, *all = NULL;
100 
101  hash_foreach(path_index, flags, mfi->mfi_hash,
102  {
103  vec_add1(all, path_index);
104  });
105 
106  vec_foreach(path_indexp, all)
107  {
108  hash_unset(mfi->mfi_hash, *path_indexp);
109  };
110 }
111 
112 void
114 {
115  mfib_itf_hash_flush(mfi);
117  pool_put(mfib_itf_pool, mfi);
118 }
119 
120 u8 *
121 format_mfib_itf (u8 * s, va_list * args)
122 {
123  mfib_itf_t *mfib_itf;
124  vnet_main_t *vnm;
125  index_t mfi;
126 
127  mfi = va_arg (*args, index_t);
128 
129  vnm = vnet_get_main();
130  mfib_itf = mfib_itf_get(mfi);
131 
132  if (~0 != mfib_itf->mfi_sw_if_index)
133  {
134  return (format(s, " %U: %U",
136  vnm,
138  mfib_itf->mfi_sw_if_index),
139  format_mfib_itf_flags, mfib_itf->mfi_flags));
140  }
141  else
142  {
143  return (format(s, " local: %U",
144  format_mfib_itf_flags, mfib_itf->mfi_flags));
145  }
146  return (s);
147 }
148 
149 static clib_error_t *
151  unformat_input_t * input,
152  vlib_cli_command_t * cmd)
153 {
154  index_t mfii;
155 
156  if (unformat (input, "%d", &mfii))
157  {
158  /*
159  * show one in detail
160  */
161  if (!pool_is_free_index(mfib_itf_pool, mfii))
162  {
163  vlib_cli_output (vm, "%d@%U",
164  mfii,
165  format_mfib_itf, mfii);
166  }
167  else
168  {
169  vlib_cli_output (vm, "itf %d invalid", mfii);
170  }
171  }
172  else
173  {
174  /*
175  * show all
176  */
177  vlib_cli_output (vm, "mFIB interfaces::");
178  pool_foreach_index(mfii, mfib_itf_pool,
179  ({
180  vlib_cli_output (vm, "%d@%U",
181  mfii,
182  format_mfib_itf, mfii);
183  }));
184  }
185 
186  return (NULL);
187 }
188 
189 /*?
190  * This commnad displays an MFIB interface, or all interfaces, indexed by their unique
191  * numerical indentifier.
192  ?*/
193 VLIB_CLI_COMMAND (show_mfib_itf, static) = {
194  .path = "show mfib interface",
195  .function = show_mfib_itf_command,
196  .short_help = "show mfib interface",
197 };
int mfib_itf_update(mfib_itf_t *mfib_itf, fib_node_index_t path_index, mfib_itf_flags_t mfi_flags)
update an interface from a path.
Definition: mfib_itf.c:66
#define hash_set(h, key, value)
Definition: hash.h:255
#define hash_unset(h, key)
Definition: hash.h:261
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define NULL
Definition: clib.h:58
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
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static clib_error_t * show_mfib_itf_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: mfib_itf.c:150
unsigned char u8
Definition: types.h:56
static mfib_itf_flags_t mfib_itf_mk_flags(const mfib_itf_t *mfib_itf)
Definition: mfib_itf.c:50
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
mfib_itf_t * mfib_itf_pool
Definition: mfib_itf.c:22
uword * mfi_hash
A hash table of path-inidices that are contributing flags to this interface.
Definition: mfib_itf.h:53
static void mfib_itf_hash_flush(mfib_itf_t *mfi)
Definition: mfib_itf.c:96
format_function_t format_vnet_sw_interface_name
static mfib_itf_t * mfib_itf_get(index_t mi)
Get the MFIB interface representation.
Definition: mfib_itf.h:78
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:287
vlib_main_t * vm
Definition: in2out_ed.c:1810
u32 mfi_si
The index of the signal in the pending list.
Definition: mfib_itf.h:45
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:231
u32 flags
Definition: vhost_user.h:141
void mfib_signal_remove_itf(const mfib_itf_t *mfi)
Definition: mfib_signal.c:184
mfib_itf_flags_t mfi_flags
Forwarding Flags on the entry - checked in the data-path.
Definition: mfib_itf.h:35
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:284
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
u8 * format_mfib_itf(u8 *s, va_list *args)
Definition: mfib_itf.c:121
An interface associated with a particular MFIB entry.
Definition: mfib_itf.h:25
index_t mfib_itf_create(fib_node_index_t path_index, mfib_itf_flags_t mfi_flags)
Definition: mfib_itf.c:25
u32 fib_path_get_resolving_interface(fib_node_index_t path_index)
Definition: fib_path.c:2161
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
u8 * format_mfib_itf_flags(u8 *s, va_list *args)
Definition: mfib_types.c:181
enum mfib_itf_flags_t_ mfib_itf_flags_t
u32 mfi_sw_if_index
The SW IF index that this MFIB interface represents.
Definition: mfib_itf.h:40
#define vec_foreach(var, vec)
Vector iterator.
void mfib_itf_delete(mfib_itf_t *mfi)
Definition: mfib_itf.c:113
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:543
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978