2 * Copyright (c) 2017 Intel 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
21 #include <pppoe/pppoe.h>
23 #define __plugin_msg_base pppoe_test_main.msg_id_base
24 #include <vlibapi/vat_helper_macros.h>
27 uword unformat_ip46_address (unformat_input_t * input, va_list * args)
29 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
30 ip46_type_t type = va_arg (*args, ip46_type_t);
31 if ((type != IP46_TYPE_IP6) &&
32 unformat(input, "%U", unformat_ip4_address, &ip46->ip4)) {
33 ip46_address_mask_ip4(ip46);
35 } else if ((type != IP46_TYPE_IP4) &&
36 unformat(input, "%U", unformat_ip6_address, &ip46->ip6)) {
41 uword unformat_ip46_prefix (unformat_input_t * input, va_list * args)
43 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
44 u8 *len = va_arg (*args, u8 *);
45 ip46_type_t type = va_arg (*args, ip46_type_t);
48 if ((type != IP46_TYPE_IP6) && unformat(input, "%U/%u", unformat_ip4_address, &ip46->ip4, &l)) {
52 ip46->pad[0] = ip46->pad[1] = ip46->pad[2] = 0;
53 } else if ((type != IP46_TYPE_IP4) && unformat(input, "%U/%u", unformat_ip6_address, &ip46->ip6, &l)) {
62 /////////////////////////
64 #include <pppoe/pppoe.api_enum.h>
65 #include <pppoe/pppoe.api_types.h>
68 /* API message ID base */
73 pppoe_test_main_t pppoe_test_main;
75 static void vl_api_pppoe_add_del_session_reply_t_handler
76 (vl_api_pppoe_add_del_session_reply_t * mp)
78 vat_main_t *vam = &vat_main;
79 i32 retval = ntohl (mp->retval);
82 vam->async_errors += (retval < 0);
87 vam->sw_if_index = ntohl (mp->sw_if_index);
88 vam->result_ready = 1;
93 api_pppoe_add_del_session (vat_main_t * vam)
95 unformat_input_t *line_input = vam->input;
96 vl_api_pppoe_add_del_session_t *mp;
98 ip46_address_t client_ip;
100 u8 client_ip_set = 0;
103 u32 decap_vrf_id = 0;
104 u8 client_mac[6] = { 0 };
105 u8 client_mac_set = 0;
108 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
109 clib_memset (&client_ip, 0, sizeof client_ip);
111 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
113 if (unformat (line_input, "del"))
117 else if (unformat (line_input, "session_id %d", &session_id))
119 else if (unformat (line_input, "client-ip %U",
120 unformat_ip4_address, &client_ip.ip4))
125 else if (unformat (line_input, "client-ip %U",
126 unformat_ip6_address, &client_ip.ip6))
131 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
133 else if (unformat (line_input, "client-mac %U", unformat_ethernet_address, client_mac))
141 if (client_ip_set == 0)
143 errmsg ("session client_ip address not specified");
147 if (ipv4_set && ipv6_set)
149 errmsg ("both IPv4 and IPv6 addresses specified");
153 if (client_mac_set == 0)
155 errmsg("session client mac not specified");
159 M (PPPOE_ADD_DEL_SESSION, mp);
163 clib_memcpy (mp->client_ip, &client_ip.ip6, sizeof (client_ip.ip6));
167 clib_memcpy (mp->client_ip, &client_ip.ip4, sizeof (client_ip.ip4));
170 mp->decap_vrf_id = ntohl (decap_vrf_id);
171 mp->session_id = ntohl (session_id);
173 mp->is_ipv6 = ipv6_set;
174 memcpy (mp->client_mac, client_mac, 6);
181 static void vl_api_pppoe_session_details_t_handler
182 (vl_api_pppoe_session_details_t * mp)
184 vat_main_t *vam = &vat_main;
185 ip46_address_t client_ip = to_ip46 (mp->is_ipv6, mp->client_ip);
187 print (vam->ofp, "%11d%14d%24U%14d%14d%30U%30U",
188 ntohl (mp->sw_if_index), ntohl (mp->session_id),
189 format_ip46_address, &client_ip, IP46_TYPE_ANY,
190 ntohl (mp->encap_if_index), ntohl (mp->decap_vrf_id),
191 format_ethernet_address, mp->local_mac,
192 format_ethernet_address, mp->client_mac);
196 api_pppoe_session_dump (vat_main_t * vam)
198 unformat_input_t *i = vam->input;
199 vl_api_pppoe_session_dump_t *mp;
201 u8 sw_if_index_set = 0;
204 /* Parse args required to build the message */
205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
207 if (unformat (i, "sw_if_index %d", &sw_if_index))
213 if (sw_if_index_set == 0)
218 if (!vam->json_output)
220 print (vam->ofp, "%11s%24s%14s%14s%14s",
221 "sw_if_index", "client_ip", "session_id",
222 "encap_if_index", "decap_fib_index",
223 "local-mac", "client-mac");
226 /* Get list of pppoe-session interfaces */
227 M (PPPOE_SESSION_DUMP, mp);
229 mp->sw_if_index = htonl (sw_if_index);
237 #include <pppoe/pppoe.api_test.c>