Changeset 7e6b54d


Ignore:
Timestamp:
09/03/15 15:21:45 (5 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
0a368ae
Parents:
87cba74
Message:

Re-work the RT protocol to be usable cross-platform

  • All structures are packed to avoid padding mismatches.
  • All fields are in network byte order.
  • Added 'version' and 'magic' fields to the header so we can identify version mismatches or invalid packets more easily.
  • Acknowledgements are now sent for 1/10 received packets and are treated as cumulative acknowledgements. Reordering shouldn't happen at this layer, since we are using TCP for transport.
  • Replace enum types in headers with uint32_t, so we can be sure of what size these fields will be.
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/format_rt.c

    r5ab626a r7e6b54d  
    9898        /* Header for the packet currently being received */
    9999        rt_header_t rt_hdr;
     100
     101        int unacked;
    100102       
    101103        /* Dummy traces that can be assigned to the received packets to ensure
     
    155157        }
    156158       
    157         switch (connect_msg.type) {
     159        if (connect_msg.magic != LIBTRACE_RT_MAGIC) {
     160                trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
     161                        "RT version mismatch: magic byte is incorrect");
     162                return -1;
     163        }
     164
     165        if (connect_msg.version != LIBTRACE_RT_VERSION) {
     166                trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
     167                        "RT version mismatch: version is incorrect (expected %d, got %d",
     168                        LIBTRACE_RT_VERSION, connect_msg.version);
     169                return -1;
     170        }
     171
     172               
     173       
     174        switch (ntohl(connect_msg.type)) {
    158175                case TRACE_RT_DENY_CONN:
    159176                        /* Connection was denied */
     
    164181                                reason = 0;
    165182                        }       
    166                         reason = deny_hdr.reason;
     183                        reason = ntohl(deny_hdr.reason);
    167184                        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
    168185                                "Connection attempt is denied: %s",
     
    179196                                return -1;
    180197                        }
    181                         RT_INFO->reliable = hello_opts.reliable;
    182198                       
     199                       
     200                        RT_INFO->reliable = hello_opts.reliable;
     201                        RT_INFO->unacked = 0;
    183202                        return 0;
    184203                default:
     
    207226        RT_INFO->hostname = NULL;
    208227        RT_INFO->port = 0;
     228        RT_INFO->unacked = 0;
    209229}
    210230
     
    245265        rt_header_t start_msg;
    246266
    247         start_msg.type = TRACE_RT_START;
     267        start_msg.type = htonl(TRACE_RT_START);
    248268        start_msg.length = 0;
    249269
     
    265285        rt_header_t close_msg;
    266286
    267         close_msg.type = TRACE_RT_CLOSE;
     287        close_msg.type = htonl(TRACE_RT_CLOSE);
    268288        close_msg.length = 0;
    269289       
     
    502522        ack_hdr = (rt_ack_t *) (ack_buffer + sizeof(rt_header_t));
    503523       
    504         hdr->type = TRACE_RT_ACK;
    505         hdr->length = sizeof(rt_ack_t);
    506 
    507         ack_hdr->sequence = seqno;
    508        
    509         to_write = hdr->length + sizeof(rt_header_t);
     524        hdr->type = htonl(TRACE_RT_ACK);
     525        hdr->length = htons(sizeof(rt_ack_t));
     526
     527        ack_hdr->sequence = htonl(seqno);
     528       
     529        to_write = sizeof(rt_ack_t) + sizeof(rt_header_t);
    510530        buf_ptr = ack_buffer;
    511531
     
    575595        /* Send an ACK if required */
    576596        if (RT_INFO->reliable > 0 && packet->type >= TRACE_RT_DATA_SIMPLE) {
    577                 if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence) == -1)
     597                RT_INFO->unacked ++;
     598                if (RT_INFO->unacked >= RT_ACK_FREQUENCY) {
     599                        if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence)
     600                                        == -1)
    578601                                return -1;
     602                        RT_INFO->unacked = 0;
     603                }
    579604        }
    580605       
     
    622647                /* Need to store these in case the next rt_read overwrites
    623648                 * the buffer they came from! */
    624                 RT_INFO->rt_hdr.type = pkt_hdr->type;
    625                 RT_INFO->rt_hdr.length = pkt_hdr->length;
    626                 RT_INFO->rt_hdr.sequence = pkt_hdr->sequence;
     649                RT_INFO->rt_hdr.type = ntohl(pkt_hdr->type);
     650                RT_INFO->rt_hdr.length = ntohs(pkt_hdr->length);
     651                RT_INFO->rt_hdr.sequence = ntohl(pkt_hdr->sequence);
    627652        }
    628653        packet->type = RT_INFO->rt_hdr.type;
  • lib/rt_protocol.h

    rc5ac872 r7e6b54d  
    5050/** Maximum size for the RT header */
    5151#define RT_MAX_HDR_SIZE 256
    52 /** Maximum sequence number for the RT protocol */
    53 #define MAX_SEQUENCE 2147483647
     52
     53#define RT_ACK_FREQUENCY (10)
     54#define LIBTRACE_RT_VERSION (0x04)
     55#define LIBTRACE_RT_MAGIC (0x5a)
    5456
    5557/* Procedure for adding new RT control types
     
    8486        uint64_t length;        /**< The total length of the fifo */
    8587        uint64_t used;          /**< The amount of fifo space in use */
    86 } fifo_info_t;
     88} PACKED fifo_info_t;
    8789
    8890/** RT packet header */
    8991typedef struct rt_header {
    9092        /** The type of RT packet */
    91         libtrace_rt_types_t type;       
    92         /** The length of the packet (not including the RT header */
     93        uint32_t type; 
     94       
     95        uint8_t magic;
     96
     97        uint8_t version;
     98
     99        /** The length of the packet (not including the RT header */
    93100        uint16_t length;               
    94101        /** The sequence number of the packet */
    95102        uint32_t sequence;
    96 } rt_header_t;
     103} PACKED rt_header_t;
    97104
    98105/* TODO: Reorganise this struct once more hello info is added */
     
    103110         *  i.e. expecting acknowledgements */
    104111        uint8_t reliable;       
    105 } rt_hello_t;
     112} PACKED rt_hello_t ;
    106113
    107114#if 0
     
    115122        /** The sequence number of the last received RT packet */
    116123        uint32_t sequence;
    117 } rt_ack_t;
     124} PACKED rt_ack_t;
    118125
    119126/** RT Status sub-header */
     
    121128        /** Statistics describing the current status of the sender fifo */
    122129        fifo_info_t fifo_status;
    123 } rt_status_t;
     130} PACKED rt_status_t;
    124131
    125132#if 0
     
    154161typedef struct rt_deny_conn {
    155162        /** The reason that the connection was denied */
    156         enum rt_conn_denied_t reason;
    157 } rt_deny_conn_t;
     163        uint32_t reason;
     164} PACKED rt_deny_conn_t;
    158165
    159166#if 0
     
    187194        /** Length of the value string that follows the header */
    188195        uint32_t value_len;
    189 } rt_metadata_t ;
     196} PACKED rt_metadata_t;
    190197
    191198/** Specifications of duck structures - duck2_4 and duck2_5 match Endace's
Note: See TracChangeset for help on using the changeset viewer.