19cd2d7a5SSteven/*
29cd2d7a5SSteven * lacp VAT support
39cd2d7a5SSteven *
49cd2d7a5SSteven * Copyright (c) 2017 Cisco and/or its affiliates.
59cd2d7a5SSteven * Licensed under the Apache License, Version 2.0 (the "License");
69cd2d7a5SSteven * you may not use this file except in compliance with the License.
79cd2d7a5SSteven * You may obtain a copy of the License at:
89cd2d7a5SSteven *
99cd2d7a5SSteven *     http://www.apache.org/licenses/LICENSE-2.0
109cd2d7a5SSteven *
119cd2d7a5SSteven * Unless required by applicable law or agreed to in writing, software
129cd2d7a5SSteven * distributed under the License is distributed on an "AS IS" BASIS,
139cd2d7a5SSteven * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
149cd2d7a5SSteven * See the License for the specific language governing permissions and
159cd2d7a5SSteven * limitations under the License.
169cd2d7a5SSteven */
179cd2d7a5SSteven
189cd2d7a5SSteven#include <inttypes.h>
199cd2d7a5SSteven
209cd2d7a5SSteven#include <vat/vat.h>
219cd2d7a5SSteven#include <vlibapi/api.h>
229cd2d7a5SSteven#include <vlibmemory/api.h>
239cd2d7a5SSteven
249cd2d7a5SSteven#include <vppinfra/error.h>
259cd2d7a5SSteven#include <lacp/node.h>
269cd2d7a5SSteven
279cd2d7a5SSteven#define __plugin_msg_base lacp_test_main.msg_id_base
289cd2d7a5SSteven#include <vlibapi/vat_helper_macros.h>
299cd2d7a5SSteven
309cd2d7a5SSteven/* declare message IDs */
31ebef4a9eSOle Troan#include <vnet/format_fns.h>
324540b2f8SOle Troan#include <lacp/lacp.api_enum.h>
334540b2f8SOle Troan#include <lacp/lacp.api_types.h>
344540b2f8SOle Troan#include <vpp/api/vpe.api_types.h>
359cd2d7a5SSteven
369cd2d7a5SSteventypedef struct
379cd2d7a5SSteven{
389cd2d7a5SSteven  /* API message ID base */
399cd2d7a5SSteven  u16 msg_id_base;
409cd2d7a5SSteven  u32 ping_id;
419cd2d7a5SSteven  vat_main_t *vat_main;
429cd2d7a5SSteven} lacp_test_main_t;
439cd2d7a5SSteven
449cd2d7a5SStevenlacp_test_main_t lacp_test_main;
459cd2d7a5SSteven
469cd2d7a5SSteven/* lacp-dump API */
479cd2d7a5SStevenstatic void vl_api_sw_interface_lacp_details_t_handler
489cd2d7a5SSteven  (vl_api_sw_interface_lacp_details_t * mp)
499cd2d7a5SSteven{
509cd2d7a5SSteven  vat_main_t *vam = &vat_main;
519cd2d7a5SSteven
529cd2d7a5SSteven  fformat (vam->ofp,
539cd2d7a5SSteven	   "%-25s %-12d %-16s %3x %3x %3x %3x %3x %3x %3x %3x "
549cd2d7a5SSteven	   "%4x %3x %3x %3x %3x %3x %3x %3x\n",
559cd2d7a5SSteven	   mp->interface_name, ntohl (mp->sw_if_index),
569cd2d7a5SSteven	   mp->bond_interface_name,
579cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 7),
589cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 6),
599cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 5),
609cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 4),
619cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 3),
629cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 2),
639cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 1),
649cd2d7a5SSteven	   lacp_bit_test (mp->actor_state, 0),
659cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 7),
669cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 6),
679cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 5),
689cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 4),
699cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 3),
709cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 2),
719cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 1),
729cd2d7a5SSteven	   lacp_bit_test (mp->partner_state, 0));
739cd2d7a5SSteven  fformat (vam->ofp,
749cd2d7a5SSteven	   "  LAG ID: [(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x), "
759cd2d7a5SSteven	   "(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x)]\n",
769cd2d7a5SSteven	   ntohs (mp->actor_system_priority), mp->actor_system[0],
779cd2d7a5SSteven	   mp->actor_system[1], mp->actor_system[2], mp->actor_system[3],
789cd2d7a5SSteven	   mp->actor_system[4], mp->actor_system[5], ntohs (mp->actor_key),
799cd2d7a5SSteven	   ntohs (mp->actor_port_priority), ntohs (mp->actor_port_number),
809cd2d7a5SSteven	   ntohs (mp->partner_system_priority), mp->partner_system[0],
819cd2d7a5SSteven	   mp->partner_system[1], mp->partner_system[2],
829cd2d7a5SSteven	   mp->partner_system[3], mp->partner_system[4],
839cd2d7a5SSteven	   mp->partner_system[5], ntohs (mp->partner_key),
849cd2d7a5SSteven	   ntohs (mp->partner_port_priority),
859cd2d7a5SSteven	   ntohs (mp->partner_port_number));
869cd2d7a5SSteven  fformat (vam->ofp,
879cd2d7a5SSteven	   "  RX-state: %U, TX-state: %U, MUX-state: %U, PTX-state: %U\n",
889cd2d7a5SSteven	   format_rx_sm_state, ntohl (mp->rx_state), format_tx_sm_state,
899cd2d7a5SSteven	   ntohl (mp->tx_state), format_mux_sm_state, ntohl (mp->mux_state),
909cd2d7a5SSteven	   format_ptx_sm_state, ntohl (mp->ptx_state));
919cd2d7a5SSteven}
929cd2d7a5SSteven
939cd2d7a5SStevenstatic int
949cd2d7a5SStevenapi_sw_interface_lacp_dump (vat_main_t * vam)
959cd2d7a5SSteven{
969cd2d7a5SSteven  lacp_test_main_t *lm = &lacp_test_main;
979cd2d7a5SSteven  vl_api_sw_interface_lacp_dump_t *mp;
989cd2d7a5SSteven  vl_api_control_ping_t *mp_ping;
999cd2d7a5SSteven  int ret;
1009cd2d7a5SSteven
1019cd2d7a5SSteven  if (vam->json_output)
1029cd2d7a5SSteven    {
1039cd2d7a5SSteven      clib_warning ("JSON output not supported for sw_interface_lacp_dump");
1049cd2d7a5SSteven      return -99;
1059cd2d7a5SSteven    }
1069cd2d7a5SSteven
1079cd2d7a5SSteven  fformat (vam->ofp, "%-55s %-32s %-32s\n", " ", "actor state",
1089cd2d7a5SSteven	   "partner state");
1099cd2d7a5SSteven  fformat (vam->ofp, "%-25s %-12s %-16s %-31s  %-31s\n", "interface name",
1109cd2d7a5SSteven	   "sw_if_index", "bond interface", "exp/def/dis/col/syn/agg/tim/act",
1119cd2d7a5SSteven	   "exp/def/dis/col/syn/agg/tim/act");
1129cd2d7a5SSteven
1139cd2d7a5SSteven  /* Get list of lacp interfaces */
1149cd2d7a5SSteven  M (SW_INTERFACE_LACP_DUMP, mp);
1159cd2d7a5SSteven  S (mp);
1169cd2d7a5SSteven
1179cd2d7a5SSteven  /* Use a control ping for synchronization */
1183f2d5718SOle Troan  if (!lm->ping_id)
1193f2d5718SOle Troan    lm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
1209cd2d7a5SSteven  mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
1219cd2d7a5SSteven  mp_ping->_vl_msg_id = htons (lm->ping_id);
1229cd2d7a5SSteven  mp_ping->client_index = vam->my_client_index;
1239cd2d7a5SSteven
1249cd2d7a5SSteven  fformat (vam->ofp, "Sending ping id=%d\n", lm->ping_id);
1259cd2d7a5SSteven
1269cd2d7a5SSteven  vam->result_ready = 0;
1279cd2d7a5SSteven  S (mp_ping);
1289cd2d7a5SSteven
1299cd2d7a5SSteven  W (ret);
1309cd2d7a5SSteven  return ret;
1319cd2d7a5SSteven}
1329cd2d7a5SSteven
1334540b2f8SOle Troan#include <lacp/lacp.api_test.c>
1349cd2d7a5SSteven
1359cd2d7a5SSteven/*
1369cd2d7a5SSteven * fd.io coding-style-patch-verification: ON
1379cd2d7a5SSteven *
1389cd2d7a5SSteven * Local Variables:
1399cd2d7a5SSteven * eval: (c-set-style "gnu")
1409cd2d7a5SSteven * End:
1419cd2d7a5SSteven */
142