/* *------------------------------------------------------------------ * Copyright (c) 2018 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include static clib_error_t * vmxnet3_create_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; vmxnet3_create_if_args_t args; u32 size; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; clib_memset (&args, 0, sizeof (args)); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr)) ; else if (unformat (line_input, "gso")) args.enable_gso = 1; else if (unformat (line_input, "elog")) args.enable_elog = 1; else if (unformat (line_input, "bind")) args.bind = 1; else if (unformat (line_input, "rx-queue-size %u", &size)) args.rxq_size = size; else if (unformat (line_input, "tx-queue-size %u", &size)) args.txq_size = size; else if (unformat (line_input, "num-tx-queues %u", &size)) args.txq_num = size; else if (unformat (line_input, "num-rx-queues %u", &size)) args.rxq_num = size; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); vmxnet3_create_if (vm, &args); return args.error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (vmxnet3_create_command, static) = { .path = "create interface vmxnet3", .short_help = "create interface vmxnet3 " " [rx-queue-size ] [tx-queue-size ]" " [num-tx-queues ] [num-rx-queues ] [bind]" " [gso]", .function = vmxnet3_create_command_fn, }; /* *INDENT-ON* */ static clib_error_t * vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u32 sw_if_index = ~0; vnet_hw_interface_t *hw; vmxnet3_main_t *vmxm = &vmxnet3_main; vmxnet3_device_t *vd; vnet_main_t *vnm = vnet_get_main (); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "sw_if_index %d", &sw_if_index)) ; else if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); if (sw_if_index == ~0) return clib_error_return (0, "please specify interface name or sw_if_index"); hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index); if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index) return clib_error_return (0, "not a vmxnet3 interface"); vd = pool_elt_at_index (vmxm->devices, hw->dev_instance); vmxnet3_delete_if (vm, vd); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = { .path = "delete interface vmxnet3", .short_help = "delete interface vmxnet3 " "{ | sw_if_index }", .function = vmxnet3_delete_command_fn, }; /* *INDENT-ON* */ static clib_error_t * vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u32 sw_if_index = ~0; vnet_hw_interface_t *hw; vmxnet3_main_t *vmxm = &vmxnet3_main; vmxnet3_device_t *vd; vnet_main_t *vnm = vnet_get_main (); int enable_elog = 0, disable_elog = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "sw_if_index %d", &sw_if_index)) ; else if (unformat (line_input, "elog-on")) enable_elog = 1; else if (unformat (line_input, "elog-off")) disable_elog = 1; else if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); if (sw_if_index == ~0) return clib_error_return (0, "please specify interface name or sw_if_index"); hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index); if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index) return clib_error_return (0, "not a vmxnet3 interface"); vd = pool_elt_at_index (vmxm->devices, hw->dev_instance); if (enable_elog) vd->flags |= VMXNET3_DEVICE_F_ELOG; if (disable_elog) vd->flags &= ~VMXNET3_DEVICE_F_ELOG; return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (vmxnet3_test_command, static) = { .path = "test vmxnet3", .short_help = "test vmxnet3 | sw_if_index [irq] " "[elog-on] [elog-off]", .function = vmxnet3_test_command_fn, }; /* *INDENT-ON* */ static void show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u8 show_one_table, u32 which, u8 show_one_slot, u32 slot) { u32 i, desc_idx; vmxnet3_device_t *vd; vnet_main_t *vnm = &vnet_main; vmxnet3_main_t *vmxm = &vmxnet3_main; vnet_hw_interface_t *hi; vmxnet3_rxq_t *rxq; vmxnet3_rx_desc *rxd; vmxnet3_rx_comp *rx_comp; vmxnet3_txq_t *txq; vmxnet3_tx_desc *txd; vmxnet3_tx_comp *tx_comp; u16 qid; if (!hw_if_indices) return; for (i = 0; i < vec_len (hw_if_indices); i++) { hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); vd = vec_elt_at_index (vmxm->devices, hi->dev_instance); vlib_cli_output (vm, "Interface: %U (ifindex %d)", format_vnet_hw_if_index_name, vnm, hw_if_indices[i], hw_if_indices[i]); vlib_cli_output (vm, " Version: %u", vd->version); vlib_cli_output (vm, " GSO enable: %u", vd->gso_enable); vlib_cli_output (vm, " PCI
/*
 *------------------------------------------------------------------
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#ifndef SRC_VLIBMEMORY_SOCKET_CLIENT_H_
#define SRC_VLIBMEMORY_SOCKET_CLIENT_H_

#include <vppinfra/file.h>
#include <vppinfra/time.h>
#include <vlibmemory/memory_shared.h>

typedef struct
{
  int socket_fd;
  int socket_enable;		/**< Can temporarily disable the connection
				     but still can keep it around... */
  u32 client_index;		/**< Client index allocated by VPP */

  clib_socket_t client_socket;

  u32 socket_buffer_size;
  u8 *socket_tx_buffer;
  u8 *socket_rx_buffer;
  u32 socket_tx_nbytes;
  int control_pings_outstanding;

  u8 *name;
  clib_time_t clib_time;
  ssvm_private_t memfd_segment;

  int want_shm_pthread;
} socket_client_main_t;

extern socket_client_main_t socket_client_main;

#define SOCKET_CLIENT_DEFAULT_BUFFER_SIZE 4096

int vl_socket_client_connect (char *socket_path, char *client_name,
			      u32 socket_buffer_size);
void vl_socket_client_disconnect (void);
int vl_socket_client_read (int wait);
int vl_socket_client_write (void);
void vl_socket_client_enable_disable (int enable);
void *vl_socket_client_msg_alloc (int nbytes);
int vl_socket_client_init_shm (vl_api_shm_elem_config_t * config,
			       int want_pthread);
clib_error_t *vl_socket_client_recv_fd_msg (int fds[],