Changeset f0fb38f for lib/format_dag25.c


Ignore:
Timestamp:
03/26/08 10:45:36 (14 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, 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:
f52bcdd
Parents:
e632f2f
Message:
  • Added prepare_packet functions to all formats, primarily to support translating RT packets into the appropriate format. These functions are all used internally as well, as most formats still need to "prepare" packets that have been read by setting pointers, updating loss counters etc.
  • Also added a trace_prepare_packet function, but this is not made available externally at this stage
  • Added init_format_data functions to some formats to initialise format data structures in cases where the init_trace function does more than just that
  • Refactored rt packet reading code to use the new trace_prepare_packet functionality - also did a lot of tidying of the code
  • Added missing RT type for BPF format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dag25.c

    r2faa57e rf0fb38f  
    9999struct dag_dev_t *open_dags = NULL;
    100100
     101static void dag_init_format_data(libtrace_t *libtrace) {
     102        libtrace->format_data = (struct dag_format_data_t *)
     103                malloc(sizeof(struct dag_format_data_t));
     104        DUCK.last_duck = 0;
     105        DUCK.duck_freq = 0;
     106        DUCK.last_pkt = 0;
     107        DUCK.dummy_duck = NULL;
     108        FORMAT_DATA->stream_attached = 0;
     109        FORMAT_DATA->drops = 0;
     110        FORMAT_DATA->device = NULL;
     111        FORMAT_DATA->dagstream = 0;
     112        FORMAT_DATA->processed = 0;
     113        FORMAT_DATA->bottom = NULL;
     114        FORMAT_DATA->top = NULL;
     115}
     116
    101117/* NOTE: This function assumes the open_dag_mutex is held by the caller */
    102118static struct dag_dev_t *dag_find_open_device(char *dev_name) {
     
    187203        struct dag_dev_t *dag_device = NULL;
    188204       
     205        dag_init_format_data(libtrace);
    189206        pthread_mutex_lock(&open_dag_mutex);
    190207        if ((scan = strchr(libtrace->uridata,',')) == NULL) {
     
    197214       
    198215       
    199         libtrace->format_data = (struct dag_format_data_t *)
    200                 malloc(sizeof(struct dag_format_data_t));
    201216
    202217        /* For now, we don't offer the ability to select the stream */
     
    219234        }
    220235
    221 
    222 
    223         DUCK.last_duck = 0;
    224         DUCK.duck_freq = 0;
    225         DUCK.last_pkt = 0;
    226         DUCK.dummy_duck = NULL;
    227236        FORMAT_DATA->device = dag_device;
    228         FORMAT_DATA->stream_attached = 0;
    229         FORMAT_DATA->drops = 0;
    230237       
    231238        pthread_mutex_unlock(&open_dag_mutex);
     
    402409}
    403410
    404 static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) {
    405         packet->buffer = erfptr;
     411static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet,
     412                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
     413       
     414        dag_record_t *erfptr;
     415       
     416        if (packet->buffer != buffer &&
     417                        packet->buf_control == TRACE_CTRL_PACKET) {
     418                free(packet->buffer);
     419        }
     420       
     421        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     422                packet->buf_control = TRACE_CTRL_PACKET;
     423        } else
     424                packet->buf_control = TRACE_CTRL_EXTERNAL;
     425       
     426        erfptr = (dag_record_t *)packet->buffer;
     427        packet->buffer = erfptr;
    406428        packet->header = erfptr;
    407         packet->type = TRACE_RT_DATA_ERF;
    408         if (erfptr->flags.rxerror == 1) {
     429        packet->type = rt_type;
     430       
     431        if (erfptr->flags.rxerror == 1) {
    409432                /* rxerror means the payload is corrupt - drop it
    410433                 * by tweaking rlen */
     
    415438                        + erf_get_framing_length(packet);
    416439        }
    417 
     440       
     441        if (libtrace->format_data == NULL) {
     442                dag_init_format_data(libtrace);
     443        }
     444       
     445        /* No loss counter for DSM coloured records - have to use
     446         * some other API */
     447        if (erfptr->type == TYPE_DSM_COLOR_ETH) {
     448               
     449        } else {
     450                DATA(libtrace)->drops += ntohs(erfptr->lctr);
     451        }
     452
     453        return 0;
    418454}
    419455
     
    424460        dag_record_t *erfptr = NULL;
    425461        int numbytes = 0;
     462        uint32_t flags = 0;
    426463       
    427464        if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq &&
     
    437474
    438475        if (packet->buf_control == TRACE_CTRL_PACKET) {
    439                 packet->buf_control = TRACE_CTRL_EXTERNAL;
    440476                free(packet->buffer);
    441477                packet->buffer = 0;
     
    452488        } while (erfptr == NULL);
    453489
    454         dag_form_packet(erfptr, packet);
     490        //dag_form_packet(erfptr, packet);
     491        if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF,
     492                                flags))
     493                return -1;
    455494        tv = trace_get_timeval(packet);
    456495        DUCK.last_pkt = tv.tv_sec;
    457496       
    458         /* No loss counter for DSM coloured records - have to use
    459          * some other API */
    460         if (erfptr->type == TYPE_DSM_COLOR_ETH) {
    461                
    462         } else {
    463                 DATA(libtrace)->drops += ntohs(erfptr->lctr);
    464         }
    465497        return packet->payload ? htons(erfptr->rlen) :
    466498                                erf_get_framing_length(packet);
     
    472504        dag_record_t *erfptr = NULL;
    473505        int numbytes;
     506        uint32_t flags = 0;
    474507       
    475508        /* Need to call dag_available so that the top pointer will get
     
    487520                return event;
    488521        }
    489         dag_form_packet(erfptr, packet);
     522        //dag_form_packet(erfptr, packet);
     523        if (dag_prepare_packet(trace, packet, erfptr, TRACE_RT_DATA_ERF,
     524                                flags)) {
     525                event.type = TRACE_EVENT_TERMINATE;
     526                return event;
     527        }
     528               
     529               
    490530        event.size = trace_get_capture_length(packet) + trace_get_framing_length(packet);
    491531        if (trace->filter) {
     
    509549
    510550static uint64_t dag_get_dropped_packets(libtrace_t *trace) {
     551        if (trace->format_data == NULL)
     552                return (uint64_t)-1;
    511553        return DATA(trace)->drops;
    512554}
     
    538580        NULL,                           /* fin_output */
    539581        dag_read_packet,                /* read_packet */
    540         NULL,                           /* fin_packet */
     582        dag_prepare_packet,             /* prepare_packet */
     583        NULL,                           /* fin_packet */
    541584        NULL,                           /* write_packet */
    542585        erf_get_link_type,              /* get_link_type */
Note: See TracChangeset for help on using the changeset viewer.