/*
 * Copyright (c) 2017 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 __sock_test_h__
#define __sock_test_h__

#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#define SOCK_TEST_TOKEN_HELP           "#H"
#define SOCK_TEST_TOKEN_EXIT           "#X"
#define SOCK_TEST_TOKEN_VERBOSE        "#V"
#define SOCK_TEST_TOKEN_TXBUF_SIZE     "#T:"
#define SOCK_TEST_TOKEN_NUM_TEST_SCKTS "#I:"
#define SOCK_TEST_TOKEN_NUM_WRITES     "#N:"
#define SOCK_TEST_TOKEN_RXBUF_SIZE     "#R:"
#define SOCK_TEST_TOKEN_SHOW_CFG       "#C"
#define SOCK_TEST_TOKEN_RUN_UNI        "#U"
#define SOCK_TEST_TOKEN_RUN_BI         "#B"

#define SOCK_TEST_BANNER_STRING \
  "============================================\n"
#define SOCK_TEST_SEPARATOR_STRING \
  "  -----------------------------\n"

#define ONE_GIG                       (1024*1024*1024)
#define SOCK_TEST_SERVER_PORT         22000
#define SOCK_TEST_LOCALHOST_IPADDR    "127.0.0.1"

#define SOCK_TEST_CFG_CTRL_MAGIC      0xfeedface
#define SOCK_TEST_CFG_NUM_WRITES_DEF  1000000
#define SOCK_TEST_CFG_TXBUF_SIZE_DEF  8192
#define SOCK_TEST_CFG_RXBUF_SIZE_DEF  (64*SOCK_TEST_CFG_TXBUF_SIZE_DEF)
#define SOCK_TEST_CFG_BUF_SIZE_MIN    128
#define SOCK_TEST_CFG_MAX_TEST_SCKTS  5

#define SOCK_TEST_AF_UNIX_FILENAME    "/tmp/ldp_server_af_unix_socket"
#define SOCK_TEST_MIXED_EPOLL_DATA    "Hello, world! (over an AF_UNIX socket)"
#define SOCK_TEST_AF_UNIX_ACCEPT_DATA 0xaf0000af
#define SOCK_TEST_AF_UNIX_FD_MASK     0x00af0000

typedef enum
{
  SOCK_TEST_TYPE_NONE,
  SOCK_TEST_TYPE_ECHO,
  SOCK_TEST_TYPE_UNI,
  SOCK_TEST_TYPE_BI,
  SOCK_TEST_TYPE_EXIT,
} sock_test_t;

typedef struct  __attribute__ ((packed))
{
  uint32_t magic;
  uint32_t seq_num;
  uint32_t test;
  uint32_t ctrl_handle;
  uint32_t num_test_sockets;
  uint32_t verbose;
  uint32_t address_ip6;
  uint32_t transport_udp;
  uint64_t rxbuf_size;
  uint64_t txbuf_size;
  uint64_t num_writes;
  uint64_t total_bytes;
} sock_test_cfg_t;

typedef struct
{
  uint64_t rx_xacts;
  uint64_t rx_bytes;
  uint32_t rx_eagain;
  uint32_t rx_incomp;
  uint64_t tx_xacts;
  uint64_t tx_bytes;
  uint32_t tx_eagain;
  uint32_t tx_incomp;
  struct timespec start;
  struct timespec stop;
} sock_test_stats_t;

typedef struct
{
  int fd;
  uint32_t txbuf_size;
  char *txbuf;
  uint32_t rxbuf_size;
  char *rxbuf;
  sock_test_cfg_t cfg;
  sock_test_stats_t stats;
} sock_test_socket_t;

static inline void
sock_test_stats_accumulate (sock_test_stats_t * accum,
                            sock_test_stats_t * incr)
{
  accum->rx_xacts += incr->rx_xacts;
  accum->rx_bytes += incr->rx_bytes;
  accum->rx_eagain += incr->rx_eagain;
  accum->rx_incomp += incr->rx_incomp;
  accum->tx_xacts += incr->tx_xacts;
  accum->tx_bytes += incr->tx_bytes;
  accum->tx_eagain += incr->tx_eagain;
  accum->tx_incomp += incr->tx_incomp;
}

static inline void
sock_test_cfg_init (sock_test_cfg_t *cfg)
{
  cfg->magic = SOCK_TEST_CFG_CTRL_MAGIC;
  cfg->test = SOCK_TEST_TYPE_NONE;
  cfg->ctrl_handle = ~0;
  cfg->num_test_sockets = 1;
  cfg->verbose = 0;
  cfg->rxbuf_size = SOCK_TEST_CFG_RXBUF_SIZE_DEF;
  cfg->num_writes = SOCK_TEST_CFG_NUM_WRITES_DEF;
  cfg->txbuf_size = SOCK_TEST_CFG_TXBUF_SIZE_DEF;
  cfg->total_bytes = cfg->num_writes * cfg->txbuf_size;
}

static inline int
sock_test_cfg_verify (sock_test_cfg_t *cfg, sock_test_cfg_t *valid_cfg)
{
  /* Note: txbuf & rxbuf on server are the same buffer,
   *       so txbuf_size is not included in this check.
   */
  return ((cfg->magic == valid_cfg->magic)
          && (cfg->test == valid_cfg->test)
          && (cfg->verbose == valid_cfg->verbose)
          && (cfg->rxbuf_size == valid_cfg->rxbuf_size)
          && (cfg->num_writes == valid_cfg->num_writes)
          && (cfg->total_bytes == valid_cfg->total_bytes));
}

static inline void
sock_test_buf_alloc (sock_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf,
                     uint32_t *bufsize)
{
  uint32_t alloc_size = is_rxbuf ? cfg->rxbuf_size : cfg->txbuf_size;
  uint8_t *lb = realloc (*buf, (size_t) alloc_size);

  if (lb)
    {
      if (is_rxbuf)
        cfg->rxbuf_size = *bufsize = alloc_size;
      else
        cfg->txbuf_size = *bufsize = alloc_size;
      
      *buf = lb;
    }
  else
    {
      int errno_val = errno;
      perror ("ERROR in sock_test_buf_alloc()");
      fprintf (stderr, "SOCK_TEST: ERROR: Buffer allocation "
               "failed (errno = %d)!\n"
               "       Using buffer size %d instead of desired"
               " size (%d)\n", errno_val, *bufsize, alloc_size);
    }
}

static inline void
sock_test_socket_buf_alloc (sock_test_socket_t *socket)
{
  socket->rxbuf_size = socket->cfg.rxbuf_size;
  socket->txbuf_size = socket->cfg.txbuf_size;
  sock_test_buf_alloc (&socket->cfg, 0 /* is_rxbuf */ ,
		       (uint8_t **) &socket->txbuf, &socket->txbuf_size);
  sock_test_buf_alloc (&socket->cfg, 1 /* is_rxbuf */ ,
		       (uint8_t **) &socket->rxbuf, &socket->rxbuf_size);
}

static inline char *
sock_test_type_str (sock_test_t t)
{
  switch (t)
    {
    case SOCK_TEST_TYPE_NONE:
      return "NONE";

    case SOCK_TEST_TYPE_ECHO:
      return "ECHO";

    case SOCK_TEST_TYPE_UNI:
      return "UNI";

    case SOCK_TEST_TYPE_BI:
      return "BI";

    case SOCK_TEST_TYPE_EXIT:
      return "EXIT";

    default:
      return "Unknown";
    }
}

static inline void
sock_test_cfg_dump (sock_test_cfg_t * cfg, uint8_t is_client)
{
  char *spc = "     ";
  
  printf ("  test config (%p):\n"
          SOCK_TEST_SEPARATOR_STRING
	  "                 magic:  0x%08x\n"
	  "               seq_num:  0x%08x\n"
	  "%-5s             test:  %s (%d)\n"
	  "           ctrl handle:  %d (0x%x)\n"
	  "%-5s num test sockets:  %u (0x%08x)\n"
	  "%-5s          verbose:  %s (%d)\n"
	  "%-5s       rxbuf size:  %lu (0x%08lx)\n"
	  "%-5s       txbuf size:  %lu (0x%08lx)\n"
	  "%-5s       num writes:  %lu (0x%08lx)\n"
	  "       client tx bytes:  %lu (0x%08lx)\n"
          SOCK_TEST_SEPARATOR_STRING,
	  (void *) cfg, cfg->magic, cfg->seq_num,
          is_client && (cfg->test == SOCK_TEST_TYPE_UNI) ?
          "'"SOCK_TEST_TOKEN_RUN_UNI"'" :
          is_client && (cfg->test == SOCK_TEST_TYPE_BI) ?
           "'"SOCK_TEST_TOKEN_RUN_BI"'" : spc,
          sock_test_type_str (cfg->test), cfg->test,
          cfg->ctrl_handle, cfg->ctrl_handle,
          is_client ? "'"SOCK_TEST_TOKEN_NUM_TEST_SCKTS"'" : spc,
          cfg->num_test_sockets, cfg->num_test_sockets,
          is_client ? "'"SOCK_TEST_TOKEN_VERBOSE"'" : spc,
          cfg->verbose ? "on" : "off", cfg->verbose,
          is_client ? "'"SOCK_TEST_TOKEN_RXBUF_SIZE"'" : spc,
          cfg->rxbuf_size, cfg->rxbuf_size,
          is_client ? "'"SOCK_TEST_TOKEN_TXBUF_SIZE"'" : spc,
          cfg->txbuf_size, cfg->txbuf_size,
          is_client ? "'"SOCK_TEST_TOKEN_NUM_WRITES"'" : spc,
          cfg->num_writes, cfg->num_writes,
          cfg->total_bytes, cfg->total_bytes);
}

static inline void
sock_test_stats_dump (char * header, sock_test_stats_t * stats,
                      uint8_t show_rx, uint8_t show_tx,
                      uint8_t verbose)
{
  struct timespec diff;
  double duration, rate;
  uint64_t total_bytes;
  
  if ((stats->stop.tv_nsec - stats->start.tv_nsec) < 0)
    {
      diff.tv_sec = stats->stop.tv_sec - stats->start.tv_sec - 1;
      diff.tv_nsec = stats->stop.tv_nsec - stats->start.tv_nsec + 1000000000;
    }
  else
    {
      diff.tv_sec = stats->stop.tv_sec - stats->start.tv_sec;
      diff.tv_nsec = stats->stop.tv_nsec - stats->start.tv_nsec;
    }
  duration = (double) diff.tv_sec + (1e-9 * diff.tv_nsec);

  total_bytes = stats->tx_bytes + stats->rx_bytes;
  rate = (double) total_bytes * 8 / duration / ONE_GIG;
  printf ("\n%s: Streamed %lu bytes\n"
          "  in %lf seconds (%lf Gbps %s-duplex)!\n",
              header, total_bytes, duration, rate,
          (show_rx && show_tx) ? "full" : "half");

  if (show_tx)
    {
      printf (SOCK_TEST_SEPARATOR_STRING
              "  tx stats (0x%p):\n"
              SOCK_TEST_SEPARATOR_STRING
              "         writes:  %lu (0x%08lx)\n"
              "       tx bytes:  %lu (0x%08lx)\n"
              "      tx eagain:  %u (0x%08x)\n"
              "  tx incomplete:  %u (0x%08x)\n",
              (void *)stats, stats->tx_xacts, stats->tx_xacts,
              stats->tx_bytes, stats->tx_bytes,
              stats->tx_eagain, stats->tx_eagain,
              stats->tx_incomp, stats->tx_incomp);
    }
  if (show_rx)
    {
      printf (SOCK_TEST_SEPARATOR_STRING
              "  rx stats (0x%p):\n"
              SOCK_TEST_SEPARATOR_STRING
              "          reads:  %lu (0x%08lx)\n"
              "       rx bytes:  %lu (0x%08lx)\n"
              "      rx eagain:  %u (0x%08x)\n"
              "  rx incomplete:  %u (0x%08x)\n",
              (void *)stats, stats->rx_xacts, stats->rx_xacts,
              stats->rx_bytes, stats->rx_bytes,
              stats->rx_eagain, stats->rx_eagain,
              stats->rx_incomp, stats->rx_incomp);
    }
  if (verbose)
    printf ("   start.tv_sec:  %ld\n"
            "  start.tv_nsec:  %ld\n"
            "    stop.tv_sec:  %ld\n"
            "   stop.tv_nsec:  %ld\n",
            stats->start.tv_sec, stats->start.tv_nsec,
            stats->stop.tv_sec, stats->stop.tv_nsec);
            
  printf (SOCK_TEST_SEPARATOR_STRING);
  
#if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
  printf ("  af_unix xacts:  %lu (0x%08lx)\n",
          sock_server_main.af_unix_xacts);
          
  printf (SOCK_TEST_SEPARATOR_STRING);
#endif
}

static inline int
sock_test_read (int fd, uint8_t *buf, uint32_t nbytes,
                sock_test_stats_t *stats)
{
  int rx_bytes, errno_val;
  
  do
    {
      if (stats)
        stats->rx_xacts++;
#ifdef VCL_TEST
      rx_bytes = vppcom_session_read (fd, buf, nbytes);

      if (rx_bytes < 0)
        {
          errno = -rx_bytes;
          rx_bytes = -1;
        }
#else
      rx_bytes = read (fd, buf, nbytes);
#endif
      if (stats)
        {
          if ((rx_bytes == 0) ||
              ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
            stats->rx_eagain++;
          else if (rx_bytes < nbytes)
            stats->rx_incomp++;
        }
    }
  while ((rx_bytes == 0) ||
         ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
  
  if (rx_bytes < 0)
    {
      errno_val = errno;
      perror ("ERROR in sock_test_read()");
      fprintf (stderr, "SOCK_TEST: ERROR: socket read "
               "failed (errno = %d)!\n", errno_val);
      errno = errno_val;
    }
  else if (stats)
    stats->rx_bytes += rx_bytes;

  return (rx_bytes);
}

static inline int
sock_test_write (int fd, uint8_t *buf, uint32_t nbytes,
                 sock_test_stats_t *stats, uint32_t verbose)
{
  int tx_bytes = 0;
  int nbytes_left = nbytes;
  int rv, errno_val;

  do
    {
      if (stats)
        stats->tx_xacts++;
#ifdef VCL_TEST
      rv = vppcom_session_write (fd, buf, nbytes_left);
      if (rv < 0)
        {
          errno = -rv;
          rv = -1;
        }
#else
      rv = write (fd, buf, nbytes_left);
#endif
      if (rv < 0)
        {
          if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
            {
              if (stats)
                stats->tx_eagain++;
              continue;
            }
          else
            break;
        }
      tx_bytes += rv;
     
      if (tx_bytes != nbytes)
        {
          nbytes_left = nbytes_left - rv;
          if (stats)
            stats->tx_incomp++;
          if (verbose)
            {
              printf ("SOCK_TEST: WARNING: bytes written (%d) "
                      "!= bytes to write (%d)!\n", tx_bytes, nbytes);
            }
        }
     
    } while (tx_bytes != nbytes);

  if (tx_bytes < 0)
    {
      errno_val = errno;
      perror ("ERROR in sock_test_write()");
      fprintf (stderr, "SOCK_TEST: ERROR: socket write failed "
               "(errno = %d)!\n", errno_val);
    }
  else if (stats)
    stats->tx_bytes += tx_bytes;
  
  return (tx_bytes);
}

#endif /* __sock_test_h__ */
