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/format_fns.h>
28 #include <vnet/qos/qos.api_enum.h>
29 #include <vnet/qos/qos.api_types.h>
31 #define REPLY_MSG_ID_BASE msg_id_base
32 #include <vlibapi/api_helper_macros.h>
34 static u16 msg_id_base;
37 qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
41 case QOS_API_SOURCE_EXT:
44 case QOS_API_SOURCE_VLAN:
47 case QOS_API_SOURCE_MPLS:
50 case QOS_API_SOURCE_IP:
55 return (VNET_API_ERROR_INVALID_VALUE);
58 static vl_api_qos_source_t
59 qos_source_encode (qos_source_t q)
61 return ((vl_api_qos_source_t) q);
65 vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t
68 vl_api_qos_record_enable_disable_reply_t *rmp;
72 VALIDATE_SW_IF_INDEX (&(mp->record));
74 rv = qos_source_decode (mp->record.input_source, &qs);
79 rv = qos_record_enable (ntohl (mp->record.sw_if_index), qs);
81 rv = qos_record_disable (ntohl (mp->record.sw_if_index), qs);
84 BAD_SW_IF_INDEX_LABEL;
85 REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
88 typedef struct qos_record_send_walk_ctx_t_
90 vl_api_registration_t *reg;
92 } qos_record_send_walk_ctx_t;
95 send_qos_record_details (u32 sw_if_index, qos_source_t input_source, void *c)
97 qos_record_send_walk_ctx_t *ctx;
98 vl_api_qos_record_details_t *mp;
101 mp = vl_msg_api_alloc_zero (sizeof (*mp));
103 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_RECORD_DETAILS);
104 mp->context = ctx->context;
105 mp->record.sw_if_index = htonl (sw_if_index);
106 mp->record.input_source = qos_source_encode (input_source);
108 vl_api_send_msg (ctx->reg, (u8 *) mp);
110 return (WALK_CONTINUE);
114 vl_api_qos_record_dump_t_handler (vl_api_qos_record_dump_t * mp)
116 vl_api_registration_t *reg;
118 reg = vl_api_client_index_to_registration (mp->client_index);
122 qos_record_send_walk_ctx_t ctx = {
124 .context = mp->context,
126 qos_record_walk (send_qos_record_details, &ctx);
130 vl_api_qos_store_enable_disable_t_handler (vl_api_qos_store_enable_disable_t
133 vl_api_qos_store_enable_disable_reply_t *rmp;
137 VALIDATE_SW_IF_INDEX (&(mp->store));
139 rv = qos_source_decode (mp->store.input_source, &qs);
144 rv = qos_store_enable (ntohl (mp->store.sw_if_index), qs,
147 rv = qos_store_disable (ntohl (mp->store.sw_if_index), qs);
150 BAD_SW_IF_INDEX_LABEL;
151 REPLY_MACRO (VL_API_QOS_STORE_ENABLE_DISABLE_REPLY);
154 typedef struct qos_store_send_walk_ctx_t_
156 vl_api_registration_t *reg;
158 } qos_store_send_walk_ctx_t;
161 send_qos_store_details (u32 sw_if_index,
162 qos_source_t input_source, qos_bits_t value, void *c)
164 qos_store_send_walk_ctx_t *ctx;
165 vl_api_qos_store_details_t *mp;
168 mp = vl_msg_api_alloc_zero (sizeof (*mp));
170 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_STORE_DETAILS);
171 mp->context = ctx->context;
172 mp->store.sw_if_index = htonl (sw_if_index);
173 mp->store.input_source = qos_source_encode (input_source);
174 mp->store.value = value;
176 vl_api_send_msg (ctx->reg, (u8 *) mp);
178 return (WALK_CONTINUE);
182 vl_api_qos_store_dump_t_handler (vl_api_qos_store_dump_t * mp)
184 vl_api_registration_t *reg;
186 reg = vl_api_client_index_to_registration (mp->client_index);
190 qos_store_send_walk_ctx_t ctx = {
192 .context = mp->context,
194 qos_store_walk (send_qos_store_details, &ctx);
198 vl_api_qos_egress_map_update_t_handler (vl_api_qos_egress_map_update_t * mp)
200 vl_api_qos_egress_map_update_reply_t *rmp;
204 FOR_EACH_QOS_SOURCE (qs)
206 qos_egress_map_update (ntohl (mp->map.id), qs,
207 &mp->map.rows[qs].outputs[0]);
210 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
214 vl_api_qos_egress_map_delete_t_handler (vl_api_qos_egress_map_delete_t * mp)
216 vl_api_qos_egress_map_delete_reply_t *rmp;
219 qos_egress_map_delete (ntohl (mp->id));
221 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
224 typedef struct qos_egress_map_send_walk_ctx_t_
226 vl_api_registration_t *reg;
228 } qos_egress_map_send_walk_ctx_t;
231 send_qos_egress_map_details (qos_egress_map_id_t id,
232 const qos_egress_map_t * m, void *c)
234 qos_egress_map_send_walk_ctx_t *ctx;
235 vl_api_qos_egress_map_details_t *mp;
239 mp = vl_msg_api_alloc_zero (sizeof (*mp));
241 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_EGRESS_MAP_DETAILS);
242 mp->context = ctx->context;
243 mp->map.id = htonl (id);
245 for (ii = 0; ii < 4; ii++)
246 clib_memcpy (mp->map.rows[ii].outputs, m->qem_output[ii], 256);
248 vl_api_send_msg (ctx->reg, (u8 *) mp);
250 return (WALK_CONTINUE);
254 vl_api_qos_egress_map_dump_t_handler (vl_api_qos_egress_map_dump_t * mp)
256 vl_api_registration_t *reg;
258 reg = vl_api_client_index_to_registration (mp->client_index);
262 qos_egress_map_send_walk_ctx_t ctx = {
264 .context = mp->context,
266 qos_egress_map_walk (send_qos_egress_map_details, &ctx);
270 vl_api_qos_mark_enable_disable_t_handler (vl_api_qos_mark_enable_disable_t *
273 vl_api_qos_mark_enable_disable_reply_t *rmp;
277 rv = qos_source_decode (mp->mark.output_source, &qs);
282 rv = qos_mark_enable (ntohl (mp->mark.sw_if_index),
283 qs, ntohl (mp->mark.map_id));
285 rv = qos_mark_disable (ntohl (mp->mark.sw_if_index), qs);
288 REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
291 typedef struct qos_mark_send_walk_ctx_t_
293 vl_api_registration_t *reg;
295 } qos_mark_send_walk_ctx_t;
298 send_qos_mark_details (u32 sw_if_index,
299 u32 map_id, qos_source_t output_source, void *c)
301 qos_mark_send_walk_ctx_t *ctx;
302 vl_api_qos_mark_details_t *mp;
305 mp = vl_msg_api_alloc_zero (sizeof (*mp));
307 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_MARK_DETAILS);
308 mp->context = ctx->context;
309 mp->mark.sw_if_index = htonl (sw_if_index);
310 mp->mark.output_source = qos_source_encode (output_source);
311 mp->mark.map_id = htonl (map_id);
313 vl_api_send_msg (ctx->reg, (u8 *) mp);
315 return (WALK_CONTINUE);
319 vl_api_qos_mark_dump_t_handler (vl_api_qos_mark_dump_t * mp)
321 vl_api_registration_t *reg;
323 reg = vl_api_client_index_to_registration (mp->client_index);
327 qos_mark_send_walk_ctx_t ctx = {
329 .context = mp->context,
331 qos_mark_walk (send_qos_mark_details, &ctx);
334 #include <vnet/qos/qos.api.c>
336 static clib_error_t *
337 qos_api_hookup (vlib_main_t * vm)
340 * Set up the (msg_name, crc, message-id) table
342 REPLY_MSG_ID_BASE = setup_message_id_table ();
347 VLIB_API_INIT_FUNCTION (qos_api_hookup);
350 * fd.io coding-style-patch-verification: ON
353 * eval: (c-set-style "gnu")