Line data Source code
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 */
44 : #include <vnet/arp/arp.api_enum.h>
45 : #include <vnet/arp/arp.api_types.h>
46 : #include <vlibmemory/vlib.api_types.h>
47 :
48 : static int
49 0 : api_proxy_arp_dump (vat_main_t * vam)
50 : {
51 0 : return -1;
52 : }
53 :
54 : static int
55 0 : api_proxy_arp_intfc_dump (vat_main_t * vam)
56 : {
57 0 : return -1;
58 : }
59 :
60 : static void
61 0 : vl_api_proxy_arp_details_t_handler (vl_api_proxy_arp_details_t * mp)
62 : {
63 0 : }
64 :
65 : static void
66 0 : vl_api_proxy_arp_intfc_details_t_handler (vl_api_proxy_arp_intfc_details_t *
67 : mp)
68 : {
69 0 : }
70 :
71 : static int
72 0 : api_proxy_arp_add_del (vat_main_t * vam)
73 : {
74 0 : unformat_input_t *i = vam->input;
75 : vl_api_proxy_arp_add_del_t *mp;
76 0 : u32 vrf_id = 0;
77 0 : u8 is_add = 1;
78 : vl_api_ip4_address_t lo, hi;
79 0 : u8 range_set = 0;
80 : int ret;
81 :
82 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
83 : {
84 0 : if (unformat (i, "vrf %d", &vrf_id))
85 : ;
86 0 : else if (unformat (i, "%U - %U", unformat_vl_api_ip4_address, &lo,
87 : unformat_vl_api_ip4_address, &hi))
88 0 : range_set = 1;
89 0 : else if (unformat (i, "del"))
90 0 : is_add = 0;
91 : else
92 : {
93 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
94 0 : return -99;
95 : }
96 : }
97 :
98 0 : if (range_set == 0)
99 : {
100 0 : errmsg ("address range not set");
101 0 : return -99;
102 : }
103 :
104 0 : M (PROXY_ARP_ADD_DEL, mp);
105 :
106 0 : mp->proxy.table_id = ntohl (vrf_id);
107 0 : mp->is_add = is_add;
108 0 : clib_memcpy (mp->proxy.low, &lo, sizeof (lo));
109 0 : clib_memcpy (mp->proxy.hi, &hi, sizeof (hi));
110 :
111 0 : S (mp);
112 0 : W (ret);
113 0 : return ret;
114 : }
115 :
116 : static int
117 0 : api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
118 : {
119 0 : unformat_input_t *i = vam->input;
120 : vl_api_proxy_arp_intfc_enable_disable_t *mp;
121 : u32 sw_if_index;
122 0 : u8 enable = 1;
123 0 : u8 sw_if_index_set = 0;
124 : int ret;
125 :
126 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
127 : {
128 0 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
129 0 : sw_if_index_set = 1;
130 0 : else if (unformat (i, "sw_if_index %d", &sw_if_index))
131 0 : sw_if_index_set = 1;
132 0 : else if (unformat (i, "enable"))
133 0 : enable = 1;
134 0 : else if (unformat (i, "disable"))
135 0 : enable = 0;
136 : else
137 : {
138 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
139 0 : return -99;
140 : }
141 : }
142 :
143 0 : if (sw_if_index_set == 0)
144 : {
145 0 : errmsg ("missing interface name or sw_if_index");
146 0 : return -99;
147 : }
148 :
149 0 : M (PROXY_ARP_INTFC_ENABLE_DISABLE, mp);
150 :
151 0 : mp->sw_if_index = ntohl (sw_if_index);
152 0 : mp->enable = enable;
153 :
154 0 : S (mp);
155 0 : W (ret);
156 0 : return ret;
157 : }
158 :
159 : #include <vnet/arp/arp.api_test.c>
160 :
161 : /*
162 : * fd.io coding-style-patch-verification: ON
163 : *
164 : * Local Variables:
165 : * eval: (c-set-style "gnu")
166 : * End:
167 : */
|