QoS recording and marking
[vpp.git] / src / vnet / qos / qos_api.c
1 /*
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
51 void
52 vl_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
58   if (mp->input_source > QOS_N_SOURCES)
59     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
71 void
72 vl_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
86 void
87 vl_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
97 void
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
104   if (mp->output_source > QOS_N_SOURCES)
105     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
122 static void
123 setup_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
130 static clib_error_t *
131 qos_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
153 VLIB_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  */