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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/qos/qos_store.h>
17 #include <vnet/ip/ip.h>
18 #include <vnet/feature/feature.h>
21 * QoS Store configuration
23 typedef struct qos_store_t_
30 * Per-interface, per-protocol vector of feature on/off configurations
32 qos_store_t *qos_store_configs[QOS_N_SOURCES];
35 qos_store_feature_config (u32 sw_if_index,
36 qos_source_t input_source,
37 u8 enable, qos_bits_t value)
42 vnet_feature_enable_disable ("ip6-unicast", "ip6-qos-store",
43 sw_if_index, enable, &value,
45 vnet_feature_enable_disable ("ip6-multicast", "ip6-qos-store",
46 sw_if_index, enable, &value,
48 vnet_feature_enable_disable ("ip4-unicast", "ip4-qos-store",
49 sw_if_index, enable, &value,
51 vnet_feature_enable_disable ("ip4-multicast", "ip4-qos-store",
52 sw_if_index, enable, &value,
58 /* not a valid option for storeing */
64 qos_store_enable (u32 sw_if_index,
65 qos_source_t input_source, qos_bits_t value)
69 if (QOS_SOURCE_IP != input_source)
70 return VNET_API_ERROR_UNIMPLEMENTED;
72 vec_validate (qos_store_configs[input_source], sw_if_index);
74 qst = &qos_store_configs[input_source][sw_if_index];
76 if (0 == qst->qst_n_cfgs)
78 qst->qst_value = value;
79 qos_store_feature_config (sw_if_index, input_source, 1, value);
88 qos_store_disable (u32 sw_if_index, qos_source_t input_source)
92 if (vec_len (qos_store_configs[input_source]) <= sw_if_index)
93 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
95 qst = &qos_store_configs[input_source][sw_if_index];
97 if (0 == qst->qst_n_cfgs)
98 return VNET_API_ERROR_VALUE_EXIST;
102 if (0 == qst->qst_n_cfgs)
104 qos_store_feature_config (sw_if_index, input_source, 0, qst->qst_value);
111 qos_store_walk (qos_store_walk_cb_t fn, void *c)
115 FOR_EACH_QOS_SOURCE (qs)
120 vec_foreach_index (sw_if_index, qos_store_configs[qs])
122 qst = &qos_store_configs[qs][sw_if_index];
123 if (0 != qst->qst_n_cfgs)
124 fn (sw_if_index, qs, qst->qst_value, c);
130 * Disable storeing feature for all protocols when the interface
133 static clib_error_t *
134 qos_store_ip_interface_add_del (vnet_main_t * vnm,
135 u32 sw_if_index, u32 is_add)
141 FOR_EACH_QOS_SOURCE (qs)
143 while (qos_store_disable (sw_if_index, qs) == 0);
150 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (qos_store_ip_interface_add_del);
153 qos_store_init (vlib_main_t * vm)
158 VLIB_INIT_FUNCTION (qos_store_init);
160 static clib_error_t *
161 qos_store_cli (vlib_main_t * vm,
162 unformat_input_t * input, vlib_cli_command_t * cmd)
164 vnet_main_t *vnm = vnet_get_main ();
165 u32 sw_if_index, qs, value;
173 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
175 if (unformat (input, "%U", unformat_vnet_sw_interface,
178 else if (unformat (input, "%U", unformat_qos_source, &qs))
180 else if (unformat (input, "enable"))
182 else if (unformat (input, "disable"))
184 else if (unformat (input, "value &d", &value))
190 if (~0 == sw_if_index)
191 return clib_error_return (0, "interface must be specified");
193 return clib_error_return (0, "value to be stored must be specified");
195 return clib_error_return (0, "input location must be specified");
198 qos_store_enable (sw_if_index, qs, value);
200 qos_store_disable (sw_if_index, qs);
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
212 * @cliexcmd{qos store ip GigEthernet0/1/0}
215 VLIB_CLI_COMMAND (qos_store_command, static) = {
217 .short_help = "qos store <store-source> <INTERFACE> [disable]",
218 .function = qos_store_cli,
224 qos_store_show_one_interface (vlib_main_t * vm, u32 sw_if_index)
226 u8 n_cfgs[QOS_N_SOURCES] = { };
232 FOR_EACH_QOS_SOURCE (qs)
234 if (vec_len (qos_store_configs[qs]) <= sw_if_index)
236 if (0 != (n_cfgs[qs] = qos_store_configs[qs][sw_if_index].qst_n_cfgs))
242 vlib_cli_output (vm, " %U:", format_vnet_sw_if_index_name,
243 vnet_get_main (), sw_if_index);
245 FOR_EACH_QOS_SOURCE (qs)
248 vlib_cli_output (vm, " %U -> %d",
249 format_qos_source, qs,
250 qos_store_configs[qs][sw_if_index].qst_value);
255 static clib_error_t *
256 qos_store_show (vlib_main_t * vm,
257 unformat_input_t * input, vlib_cli_command_t * cmd)
259 vnet_main_t *vnm = vnet_get_main ();
265 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
267 if (unformat (input, "%U", unformat_vnet_sw_interface,
272 if (~0 == sw_if_index)
276 FOR_EACH_QOS_SOURCE (qs)
278 n_ints = clib_max (n_ints, vec_len (qos_store_configs[qs]));
281 for (ii = 0; ii < n_ints; ii++)
283 qos_store_show_one_interface (vm, ii);
287 qos_store_show_one_interface (vm, sw_if_index);
293 * Show Egress Qos Maps
296 * @cliexcmd{show qos egress map}
299 VLIB_CLI_COMMAND (qos_store_show_command, static) = {
300 .path = "show qos store",
301 .short_help = "show qos store [interface]",
302 .function = qos_store_show,
308 * fd.io coding-style-patch-verification: ON
311 * eval: (c-set-style "gnu")