summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>2021-09-17 14:32:03 +0200
committerDamjan Marion <dmarion@me.com>2021-09-20 11:26:03 +0000
commit8430b8de1df1b0732beab9534a7a91fc8c7b3c7d (patch)
tree65d0d9b3c639f0b0f0c8a56215513d2ddbe7929c /src
parent41b23bc9554a134aee37b430ebf5553cc3260624 (diff)
vppinfra: format table improvements
This adds a way to define default fg, bg colors and alignement for cell tables. It also allows removing the table title by not setting it. It also removes the trailing newline, for usage inside a format("%U", format_table, ...) Type: improvement Change-Id: I27d7a04c4a919b34d0170b04e24a56831f581ea1 Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/format_table.c23
-rw-r--r--src/vppinfra/format_table.h19
2 files changed, 32 insertions, 10 deletions
diff --git a/src/vppinfra/format_table.c b/src/vppinfra/format_table.c
index 5d83f7a6abe..b698cfdcc56 100644
--- a/src/vppinfra/format_table.c
+++ b/src/vppinfra/format_table.c
@@ -126,17 +126,25 @@ format_table (u8 *s, va_list *args)
for (int i = 0; i < vec_len (t->row_sizes); i++)
table_width += t->row_sizes[i];
- s = format_text_cell (t, s, &title_cell, &default_title, table_width);
- s = format (s, "\n");
+ if (t->title)
+ {
+ table_text_attr_t *title_default;
+ title_default =
+ t->default_title.as_u32 ? &t->default_title : &default_title;
+ s = format_text_cell (t, s, &title_cell, title_default, table_width);
+ s = format (s, "\n");
+ }
for (int c = 0; c < vec_len (t->cells); c++)
{
table_text_attr_t *col_default;
if (c < t->n_header_cols)
- col_default = &default_header_col;
+ col_default = t->default_header_col.as_u32 ? &t->default_header_col :
+ &default_header_col;
else
- col_default = &default_body;
+ col_default =
+ t->default_body.as_u32 ? &t->default_body : &default_body;
for (int r = 0; r < vec_len (t->cells[c]); r++)
{
@@ -144,11 +152,14 @@ format_table (u8 *s, va_list *args)
if (r)
s = format (s, " ");
if (r < t->n_header_rows && c >= t->n_header_cols)
- row_default = &default_header_row;
+ row_default = t->default_header_row.as_u32 ?
+ &t->default_header_row :
+ &default_header_row;
s = format_text_cell (t, s, &t->cells[c][r], row_default,
t->row_sizes[r]);
}
- s = format (s, "\n");
+ if (c + 1 < vec_len (t->cells))
+ s = format (s, "\n");
}
return s;
diff --git a/src/vppinfra/format_table.h b/src/vppinfra/format_table.h
index f9b66a77c40..a6595333e0b 100644
--- a/src/vppinfra/format_table.h
+++ b/src/vppinfra/format_table.h
@@ -58,10 +58,17 @@ typedef enum
typedef struct
{
- table_text_attr_flags_t flags : 16;
- table_text_attr_color_t fg_color : 4;
- table_text_attr_color_t bg_color : 4;
- table_text_attr_align_t align : 4;
+ union
+ {
+ struct
+ {
+ table_text_attr_flags_t flags : 16;
+ table_text_attr_color_t fg_color : 4;
+ table_text_attr_color_t bg_color : 4;
+ table_text_attr_align_t align : 4;
+ };
+ u32 as_u32;
+ };
} table_text_attr_t;
typedef struct
@@ -79,6 +86,10 @@ typedef struct
int n_header_cols;
int n_header_rows;
int n_footer_cols;
+ table_text_attr_t default_title;
+ table_text_attr_t default_body;
+ table_text_attr_t default_header_col;
+ table_text_attr_t default_header_row;
} table_t;
__clib_export format_function_t format_table;
* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
# Copyright (c) 2016 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.

##############################################################################
# Find lib and include files
##############################################################################
find_path(DPDK_INCLUDE_DIR PATH_SUFFIXES dpdk NAMES rte_config.h)
find_library(DPDK_LIB NAMES libdpdk.a)

##############################################################################
# Find DPDK Version
##############################################################################
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.c
"
#include <stdio.h>
#include <rte_version.h>
int main()
{
  printf(\"VERSION=%s\\n\", strchr(rte_version(), ' ') + 1);
  printf(\"RTE_PKTMBUF_HEADROOM=%u\\n\", RTE_PKTMBUF_HEADROOM);
#ifdef RTE_LIBRTE_PMD_AESNI_MB
  printf(\"RTE_LIBRTE_PMD_AESNI_MB=%u\\n\", RTE_LIBRTE_PMD_AESNI_MB);
#endif
#ifdef RTE_LIBRTE_PMD_AESNI_GCM
  printf(\"RTE_LIBRTE_PMD_AESNI_GCM=%u\\n\", RTE_LIBRTE_PMD_AESNI_GCM);
#endif
#ifdef RTE_LIBRTE_MLX4_PMD
  printf(\"RTE_LIBRTE_MLX4_PMD=%u\\n\", RTE_LIBRTE_MLX4_PMD);
#endif
#ifdef RTE_LIBRTE_MLX5_PMD
  printf(\"RTE_LIBRTE_MLX5_PMD=%u\\n\", RTE_LIBRTE_MLX5_PMD);
#endif
  return 0;
}
")

try_compile(DPDK_VARS_COMPILED
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.c
  CMAKE_FLAGS
  -DINCLUDE_DIRECTORIES=${DPDK_INCLUDE_DIR}
  COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.bin
)

if(DPDK_VARS_COMPILED)
  execute_process(
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMAND ./dpdk_vars.bin
    OUTPUT_VARIABLE DPDK_VARS
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  string(REPLACE "\n" ";" DPDK_VARS ${DPDK_VARS})
  foreach(v ${DPDK_VARS})
    string(REPLACE "=" ";" v ${v})
    list(GET v 0 name)
    list(GET v 1 value)
    set(DPDK_${name} ${value})
  endforeach()
endif()

file(REMOVE
  ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.c
  ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.bin
)

if(NOT ${DPDK_RTE_PKTMBUF_HEADROOM} EQUAL ${PRE_DATA_SIZE})
  message(
    FATAL_ERROR
    "DPDK RTE_PKTMBUF_HEADROOM (${DPDK_RTE_PKTMBUF_HEADROOM}) "
     "must be equal to PRE_DATA_SIZE (${PRE_DATA_SIZE})"
  )
endif()

##############################################################################
# DPDK plugin
##############################################################################
if(DPDK_INCLUDE_DIR AND DPDK_LIB)
  include_directories (${DPDK_INCLUDE_DIR})

  message(STATUS "Found DPDK ${DPDK_VERSION} in ${DPDK_INCLUDE_DIR}")
  get_filename_component(DPDK_LIB_DIR ${DPDK_LIB} DIRECTORY)
  set(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR} -Wl,--whole-archive,${DPDK_LIB},--no-whole-archive")
  if(DPDK_RTE_LIBRTE_PMD_AESNI_MB OR DPDK_RTE_LIBRTE_PMD_AESNI_GCM)
    set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,--exclude-libs,libIPSec_MB.a,-l:libIPSec_MB.a")
    message(STATUS "DPDK depends on IPSec MB library")
  endif()
  if(DPDK_RTE_LIBRTE_MLX4_PMD OR DPDK_RTE_LIBRTE_MLX5_PMD)
    set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lmnl")
    message(STATUS "DPDK depends on libmnl (Mellanox PMD requirement)")
  endif()
  set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lnuma")
  add_vpp_plugin(dpdk
    SOURCES
    buffer.c
    main.c
    thread.c
    api/dpdk_api.c
    api/dpdk_test.c
    device/cli.c
    device/common.c
    device/device.c
    device/flow.c
    device/format.c
    device/init.c
    device/node.c
    hqos/hqos.c
    ipsec/cli.c
    ipsec/crypto_node.c
    ipsec/esp_decrypt.c
    ipsec/esp_encrypt.c
    ipsec/ipsec.c

    MULTIARCH_SOURCES
    buffer.c
    device/device.c
    device/node.c

    API_FILES
    api/dpdk.api

    API_TEST_SOURCES
    api/dpdk_test.c

    INSTALL_HEADERS
    device/dpdk.h
    api/dpdk_all_api_h.h
    ipsec/ipsec.h

    LINK_FLAGS
    ${DPDK_LINK_FLAGS}

    COMPONENT
    vpp-plugin-dpdk
  )
else()
  message(WARNING "DPDK not found - dpdk disabled")
endif()