source: test/test-format-parallel-reporter.c @ d994324

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d994324 was d994324, checked in by Richard Sanger <rsangerarj@…>, 6 years ago

Remove anything to do with the combiner from set configuration and removes any options/storage related to these such as the next expected packet.

Instead this is done using trace_set_combiner now, and the for the built-in combiners.h header. This is a lot more flexible and allows the users to specify there own combiner, and any number of options for it.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: test-rtclient.c,v 1.2 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#ifndef WIN32
31#  include <sys/time.h>
32#  include <netinet/in.h>
33#  include <netinet/in_systm.h>
34#  include <netinet/tcp.h>
35#  include <netinet/ip.h>
36#  include <netinet/ip_icmp.h>
37#  include <arpa/inet.h>
38#  include <sys/socket.h>
39#endif
40#include <stdio.h>
41#include <stdlib.h>
42#include <assert.h>
43#include <string.h>
44#include <sys/types.h>
45#include <time.h>
46#include <string.h>
47#include <signal.h>
48#include <unistd.h>
49
50#include "dagformat.h"
51#include "libtrace.h"
52#include "data-struct/vector.h"
53#include "combiners.h"
54
55void iferr(libtrace_t *trace,const char *msg)
56{
57        libtrace_err_t err = trace_get_err(trace);
58        if (err.err_num==0)
59                return;
60        printf("Error: %s: %s\n", msg, err.problem);
61        exit(1);
62}
63
64const char *lookup_uri(const char *type) {
65        if (strchr(type,':'))
66                return type;
67        if (!strcmp(type,"erf"))
68                return "erf:traces/100_packets.erf";
69        if (!strcmp(type,"rawerf"))
70                return "rawerf:traces/100_packets.erf";
71        if (!strcmp(type,"pcap"))
72                return "pcap:traces/100_packets.pcap";
73        if (!strcmp(type,"wtf"))
74                return "wtf:traces/wed.wtf";
75        if (!strcmp(type,"rtclient"))
76                return "rtclient:chasm";
77        if (!strcmp(type,"pcapfile"))
78                return "pcapfile:traces/100_packets.pcap";
79        if (!strcmp(type,"pcapfilens"))
80                return "pcapfile:traces/100_packetsns.pcap";
81        if (!strcmp(type, "duck"))
82                return "duck:traces/100_packets.duck";
83        if (!strcmp(type, "legacyatm"))
84                return "legacyatm:traces/legacyatm.gz";
85        if (!strcmp(type, "legacypos"))
86                return "legacypos:traces/legacypos.gz";
87        if (!strcmp(type, "legacyeth"))
88                return "legacyeth:traces/legacyeth.gz";
89        if (!strcmp(type, "tsh"))
90                return "tsh:traces/10_packets.tsh.gz";
91        return type;
92}
93
94int globalcount = 0;
95
96static void reporter(libtrace_t *libtrace, libtrace_result_t *res, libtrace_message_t *mesg) {
97        static uint64_t last = -1;
98        static int pktcount = 0;
99        if (res) {
100                libtrace_packet_t *packet = libtrace_result_get_value(res).pkt;
101                assert(libtrace_result_get_key(res) == trace_packet_get_order(packet));
102                if(last == (uint64_t)-1) {
103                        last = libtrace_result_get_key(res);
104                } else {
105                assert (last < libtrace_result_get_key(res));
106                last = libtrace_result_get_key(res);
107                }
108                pktcount++;
109                trace_free_result_packet(libtrace, packet);
110        } else {
111                // Mesg
112                switch (mesg->code) {
113                case MESSAGE_STOPPING:
114                        globalcount = pktcount;
115                default:
116                        break;
117                }
118        }
119}
120
121static void* per_packet(libtrace_t *trace, libtrace_packet_t *pkt, 
122                                                libtrace_message_t *mesg,
123                                                libtrace_thread_t *t) {
124        UNUSED static __thread int x = 0;
125        if (pkt) {
126                int a,*b,c=0;
127                // Do some work to even out the load on cores
128                b = &c;
129                for (a = 0; a < 10000000; a++) {
130                        c += a**b;
131                }
132                x = c;
133                trace_publish_result(trace, t, trace_packet_get_order(pkt), (libtrace_generic_types_t){.pkt=pkt}, RESULT_PACKET);
134                return NULL;
135        }
136        else switch (mesg->code) {
137                // We don't care we have no state
138                default:
139                        break;
140        }
141        return pkt;
142}
143
144int main(int argc, char *argv[]) {
145        int error = 0;
146        int expected = 100;
147        const char *tracename;
148        libtrace_t *trace;
149
150        if (argc<2) {
151                fprintf(stderr,"usage: %s type\n",argv[0]);
152                return 1;
153        }
154
155        tracename = lookup_uri(argv[1]);
156
157        trace = trace_create(tracename);
158        iferr(trace,tracename);
159
160        if (strcmp(argv[1],"rtclient")==0) expected=101;
161
162        trace_set_combiner(trace, &combiner_ordered, (libtrace_generic_types_t){0});
163
164        trace_pstart(trace, NULL, per_packet, reporter);
165        iferr(trace,tracename);
166
167        /* Make sure traces survive a pause */
168        trace_ppause(trace);
169        iferr(trace,tracename);
170        trace_pstart(trace, NULL, NULL, NULL);
171        iferr(trace,tracename);
172
173        /* Wait for all threads to stop */
174        trace_join(trace);
175
176        if (error == 0) {
177                if (globalcount == expected) {
178                        printf("success: %d packets read\n",expected);
179                } else {
180                        printf("failure: %d packets expected, %d seen\n",expected,globalcount);
181                        error = 1;
182                }
183        } else {
184                iferr(trace,tracename);
185        }
186        trace_destroy(trace);
187        return error;
188}
Note: See TracBrowser for help on using the repository browser.