FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
qos_store.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 <vnet/qos/qos_store.h>
17 #include <vnet/ip/ip.h>
18 #include <vnet/feature/feature.h>
19 
20 /**
21  * QoS Store configuration
22  */
23 typedef struct qos_store_t_
24 {
27 } qos_store_t;
28 
29 /**
30  * Per-interface, per-protocol vector of feature on/off configurations
31  */
33 
34 static void
37  u8 enable, qos_bits_t value)
38 {
39  switch (input_source)
40  {
41  case QOS_SOURCE_IP:
42  vnet_feature_enable_disable ("ip6-unicast", "ip6-qos-store",
43  sw_if_index, enable, &value,
44  sizeof (value));
45  vnet_feature_enable_disable ("ip6-multicast", "ip6-qos-store",
46  sw_if_index, enable, &value,
47  sizeof (value));
48  vnet_feature_enable_disable ("ip4-unicast", "ip4-qos-store",
49  sw_if_index, enable, &value,
50  sizeof (value));
51  vnet_feature_enable_disable ("ip4-multicast", "ip4-qos-store",
52  sw_if_index, enable, &value,
53  sizeof (value));
54  break;
55  case QOS_SOURCE_MPLS:
56  case QOS_SOURCE_VLAN:
57  case QOS_SOURCE_EXT:
58  /* not a valid option for storeing */
59  break;
60  }
61 }
62 
63 int
66 {
68 
70  return VNET_API_ERROR_UNIMPLEMENTED;
71 
73 
75 
76  if (0 == qst->qst_n_cfgs)
77  {
78  qst->qst_value = value;
80  }
81 
82  qst->qst_n_cfgs++;
83 
84  return (0);
85 }
86 
87 int
89 {
91 
93  return VNET_API_ERROR_NO_MATCHING_INTERFACE;
94 
96 
97  if (0 == qst->qst_n_cfgs)
98  return VNET_API_ERROR_VALUE_EXIST;
99 
100  qst->qst_n_cfgs--;
101 
102  if (0 == qst->qst_n_cfgs)
103  {
105  }
106 
107  return (0);
108 }
109 
110 void
112 {
113  qos_source_t qs;
114 
116  {
117  qos_store_t *qst;
119 
121  {
123  if (0 != qst->qst_n_cfgs)
124  fn (sw_if_index, qs, qst->qst_value, c);
125  }
126  }
127 }
128 
129 /*
130  * Disable storeing feature for all protocols when the interface
131  * is deleted
132  */
133 static clib_error_t *
135  u32 sw_if_index, u32 is_add)
136 {
137  if (!is_add)
138  {
139  qos_source_t qs;
140 
142  {
143  while (qos_store_disable (sw_if_index, qs) == 0);
144  }
145  }
146 
147  return (NULL);
148 }
149 
151 
152 clib_error_t *
154 {
155  return 0;
156 }
157 
159 
160 static clib_error_t *
162  unformat_input_t * input, vlib_cli_command_t * cmd)
163 {
164  vnet_main_t *vnm = vnet_get_main ();
165  u32 sw_if_index, qs, value;
166  u8 enable;
167 
168  qs = 0xff;
169  enable = 1;
170  sw_if_index = ~0;
171  value = ~0;
172 
174  {
175  if (unformat (input, "%U", unformat_vnet_sw_interface,
176  vnm, &sw_if_index))
177  ;
178  else if (unformat (input, "%U", unformat_qos_source, &qs))
179  ;
180  else if (unformat (input, "enable"))
181  enable = 1;
182  else if (unformat (input, "disable"))
183  enable = 0;
184  else if (unformat (input, "value &d", &value))
185  ;
186  else
187  break;
188  }
189 
190  if (~0 == sw_if_index)
191  return clib_error_return (0, "interface must be specified");
192  if (~0 == value)
193  return clib_error_return (0, "value to be stored must be specified");
194  if (0xff == qs)
195  return clib_error_return (0, "input location must be specified");
196 
197  if (enable)
199  else
201 
202  return (NULL);
203 }
204 
205 /*?
206  * Enable QoS bit storeing on an interface using the packet's input DSCP bits
207  * Which input QoS bits to use are either; IP, MPLS or VLAN. If more than
208  * one protocol is chosen (which is foolish) the higher layers override the
209  * lower.
210  *
211  * @cliexpar
212  * @cliexcmd{qos store ip GigEthernet0/1/0}
213  ?*/
214 /* *INDENT-OFF* */
216  .path = "qos store",
217  .short_help = "qos store <store-source> <INTERFACE> [disable]",
218  .function = qos_store_cli,
219  .is_mp_safe = 1,
220 };
221 /* *INDENT-ON* */
222 
223 static void
225 {
226  u8 n_cfgs[QOS_N_SOURCES] = { };
227  qos_source_t qs;
228  bool set;
229 
230  set = false;
231 
233  {
235  continue;
236  if (0 != (n_cfgs[qs] = qos_store_configs[qs][sw_if_index].qst_n_cfgs))
237  set = true;
238  }
239 
240  if (set)
241  {
244 
246  {
247  if (n_cfgs[qs] != 0)
248  vlib_cli_output (vm, " %U -> %d",
249  format_qos_source, qs,
250  qos_store_configs[qs][sw_if_index].qst_value);
251  }
252  }
253 }
254 
255 static clib_error_t *
257  unformat_input_t * input, vlib_cli_command_t * cmd)
258 {
259  vnet_main_t *vnm = vnet_get_main ();
260  qos_source_t qs;
262 
263  sw_if_index = ~0;
264 
266  {
267  if (unformat (input, "%U", unformat_vnet_sw_interface,
268  vnm, &sw_if_index))
269  ;
270  }
271 
272  if (~0 == sw_if_index)
273  {
274  u32 ii, n_ints = 0;
275 
277  {
278  n_ints = clib_max (n_ints, vec_len (qos_store_configs[qs]));
279  }
280 
281  for (ii = 0; ii < n_ints; ii++)
282  {
284  }
285  }
286  else
288 
289  return (NULL);
290 }
291 
292 /*?
293  * Show Egress Qos Maps
294  *
295  * @cliexpar
296  * @cliexcmd{show qos egress map}
297  ?*/
298 /* *INDENT-OFF* */
300  .path = "show qos store",
301  .short_help = "show qos store [interface]",
302  .function = qos_store_show,
303  .is_mp_safe = 1,
304 };
305 /* *INDENT-ON* */
306 
307 /*
308  * fd.io coding-style-patch-verification: ON
309  *
310  * Local Variables:
311  * eval: (c-set-style "gnu")
312  * End:
313  */
QOS_SOURCE_EXT
@ QOS_SOURCE_EXT
Some external source, e.g.
Definition: qos_types.h:35
qos_store_show_one_interface
static void qos_store_show_one_interface(vlib_main_t *vm, u32 sw_if_index)
Definition: qos_store.c:224
unformat_qos_source
uword unformat_qos_source(unformat_input_t *input, va_list *args)
Definition: qos_types.c:35
clib_max
#define clib_max(x, y)
Definition: clib.h:335
qos_store_show
static clib_error_t * qos_store_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: qos_store.c:256
qos_store_t_::qst_n_cfgs
u8 qst_n_cfgs
Definition: qos_store.c:25
QOS_SOURCE_MPLS
@ QOS_SOURCE_MPLS
Definition: qos_types.h:37
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
set
description can t DF set
Definition: map.api:451
qos_store_init
clib_error_t * qos_store_init(vlib_main_t *vm)
Definition: qos_store.c:153
qos_store_walk
void qos_store_walk(qos_store_walk_cb_t fn, void *c)
Definition: qos_store.c:111
qos_bits_t
u8 qos_bits_t
Type, er, safety for us water based entities.
Definition: qos_types.h:68
QOS_SOURCE_VLAN
@ QOS_SOURCE_VLAN
Definition: qos_types.h:36
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
format_qos_source
u8 * format_qos_source(u8 *s, va_list *args)
format/unformat QoS source types
Definition: qos_types.c:27
qos_store_feature_config
static void qos_store_feature_config(u32 sw_if_index, qos_source_t input_source, u8 enable, qos_bits_t value)
Definition: qos_store.c:35
feature.h
qos_store_t_
QoS Store configuration.
Definition: qos_store.c:23
qos_store_configs
qos_store_t * qos_store_configs[QOS_N_SOURCES]
Per-interface, per-protocol vector of feature on/off configurations.
Definition: qos_store.c:32
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
qos_store_show_command
static vlib_cli_command_t qos_store_show_command
(constructor) VLIB_CLI_COMMAND (qos_store_show_command)
Definition: qos_store.c:299
qos_store_command
static vlib_cli_command_t qos_store_command
(constructor) VLIB_CLI_COMMAND (qos_store_command)
Definition: qos_store.c:215
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
qst
static void qst(qst_t *q, char *base, char *max)
Definition: qsort.c:145
input_source
vl_api_qos_source_t input_source
Definition: qos.api:53
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
qos_source_t
enum qos_source_t_ qos_source_t
QoS types.
qos_store_t_::qst_value
qos_bits_t qst_value
Definition: qos_store.c:26
vnet_main_t
Definition: vnet.h:76
qos_store_t
struct qos_store_t_ qos_store_t
QoS Store configuration.
qos_store_cli
static clib_error_t * qos_store_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: qos_store.c:161
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:455
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
qos_store.h
ip.h
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
FOR_EACH_QOS_SOURCE
#define FOR_EACH_QOS_SOURCE(_src)
Definition: qos_types.h:54
value
u8 value
Definition: qos.api:54
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
qos_store_walk_cb_t
walk_rc_t(* qos_store_walk_cb_t)(u32 sw_if_index, qos_source_t input_source, qos_bits_t value, void *ctx)
Definition: qos_store.h:26
qos_store_ip_interface_add_del
static clib_error_t * qos_store_ip_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: qos_store.c:134
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
VNET_SW_INTERFACE_ADD_DEL_FUNCTION
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(qos_store_ip_interface_add_del)
QOS_N_SOURCES
#define QOS_N_SOURCES
The maximum number of sources.
Definition: qos_types.h:45
QOS_SOURCE_IP
@ QOS_SOURCE_IP
Definition: qos_types.h:38
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
qos_store_disable
int qos_store_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_store.c:88
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
qos_store_enable
int qos_store_enable(u32 sw_if_index, qos_source_t input_source, qos_bits_t value)
Definition: qos_store.c:64