LCOV - code coverage report
Current view: top level - plugins/tracedump - tracedump_test.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 4 143 2.8 %
Date: 2023-07-05 22:20:52 Functions: 1 13 7.7 %

          Line data    Source code
       1             : /*
       2             :  * tracedump.c - tracedump vpp-api-test plug-in
       3             :  *
       4             :  * Copyright (c) <current-year> <your-organization>
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at:
       8             :  *
       9             :  *     http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : #include <vat/vat.h>
      18             : #include <vlibapi/api.h>
      19             : #include <vlibmemory/api.h>
      20             : #include <vppinfra/error.h>
      21             : #include <vnet/api_errno.h>
      22             : #include <stdbool.h>
      23             : 
      24             : #define __plugin_msg_base tracedump_test_main.msg_id_base
      25             : #include <vlibapi/vat_helper_macros.h>
      26             : 
      27             : /* Declare message IDs */
      28             : #include <tracedump/tracedump.api_enum.h>
      29             : #include <tracedump/tracedump.api_types.h>
      30             : 
      31             : typedef struct
      32             : {
      33             :   /* API message ID base */
      34             :   u16 msg_id_base;
      35             :   vat_main_t *vat_main;
      36             : } tracedump_test_main_t;
      37             : 
      38             : tracedump_test_main_t tracedump_test_main;
      39             : 
      40             : 
      41             : int
      42           0 : api_trace_set_filters (vat_main_t * vam)
      43             : {
      44           0 :   unformat_input_t *i = vam->input;
      45             :   vl_api_trace_set_filters_t *mp;
      46             :   u32 flag;
      47             :   u32 count;
      48             :   u32 node_index;
      49             :   u32 classifier;
      50             : 
      51           0 :   flag = TRACE_FF_NONE;
      52           0 :   count = 50;
      53           0 :   node_index = ~0;
      54           0 :   classifier = ~0;
      55             : 
      56           0 :   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
      57             :     {
      58           0 :       if (unformat (i, "none"))
      59           0 :         flag = TRACE_FF_NONE;
      60           0 :       else if (unformat (i, "include_node %u", &node_index))
      61           0 :         flag = TRACE_FF_INCLUDE_NODE;
      62           0 :       else if (unformat (i, "exclude_node %u", &node_index))
      63           0 :         flag = TRACE_FF_EXCLUDE_NODE;
      64           0 :       else if (unformat (i, "include_classifier %u", &classifier))
      65           0 :         flag = TRACE_FF_INCLUDE_CLASSIFIER;
      66           0 :       else if (unformat (i, "exclude_classifier %u", &classifier))
      67           0 :         flag = TRACE_FF_EXCLUDE_CLASSIFIER;
      68           0 :       else if (unformat (i, "count %u", &count))
      69             :         ;
      70             :       else
      71             :         {
      72           0 :           clib_warning ("Unknown input: %U\n", format_unformat_error, i);
      73           0 :           return -99;
      74             :         }
      75             :     }
      76             : 
      77           0 :   M (TRACE_SET_FILTERS, mp);
      78           0 :   mp->flag = htonl (flag);
      79           0 :   mp->node_index = htonl (node_index);
      80           0 :   mp->count = htonl (count);
      81           0 :   mp->classifier_table_index = htonl (classifier);
      82             : 
      83           0 :   int ret = 0;
      84           0 :   S (mp);
      85           0 :   W (ret);
      86             : 
      87           0 :   return ret;
      88             : }
      89             : 
      90             : 
      91             : int
      92           0 : api_trace_capture_packets (vat_main_t * vam)
      93             : {
      94           0 :   unformat_input_t *i = vam->input;
      95             :   vl_api_trace_capture_packets_t *mp;
      96             :   u32 node_index;
      97             :   u32 max;
      98             :   bool pre_capture_clear;
      99             :   bool use_filter;
     100             :   bool verbose;
     101             : 
     102           0 :   node_index = ~0;
     103           0 :   max = 50;
     104           0 :   pre_capture_clear = use_filter = verbose = false;
     105             : 
     106           0 :   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     107             :     {
     108           0 :       if (unformat (i, "node_index %u", &node_index))
     109             :         ;
     110           0 :       else if (unformat (i, "max %u", &max))
     111             :         ;
     112           0 :       else if (unformat (i, "pre_capture_clear"))
     113           0 :         pre_capture_clear = false;
     114           0 :       else if (unformat (i, "use_filter"))
     115           0 :         use_filter = false;
     116           0 :       else if (unformat (i, "verbose"))
     117           0 :         verbose = false;
     118             :       else
     119             :         {
     120           0 :           clib_warning ("Unknown input: %U\n", format_unformat_error, i);
     121           0 :           return -99;
     122             :         }
     123             :     }
     124             : 
     125           0 :   M (TRACE_CAPTURE_PACKETS, mp);
     126           0 :   mp->node_index = htonl (node_index);
     127           0 :   mp->max_packets = htonl (max);
     128           0 :   mp->use_filter = use_filter;
     129           0 :   mp->verbose = verbose;
     130           0 :   mp->pre_capture_clear = pre_capture_clear;
     131             : 
     132           0 :   int ret = 0;
     133           0 :   S (mp);
     134           0 :   W (ret);
     135             : 
     136           0 :   return ret;
     137             : }
     138             : 
     139             : 
     140             : static void
     141           0 : vl_api_trace_details_t_handler (vl_api_trace_details_t * dmp)
     142             : {
     143             :   u32 packet_number;
     144             :   u32 thread_id, position;
     145             : 
     146           0 :   thread_id = clib_net_to_host_u32 (dmp->thread_id);
     147           0 :   position = clib_net_to_host_u32 (dmp->position);
     148           0 :   packet_number = clib_net_to_host_u32 (dmp->packet_number);
     149           0 :   fformat
     150             :     (stdout,
     151             :      "thread %d position %d more_this_thread %d more_threads %d done %d\n",
     152           0 :      thread_id, position, (u32) dmp->more_this_thread,
     153           0 :      (u32) dmp->more_threads, (u32) dmp->done);
     154           0 :   fformat (stdout, "Packet %d\n%U\n\n",
     155             :            packet_number, vl_api_format_string, (&dmp->trace_data));
     156           0 : }
     157             : 
     158             : static void
     159           0 : vl_api_trace_v2_details_t_handler (vl_api_trace_v2_details_t *dmp)
     160             : {
     161             :   u32 thread_id, position;
     162             : 
     163           0 :   thread_id = clib_net_to_host_u32 (dmp->thread_id);
     164           0 :   position = clib_net_to_host_u32 (dmp->position);
     165           0 :   fformat (stdout, "thread %d position %d more %d", thread_id, position,
     166           0 :            dmp->more);
     167           0 :   fformat (stdout, "Packet %d\n%U\n\n", position, vl_api_format_string,
     168             :            (&dmp->trace_data));
     169           0 : }
     170             : 
     171             : static void
     172           0 : vl_api_trace_dump_reply_t_handler (vl_api_trace_dump_reply_t * rmp)
     173             : {
     174           0 :   tracedump_test_main_t *ttm = &tracedump_test_main;
     175           0 :   vat_main_t *vam = ttm->vat_main;
     176             :   vl_api_trace_dump_t *mp;
     177           0 :   i32 retval = (i32) clib_net_to_host_u32 (rmp->retval);
     178             :   u32 thread_id, position;
     179             : 
     180           0 :   if (retval != 0 || rmp->done)
     181             :     {
     182           0 :       vam->result_ready = 1;
     183           0 :       vam->retval = retval;
     184             : 
     185             :       /* Clear the cache */
     186           0 :       if (retval == 0 && rmp->flush_only == 0)
     187             :         {
     188           0 :           M (TRACE_DUMP, mp);
     189           0 :           mp->clear_cache = 1;
     190           0 :           mp->thread_id = 0xFFFFFFFF;
     191           0 :           mp->position = 0xFFFFFFFF;
     192           0 :           S (mp);
     193             :         }
     194           0 :       return;
     195             :     }
     196             : 
     197             :   /* Figure out where the next batch starts */
     198           0 :   thread_id = clib_host_to_net_u32 (rmp->last_thread_id);
     199           0 :   position = clib_host_to_net_u32 (rmp->last_position);
     200             : 
     201           0 :   if (rmp->more_threads)
     202             :     {
     203           0 :       position = 0;
     204           0 :       thread_id++;
     205             :     }
     206             :   else
     207           0 :     position++;
     208             : 
     209           0 :   M (TRACE_DUMP, mp);
     210           0 :   mp->clear_cache = 0;
     211           0 :   mp->thread_id = clib_host_to_net_u32 (thread_id);
     212           0 :   mp->position = clib_host_to_net_u32 (position);
     213           0 :   mp->max_records = clib_host_to_net_u32 (10);
     214           0 :   S (mp);
     215             : }
     216             : 
     217             : static int
     218           0 : api_trace_dump (vat_main_t *vam)
     219             : {
     220             :   vl_api_trace_dump_t *mp;
     221             :   int ret;
     222             : 
     223           0 :   M (TRACE_DUMP, mp);
     224           0 :   mp->clear_cache = 1;
     225           0 :   mp->thread_id = 0;
     226           0 :   mp->position = 0;
     227           0 :   mp->max_records = clib_host_to_net_u32 (10);
     228             : 
     229           0 :   S (mp);
     230             : 
     231           0 :   W (ret);
     232           0 :   return ret;
     233             : }
     234             : 
     235             : static int
     236           0 : api_trace_v2_dump (vat_main_t *vam)
     237             : {
     238             :   vl_api_trace_v2_dump_t *mp;
     239             :   int ret;
     240             : 
     241           0 :   M (TRACE_V2_DUMP, mp);
     242           0 :   mp->clear_cache = 1;
     243           0 :   mp->thread_id = ~0;
     244           0 :   mp->position = 0;
     245           0 :   mp->max = clib_host_to_net_u32 (10);
     246             : 
     247           0 :   S (mp);
     248             : 
     249           0 :   W (ret);
     250           0 :   return ret;
     251             : }
     252             : 
     253             : int
     254           0 : api_trace_clear_capture (vat_main_t *vam)
     255             : {
     256             :   vl_api_trace_clear_capture_t *mp;
     257             :   int ret;
     258             : 
     259           0 :   M (TRACE_CLEAR_CAPTURE, mp);
     260           0 :   S (mp);
     261           0 :   W (ret);
     262           0 :   return ret;
     263             : }
     264             : 
     265             : static int
     266           0 : api_trace_clear_cache (vat_main_t *vam)
     267             : {
     268             :   vl_api_trace_clear_capture_t *mp;
     269             :   int ret;
     270             : 
     271           0 :   M (TRACE_CLEAR_CACHE, mp);
     272           0 :   S (mp);
     273           0 :   W (ret);
     274           0 :   return ret;
     275             : }
     276             : 
     277             : static int
     278           0 : api_trace_set_filter_function (vat_main_t *vam)
     279             : {
     280             :   vl_api_trace_set_filter_function_t *mp;
     281             :   int ret;
     282             : 
     283           0 :   M (TRACE_SET_FILTER_FUNCTION, mp);
     284           0 :   S (mp);
     285           0 :   W (ret);
     286           0 :   return ret;
     287             : }
     288             : 
     289             : static int
     290           0 : api_trace_filter_function_dump (vat_main_t *vam)
     291             : {
     292             :   vl_api_trace_filter_function_dump_t *mp;
     293             :   int ret;
     294             : 
     295           0 :   M (TRACE_FILTER_FUNCTION_DUMP, mp);
     296           0 :   S (mp);
     297           0 :   W (ret);
     298           0 :   return ret;
     299             : }
     300             : 
     301             : static void
     302           0 : vl_api_trace_filter_function_details_t_handler (
     303             :   vl_api_trace_filter_function_details_t *dmp)
     304             : {
     305           0 :   fformat (stdout, "name: %U, selected: %u\n\n", vl_api_format_string,
     306           0 :            &dmp->name, dmp->selected);
     307           0 : }
     308             : 
     309             : #define vl_endianfun
     310             : #include <tracedump/tracedump.api.h>
     311             : #undef vl_endianfun
     312             : #define vl_printfun
     313             : #include <tracedump/tracedump.api.h>
     314             : #undef vl_printfun
     315             : #define vl_calcsizefun
     316             : #include <tracedump/tracedump.api.h>
     317             : #undef vl_calcsizefun
     318             : 
     319             : void
     320         559 : manual_setup_message_id_table (vat_main_t * vam)
     321             : {
     322         559 :   vl_msg_api_config (&(vl_msg_api_msg_config_t){
     323         559 :     .id = VL_API_TRACE_DETAILS + tracedump_test_main.msg_id_base,
     324             :     .name = "trace_details",
     325             :     .handler = vl_api_trace_details_t_handler,
     326             :     .endian = vl_api_trace_details_t_endian,
     327             :     .format_fn = vl_api_trace_details_t_format,
     328             :     .size = sizeof (vl_api_trace_details_t),
     329             :     .traced = 1,
     330             :     .tojson = vl_api_trace_details_t_tojson,
     331             :     .fromjson = vl_api_trace_details_t_fromjson,
     332             :     .calc_size = vl_api_trace_details_t_calc_size,
     333             :   });
     334         559 : }
     335             : 
     336             : #define VL_API_LOCAL_SETUP_MESSAGE_ID_TABLE manual_setup_message_id_table
     337             : #define VL_API_TRACE_DUMP_REPLY_T_HANDLER
     338             : 
     339             : #include <tracedump/tracedump.api_test.c>
     340             : 
     341             : /*
     342             :  * fd.io coding-style-patch-verification: ON
     343             :  *
     344             :  * Local Variables:
     345             :  * eval: (c-set-style "gnu")
     346             :  * End:
     347             :  */

Generated by: LCOV version 1.14