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>
22 #include <vnet/format_fns.h>
24 #include <vnet/ip/ip_types_api.h>
26 #define __plugin_msg_base pppoe_test_main.msg_id_base
27 #include <vlibapi/vat_helper_macros.h>
30 uword unformat_ip46_address (unformat_input_t * input, va_list * args)
32 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
33 ip46_type_t type = va_arg (*args, ip46_type_t);
34 if ((type != IP46_TYPE_IP6) &&
35 unformat(input, "%U", unformat_ip4_address, &ip46->ip4)) {
36 ip46_address_mask_ip4(ip46);
38 } else if ((type != IP46_TYPE_IP4) &&
39 unformat(input, "%U", unformat_ip6_address, &ip46->ip6)) {
44 uword unformat_ip46_prefix (unformat_input_t * input, va_list * args)
46 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
47 u8 *len = va_arg (*args, u8 *);
48 ip46_type_t type = va_arg (*args, ip46_type_t);
51 if ((type != IP46_TYPE_IP6) && unformat(input, "%U/%u", unformat_ip4_address, &ip46->ip4, &l)) {
55 ip46->pad[0] = ip46->pad[1] = ip46->pad[2] = 0;
56 } else if ((type != IP46_TYPE_IP4) && unformat(input, "%U/%u", unformat_ip6_address, &ip46->ip6, &l)) {
65 /////////////////////////
67 #include <pppoe/pppoe.api_enum.h>
68 #include <pppoe/pppoe.api_types.h>
71 /* API message ID base */
76 pppoe_test_main_t pppoe_test_main;
78 static void vl_api_pppoe_add_del_session_reply_t_handler
79 (vl_api_pppoe_add_del_session_reply_t * mp)
81 vat_main_t *vam = &vat_main;
82 i32 retval = ntohl (mp->retval);
85 vam->async_errors += (retval < 0);
90 vam->sw_if_index = ntohl (mp->sw_if_index);
91 vam->result_ready = 1;
96 api_pppoe_add_del_session (vat_main_t * vam)
98 unformat_input_t *line_input = vam->input;
99 vl_api_pppoe_add_del_session_t *mp;
101 ip46_address_t client_ip;
103 u8 client_ip_set = 0;
106 u32 decap_vrf_id = 0;
107 u8 client_mac[6] = { 0 };
108 u8 client_mac_set = 0;
111 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
112 clib_memset (&client_ip, 0, sizeof client_ip);
114 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
116 if (unformat (line_input, "del"))
120 else if (unformat (line_input, "session_id %d", &session_id))
122 else if (unformat (line_input, "client-ip %U",
123 unformat_ip4_address, &client_ip.ip4))
128 else if (unformat (line_input, "client-ip %U",
129 unformat_ip6_address, &client_ip.ip6))
134 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
136 else if (unformat (line_input, "client-mac %U", unformat_ethernet_address, client_mac))
144 if (client_ip_set == 0)
146 errmsg ("session client_ip address not specified");
150 if (ipv4_set && ipv6_set)
152 errmsg ("both IPv4 and IPv6 addresses specified");
156 if (client_mac_set == 0)
158 errmsg("session client mac not specified");
162 M (PPPOE_ADD_DEL_SESSION, mp);
167 ip_address_encode(&client_ip, IP46_TYPE_IP6, &mp->client_ip);
171 ip_address_encode(&client_ip, IP46_TYPE_IP4, &mp->client_ip);
174 mp->decap_vrf_id = ntohl (decap_vrf_id);
175 mp->session_id = ntohl (session_id);
177 memcpy (mp->client_mac, client_mac, 6);
184 static void vl_api_pppoe_session_details_t_handler
185 (vl_api_pppoe_session_details_t * mp)
187 vat_main_t *vam = &vat_main;
188 ip46_address_t client_ip;
189 ip_address_decode(&mp->client_ip, &client_ip);
190 print (vam->ofp, "%11d%14d%24U%14d%14d%30U%30U",
191 ntohl (mp->sw_if_index), ntohl (mp->session_id),
192 format_ip46_address, &client_ip, IP46_TYPE_ANY,
193 ntohl (mp->encap_if_index), ntohl (mp->decap_vrf_id),
194 format_ethernet_address, mp->local_mac,
195 format_ethernet_address, mp->client_mac);
199 api_pppoe_session_dump (vat_main_t * vam)
201 unformat_input_t *i = vam->input;
202 vl_api_pppoe_session_dump_t *mp;
204 u8 sw_if_index_set = 0;
207 /* Parse args required to build the message */
208 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
210 if (unformat (i, "sw_if_index %d", &sw_if_index))
216 if (sw_if_index_set == 0)
221 if (!vam->json_output)
223 print (vam->ofp, "%11s%24s%14s%14s%14s",
224 "sw_if_index", "client_ip", "session_id",
225 "encap_if_index", "decap_fib_index",
226 "local-mac", "client-mac");
229 /* Get list of pppoe-session interfaces */
230 M (PPPOE_SESSION_DUMP, mp);
232 mp->sw_if_index = htonl (sw_if_index);
240 #include <pppoe/pppoe.api_test.c>