blob: e2393137d1524a61097d55083f976f361ed92e02 [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>
23#include <vnet/qos/qos_mark.h>
24#include <vnet/qos/qos_egress_map.h>
25
26#include <vnet/vnet_msg_enum.h>
27
28#define vl_typedefs /* define message structures */
29#include <vnet/vnet_all_api_h.h>
30#undef vl_typedefs
31
32#define vl_endianfun /* define message structures */
33#include <vnet/vnet_all_api_h.h>
34#undef vl_endianfun
35
36/* instantiate all the print functions we know about */
37#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38#define vl_printfun
39#include <vnet/vnet_all_api_h.h>
40#undef vl_printfun
41
42#include <vlibapi/api_helper_macros.h>
43
44
45#define foreach_qos_api_msg \
46 _(QOS_RECORD_ENABLE_DISABLE, qos_record_enable_disable) \
47 _(QOS_EGRESS_MAP_DELETE, qos_egress_map_delete) \
48 _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update) \
49 _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable)
50
51void
52vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t
53 * mp)
54{
55 vl_api_qos_record_enable_disable_reply_t *rmp;
56 int rv = 0;
57
Neale Ranns9a1f49e2018-03-19 02:39:45 -070058 if (mp->input_source >= QOS_N_SOURCES)
Neale Ranns039cbfe2018-02-27 03:45:38 -080059 rv = VNET_API_ERROR_INVALID_VALUE;
60 else
61 {
62 if (mp->enable)
63 rv = qos_record_enable (ntohl (mp->sw_if_index), mp->input_source);
64 else
65 rv = qos_record_disable (ntohl (mp->sw_if_index), mp->input_source);
66 }
67
68 REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
69}
70
71void
72vl_api_qos_egress_map_update_t_handler (vl_api_qos_egress_map_update_t * mp)
73{
74 vl_api_qos_egress_map_update_reply_t *rmp;
75 qos_source_t qs;
76 int rv = 0;
77
78 FOR_EACH_QOS_SOURCE (qs)
79 {
80 qos_egress_map_update (ntohl (mp->map_id), qs, &mp->rows[qs].outputs[0]);
81 }
82
83 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
84}
85
86void
87vl_api_qos_egress_map_delete_t_handler (vl_api_qos_egress_map_delete_t * mp)
88{
89 vl_api_qos_egress_map_delete_reply_t *rmp;
90 int rv = 0;
91
92 qos_egress_map_delete (ntohl (mp->map_id));
93
94 REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
95}
96
97void
98 vl_api_qos_mark_enable_disable_t_handler
99 (vl_api_qos_mark_enable_disable_t * mp)
100{
101 vl_api_qos_mark_enable_disable_reply_t *rmp;
102 int rv = 0;
103
Neale Ranns9a1f49e2018-03-19 02:39:45 -0700104 if (mp->output_source >= QOS_N_SOURCES)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800105 rv = VNET_API_ERROR_INVALID_VALUE;
106 else
107 {
108 if (mp->enable)
109 rv = qos_mark_enable (ntohl (mp->sw_if_index),
110 mp->output_source, ntohl (mp->map_id));
111 else
112 rv = qos_mark_disable (ntohl (mp->sw_if_index), mp->output_source);
113 }
114
115 REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
116}
117
118#define vl_msg_name_crc_list
119#include <vnet/qos/qos.api.h>
120#undef vl_msg_name_crc_list
121
122static void
123setup_message_id_table (api_main_t * am)
124{
125#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
126 foreach_vl_msg_name_crc_qos;
127#undef _
128}
129
130static clib_error_t *
131qos_api_hookup (vlib_main_t * vm)
132{
133 api_main_t *am = &api_main;
134
135#define _(N,n) \
136 vl_msg_api_set_handlers(VL_API_##N, #n, \
137 vl_api_##n##_t_handler, \
138 vl_noop_handler, \
139 vl_api_##n##_t_endian, \
140 vl_api_##n##_t_print, \
141 sizeof(vl_api_##n##_t), 1);
142 foreach_qos_api_msg;
143#undef _
144
145 /*
146 * Set up the (msg_name, crc, message-id) table
147 */
148 setup_message_id_table (am);
149
150 return 0;
151}
152
153VLIB_API_INIT_FUNCTION (qos_api_hookup);
154
155/*
156 * fd.io coding-style-patch-verification: ON
157 *
158 * Local Variables:
159 * eval: (c-set-style "gnu")
160 * End:
161 */