Changeset f0fb38f for lib/format_dag24.c


Ignore:
Timestamp:
03/26/08 10:45:36 (13 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_dag24.c

    r121b7e2 rf0fb38f  
    8383};
    8484
     85static void dag_init_format_data(libtrace_t *libtrace) {
     86        libtrace->format_data = (struct dag_format_data_t *)
     87                malloc(sizeof(struct dag_format_data_t));
     88
     89        DUCK.last_duck = 0;
     90        DUCK.duck_freq = 0;
     91        DUCK.last_pkt = 0;
     92        DUCK.dummy_duck = NULL;
     93        FORMAT_DATA->drops = 0;
     94        FORMAT_DATA->top = 0;
     95        FORMAT_DATA->bottom = 0;
     96        FORMAT_DATA->buf = NULL;
     97        FORMAT_DATA->fd = -1;
     98        FORMAT_DATA->offset = 0;
     99        FORMAT_DATA->diff = 0;
     100}
     101
    85102static int dag_available(libtrace_t *libtrace) {
    86103
     
    120137        }
    121138       
    122         libtrace->format_data = (struct dag_format_data_t *)
    123                 malloc(sizeof(struct dag_format_data_t));
    124         FORMAT_DATA->top = 0;
    125         FORMAT_DATA->bottom = 0;
     139        dag_init_format_data(libtrace);
    126140        if (S_ISCHR(buf.st_mode)) {
    127141                /* DEVICE */
     
    145159        }
    146160
    147         DUCK.last_duck = 0;
    148         DUCK.duck_freq = 0;
    149         DUCK.last_pkt = 0;
    150         DUCK.dummy_duck = NULL;
    151         FORMAT_DATA->drops = 0;
    152161        free(dag_dev_name);
    153162
     
    259268}
    260269
    261 static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) {
     270static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet,
     271                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
     272
     273        dag_record_t *erfptr;
     274        if (packet->buffer != buffer &&
     275                        packet->buf_control == TRACE_CTRL_PACKET) {
     276                free(packet->buffer);
     277        }
     278
     279        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     280                packet->buf_control = TRACE_CTRL_PACKET;
     281        } else
     282                packet->buf_control = TRACE_CTRL_EXTERNAL;
     283       
     284        erfptr = (dag_record_t *)packet->buffer;
    262285        packet->buffer = erfptr;
    263286        packet->header = erfptr;
    264         packet->type = TRACE_RT_DATA_ERF;
     287        packet->type = rt_type;
     288
    265289        if (erfptr->flags.rxerror == 1) {
    266290                /* rxerror means the payload is corrupt - drop it
     
    273297        }
    274298
     299        if (libtrace->format_data == NULL) {
     300                dag_init_format_data(libtrace);
     301        }
     302
     303        DATA(libtrace)->drops += ntohs(erfptr->lctr);
     304
     305        return 0;
     306
    275307}
    276308
     
    278310        int numbytes;
    279311        int size = 0;
    280         struct timeval tv;
     312        uint32_t flags = 0;
     313        struct timeval tv;
    281314        dag_record_t *erfptr = NULL;
    282315
     
    307340                erfptr = dag_get_record(libtrace);
    308341        } while (erfptr == NULL);
    309         dag_form_packet(erfptr, packet);
    310         tv = trace_get_timeval(packet);
     342       
     343       
     344        if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF,
     345                                flags))
     346                return -1;
     347        tv = trace_get_timeval(packet);
    311348        DUCK.last_pkt = tv.tv_sec;
    312         DATA(libtrace)->drops += ntohs(erfptr->lctr);
    313349        return packet->payload ? htons(erfptr->rlen) : erf_get_framing_length(packet);
    314350}
     
    348384static uint64_t dag_get_dropped_packets(libtrace_t *trace)
    349385{
     386        if (!trace->format_data)
     387                return (uint64_t)-1;
    350388        return DATA(trace)->drops;
    351389}
     
    377415        NULL,                           /* fin_output */
    378416        dag_read_packet,                /* read_packet */
    379         NULL,                           /* fin_packet */
     417        dag_prepare_packet,             /* prepare_packet */
     418        NULL,                           /* fin_packet */
    380419        NULL,                           /* write_packet */
    381420        erf_get_link_type,              /* get_link_type */
Note: See TracChangeset for help on using the changeset viewer.