Damjan Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * dpdk_test.c - skeleton vpp-api-test plug-in |
| 4 | * |
| 5 | * Copyright (c) <current-year> <your-organization> |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | #include <vat/vat.h> |
| 19 | #include <vlibapi/api.h> |
| 20 | #include <vlibmemory/api.h> |
Damjan Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 21 | #include <vppinfra/error.h> |
| 22 | #include <vnet/ip/ip.h> |
| 23 | |
| 24 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 25 | |
| 26 | /* Declare message IDs */ |
Ole Troan | 025166d | 2019-10-02 17:17:58 +0200 | [diff] [blame] | 27 | #include <dpdk/api/dpdk.api_enum.h> |
| 28 | #include <dpdk/api/dpdk.api_types.h> |
Damjan Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 29 | |
| 30 | typedef struct { |
| 31 | /* API message ID base */ |
| 32 | u16 msg_id_base; |
| 33 | vat_main_t *vat_main; |
| 34 | } dpdk_test_main_t; |
| 35 | |
| 36 | dpdk_test_main_t dpdk_test_main; |
| 37 | |
Damjan Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 38 | /* M: construct, but don't yet send a message */ |
| 39 | #define M(T,t) \ |
| 40 | do { \ |
| 41 | vam->result_ready = 0; \ |
| 42 | mp = vl_msg_api_alloc(sizeof(*mp)); \ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 43 | clib_memset (mp, 0, sizeof (*mp)); \ |
Damjan Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 44 | mp->_vl_msg_id = ntohs (VL_API_##T + dm->msg_id_base); \ |
| 45 | mp->client_index = vam->my_client_index; \ |
| 46 | } while(0); |
| 47 | |
| 48 | #define M2(T,t,n) \ |
| 49 | do { \ |
| 50 | vam->result_ready = 0; \ |
| 51 | mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 52 | clib_memset (mp, 0, sizeof (*mp)); \ |
Damjan Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 53 | mp->_vl_msg_id = ntohs (VL_API_##T + dm->msg_id_base); \ |
| 54 | mp->client_index = vam->my_client_index; \ |
| 55 | } while(0); |
| 56 | |
| 57 | /* S: send a message */ |
| 58 | #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp)) |
| 59 | |
| 60 | /* W: wait for results, with timeout */ |
| 61 | #define W \ |
| 62 | do { \ |
| 63 | timeout = vat_time_now (vam) + 1.0; \ |
| 64 | \ |
| 65 | while (vat_time_now (vam) < timeout) { \ |
| 66 | if (vam->result_ready == 1) { \ |
| 67 | return (vam->retval); \ |
| 68 | } \ |
| 69 | } \ |
| 70 | return -99; \ |
| 71 | } while(0); |
| 72 | |
| 73 | static int |
| 74 | api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam) |
| 75 | { |
| 76 | dpdk_test_main_t * dm = &dpdk_test_main; |
| 77 | unformat_input_t *i = vam->input; |
| 78 | vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp; |
| 79 | f64 timeout; |
| 80 | u32 sw_if_index; |
| 81 | u8 sw_if_index_set = 0; |
| 82 | u32 subport; |
| 83 | u8 subport_set = 0; |
| 84 | u32 pipe; |
| 85 | u8 pipe_set = 0; |
| 86 | u32 profile; |
| 87 | u8 profile_set = 0; |
| 88 | |
| 89 | /* Parse args required to build the message */ |
| 90 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 91 | { |
| 92 | if (unformat (i, "rx sw_if_index %u", &sw_if_index)) |
| 93 | sw_if_index_set = 1; |
| 94 | else if (unformat (i, "subport %u", &subport)) |
| 95 | subport_set = 1; |
| 96 | else if (unformat (i, "pipe %u", &pipe)) |
| 97 | pipe_set = 1; |
| 98 | else if (unformat (i, "profile %u", &profile)) |
| 99 | profile_set = 1; |
| 100 | else |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | if (sw_if_index_set == 0) |
| 105 | { |
| 106 | errmsg ("missing interface name or sw_if_index"); |
| 107 | return -99; |
| 108 | } |
| 109 | |
| 110 | if (subport_set == 0) |
| 111 | { |
| 112 | errmsg ("missing subport "); |
| 113 | return -99; |
| 114 | } |
| 115 | |
| 116 | if (pipe_set == 0) |
| 117 | { |
| 118 | errmsg ("missing pipe"); |
| 119 | return -99; |
| 120 | } |
| 121 | |
| 122 | if (profile_set == 0) |
| 123 | { |
| 124 | errmsg ("missing profile"); |
| 125 | return -99; |
| 126 | } |
| 127 | |
| 128 | M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe); |
| 129 | |
| 130 | mp->sw_if_index = ntohl (sw_if_index); |
| 131 | mp->subport = ntohl (subport); |
| 132 | mp->pipe = ntohl (pipe); |
| 133 | mp->profile = ntohl (profile); |
| 134 | |
| 135 | |
| 136 | S; |
| 137 | W; |
| 138 | /* NOTREACHED */ |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static int |
| 143 | api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam) |
| 144 | { |
| 145 | dpdk_test_main_t * dm = &dpdk_test_main; |
| 146 | unformat_input_t *i = vam->input; |
| 147 | vl_api_sw_interface_set_dpdk_hqos_subport_t *mp; |
| 148 | f64 timeout; |
| 149 | u32 sw_if_index; |
| 150 | u8 sw_if_index_set = 0; |
| 151 | u32 subport; |
| 152 | u8 subport_set = 0; |
| 153 | u32 tb_rate = 1250000000; /* 10GbE */ |
| 154 | u32 tb_size = 1000000; |
| 155 | u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 }; |
| 156 | u32 tc_period = 10; |
| 157 | |
| 158 | /* Parse args required to build the message */ |
| 159 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 160 | { |
| 161 | if (unformat (i, "rx sw_if_index %u", &sw_if_index)) |
| 162 | sw_if_index_set = 1; |
| 163 | else if (unformat (i, "subport %u", &subport)) |
| 164 | subport_set = 1; |
| 165 | else if (unformat (i, "rate %u", &tb_rate)) |
| 166 | { |
| 167 | u32 tc_id; |
| 168 | |
| 169 | for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0])); |
| 170 | tc_id++) |
| 171 | tc_rate[tc_id] = tb_rate; |
| 172 | } |
| 173 | else if (unformat (i, "bktsize %u", &tb_size)) |
| 174 | ; |
| 175 | else if (unformat (i, "tc0 %u", &tc_rate[0])) |
| 176 | ; |
| 177 | else if (unformat (i, "tc1 %u", &tc_rate[1])) |
| 178 | ; |
| 179 | else if (unformat (i, "tc2 %u", &tc_rate[2])) |
| 180 | ; |
| 181 | else if (unformat (i, "tc3 %u", &tc_rate[3])) |
| 182 | ; |
| 183 | else if (unformat (i, "period %u", &tc_period)) |
| 184 | ; |
| 185 | else |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | if (sw_if_index_set == 0) |
| 190 | { |
| 191 | errmsg ("missing interface name or sw_if_index"); |
| 192 | return -99; |
| 193 | } |
| 194 | |
| 195 | if (subport_set == 0) |
| 196 | { |
| 197 | errmsg ("missing subport "); |
| 198 | return -99; |
| 199 | } |
| 200 | |
| 201 | M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport); |
| 202 | |
| 203 | mp->sw_if_index = ntohl (sw_if_index); |
| 204 | mp->subport = ntohl (subport); |
| 205 | mp->tb_rate = ntohl (tb_rate); |
| 206 | mp->tb_size = ntohl (tb_size); |
| 207 | mp->tc_rate[0] = ntohl (tc_rate[0]); |
| 208 | mp->tc_rate[1] = ntohl (tc_rate[1]); |
| 209 | mp->tc_rate[2] = ntohl (tc_rate[2]); |
| 210 | mp->tc_rate[3] = ntohl (tc_rate[3]); |
| 211 | mp->tc_period = ntohl (tc_period); |
| 212 | |
| 213 | S; |
| 214 | W; |
| 215 | /* NOTREACHED */ |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int |
| 220 | api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam) |
| 221 | { |
| 222 | dpdk_test_main_t * dm = &dpdk_test_main; |
| 223 | unformat_input_t *i = vam->input; |
| 224 | vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp; |
| 225 | f64 timeout; |
| 226 | u32 sw_if_index; |
| 227 | u8 sw_if_index_set = 0; |
| 228 | u8 entry_set = 0; |
| 229 | u8 tc_set = 0; |
| 230 | u8 queue_set = 0; |
| 231 | u32 entry, tc, queue; |
| 232 | |
| 233 | /* Parse args required to build the message */ |
| 234 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 235 | { |
| 236 | if (unformat (i, "rx sw_if_index %u", &sw_if_index)) |
| 237 | sw_if_index_set = 1; |
| 238 | else if (unformat (i, "entry %d", &entry)) |
| 239 | entry_set = 1; |
| 240 | else if (unformat (i, "tc %d", &tc)) |
| 241 | tc_set = 1; |
| 242 | else if (unformat (i, "queue %d", &queue)) |
| 243 | queue_set = 1; |
| 244 | else |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | if (sw_if_index_set == 0) |
| 249 | { |
| 250 | errmsg ("missing interface name or sw_if_index"); |
| 251 | return -99; |
| 252 | } |
| 253 | |
| 254 | if (entry_set == 0) |
| 255 | { |
| 256 | errmsg ("missing entry "); |
| 257 | return -99; |
| 258 | } |
| 259 | |
| 260 | if (tc_set == 0) |
| 261 | { |
| 262 | errmsg ("missing traffic class "); |
| 263 | return -99; |
| 264 | } |
| 265 | |
| 266 | if (queue_set == 0) |
| 267 | { |
| 268 | errmsg ("missing queue "); |
| 269 | return -99; |
| 270 | } |
| 271 | |
| 272 | M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl); |
| 273 | |
| 274 | mp->sw_if_index = ntohl (sw_if_index); |
| 275 | mp->entry = ntohl (entry); |
| 276 | mp->tc = ntohl (tc); |
| 277 | mp->queue = ntohl (queue); |
| 278 | |
| 279 | S; |
| 280 | W; |
| 281 | /* NOTREACHED */ |
| 282 | return 0; |
| 283 | } |
| 284 | |
Ole Troan | 025166d | 2019-10-02 17:17:58 +0200 | [diff] [blame] | 285 | #include <dpdk/api/dpdk.api_test.c> |