File: Reporter.h

package info (click to toggle)
iperf 2.0.12%2Bdfsg1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,860 kB
  • sloc: ansic: 6,120; cpp: 4,352; sh: 3,784; makefile: 86
file content (443 lines) | stat: -rw-r--r-- 13,365 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
/*---------------------------------------------------------------
 * 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"
#ifdef HAVE_UDPTRIGGERS
#include "ioctls.h"
#endif

struct thread_Settings;
struct server_hdr;

#include "Settings.hpp"

#define NUM_REPORT_STRUCTS 10000
#define NUM_MULTI_SLOTS    5
// 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

/*
 *
 * Used for end/end latency measurements
 *
 */
typedef 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;
} TransitStats;

typedef struct ReadStats {
    int cntRead;
    int totcntRead;
    int bins[8];
    int totbins[8];
    int binsize;
} ReadStats;

typedef struct WriteStats {
    int WriteCnt;
    int WriteErr;
    int TCPretry;
    int totWriteCnt;
    int totWriteErr;
    int totTCPretry;
    int lastTCPretry;
    int cwnd;
    int rtt;
} WriteStats;

#ifdef HAVE_ISOCHRONOUS
typedef 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
    max_size_t slipcnt;
    max_size_t framecnt;
    max_size_t framelostcnt;
    unsigned int mBurstInterval;
    unsigned int mBurstIPG; //IPG of packets within the burst
    int frameID;
} IsochStats;
#endif

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

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


#ifdef HAVE_UDPTRIGGERS
/*
 *  FW timestamps are broken accross packets, the rx comes first
 *  then the tx
 *
 *
 *                +--------+--------+--------+--------+
 *            7   |        fw rx ts 1 (mac)           |
 *                +--------+--------+--------+--------+
 *            8   |        fw rx ts 2 (pcie)          |
 *                +--------+--------+--------+--------+
 *            9   |     type (0x2)  |      cnt (1)    |    fw tx tlv
 *                +--------+--------+--------+--------+
 *            10  |        seqno lower                |
 *                +--------+--------+--------+--------+
 *            11  |        iperf tv_sec               |
 *                +--------+--------+--------+--------+
 *            12  |        iperf tv_usec              |
 *                +--------+--------+--------+--------+
 *            13  |        seqno upper ??             |
 *                +--------+--------+--------+--------+
 *            14  |        fw tx ts 1 pcie            |
 *                +--------+--------+--------+--------+
 *            15  |        fw tx ts 2 tx dma          |
 *                +--------+--------+--------+--------+
 *            16  |        fw tx ts 3 tx status       |
 *                +--------+--------+--------+--------+
 *            17  |        fw tx ts 4 pcie rt         |
 *                +--------+--------+--------+--------+
 *
 * TSF histograms
 * hs1 = 14,8
 * hs2 = 15,7
 * hs3 = 14,17
 * hs4 = 15,16
 * hs5 = 7,8
 */

typedef struct fwtsf_report_entry_t {
    u_int32_t tsf_rxmac; // 7
    u_int32_t tsf_rxpcie; // 8
    u_int32_t tsf_txpcie; // 14
    u_int32_t tsf_txdma; // 15
    u_int32_t tsf_txstatus; // 16
    u_int32_t tsf_txpciert; // 17
} fwtsf_report_entry_t;
#endif

typedef struct ReportStruct {
    max_size_t packetID;
    umax_size_t packetLen;
    struct timeval packetTime;
    struct timeval sentTime;
    int errwrite;
    int emptyreport;
    int socket;
    int l2errors;
    int l2len;
    int expected_l2len;
#ifdef HAVE_ISOCHRONOUS
    struct timeval isochStartTime;
    max_size_t prevframeID;
    max_size_t frameID;
    max_size_t burstsize;
    max_size_t burstperiod;
    max_size_t remaining;
#endif
#ifdef HAVE_UDPTRIGGERS
#define MAXTSFCHAIN 1470/32
    struct timeval hostTxTime;
    struct timeval hostRxTime;
    struct timespec ref_sync;
    struct timespec gps_sync;
    bool hashcollision;
    int tsfcount;
    struct fwtsf_report_entry_t tsf[MAXTSFCHAIN];
#endif
} ReportStruct;

/*
 * The type field of ReporterData is a bitmask
 * with one or more of the following
 */
#define    TRANSFER_REPORT      0x00000001
#define    SERVER_RELAY_REPORT  0x00000002
#define    SETTINGS_REPORT      0x00000004
#define    CONNECTION_REPORT    0x00000008
#define    MULTIPLE_REPORT      0x00000010

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

typedef struct Transfer_Info {
    void *reserved_delay;
    int transferID;
    int groupID;
    max_size_t cntError;
    max_size_t cntOutofOrder;
    max_size_t cntDatagrams;
    max_size_t IPGcnt;
    int socket;
    TransitStats transit;
    SendReadStats sock_callstats;
    // Hopefully int64_t's
    umax_size_t TotalLen;
    double jitter;
    double startTime;
    double endTime;
    double IPGsum;
    // chars
    char   mFormat;                 // -f
    char   mEnhanced;               // -e
    u_char mTTL;                    // -T
    char   mUDP;
    char   mTCP;
    char   free;
    histogram_t *latency_histogram;
    L2Stats l2counts;
#ifdef HAVE_ISOCHRONOUS
    IsochStats isochstats;
    char   mIsochronous;                 // -e
    TransitStats frame;
    histogram_t *framelatency_histogram;
#endif
#ifdef HAVE_UDPTRIGGERS
    histogram_t *hostlatency_histogram;
    histogram_t *h1_histogram;
    histogram_t *h2_histogram;
    histogram_t *h3_histogram;
    histogram_t *h4_histogram;
    histogram_t *h5_histogram;
    histogram_t *h6_histogram;
    /*
     * u_int32_t tsf_rxmac   7
     * u_int32_t tsf_rxpcie  8
     * u_int32_t tsf_txpcie  14
     * u_int32_t tsf_txdma   15
     * u_int32_t tsf_txstatus 16
     * u_int32_t tsf_txpciert  17
     */
    struct tsftv_t tsftv_rxpcie;
    struct tsftv_t tsftv_rxmac;
    struct tsftv_t tsftv_txpcie;
    struct tsftv_t tsftv_txpciert;
    struct tsftv_t tsftv_txdma;
    struct tsftv_t tsftv_txstatus;
#endif
} Transfer_Info;

typedef struct Connection_Info {
    iperf_sockaddr peer;
    Socklen_t size_peer;
    iperf_sockaddr local;
    Socklen_t size_local;
    char *peerversion;
    int l2mode;
} Connection_Info;

typedef struct ReporterData {
    char*  mHost;                   // -c
    char*  mLocalhost;              // -B
    char*  mIfrname;
    char*  mSSMMulticastStr;

    // int's
    int type;
    max_size_t cntError;
    max_size_t lastError;
    max_size_t cntOutofOrder;
    max_size_t lastOutofOrder;
    max_size_t cntDatagrams;
    max_size_t lastDatagrams;
    max_size_t PacketID;

    int mBufLen;                    // -l
    int mMSS;                       // -M
    int mTCPWin;                    // -w
    max_size_t mUDPRate;            // -b or -u
    RateUnits mUDPRateUnits;        // -b is either bw or pps
    /*   flags is a BitMask of old bools
        bool   mBufLenSet;              // -l
        bool   mCompat;                 // -C
        bool   mDaemon;                 // -D
        bool   mDomain;                 // -V
        bool   mFileInput;              // -F or -I
        bool   mNodelay;                // -N
        bool   mPrintMSS;               // -m
        bool   mRemoveService;          // -R
        bool   mStdin;                  // -I
        bool   mStdout;                 // -o
        bool   mSuggestWin;             // -W
        bool   mUDP;
        bool   mMode_time;*/
    int flags;
    int flags_extend;
    // enums (which should be special int's)
    ThreadMode mThreadMode;         // -s or -c
    ReportMode mode;
    umax_size_t TotalLen;
    umax_size_t lastTotal;
    // doubles
    // shorts
    unsigned short mPort;           // -p
    // structs or miscellaneous
    Transfer_Info info;
    Connection_Info connection;
    struct timeval startTime;
    struct timeval packetTime;
    struct timeval nextTime;
    struct timeval intervalTime;
    struct timeval IPGstart;
#ifdef HAVE_ISOCHRONOUS
    IsochStats isochstats;
#endif
    double TxSyncInterval;
} ReporterData;

typedef struct MultiHeader {
    int reporterindex;
    int agentindex;
    int groupID;
    int threads;
    ReporterData *report;
    Transfer_Info *data;
    Condition barrier;
    struct timeval startTime;
} MultiHeader;

typedef struct ReportHeader {
    int reporterindex;
    int agentindex;
    ReporterData report;
    ReportStruct *data;
    MultiHeader *multireport;
    struct ReportHeader *next;
} ReportHeader;

typedef void* (* report_connection)( Connection_Info*, int );
typedef void (* report_settings)( ReporterData* );
typedef void (* report_statistics)( Transfer_Info* );
typedef void (* report_serverstatistics)( Connection_Info*, Transfer_Info* );

MultiHeader* InitMulti( struct thread_Settings *agent, int inID );
ReportHeader* InitReport( struct thread_Settings *agent );
void ReportPacket( ReportHeader *agent, ReportStruct *packet );
void CloseReport( ReportHeader *agent, ReportStruct *packet );
void EndReport( ReportHeader *agent );
Transfer_Info* GetReport( ReportHeader *agent );
void ReportServerUDP( struct thread_Settings *agent, struct server_hdr *server );
void ReportSettings( struct thread_Settings *agent );
void ReportConnections( struct thread_Settings *agent );
void reporter_peerversion (struct thread_Settings *inSettings, int upper, int lower);

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[];

#define SNBUFFERSIZE 120
extern char buffer[SNBUFFERSIZE]; // Buffer for printing

#define rMillion 1000000

#define TimeDifference( left, right ) (left.tv_sec  - right.tv_sec) +   \
        (left.tv_usec - right.tv_usec) / ((double) rMillion)

#define TimeAdd( left, right )  do {                                    \
                                    left.tv_usec += right.tv_usec;      \
                                    if ( left.tv_usec > rMillion ) {    \
                                        left.tv_usec -= rMillion;       \
                                        left.tv_sec++;                  \
                                    }                                   \
                                    left.tv_sec += right.tv_sec;        \
                                } while ( 0 )
#ifdef __cplusplus
} /* end extern "C" */
#endif

#endif // REPORTER_H