Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 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 | |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 51 | static int |
| 52 | qos_source_decode (vl_api_qos_source_t v, qos_source_t * q) |
| 53 | { |
| 54 | v = ntohl (v); |
| 55 | |
| 56 | switch (v) |
| 57 | { |
| 58 | case QOS_API_SOURCE_EXT: |
| 59 | *q = QOS_SOURCE_EXT; |
| 60 | return 0; |
| 61 | case QOS_API_SOURCE_VLAN: |
| 62 | *q = QOS_SOURCE_VLAN; |
| 63 | return 0; |
| 64 | case QOS_API_SOURCE_MPLS: |
| 65 | *q = QOS_SOURCE_MPLS; |
| 66 | return 0; |
| 67 | case QOS_API_SOURCE_IP: |
| 68 | *q = QOS_SOURCE_IP; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | return (VNET_API_ERROR_INVALID_VALUE); |
| 73 | } |
| 74 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 75 | void |
| 76 | vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t |
| 77 | * mp) |
| 78 | { |
| 79 | vl_api_qos_record_enable_disable_reply_t *rmp; |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 80 | qos_source_t qs; |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 81 | int rv = 0; |
| 82 | |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 83 | rv = qos_source_decode (mp->input_source, &qs); |
| 84 | |
| 85 | if (0 == rv) |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 86 | { |
| 87 | if (mp->enable) |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 88 | rv = qos_record_enable (ntohl (mp->sw_if_index), qs); |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 89 | else |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 90 | rv = qos_record_disable (ntohl (mp->sw_if_index), qs); |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY); |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | vl_api_qos_egress_map_update_t_handler (vl_api_qos_egress_map_update_t * mp) |
| 98 | { |
| 99 | vl_api_qos_egress_map_update_reply_t *rmp; |
| 100 | qos_source_t qs; |
| 101 | int rv = 0; |
| 102 | |
| 103 | FOR_EACH_QOS_SOURCE (qs) |
| 104 | { |
| 105 | qos_egress_map_update (ntohl (mp->map_id), qs, &mp->rows[qs].outputs[0]); |
| 106 | } |
| 107 | |
| 108 | REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY); |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | vl_api_qos_egress_map_delete_t_handler (vl_api_qos_egress_map_delete_t * mp) |
| 113 | { |
| 114 | vl_api_qos_egress_map_delete_reply_t *rmp; |
| 115 | int rv = 0; |
| 116 | |
| 117 | qos_egress_map_delete (ntohl (mp->map_id)); |
| 118 | |
| 119 | REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | vl_api_qos_mark_enable_disable_t_handler |
| 124 | (vl_api_qos_mark_enable_disable_t * mp) |
| 125 | { |
| 126 | vl_api_qos_mark_enable_disable_reply_t *rmp; |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 127 | qos_source_t qs; |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 128 | int rv = 0; |
| 129 | |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 130 | rv = qos_source_decode (mp->output_source, &qs); |
| 131 | |
| 132 | if (0 == rv) |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 133 | { |
| 134 | if (mp->enable) |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 135 | rv = |
| 136 | qos_mark_enable (ntohl (mp->sw_if_index), qs, ntohl (mp->map_id)); |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 137 | else |
Neale Ranns | ed234e7 | 2018-09-05 09:36:05 -0700 | [diff] [blame] | 138 | rv = qos_mark_disable (ntohl (mp->sw_if_index), qs); |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY); |
| 142 | } |
| 143 | |
| 144 | #define vl_msg_name_crc_list |
| 145 | #include <vnet/qos/qos.api.h> |
| 146 | #undef vl_msg_name_crc_list |
| 147 | |
| 148 | static void |
| 149 | setup_message_id_table (api_main_t * am) |
| 150 | { |
| 151 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 152 | foreach_vl_msg_name_crc_qos; |
| 153 | #undef _ |
| 154 | } |
| 155 | |
| 156 | static clib_error_t * |
| 157 | qos_api_hookup (vlib_main_t * vm) |
| 158 | { |
| 159 | api_main_t *am = &api_main; |
| 160 | |
| 161 | #define _(N,n) \ |
| 162 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 163 | vl_api_##n##_t_handler, \ |
| 164 | vl_noop_handler, \ |
| 165 | vl_api_##n##_t_endian, \ |
| 166 | vl_api_##n##_t_print, \ |
| 167 | sizeof(vl_api_##n##_t), 1); |
| 168 | foreach_qos_api_msg; |
| 169 | #undef _ |
| 170 | |
| 171 | /* |
| 172 | * Set up the (msg_name, crc, message-id) table |
| 173 | */ |
| 174 | setup_message_id_table (am); |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | VLIB_API_INIT_FUNCTION (qos_api_hookup); |
| 180 | |
| 181 | /* |
| 182 | * fd.io coding-style-patch-verification: ON |
| 183 | * |
| 184 | * Local Variables: |
| 185 | * eval: (c-set-style "gnu") |
| 186 | * End: |
| 187 | */ |