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/vnet.h>
19 #include <vlibmemory/api.h>
20 #include <vnet/api_errno.h>
22 #include <vnet/qos/qos_record.h>
23 #include <vnet/qos/qos_store.h>
24 #include <vnet/qos/qos_mark.h>
25 #include <vnet/qos/qos_egress_map.h>
27 #include <vnet/vnet_msg_enum.h>
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
40 #include <vnet/vnet_all_api_h.h>
43 #include <vlibapi/api_helper_macros.h>
46 #define foreach_qos_api_msg \
47 _(QOS_RECORD_ENABLE_DISABLE, qos_record_enable_disable) \
48 _(QOS_RECORD_DUMP, qos_record_dump) \
49 _(QOS_STORE_ENABLE_DISABLE, qos_store_enable_disable) \
50 _(QOS_STORE_DUMP, qos_store_dump) \
51 _(QOS_EGRESS_MAP_DELETE, qos_egress_map_delete) \
52 _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update) \
53 _(QOS_EGRESS_MAP_DUMP, qos_egress_map_dump) \
54 _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable) \
55 _(QOS_MARK_DUMP, qos_mark_dump)
58 qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
62 case QOS_API_SOURCE_EXT:
65 case QOS_API_SOURCE_VLAN:
68 case QOS_API_SOURCE_MPLS:
71 case QOS_API_SOURCE_IP:
76 return (VNET_API_ERROR_INVALID_VALUE);
79 static vl_api_qos_source_t
80 qos_source_encode (qos_source_t q)
82 return ((vl_api_qos_source_t) q);
86 vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t
89 vl_api_qos_record_enable_disable_reply_t *rmp;
93 VALIDATE_SW_IF_INDEX (&(mp->record));
95 rv = qos_source_decode (mp->record.input_source, &qs);
100 rv = qos_record_enable (ntohl (mp->record.sw_if_index), qs);
102 rv = qos_record_disable (ntohl (mp->record.sw_if_index), qs);
105 BAD_SW_IF_INDEX_LABEL;
106 REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
109 typedef struct qos_record_send_walk_ctx_t_
111 vl_api_registration_t *reg;
113 } qos_record_send_walk_ctx_t;
116 send_qos_record_details (u32 sw_if_index, qos_source_t input_source, void *c)
118 qos_record_send_walk_ctx_t *ctx;
119 vl_api_qos_record_details_t *mp;
122 mp = vl_msg_api_alloc_zero (sizeof (*mp));
124 mp->_vl_msg_id = ntohs (VL_API_QOS_RECORD_DETAILS);
125 mp->context = ctx->context;
126 mp->record.sw_if_index = htonl (sw_if_index);
127 mp->record.input_source = qos_source_encode (input_source);
129 vl_api_send_msg (ctx->reg, (u8 *) mp);
131 return (WALK_CONTINUE);
135 vl_api_qos_record_dump_t_handler (vl_api_qos_record_dump_t * mp)
137 vl_api_registration_t *reg;
139 reg = vl_api_client_index_to_registration (mp->client_index);
143 qos_record_send_walk_ctx_t ctx = {
145 .context = mp->context,
147 qos_record_walk (send_qos_record_details, &ctx);
151 vl_api_qos_store_enable_disable_t_handler (vl_api_qos_store_enable_disable_t
154 vl_api_qos_store_enable_disable_reply_t *rmp;
158 VALIDATE_SW_IF_INDEX (&(mp->store));
160 rv = qos_source_decode (mp->store.input_source, &qs);
165 rv = qos_store_enable (ntohl (mp->store.sw_if_index), qs,
168 rv = qos_store_disable (ntohl (mp->store.sw_if_index), qs);
171 BAD_SW_IF_INDEX_LABEL;
172 REPLY_MACRO (VL_API_QOS_STORE_ENABLE_DISABLE_REPLY);
175 typedef struct qos_store_send_walk_ctx_t_
177 vl_api_registration_t *reg;
179 } qos_store_send_walk_ctx_t;
182 send_qos_store_details (u32 sw_if_index,
183 qos_source_t input_source, qos_bits_t value, void *c)
185 qos_store_send_walk_ctx_t *ctx;
186 vl_api_qos_store_details_t *mp;
189 mp = vl_msg_api_alloc_zero (sizeof (*mp));
191 mp->_vl_msg_id = ntohs (VL_API_QOS_STORE_DETAILS);
192 mp->context = ctx->context;
193 mp->store.sw_if_index = htonl (sw_if_index);
194 mp->store.input_source = qos_source_encode (input_source);
195 mp->store.value = value;
197 vl_api_send_msg (ctx->reg, (u8 *) mp);
199 return (WALK_CONTINUE);
203 vl_api_qos_store_dump_t_handler (vl_api_qos_store_dump_t * mp)
205 vl_api_registration_t *reg;
207 reg = vl_api_client_index_to_registration (mp->client_index);
211 qos_store_send_walk_ctx_t ctx = {
213 .context = mp->context,
215 qos_store_walk (send_qos_store_details, &ctx);
219 vl_api_qos_egress_map_update_t_handler (vl_api_qos_egress_map_update_t * mp)
221 vl_api_qos_egress_map_update_reply_t *rmp;
225 FOR_EACH_QOS_SOURCE (qs)
227 qos_egress_map_update (ntohl (mp->map.id), qs,
228 &mp->map.rows[qs].outputs[0]);
231 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
235 vl_api_qos_egress_map_delete_t_handler (vl_api_qos_egress_map_delete_t * mp)
237 vl_api_qos_egress_map_delete_reply_t *rmp;
240 qos_egress_map_delete (ntohl (mp->id));
242 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
245 typedef struct qos_egress_map_send_walk_ctx_t_
247 vl_api_registration_t *reg;
249 } qos_egress_map_send_walk_ctx_t;
252 send_qos_egress_map_details (qos_egress_map_id_t id,
253 const qos_egress_map_t * m, void *c)
255 qos_egress_map_send_walk_ctx_t *ctx;
256 vl_api_qos_egress_map_details_t *mp;
260 mp = vl_msg_api_alloc_zero (sizeof (*mp));
262 mp->_vl_msg_id = ntohs (VL_API_QOS_EGRESS_MAP_DETAILS);
263 mp->context = ctx->context;
264 mp->map.id = htonl (id);
266 for (ii = 0; ii < 4; ii++)
267 clib_memcpy (mp->map.rows[ii].outputs, m->qem_output[ii], 256);
269 vl_api_send_msg (ctx->reg, (u8 *) mp);
271 return (WALK_CONTINUE);
275 vl_api_qos_egress_map_dump_t_handler (vl_api_qos_egress_map_dump_t * mp)
277 vl_api_registration_t *reg;
279 reg = vl_api_client_index_to_registration (mp->client_index);
283 qos_egress_map_send_walk_ctx_t ctx = {
285 .context = mp->context,
287 qos_egress_map_walk (send_qos_egress_map_details, &ctx);
291 vl_api_qos_mark_enable_disable_t_handler (vl_api_qos_mark_enable_disable_t *
294 vl_api_qos_mark_enable_disable_reply_t *rmp;
298 rv = qos_source_decode (mp->mark.output_source, &qs);
303 rv = qos_mark_enable (ntohl (mp->mark.sw_if_index),
304 qs, ntohl (mp->mark.map_id));
306 rv = qos_mark_disable (ntohl (mp->mark.sw_if_index), qs);
309 REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
312 typedef struct qos_mark_send_walk_ctx_t_
314 vl_api_registration_t *reg;
316 } qos_mark_send_walk_ctx_t;
319 send_qos_mark_details (u32 sw_if_index,
320 u32 map_id, qos_source_t output_source, void *c)
322 qos_mark_send_walk_ctx_t *ctx;
323 vl_api_qos_mark_details_t *mp;
326 mp = vl_msg_api_alloc_zero (sizeof (*mp));
328 mp->_vl_msg_id = ntohs (VL_API_QOS_MARK_DETAILS);
329 mp->context = ctx->context;
330 mp->mark.sw_if_index = htonl (sw_if_index);
331 mp->mark.output_source = qos_source_encode (output_source);
332 mp->mark.map_id = htonl (map_id);
334 vl_api_send_msg (ctx->reg, (u8 *) mp);
336 return (WALK_CONTINUE);
340 vl_api_qos_mark_dump_t_handler (vl_api_qos_mark_dump_t * mp)
342 vl_api_registration_t *reg;
344 reg = vl_api_client_index_to_registration (mp->client_index);
348 qos_mark_send_walk_ctx_t ctx = {
350 .context = mp->context,
352 qos_mark_walk (send_qos_mark_details, &ctx);
355 #define vl_msg_name_crc_list
356 #include <vnet/qos/qos.api.h>
357 #undef vl_msg_name_crc_list
360 setup_message_id_table (api_main_t * am)
362 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
363 foreach_vl_msg_name_crc_qos;
367 static clib_error_t *
368 qos_api_hookup (vlib_main_t * vm)
370 api_main_t *am = &api_main;
373 vl_msg_api_set_handlers(VL_API_##N, #n, \
374 vl_api_##n##_t_handler, \
376 vl_api_##n##_t_endian, \
377 vl_api_##n##_t_print, \
378 sizeof(vl_api_##n##_t), 1);
383 * Set up the (msg_name, crc, message-id) table
385 setup_message_id_table (am);
390 VLIB_API_INIT_FUNCTION (qos_api_hookup);
393 * fd.io coding-style-patch-verification: ON
396 * eval: (c-set-style "gnu")