Ignore:
Timestamp:
02/04/10 10:36:53 (12 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:
43c00e5
Parents:
2c743a7
Message:
  • Updated internal documentation and licensing for several format modules
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_atmhdr.c

    r1aa4bf7 r5952ff0  
     1/*
     2 * This file is part of libtrace
     3 *
     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
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 * $Id$
     31 *
     32 */
     33
    134#define _GNU_SOURCE
    235
     
    1649#include <stdlib.h>
    1750
     51/* This particular format covers the ATM cell header capture format used to
     52 * take the Auckland VII trace set.
     53 *
     54 * Each capture record contains only a timestamp and the first four bytes of
     55 * the ATM header - nothing else.
     56 *
     57 * As a result, there isn't a lot you can actually do with these traces!
     58 *
     59 * Libtrace does not support writing using this format, because it is so
     60 * useless :)
     61 */
     62
     63/* Returns the size of the ATM cell framing header */
    1864static int atmhdr_get_framing_length(const libtrace_packet_t *packet UNUSED)
    1965{
     
    2167}
    2268
     69/* Initialise an input trace to read an ATM cell header capture */
    2370static int atmhdr_init_input(libtrace_t *libtrace) {
    2471        libtrace->format_data = NULL; /* No format data needed */
     
    2673}
    2774
     75/* Start an ATM cell header input trace */
    2876static int atmhdr_start_input(libtrace_t *libtrace)
    2977{
     
    3684}
    3785
     86/* Close an ATM cell header input trace */
    3887static int atmhdr_fin_input(libtrace_t *libtrace)
    3988{
     
    4291}
    4392
     93
     94/* Converts a buffer containing a recently read ATM cell header record into
     95 * a libtrace packet */
    4496static int atmhdr_prepare_packet(libtrace_t *libtrace,
    4597                libtrace_packet_t *packet, void *buffer,
    4698                libtrace_rt_types_t rt_type, uint32_t flags) {
    4799
     100        /* If the packet previously owned a buffer that was not the buffer
     101         * containing the new packet data, we need to free the old one to
     102         * avoid leaking memory */
    48103        if (packet->buffer != buffer &&
    49104                        packet->buf_control == TRACE_CTRL_PACKET) {
     
    51106        }
    52107
     108        /* Set the buffer owner appropriately */
    53109        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
    54110                packet->buf_control = TRACE_CTRL_PACKET;
     
    56112                packet->buf_control = TRACE_CTRL_EXTERNAL;
    57113
     114        /* Update the packet pointers appropriately */
    58115        packet->buffer = buffer;
    59116        packet->header = buffer;
    60117        packet->payload = (void*)((char*)packet->buffer +
    61118                        libtrace->format->get_framing_length(packet));
     119
     120        /* Set the packet type */
    62121        packet->type = rt_type;
    63122
    64         if (libtrace->format_data == NULL) {
    65                 if (atmhdr_init_input(libtrace))
    66                         return -1;
    67         }
    68123        return 0;
    69124}
    70125
     126/* Reads the next ATM cell header record from the given trace and writes it
     127 * into a libtrace packet */
    71128static int atmhdr_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
    72129        int numbytes;
     
    74131        uint32_t flags = 0;
    75132       
     133        /* Make sure we have a buffer available to read the next record into */
    76134        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    77135                packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
     
    82140        packet->type = TRACE_RT_DATA_ATMHDR;
    83141
     142        /* The records are a fixed size so we can read the entire record in
     143         * one go */
    84144        if ((numbytes=wandio_read(libtrace->io, buffer, (size_t)12)) != 12)
    85145        {
     
    90150        }
    91151
     152        /* Update all our packet pointers appropriately */
    92153        if (atmhdr_prepare_packet(libtrace, packet, buffer,
    93154                                TRACE_RT_DATA_ATMHDR, flags)) {
     
    99160}
    100161
     162/* Get the link type for an ATM cell header record */
    101163static libtrace_linktype_t atmhdr_get_link_type(const libtrace_packet_t *packet UNUSED) {
     164        /* Unsurprisingly, we're always going to be an ATM header */
    102165        return TRACE_TYPE_ATM;
    103166}
    104167
     168/* Get the capture length for an ATM cell header record */
    105169static int atmhdr_get_capture_length(const libtrace_packet_t *packet UNUSED) {
     170        /* There is always 4 bytes of ATM header retained by this format */
    106171        return 4;
    107172}
    108173
     174/* Get the wire length for an ATM cell header record */
    109175static int atmhdr_get_wire_length(const libtrace_packet_t *packet UNUSED) {
     176        /* ATM packets are 53 byte fixed length records */
    110177        return 53;
    111178}
    112179
     180/* Returns the timestamp for an ATM cell header record in the ERF timestamp
     181 * format */
    113182static uint64_t atmhdr_get_erf_timestamp(const libtrace_packet_t *packet) {
    114183        uint64_t ts;
    115184        atmhdr_t *atm = (atmhdr_t *)packet->header;
     185       
     186        /* Basically, the capture format header is an ERF timestamp except
     187         * the two 32-bit segments are reversed */
    116188        ts = (uint64_t)atm->ts_fraction + ((uint64_t)atm->ts_sec << 32);
    117189
Note: See TracChangeset for help on using the changeset viewer.