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_get_id (index_t qemi)
47 qos_egress_map_id_t qid;
51 hash_foreach(qid, qmi, qem_db,
62 qos_egress_map_find_i (qos_egress_map_id_t mid)
66 qemi = qos_egress_map_find (mid);
68 if (INDEX_INVALID != qemi)
70 return (pool_elt_at_index (qem_pool, qemi));
76 static qos_egress_map_t *
77 qos_egress_map_find_or_create (qos_egress_map_id_t mid)
79 qos_egress_map_t *qem;
82 * Find the existing or create a new table
84 qem = qos_egress_map_find_i (mid);
90 pool_get_aligned (qem_pool, qem, CLIB_CACHE_LINE_BYTES);
91 qemi = qem - qem_pool;
93 clib_memset (qem, 0, sizeof (*qem));
94 hash_set (qem_db, mid, qemi);
101 qos_egress_map_update (qos_egress_map_id_t mid,
102 qos_source_t input_source, qos_bits_t * values)
104 qos_egress_map_t *qem;
106 qem = qos_egress_map_find_or_create (mid);
108 clib_memcpy (qem->qem_output[input_source],
109 values, sizeof (qem->qem_output[input_source]));
113 qos_egress_map_delete (qos_egress_map_id_t mid)
115 qos_egress_map_t *qem;
117 qem = qos_egress_map_find_i (mid);
118 hash_unset (qem_db, mid);
122 pool_put (qem_pool, qem);
127 qos_egress_map_walk (qos_egress_map_walk_cb_t fn, void *c)
129 qos_egress_map_id_t qid;
133 hash_foreach(qid, qmi, qem_db,
135 fn(qid, pool_elt_at_index(qem_pool, qmi), c);
140 static clib_error_t *
141 qos_egress_map_update_cli (vlib_main_t * vm,
142 unformat_input_t * input, vlib_cli_command_t * cmd)
144 qos_egress_map_id_t map_id;
145 qos_egress_map_t *qem;
152 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
154 if (unformat (input, "delete") || unformat (input, "del"))
156 else if (unformat (input, "id %d", &map_id))
157 qem = qos_egress_map_find_or_create (map_id);
163 return clib_error_return (0, "map-id must be specified");
166 (input, "[%U][%d]=%d", unformat_qos_source, &qs, &qi, &qo))
167 qem->qem_output[qs][qi] = qo;
173 qos_egress_map_delete (map_id);
179 * Update a Egress Qos Map table
182 * @cliexcmd{qos egress map id 0 [ip][4]=4}
185 VLIB_CLI_COMMAND (qos_egress_map_update_command, static) = {
186 .path = "qos egress map",
187 .short_help = "qos egress map id %d [delete] {[SOURCE][INPUT]=OUTPUT}",
188 .function = qos_egress_map_update_cli,
193 u8 *format_qos_egress_map (u8 * s, va_list * args)
195 qos_egress_map_t *qem = va_arg (*args, qos_egress_map_t *);
196 u32 indent = va_arg (*args, u32);
200 FOR_EACH_QOS_SOURCE (qs)
202 s = format (s, "%U%U:[",
203 format_white_space, indent, format_qos_source, qs);
205 for (ii = 0; ii < ARRAY_LEN (qem->qem_output[qs]) - 1; ii++)
207 s = format (s, "%d,", qem->qem_output[qs][ii]);
209 s = format (s, "%d]\n", qem->qem_output[qs][ii]);
215 static clib_error_t *qos_egress_map_show (vlib_main_t * vm,
216 unformat_input_t * input,
217 vlib_cli_command_t * cmd)
219 qos_egress_map_id_t map_id;
220 qos_egress_map_t *qem;
227 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
229 if (unformat (input, "id %d", &map_id))
233 error = unformat_parse_error (input);
243 hash_foreach(map_id, qemi, qem_db,
245 vlib_cli_output (vm, " Map-ID:%d\n%U",
247 format_qos_egress_map,
248 pool_elt_at_index(qem_pool, qemi), 2);
254 qem = qos_egress_map_find_i (map_id);
258 error = clib_error_return (0, "No Map for ID %d", map_id);
262 vlib_cli_output (vm, " Map-ID:%d\n%U",
263 map_id, format_qos_egress_map, qem, 2);
272 * Show Egress Qos Maps
275 * @cliexcmd{show qos egress map}
278 VLIB_CLI_COMMAND (qos_egress_map_show_command, static) = {
279 .path = "show qos egress map",
280 .short_help = "show qos egress map id %d",
281 .function = qos_egress_map_show,
287 * fd.io coding-style-patch-verification: ON
290 * eval: (c-set-style "gnu")