1 /*---------------------------------------------------------------
2 * Copyright (c) 1999,2000,2001,2002,2003
3 * The Board of Trustees of the University of Illinois
5 *---------------------------------------------------------------
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software (Iperf) and associated
8 * documentation files (the "Software"), to deal in the Software
9 * without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute,
11 * sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do
13 * so, subject to the following conditions:
16 * Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and
18 * the following disclaimers.
21 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimers in the documentation and/or other materials
24 * provided with the distribution.
27 * Neither the names of the University of Illinois, NCSA,
28 * nor the names of its contributors may be used to endorse
29 * or promote products derived from this Software without
30 * specific prior written permission.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
34 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
36 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
38 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 * ________________________________________________________________
41 * National Laboratory for Applied Network Research
42 * National Center for Supercomputing Applications
43 * University of Illinois at Urbana-Champaign
44 * http://www.ncsa.uiuc.edu
45 * ________________________________________________________________
48 * by Kevin Gibbs <kgibbs@nlanr.net>
50 * ________________________________________________________________ */
53 #include "Settings.hpp"
58 #include "PerfSocket.hpp"
59 #include "SocketAddr.h"
66 The following 4 functions are provided for Reporting
67 styles that do not have all the reporting formats. For
68 instance the provided CSV format does not have a settings
69 report so it uses settings_notimpl.
71 void* connection_notimpl( Connection_Info * nused, int nuse ) {
74 void settings_notimpl( ReporterData * nused ) { }
75 void statistics_notimpl( Transfer_Info * nused ) { }
76 void serverstatistics_notimpl( Connection_Info *nused1, Transfer_Info *nused2 ) { }
78 // To add a reporting style include its header here.
79 #include "report_default.h"
80 #include "report_CSV.h"
82 // The following array of report structs contains the
83 // pointers required for reporting in different reporting
84 // styles. To add a reporting style add a report struct
86 report_connection connection_reports[kReport_MAXIMUM] = {
91 report_settings settings_reports[kReport_MAXIMUM] = {
92 reporter_reportsettings,
96 report_statistics statistics_reports[kReport_MAXIMUM] = {
101 report_serverstatistics serverstatistics_reports[kReport_MAXIMUM] = {
102 reporter_serverstats,
106 report_statistics multiple_reports[kReport_MAXIMUM] = {
111 char buffer[64]; // Buffer for printing
112 ReportHeader *ReportRoot = NULL;
113 extern Condition ReportCond;
114 extern Condition ReportDoneCond;
115 int reporter_process_report ( ReportHeader *report );
116 void process_report ( ReportHeader *report );
117 int reporter_handle_packet( ReportHeader *report );
118 int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force );
119 int reporter_print( ReporterData *stats, int type, int end );
120 void PrintMSS( ReporterData *stats );
122 MultiHeader* InitMulti( thread_Settings *agent, int inID ) {
123 MultiHeader *multihdr = NULL;
124 if ( agent->mThreads > 1 || agent->mThreadMode == kMode_Server ) {
125 if ( isMultipleReport( agent ) ) {
126 multihdr = malloc(sizeof(MultiHeader) + sizeof(ReporterData) +
127 NUM_MULTI_SLOTS * sizeof(Transfer_Info));
129 multihdr = malloc(sizeof(MultiHeader));
131 if ( multihdr != NULL ) {
132 memset( multihdr, 0, sizeof(MultiHeader) );
133 Condition_Initialize( &multihdr->barrier );
134 multihdr->groupID = inID;
135 multihdr->threads = agent->mThreads;
136 if ( isMultipleReport( agent ) ) {
138 ReporterData *data = NULL;
139 multihdr->report = (ReporterData*)(multihdr + 1);
140 memset(multihdr->report, 0, sizeof(ReporterData));
141 multihdr->data = (Transfer_Info*)(multihdr->report + 1);
142 data = multihdr->report;
143 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
144 multihdr->data[i].startTime = -1;
145 multihdr->data[i].transferID = inID;
146 multihdr->data[i].groupID = -2;
148 data->type = TRANSFER_REPORT;
149 if ( agent->mInterval != 0.0 ) {
150 struct timeval *interval = &data->intervalTime;
151 interval->tv_sec = (long) agent->mInterval;
152 interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec)
155 data->mHost = agent->mHost;
156 data->mLocalhost = agent->mLocalhost;
157 data->mBufLen = agent->mBufLen;
158 data->mMSS = agent->mMSS;
159 data->mTCPWin = agent->mTCPWin;
160 data->flags = agent->flags;
161 data->mThreadMode = agent->mThreadMode;
162 data->mode = agent->mReportMode;
163 data->info.mFormat = agent->mFormat;
164 data->info.mTTL = agent->mTTL;
165 if ( isUDP( agent ) ) {
166 multihdr->report->info.mUDP = (char)agent->mThreadMode;
168 if ( isConnectionReport( agent ) ) {
169 data->type |= CONNECTION_REPORT;
170 data->connection.peer = agent->peer;
171 data->connection.size_peer = agent->size_peer;
172 SockAddr_setPortAny( &data->connection.peer );
173 data->connection.local = agent->local;
174 data->connection.size_local = agent->size_local;
175 SockAddr_setPortAny( &data->connection.local );
179 FAIL(1, "Out of Memory!!\n", agent);
186 * BarrierClient allows for multiple stream clients to be syncronized
188 void BarrierClient( ReportHeader *agent ) {
189 Condition_Lock(agent->multireport->barrier);
190 agent->multireport->threads--;
191 if ( agent->multireport->threads == 0 ) {
192 // last one set time and wake up everyone
193 gettimeofday( &(agent->multireport->startTime), NULL );
194 Condition_Broadcast( &agent->multireport->barrier );
196 Condition_Wait( &agent->multireport->barrier );
198 agent->multireport->threads++;
199 Condition_Unlock( agent->multireport->barrier );
200 agent->report.startTime = agent->multireport->startTime;
201 agent->report.nextTime = agent->report.startTime;
202 TimeAdd( agent->report.nextTime, agent->report.intervalTime );
206 * InitReport is called by a transfer agent (client or
207 * server) to setup the needed structures to communicate
210 ReportHeader* InitReport( thread_Settings *agent ) {
211 ReportHeader *reporthdr = NULL;
212 ReporterData *data = NULL;
213 if ( isDataReport( agent ) ) {
215 * Create in one big chunk
217 reporthdr = malloc( sizeof(ReportHeader) +
218 NUM_REPORT_STRUCTS * sizeof(ReportStruct) );
219 if ( reporthdr != NULL ) {
220 // Only need to make sure the headers are clean
221 memset( reporthdr, 0, sizeof(ReportHeader));
222 reporthdr->data = (ReportStruct*)(reporthdr+1);
223 reporthdr->multireport = agent->multihdr;
224 data = &reporthdr->report;
225 reporthdr->reporterindex = NUM_REPORT_STRUCTS - 1;
226 data->info.transferID = agent->mSock;
227 data->info.groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
229 data->type = TRANSFER_REPORT;
230 if ( agent->mInterval != 0.0 ) {
231 struct timeval *interval = &data->intervalTime;
232 interval->tv_sec = (long) agent->mInterval;
233 interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec)
236 data->mHost = agent->mHost;
237 data->mLocalhost = agent->mLocalhost;
238 data->mBufLen = agent->mBufLen;
239 data->mMSS = agent->mMSS;
240 data->mTCPWin = agent->mTCPWin;
241 data->flags = agent->flags;
242 data->mThreadMode = agent->mThreadMode;
243 data->mode = agent->mReportMode;
244 data->info.mFormat = agent->mFormat;
245 data->info.mTTL = agent->mTTL;
246 if ( isUDP( agent ) ) {
247 reporthdr->report.info.mUDP = (char)agent->mThreadMode;
250 FAIL(1, "Out of Memory!!\n", agent);
253 if ( isConnectionReport( agent ) ) {
254 if ( reporthdr == NULL ) {
256 * Create in one big chunk
258 reporthdr = malloc( sizeof(ReportHeader) );
259 if ( reporthdr != NULL ) {
260 // Only need to make sure the headers are clean
261 memset( reporthdr, 0, sizeof(ReportHeader));
262 data = &reporthdr->report;
263 data->info.transferID = agent->mSock;
264 data->info.groupID = -1;
266 FAIL(1, "Out of Memory!!\n", agent);
269 if ( reporthdr != NULL ) {
270 data->type |= CONNECTION_REPORT;
271 data->connection.peer = agent->peer;
272 data->connection.size_peer = agent->size_peer;
273 data->connection.local = agent->local;
274 data->connection.size_local = agent->size_local;
276 FAIL(1, "Out of Memory!!\n", agent);
279 if ( isConnectionReport( agent ) || isDataReport( agent ) ) {
283 * Update the ReportRoot to include this report.
285 if ( reporthdr->report.mThreadMode == kMode_Client &&
286 reporthdr->multireport != NULL ) {
287 // syncronize watches on my mark......
288 BarrierClient( reporthdr );
290 if ( reporthdr->multireport != NULL && isMultipleReport( agent )) {
291 reporthdr->multireport->threads++;
292 if ( reporthdr->multireport->report->startTime.tv_sec == 0 ) {
293 gettimeofday( &(reporthdr->multireport->report->startTime), NULL );
295 reporthdr->report.startTime = reporthdr->multireport->report->startTime;
298 gettimeofday( &(reporthdr->report.startTime), NULL );
300 reporthdr->report.nextTime = reporthdr->report.startTime;
301 TimeAdd( reporthdr->report.nextTime, reporthdr->report.intervalTime );
303 Condition_Lock( ReportCond );
304 reporthdr->next = ReportRoot;
305 ReportRoot = reporthdr;
306 Condition_Signal( &ReportCond );
307 Condition_Unlock( ReportCond );
310 gettimeofday( &(reporthdr->report.startTime), NULL );
312 * Process the report in this thread
314 reporthdr->next = NULL;
315 process_report ( reporthdr );
318 if ( !isDataReport( agent ) ) {
325 * ReportPacket is called by a transfer agent to record
326 * the arrival or departure of a "packet" (for TCP it
327 * will actually represent many packets). This needs to
328 * be as simple and fast as possible as it gets called for
331 void ReportPacket( ReportHeader* agent, ReportStruct *packet ) {
332 if ( agent != NULL ) {
333 int index = agent->reporterindex;
335 * First find the appropriate place to put the information
337 if ( agent->agentindex == NUM_REPORT_STRUCTS ) {
338 // Just need to make sure that reporter is not on the first
340 while ( index == 0 ) {
341 Condition_Signal( &ReportCond );
342 Condition_Wait( &ReportDoneCond );
343 index = agent->reporterindex;
345 agent->agentindex = 0;
347 // Need to make sure that reporter is not about to be "lapped"
348 while ( index - 1 == agent->agentindex ) {
349 Condition_Signal( &ReportCond );
350 Condition_Wait( &ReportDoneCond );
351 index = agent->reporterindex;
354 // Put the information there
355 memcpy( agent->data + agent->agentindex, packet, sizeof(ReportStruct) );
357 // Updating agentindex MUST be the last thing done
361 * Process the report in this thread
363 process_report ( agent );
369 * CloseReport is called by a transfer agent to finalize
370 * the report and signal transfer is over.
372 void CloseReport( ReportHeader *agent, ReportStruct *packet ) {
373 if ( agent != NULL) {
376 * Using PacketID of -1 ends reporting
378 packet->packetID = -1;
379 packet->packetLen = 0;
380 ReportPacket( agent, packet );
381 packet->packetID = agent->report.cntDatagrams;
386 * EndReport signifies the agent no longer is interested
387 * in the report. Calls to GetReport will no longer be
390 void EndReport( ReportHeader *agent ) {
391 if ( agent != NULL ) {
392 int index = agent->reporterindex;
393 while ( index != -1 ) {
395 index = agent->reporterindex;
397 agent->agentindex = -1;
400 * Process the report in this thread
402 process_report ( agent );
408 * GetReport is called by the agent after a CloseReport
409 * but before an EndReport to get the stats generated
410 * by the reporter thread.
412 Transfer_Info *GetReport( ReportHeader *agent ) {
413 int index = agent->reporterindex;
414 while ( index != -1 ) {
416 index = agent->reporterindex;
418 return &agent->report.info;
422 * ReportSettings will generate a summary report for
423 * settings being used with Listeners or Clients
425 void ReportSettings( thread_Settings *agent ) {
426 if ( isSettingsReport( agent ) ) {
428 * Create in one big chunk
430 ReportHeader *reporthdr = malloc( sizeof(ReportHeader) );
432 if ( reporthdr != NULL ) {
433 ReporterData *data = &reporthdr->report;
434 data->info.transferID = agent->mSock;
435 data->info.groupID = -1;
436 reporthdr->agentindex = -1;
437 reporthdr->reporterindex = -1;
439 data->mHost = agent->mHost;
440 data->mLocalhost = agent->mLocalhost;
441 data->mode = agent->mReportMode;
442 data->type = SETTINGS_REPORT;
443 data->mBufLen = agent->mBufLen;
444 data->mMSS = agent->mMSS;
445 data->mTCPWin = agent->mTCPWin;
446 data->flags = agent->flags;
447 data->mThreadMode = agent->mThreadMode;
448 data->mPort = agent->mPort;
449 data->info.mFormat = agent->mFormat;
450 data->info.mTTL = agent->mTTL;
451 data->connection.peer = agent->peer;
452 data->connection.size_peer = agent->size_peer;
453 data->connection.local = agent->local;
454 data->connection.size_local = agent->size_local;
458 * Update the ReportRoot to include this report.
460 Condition_Lock( ReportCond );
461 reporthdr->next = ReportRoot;
462 ReportRoot = reporthdr;
463 Condition_Signal( &ReportCond );
464 Condition_Unlock( ReportCond );
467 * Process the report in this thread
469 reporthdr->next = NULL;
470 process_report ( reporthdr );
473 FAIL(1, "Out of Memory!!\n", agent);
479 * ReportServerUDP will generate a report of the UDP
480 * statistics as reported by the server on the client
483 void ReportServerUDP( thread_Settings *agent, server_hdr *server ) {
484 if ( (ntohl(server->flags) & HEADER_VERSION1) != 0 &&
485 isServerReport( agent ) ) {
487 * Create in one big chunk
489 ReportHeader *reporthdr = malloc( sizeof(ReportHeader) );
490 Transfer_Info *stats = &reporthdr->report.info;
492 if ( reporthdr != NULL ) {
493 stats->transferID = agent->mSock;
494 stats->groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
496 reporthdr->agentindex = -1;
497 reporthdr->reporterindex = -1;
499 reporthdr->report.type = SERVER_RELAY_REPORT;
500 reporthdr->report.mode = agent->mReportMode;
501 stats->mFormat = agent->mFormat;
502 stats->jitter = ntohl( server->jitter1 );
503 stats->jitter += ntohl( server->jitter2 ) / (double)rMillion;
504 stats->TotalLen = (((max_size_t) ntohl( server->total_len1 )) << 32) +
505 ntohl( server->total_len2 );
506 stats->startTime = 0;
507 stats->endTime = ntohl( server->stop_sec );
508 stats->endTime += ntohl( server->stop_usec ) / (double)rMillion;
509 stats->cntError = ntohl( server->error_cnt );
510 stats->cntOutofOrder = ntohl( server->outorder_cnt );
511 stats->cntDatagrams = ntohl( server->datagrams );
512 stats->mUDP = (char)kMode_Server;
513 reporthdr->report.connection.peer = agent->local;
514 reporthdr->report.connection.size_peer = agent->size_local;
515 reporthdr->report.connection.local = agent->peer;
516 reporthdr->report.connection.size_local = agent->size_peer;
520 * Update the ReportRoot to include this report.
522 Condition_Lock( ReportCond );
523 reporthdr->next = ReportRoot;
524 ReportRoot = reporthdr;
525 Condition_Signal( &ReportCond );
526 Condition_Unlock( ReportCond );
529 * Process the report in this thread
531 reporthdr->next = NULL;
532 process_report ( reporthdr );
535 FAIL(1, "Out of Memory!!\n", agent);
541 * This function is called only when the reporter thread
542 * This function is the loop that the reporter thread processes
544 void reporter_spawn( thread_Settings *thread ) {
546 // This section allows for safe exiting with Ctrl-C
547 Condition_Lock ( ReportCond );
548 if ( ReportRoot == NULL ) {
549 // Allow main thread to exit if Ctrl-C is received
551 Condition_Wait ( &ReportCond );
552 // Stop main thread from exiting until done with all reports
553 thread_unsetignore();
555 Condition_Unlock ( ReportCond );
558 if ( ReportRoot != NULL ) {
559 ReportHeader *temp = ReportRoot;
560 //Condition_Unlock ( ReportCond );
561 if ( reporter_process_report ( temp ) ) {
562 // This section allows for more reports to be added while
563 // the reporter is processing reports without needing to
564 // stop the reporter or immediately notify it
565 Condition_Lock ( ReportCond );
566 if ( temp == ReportRoot ) {
568 ReportRoot = temp->next;
571 ReportHeader *itr = ReportRoot;
572 while ( itr->next != temp ) {
575 itr->next = temp->next;
577 // finished with report so free it
579 Condition_Unlock ( ReportCond );
580 Condition_Signal( &ReportDoneCond );
584 Condition_Signal( &ReportDoneCond );
587 //Condition_Unlock ( ReportCond );
593 * Used for single threaded reporting
595 void process_report ( ReportHeader *report ) {
596 if ( report != NULL ) {
597 if ( reporter_process_report( report ) ) {
604 * Process reports starting with "reporthdr"
606 int reporter_process_report ( ReportHeader *reporthdr ) {
609 // Recursively process reports
610 if ( reporthdr->next != NULL ) {
611 if ( reporter_process_report( reporthdr->next ) ) {
612 // If we are done with this report then free it
613 ReportHeader *temp = reporthdr->next;
614 reporthdr->next = reporthdr->next->next;
619 if ( (reporthdr->report.type & SETTINGS_REPORT) != 0 ) {
620 reporthdr->report.type &= ~SETTINGS_REPORT;
621 return reporter_print( &reporthdr->report, SETTINGS_REPORT, 1 );
622 } else if ( (reporthdr->report.type & CONNECTION_REPORT) != 0 ) {
623 reporthdr->report.type &= ~CONNECTION_REPORT;
624 reporter_print( &reporthdr->report, CONNECTION_REPORT,
625 (reporthdr->report.type == 0 ? 1 : 0) );
626 if ( reporthdr->multireport != NULL && isMultipleReport( (&reporthdr->report) )) {
627 if ( (reporthdr->multireport->report->type & CONNECTION_REPORT) != 0 ) {
628 reporthdr->multireport->report->type &= ~CONNECTION_REPORT;
629 reporter_print( reporthdr->multireport->report, CONNECTION_REPORT,
630 (reporthdr->report.type == 0 ? 1 : 0) );
633 } else if ( (reporthdr->report.type & SERVER_RELAY_REPORT) != 0 ) {
634 reporthdr->report.type &= ~SERVER_RELAY_REPORT;
635 return reporter_print( &reporthdr->report, SERVER_RELAY_REPORT, 1 );
637 if ( (reporthdr->report.type & TRANSFER_REPORT) != 0 ) {
638 // If there are more packets to process then handle them
639 if ( reporthdr->reporterindex >= 0 ) {
640 // Need to make sure we do not pass the "agent"
641 while ( reporthdr->reporterindex != reporthdr->agentindex - 1 ) {
642 if ( reporthdr->reporterindex == NUM_REPORT_STRUCTS - 1 ) {
643 if ( reporthdr->agentindex == 0 ) {
646 reporthdr->reporterindex = 0;
649 reporthdr->reporterindex++;
651 if ( reporter_handle_packet( reporthdr ) ) {
652 // No more packets to process
653 reporthdr->reporterindex = -1;
658 // If the agent is done with the report then free it
659 if ( reporthdr->agentindex == -1 ) {
667 * Updates connection stats
669 int reporter_handle_packet( ReportHeader *reporthdr ) {
670 ReportStruct *packet = &reporthdr->data[reporthdr->reporterindex];
671 ReporterData *data = &reporthdr->report;
672 Transfer_Info *stats = &reporthdr->report.info;
675 data->cntDatagrams++;
676 // If this is the last packet set the endTime
677 if ( packet->packetID < 0 ) {
678 data->packetTime = packet->packetTime;
680 if ( reporthdr->report.mThreadMode != kMode_Client ) {
681 data->TotalLen += packet->packetLen;
684 // update recieved amount and time
685 data->packetTime = packet->packetTime;
686 reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
687 data->TotalLen += packet->packetLen;
688 if ( packet->packetID != 0 ) {
693 // from RFC 1889, Real Time Protocol (RTP)
694 // J = J + ( | D(i-1,i) | - J ) / 16
695 transit = TimeDifference( packet->packetTime, packet->sentTime );
696 if ( data->lastTransit != 0.0 ) {
697 deltaTransit = transit - data->lastTransit;
698 if ( deltaTransit < 0.0 ) {
699 deltaTransit = -deltaTransit;
701 stats->jitter += (deltaTransit - stats->jitter) / (16.0);
703 data->lastTransit = transit;
705 // packet loss occured if the datagram numbers aren't sequential
706 if ( packet->packetID != data->PacketID + 1 ) {
707 if ( packet->packetID < data->PacketID + 1 ) {
708 data->cntOutofOrder++;
710 data->cntError += packet->packetID - data->PacketID - 1;
713 // never decrease datagramID (e.g. if we get an out-of-order packet)
714 if ( packet->packetID > data->PacketID ) {
715 data->PacketID = packet->packetID;
720 // Print a report if appropriate
721 return reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
725 * Handles summing of threads
727 void reporter_handle_multiple_reports( MultiHeader *reporthdr, Transfer_Info *stats, int force ) {
728 if ( reporthdr != NULL ) {
729 if ( reporthdr->threads > 1 ) {
731 Transfer_Info *current = NULL;
732 // Search for start Time
733 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
734 current = &reporthdr->data[i];
735 if ( current->startTime == stats->startTime ) {
739 if ( current->startTime != stats->startTime ) {
740 // Find first available
741 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
742 current = &reporthdr->data[i];
743 if ( current->startTime < 0 ) {
747 current->cntDatagrams = stats->cntDatagrams;
748 current->cntError = stats->cntError;
749 current->cntOutofOrder = stats->cntOutofOrder;
750 current->TotalLen = stats->TotalLen;
751 current->mFormat = stats->mFormat;
752 current->endTime = stats->endTime;
753 current->jitter = stats->jitter;
754 current->startTime = stats->startTime;
757 current->cntDatagrams += stats->cntDatagrams;
758 current->cntError += stats->cntError;
759 current->cntOutofOrder += stats->cntOutofOrder;
760 current->TotalLen += stats->TotalLen;
761 current->mFormat = stats->mFormat;
762 if ( current->endTime < stats->endTime ) {
763 current->endTime = stats->endTime;
765 if ( current->jitter < stats->jitter ) {
766 current->jitter = stats->jitter;
769 if ( current->free == reporthdr->threads ) {
770 void *reserved = reporthdr->report->info.reserved_delay;
771 current->free = force;
772 memcpy( &reporthdr->report->info, current, sizeof(Transfer_Info) );
773 current->startTime = -1;
774 reporthdr->report->info.reserved_delay = reserved;
775 reporter_print( reporthdr->report, MULTIPLE_REPORT, force );
783 * Prints reports conditionally
785 int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force ) {
787 stats->info.cntOutofOrder = stats->cntOutofOrder;
788 // assume most of the time out-of-order packets are not
789 // duplicate packets, so conditionally subtract them from the lost packets.
790 stats->info.cntError = stats->cntError;
791 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
792 stats->info.cntError -= stats->info.cntOutofOrder;
794 stats->info.cntDatagrams = (isUDP(stats) ? stats->PacketID : stats->cntDatagrams);
795 stats->info.TotalLen = stats->TotalLen;
796 stats->info.startTime = 0;
797 stats->info.endTime = TimeDifference( stats->packetTime, stats->startTime );
798 stats->info.free = 1;
799 reporter_print( stats, TRANSFER_REPORT, force );
800 if ( isMultipleReport(stats) ) {
801 reporter_handle_multiple_reports( multireport, &stats->info, force );
803 } else while ((stats->intervalTime.tv_sec != 0 ||
804 stats->intervalTime.tv_usec != 0) &&
805 TimeDifference( stats->nextTime,
806 stats->packetTime ) < 0 ) {
807 stats->info.cntOutofOrder = stats->cntOutofOrder - stats->lastOutofOrder;
808 stats->lastOutofOrder = stats->cntOutofOrder;
809 // assume most of the time out-of-order packets are not
810 // duplicate packets, so conditionally subtract them from the lost packets.
811 stats->info.cntError = stats->cntError - stats->lastError;
812 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
813 stats->info.cntError -= stats->info.cntOutofOrder;
815 stats->lastError = stats->cntError;
816 stats->info.cntDatagrams = (isUDP( stats ) ? stats->PacketID - stats->lastDatagrams :
817 stats->cntDatagrams - stats->lastDatagrams);
818 stats->lastDatagrams = (isUDP( stats ) ? stats->PacketID : stats->cntDatagrams);
819 stats->info.TotalLen = stats->TotalLen - stats->lastTotal;
820 stats->lastTotal = stats->TotalLen;
821 stats->info.startTime = stats->info.endTime;
822 stats->info.endTime = TimeDifference( stats->nextTime, stats->startTime );
823 TimeAdd( stats->nextTime, stats->intervalTime );
824 stats->info.free = 0;
825 reporter_print( stats, TRANSFER_REPORT, force );
826 if ( isMultipleReport(stats) ) {
827 reporter_handle_multiple_reports( multireport, &stats->info, force );
834 * This function handles multiple format printing by sending to the
835 * appropriate dispatch function
837 int reporter_print( ReporterData *stats, int type, int end ) {
839 case TRANSFER_REPORT:
840 statistics_reports[stats->mode]( &stats->info );
841 if ( end != 0 && isPrintMSS( stats ) && !isUDP( stats ) ) {
845 case SERVER_RELAY_REPORT:
846 serverstatistics_reports[stats->mode]( &stats->connection, &stats->info );
848 case SETTINGS_REPORT:
849 settings_reports[stats->mode]( stats );
851 case CONNECTION_REPORT:
852 stats->info.reserved_delay = connection_reports[stats->mode](
854 stats->info.transferID );
856 case MULTIPLE_REPORT:
857 multiple_reports[stats->mode]( &stats->info );
860 fprintf( stderr, "Printing type not implemented! No Output\n" );
866 /* -------------------------------------------------------------------
867 * Report the MSS and MTU, given the MSS (or a guess thereof)
868 * ------------------------------------------------------------------- */
870 // compare the MSS against the (MTU - 40) to (MTU - 80) bytes.
871 // 40 byte IP header and somewhat arbitrarily, 40 more bytes of IP options.
873 #define checkMSS_MTU( inMSS, inMTU ) (inMTU-40) >= inMSS && inMSS >= (inMTU-80)
875 void PrintMSS( ReporterData *stats ) {
876 int inMSS = getsock_tcp_mss( stats->info.transferID );
879 printf( report_mss_unsupported, stats->info.transferID );
884 if ( checkMSS_MTU( inMSS, 1500 ) ) {
887 } else if ( checkMSS_MTU( inMSS, 4352 ) ) {
890 } else if ( checkMSS_MTU( inMSS, 9180 ) ) {
893 } else if ( checkMSS_MTU( inMSS, 65280 ) ) {
896 } else if ( checkMSS_MTU( inMSS, 576 ) ) {
899 printf( warn_no_pathmtu );
902 net = "unknown interface";
906 stats->info.transferID, inMSS, mtu, net );
912 } /* end extern "C" */