Line data Source code
1 :
2 : #include "../../shared/commands/configure/configure.h"
3 : #include "../../shared/commands/run/run.h"
4 : #include "../../../disco/metrics/fd_metrics.h"
5 : #include "../../../disco/topo/fd_topob.h"
6 :
7 : #include <time.h>
8 : #include <stdio.h>
9 : #include <unistd.h>
10 :
11 : #define NAME "ipecho-server"
12 :
13 : extern fd_topo_obj_callbacks_t * CALLBACKS[];
14 :
15 : fd_topo_run_tile_t
16 : fdctl_tile_run( fd_topo_tile_t const * tile );
17 :
18 : static void
19 : ipecho_topo( fd_topo_t * topo,
20 0 : char const * name ) {
21 0 : fd_topob_new( topo, name );
22 0 : topo->max_page_size = 1UL<<21UL;
23 :
24 0 : fd_topob_wksp( topo, "all" );
25 0 : fd_topo_link_t * link = fd_topob_link( topo, "ipecho_out", "all", 4UL, 0UL, 1UL );
26 0 : link->permit_no_consumers = 1;
27 0 : fd_topo_tile_t * tile = fd_topob_tile( topo, "ipecho", "all", "all", 0UL, 0, 0, 0 );
28 0 : tile->ipecho.expected_shred_version = 32;
29 0 : tile->ipecho.entrypoints_cnt = 0UL;
30 0 : tile->ipecho.bind_address = FD_IP4_ADDR(127,0,0,1);
31 0 : tile->ipecho.bind_port = 12008;
32 0 : fd_topob_tile_out( topo, "ipecho", 0UL, "ipecho_out", 0UL );
33 :
34 0 : fd_topob_auto_layout( topo, 0 );
35 0 : fd_topob_finish( topo, CALLBACKS );
36 0 : }
37 :
38 : static void
39 0 : ipecho_server_cmd_topo( config_t * config ) {
40 0 : ipecho_topo( &config->topo, config->name );
41 0 : }
42 :
43 : static args_t
44 0 : configure_args( void ) {
45 0 : args_t args = {
46 0 : .configure.command = CONFIGURE_CMD_INIT,
47 0 : };
48 :
49 0 : ulong stage_idx = 0UL;
50 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
51 0 : args.configure.stages[ stage_idx++ ] = NULL;
52 :
53 0 : return args;
54 0 : }
55 :
56 : void
57 : ipecho_server_cmd_perm( args_t * args FD_PARAM_UNUSED,
58 : fd_cap_chk_t * chk,
59 0 : config_t const * config ) {
60 0 : args_t c_args = configure_args();
61 0 : configure_cmd_perm( &c_args, chk, config );
62 0 : run_cmd_perm( NULL, chk, config );
63 0 : }
64 :
65 : static void
66 : ipecho_server_cmd_fn( args_t * args,
67 0 : config_t * config ) {
68 0 : (void)args;
69 :
70 0 : args_t c_args = configure_args();
71 0 : configure_cmd_fn( &c_args, config );
72 :
73 0 : run_firedancer_init( config, 1, 0 );
74 :
75 0 : fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
76 0 : fd_topo_fill( &config->topo );
77 :
78 0 : ulong tile_idx1 = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
79 0 : fd_topo_tile_t * ipecho_tile1 = &config->topo.tiles[ tile_idx1 ];
80 0 : ulong volatile * const ipecho_metrics1 = fd_metrics_tile( ipecho_tile1->metrics );
81 0 : (void)ipecho_metrics1;
82 :
83 0 : fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
84 :
85 0 : ulong tile_idx = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
86 0 : FD_TEST( tile_idx!=ULONG_MAX );
87 0 : fd_topo_tile_t * ipecho_tile = &config->topo.tiles[ tile_idx ];
88 :
89 0 : sleep(1);
90 0 : ulong volatile * const ipecho_metrics = fd_metrics_tile( ipecho_tile->metrics );
91 :
92 0 : ulong last_conns = ULONG_MAX;
93 0 : ulong last_closed_ok = ULONG_MAX;
94 0 : ulong last_closed_error = ULONG_MAX;
95 :
96 0 : for(;;) {
97 0 : ulong ipecho_conns = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( GAUGE, IPECHO, CONN_ACTIVE ) ] );
98 0 : ulong ipecho_closed_ok = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONN_CLOSED_OK ) ] );
99 0 : ulong ipecho_closed_error = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONN_CLOSED_ERROR ) ] );
100 :
101 0 : if( FD_UNLIKELY( ipecho_conns!=last_conns || ipecho_closed_ok!=last_closed_ok || ipecho_closed_error!=last_closed_error ) ) {
102 0 : FD_LOG_NOTICE(( "connections=%lu closed_ok=%lu closed_err=%lu", ipecho_conns, ipecho_closed_ok, ipecho_closed_error ));
103 0 : last_conns = ipecho_conns;
104 0 : last_closed_ok = ipecho_closed_ok;
105 0 : last_closed_error = ipecho_closed_error;
106 0 : }
107 :
108 : nanosleep( &(struct timespec){ .tv_sec=0, .tv_nsec=1000L*1000L }, NULL );
109 0 : }
110 0 : }
111 :
112 : action_t fd_action_ipecho_server = {
113 : .name = NAME,
114 : .args = NULL,
115 : .perm = ipecho_server_cmd_perm,
116 : .fn = ipecho_server_cmd_fn,
117 : .topo = ipecho_server_cmd_topo,
118 : .description = "Run a standalone IP echo protocol server for testing",
119 : };
|