Changeset d026488


Ignore:
Timestamp:
02/09/10 10:05:10 (11 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:
8414770
Parents:
238d50a
Message:
  • Updated documentation and licensing for the last two format modules
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/format_rt.c

    r226c08b rd026488  
    22 * This file is part of libtrace
    33 *
    4  * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand.
    5  * Authors: Daniel Lawson
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
    68 *          Perry Lorier
    7  *          Shane Alcock
    8  *
     9 *          Shane Alcock
     10 *         
    911 * All rights reserved.
    1012 *
    11  * This code has been developed by the University of Waikato WAND
     13 * This code has been developed by the University of Waikato WAND 
    1214 * research group. For further information please see http://www.wand.net.nz/
    1315 *
     
    2931 *
    3032 */
     33
    3134
    3235#define _GNU_SOURCE
     
    5457#define RT_INFO ((struct rt_format_data_t*)libtrace->format_data)
    5558
     59/* Convert the RT denial code into a nice printable and coherent string */
    5660static const char *rt_deny_reason(enum rt_conn_denied_t reason)
    5761{
     
    7781
    7882struct rt_format_data_t {
     83        /* Name of the host to connect to */
    7984        char *hostname;
     85        /* Buffer to store received packets into */
    8086        char *pkt_buffer;
     87        /* Pointer to the next packet to be read from the buffer */
    8188        char *buf_current;
     89        /* Amount of buffer space used */
    8290        size_t buf_filled;
     91        /* The port to connect to */
    8392        int port;
     93        /* The file descriptor for the RT connection */
    8494        int input_fd;
     95        /* Flag indicating whether the server is doing reliable RT */
    8596        int reliable;
     97
     98        /* Header for the packet currently being received */
    8699        rt_header_t rt_hdr;
    87100       
     101        /* Dummy traces that can be assigned to the received packets to ensure
     102         * that the appropriate functions can be used to process them */
    88103        libtrace_t *dummy_duck;
    89104        libtrace_t *dummy_erf;
     
    92107};
    93108
     109/* Connects to an RT server
     110 *
     111 * Returns -1 if an error occurs
     112 */
    94113static int rt_connect(libtrace_t *libtrace) {
    95114        struct hostent *he;
     
    125144        }
    126145
    127        
    128 #if 0
    129         oldflags = fcntl(RT_INFO->input_fd, F_GETFL, 0);
    130         if (oldflags == -1) {
    131                 trace_set_err(libtrace, errno,
    132                                 "Could not get fd flags from fd %d\n",
    133                                 RT_INFO->input_fd);
    134                 return -1;
    135         }
    136         oldflags |= O_NONBLOCK;
    137         if (fcntl(RT_INFO->input_fd, F_SETFL, oldflags) == -1) {
    138                 trace_set_err(libtrace, errno,
    139                                 "Could not set fd flags for fd %d\n",
    140                                 RT_INFO->input_fd);
    141                 return -1;
    142         }
    143 #endif
    144        
    145        
    146146        /* We are connected, now receive message from server */
    147147       
     
    155155        switch (connect_msg.type) {
    156156                case TRACE_RT_DENY_CONN:
     157                        /* Connection was denied */
    157158                       
    158159                        if (recv(RT_INFO->input_fd, (void*)&deny_hdr,
     
    167168                        return -1;
    168169                case TRACE_RT_HELLO:
    169                         /* do something with options */
     170                        /* Hello message - read the options sent to us by the
     171                         * server */
    170172                        if (recv(RT_INFO->input_fd, (void*)&hello_opts,
    171173                                                sizeof(rt_hello_t), 0)
     
    208210
    209211        rt_init_format_data(libtrace);
    210        
     212
     213        /* If the user specifies "rt:" then assume localhost and the default
     214         * port */     
    211215        if (strlen(uridata) == 0) {
    212216                RT_INFO->hostname =
     
    215219                        COLLECTOR_PORT;
    216220        } else {
    217                 if ((scan = strchr(uridata,':')) == NULL) {
     221                /* If the user does not specify a port, assume the default
     222                 * port */
     223                if ((scan = strchr(uridata,':')) == NULL) {
    218224                        RT_INFO->hostname =
    219225                                strdup(uridata);
     
    271277
    272278static int rt_fin_input(libtrace_t *libtrace) {
     279        /* Make sure we clean up any dummy traces that we have been using */
     280       
    273281        if (RT_INFO->dummy_duck)
    274282                trace_destroy_dead(RT_INFO->dummy_duck);
     
    299307#define RT_BUF_SIZE 10000U
    300308
     309/* Receives data from an RT server */
    301310static int rt_read(libtrace_t *libtrace, void **buffer, size_t len, int block)
    302311{
     
    320329                block=MSG_DONTWAIT;
    321330
    322        
     331        /* If we don't have enough buffer space for the amount we want to
     332         * read, move the current buffer contents to the front of the buffer
     333         * to make room */
    323334        if (len > RT_INFO->buf_filled) {
    324335                memcpy(RT_INFO->pkt_buffer, RT_INFO->buf_current,
     
    328339#  define MSG_NOSIGNAL 0
    329340#endif
     341                /* Loop as long as we don't have all the data that we were
     342                 * asked for */
    330343                while (len > RT_INFO->buf_filled) {
    331344                        if ((numbytes = recv(RT_INFO->input_fd,
     
    347360                                }
    348361                                if (errno == EAGAIN) {
     362                                        /* We asked for non-blocking mode, so
     363                                         * we need to return now */
    349364                                        trace_set_err(libtrace,
    350365                                                        EAGAIN,
     
    358373                                return -1;
    359374                        }
    360                         /*
    361                         buf_ptr = RT_INFO->pkt_buffer;
    362                         for (i = 0; i < RT_BUF_SIZE ; i++) {
    363                                        
    364                                 printf("%02x", (unsigned char)*buf_ptr);
    365                                 buf_ptr ++;
    366                         }
    367                         printf("\n");
    368                         */
    369375                        RT_INFO->buf_filled+=numbytes;
    370376                }
     
    378384
    379385
     386/* Sets the trace format for the packet to match the format it was originally
     387 * captured in, rather than the RT format */
    380388static int rt_set_format(libtrace_t *libtrace, libtrace_packet_t *packet)
    381389{
     390
     391        /* We need to assign the packet to a "dead" trace */
    382392
    383393        /* Try to minimize the number of corrupt packets that slip through
     
    431441}               
    432442
     443/* Sends an RT ACK to the server to acknowledge receipt of packets */
    433444static int rt_send_ack(libtrace_t *libtrace,
    434445                uint32_t seqno)  {
     
    457468        buf_ptr = ack_buffer;
    458469
     470        /* Keep trying until we write the entire ACK */
    459471        while (to_write > 0) {
    460472                numbytes = send(RT_INFO->input_fd, buf_ptr, to_write, 0);
     
    479491}
    480492
     493/* Shouldn't need to call this too often */
    481494static int rt_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet,
    482495                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
     
    505518}       
    506519
     520/* Reads the body of an RT packet from the network */
    507521static int rt_read_data_packet(libtrace_t *libtrace,
    508522                libtrace_packet_t *packet, int blocking) {
     
    511525        prep_flags |= TRACE_PREP_DO_NOT_OWN_BUFFER;
    512526
     527        /* The stored RT header will tell us how much data we need to read */
    513528        if (rt_read(libtrace, &packet->buffer, (size_t)RT_INFO->rt_hdr.length,
    514529                                blocking) != RT_INFO->rt_hdr.length) {
     
    516531        }
    517532
     533        /* Send an ACK if required */
    518534        if (RT_INFO->reliable > 0 && packet->type >= TRACE_RT_DATA_SIMPLE) {
    519535                if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence) == -1)
     
    521537        }
    522538       
     539        /* Convert to the original capture format */
    523540        if (rt_set_format(libtrace, packet) < 0) {
    524541                return -1;
    525542        }
    526543               
    527         /* Update payload pointers and loss counters correctly */
     544        /* Update payload pointers and packet type to match the original
     545         * format */
    528546        if (trace_prepare_packet(packet->trace, packet, packet->buffer,
    529547                                packet->type, prep_flags)) {
     
    534552}
    535553
     554/* Reads an RT packet from the network. Will block if the "blocking" flag is
     555 * set to 1, otherwise will return if insufficient data is available */
    536556static int rt_read_packet_versatile(libtrace_t *libtrace,
    537557                libtrace_packet_t *packet,int blocking) {
     
    546566        }
    547567
    548         /* RT_LAST means that the next bytes received should be a
    549          * rt header - I know it's hax and maybe I'll fix it later on */
     568        /* RT_LAST indicates that we need to read the RT header for the next
     569         * packet. This is a touch hax, I admit */
    550570        if (RT_INFO->rt_hdr.type == TRACE_RT_LAST) {
    551571                void_hdr = (void *)pkt_hdr;
     
    558578                pkt_hdr = (rt_header_t *)void_hdr;
    559579               
    560                 /* Need to salvage these in case the next rt_read overwrites
     580                /* Need to store these in case the next rt_read overwrites
    561581                 * the buffer they came from! */
    562582                RT_INFO->rt_hdr.type = pkt_hdr->type;
     
    566586        packet->type = RT_INFO->rt_hdr.type;
    567587       
     588        /* All data-bearing packets (as opposed to RT internal messages)
     589         * should be treated the same way when it comes to reading the rest
     590         * of the packet */
    568591        if (packet->type >= TRACE_RT_DATA_SIMPLE) {
    569592                switch_type = TRACE_RT_DATA_SIMPLE;
     
    607630}
    608631
     632/* Reads the next available packet in a blocking fashion */
    609633static int rt_read_packet(libtrace_t *libtrace,
    610634                libtrace_packet_t *packet) {
     
    613637
    614638
     639/* This should only get called for RT messages - RT-encapsulated data records
     640 * should be converted to the appropriate capture format */
    615641static int rt_get_capture_length(const libtrace_packet_t *packet) {
    616642        rt_metadata_t *rt_md_hdr;
     
    656682}
    657683
     684/* RT messages do not have a wire length because they were not captured from
     685 * the wire - they were generated by the capture process */
    658686static int rt_get_wire_length(UNUSED const libtrace_packet_t *packet) {
    659687        return 0;
    660688}
    661                        
     689
     690/* Although RT messages do contain "framing", this framing is considered to be
     691 * stripped as soon as the packet is read by the RT client */                   
    662692static int rt_get_framing_length(UNUSED const libtrace_packet_t *packet) {
    663693        return 0;
    664694}
    665695
     696
    666697static libtrace_linktype_t rt_get_link_type(UNUSED const libtrace_packet_t *packet)
    667698{
     699        /* RT messages don't have a link type */
    668700        return TRACE_TYPE_NONDATA;
    669701}
     
    688720        }
    689721
     722        /* Attempt to read a packet in a non-blocking fashion */
    690723        event.size = rt_read_packet_versatile(trace, packet, 0);
    691724        if (event.size == -1) {
    692725                read_err = trace_get_err(trace);
    693726                if (read_err.err_num == EAGAIN) {
     727                        /* No data available - do an IOWAIT */
    694728                        event.type = TRACE_EVENT_IOWAIT;
    695729                }
     
    698732                }
    699733        } else if (event.size == 0) {
     734                /* RT gives us a specific indicator that there will be no
     735                 * more packets. */
    700736                if (packet->type == TRACE_RT_END_DATA)
    701737                        event.type = TRACE_EVENT_TERMINATE;
    702738                else
     739                        /* Since several RT messages can have zero-byte
     740                         * length (once the framing is removed), an event size
     741                         * of zero can still indicate a PACKET event */
    703742                        event.type = TRACE_EVENT_PACKET;
    704743               
  • lib/format_tsh.c

    rd267f4d rd026488  
    22 * This file is part of libtrace
    33 *
    4  * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand.
    5  * Authors: Perry Lorier
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
     8 *          Perry Lorier
     9 *          Shane Alcock
    610 *         
    711 * All rights reserved.
     
    2731 *
    2832 */
     33
     34
    2935#include "config.h"
    3036#include "common.h"
     
    3945#include <string.h>
    4046#include <stdlib.h>
     47
     48/* This format module deals with reading traces that are in the TSH format.
     49 *
     50 * We do not support writing TSH traces, because it's a pretty rubbish format.
     51 */
    4152
    4253static struct libtrace_format_t tshformat;
Note: See TracChangeset for help on using the changeset viewer.