- Timestamp:
- 02/09/10 10:05:10 (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:
- 8414770
- Parents:
- 238d50a
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_rt.c
r226c08b rd026488 2 2 * This file is part of libtrace 3 3 * 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 6 8 * Perry Lorier 7 * Shane Alcock8 * 9 * Shane Alcock 10 * 9 11 * All rights reserved. 10 12 * 11 * This code has been developed by the University of Waikato WAND 13 * This code has been developed by the University of Waikato WAND 12 14 * research group. For further information please see http://www.wand.net.nz/ 13 15 * … … 29 31 * 30 32 */ 33 31 34 32 35 #define _GNU_SOURCE … … 54 57 #define RT_INFO ((struct rt_format_data_t*)libtrace->format_data) 55 58 59 /* Convert the RT denial code into a nice printable and coherent string */ 56 60 static const char *rt_deny_reason(enum rt_conn_denied_t reason) 57 61 { … … 77 81 78 82 struct rt_format_data_t { 83 /* Name of the host to connect to */ 79 84 char *hostname; 85 /* Buffer to store received packets into */ 80 86 char *pkt_buffer; 87 /* Pointer to the next packet to be read from the buffer */ 81 88 char *buf_current; 89 /* Amount of buffer space used */ 82 90 size_t buf_filled; 91 /* The port to connect to */ 83 92 int port; 93 /* The file descriptor for the RT connection */ 84 94 int input_fd; 95 /* Flag indicating whether the server is doing reliable RT */ 85 96 int reliable; 97 98 /* Header for the packet currently being received */ 86 99 rt_header_t rt_hdr; 87 100 101 /* Dummy traces that can be assigned to the received packets to ensure 102 * that the appropriate functions can be used to process them */ 88 103 libtrace_t *dummy_duck; 89 104 libtrace_t *dummy_erf; … … 92 107 }; 93 108 109 /* Connects to an RT server 110 * 111 * Returns -1 if an error occurs 112 */ 94 113 static int rt_connect(libtrace_t *libtrace) { 95 114 struct hostent *he; … … 125 144 } 126 145 127 128 #if 0129 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 #endif144 145 146 146 /* We are connected, now receive message from server */ 147 147 … … 155 155 switch (connect_msg.type) { 156 156 case TRACE_RT_DENY_CONN: 157 /* Connection was denied */ 157 158 158 159 if (recv(RT_INFO->input_fd, (void*)&deny_hdr, … … 167 168 return -1; 168 169 case TRACE_RT_HELLO: 169 /* do something with options */ 170 /* Hello message - read the options sent to us by the 171 * server */ 170 172 if (recv(RT_INFO->input_fd, (void*)&hello_opts, 171 173 sizeof(rt_hello_t), 0) … … 208 210 209 211 rt_init_format_data(libtrace); 210 212 213 /* If the user specifies "rt:" then assume localhost and the default 214 * port */ 211 215 if (strlen(uridata) == 0) { 212 216 RT_INFO->hostname = … … 215 219 COLLECTOR_PORT; 216 220 } 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) { 218 224 RT_INFO->hostname = 219 225 strdup(uridata); … … 271 277 272 278 static int rt_fin_input(libtrace_t *libtrace) { 279 /* Make sure we clean up any dummy traces that we have been using */ 280 273 281 if (RT_INFO->dummy_duck) 274 282 trace_destroy_dead(RT_INFO->dummy_duck); … … 299 307 #define RT_BUF_SIZE 10000U 300 308 309 /* Receives data from an RT server */ 301 310 static int rt_read(libtrace_t *libtrace, void **buffer, size_t len, int block) 302 311 { … … 320 329 block=MSG_DONTWAIT; 321 330 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 */ 323 334 if (len > RT_INFO->buf_filled) { 324 335 memcpy(RT_INFO->pkt_buffer, RT_INFO->buf_current, … … 328 339 # define MSG_NOSIGNAL 0 329 340 #endif 341 /* Loop as long as we don't have all the data that we were 342 * asked for */ 330 343 while (len > RT_INFO->buf_filled) { 331 344 if ((numbytes = recv(RT_INFO->input_fd, … … 347 360 } 348 361 if (errno == EAGAIN) { 362 /* We asked for non-blocking mode, so 363 * we need to return now */ 349 364 trace_set_err(libtrace, 350 365 EAGAIN, … … 358 373 return -1; 359 374 } 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 */369 375 RT_INFO->buf_filled+=numbytes; 370 376 } … … 378 384 379 385 386 /* Sets the trace format for the packet to match the format it was originally 387 * captured in, rather than the RT format */ 380 388 static int rt_set_format(libtrace_t *libtrace, libtrace_packet_t *packet) 381 389 { 390 391 /* We need to assign the packet to a "dead" trace */ 382 392 383 393 /* Try to minimize the number of corrupt packets that slip through … … 431 441 } 432 442 443 /* Sends an RT ACK to the server to acknowledge receipt of packets */ 433 444 static int rt_send_ack(libtrace_t *libtrace, 434 445 uint32_t seqno) { … … 457 468 buf_ptr = ack_buffer; 458 469 470 /* Keep trying until we write the entire ACK */ 459 471 while (to_write > 0) { 460 472 numbytes = send(RT_INFO->input_fd, buf_ptr, to_write, 0); … … 479 491 } 480 492 493 /* Shouldn't need to call this too often */ 481 494 static int rt_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 482 495 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { … … 505 518 } 506 519 520 /* Reads the body of an RT packet from the network */ 507 521 static int rt_read_data_packet(libtrace_t *libtrace, 508 522 libtrace_packet_t *packet, int blocking) { … … 511 525 prep_flags |= TRACE_PREP_DO_NOT_OWN_BUFFER; 512 526 527 /* The stored RT header will tell us how much data we need to read */ 513 528 if (rt_read(libtrace, &packet->buffer, (size_t)RT_INFO->rt_hdr.length, 514 529 blocking) != RT_INFO->rt_hdr.length) { … … 516 531 } 517 532 533 /* Send an ACK if required */ 518 534 if (RT_INFO->reliable > 0 && packet->type >= TRACE_RT_DATA_SIMPLE) { 519 535 if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence) == -1) … … 521 537 } 522 538 539 /* Convert to the original capture format */ 523 540 if (rt_set_format(libtrace, packet) < 0) { 524 541 return -1; 525 542 } 526 543 527 /* Update payload pointers and loss counters correctly */ 544 /* Update payload pointers and packet type to match the original 545 * format */ 528 546 if (trace_prepare_packet(packet->trace, packet, packet->buffer, 529 547 packet->type, prep_flags)) { … … 534 552 } 535 553 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 */ 536 556 static int rt_read_packet_versatile(libtrace_t *libtrace, 537 557 libtrace_packet_t *packet,int blocking) { … … 546 566 } 547 567 548 /* RT_LAST means that the next bytes received should be a549 * 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 */ 550 570 if (RT_INFO->rt_hdr.type == TRACE_RT_LAST) { 551 571 void_hdr = (void *)pkt_hdr; … … 558 578 pkt_hdr = (rt_header_t *)void_hdr; 559 579 560 /* Need to s alvage these in case the next rt_read overwrites580 /* Need to store these in case the next rt_read overwrites 561 581 * the buffer they came from! */ 562 582 RT_INFO->rt_hdr.type = pkt_hdr->type; … … 566 586 packet->type = RT_INFO->rt_hdr.type; 567 587 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 */ 568 591 if (packet->type >= TRACE_RT_DATA_SIMPLE) { 569 592 switch_type = TRACE_RT_DATA_SIMPLE; … … 607 630 } 608 631 632 /* Reads the next available packet in a blocking fashion */ 609 633 static int rt_read_packet(libtrace_t *libtrace, 610 634 libtrace_packet_t *packet) { … … 613 637 614 638 639 /* This should only get called for RT messages - RT-encapsulated data records 640 * should be converted to the appropriate capture format */ 615 641 static int rt_get_capture_length(const libtrace_packet_t *packet) { 616 642 rt_metadata_t *rt_md_hdr; … … 656 682 } 657 683 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 */ 658 686 static int rt_get_wire_length(UNUSED const libtrace_packet_t *packet) { 659 687 return 0; 660 688 } 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 */ 662 692 static int rt_get_framing_length(UNUSED const libtrace_packet_t *packet) { 663 693 return 0; 664 694 } 665 695 696 666 697 static libtrace_linktype_t rt_get_link_type(UNUSED const libtrace_packet_t *packet) 667 698 { 699 /* RT messages don't have a link type */ 668 700 return TRACE_TYPE_NONDATA; 669 701 } … … 688 720 } 689 721 722 /* Attempt to read a packet in a non-blocking fashion */ 690 723 event.size = rt_read_packet_versatile(trace, packet, 0); 691 724 if (event.size == -1) { 692 725 read_err = trace_get_err(trace); 693 726 if (read_err.err_num == EAGAIN) { 727 /* No data available - do an IOWAIT */ 694 728 event.type = TRACE_EVENT_IOWAIT; 695 729 } … … 698 732 } 699 733 } else if (event.size == 0) { 734 /* RT gives us a specific indicator that there will be no 735 * more packets. */ 700 736 if (packet->type == TRACE_RT_END_DATA) 701 737 event.type = TRACE_EVENT_TERMINATE; 702 738 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 */ 703 742 event.type = TRACE_EVENT_PACKET; 704 743 -
lib/format_tsh.c
rd267f4d rd026488 2 2 * This file is part of libtrace 3 3 * 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 6 10 * 7 11 * All rights reserved. … … 27 31 * 28 32 */ 33 34 29 35 #include "config.h" 30 36 #include "common.h" … … 39 45 #include <string.h> 40 46 #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 */ 41 52 42 53 static struct libtrace_format_t tshformat;
Note: See TracChangeset
for help on using the changeset viewer.