FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
qos_record.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_record.h>
17 #include <vnet/ip/ip.h>
18 #include <vnet/ip/ip6_to_ip4.h>
19 #include <vnet/feature/feature.h>
20 #include <vnet/qos/qos_types.h>
21 #include <vnet/l2/l2_input.h>
22 #include <vnet/l2/feat_bitmap.h>
23 
24 /**
25  * Per-interface, per-protocol vector of feature on/off configurations
26  */
29 
30 static void
33 {
34  switch (input_source)
35  {
36  case QOS_SOURCE_IP:
37  ip_feature_enable_disable (AF_IP6, N_SAFI, IP_FEATURE_INPUT,
38  "ip6-qos-record",
39  sw_if_index, enable, NULL, 0);
40  ip_feature_enable_disable (AF_IP4, N_SAFI, IP_FEATURE_INPUT,
41  "ip4-qos-record",
42  sw_if_index, enable, NULL, 0);
43  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_L2_IP_QOS_RECORD,
44  enable);
45  break;
46  case QOS_SOURCE_MPLS:
47  vnet_feature_enable_disable ("mpls-input", "mpls-qos-record",
48  sw_if_index, enable, NULL, 0);
49  break;
50  case QOS_SOURCE_VLAN:
51  ip_feature_enable_disable (AF_IP6, N_SAFI, IP_FEATURE_INPUT,
52  "vlan-ip6-qos-record",
53  sw_if_index, enable, NULL, 0);
54  ip_feature_enable_disable (AF_IP4, N_SAFI, IP_FEATURE_INPUT,
55  "vlan-ip4-qos-record",
56  sw_if_index, enable, NULL, 0);
57  vnet_feature_enable_disable ("mpls-input", "vlan-mpls-qos-record",
58  sw_if_index, enable, NULL, 0);
59  break;
60  case QOS_SOURCE_EXT:
61  /* not a valid option for recording */
62  break;
63  }
64 }
65 
66 int
68 {
70 
72  {
74  }
75 
77  return (0);
78 }
79 
80 int
82 {
84  return VNET_API_ERROR_NO_MATCHING_INTERFACE;
85 
87  return VNET_API_ERROR_VALUE_EXIST;
88 
90 
92  {
94  }
95 
96  return (0);
97 }
98 
99 void
101 {
102  qos_source_t qs;
103 
105  {
107 
109  {
110  if (0 != qos_record_configs[qs][sw_if_index])
111  fn (sw_if_index, qs, c);
112  }
113  }
114 }
115 
116 /*
117  * Disable recording feature for all protocols when the interface
118  * is deleted
119  */
120 static clib_error_t *
122  u32 sw_if_index, u32 is_add)
123 {
124  if (!is_add)
125  {
126  qos_source_t qs;
127 
129  {
130  while (qos_record_disable (sw_if_index, qs) == 0);
131  }
132  }
133 
134  return (NULL);
135 }
136 
138 
139 clib_error_t *
141 {
142  qos_source_t qs;
143  vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "l2-ip-qos-record");
144 
145  /* Initialize the feature next-node indexes */
148  node->index,
151  l2_qos_input_next[qs]);
152  return 0;
153 }
154 
156 
157 static clib_error_t *
159  unformat_input_t * input, vlib_cli_command_t * cmd)
160 {
161  vnet_main_t *vnm = vnet_get_main ();
162  u32 sw_if_index, qs;
163  u8 enable;
164 
165  qs = 0xff;
166  enable = 1;
167  sw_if_index = ~0;
168 
170  {
171  if (unformat (input, "%U", unformat_vnet_sw_interface,
172  vnm, &sw_if_index))
173  ;
174  else if (unformat (input, "%U", unformat_qos_source, &qs))
175  ;
176  else if (unformat (input, "enable"))
177  enable = 1;
178  else if (unformat (input, "disable"))
179  enable = 0;
180  else
181  break;
182  }
183 
184  if (~0 == sw_if_index)
185  return clib_error_return (0, "interface must be specified");
186  if (0xff == qs)
187  return clib_error_return (0, "input location must be specified");
188 
189  if (enable)
191  else
193 
194  return (NULL);
195 }
196 
197 /*?
198  * Enable QoS bit recording on an interface using the packet's input DSCP bits
199  * Which input QoS bits to use are either; IP, MPLS or VLAN. If more than
200  * one protocol is chosen (which is foolish) the higher layers override the
201  * lower.
202  *
203  * @cliexpar
204  * @cliexcmd{qos record ip GigEthernet0/1/0}
205  ?*/
206 /* *INDENT-OFF* */
208  .path = "qos record",
209  .short_help = "qos record <record-source> <INTERFACE> [disable]",
210  .function = qos_record_cli,
211  .is_mp_safe = 1,
212 };
213 /* *INDENT-ON* */
214 
215 static void
217 {
218  u8 n_cfgs[QOS_N_SOURCES] = { };
219  qos_source_t qs;
220  bool set;
221 
222  set = false;
223 
225  {
227  continue;
228  if (0 != (n_cfgs[qs] = qos_record_configs[qs][sw_if_index]))
229  set = true;
230  }
231 
232  if (set)
233  {
236 
238  {
239  if (n_cfgs[qs] != 0)
240  vlib_cli_output (vm, " %U", format_qos_source, qs);
241  }
242  }
243 }
244 
245 static clib_error_t *
247  unformat_input_t * input, vlib_cli_command_t * cmd)
248 {
249  vnet_main_t *vnm = vnet_get_main ();
250  qos_source_t qs;
252 
253  sw_if_index = ~0;
254 
256  {
257  if (unformat (input, "%U", unformat_vnet_sw_interface,
258  vnm, &sw_if_index))
259  ;
260  }
261 
262  if (~0 == sw_if_index)
263  {
264  u32 ii, n_ints = 0;
265 
267  {
268  n_ints = clib_max (n_ints, vec_len (qos_record_configs[qs]));
269  }
270 
271  for (ii = 0; ii < n_ints; ii++)
272  {
274  }
275  }
276  else
278 
279  return (NULL);
280 }
281 
282 /*?
283  * Show Egress Qos Maps
284  *
285  * @cliexpar
286  * @cliexcmd{show qos egress map}
287  ?*/
288 /* *INDENT-OFF* */
290  .path = "show qos record",
291  .short_help = "show qos record [interface]",
292  .function = qos_record_show,
293  .is_mp_safe = 1,
294 };
295 /* *INDENT-ON* */
296 
297 /*
298  * fd.io coding-style-patch-verification: ON
299  *
300  * Local Variables:
301  * eval: (c-set-style "gnu")
302  * End:
303  */
ip_feature_enable_disable
void ip_feature_enable_disable(ip_address_family_t af, ip_sub_address_family_t safi, ip_feature_location_t loc, const char *feature_name, u32 sw_if_index, int enable, void *feature_config, u32 n_feature_config_bytes)
Definition: ip.c:163
qos_record_show_command
static vlib_cli_command_t qos_record_show_command
(constructor) VLIB_CLI_COMMAND (qos_record_show_command)
Definition: qos_record.c:289
QOS_SOURCE_EXT
@ QOS_SOURCE_EXT
Some external source, e.g.
Definition: qos_types.h:35
unformat_qos_source
uword unformat_qos_source(unformat_input_t *input, va_list *args)
Definition: qos_types.c:35
qos_record_init
clib_error_t * qos_record_init(vlib_main_t *vm)
Definition: qos_record.c:140
qos_record_show_one_interface
static void qos_record_show_one_interface(vlib_main_t *vm, u32 sw_if_index)
Definition: qos_record.c:216
clib_max
#define clib_max(x, y)
Definition: clib.h:335
qos_record_walk_cb_t
walk_rc_t(* qos_record_walk_cb_t)(u32 sw_if_index, qos_source_t input_source, void *ctx)
Definition: qos_record.h:24
QOS_SOURCE_MPLS
@ QOS_SOURCE_MPLS
Definition: qos_types.h:37
qos_record_enable
int qos_record_enable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:67
qos_types.h
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
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
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
qos_record_ip_interface_add_del
static clib_error_t * qos_record_ip_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: qos_record.c:121
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_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
feature.h
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
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
qos_record_cli
static clib_error_t * qos_record_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: qos_record.c:158
l2input_intf_bitmap_enable
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:177
l2input_get_feat_names
char ** l2input_get_feat_names(void)
Return an array of strings containing graph node names of each feature.
Definition: l2_input.c:59
qos_record_walk
void qos_record_walk(qos_record_walk_cb_t fn, void *c)
Definition: qos_record.c:100
qos_record_configs
u8 * qos_record_configs[QOS_N_SOURCES]
Per-interface, per-protocol vector of feature on/off configurations.
Definition: qos_record.c:27
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
ip6_to_ip4.h
IPv6 to IPv4 translation.
L2INPUT_N_FEAT
@ L2INPUT_N_FEAT
Definition: l2_input.h:165
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
l2_qos_input_next
u32 l2_qos_input_next[QOS_N_SOURCES][32]
Definition: qos_record.c:28
l2_input.h
qos_source_t
enum qos_source_t_ qos_source_t
QoS types.
qos_record_feature_config
static void qos_record_feature_config(u32 sw_if_index, qos_source_t input_source, u8 enable)
Definition: qos_record.c:31
vnet_main_t
Definition: vnet.h:76
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
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
AF_IP6
@ AF_IP6
Definition: ip_types.h:24
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
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
qos_record.h
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
feat_bitmap.h
N_SAFI
#define N_SAFI
Definition: ip_types.h:47
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
QOS_N_SOURCES
#define QOS_N_SOURCES
The maximum number of sources.
Definition: qos_types.h:45
VNET_SW_INTERFACE_ADD_DEL_FUNCTION
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(qos_record_ip_interface_add_del)
QOS_SOURCE_IP
@ QOS_SOURCE_IP
Definition: qos_types.h:38
qos_record_show
static clib_error_t * qos_record_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: qos_record.c:246
qos_record_disable
int qos_record_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:81
vlib_cli_command_t
Definition: cli.h:92
qos_record_command
static vlib_cli_command_t qos_record_command
(constructor) VLIB_CLI_COMMAND (qos_record_command)
Definition: qos_record.c:207
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
feat_bitmap_init_next_nodes
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
Definition: feat_bitmap.h:43
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137