Line data Source code
1 : #ifndef HEADER_fd_src_disco_fd_disco_base_h 2 : #define HEADER_fd_src_disco_fd_disco_base_h 3 : 4 : #include "../tango/fd_tango.h" 5 : #include "../ballet/shred/fd_shred.h" 6 : #include "../ballet/txn/fd_txn.h" 7 : #include "../flamenco/fd_flamenco_base.h" 8 : #include "../util/wksp/fd_wksp_private.h" 9 : 10 18 : #define DST_PROTO_OUTGOING (0UL) 11 0 : #define DST_PROTO_TPU_UDP (1UL) 12 0 : #define DST_PROTO_TPU_QUIC (2UL) 13 18 : #define DST_PROTO_SHRED (3UL) 14 0 : #define DST_PROTO_REPAIR (4UL) 15 0 : #define DST_PROTO_GOSSIP (5UL) 16 0 : #define DST_PROTO_SEND (6UL) 17 0 : #define DST_PROTO_RSERVE (7UL) 18 : 19 0 : #define POH_PKT_TYPE_MICROBLOCK (0UL) 20 0 : #define POH_PKT_TYPE_BECAME_LEADER (1UL) 21 0 : #define POH_PKT_TYPE_SHRED_EPOCH_MSG (2UL) 22 0 : #define POH_PKT_TYPE_LEADER_BANK (3UL) 23 : 24 : /* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP 25 : headers that can go in or out of the net tile. 2048 is the maximum 26 : XSK entry size, so this value follows naturally. */ 27 : 28 42 : #define FD_NET_MTU (2048UL) 29 : 30 : /* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU. 31 : 32 : This is minimum MTU of IPv6 packet - IPv6 header - UDP header 33 : 1280 - 40 - 8 */ 34 : 35 0 : #define FD_TPU_MTU (1232UL) 36 : 37 : /* FD_GOSSIP_MTU is the max sz of a gossip packet which is the same as 38 : above. */ 39 : 40 0 : #define FD_GOSSIP_MTU (FD_TPU_MTU) 41 : 42 : /* FD_SHRED_STORE_MTU is the size of an fd_fec_set (statically 43 : asserted in fd_shred_tile.c). */ 44 : 45 0 : #define FD_SHRED_STORE_MTU (77888UL) 46 : 47 0 : #define FD_NETMUX_SIG_MIN_HDR_SZ (42UL) /* The default header size, which means no vlan tags and no IP options. */ 48 : 49 : /* These limits are defined here to prevent circular dependencies, and 50 : statically asserted they are calculated correctly in the relevant 51 : places. We get one bound using transactions that consume the minimum 52 : number of CUs and another bound using the minimum size transactions. 53 : The overall bound is the lower of the two. */ 54 : #define FD_MAX_TXN_PER_SLOT_CU 98039UL 55 : #define FD_MAX_TXN_PER_SLOT_SHRED 272635UL 56 24 : #define FD_MAX_TXN_PER_SLOT 98039UL 57 : FD_STATIC_ASSERT( FD_MAX_TXN_PER_SLOT<=FD_MAX_TXN_PER_SLOT_CU&&FD_MAX_TXN_PER_SLOT<=FD_MAX_TXN_PER_SLOT_SHRED, max_txn_per_slot ); 58 : FD_STATIC_ASSERT( FD_MAX_TXN_PER_SLOT>=FD_MAX_TXN_PER_SLOT_CU||FD_MAX_TXN_PER_SLOT>=FD_MAX_TXN_PER_SLOT_SHRED, max_txn_per_slot ); 59 : 60 : 61 : FD_PROTOTYPES_BEGIN 62 : 63 : /* hdr_sz is the total size of network headers, including eth, ip, udp. 64 : Ignored for outgoing packets. 65 : For incoming packets, hash_{ip_addr,port} are the source IP and port, 66 : for outgoing packets, they are the destination IP and port. */ 67 : FD_FN_CONST static inline ulong 68 : fd_disco_netmux_sig( uint hash_ip_addr, 69 : ushort hash_port, 70 : uint ip_addr, 71 : ulong proto, 72 36 : ulong hdr_sz ) { 73 : /* The size of an Ethernet header is 14+4k bytes, where 0<=k<=3 (?) is 74 : the number of vlan tags. The size of an IP header is 4j, where 75 : 5<=j<=15 is the size given in the header. The size of a UDP header 76 : is 8B. Thus, the total sum of these is 42+4i, where i=k+j-5, 77 : 0<=i<=13. Since bits are at a premium here, we compress the header 78 : size by just storing i. */ 79 36 : ulong hdr_sz_i = ((hdr_sz - 42UL)>>2)&0xFUL; 80 36 : ulong hash = 0xfffffUL & fd_ulong_hash( (ulong)hash_ip_addr | ((ulong)hash_port<<32) ); 81 36 : return (hash<<44) | ((hdr_sz_i&0xFUL)<<40UL) | ((proto&0xFFUL)<<32UL) | ((ulong)ip_addr); 82 36 : } 83 : 84 18 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hash ( ulong sig ) { return (sig>>44UL); } 85 18 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_proto( ulong sig ) { return (sig>>32UL) & 0xFFUL; } 86 18 : FD_FN_CONST static inline uint fd_disco_netmux_sig_ip ( ulong sig ) { return (uint)(sig & 0xFFFFFFFFUL); } 87 : 88 : /* fd_disco_netmux_sig_hdr_sz extracts the total size of the Ethernet, 89 : IP, and UDP headers from the netmux signature field. The UDP payload 90 : of the packet stored in the corresponding frag begins at the returned 91 : offset. */ 92 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hdr_sz( ulong sig ) { return 4UL*((sig>>40UL) & 0xFUL) + 42UL; } 93 : 94 : FD_FN_CONST static inline ulong 95 : fd_disco_poh_sig( ulong slot, 96 : ulong pkt_type, 97 0 : ulong execle_tile ) { 98 : /* The high 6 bits of the low byte of the signature field is the 99 : execle idx. Execles will filter to only handle frags with their 100 : own idx. The higher 7 bytes are the slot number. Technically, 101 : the slot number is a ulong, but it won't hit 256^7 for about 10^9 102 : years at the current rate. The lowest bits of the low byte is the 103 : packet type. */ 104 0 : return (slot << 8) | ((execle_tile & 0x3FUL) << 2) | (pkt_type & 0x3UL); 105 0 : } 106 : 107 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_pkt_type( ulong sig ) { return (sig & 0x3UL); } 108 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_slot( ulong sig ) { return (sig >> 8); } 109 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_execle_tile( ulong sig ) { return (sig >> 2) & 0x3FUL; } 110 : 111 : FD_FN_CONST static inline ulong 112 : fd_disco_execle_sig( ulong slot, 113 0 : ulong pack_idx ) { 114 0 : return (slot << 32) | pack_idx; 115 0 : } 116 : 117 0 : FD_FN_CONST static inline ulong fd_disco_execle_sig_slot( ulong sig ) { return (sig >> 32); } 118 0 : FD_FN_CONST static inline ulong fd_disco_execle_sig_pack_idx( ulong sig ) { return sig & 0xFFFFFFFFUL; } 119 : 120 : FD_FN_PURE static inline ulong 121 0 : fd_disco_compact_chunk0( void * wksp ) { 122 0 : return (((struct fd_wksp_private *)wksp)->gaddr_lo) >> FD_CHUNK_LG_SZ; 123 0 : } 124 : 125 : FD_FN_PURE static inline ulong 126 0 : fd_disco_compact_wmark( void * wksp, ulong mtu ) { 127 0 : ulong chunk_mtu = ((mtu + 2UL*FD_CHUNK_SZ-1UL) >> (1+FD_CHUNK_LG_SZ)) << 1; 128 0 : ulong wksp_hi = ((struct fd_wksp_private *)wksp)->gaddr_hi; 129 0 : return (wksp_hi >> FD_CHUNK_LG_SZ) - chunk_mtu; 130 0 : } 131 : 132 : FD_PROTOTYPES_END 133 : 134 : #endif /* HEADER_fd_src_disco_fd_disco_base_h */