blob: af0a700d2b52c805c66bc2e1753b83bfff9b203b [file] [log] [blame]
Neale Ranns039cbfe2018-02-27 03:45:38 -08001/*
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 *------------------------------------------------------------------
16 */
17
18#include <vnet/vnet.h>
19#include <vlibmemory/api.h>
20#include <vnet/api_errno.h>
21
22#include <vnet/qos/qos_record.h>
Neale Ranns83832e72019-07-31 02:48:02 -070023#include <vnet/qos/qos_store.h>
Neale Ranns039cbfe2018-02-27 03:45:38 -080024#include <vnet/qos/qos_mark.h>
25#include <vnet/qos/qos_egress_map.h>
26
27#include <vnet/vnet_msg_enum.h>
28
29#define vl_typedefs /* define message structures */
30#include <vnet/vnet_all_api_h.h>
31#undef vl_typedefs
32
33#define vl_endianfun /* define message structures */
34#include <vnet/vnet_all_api_h.h>
35#undef vl_endianfun
36
37/* instantiate all the print functions we know about */
38#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39#define vl_printfun
40#include <vnet/vnet_all_api_h.h>
41#undef vl_printfun
42
43#include <vlibapi/api_helper_macros.h>
44
45
46#define foreach_qos_api_msg \
47 _(QOS_RECORD_ENABLE_DISABLE, qos_record_enable_disable) \
Neale Ranns5281a902019-07-23 08:16:19 -070048 _(QOS_RECORD_DUMP, qos_record_dump) \
Neale Ranns83832e72019-07-31 02:48:02 -070049 _(QOS_STORE_ENABLE_DISABLE, qos_store_enable_disable) \
50 _(QOS_STORE_DUMP, qos_store_dump) \
Neale Ranns039cbfe2018-02-27 03:45:38 -080051 _(QOS_EGRESS_MAP_DELETE, qos_egress_map_delete) \
52 _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update) \
Neale Ranns5281a902019-07-23 08:16:19 -070053 _(QOS_EGRESS_MAP_DUMP, qos_egress_map_dump) \
54 _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable) \
55 _(QOS_MARK_DUMP, qos_mark_dump)
Neale Ranns039cbfe2018-02-27 03:45:38 -080056
Neale Rannsed234e72018-09-05 09:36:05 -070057static int
58qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
59{
Neale Rannsed234e72018-09-05 09:36:05 -070060 switch (v)
61 {
62 case QOS_API_SOURCE_EXT:
63 *q = QOS_SOURCE_EXT;
64 return 0;
65 case QOS_API_SOURCE_VLAN:
66 *q = QOS_SOURCE_VLAN;
67 return 0;
68 case QOS_API_SOURCE_MPLS:
69 *q = QOS_SOURCE_MPLS;
70 return 0;
71 case QOS_API_SOURCE_IP:
72 *q = QOS_SOURCE_IP;
73 return 0;
74 }
75
76 return (VNET_API_ERROR_INVALID_VALUE);
77}
78
Neale Ranns5281a902019-07-23 08:16:19 -070079static vl_api_qos_source_t
80qos_source_encode (qos_source_t q)
81{
82 return ((vl_api_qos_source_t) q);
83}
84
Neale Ranns039cbfe2018-02-27 03:45:38 -080085void
86vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t
87 * mp)
88{
89 vl_api_qos_record_enable_disable_reply_t *rmp;
Neale Rannsed234e72018-09-05 09:36:05 -070090 qos_source_t qs;
Neale Ranns039cbfe2018-02-27 03:45:38 -080091 int rv = 0;
92
Neale Ranns5281a902019-07-23 08:16:19 -070093 VALIDATE_SW_IF_INDEX (&(mp->record));
94
95 rv = qos_source_decode (mp->record.input_source, &qs);
Neale Rannsed234e72018-09-05 09:36:05 -070096
97 if (0 == rv)
Neale Ranns039cbfe2018-02-27 03:45:38 -080098 {
99 if (mp->enable)
Neale Ranns5281a902019-07-23 08:16:19 -0700100 rv = qos_record_enable (ntohl (mp->record.sw_if_index), qs);
Neale Ranns039cbfe2018-02-27 03:45:38 -0800101 else
Neale Ranns5281a902019-07-23 08:16:19 -0700102 rv = qos_record_disable (ntohl (mp->record.sw_if_index), qs);
Neale Ranns039cbfe2018-02-27 03:45:38 -0800103 }
104
Neale Ranns5281a902019-07-23 08:16:19 -0700105 BAD_SW_IF_INDEX_LABEL;
Neale Ranns039cbfe2018-02-27 03:45:38 -0800106 REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
107}
108
Neale Ranns5281a902019-07-23 08:16:19 -0700109typedef struct qos_record_send_walk_ctx_t_
110{
111 vl_api_registration_t *reg;
112 u32 context;
113} qos_record_send_walk_ctx_t;
114
115static walk_rc_t
116send_qos_record_details (u32 sw_if_index, qos_source_t input_source, void *c)
117{
118 qos_record_send_walk_ctx_t *ctx;
119 vl_api_qos_record_details_t *mp;
120
121 ctx = c;
122 mp = vl_msg_api_alloc_zero (sizeof (*mp));
123
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);
128
129 vl_api_send_msg (ctx->reg, (u8 *) mp);
130
131 return (WALK_CONTINUE);
132}
133
134static void
135vl_api_qos_record_dump_t_handler (vl_api_qos_record_dump_t * mp)
136{
137 vl_api_registration_t *reg;
138
139 reg = vl_api_client_index_to_registration (mp->client_index);
140 if (!reg)
141 return;
142
143 qos_record_send_walk_ctx_t ctx = {
144 .reg = reg,
145 .context = mp->context,
146 };
147 qos_record_walk (send_qos_record_details, &ctx);
148}
149
Neale Ranns039cbfe2018-02-27 03:45:38 -0800150void
Neale Ranns83832e72019-07-31 02:48:02 -0700151vl_api_qos_store_enable_disable_t_handler (vl_api_qos_store_enable_disable_t
152 * mp)
153{
154 vl_api_qos_store_enable_disable_reply_t *rmp;
155 qos_source_t qs;
156 int rv = 0;
157
158 VALIDATE_SW_IF_INDEX (&(mp->store));
159
160 rv = qos_source_decode (mp->store.input_source, &qs);
161
162 if (0 == rv)
163 {
164 if (mp->enable)
165 rv = qos_store_enable (ntohl (mp->store.sw_if_index), qs,
166 mp->store.value);
167 else
168 rv = qos_store_disable (ntohl (mp->store.sw_if_index), qs);
169 }
170
171 BAD_SW_IF_INDEX_LABEL;
172 REPLY_MACRO (VL_API_QOS_STORE_ENABLE_DISABLE_REPLY);
173}
174
175typedef struct qos_store_send_walk_ctx_t_
176{
177 vl_api_registration_t *reg;
178 u32 context;
179} qos_store_send_walk_ctx_t;
180
181static walk_rc_t
182send_qos_store_details (u32 sw_if_index,
183 qos_source_t input_source, qos_bits_t value, void *c)
184{
185 qos_store_send_walk_ctx_t *ctx;
186 vl_api_qos_store_details_t *mp;
187
188 ctx = c;
189 mp = vl_msg_api_alloc_zero (sizeof (*mp));
190
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;
196
197 vl_api_send_msg (ctx->reg, (u8 *) mp);
198
199 return (WALK_CONTINUE);
200}
201
202static void
203vl_api_qos_store_dump_t_handler (vl_api_qos_store_dump_t * mp)
204{
205 vl_api_registration_t *reg;
206
207 reg = vl_api_client_index_to_registration (mp->client_index);
208 if (!reg)
209 return;
210
211 qos_store_send_walk_ctx_t ctx = {
212 .reg = reg,
213 .context = mp->context,
214 };
215 qos_store_walk (send_qos_store_details, &ctx);
216}
217
218void
Neale Ranns039cbfe2018-02-27 03:45:38 -0800219vl_api_qos_egress_map_update_t_handler (vl_api_qos_egress_map_update_t * mp)
220{
221 vl_api_qos_egress_map_update_reply_t *rmp;
222 qos_source_t qs;
223 int rv = 0;
224
225 FOR_EACH_QOS_SOURCE (qs)
226 {
Neale Ranns5281a902019-07-23 08:16:19 -0700227 qos_egress_map_update (ntohl (mp->map.id), qs,
228 &mp->map.rows[qs].outputs[0]);
Neale Ranns039cbfe2018-02-27 03:45:38 -0800229 }
230
231 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
232}
233
234void
235vl_api_qos_egress_map_delete_t_handler (vl_api_qos_egress_map_delete_t * mp)
236{
237 vl_api_qos_egress_map_delete_reply_t *rmp;
238 int rv = 0;
239
Neale Ranns5281a902019-07-23 08:16:19 -0700240 qos_egress_map_delete (ntohl (mp->id));
Neale Ranns039cbfe2018-02-27 03:45:38 -0800241
242 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
243}
244
Neale Ranns5281a902019-07-23 08:16:19 -0700245typedef struct qos_egress_map_send_walk_ctx_t_
246{
247 vl_api_registration_t *reg;
248 u32 context;
249} qos_egress_map_send_walk_ctx_t;
250
251static walk_rc_t
252send_qos_egress_map_details (qos_egress_map_id_t id,
253 const qos_egress_map_t * m, void *c)
254{
255 qos_egress_map_send_walk_ctx_t *ctx;
256 vl_api_qos_egress_map_details_t *mp;
257 u8 ii;
258
259 ctx = c;
260 mp = vl_msg_api_alloc_zero (sizeof (*mp));
261
262 mp->_vl_msg_id = ntohs (VL_API_QOS_EGRESS_MAP_DETAILS);
263 mp->context = ctx->context;
264 mp->map.id = htonl (id);
265
266 for (ii = 0; ii < 4; ii++)
267 clib_memcpy (mp->map.rows[ii].outputs, m->qem_output[ii], 256);
268
269 vl_api_send_msg (ctx->reg, (u8 *) mp);
270
271 return (WALK_CONTINUE);
272}
273
274static void
275vl_api_qos_egress_map_dump_t_handler (vl_api_qos_egress_map_dump_t * mp)
276{
277 vl_api_registration_t *reg;
278
279 reg = vl_api_client_index_to_registration (mp->client_index);
280 if (!reg)
281 return;
282
283 qos_egress_map_send_walk_ctx_t ctx = {
284 .reg = reg,
285 .context = mp->context,
286 };
287 qos_egress_map_walk (send_qos_egress_map_details, &ctx);
288}
289
Neale Ranns039cbfe2018-02-27 03:45:38 -0800290void
Neale Ranns5281a902019-07-23 08:16:19 -0700291vl_api_qos_mark_enable_disable_t_handler (vl_api_qos_mark_enable_disable_t *
292 mp)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800293{
294 vl_api_qos_mark_enable_disable_reply_t *rmp;
Neale Rannsed234e72018-09-05 09:36:05 -0700295 qos_source_t qs;
Neale Ranns039cbfe2018-02-27 03:45:38 -0800296 int rv = 0;
297
Neale Ranns5281a902019-07-23 08:16:19 -0700298 rv = qos_source_decode (mp->mark.output_source, &qs);
Neale Rannsed234e72018-09-05 09:36:05 -0700299
300 if (0 == rv)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800301 {
302 if (mp->enable)
Neale Ranns5281a902019-07-23 08:16:19 -0700303 rv = qos_mark_enable (ntohl (mp->mark.sw_if_index),
304 qs, ntohl (mp->mark.map_id));
Neale Ranns039cbfe2018-02-27 03:45:38 -0800305 else
Neale Ranns5281a902019-07-23 08:16:19 -0700306 rv = qos_mark_disable (ntohl (mp->mark.sw_if_index), qs);
Neale Ranns039cbfe2018-02-27 03:45:38 -0800307 }
308
309 REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
310}
311
Neale Ranns5281a902019-07-23 08:16:19 -0700312typedef struct qos_mark_send_walk_ctx_t_
313{
314 vl_api_registration_t *reg;
315 u32 context;
316} qos_mark_send_walk_ctx_t;
317
318static walk_rc_t
319send_qos_mark_details (u32 sw_if_index,
320 u32 map_id, qos_source_t output_source, void *c)
321{
322 qos_mark_send_walk_ctx_t *ctx;
323 vl_api_qos_mark_details_t *mp;
324
325 ctx = c;
326 mp = vl_msg_api_alloc_zero (sizeof (*mp));
327
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);
333
334 vl_api_send_msg (ctx->reg, (u8 *) mp);
335
336 return (WALK_CONTINUE);
337}
338
339static void
340vl_api_qos_mark_dump_t_handler (vl_api_qos_mark_dump_t * mp)
341{
342 vl_api_registration_t *reg;
343
344 reg = vl_api_client_index_to_registration (mp->client_index);
345 if (!reg)
346 return;
347
348 qos_mark_send_walk_ctx_t ctx = {
349 .reg = reg,
350 .context = mp->context,
351 };
352 qos_mark_walk (send_qos_mark_details, &ctx);
353}
354
Neale Ranns039cbfe2018-02-27 03:45:38 -0800355#define vl_msg_name_crc_list
356#include <vnet/qos/qos.api.h>
357#undef vl_msg_name_crc_list
358
359static void
360setup_message_id_table (api_main_t * am)
361{
362#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
363 foreach_vl_msg_name_crc_qos;
364#undef _
365}
366
367static clib_error_t *
368qos_api_hookup (vlib_main_t * vm)
369{
Dave Barach39d69112019-11-27 11:42:13 -0500370 api_main_t *am = vlibapi_get_main ();
Neale Ranns039cbfe2018-02-27 03:45:38 -0800371
372#define _(N,n) \
373 vl_msg_api_set_handlers(VL_API_##N, #n, \
374 vl_api_##n##_t_handler, \
375 vl_noop_handler, \
376 vl_api_##n##_t_endian, \
377 vl_api_##n##_t_print, \
378 sizeof(vl_api_##n##_t), 1);
379 foreach_qos_api_msg;
380#undef _
381
382 /*
383 * Set up the (msg_name, crc, message-id) table
384 */
385 setup_message_id_table (am);
386
387 return 0;
388}
389
390VLIB_API_INIT_FUNCTION (qos_api_hookup);
391
392/*
393 * fd.io coding-style-patch-verification: ON
394 *
395 * Local Variables:
396 * eval: (c-set-style "gnu")
397 * End:
398 */