FD.io VPP  v18.01.2-1-g9b554f3
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 
22 
23 index_t
24 mfib_itf_create (u32 sw_if_index,
25  mfib_itf_flags_t mfi_flags)
26 {
27  mfib_itf_t *mfib_itf;
28 
29  pool_get_aligned(mfib_itf_pool, mfib_itf,
31 
32  mfib_itf->mfi_sw_if_index = sw_if_index;
33  mfib_itf->mfi_flags = mfi_flags;
34  mfib_itf->mfi_si = INDEX_INVALID;
35 
36  return (mfib_itf - mfib_itf_pool);
37 }
38 
39 void
41 {
43  pool_put(mfib_itf_pool, mfi);
44 }
45 
46 u8 *
47 format_mfib_itf (u8 * s, va_list * args)
48 {
49  mfib_itf_t *mfib_itf;
50  vnet_main_t *vnm;
51  index_t mfi;
52 
53  mfi = va_arg (*args, index_t);
54 
55  vnm = vnet_get_main();
56  mfib_itf = mfib_itf_get(mfi);
57 
58  if (~0 != mfib_itf->mfi_sw_if_index)
59  {
60  return (format(s, " %U: %U",
62  vnm,
64  mfib_itf->mfi_sw_if_index),
65  format_mfib_itf_flags, mfib_itf->mfi_flags));
66  }
67  else
68  {
69  return (format(s, " local: %U",
70  format_mfib_itf_flags, mfib_itf->mfi_flags));
71  }
72  return (s);
73 }
74 
75 static clib_error_t *
77  unformat_input_t * input,
78  vlib_cli_command_t * cmd)
79 {
80  index_t mfii;
81 
82  if (unformat (input, "%d", &mfii))
83  {
84  /*
85  * show one in detail
86  */
87  if (!pool_is_free_index(mfib_itf_pool, mfii))
88  {
89  vlib_cli_output (vm, "%d@%U",
90  mfii,
91  format_mfib_itf, mfii);
92  }
93  else
94  {
95  vlib_cli_output (vm, "itf %d invalid", mfii);
96  }
97  }
98  else
99  {
100  /*
101  * show all
102  */
103  vlib_cli_output (vm, "mFIB interfaces::");
104  pool_foreach_index(mfii, mfib_itf_pool,
105  ({
106  vlib_cli_output (vm, "%d@%U",
107  mfii,
108  format_mfib_itf, mfii);
109  }));
110  }
111 
112  return (NULL);
113 }
114 
115 /*?
116  * This commnad displays an MFIB interface, or all interfaces, indexed by their unique
117  * numerical indentifier.
118  ?*/
119 VLIB_CLI_COMMAND (show_mfib_itf, static) = {
120  .path = "show mfib interface",
121  .function = show_mfib_itf_command,
122  .short_help = "show mfib interface",
123 };
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
#define NULL
Definition: clib.h:55
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:419
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:76
mfib_itf_t * mfib_itf_pool
Definition: mfib_itf.c:21
index_t mfib_itf_create(u32 sw_if_index, mfib_itf_flags_t mfi_flags)
Definition: mfib_itf.c:24
format_function_t format_vnet_sw_interface_name
static mfib_itf_t * mfib_itf_get(index_t mi)
Definition: mfib_itf.h:53
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
u32 mfi_si
The index of the signal in the pending list.
Definition: mfib_itf.h:40
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
vlib_main_t * vm
Definition: buffer.c:283
void mfib_signal_remove_itf(const mfib_itf_t *mfi)
Definition: mfib_signal.c:184
mfib_itf_flags_t mfi_flags
Falags on the entry.
Definition: mfib_itf.h:30
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:268
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
unsigned int u32
Definition: types.h:88
u8 * format_mfib_itf(u8 *s, va_list *args)
Definition: mfib_itf.c:47
An interface associated with a particular MFIB entry.
Definition: mfib_itf.h:25
unsigned char u8
Definition: types.h:56
#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:105
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:35
void mfib_itf_delete(mfib_itf_t *mfi)
Definition: mfib_itf.c:40
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:480
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972