Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | *------------------------------------------------------------------ |
| 17 | * sample_test.c - test harness plugin |
| 18 | *------------------------------------------------------------------ |
| 19 | */ |
| 20 | |
| 21 | #include <vat/vat.h> |
| 22 | #include <vlibapi/api.h> |
| 23 | #include <vlibmemory/api.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | #include <vppinfra/error.h> |
Dave Barach | 2d6b2d6 | 2017-01-25 16:32:08 -0500 | [diff] [blame] | 25 | |
| 26 | #define __plugin_msg_base sample_test_main.msg_id_base |
Dave Barach | fe6bdfd | 2017-01-20 19:50:09 -0500 | [diff] [blame] | 27 | #include <vlibapi/vat_helper_macros.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | |
| 29 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 30 | |
| 31 | /* Declare message IDs */ |
Ole Troan | 2a1ca78 | 2019-09-19 01:08:30 +0200 | [diff] [blame] | 32 | #include <sample/sample.api_enum.h> |
| 33 | #include <sample/sample.api_types.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | |
| 35 | typedef struct { |
| 36 | /* API message ID base */ |
| 37 | u16 msg_id_base; |
| 38 | vat_main_t *vat_main; |
| 39 | } sample_test_main_t; |
| 40 | |
| 41 | sample_test_main_t sample_test_main; |
| 42 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | static int api_sample_macswap_enable_disable (vat_main_t * vam) |
| 44 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | unformat_input_t * i = vam->input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | int enable_disable = 1; |
| 47 | u32 sw_if_index = ~0; |
| 48 | vl_api_sample_macswap_enable_disable_t * mp; |
Jon Loeliger | 56c7b01 | 2017-02-01 12:31:41 -0600 | [diff] [blame] | 49 | int ret; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
| 51 | /* Parse args required to build the message */ |
| 52 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { |
| 53 | if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index)) |
| 54 | ; |
| 55 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 56 | ; |
| 57 | else if (unformat (i, "disable")) |
| 58 | enable_disable = 0; |
| 59 | else |
| 60 | break; |
| 61 | } |
Dave Barach | 21a4384 | 2019-07-09 10:04:18 -0400 | [diff] [blame] | 62 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | if (sw_if_index == ~0) { |
| 64 | errmsg ("missing interface name / explicit sw_if_index number \n"); |
| 65 | return -99; |
| 66 | } |
Dave Barach | 21a4384 | 2019-07-09 10:04:18 -0400 | [diff] [blame] | 67 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | /* Construct the API message */ |
Jon Loeliger | 8a2aea3 | 2017-01-31 13:19:40 -0600 | [diff] [blame] | 69 | M(SAMPLE_MACSWAP_ENABLE_DISABLE, mp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | mp->sw_if_index = ntohl (sw_if_index); |
| 71 | mp->enable_disable = enable_disable; |
| 72 | |
| 73 | /* send it... */ |
Jon Loeliger | 7bc770c | 2017-01-31 14:03:33 -0600 | [diff] [blame] | 74 | S(mp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | |
| 76 | /* Wait for a reply... */ |
Jon Loeliger | 56c7b01 | 2017-02-01 12:31:41 -0600 | [diff] [blame] | 77 | W (ret); |
| 78 | return ret; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Dave Barach | 21a4384 | 2019-07-09 10:04:18 -0400 | [diff] [blame] | 81 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | * List of messages that the api test plugin sends, |
| 83 | * and that the data plane plugin processes |
| 84 | */ |
Ole Troan | 2a1ca78 | 2019-09-19 01:08:30 +0200 | [diff] [blame] | 85 | #include <sample/sample.api_test.c> |