Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * arp_test.c |
| 4 | * |
| 5 | * Copyright (c) 2019 Cisco and/or its affiliates. |
| 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 | */ |
| 19 | |
| 20 | #include <vat/vat.h> |
| 21 | #include <vlibapi/api.h> |
| 22 | #include <vlibmemory/api.h> |
| 23 | #include <vppinfra/error.h> |
| 24 | |
| 25 | #include <vnet/ip/ip_format_fns.h> |
| 26 | |
| 27 | #include <vpp/api/types.h> |
| 28 | |
| 29 | typedef struct |
| 30 | { |
| 31 | /* API message ID base */ |
| 32 | u16 msg_id_base; |
| 33 | u32 ping_id; |
| 34 | vat_main_t *vat_main; |
| 35 | } arp_test_main_t; |
| 36 | |
| 37 | arp_test_main_t arp_test_main; |
| 38 | |
| 39 | #define __plugin_msg_base arp_test_main.msg_id_base |
| 40 | #include <vlibapi/vat_helper_macros.h> |
| 41 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 42 | |
| 43 | /* Declare message IDs */ |
Ole Troan | 3d81267 | 2020-09-15 10:53:34 +0200 | [diff] [blame] | 44 | #include <vnet/arp/arp.api_enum.h> |
| 45 | #include <vnet/arp/arp.api_types.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 46 | #include <vpp/api/vpe.api_types.h> |
| 47 | |
| 48 | static int |
| 49 | api_proxy_arp_dump (vat_main_t * vam) |
| 50 | { |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | static int |
| 55 | api_proxy_arp_intfc_dump (vat_main_t * vam) |
| 56 | { |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | static void |
| 61 | vl_api_proxy_arp_details_t_handler (vl_api_proxy_arp_details_t * mp) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | static void |
| 66 | vl_api_proxy_arp_intfc_details_t_handler (vl_api_proxy_arp_intfc_details_t * |
| 67 | mp) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | static int |
| 72 | api_proxy_arp_add_del (vat_main_t * vam) |
| 73 | { |
| 74 | unformat_input_t *i = vam->input; |
| 75 | vl_api_proxy_arp_add_del_t *mp; |
| 76 | u32 vrf_id = 0; |
| 77 | u8 is_add = 1; |
| 78 | vl_api_ip4_address_t lo, hi; |
| 79 | u8 range_set = 0; |
| 80 | int ret; |
| 81 | |
| 82 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 83 | { |
| 84 | if (unformat (i, "vrf %d", &vrf_id)) |
| 85 | ; |
| 86 | else if (unformat (i, "%U - %U", unformat_vl_api_ip4_address, &lo, |
| 87 | unformat_vl_api_ip4_address, &hi)) |
| 88 | range_set = 1; |
| 89 | else if (unformat (i, "del")) |
| 90 | is_add = 0; |
| 91 | else |
| 92 | { |
| 93 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 94 | return -99; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if (range_set == 0) |
| 99 | { |
| 100 | errmsg ("address range not set"); |
| 101 | return -99; |
| 102 | } |
| 103 | |
| 104 | M (PROXY_ARP_ADD_DEL, mp); |
| 105 | |
| 106 | mp->proxy.table_id = ntohl (vrf_id); |
| 107 | mp->is_add = is_add; |
| 108 | clib_memcpy (mp->proxy.low, &lo, sizeof (lo)); |
| 109 | clib_memcpy (mp->proxy.hi, &hi, sizeof (hi)); |
| 110 | |
| 111 | S (mp); |
| 112 | W (ret); |
| 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | static int |
| 117 | api_proxy_arp_intfc_enable_disable (vat_main_t * vam) |
| 118 | { |
| 119 | unformat_input_t *i = vam->input; |
| 120 | vl_api_proxy_arp_intfc_enable_disable_t *mp; |
| 121 | u32 sw_if_index; |
| 122 | u8 enable = 1; |
| 123 | u8 sw_if_index_set = 0; |
| 124 | int ret; |
| 125 | |
| 126 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 127 | { |
| 128 | if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index)) |
| 129 | sw_if_index_set = 1; |
| 130 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 131 | sw_if_index_set = 1; |
| 132 | else if (unformat (i, "enable")) |
| 133 | enable = 1; |
| 134 | else if (unformat (i, "disable")) |
| 135 | enable = 0; |
| 136 | else |
| 137 | { |
| 138 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 139 | return -99; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if (sw_if_index_set == 0) |
| 144 | { |
| 145 | errmsg ("missing interface name or sw_if_index"); |
| 146 | return -99; |
| 147 | } |
| 148 | |
| 149 | M (PROXY_ARP_INTFC_ENABLE_DISABLE, mp); |
| 150 | |
| 151 | mp->sw_if_index = ntohl (sw_if_index); |
| 152 | mp->enable = enable; |
| 153 | |
| 154 | S (mp); |
| 155 | W (ret); |
| 156 | return ret; |
| 157 | } |
| 158 | |
Ole Troan | 3d81267 | 2020-09-15 10:53:34 +0200 | [diff] [blame] | 159 | #include <vnet/arp/arp.api_test.c> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 160 | |
Ole Troan | 3d81267 | 2020-09-15 10:53:34 +0200 | [diff] [blame] | 161 | VAT_REGISTER_FEATURE_FUNCTION (vat_arp_plugin_register); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 162 | |
| 163 | /* |
| 164 | * fd.io coding-style-patch-verification: ON |
| 165 | * |
| 166 | * Local Variables: |
| 167 | * eval: (c-set-style "gnu") |
| 168 | * End: |
| 169 | */ |