File: Reporter.h

package info (click to toggle)
iperf 2.0.14a%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 2,144 kB
  • sloc: ansic: 7,905; cpp: 5,443; sh: 3,784; makefile: 87
file content (516 lines) | stat: -rw-r--r-- 17,136 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
/*---------------------------------------------------------------
 * Copyright (c) 1999,2000,2001,2002,2003
 * The Board of Trustees of the University of Illinois
 * All Rights Reserved.
 *---------------------------------------------------------------
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software (Iperf) and associated
 * documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 *
 * Redistributions of source code must retain the above
 * copyright notice, this list of conditions and
 * the following disclaimers.
 *
 *
 * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimers in the documentation and/or other materials
 * provided with the distribution.
 *
 *
 * Neither the names of the University of Illinois, NCSA,
 * nor the names of its contributors may be used to endorse
 * or promote products derived from this Software without
 * specific prior written permission.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * ________________________________________________________________
 * National Laboratory for Applied Network Research
 * National Center for Supercomputing Applications
 * University of Illinois at Urbana-Champaign
 * http://www.ncsa.uiuc.edu
 * ________________________________________________________________
 *
 * Reporter.h
 * by Kevin Gibbs <kgibbs@nlanr.net>
 *
 * Since version 2.0 this handles all reporting.
 * ________________________________________________________________ */

#ifndef REPORTER_H
#define REPORTER_H

#include "headers.h"
#include "Mutex.h"
#include "histogram.h"
#include "packet_ring.h"

// forward declarations found in Settings.hpp
struct thread_Settings;
struct server_hdr;
#include "Settings.hpp"

#define NUM_REPORT_STRUCTS 10000
#define PEERVERBUFSIZE 256
#define NETPOWERCONSTANT 1e-6
#define REPORTTXTMAX 80
#define MINBARRIERTIMEOUT 3

// If the minimum latency exceeds the boundaries below
// assume the clocks are not synched and suppress the
// latency output. Units are seconds
#define UNREALISTIC_LATENCYMINMIN -1
#define UNREALISTIC_LATENCYMINMAX 60

#ifdef __cplusplus
extern "C" {
#endif

extern struct Condition ReportCond;
extern struct Condition ReportsPending;

/*
 *
 * Used for end/end latency measurements
 *
 */
struct TransitStats {
    double maxTransit;
    double minTransit;
    double sumTransit;
    double lastTransit;
    double meanTransit;
    double m2Transit;
    double vdTransit;
    int cntTransit;
    double totmaxTransit;
    double totminTransit;
    double totsumTransit;
    int totcntTransit;
    double totmeanTransit;
    double totm2Transit;
    double totvdTransit;
};

struct MeanMinMaxStats {
    double max;
    double min;
    double sum;
    double last;
    double mean;
    double m2;
    double vd;
    int cnt;
    int err;
};

#define TCPREADBINCOUNT 8
struct ReadStats {
    int cntRead;
    int totcntRead;
    int bins[TCPREADBINCOUNT];
    int totbins[TCPREADBINCOUNT];
    int binsize;
};

struct WriteStats {
    int WriteCnt;
    int WriteErr;
    int TCPretry;
    int totWriteCnt;
    int totWriteErr;
    int totTCPretry;
    int lastTCPretry;
    int cwnd;
    int rtt;
    double meanrtt;
    int up_to_date;
};

struct IsochStats {
    int mFPS; //frames per second
    double mMean; //variable bit rate mean
    double mVariance; //vbr variance
    int mJitterBufSize; //Server jitter buffer size, units is frames
    intmax_t slipcnt;
    intmax_t framecnt;
    intmax_t framelostcnt;
    unsigned int mBurstInterval;
    unsigned int mBurstIPG; //IPG of packets within the burst
    uint32_t frameID;
};

/*
 * This struct contains all important information from the sending or
 * recieving thread.
 */
#define L2UNKNOWN  0x01
#define L2LENERR   0x02
#define L2CSUMERR  0x04

enum WriteErrType {
    WriteNoErr  = 0,
    WriteErrAccount,
    WriteErrFatal,
    WriteErrNoAccount,
};

struct L2Stats {
    intmax_t cnt;
    intmax_t unknown;
    intmax_t udpcsumerr;
    intmax_t lengtherr;
    intmax_t tot_cnt;
    intmax_t tot_unknown;
    intmax_t tot_udpcsumerr;
    intmax_t tot_lengtherr;
};

/*
 * The type field of ReporterData is a bitmask
 * with one or more of the following
 */
enum ReportType {
    DATA_REPORT = 1,
    SUM_REPORT,
    SETTINGS_REPORT,
    CONNECTION_REPORT,
    SERVER_RELAY_REPORT
};

enum ReportSubType {
    FULLDUPLEXSUM_REPORT = 1,
    HOSTSUM_REPORT,
    TOTALSUM_REPORT
};

union SendReadStats {
    struct ReadStats read;
    struct WriteStats write;
};

// This attributes are shared by all reports
// deep copies are made when creating a new report
// rather than using references
struct ReportCommon {
    enum ThreadMode ThreadMode;
    int flags;
    int flags_extend;
    int threads;
    unsigned short Port;
    unsigned short BindPort;
    unsigned short ListenPort;
    intmax_t UDPRate;            // -b or -u
    int UDPRateUnits;
    char Format;
    int TTL;
    int BufLen;
    int MSS;
    int TCPWin;
    int winsize_requested;
    unsigned int FQPacingRate;
    int RXbins;
    int RXbinsize;
    int RXunits;
    double pktIPG;
    iperf_sockaddr peer;
    Socklen_t size_peer;
    iperf_sockaddr local;
    Socklen_t size_local;
    char* Host;                   // -c
    char* Localhost;              // -B
    char* Ifrname;
    char* Ifrnametx;
    char* SSMMulticastStr;
    char* Congestion;
#if WIN32
    SOCKET socket;
#else
    int socket;
#if defined(HAVE_LINUX_FILTER_H) && defined(HAVE_AF_PACKET)
    int socketdrop;
#endif
#endif
};

struct ConnectionInfo {
    struct ReportCommon *common;
    double connecttime;
    double txholdbacktime;
    struct timeval epochStartTime;
    int winsize;
    char peerversion[PEERVERBUFSIZE];
    struct MeanMinMaxStats connect_times;
    int MSS;
};

struct ReportSettings {
    struct ReportCommon *common;
    iperf_sockaddr peer;
    Socklen_t size_peer;
    iperf_sockaddr local;
    Socklen_t size_local;
    intmax_t UDPRate;            // -b or -u
    int UDPRateUnits;            // -b is either bw or pps
    int pid;
    struct IsochStats isochstats;
    void (*output_handler) (struct ReportSettings *settings);
};

// Timestamps
enum TimeStampType {
    INTERVAL  = 0,
    FINALPARTIAL,
    TOTAL,
    FRAME
};


struct ShiftIntCounter {
    intmax_t current;
    intmax_t prev;
};

struct ShiftUintCounter {
    uintmax_t current;
    uintmax_t prev;
};

struct ShiftCounters {
    struct ShiftUintCounter Bytes;
    struct ShiftIntCounter Lost;
    struct ShiftIntCounter OutofOrder;
    struct ShiftIntCounter Datagrams;
    struct ShiftIntCounter IPG;
};

struct ReportTimeStamps {
    double iStart;
    double iEnd;
    struct timeval startTime;
    struct timeval matchTime;
    struct timeval packetTime;
    struct timeval prevpacketTime;
    struct timeval nextTime;
    struct timeval intervalTime;
    struct timeval IPGstart;
};

struct TransferInfo {
    struct ReportCommon *common;
    struct ReportTimeStamps ts;
    void (*output_handler) (struct TransferInfo *stats);
    int transferID;
    int groupID;
    int threadcnt;
    int sumflag;
    uintmax_t cntBytes;
    intmax_t cntError;
    intmax_t cntOutofOrder;
    intmax_t cntDatagrams;
    intmax_t cntIPG;
    intmax_t PacketID;
    double jitter;
    double tripTime;
    double IPGsum;
    struct ShiftCounters total; // Shift counters used to calculate interval reports and hold totals
    union SendReadStats sock_callstats;
    struct IsochStats isochstats;
    struct histogram *latency_histogram;
    struct TransitStats transit;
    struct histogram *framelatency_histogram;
    struct TransitStats frame;
    struct L2Stats l2counts;
    // Packet and frame state info
    uint32_t matchframeID;
    uint32_t frameID;
    char csv_peer[CSVPEERLIMIT];
};

struct SumReport {
    struct ReferenceMutex reference;
    int threads;
    struct TransferInfo info;
    void (*transfer_protocol_sum_handler) (struct TransferInfo *stats, int final);
    struct BarrierMutex fullduplex_barrier;
};

struct ReporterData {
    // function pointer for per packet processing
    void (*packet_handler) (struct ReporterData *data, struct ReportStruct *packet);
    void (*transfer_protocol_handler) (struct ReporterData *data, int final);
    int (*transfer_interval_handler) (struct ReporterData *data, struct ReportStruct *packet);

    struct PacketRing *packetring;
    int reporter_thread_suspends; // used to detect CPU bound systems

    // group sum and full duplext reports
    struct SumReport *GroupSumReport;
    struct SumReport *FullDuplexReport;

    struct TransferInfo info;
};

struct ServerRelay {
    struct TransferInfo info;
    iperf_sockaddr peer;
    Socklen_t size_peer;
    iperf_sockaddr local;
    Socklen_t size_local;
};

struct ReportHeader {
    enum ReportType type;
    enum ReportMode ReportMode;
    void *this_report;
    struct ReportHeader *next;
};

typedef void* (* report_connection)( struct ConnectionInfo*, int );
typedef void (* report_settings)( struct ReporterData* );
typedef void (* report_statistics)( struct TransferInfo* );
typedef void (* report_serverstatistics)( struct ConnectionInfo *, struct TransferInfo* );

void SetSumHandlers (struct thread_Settings *inSettings, struct SumReport* sumreport, int fullduplex);
struct SumReport* InitSumReport(struct thread_Settings *inSettings, int inID, int fullduplex);
struct ReportHeader* InitIndividualReport(struct thread_Settings *inSettings);
struct ReportHeader* InitConnectionReport(struct thread_Settings *inSettings, double ct);
struct ConnectionInfo* InitConnectOnlyReport(struct thread_Settings *inSettings);
struct ReportHeader *InitSettingsReport(struct thread_Settings *inSettings);
struct ReportHeader* InitServerRelayUDPReport(struct thread_Settings *inSettings, struct server_hdr *server);
void PostReport(struct ReportHeader *reporthdr);
void ReportPacket(struct ReporterData *reporthdr, struct ReportStruct *packet);
int EndJob(struct ReportHeader *reporthdr,  struct ReportStruct *packet);
void FreeReport(struct ReportHeader *reporthdr);
void FreeSumReport (struct SumReport *sumreport);
void FreeConnectionReport(struct ConnectionInfo *reporthdr);
void ReportServerUDP(struct thread_Settings *inSettings, struct server_hdr *server);
void ReportConnections(struct thread_Settings *inSettings );
void reporter_dump_job_queue(void);
void IncrSumReportRefCounter(struct SumReport *multihdr);
int DecrSumReportRefCounter(struct SumReport *multihdr);

extern struct AwaitMutex reporter_state;
extern struct AwaitMutex threads_start;

extern report_connection connection_reports[];
extern report_settings settings_reports[];
extern report_statistics statistics_reports[];
extern report_serverstatistics serverstatistics_reports[];
extern report_statistics multiple_reports[];


// Packet accounting routines
void reporter_handle_packet_null(struct ReporterData *report, struct ReportStruct *packet);
void reporter_handle_packet_server_udp(struct ReporterData *report, struct ReportStruct *packet);
void reporter_handle_packet_server_tcp(struct ReporterData *report, struct ReportStruct *packet);
void reporter_handle_packet_client(struct ReporterData *report, struct ReportStruct *packet);
void reporter_handle_packet_pps(struct ReporterData *data, struct ReportStruct *packet);
void reporter_handle_packet_isochronous(struct ReporterData *data, struct ReportStruct *packet);

// Reporter's conditional prints, right now have time and frame based sampling, possibly add packet based
int reporter_condprint_time_interval_report(struct ReporterData *reporthdr, struct ReportStruct *packet);
int reporter_condprint_frame_interval_report_udp(struct ReporterData *reporthdr, struct ReportStruct *packet);
int reporter_condprint_frame_interval_report_tcp(struct ReporterData *reporthdr, struct ReportStruct *packet);
//void reporter_set_timestamps_time(struct ReporterData *stats, enum TimestampType);

// Reporter's interval ouput specialize routines
void reporter_transfer_protocol_null(struct ReporterData *stats, int final);
//void reporter_transfer_protocol_reports(struct ReporterData *stats, struct ReportStruct *packet);
//void reporter_transfer_protocol_multireports(struct ReporterData *stats, struct ReportStruct *packet);
void reporter_transfer_protocol_client_tcp(struct ReporterData *stats, int final);
void reporter_transfer_protocol_client_udp(struct ReporterData *stats, int final);
void reporter_transfer_protocol_server_tcp(struct ReporterData *stats, int final);
void reporter_transfer_protocol_server_udp(struct ReporterData *stats, int final);

// Reporter's sum ouput routines (per -P > 1)
void reporter_transfer_protocol_sum_client_tcp(struct TransferInfo *stats, int final);
void reporter_transfer_protocol_sum_server_tcp(struct TransferInfo *stats, int final);
void reporter_transfer_protocol_sum_client_udp(struct TransferInfo *stats, int final);
void reporter_transfer_protocol_sum_server_udp(struct TransferInfo *stats, int final);
void reporter_transfer_protocol_fullduplex_tcp(struct TransferInfo *stats, int final);
void reporter_transfer_protocol_fullduplex_udp(struct TransferInfo *stats, int final);


// Reporter print routines
// TCP server
void tcp_output_read(struct TransferInfo *stats);
void tcp_output_read_enhanced(struct TransferInfo *stats);
void tcp_output_read_enhanced_triptime(struct TransferInfo *stats);
void tcp_output_sum_read(struct TransferInfo *stats);
void tcp_output_sum_read_enhanced(struct TransferInfo *stats);
void tcp_output_sumcnt_read(struct TransferInfo *stats);
void tcp_output_sumcnt_read_enhanced (struct TransferInfo *stats);
// TCP client
void tcp_output_write(struct TransferInfo *stats);
void tcp_output_sum_write(struct TransferInfo *stats);
void tcp_output_sumcnt_write(struct TransferInfo *stats);
void tcp_output_write_enhanced (struct TransferInfo *stats);
void tcp_output_sum_write_enhanced (struct TransferInfo *stats);
void tcp_output_sumcnt_write_enhanced (struct TransferInfo *stats);
// TCP fullduplex
void tcp_output_fullduplex_write(struct TransferInfo *stats);
void tcp_output_fullduplex_write_enhanced(struct TransferInfo *stats);
void tcp_output_fullduplex_read(struct TransferInfo *stats);
void tcp_output_fullduplex_read_enhanced(struct TransferInfo *stats);
void tcp_output_fullduplex(struct TransferInfo *stats);
void tcp_output_fullduplex_enhanced(struct TransferInfo *stats);

// UDP server
void udp_output_read(struct TransferInfo *stats);
void udp_output_read_enhanced(struct TransferInfo *stats);
void udp_output_read_enhanced_triptime(struct TransferInfo *stats);
void udp_output_read_enhanced_triptime_isoch(struct TransferInfo *stats);
void udp_output_sum_read(struct TransferInfo *stats);
void udp_output_sumcnt_read(struct TransferInfo *stats);
void udp_output_sumcnt_read_enhanced (struct TransferInfo *stats);

//UDP client
void udp_output_write(struct TransferInfo *stats);
void udp_output_sum_write(struct TransferInfo *stats);
void udp_output_write_enhanced(struct TransferInfo *stats);
void udp_output_write_enhanced_isoch(struct TransferInfo *stats);
void udp_output_sum_write_enhanced (struct TransferInfo *stats);
void udp_output_sumcnt_write(struct TransferInfo *stats);
void udp_output_sumcnt_write_enhanced (struct TransferInfo *stats);
// UDP full duplex
void udp_output_fullduplex(struct TransferInfo *stats);
void udp_output_fullduplex_sum(struct TransferInfo *stats);
void udp_output_fullduplex_enhanced(struct TransferInfo *stats);

// CSV output
void udp_output_basic_csv(struct TransferInfo *stats);
void tcp_output_basic_csv(struct TransferInfo *stats);

// Rest of the reporter output routines
void reporter_print_connection_report(struct ConnectionInfo *report);
void reporter_print_settings_report(struct ReportSettings *report);
void reporter_print_server_relay_report(struct ServerRelay *report);
void reporter_peerversion (struct ConnectionInfo *report, uint32_t upper, uint32_t lower);
void PrintMSS(struct ReporterData *data);
void reporter_default_heading_flags(int);
void reporter_connect_printf_tcp_final(struct ConnectionInfo *report);

void write_UDP_AckFIN(struct TransferInfo *stats);

int reporter_process_transfer_report (struct ReporterData *this_ireport);
int reporter_process_report (struct ReportHeader *reporthdr);

#ifdef __cplusplus
} /* end extern "C" */
#endif

#endif // REPORTER_H