LCOV - code coverage report
Current view: top level - app/shared_dev/commands/udpecho - udpecho.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 76 0.0 %
Date: 2026-08-14 04:54:57 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #include "../dev.h"
       2             : #include "../../../shared/commands/configure/configure.h" /* CONFIGURE_CMD_INIT */
       3             : #include "../../../shared/commands/run/run.h" /* fdctl_check_configure */
       4             : #include "../../../../disco/net/fd_net_tile.h"
       5             : #include "../../../../disco/topo/fd_topob.h"
       6             : #include "../../../../disco/topo/fd_cpu_topo.h"
       7             : #include "../../../../util/net/fd_ip4.h"
       8             : 
       9             : #include <unistd.h> /* pause */
      10             : 
      11             : extern fd_topo_obj_callbacks_t * CALLBACKS[];
      12             : 
      13             : fd_topo_run_tile_t
      14             : fdctl_tile_run( fd_topo_tile_t const * tile );
      15             : 
      16             : static void
      17           0 : udpecho_topo( config_t * config ) {
      18           0 :   char const * affinity = config->development.udpecho.affinity;
      19           0 :   int is_auto_affinity = !strcmp( affinity, "auto" );
      20             : 
      21           0 :   ushort parsed_tile_to_cpu[ FD_TILE_MAX ];
      22           0 :   for( ulong i=0UL; i<FD_TILE_MAX; i++ ) parsed_tile_to_cpu[ i ] = USHORT_MAX;
      23             : 
      24           0 :   fd_topo_cpus_t cpus[1];
      25           0 :   fd_topo_cpus_init( cpus );
      26             : 
      27           0 :   ulong affinity_tile_cnt = 0UL;
      28           0 :   if( FD_LIKELY( !is_auto_affinity ) ) affinity_tile_cnt = fd_topob_parse_affinity_cstr( affinity, parsed_tile_to_cpu, 0 );
      29             : 
      30           0 :   ulong tile_to_cpu[ FD_TILE_MAX ] = {0};
      31           0 :   for( ulong i=0UL; i<affinity_tile_cnt; i++ ) {
      32           0 :     if( FD_UNLIKELY( parsed_tile_to_cpu[ i ]!=USHORT_MAX && parsed_tile_to_cpu[ i ]>=cpus->cpu_cnt ) )
      33           0 :       FD_LOG_ERR(( "The CPU affinity string in the configuration file under [development.udpecho.affinity] specifies a CPU index of %hu, but the system "
      34           0 :                    "only has %lu CPUs. You should either change the CPU allocations in the affinity string, or increase the number of CPUs "
      35           0 :                    "in the system.",
      36           0 :                    parsed_tile_to_cpu[ i ], cpus->cpu_cnt ));
      37           0 :     tile_to_cpu[ i ] = fd_ulong_if( parsed_tile_to_cpu[ i ]==USHORT_MAX, ULONG_MAX, (ulong)parsed_tile_to_cpu[ i ] );
      38           0 :   }
      39           0 :   if( FD_LIKELY( !is_auto_affinity ) ) {
      40           0 :     if( FD_UNLIKELY( affinity_tile_cnt!=4UL ) )
      41           0 :       FD_LOG_ERR(( "Invalid [development.udpecho.affinity]: must include exactly three CPUs" ));
      42           0 :   }
      43             : 
      44             :   /* Reset topology from scratch */
      45           0 :   fd_topo_t * topo = &config->topo;
      46           0 :   fd_topob_new( &config->topo, config->name );
      47           0 :   topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
      48             : 
      49           0 :   fd_topob_wksp( topo, "metric" );
      50           0 :   fd_topob_wksp( topo, "metric_in" );
      51           0 :   fd_topos_net_tiles( topo, config->layout.net_tile_count, &config->net, config->tiles.netlink.max_routes, config->tiles.netlink.max_peer_routes, config->tiles.netlink.max_neighbors, 0, tile_to_cpu );
      52           0 :   fd_topob_tile( topo, "metric",  "metric", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0, 0 );
      53             : 
      54           0 :   fd_topob_wksp( topo, "l4swap" );
      55           0 :   fd_topob_tile( topo, "l4swap", "l4swap", "l4swap", tile_to_cpu[ topo->tile_cnt ], 0, 0, 0 );
      56             : 
      57           0 :   fd_topob_link( topo, "quic_net", "l4swap", 2048UL, FD_NET_MTU, 1UL );
      58           0 :   fd_topob_tile_out( topo, "l4swap", 0UL, "quic_net", 0UL );
      59           0 :   fd_topob_tile_in( topo, "net", 0UL, "metric_in", "quic_net", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
      60             : 
      61           0 :   fd_topos_net_rx_link( topo, "net_quic", 0UL, config->net.ingress_buffer_size );
      62           0 :   fd_topob_tile_in( topo, "l4swap", 0UL, "metric_in", "net_quic", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
      63             : 
      64           0 :   fd_topos_net_tile_finish( topo, 0UL );
      65           0 :   if( FD_UNLIKELY( is_auto_affinity ) ) fd_topob_auto_layout( topo, 0 );
      66           0 :   topo->agave_affinity_cnt = 0;
      67           0 :   fd_topob_finish( topo, CALLBACKS );
      68           0 :   fd_topo_print_log( /* stdout */ 1, topo );
      69           0 : }
      70             : 
      71             : void
      72             : udpecho_cmd_args( int *    pargc,
      73             :                  char *** pargv,
      74           0 :                  args_t * args ) {
      75           0 :   ushort port_l = fd_env_strip_cmdline_ushort( pargc, pargv, "--port", NULL, 0 );
      76           0 :   ushort port_s = fd_env_strip_cmdline_ushort( pargc, pargv, "-p",     NULL, 0 );
      77           0 :   ushort port   = port_s ? port_s : port_l;
      78           0 :   if( FD_UNLIKELY( !port ) ) FD_LOG_ERR(( "Missing --port argument" ));
      79           0 :   args->udpecho.listen_port = port;
      80           0 : }
      81             : 
      82             : void
      83             : udpecho_cmd_fn( args_t *   args,
      84           0 :                 config_t * config ) {
      85           0 :   udpecho_topo( config );
      86           0 :   fd_topo_t *      topo        = &config->topo;
      87           0 :   fd_topo_tile_t * net_tile    = &topo->tiles[ fd_topo_find_tile( topo, "net",    0UL ) ];
      88           0 :   fd_topo_tile_t * metric_tile = &topo->tiles[ fd_topo_find_tile( topo, "metric", 0UL ) ];
      89             : 
      90           0 :   net_tile->net.legacy_transaction_listen_port = args->udpecho.listen_port;
      91           0 :   config->tiles.quic.regular_transaction_listen_port = args->udpecho.listen_port;
      92             : 
      93           0 :   if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( config->tiles.metric.prometheus_listen_address, &metric_tile->metric.prometheus_listen_addr ) ) )
      94           0 :     FD_LOG_ERR(( "failed to parse prometheus listen address `%s`", config->tiles.metric.prometheus_listen_address ));
      95           0 :   metric_tile->metric.prometheus_listen_port = config->tiles.metric.prometheus_listen_port;
      96             : 
      97           0 :   configure_stage( &fd_cfg_stage_sysctl,           CONFIGURE_CMD_INIT, config );
      98           0 :   configure_stage( &fd_cfg_stage_hugetlbfs,        CONFIGURE_CMD_INIT, config );
      99           0 :   configure_stage( &fd_cfg_stage_bonding,          CONFIGURE_CMD_INIT, config );
     100           0 :   configure_stage( &fd_cfg_stage_ethtool_channels, CONFIGURE_CMD_INIT, config );
     101           0 :   configure_stage( &fd_cfg_stage_ethtool_offloads, CONFIGURE_CMD_INIT, config );
     102           0 :   configure_stage( &fd_cfg_stage_ethtool_loopback, CONFIGURE_CMD_INIT, config );
     103           0 :   configure_stage( &fd_cfg_stage_sysfs_poll,       CONFIGURE_CMD_INIT, config );
     104             : 
     105           0 :   fdctl_check_configure( config );
     106             :   /* FIXME this allocates lots of memory unnecessarily */
     107           0 :   initialize_workspaces( config );
     108           0 :   initialize_stacks( config );
     109           0 :   if( 0==strcmp( config->net.provider, "xdp" ) ) {
     110           0 :     fd_topo_install_xdp_simple( &config->topo, config->net.bind_address_parsed );
     111           0 :   }
     112           0 :   fd_topo_join_workspaces( topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
     113             : 
     114             :   /* FIXME allow running sandboxed/multiprocess */
     115           0 :   fd_topo_run_single_process( topo, 2, config->uid, config->gid, fdctl_tile_run );
     116           0 :   for(;;) pause();
     117           0 : }
     118             : 
     119             : action_t fd_action_udpecho = {
     120             :   .name        = "udpecho",
     121             :   .args        = udpecho_cmd_args,
     122             :   .fn          = udpecho_cmd_fn,
     123             :   .perm        = dev_cmd_perm,
     124             :   .description = "Run a UDP echo server"
     125             : };

Generated by: LCOV version 1.14