2 *------------------------------------------------------------------
3 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #include <vnet/qos/qos_egress_map.h>
19 #include <vnet/qos/qos_mark.h>
22 * Pool from which to allocate table
24 qos_egress_map_t *qem_pool;
27 * DB to map user table-IDs to internal table indicies.
32 qos_egress_map_find (qos_egress_map_id_t mid)
36 p = hash_get (qem_db, mid);
41 return (INDEX_INVALID);
45 qos_egress_map_find_i (qos_egress_map_id_t mid)
49 qemi = qos_egress_map_find (mid);
51 if (INDEX_INVALID != qemi)
53 return (pool_elt_at_index (qem_pool, qemi));
59 static qos_egress_map_t *
60 qos_egress_map_find_or_create (qos_egress_map_id_t mid)
62 qos_egress_map_t *qem;
65 * Find the existing or create a new table
67 qem = qos_egress_map_find_i (mid);
73 pool_get_aligned (qem_pool, qem, CLIB_CACHE_LINE_BYTES);
74 qemi = qem - qem_pool;
76 clib_memset (qem, 0, sizeof (*qem));
77 hash_set (qem_db, mid, qemi);
84 qos_egress_map_update (qos_egress_map_id_t mid,
85 qos_source_t input_source, qos_bits_t * values)
87 qos_egress_map_t *qem;
89 qem = qos_egress_map_find_or_create (mid);
91 clib_memcpy (qem->qem_output[input_source],
92 values, sizeof (qem->qem_output[input_source]));
96 qos_egress_map_delete (qos_egress_map_id_t mid)
98 qos_egress_map_t *qem;
100 qem = qos_egress_map_find_i (mid);
101 hash_unset (qem_db, mid);
105 pool_put (qem_pool, qem);
109 static clib_error_t *
110 qos_egress_map_update_cli (vlib_main_t * vm,
111 unformat_input_t * input, vlib_cli_command_t * cmd)
113 qos_egress_map_id_t map_id;
114 qos_egress_map_t *qem;
121 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
123 if (unformat (input, "delete") || unformat (input, "del"))
125 else if (unformat (input, "id %d", &map_id))
126 qem = qos_egress_map_find_or_create (map_id);
132 return clib_error_return (0, "map-id must be specified");
135 (input, "[%U][%d]=%d", unformat_qos_source, &qs, &qi, &qo))
136 qem->qem_output[qs][qi] = qo;
142 qos_egress_map_delete (map_id);
148 * Update a Egress Qos Map table
151 * @cliexcmd{qos egress map id 0 [ip][4]=4}
154 VLIB_CLI_COMMAND (qos_egress_map_update_command, static) = {
155 .path = "qos egress map",
156 .short_help = "qos egress map id %d [delete] {[SOURCE][INPUT]=OUTPUT}",
157 .function = qos_egress_map_update_cli,
163 format_qos_egress_map (u8 * s, va_list * args)
165 qos_egress_map_t *qem = va_arg (*args, qos_egress_map_t *);
166 u32 indent = va_arg (*args, u32);
170 FOR_EACH_QOS_SOURCE (qs)
172 s = format (s, "%U%U:[",
173 format_white_space, indent, format_qos_source, qs);
175 for (ii = 0; ii < ARRAY_LEN (qem->qem_output[qs]) - 1; ii++)
177 s = format (s, "%d,", qem->qem_output[qs][ii]);
179 s = format (s, "%d]\n", qem->qem_output[qs][ii]);
185 static clib_error_t *
186 qos_egress_map_show (vlib_main_t * vm,
187 unformat_input_t * input, vlib_cli_command_t * cmd)
189 qos_egress_map_id_t map_id;
190 qos_egress_map_t *qem;
197 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
199 if (unformat (input, "id %d", &map_id))
203 error = unformat_parse_error (input);
213 hash_foreach(map_id, qemi, qem_db,
215 vlib_cli_output (vm, " Map-ID:%d\n%U",
217 format_qos_egress_map,
218 pool_elt_at_index(qem_pool, qemi), 2);
224 qem = qos_egress_map_find_i (map_id);
228 error = clib_error_return (0, "No Map for ID %d", map_id);
232 vlib_cli_output (vm, " Map-ID:%d\n%U",
233 map_id, format_qos_egress_map, qem, 2);
242 * Show Egress Qos Maps
245 * @cliexcmd{show qos egress map}
248 VLIB_CLI_COMMAND (qos_egress_map_show_command, static) = {
249 .path = "show qos egress map",
250 .short_help = "show qos egress map id %d",
251 .function = qos_egress_map_show,
257 * fd.io coding-style-patch-verification: ON
260 * eval: (c-set-style "gnu")