Line data Source code
1 : /* 2 : * adl.c - adl vpp-api-test plug-in 3 : * 4 : * Copyright (c) 2020 Cisco Systems and/or affiliates. 5 : * Licensed under the Apache License, Version 2.0 (the "License"); 6 : * you may not use this file except in compliance with the License. 7 : * You may obtain a copy of the License at: 8 : * 9 : * http://www.apache.org/licenses/LICENSE-2.0 10 : * 11 : * Unless required by applicable law or agreed to in writing, software 12 : * distributed under the License is distributed on an "AS IS" BASIS, 13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 : * See the License for the specific language governing permissions and 15 : * limitations under the License. 16 : */ 17 : #include <vat/vat.h> 18 : #include <vlibapi/api.h> 19 : #include <vlibmemory/api.h> 20 : #include <vppinfra/error.h> 21 : #include <stdbool.h> 22 : 23 : #define __plugin_msg_base adl_test_main.msg_id_base 24 : #include <vlibapi/vat_helper_macros.h> 25 : 26 : uword unformat_sw_if_index (unformat_input_t * input, va_list * args); 27 : 28 : /* Declare message IDs */ 29 : #include <adl/adl.api_enum.h> 30 : #include <adl/adl.api_types.h> 31 : 32 : typedef struct 33 : { 34 : /* API message ID base */ 35 : u16 msg_id_base; 36 : vat_main_t *vat_main; 37 : } adl_test_main_t; 38 : 39 : adl_test_main_t adl_test_main; 40 : 41 : static int 42 1 : api_adl_interface_enable_disable (vat_main_t * vam) 43 : { 44 1 : unformat_input_t *i = vam->input; 45 1 : int enable_disable = 1; 46 1 : u32 sw_if_index = ~0; 47 : vl_api_adl_interface_enable_disable_t *mp; 48 : int ret; 49 : 50 : /* Parse args required to build the message */ 51 2 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) 52 : { 53 1 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index)) 54 : ; 55 0 : else if (unformat (i, "sw_if_index %d", &sw_if_index)) 56 : ; 57 0 : else if (unformat (i, "disable")) 58 0 : enable_disable = 0; 59 : else 60 0 : break; 61 : } 62 : 63 1 : if (sw_if_index == ~0) 64 : { 65 0 : errmsg ("missing interface name / explicit sw_if_index number \n"); 66 0 : return -99; 67 : } 68 : 69 : /* Construct the API message */ 70 1 : M (ADL_INTERFACE_ENABLE_DISABLE, mp); 71 1 : mp->sw_if_index = ntohl (sw_if_index); 72 1 : mp->enable_disable = enable_disable; 73 : 74 : /* send it... */ 75 1 : S (mp); 76 : 77 : /* Wait for a reply... */ 78 49164 : W (ret); 79 1 : return ret; 80 : } 81 : 82 : static int 83 1 : api_adl_allowlist_enable_disable (vat_main_t * vam) 84 : { 85 1 : unformat_input_t *i = vam->input; 86 1 : u32 sw_if_index = ~0; 87 : vl_api_adl_allowlist_enable_disable_t *mp; 88 1 : u32 fib_id = ~0; 89 1 : int ip4 = 0; 90 1 : int ip6 = 0; 91 1 : int default_adl = 0; 92 : int ret; 93 : 94 : /* Parse args required to build the message */ 95 5 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) 96 : { 97 4 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index)) 98 : ; 99 3 : else if (unformat (i, "sw_if_index %d", &sw_if_index)) 100 : ; 101 3 : else if (unformat (i, "fib-id %d", &fib_id)) 102 : ; 103 2 : else if (unformat (i, "ip4")) 104 1 : ip4 = 1; 105 1 : else if (unformat (i, "ip6")) 106 1 : ip6 = 1; 107 0 : else if (unformat (i, "default")) 108 0 : default_adl = 1; 109 : else 110 0 : break; 111 : } 112 : 113 1 : if (sw_if_index == ~0) 114 : { 115 0 : errmsg ("missing interface name / explicit sw_if_index number \n"); 116 0 : return -99; 117 : } 118 : 119 1 : if (fib_id == ~0) 120 : { 121 0 : errmsg ("FIB id must be specified...\n"); 122 0 : return -99; 123 : } 124 : 125 : /* Construct the API message */ 126 1 : M (ADL_ALLOWLIST_ENABLE_DISABLE, mp); 127 1 : mp->sw_if_index = ntohl (sw_if_index); 128 1 : mp->fib_id = ntohl (fib_id); 129 1 : mp->ip4 = ip4; 130 1 : mp->ip6 = ip6; 131 1 : mp->default_adl = default_adl; 132 : 133 : /* send it... */ 134 1 : S (mp); 135 : 136 : /* Wait for a reply... */ 137 49120 : W (ret); 138 1 : return ret; 139 : } 140 : 141 : /* 142 : * List of messages that the adl test plugin sends, 143 : * and that the data plane plugin processes 144 : */ 145 : #include <adl/adl.api_test.c> 146 : 147 : /* 148 : * fd.io coding-style-patch-verification: ON 149 : * 150 : * Local Variables: 151 : * eval: (c-set-style "gnu") 152 : * End: 153 : */