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_mark.h>
24 #include <vnet/qos/qos_egress_map.h>
26 #include <vnet/vnet_msg_enum.h>
28 #define vl_typedefs /* define message structures */
29 #include <vnet/vnet_all_api_h.h>
32 #define vl_endianfun /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #include <vnet/vnet_all_api_h.h>
42 #include <vlibapi/api_helper_macros.h>
45 #define foreach_qos_api_msg \
46 _(QOS_RECORD_ENABLE_DISABLE, qos_record_enable_disable) \
47 _(QOS_RECORD_DUMP, qos_record_dump) \
48 _(QOS_EGRESS_MAP_DELETE, qos_egress_map_delete) \
49 _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update) \
50 _(QOS_EGRESS_MAP_DUMP, qos_egress_map_dump) \
51 _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable) \
52 _(QOS_MARK_DUMP, qos_mark_dump)
55 qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
59 case QOS_API_SOURCE_EXT:
62 case QOS_API_SOURCE_VLAN:
65 case QOS_API_SOURCE_MPLS:
68 case QOS_API_SOURCE_IP:
73 return (VNET_API_ERROR_INVALID_VALUE);
76 static vl_api_qos_source_t
77 qos_source_encode (qos_source_t q)
79 return ((vl_api_qos_source_t) q);
83 vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t
86 vl_api_qos_record_enable_disable_reply_t *rmp;
90 VALIDATE_SW_IF_INDEX (&(mp->record));
92 rv = qos_source_decode (mp->record.input_source, &qs);
97 rv = qos_record_enable (ntohl (mp->record.sw_if_index), qs);
99 rv = qos_record_disable (ntohl (mp->record.sw_if_index), qs);
102 BAD_SW_IF_INDEX_LABEL;
103 REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
106 typedef struct qos_record_send_walk_ctx_t_
108 vl_api_registration_t *reg;
110 } qos_record_send_walk_ctx_t;
113 send_qos_record_details (u32 sw_if_index, qos_source_t input_source, void *c)
115 qos_record_send_walk_ctx_t *ctx;
116 vl_api_qos_record_details_t *mp;
119 mp = vl_msg_api_alloc_zero (sizeof (*mp));
121 mp->_vl_msg_id = ntohs (VL_API_QOS_RECORD_DETAILS);
122 mp->context = ctx->context;
123 mp->record.sw_if_index = htonl (sw_if_index);
124 mp->record.input_source = qos_source_encode (input_source);
126 vl_api_send_msg (ctx->reg, (u8 *) mp);
128 return (WALK_CONTINUE);
132 vl_api_qos_record_dump_t_handler (vl_api_qos_record_dump_t * mp)
134 vl_api_registration_t *reg;
136 reg = vl_api_client_index_to_registration (mp->client_index);
140 qos_record_send_walk_ctx_t ctx = {
142 .context = mp->context,
144 qos_record_walk (send_qos_record_details, &ctx);
148 vl_api_qos_egress_map_update_t_handler (vl_api_qos_egress_map_update_t * mp)
150 vl_api_qos_egress_map_update_reply_t *rmp;
154 FOR_EACH_QOS_SOURCE (qs)
156 qos_egress_map_update (ntohl (mp->map.id), qs,
157 &mp->map.rows[qs].outputs[0]);
160 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
164 vl_api_qos_egress_map_delete_t_handler (vl_api_qos_egress_map_delete_t * mp)
166 vl_api_qos_egress_map_delete_reply_t *rmp;
169 qos_egress_map_delete (ntohl (mp->id));
171 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
174 typedef struct qos_egress_map_send_walk_ctx_t_
176 vl_api_registration_t *reg;
178 } qos_egress_map_send_walk_ctx_t;
181 send_qos_egress_map_details (qos_egress_map_id_t id,
182 const qos_egress_map_t * m, void *c)
184 qos_egress_map_send_walk_ctx_t *ctx;
185 vl_api_qos_egress_map_details_t *mp;
189 mp = vl_msg_api_alloc_zero (sizeof (*mp));
191 mp->_vl_msg_id = ntohs (VL_API_QOS_EGRESS_MAP_DETAILS);
192 mp->context = ctx->context;
193 mp->map.id = htonl (id);
195 for (ii = 0; ii < 4; ii++)
196 clib_memcpy (mp->map.rows[ii].outputs, m->qem_output[ii], 256);
198 vl_api_send_msg (ctx->reg, (u8 *) mp);
200 return (WALK_CONTINUE);
204 vl_api_qos_egress_map_dump_t_handler (vl_api_qos_egress_map_dump_t * mp)
206 vl_api_registration_t *reg;
208 reg = vl_api_client_index_to_registration (mp->client_index);
212 qos_egress_map_send_walk_ctx_t ctx = {
214 .context = mp->context,
216 qos_egress_map_walk (send_qos_egress_map_details, &ctx);
220 vl_api_qos_mark_enable_disable_t_handler (vl_api_qos_mark_enable_disable_t *
223 vl_api_qos_mark_enable_disable_reply_t *rmp;
227 rv = qos_source_decode (mp->mark.output_source, &qs);
232 rv = qos_mark_enable (ntohl (mp->mark.sw_if_index),
233 qs, ntohl (mp->mark.map_id));
235 rv = qos_mark_disable (ntohl (mp->mark.sw_if_index), qs);
238 REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
241 typedef struct qos_mark_send_walk_ctx_t_
243 vl_api_registration_t *reg;
245 } qos_mark_send_walk_ctx_t;
248 send_qos_mark_details (u32 sw_if_index,
249 u32 map_id, qos_source_t output_source, void *c)
251 qos_mark_send_walk_ctx_t *ctx;
252 vl_api_qos_mark_details_t *mp;
255 mp = vl_msg_api_alloc_zero (sizeof (*mp));
257 mp->_vl_msg_id = ntohs (VL_API_QOS_MARK_DETAILS);
258 mp->context = ctx->context;
259 mp->mark.sw_if_index = htonl (sw_if_index);
260 mp->mark.output_source = qos_source_encode (output_source);
261 mp->mark.map_id = htonl (map_id);
263 vl_api_send_msg (ctx->reg, (u8 *) mp);
265 return (WALK_CONTINUE);
269 vl_api_qos_mark_dump_t_handler (vl_api_qos_mark_dump_t * mp)
271 vl_api_registration_t *reg;
273 reg = vl_api_client_index_to_registration (mp->client_index);
277 qos_mark_send_walk_ctx_t ctx = {
279 .context = mp->context,
281 qos_mark_walk (send_qos_mark_details, &ctx);
284 #define vl_msg_name_crc_list
285 #include <vnet/qos/qos.api.h>
286 #undef vl_msg_name_crc_list
289 setup_message_id_table (api_main_t * am)
291 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
292 foreach_vl_msg_name_crc_qos;
296 static clib_error_t *
297 qos_api_hookup (vlib_main_t * vm)
299 api_main_t *am = &api_main;
302 vl_msg_api_set_handlers(VL_API_##N, #n, \
303 vl_api_##n##_t_handler, \
305 vl_api_##n##_t_endian, \
306 vl_api_##n##_t_print, \
307 sizeof(vl_api_##n##_t), 1);
312 * Set up the (msg_name, crc, message-id) table
314 setup_message_id_table (am);
319 VLIB_API_INIT_FUNCTION (qos_api_hookup);
322 * fd.io coding-style-patch-verification: ON
325 * eval: (c-set-style "gnu")