LCOV - code coverage report
Current view: top level - app/shared_dev/commands/pktgen - fd_pktgen_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 46 0.0 %
Date: 2026-11-26 02:16:43 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* fd_pktgen_tile floods a net tile with outgoing packets.
       2             : 
       3             :    Each packet is an Ethernet frame whose L3 header + payload is pkt_sz
       4             :    bytes (a minimum size Ethernet frame by default). An invalid ip4 hdr
       5             :    is used to avoid leaking the flood out to the Internet.
       6             : 
       7             :    Each packet contains a 64 bit sequence number such that each
       8             :    payload is different.  Experiments revealed that some NICs stop
       9             :    sending if we send the same payload over and over again
      10             :    (probably protection against a buggy driver melting the network). */
      11             : 
      12             : #include "../../../../disco/topo/fd_topo.h"
      13             : #include "../../../../util/net/fd_eth.h"
      14             : 
      15             : extern uint fd_pktgen_active;
      16             : uint fd_pktgen_active = 0U;
      17             : 
      18             : struct fd_pktgen_tile_ctx {
      19             :   void * out_base;
      20             :   ulong  chunk0;
      21             :   ulong  wmark;
      22             :   ulong  chunk;
      23             :   ulong  tag;
      24             :   ulong  pkt_sz; /* size of the L3 header + payload */
      25             :   uint   fake_dst_ip;
      26             : };
      27             : 
      28             : typedef struct fd_pktgen_tile_ctx fd_pktgen_tile_ctx_t;
      29             : 
      30             : FD_FN_CONST static inline ulong
      31           0 : scratch_align( void ) {
      32           0 :   return alignof(fd_pktgen_tile_ctx_t);
      33           0 : }
      34             : 
      35             : FD_FN_PURE static inline ulong
      36           0 : scratch_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
      37           0 :   return sizeof(fd_pktgen_tile_ctx_t);
      38           0 : }
      39             : 
      40             : static void
      41             : unprivileged_init( fd_topo_t const *      topo,
      42           0 :                    fd_topo_tile_t const * tile ) {
      43           0 :   fd_pktgen_tile_ctx_t * ctx = fd_topo_obj_laddr( topo, tile->tile_obj_id );
      44           0 :   FD_TEST( tile->out_cnt==1UL );
      45           0 :   void * out_base   = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ 0 ] ].dcache_obj_id ].wksp_id ].wksp;
      46           0 :   void * out_dcache = topo->links[ tile->out_link_id[ 0 ] ].dcache;
      47           0 :   ctx->out_base    = out_base;
      48           0 :   ctx->chunk0      = fd_dcache_compact_chunk0( out_base, out_dcache );
      49           0 :   ctx->wmark       = fd_dcache_compact_wmark( out_base, out_dcache, FD_NET_MTU );
      50           0 :   ctx->chunk       = ctx->chunk0;
      51           0 :   ctx->tag         = 0UL;
      52           0 :   ctx->fake_dst_ip = tile->pktgen.fake_dst_ip;
      53           0 :   ctx->pkt_sz      = tile->pktgen.pkt_sz;
      54             : 
      55             :   /* L3 header + payload must hold the ip4 hdr and the seq number, and
      56             :      the full frame must not exceed the net tile's max Ethernet frame
      57             :      size (see fd_net_in_frag_validate) */
      58           0 :   FD_TEST( ctx->pkt_sz>=sizeof(fd_ip4_hdr_t)+sizeof(ulong) );
      59           0 :   FD_TEST( sizeof(fd_eth_hdr_t)+ctx->pkt_sz<=FD_ETH_PAYLOAD_MAX );
      60             : 
      61             :   /* Assume dcache was zero initialized */
      62           0 : }
      63             : 
      64             : static void
      65             : after_credit( fd_pktgen_tile_ctx_t * ctx,
      66             :               fd_stem_context_t *    stem,
      67             :               int *                  opt_poll_in,
      68           0 :               int *                  charge_busy ) {
      69           0 :   if( FD_VOLATILE_CONST( fd_pktgen_active )!=1U ) return;
      70             : 
      71           0 :   *charge_busy = 1;
      72           0 :   *opt_poll_in = 0;
      73             : 
      74             :   /* Select an arbitrary public IP as the fake destination.  The outgoing
      75             :      packet has an an invalid ip header, so it will not reach that
      76             :      destination. The net tile, however, needs a valid dst IP to select
      77             :      the dst MAC address. */
      78           0 :   ulong sig = fd_disco_netmux_sig( 0U, 0U, ctx->fake_dst_ip, DST_PROTO_OUTGOING, FD_NETMUX_SIG_MIN_HDR_SZ );
      79             : 
      80             :   /* Send an Ethernet frame */
      81           0 :   ulong          chunk = ctx->chunk;
      82           0 :   uchar *        frame = fd_chunk_to_laddr( ctx->out_base, chunk );
      83           0 :   fd_eth_hdr_t * eth   = (fd_eth_hdr_t *)frame;
      84           0 :   fd_ip4_hdr_t * ip4   = (fd_ip4_hdr_t *)(eth+1);
      85           0 :   ulong          tag   = ctx->tag;
      86           0 :   ulong          sz    = sizeof(fd_eth_hdr_t) + ctx->pkt_sz;
      87           0 :   eth->net_type        = fd_ushort_bswap( FD_ETH_HDR_TYPE_IP );
      88           0 :   ip4->verihl          = FD_IP4_VERIHL( 4, 5 );
      89             :   /* Routing over the socket fallback requires a correct daddr */
      90           0 :   ip4->daddr           = ctx->fake_dst_ip;
      91           0 :   ip4->protocol         = FD_IP4_HDR_PROTOCOL_UDP;
      92           0 :   FD_STORE( ulong, ip4+1, tag ); /* Unique seq number */
      93           0 :   fd_stem_publish( stem, 0UL, sig, chunk, sz, 0UL, 0UL, 0UL );
      94             : 
      95             :   /* Wind up for next iteration */
      96           0 :   ctx->chunk = fd_dcache_compact_next( chunk, sz, ctx->chunk0, ctx->wmark );
      97           0 :   ctx->tag   = tag+1UL;
      98           0 : }
      99             : 
     100           0 : #define STEM_BURST (1UL)
     101             : 
     102           0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_pktgen_tile_ctx_t
     103           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_pktgen_tile_ctx_t)
     104             : 
     105           0 : #define STEM_CALLBACK_AFTER_CREDIT after_credit
     106             : 
     107           0 : #define STEM_LAZY ((ulong)384e3) /* 384us, same as shred tile */
     108             : 
     109             : #include "../../../../disco/stem/fd_stem.c"
     110             : 
     111             : fd_topo_run_tile_t fd_tile_pktgen = {
     112             :   .name              = "pktgen",
     113             :   .scratch_align     = scratch_align,
     114             :   .scratch_footprint = scratch_footprint,
     115             :   .unprivileged_init = unprivileged_init,
     116             :   .run               = stem_run
     117             : };

Generated by: LCOV version 1.14