FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
gbp_itf.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 <plugins/gbp/gbp_itf.h>
17 
18 /**
19  * Attributes and configurations attached to interfaces by GBP
20  */
21 typedef struct gbp_itf_t_
22 {
23  /**
24  * Number of references to this interface
25  */
27 
30 
31  /**
32  * L2/L3 Features configured by each user
33  */
38 } gbp_itf_t;
39 
41 
42 static gbp_itf_t *
44 {
45  vec_validate (gbp_itfs, gii);
46 
47  return (&gbp_itfs[gii]);
48 }
49 
50 static index_t
52 {
53  return (sw_if_index);
54 }
55 
56 index_t
58 {
59  gbp_itf_t *gi;
60 
61  gi = gbp_itf_get (gbp_itf_get_itf (sw_if_index));
62 
63  if (0 == gi->gi_locks)
64  {
66  gi->gi_bd_index = bd_index;
67 
68  if (~0 != gi->gi_bd_index)
70  MODE_L2_BRIDGE, sw_if_index, bd_index,
72 
73  }
74 
75  gi->gi_locks++;
76 
77  return (sw_if_index);
78 }
79 
80 void
82 {
83  gbp_itf_t *gi;
84 
85  gi = gbp_itf_get (gii);
86  ASSERT (gi->gi_locks > 0);
87  gi->gi_locks--;
88 
89  if (0 == gi->gi_locks)
90  {
91  if (~0 != gi->gi_bd_index)
96 
97  memset (gi, 0, sizeof (*gi));
98  }
99 }
100 
101 void
103  index_t useri, l2input_feat_masks_t feats)
104 {
105  u32 diff_fb, new_fb, *fb, feat;
106  gbp_itf_t *gi;
107 
108  gi = gbp_itf_get (gii);
109 
110  if (gi->gi_bd_index == ~0)
111  return;
112 
113  vec_validate (gi->gi_l2_input_fbs, useri);
114  gi->gi_l2_input_fbs[useri] = feats;
115 
116  new_fb = 0;
117  vec_foreach (fb, gi->gi_l2_input_fbs)
118  {
119  new_fb |= *fb;
120  }
121 
122  /* add new features */
123  diff_fb = (gi->gi_l2_input_fb ^ new_fb) & new_fb;
124 
125  /* *INDENT-OFF* */
126  foreach_set_bit (feat, diff_fb,
127  ({
128  l2input_intf_bitmap_enable (gi->gi_sw_if_index, (1 << feat), 1);
129  }));
130  /* *INDENT-ON* */
131 
132  /* remove unneeded features */
133  diff_fb = (gi->gi_l2_input_fb ^ new_fb) & gi->gi_l2_input_fb;
134 
135  /* *INDENT-OFF* */
136  foreach_set_bit (feat, diff_fb,
137  ({
138  l2input_intf_bitmap_enable (gi->gi_sw_if_index, (1 << feat), 0);
139  }));
140  /* *INDENT-ON* */
141 
142  gi->gi_l2_input_fb = new_fb;
143 }
144 
145 void
147  index_t useri, l2output_feat_masks_t feats)
148 {
149  u32 diff_fb, new_fb, *fb, feat;
150  gbp_itf_t *gi;
151 
152  gi = gbp_itf_get (gii);
153 
154  if (gi->gi_bd_index == ~0)
155  return;
156 
157  vec_validate (gi->gi_l2_output_fbs, useri);
158  gi->gi_l2_output_fbs[useri] = feats;
159 
160  new_fb = 0;
161  vec_foreach (fb, gi->gi_l2_output_fbs)
162  {
163  new_fb |= *fb;
164  }
165 
166  /* add new features */
167  diff_fb = (gi->gi_l2_output_fb ^ new_fb) & new_fb;
168 
169  /* *INDENT-OFF* */
170  foreach_set_bit (feat, diff_fb,
171  ({
172  l2output_intf_bitmap_enable (gi->gi_sw_if_index, (1 << feat), 1);
173  }));
174  /* *INDENT-ON* */
175 
176  /* remove unneeded features */
177  diff_fb = (gi->gi_l2_output_fb ^ new_fb) & gi->gi_l2_output_fb;
178 
179  /* *INDENT-OFF* */
180  foreach_set_bit (feat, diff_fb,
181  ({
182  l2output_intf_bitmap_enable (gi->gi_sw_if_index, (1 << feat), 0);
183  }));
184  /* *INDENT-ON* */
185 
186  gi->gi_l2_output_fb = new_fb;
187 }
188 
189 u8 *
190 format_gbp_itf (u8 * s, va_list * args)
191 {
192  index_t gii = va_arg (*args, index_t);
193  gbp_itf_t *gi;
194 
195  gi = gbp_itf_get (gii);
196 
197  s = format (s, "%U locks:%d bd-index:%d input-feats:%U output-feats:%U",
199  gi->gi_sw_if_index, gi->gi_locks,
200  gi->gi_bd_index,
203 
204  return (s);
205 }
206 
207 static clib_error_t *
209  unformat_input_t * input, vlib_cli_command_t * cmd)
210 {
211  u32 gii;
212 
213  vlib_cli_output (vm, "Interfaces:");
214 
215  vec_foreach_index (gii, gbp_itfs)
216  {
217  vlib_cli_output (vm, " [%d] %U", gii, format_gbp_itf, gii);
218  }
219 
220  return (NULL);
221 }
222 
223 /*?
224  * Show Group Based Interfaces
225  *
226  * @cliexpar
227  * @cliexstart{show gbp contract}
228  * @cliexend
229  ?*/
230 /* *INDENT-OFF* */
231 VLIB_CLI_COMMAND (gbp_contract_show_node, static) = {
232  .path = "show gbp interface",
233  .short_help = "show gbp interface\n",
234  .function = gbp_itf_show,
235 };
236 /* *INDENT-ON* */
237 
238 
239 /*
240  * fd.io coding-style-patch-verification: ON
241  *
242  * Local Variables:
243  * eval: (c-set-style "gnu")
244  * End:
245  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
u32 sw_if_index
Definition: ipsec_gre.api:37
u8 * format_l2_input_features(u8 *s, va_list *args)
Definition: l2_input.c:68
#define vec_foreach_index(var, v)
Iterate over vector indices.
void gbp_itf_set_l2_input_feature(index_t gii, index_t useri, l2input_feat_masks_t feats)
Definition: gbp_itf.c:102
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
u8 * format_l2_output_features(u8 *s, va_list *args)
Definition: l2_output.c:45
u32 * gi_l2_input_fbs
L2/L3 Features configured by each user.
Definition: gbp_itf.c:34
u32 gi_sw_if_index
Definition: gbp_itf.c:28
#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 gbp_itf_t * gbp_itfs
Definition: gbp_itf.c:40
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
void gbp_itf_unlock(index_t gii)
Definition: gbp_itf.c:81
#define foreach_set_bit(var, mask, body)
Definition: bitops.h:166
struct gbp_itf_t_ gbp_itf_t
Attributes and configurations attached to interfaces by GBP.
#define MODE_L2_BRIDGE
Definition: l2_input.h:211
u32 gi_bd_index
Definition: gbp_itf.c:29
u8 * format_gbp_itf(u8 *s, va_list *args)
Definition: gbp_itf.c:190
unsigned int u32
Definition: types.h:88
static index_t gbp_itf_get_itf(u32 sw_if_index)
Definition: gbp_itf.c:51
u32 gi_locks
Number of references to this interface.
Definition: gbp_itf.c:26
struct _unformat_input_t unformat_input_t
u32 gi_l2_output_fb
Definition: gbp_itf.c:37
static gbp_itf_t * gbp_itf_get(index_t gii)
Definition: gbp_itf.c:43
void gbp_itf_set_l2_output_feature(index_t gii, index_t useri, l2output_feat_masks_t feats)
Definition: gbp_itf.c:146
l2input_feat_masks_t
Definition: l2_input.h:138
void l2output_intf_bitmap_enable(u32 sw_if_index, l2output_feat_masks_t feature_bitmap, u32 enable)
Enable (or disable) the feature in the bitmap for the given interface.
Definition: l2_output.c:626
Attributes and configurations attached to interfaces by GBP.
Definition: gbp_itf.c:21
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
#define ASSERT(truth)
l2output_feat_masks_t
Definition: l2_output.h:110
static clib_error_t * gbp_itf_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gbp_itf.c:208
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, l2_bd_port_type_t port_type, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:589
u32 l2input_intf_bitmap_enable(u32 sw_if_index, l2input_feat_masks_t feature_bitmap, u32 enable)
Enable (or disable) the feature in the bitmap for the given interface.
Definition: l2_input.c:536
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u32 gi_l2_input_fb
Definition: gbp_itf.c:35
#define vec_foreach(var, vec)
Vector iterator.
index_t gbp_itf_add_and_lock(u32 sw_if_index, u32 bd_index)
Definition: gbp_itf.c:57
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
u32 * gi_l2_output_fbs
Definition: gbp_itf.c:36
#define MODE_L3
Definition: l2_input.h:210