blob: df862bb3647e9b8093319777dd7d7f5866ac9de8 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Warnickecb9cada2015-12-08 15:45:58 -070024#include <vppinfra/error.h>
Dave Barach2d6b2d62017-01-25 16:32:08 -050025
26#define __plugin_msg_base sample_test_main.msg_id_base
Dave Barachfe6bdfd2017-01-20 19:50:09 -050027#include <vlibapi/vat_helper_macros.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070028
29uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
30
31/* Declare message IDs */
Ole Troan2a1ca782019-09-19 01:08:30 +020032#include <sample/sample.api_enum.h>
33#include <sample/sample.api_types.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070034
35typedef struct {
36 /* API message ID base */
37 u16 msg_id_base;
38 vat_main_t *vat_main;
39} sample_test_main_t;
40
41sample_test_main_t sample_test_main;
42
Ed Warnickecb9cada2015-12-08 15:45:58 -070043static int api_sample_macswap_enable_disable (vat_main_t * vam)
44{
Ed Warnickecb9cada2015-12-08 15:45:58 -070045 unformat_input_t * i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070046 int enable_disable = 1;
47 u32 sw_if_index = ~0;
48 vl_api_sample_macswap_enable_disable_t * mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060049 int ret;
Ed Warnickecb9cada2015-12-08 15:45:58 -070050
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 Barach21a43842019-07-09 10:04:18 -040062
Ed Warnickecb9cada2015-12-08 15:45:58 -070063 if (sw_if_index == ~0) {
64 errmsg ("missing interface name / explicit sw_if_index number \n");
65 return -99;
66 }
Dave Barach21a43842019-07-09 10:04:18 -040067
Ed Warnickecb9cada2015-12-08 15:45:58 -070068 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060069 M(SAMPLE_MACSWAP_ENABLE_DISABLE, mp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 mp->sw_if_index = ntohl (sw_if_index);
71 mp->enable_disable = enable_disable;
72
73 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060074 S(mp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070075
76 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060077 W (ret);
78 return ret;
Ed Warnickecb9cada2015-12-08 15:45:58 -070079}
80
Dave Barach21a43842019-07-09 10:04:18 -040081/*
Ed Warnickecb9cada2015-12-08 15:45:58 -070082 * List of messages that the api test plugin sends,
83 * and that the data plane plugin processes
84 */
Ole Troan2a1ca782019-09-19 01:08:30 +020085#include <sample/sample.api_test.c>