Difference between revisions of "UDP Packet Header Formats"
Jump to navigation
Jump to search
(Created page with " <pre> /** * Set the Load Balancer header data. * The first four bytes go as ordered. * The entropy goes as a single, network byte ordere...") |
|||
Line 10: | Line 10: | ||
* The tick goes as a single, network byte ordered, 64-bit int. | * The tick goes as a single, network byte ordered, 64-bit int. | ||
* | * | ||
− | |||
* protocol 'L:8,B:8,Version:8,Protocol:8,Reserved:16,Entropy:16,Tick:64' | * protocol 'L:8,B:8,Version:8,Protocol:8,Reserved:16,Entropy:16,Tick:64' | ||
* | * | ||
Line 30: | Line 29: | ||
* | | | * | | | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
− | |||
* | * | ||
* @param buffer buffer in which to write the header. | * @param buffer buffer in which to write the header. | ||
Line 50: | Line 48: | ||
</pre> | </pre> | ||
+ | |||
<pre> | <pre> | ||
Line 61: | Line 60: | ||
* This is the new, version 2, RE header. | * This is the new, version 2, RE header. | ||
* | * | ||
− | |||
* protocol 'Version:4, Rsvd:12, Data-ID:16, Offset:32, Length:32, Tick:64' | * protocol 'Version:4, Rsvd:12, Data-ID:16, Offset:32, Length:32, Tick:64' | ||
* | * | ||
Line 77: | Line 75: | ||
* | | | * | | | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
− | |||
* | * | ||
* @param buffer buffer in which to write the header. | * @param buffer buffer in which to write the header. |
Revision as of 21:03, 16 November 2023
/** * Set the Load Balancer header data. * The first four bytes go as ordered. * The entropy goes as a single, network byte ordered, 16-bit int. * The tick goes as a single, network byte ordered, 64-bit int. * * protocol 'L:8,B:8,Version:8,Protocol:8,Reserved:16,Entropy:16,Tick:64' * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | L | B | Version | Protocol | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 3 4 5 6 * 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Rsvd | Entropy | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 6 12 * 4 5 ... ... ... 0 1 2 3 4 5 6 7 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + Tick + * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * @param buffer buffer in which to write the header. * @param tick unsigned 64 bit tick number used to tell the load balancer * which backend host to direct the packet to. * @param version version of this software. * @param protocol protocol this software uses. * @param entropy entropy field used to determine destination port. */ static void setLbMetadata(char* buffer, uint64_t tick, int version, int protocol, int entropy) { *buffer = 'L'; *(buffer+1) = 'B'; *(buffer+2) = version; *(buffer+3) = protocol; // Put the data in network byte order (big endian) *((uint16_t *)(buffer + 6)) = htons(entropy); *((uint64_t *)(buffer + 8)) = htonll(tick); }
/** * <p>Set the Reassembly Header data. * The first 16 bits go as ordered. The dataId is put in network byte order. * The offset, length and tick are also put into network byte order.</p> * Implemented <b>without</b> using C++ bit fields. * This is the new, version 2, RE header. * * protocol 'Version:4, Rsvd:12, Data-ID:16, Offset:32, Length:32, Tick:64' * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |Version| Rsvd | Data-ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Buffer Offset | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Buffer Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + Tick + * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * @param buffer buffer in which to write the header. * @param offset byte offset into full buffer payload. * @param length total length in bytes of full buffer payload. * @param tick 64 bit tick number used to tell the load balancer * which backend host to direct the packet to. Necessary to * disentangle packets from different ticks at one destination * as there may be overlap in time. * @param version the version of this software. * @param dataId the data source id number. */ static void setReMetadata(char* buffer, uint32_t offset, uint32_t length, uint64_t tick, int version, uint16_t dataId) { buffer[0] = version << 4; *((uint16_t *)(buffer + 2)) = htons(dataId); *((uint32_t *)(buffer + 4)) = htonl(offset); *((uint32_t *)(buffer + 8)) = htonl(length); *((uint64_t *)(buffer + 12)) = htonll(tick); }