- Timestamp:
- 02/08/10 14:11:04 (12 years ago)
- 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:
- 238d50a
- Parents:
- 81c0b9e
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_duck.c
r1aa4bf7 r5511c14 2 2 * This file is part of libtrace 3 3 * 4 * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand. 4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, 5 * New Zealand. 6 * 5 7 * Authors: Daniel Lawson 6 * Perry Lorier 8 * Perry Lorier 9 * Shane Alcock 7 10 * 8 11 * All rights reserved. … … 41 44 #include <stdio.h> 42 45 #include <fcntl.h> 46 47 /* This format module deals with reading and writing DUCK records. 48 * 49 * Both DUCK record types (the DAG 2.4 and 2.5 versions) are supported by this 50 * module. 51 * 52 * We differentiate between DUCK versions by writing the RT type to the start 53 * of the DUCK trace. This means that this code can only read DUCK files that 54 * were written using libtrace 3. 55 */ 43 56 44 57 #define DATA(x) ((struct duck_format_data_t *)x->format_data) -
lib/format_erf.c
r3d9cf9f r5511c14 2 2 * This file is part of libtrace 3 3 * 4 * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand. 4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, 5 * New Zealand. 6 * 5 7 * Authors: Daniel Lawson 6 * Perry Lorier 8 * Perry Lorier 9 * Shane Alcock 7 10 * 8 11 * All rights reserved. … … 28 31 * 29 32 */ 33 34 30 35 #define _GNU_SOURCE 31 36 … … 57 62 #endif 58 63 59 60 #define COLLECTOR_PORT 3435 64 /* This format module deals with reading and writing ERF traces. ERF is the 65 * trace format developed by Endace for use by DAG hardware capture cards. 66 * 67 * ERF is not a live capture format. 68 * 69 */ 70 61 71 62 72 static struct libtrace_format_t erfformat; … … 66 76 67 77 #define IN_OPTIONS DATA(libtrace)->options 68 #define OUTPUT DATAOUT(libtrace) ->output78 #define OUTPUT DATAOUT(libtrace) 69 79 #define OUT_OPTIONS DATAOUT(libtrace)->options 80 81 /* "Global" data that is stored for each ERF input trace */ 70 82 struct erf_format_data_t { 71 83 84 /* Index used for seeking within a trace */ 72 85 struct { 86 /* The index itself */ 73 87 io_t *index; 88 /* The offset of the index */ 74 89 off_t index_len; 90 /* Indicates the existence of an index */ 75 91 enum { INDEX_UNKNOWN=0, INDEX_NONE, INDEX_EXISTS } exists; 76 92 } seek; 77 93 94 /* Number of packets that were dropped during the capture */ 78 95 uint64_t drops; 96 97 /* Config options for the input trace */ 79 98 struct { 99 /* Flag indicating whether the event API should replicate the 100 * time gaps between each packet or return a PACKET event for 101 * each packet */ 80 102 int real_time; 81 103 } options; 82 104 }; 83 105 106 /* "Global" data that is stored for each ERF output trace */ 84 107 struct erf_format_data_out_t { 85 union { 86 struct { 87 int level; 88 int fileflag; 89 } erf; 90 108 109 /* Config options for the output trace */ 110 struct { 111 /* Compression level for the output file */ 112 int level; 113 /* File flags used to open the file, e.g. O_CREATE */ 114 int fileflag; 91 115 } options; 92 93 union { 94 int fd; 95 struct rtserver_t * rtserver; 96 iow_t *file; 97 } output; 116 117 /* The output file itself */ 118 iow_t *file; 119 98 120 }; 99 100 /** Structure holding status information for a packet */101 typedef struct libtrace_packet_status {102 uint8_t type;103 uint8_t reserved;104 uint16_t message;105 } libtrace_packet_status_t;106 121 107 122 typedef struct erf_index_t { … … 111 126 112 127 113 /* Dag erf etherpackets have a 2 byte padding before the packet114 * so that the ipheader is aligned on a 32 bit boundary.128 /* Ethernet packets have a 2 byte padding before the packet 129 * so that the IP header is aligned on a 32 bit boundary. 115 130 */ 116 131 static int erf_get_padding(const libtrace_packet_t *packet) … … 138 153 } 139 154 155 /* Attempts to determine whether a given trace file is using the ERF format 156 * 157 * Returns 1 if the trace is probably ERF, 0 otherwise 158 */ 140 159 static int erf_probe_magic(io_t *io) 141 160 { … … 278 297 } 279 298 299 /* Seek within an ERF trace based on an ERF timestamp */ 280 300 static int erf_seek_erf(libtrace_t *libtrace,uint64_t erfts) 281 301 { … … 328 348 libtrace->format_data = malloc(sizeof(struct erf_format_data_out_t)); 329 349 330 OUT_OPTIONS. erf.level = 0;331 OUT_OPTIONS. erf.fileflag = O_CREAT | O_WRONLY;332 OUTPUT .file = 0;350 OUT_OPTIONS.level = 0; 351 OUT_OPTIONS.fileflag = O_CREAT | O_WRONLY; 352 OUTPUT->file = 0; 333 353 334 354 return 0; 335 355 } 336 356 337 static int erf_config_output(libtrace_out_t *libtrace, trace_option_output_t option,338 void *value) {357 static int erf_config_output(libtrace_out_t *libtrace, 358 trace_option_output_t option, void *value) { 339 359 340 360 switch (option) { 341 361 case TRACE_OPTION_OUTPUT_COMPRESS: 342 OUT_OPTIONS. erf.level = *(int*)value;362 OUT_OPTIONS.level = *(int*)value; 343 363 return 0; 344 364 case TRACE_OPTION_OUTPUT_FILEFLAGS: 345 OUT_OPTIONS. erf.fileflag = *(int*)value;365 OUT_OPTIONS.fileflag = *(int*)value; 346 366 return 0; 347 367 default: … … 363 383 364 384 static int erf_fin_output(libtrace_out_t *libtrace) { 365 if (OUTPUT .file)366 wandio_wdestroy(OUTPUT .file);385 if (OUTPUT->file) 386 wandio_wdestroy(OUTPUT->file); 367 387 free(libtrace->format_data); 368 388 return 0; … … 391 411 if (erfptr->flags.rxerror == 1) { 392 412 packet->payload = NULL; 393 /* XXX: Do we want to do this? We never used to do this394 395 erfptr->rlen = htons(erf_get_framing_length(packet));396 */397 413 } else { 398 414 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); … … 452 468 453 469 if (size >= LIBTRACE_PACKET_BUFSIZE) { 454 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Packet size %u larger than supported by libtrace - packet is probably corrupt", size); 470 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 471 "Packet size %u larger than supported by libtrace - packet is probably corrupt", 472 size); 455 473 return -1; 456 474 } 457 475 458 476 /* Unknown/corrupt */ 459 if (((dag_record_t *)packet->buffer)->type >= TYPE_AAL2) { 460 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Corrupt or Unknown ERF type"); 477 if (((dag_record_t *)packet->buffer)->type >= TYPE_RAW_LINK) { 478 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 479 "Corrupt or Unknown ERF type"); 461 480 return -1; 462 481 } … … 467 486 (size_t)size)) != (int)size) { 468 487 if (numbytes==-1) { 469 trace_set_err(libtrace,errno, "read(%s)", libtrace->uridata); 488 trace_set_err(libtrace,errno, "read(%s)", 489 libtrace->uridata); 470 490 return -1; 471 491 } 472 trace_set_err(libtrace,EIO,"Truncated packet (wanted %d, got %d)", size, numbytes); 492 trace_set_err(libtrace,EIO, 493 "Truncated packet (wanted %d, got %d)", 494 size, numbytes); 473 495 /* Failed to read the full packet? must be EOF */ 474 496 return -1; 475 497 } 476 498 477 if (erf_prepare_packet(libtrace, packet, packet->buffer, TRACE_RT_DATA_ERF, flags)) 499 if (erf_prepare_packet(libtrace, packet, packet->buffer, 500 TRACE_RT_DATA_ERF, flags)) 478 501 return -1; 479 502 … … 487 510 488 511 if ((numbytes = 489 wandio_wwrite(OUTPUT .file,512 wandio_wwrite(OUTPUT->file, 490 513 erfptr, 491 514 (size_t)(dag_record_size + pad))) … … 497 520 498 521 size=ntohs(erfptr->rlen)-(dag_record_size+pad); 499 numbytes=wandio_wwrite(OUTPUT .file, buffer, (size_t)size);522 numbytes=wandio_wwrite(OUTPUT->file, buffer, (size_t)size); 500 523 if (numbytes != size) { 501 524 trace_set_err_out(libtrace,errno, … … 508 531 static int erf_start_output(libtrace_out_t *libtrace) 509 532 { 510 OUTPUT .file = trace_open_file_out(libtrace,511 OUT_OPTIONS. erf.level,512 OUT_OPTIONS. erf.fileflag);513 if (!OUTPUT .file) {533 OUTPUT->file = trace_open_file_out(libtrace, 534 OUT_OPTIONS.level, 535 OUT_OPTIONS.fileflag); 536 if (!OUTPUT->file) { 514 537 return -1; 515 538 } … … 550 573 void *payload = packet->payload; 551 574 552 assert(OUTPUT .file);575 assert(OUTPUT->file); 553 576 554 577 if (!packet->header) { … … 579 602 } else { 580 603 dag_record_t erfhdr; 604 int rlen; 581 605 /* convert format - build up a new erf header */ 582 606 /* Timestamp */ … … 601 625 assert(erf_get_framing_length(packet)>0 602 626 && trace_get_framing_length(packet)<=65536); 603 assert( 604 trace_get_capture_length(packet)+erf_get_framing_length(packet)>0605 &&trace_get_capture_length(packet)+erf_get_framing_length(packet)<=65536);606 erfhdr.rlen = htons(trace_get_capture_length(packet)607 + erf_get_framing_length(packet));627 628 rlen = trace_get_capture_length(packet) + 629 erf_get_framing_length(packet); 630 assert(rlen > 0 && rlen <= 65536); 631 erfhdr.rlen = htons(rlen); 608 632 /* loss counter. Can't do this */ 609 633 erfhdr.lctr = 0; … … 676 700 assert(packet); 677 701 if(size > trace_get_capture_length(packet)) { 678 /* can't make a packet larger */702 /* Can't make a packet larger */ 679 703 return trace_get_capture_length(packet); 680 704 } … … 691 715 struct libtrace_eventobj_t event = {0,0,0.0,0}; 692 716 717 /* If we are being told to replay packets as fast as possible, then 718 * we just need to read and return the next packet in the trace */ 693 719 if (IN_OPTIONS.real_time) { 694 720 event.size = erf_read_packet(libtrace, packet); … … 700 726 701 727 } else { 728 /* Otherwise, use the generic event function */ 702 729 return trace_event_trace(libtrace, packet); 703 730 } … … 728 755 printf("\n"); 729 756 printf("\te.g.: erf:/tmp/trace\n"); 730 printf("\n");731 printf("Supported output options:\n");732 printf("\t-z\tSpecify the gzip compression, ranging from 0 (uncompressed) to 9 - defaults to 1\n");733 757 printf("\n"); 734 758
Note: See TracChangeset
for help on using the changeset viewer.