Difference between revisions of "UDP Packet Header Formats"

From epsciwiki
Jump to navigation Jump to search
Line 1: Line 1:
 +
<font size="+1">
  
 +
=== Load Balancer Header ===
  
 +
: Following is the C routine to write the header that the LB reads, and eventually strips off, in order to direct the packet to the proper destination.
  
 
<pre>
 
<pre>
Line 10: Line 13:
 
         * 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'
 
 
         *
 
         *
 
         *  0                  1                  2                  3
 
         *  0                  1                  2                  3
Line 48: Line 50:
  
 
</pre>
 
</pre>
 +
 +
: Currently the version = 2.
  
  
Line 97: Line 101:
 
         }
 
         }
 
</pre>
 
</pre>
 +
 +
</font>

Revision as of 21:39, 16 November 2023

Load Balancer Header

Following is the C routine to write the header that the LB reads, and eventually strips off, in order to direct the packet to the proper destination.

        /**
         * 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.
         *
         *
         *  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);
        }

Currently the version = 2.




      /**
        * <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);
        }