Changeset 50bbce8


Ignore:
Timestamp:
11/30/07 08:57:55 (13 years ago)
Author:
Perry Lorier <perry@…>
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:
25a9201
Parents:
b282cf8
Message:

First pass implementation of loss recording framework.

Location:
lib
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • lib/format_bpf.c

    rf2fae49 r50bbce8  
    6262        int remaining;
    6363        unsigned int linktype;
     64        struct bpf_stat stats;
     65        int stats_valid;
    6466};
    6567
     
    7577        FORMATIN(libtrace)->promisc = 0;
    7678        FORMATIN(libtrace)->snaplen = 65536;
     79        FORMATIN(libtrace)->stats_valid = 0;
    7780
    7881        return 0;
     
    193196        }
    194197
     198        FORMATIN(libtrace)->stats_valid = 0;
     199
    195200        /* TODO: we should always set a bpf filter for snapping */
    196201
    197202        /* We're done! */
    198203        return 0;
     204}
     205
     206static uint64_t bpf_get_received_packets(libtrace_t *trace)
     207{
     208        /* If we're called with stats_valid == 0, or we're called again
     209         * then refresh the stats.  Don't refresh the stats if we're called
     210         * immediately after get_dropped_packets
     211         */
     212        if (FORMATIN(trace)->stats_valid != 2) {
     213                ioctl(FORMATIN(trace)->fd, BIOCGSTATS, &FORMATIN(trace)->stats);
     214                FORMATIN(trace)->stats_valid = 1;
     215        }
     216
     217        return FORMATIN(trace)->stats.bs_recv;
     218}
     219
     220static uint64_t bpf_get_dropped_packets(libtrace_t *trace)
     221{
     222        /* If we're called with stats_valid == 0, or we're called again
     223         * then refresh the stats.  Don't refresh the stats if we're called
     224         * immediately after get_received_packets
     225         */
     226        if (!FORMATIN(trace)->stats_valid != 1) {
     227                ioctl(FORMATIN(trace)->fd, BIOCGSTATS, &FORMATIN(trace)->stats);
     228                FORMATIN(trace)->stats_valid = 2;
     229        }
     230
     231        return FORMATIN(trace)->stats.bs_drop;
    199232}
    200233
     
    369402        bpf_get_framing_length, /* get_framing_length */
    370403        NULL,                   /* set_capture_length */
    371         NULL,                   /* get_received_packets */
     404        bpf_get_received_packets,/* get_received_packets */
    372405        NULL,                   /* get_filtered_packets */
    373         NULL,                   /* get_dropped_packets */
     406        bpf_get_dropped_packets,/* get_dropped_packets */
    374407        NULL,                   /* get_captured_packets */
    375408        bpf_get_fd,             /* get_fd */
  • lib/format_dag24.c

    rf2fae49 r50bbce8  
    8080        uint32_t bottom;
    8181        uint32_t top;
     82        uint64_t drops;
    8283};
    8384
     
    130131        DUCK.last_pkt = 0;
    131132        DUCK.dummy_duck = NULL;
     133        FORMAT_DATA->drops = 0;
    132134
    133135        return 0;
     
    164166        while(dag_available(libtrace) != 0)
    165167                FORMAT_DATA->diff = 0;
     168        FORMAT_DATA->drops = 0;
    166169        return 0;
    167170}
     
    288291        tv = trace_get_timeval(packet);
    289292        DUCK.last_pkt = tv.tv_sec;
     293        DATA(libtrace)->drops += ntohs(erfptr->lctr);
    290294        return packet->payload ? htons(erfptr->rlen) : erf_get_framing_length(packet);
    291295}
     
    321325        event.seconds = 0.0001;
    322326        return event;
     327}
     328
     329static uint64_t dag24_get_dropped_packets(libtrace_t *trace)
     330{
     331        return DATA(trace)->drops;
    323332}
    324333
     
    366375        NULL,                           /* get_received_packets */
    367376        NULL,                           /* get_filtered_packets */
    368         NULL,                           /* get_dropped_packets */
     377        dag24_get_dropped_packets,      /* get_dropped_packets */
    369378        NULL,                           /* get_captured_packets */
    370379        NULL,                           /* get_fd */
  • lib/format_dag25.c

    rf2fae49 r50bbce8  
    7979        uint8_t *top;
    8080        uint32_t processed;
     81        uint64_t drops;
    8182};
    8283
     
    110111        DUCK.dummy_duck = NULL;
    111112        FORMAT_DATA->stream_attached = 0;
     113        FORMAT_DATA->drops = 0;
    112114       
    113115        return 0;
     
    181183        FORMAT_DATA->bottom = NULL;
    182184        FORMAT_DATA->processed = 0;
     185        FORMAT_DATA->drops = 0;
    183186       
    184187        return 0;
     
    329332        tv = trace_get_timeval(packet);
    330333        DUCK.last_pkt = tv.tv_sec;
     334        DATA(libtrace)->drops += ntohs(erfptr->lctr);
    331335        return packet->payload ? htons(erfptr->rlen) :
    332336                                erf_get_framing_length(packet);
     
    410414        NULL,                           /* get_received_packets */
    411415        NULL,                           /* get_filtered_packets */
    412         NULL,                           /* get_dropped_packets */
     416        dag25_get_dropped_packets,      /* get_dropped_packets */
    413417        NULL,                           /* get_captured_packets */
    414418        NULL,                           /* get_fd */
  • lib/format_erf.c

    rf2fae49 r50bbce8  
    8585                int real_time;
    8686        } options;
     87        uint64_t drops;
    8788};
    8889
     
    148149        INPUT.file = 0;
    149150        IN_OPTIONS.real_time = 0;
     151        DATA(libtrace)->drops = 0;
    150152       
    151153        return 0; /* success */
     
    176178        if (!INPUT.file)
    177179                return -1;
     180
     181        DATA(libtrace)->drops = 0;
    178182
    179183        return 0; /* success */
     
    616620        }
    617621       
     622}
     623
     624static uint64_t erf_get_dropped_packets(libtrace_t *trace)
     625{
     626        return DATA(trace)->drops;
    618627}
    619628
     
    673682        NULL,                           /* get_received_packets */
    674683        NULL,                           /* get_filtered_packets */
    675         NULL,                           /* get_dropped_packets */
     684        erf_get_dropped_packets,        /* get_dropped_packets */
    676685        NULL,                           /* get_captured_packets */
    677686        NULL,                           /* get_fd */
  • lib/format_linux.c

    rf2fae49 r50bbce8  
    5353#include <assert.h>
    5454
     55struct tpacket_stats {
     56        unsigned int tp_packets;
     57        unsigned int tp_drops;
     58};
     59
    5560struct libtrace_format_data_t {
    5661        int fd;
     
    5863        int promisc;
    5964        libtrace_filter_t *filter;
     65        struct tpacket_stats stats;
     66        int stats_valid;
    6067};
    6168
     
    8289        FORMAT(libtrace->format_data)->snaplen = 65536;
    8390        FORMAT(libtrace->format_data)->filter = NULL;
     91        FORMAT(libtrace->format_data)->stats_valid = 0;
    8492
    8593        return 0;
     
    187195                }
    188196        }
     197
     198        FORMAT(libtrace->format_data)->stats_valid=0;
    189199                                       
    190200        return 0;
     
    199209                return -1;
    200210        }
     211        FORMAT(libtrace->format_data)->stats_valid=0;
    201212
    202213        return 0;
     
    480491static int linuxnative_get_fd(const libtrace_t *trace) {
    481492        return FORMAT(trace->format_data)->fd;
     493}
     494
     495static uint64_t linuxnative_get_captured_packets(libtrace_t *trace) {
     496        if (FORMAT(trace->format_data)->stats_valid != 2) {
     497                socklen_t len = sizeof(FORMAT(trace->format_data)->stats);
     498                getsockopt(FORMAT(trace->format_data)->fd,
     499                                SOL_PACKET,
     500                                PACKET_STATISTICS,
     501                                &FORMAT(trace->format_data)->stats,
     502                                &len);
     503                FORMAT(trace->format_data)->stats_valid = 1;
     504        }
     505
     506        return FORMAT(trace->format_data)->stats.tp_packets;
     507}
     508
     509static uint64_t linuxnative_get_dropped_packets(libtrace_t *trace) {
     510        if (FORMAT(trace->format_data)->stats_valid != 1) {
     511                socklen_t len = sizeof(FORMAT(trace->format_data)->stats);
     512                getsockopt(FORMAT(trace->format_data)->fd,
     513                                SOL_PACKET,
     514                                PACKET_STATISTICS,
     515                                &FORMAT(trace->format_data)->stats,
     516                                &len);
     517                FORMAT(trace->format_data)->stats_valid = 2;
     518        }
     519
     520        return FORMAT(trace->format_data)->stats.tp_drops;
    482521}
    483522
     
    523562        NULL,                           /* get_received_packets */
    524563        NULL,                           /* get_filtered_packets */
    525         NULL,                           /* get_dropped_packets */
    526         NULL,                           /* get_captured_packets */
     564        linuxnative_get_dropped_packets,/* get_dropped_packets */
     565        linuxnative_get_captured_packets,/* get_captured_packets */
    527566        linuxnative_get_fd,             /* get_fd */
    528567        trace_event_device,             /* trace_event */
  • lib/format_pcap.c

    rf2fae49 r50bbce8  
    9191static int pcap_start_input(libtrace_t *libtrace) {
    9292        char errbuf[PCAP_ERRBUF_SIZE];
     93
    9394
    9495        /* if the file is already open */
     
    567568        assert(trace->format_data);
    568569        return pcap_fileno(DATA(trace)->input.pcap);
     570}
     571
     572static uint64_t pcap_get_dropped_packets(libtrace_t *trace)
     573{
     574        struct pcap_stat stats;
     575        if (pcap_stats(DATA(trace)->input.pcap,&stats)==-1) {
     576                char *errmsg = pcap_geterr(DATA(trace)->input.pcap);
     577                trace_set_err(trace,TRACE_ERR_UNSUPPORTED,
     578                                "Failed to retreive stats: %s\n",
     579                                errmsg ? errmsg : "Unknown pcap error");
     580                return ~0;
     581        }
     582
     583        return stats.ps_drop;
    569584}
    570585
     
    664679        NULL,                           /* get_received_packets */
    665680        NULL,                           /* get_filtered_packets */
    666         NULL,                           /* get_dropped_packets */
     681        pcap_get_dropped_packets,       /* get_dropped_packets */
    667682        NULL,                           /* get_captured_packets */
    668683        pcap_get_fd,                    /* get_fd */
  • lib/libtrace.h.in

    rf2fae49 r50bbce8  
    843843 * If this is not known, this will return UINT64_MAX
    844844 */
    845 uint64_t trace_get_received_packets(const libtrace_t *trace);
     845uint64_t trace_get_received_packets(libtrace_t *trace);
    846846
    847847/** Return the number of filtered packets
     
    854854 * If this is not known, this will return UINT64_MAX
    855855 */
    856 uint64_t trace_get_filtered_packets(const libtrace_t *trace);
     856uint64_t trace_get_filtered_packets(libtrace_t *trace);
    857857
    858858/** Return the number of packets that have been dropped for lack of packets
     
    860860 * @returns The number of packets captured, but dropped due to buffer overruns
    861861 */
    862 uint64_t trace_get_dropped_packets(const libtrace_t *trace);
     862uint64_t trace_get_dropped_packets(libtrace_t *trace);
    863863
    864864/** Return the number of packets that have been returned to library user
     
    866866 * @returns The number of packets returned to the user of the library.
    867867 */
    868 uint64_t trace_get_accepted_packets(const libtrace_t *trace);
     868uint64_t trace_get_accepted_packets(libtrace_t *trace);
    869869
    870870
  • lib/libtrace_int.h

    r9d3c721 r50bbce8  
    349349        /** Report the number of packets ever seen as early as possible
    350350         */
    351         uint64_t (*get_received_packets)(const libtrace_t *trace);
     351        uint64_t (*get_received_packets)(libtrace_t *trace);
    352352        /** Report the number of filtered packets.
    353353         */
    354         uint64_t (*get_filtered_packets)(const libtrace_t *trace);
     354        uint64_t (*get_filtered_packets)(libtrace_t *trace);
    355355        /** Return the number of dropped packets */
    356         uint64_t (*get_dropped_packets)(const libtrace_t *trace);
     356        uint64_t (*get_dropped_packets)(libtrace_t *trace);
    357357        /** Report number of captured packets
    358358         */
    359         uint64_t (*get_captured_packets)(const libtrace_t *trace);
     359        uint64_t (*get_captured_packets)(libtrace_t *trace);
    360360        /** return the filedescriptor associated with this interface.
    361361         * @note This callback may be NULL if not supported.
  • lib/trace.c

    r9d3c721 r50bbce8  
    15951595}
    15961596
    1597 uint64_t trace_get_received_packets(const libtrace_t *trace)
     1597uint64_t trace_get_received_packets(libtrace_t *trace)
    15981598{
    15991599        assert(trace);
     
    16041604}
    16051605
    1606 uint64_t trace_get_filtered_packets(const libtrace_t *trace)
     1606uint64_t trace_get_filtered_packets(libtrace_t *trace)
    16071607{
    16081608        assert(trace);
     
    16221622}
    16231623
    1624 uint64_t trace_get_dropped_packets(const libtrace_t *trace)
     1624uint64_t trace_get_dropped_packets(libtrace_t *trace)
    16251625{
    16261626        assert(trace);
     
    16311631}
    16321632
    1633 uint64_t trace_get_accepted_packets(const libtrace_t *trace)
     1633uint64_t trace_get_accepted_packets(libtrace_t *trace)
    16341634{
    16351635        assert(trace);
Note: See TracChangeset for help on using the changeset viewer.