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/txn/fd_txn.h" 6 : 7 : #include "../util/wksp/fd_wksp_private.h" 8 : 9 0 : #define DST_PROTO_OUTGOING (0UL) 10 0 : #define DST_PROTO_TPU_UDP (1UL) 11 0 : #define DST_PROTO_TPU_QUIC (2UL) 12 0 : #define DST_PROTO_SHRED (3UL) 13 0 : #define DST_PROTO_REPAIR (4UL) 14 0 : #define DST_PROTO_GOSSIP (5UL) 15 : 16 0 : #define POH_PKT_TYPE_MICROBLOCK (0UL) 17 0 : #define POH_PKT_TYPE_BECAME_LEADER (1UL) 18 0 : #define POH_PKT_TYPE_DONE_PACKING (2UL) 19 : #define POH_PKT_REACHED_LEADER (3UL) 20 : 21 : #define REPLAY_FLAG_FINISHED_BLOCK (0x01UL) 22 : #define REPLAY_FLAG_PACKED_MICROBLOCK (0x02UL) 23 : #define REPLAY_FLAG_MICROBLOCK (0x04UL) 24 : #define REPLAY_FLAG_CATCHING_UP (0x08UL) 25 : #define REPLAY_FLAG_INIT (0x10UL) 26 : 27 : 28 : /* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP 29 : headers that can go in or out of the net tile. 2048 is the maximum 30 : XSK entry size, so this value follows naturally. */ 31 12 : #define FD_NET_MTU (2048UL) 32 : 33 : /* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU. 34 : 35 : This is minimum MTU of IPv6 packet - IPv6 header - UDP header 36 : 1280 - 40 - 8 */ 37 3 : #define FD_TPU_MTU (1232UL) 38 : 39 : /* FD_GOSSIP_MTU is the max sz of a gossip packet which is the same as 40 : above. */ 41 : #define FD_GOSSIP_MTU (FD_TPU_MTU) 42 : 43 : /* FD_SHRED_STORE_MTU is the size of an fd_shred34_t (statically 44 : asserted in fd_shred_tile.c). */ 45 3 : #define FD_SHRED_STORE_MTU (41792UL) 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 : #define FD_NETMUX_SIG_IGNORE_HDR_SZ (102UL) /* Outside the allowable range, but still fits in 4 bits when compressed */ 49 : 50 : FD_PROTOTYPES_BEGIN 51 : 52 : /* hdr_sz is the total size of network headers, including eth, ip, udp. 53 : Ignored for outgoing packets. */ 54 : FD_FN_CONST static inline ulong 55 : fd_disco_netmux_sig( uint src_ip_addr, 56 : ushort src_port, 57 : uint dst_ip_addr, 58 : ulong proto, 59 0 : ulong hdr_sz ) { 60 : /* The size of an Ethernet header is 14+4k bytes, where 0<=k<=3 (?) is 61 : the number of vlan tags. The size of an IP header is 4j, where 62 : 5<=j<=15 is the size given in the header. The size of a UDP header 63 : is 8B. Thus, the total sum of these is 42+4i, where i=k+j-5, 64 : 0<=i<=13. Since bits are at a premium here, we compress the header 65 : size by just storing i. */ 66 0 : ulong hdr_sz_i = ((hdr_sz - 42UL)>>2)&0xFUL; 67 0 : ulong hash = fd_uint_hash( src_ip_addr ) + src_port; 68 : 69 : /* Currently only using 52 bits of the provided 64. */ 70 0 : return (hash<<56UL) | ((proto&0xFFUL)<<48UL) | ((hdr_sz_i&0xFUL)<<44UL) | (((ulong)dst_ip_addr)<<12UL); 71 0 : } 72 : 73 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hash ( ulong sig ) { return (sig>>56UL) & 0xFFUL; } 74 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_proto ( ulong sig ) { return (sig>>48UL) & 0xFFUL; } 75 0 : FD_FN_CONST static inline uint fd_disco_netmux_sig_dst_ip( ulong sig ) { return (uint)((sig>>12UL) & 0xFFFFFFFFUL); } 76 : 77 : /* fd_disco_netmux_sig_hdr_sz extracts the total size of the Ethernet, 78 : IP, and UDP headers from the netmux signature field. The UDP payload 79 : of the packet stored in the corresponding frag begins at the returned 80 : offset. */ 81 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hdr_sz( ulong sig ) { return 4UL*((sig>>44UL) & 0xFUL) + 42UL; } 82 : 83 : FD_FN_CONST static inline ulong 84 : fd_disco_poh_sig( ulong slot, 85 : ulong pkt_type, 86 0 : ulong bank_tile ) { 87 : /* The high 6 bits of the low byte of the signature field is the bank 88 : idx. Banks will filter to only handle frags with their own idx. 89 : The higher 7 bytes are the slot number. Technically, the slot 90 : number is a ulong, but it won't hit 256^7 for about 10^9 years at 91 : the current rate. The lowest bits of the low byte is the packet 92 : type. */ 93 0 : return (slot << 8) | ((bank_tile & 0x3FUL) << 2) | (pkt_type & 0x3UL); 94 0 : } 95 : 96 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_pkt_type( ulong sig ) { return (sig & 0x3UL); } 97 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_slot( ulong sig ) { return (sig >> 8); } 98 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_bank_tile( ulong sig ) { return (sig >> 2) & 0x3FUL; } 99 : 100 : FD_FN_CONST static inline ulong 101 : fd_disco_bank_sig( ulong slot, 102 0 : ulong microblock_idx ) { 103 0 : return (slot << 32) | microblock_idx; 104 0 : } 105 : 106 0 : FD_FN_CONST static inline ulong fd_disco_bank_sig_slot( ulong sig ) { return (sig >> 32); } 107 0 : FD_FN_CONST static inline ulong fd_disco_bank_sig_microblock_idx( ulong sig ) { return sig & 0xFFFFFFFFUL; } 108 : 109 : FD_FN_CONST static inline ulong 110 : fd_disco_replay_sig( ulong slot, 111 0 : ulong flags ) { 112 0 : /* The low byte of the signature field is the flags for replay message. 113 0 : The higher 7 bytes are the slot number. These flags indicate the status 114 0 : of a microblock as it transits through the replay system. Technically, 115 0 : the slot number is a ulong, but it won't hit 256^7 for about 10^9 years 116 0 : at the current rate. The lowest bit of the low byte is the packet 117 0 : type. */ 118 0 : return (slot << 8) | (flags & 0xFFUL); 119 0 : } 120 : 121 0 : FD_FN_CONST static inline ulong fd_disco_replay_sig_flags( ulong sig ) { return (sig & 0xFFUL); } 122 0 : FD_FN_CONST static inline ulong fd_disco_replay_sig_slot( ulong sig ) { return (sig >> 8); } 123 : 124 : FD_FN_PURE static inline ulong 125 0 : fd_disco_compact_chunk0( void * wksp ) { 126 0 : return (((struct fd_wksp_private *)wksp)->gaddr_lo) >> FD_CHUNK_LG_SZ; 127 0 : } 128 : 129 : FD_FN_PURE static inline ulong 130 0 : fd_disco_compact_wmark( void * wksp, ulong mtu ) { 131 0 : ulong chunk_mtu = ((mtu + 2UL*FD_CHUNK_SZ-1UL) >> (1+FD_CHUNK_LG_SZ)) << 1; 132 0 : ulong wksp_hi = ((struct fd_wksp_private *)wksp)->gaddr_hi; 133 0 : return (wksp_hi >> FD_CHUNK_LG_SZ) - chunk_mtu; 134 0 : } 135 : 136 : FD_PROTOTYPES_END 137 : 138 : #endif /* HEADER_fd_src_disco_fd_disco_base_h */