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 int reporter_process_report ( ReportHeader *report );
115 void process_report ( ReportHeader *report );
116 int reporter_handle_packet( ReportHeader *report );
117 int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force );
118 int reporter_print( ReporterData *stats, int type, int end );
119 void PrintMSS( ReporterData *stats );
121 MultiHeader* InitMulti( thread_Settings *agent, int inID ) {
122 MultiHeader *multihdr = NULL;
123 if ( agent->mThreads > 1 || agent->mThreadMode == kMode_Server ) {
124 if ( isMultipleReport( agent ) ) {
125 multihdr = malloc(sizeof(MultiHeader) + sizeof(ReporterData) +
126 NUM_MULTI_SLOTS * sizeof(Transfer_Info));
128 multihdr = malloc(sizeof(MultiHeader));
130 if ( multihdr != NULL ) {
131 memset( multihdr, 0, sizeof(MultiHeader) );
132 Condition_Initialize( &multihdr->barrier );
133 multihdr->groupID = inID;
134 multihdr->threads = agent->mThreads;
135 if ( isMultipleReport( agent ) ) {
137 ReporterData *data = NULL;
138 multihdr->report = (ReporterData*)(multihdr + 1);
139 memset(multihdr->report, 0, sizeof(ReporterData));
140 multihdr->data = (Transfer_Info*)(multihdr->report + 1);
141 data = multihdr->report;
142 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
143 multihdr->data[i].startTime = -1;
144 multihdr->data[i].transferID = inID;
145 multihdr->data[i].groupID = -2;
147 data->type = TRANSFER_REPORT;
148 if ( agent->mInterval != 0.0 ) {
149 struct timeval *interval = &data->intervalTime;
150 interval->tv_sec = (long) agent->mInterval;
151 interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec)
154 data->mHost = agent->mHost;
155 data->mLocalhost = agent->mLocalhost;
156 data->mBufLen = agent->mBufLen;
157 data->mMSS = agent->mMSS;
158 data->mTCPWin = agent->mTCPWin;
159 data->flags = agent->flags;
160 data->mThreadMode = agent->mThreadMode;
161 data->mode = agent->mReportMode;
162 data->info.mFormat = agent->mFormat;
163 data->info.mTTL = agent->mTTL;
164 if ( isUDP( agent ) ) {
165 multihdr->report->info.mUDP = (char)agent->mThreadMode;
167 if ( isConnectionReport( agent ) ) {
168 data->type |= CONNECTION_REPORT;
169 data->connection.peer = agent->peer;
170 data->connection.size_peer = agent->size_peer;
171 SockAddr_setPortAny( &data->connection.peer );
172 data->connection.local = agent->local;
173 data->connection.size_local = agent->size_local;
174 SockAddr_setPortAny( &data->connection.local );
178 FAIL(1, "Out of Memory!!\n", agent);
185 * BarrierClient allows for multiple stream clients to be syncronized
187 void BarrierClient( ReportHeader *agent ) {
188 Condition_Lock(agent->multireport->barrier);
189 agent->multireport->threads--;
190 if ( agent->multireport->threads == 0 ) {
191 // last one set time and wake up everyone
192 gettimeofday( &(agent->multireport->startTime), NULL );
193 Condition_Broadcast( &agent->multireport->barrier );
195 Condition_Wait( &agent->multireport->barrier );
197 agent->multireport->threads++;
198 Condition_Unlock( agent->multireport->barrier );
199 agent->report.startTime = agent->multireport->startTime;
200 agent->report.nextTime = agent->report.startTime;
201 TimeAdd( agent->report.nextTime, agent->report.intervalTime );
205 * InitReport is called by a transfer agent (client or
206 * server) to setup the needed structures to communicate
209 ReportHeader* InitReport( thread_Settings *agent ) {
210 ReportHeader *reporthdr = NULL;
211 ReporterData *data = NULL;
212 if ( isDataReport( agent ) ) {
214 * Create in one big chunk
216 reporthdr = malloc( sizeof(ReportHeader) +
217 NUM_REPORT_STRUCTS * sizeof(ReportStruct) );
218 if ( reporthdr != NULL ) {
219 // Only need to make sure the headers are clean
220 memset( reporthdr, 0, sizeof(ReportHeader));
221 reporthdr->data = (ReportStruct*)(reporthdr+1);
222 reporthdr->multireport = agent->multihdr;
223 data = &reporthdr->report;
224 reporthdr->reporterindex = NUM_REPORT_STRUCTS - 1;
225 data->info.transferID = agent->mSock;
226 data->info.groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
228 data->type = TRANSFER_REPORT;
229 if ( agent->mInterval != 0.0 ) {
230 struct timeval *interval = &data->intervalTime;
231 interval->tv_sec = (long) agent->mInterval;
232 interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec)
235 data->mHost = agent->mHost;
236 data->mLocalhost = agent->mLocalhost;
237 data->mBufLen = agent->mBufLen;
238 data->mMSS = agent->mMSS;
239 data->mTCPWin = agent->mTCPWin;
240 data->flags = agent->flags;
241 data->mThreadMode = agent->mThreadMode;
242 data->mode = agent->mReportMode;
243 data->info.mFormat = agent->mFormat;
244 data->info.mTTL = agent->mTTL;
245 if ( isUDP( agent ) ) {
246 reporthdr->report.info.mUDP = (char)agent->mThreadMode;
249 FAIL(1, "Out of Memory!!\n", agent);
252 if ( isConnectionReport( agent ) ) {
253 if ( reporthdr == NULL ) {
255 * Create in one big chunk
257 reporthdr = malloc( sizeof(ReportHeader) );
258 if ( reporthdr != NULL ) {
259 // Only need to make sure the headers are clean
260 memset( reporthdr, 0, sizeof(ReportHeader));
261 data = &reporthdr->report;
262 data->info.transferID = agent->mSock;
263 data->info.groupID = -1;
265 FAIL(1, "Out of Memory!!\n", agent);
268 if ( reporthdr != NULL ) {
269 data->type |= CONNECTION_REPORT;
270 data->connection.peer = agent->peer;
271 data->connection.size_peer = agent->size_peer;
272 data->connection.local = agent->local;
273 data->connection.size_local = agent->size_local;
275 FAIL(1, "Out of Memory!!\n", agent);
278 if ( isConnectionReport( agent ) || isDataReport( agent ) ) {
282 * Update the ReportRoot to include this report.
284 if ( reporthdr->report.mThreadMode == kMode_Client &&
285 reporthdr->multireport != NULL ) {
286 // syncronize watches on my mark......
287 BarrierClient( reporthdr );
289 if ( reporthdr->multireport != NULL && isMultipleReport( agent )) {
290 reporthdr->multireport->threads++;
291 if ( reporthdr->multireport->report->startTime.tv_sec == 0 ) {
292 gettimeofday( &(reporthdr->multireport->report->startTime), NULL );
294 reporthdr->report.startTime = reporthdr->multireport->report->startTime;
297 gettimeofday( &(reporthdr->report.startTime), NULL );
299 reporthdr->report.nextTime = reporthdr->report.startTime;
300 TimeAdd( reporthdr->report.nextTime, reporthdr->report.intervalTime );
302 Condition_Lock( ReportCond );
303 reporthdr->next = ReportRoot;
304 ReportRoot = reporthdr;
305 Condition_Signal( &ReportCond );
306 Condition_Unlock( ReportCond );
309 gettimeofday( &(reporthdr->report.startTime), NULL );
311 * Process the report in this thread
313 reporthdr->next = NULL;
314 process_report ( reporthdr );
317 if ( !isDataReport( agent ) ) {
324 * ReportPacket is called by a transfer agent to record
325 * the arrival or departure of a "packet" (for TCP it
326 * will actually represent many packets). This needs to
327 * be as simple and fast as possible as it gets called for
330 void ReportPacket( ReportHeader* agent, ReportStruct *packet ) {
331 if ( agent != NULL ) {
332 int index = agent->reporterindex;
334 * First find the appropriate place to put the information
336 if ( agent->agentindex == NUM_REPORT_STRUCTS ) {
337 // Just need to make sure that reporter is not on the first
339 while ( index == 0 ) {
340 Condition_Signal( &ReportCond );
342 index = agent->reporterindex;
344 agent->agentindex = 0;
346 // Need to make sure that reporter is not about to be "lapped"
347 while ( index - 1 == agent->agentindex ) {
348 Condition_Signal( &ReportCond );
350 index = agent->reporterindex;
353 // Put the information there
354 memcpy( agent->data + agent->agentindex, packet, sizeof(ReportStruct) );
356 // Updating agentindex MUST be the last thing done
360 * Process the report in this thread
362 process_report ( agent );
368 * CloseReport is called by a transfer agent to finalize
369 * the report and signal transfer is over.
371 void CloseReport( ReportHeader *agent, ReportStruct *packet ) {
372 if ( agent != NULL) {
375 * Using PacketID of -1 ends reporting
377 packet->packetID = -1;
378 packet->packetLen = 0;
379 ReportPacket( agent, packet );
380 packet->packetID = agent->report.cntDatagrams;
385 * EndReport signifies the agent no longer is interested
386 * in the report. Calls to GetReport will no longer be
389 void EndReport( ReportHeader *agent ) {
390 if ( agent != NULL ) {
391 int index = agent->reporterindex;
392 while ( index != -1 ) {
394 index = agent->reporterindex;
396 agent->agentindex = -1;
399 * Process the report in this thread
401 process_report ( agent );
407 * GetReport is called by the agent after a CloseReport
408 * but before an EndReport to get the stats generated
409 * by the reporter thread.
411 Transfer_Info *GetReport( ReportHeader *agent ) {
412 int index = agent->reporterindex;
413 while ( index != -1 ) {
415 index = agent->reporterindex;
417 return &agent->report.info;
421 * ReportSettings will generate a summary report for
422 * settings being used with Listeners or Clients
424 void ReportSettings( thread_Settings *agent ) {
425 if ( isSettingsReport( agent ) ) {
427 * Create in one big chunk
429 ReportHeader *reporthdr = malloc( sizeof(ReportHeader) );
431 if ( reporthdr != NULL ) {
432 ReporterData *data = &reporthdr->report;
433 data->info.transferID = agent->mSock;
434 data->info.groupID = -1;
435 reporthdr->agentindex = -1;
436 reporthdr->reporterindex = -1;
438 data->mHost = agent->mHost;
439 data->mLocalhost = agent->mLocalhost;
440 data->mode = agent->mReportMode;
441 data->type = SETTINGS_REPORT;
442 data->mBufLen = agent->mBufLen;
443 data->mMSS = agent->mMSS;
444 data->mTCPWin = agent->mTCPWin;
445 data->flags = agent->flags;
446 data->mThreadMode = agent->mThreadMode;
447 data->mPort = agent->mPort;
448 data->info.mFormat = agent->mFormat;
449 data->info.mTTL = agent->mTTL;
450 data->connection.peer = agent->peer;
451 data->connection.size_peer = agent->size_peer;
452 data->connection.local = agent->local;
453 data->connection.size_local = agent->size_local;
457 * Update the ReportRoot to include this report.
459 Condition_Lock( ReportCond );
460 reporthdr->next = ReportRoot;
461 ReportRoot = reporthdr;
462 Condition_Signal( &ReportCond );
463 Condition_Unlock( ReportCond );
466 * Process the report in this thread
468 reporthdr->next = NULL;
469 process_report ( reporthdr );
472 FAIL(1, "Out of Memory!!\n", agent);
478 * ReportServerUDP will generate a report of the UDP
479 * statistics as reported by the server on the client
482 void ReportServerUDP( thread_Settings *agent, server_hdr *server ) {
483 if ( (ntohl(server->flags) & HEADER_VERSION1) != 0 &&
484 isServerReport( agent ) ) {
486 * Create in one big chunk
488 ReportHeader *reporthdr = malloc( sizeof(ReportHeader) );
489 Transfer_Info *stats = &reporthdr->report.info;
491 if ( reporthdr != NULL ) {
492 stats->transferID = agent->mSock;
493 stats->groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
495 reporthdr->agentindex = -1;
496 reporthdr->reporterindex = -1;
498 reporthdr->report.type = SERVER_RELAY_REPORT;
499 reporthdr->report.mode = agent->mReportMode;
500 stats->mFormat = agent->mFormat;
501 stats->jitter = ntohl( server->jitter1 );
502 stats->jitter += ntohl( server->jitter2 ) / (double)rMillion;
503 stats->TotalLen = (((max_size_t) ntohl( server->total_len1 )) << 32) +
504 ntohl( server->total_len2 );
505 stats->startTime = 0;
506 stats->endTime = ntohl( server->stop_sec );
507 stats->endTime += ntohl( server->stop_usec ) / (double)rMillion;
508 stats->cntError = ntohl( server->error_cnt );
509 stats->cntOutofOrder = ntohl( server->outorder_cnt );
510 stats->cntDatagrams = ntohl( server->datagrams );
511 stats->mUDP = (char)kMode_Server;
512 reporthdr->report.connection.peer = agent->local;
513 reporthdr->report.connection.size_peer = agent->size_local;
514 reporthdr->report.connection.local = agent->peer;
515 reporthdr->report.connection.size_local = agent->size_peer;
519 * Update the ReportRoot to include this report.
521 Condition_Lock( ReportCond );
522 reporthdr->next = ReportRoot;
523 ReportRoot = reporthdr;
524 Condition_Signal( &ReportCond );
525 Condition_Unlock( ReportCond );
528 * Process the report in this thread
530 reporthdr->next = NULL;
531 process_report ( reporthdr );
534 FAIL(1, "Out of Memory!!\n", agent);
540 * This function is called only when the reporter thread
541 * This function is the loop that the reporter thread processes
543 void reporter_spawn( thread_Settings *thread ) {
545 // This section allows for safe exiting with Ctrl-C
546 Condition_Lock ( ReportCond );
547 if ( ReportRoot == NULL ) {
548 // Allow main thread to exit if Ctrl-C is received
550 Condition_Wait ( &ReportCond );
551 // Stop main thread from exiting until done with all reports
552 thread_unsetignore();
554 Condition_Unlock ( ReportCond );
556 if ( ReportRoot != NULL ) {
557 ReportHeader *temp = ReportRoot;
558 //Condition_Unlock ( ReportCond );
559 if ( reporter_process_report ( temp ) ) {
560 // This section allows for more reports to be added while
561 // the reporter is processing reports without needing to
562 // stop the reporter or immediately notify it
563 Condition_Lock ( ReportCond );
564 if ( temp == ReportRoot ) {
566 ReportRoot = temp->next;
569 ReportHeader *itr = ReportRoot;
570 while ( itr->next != temp ) {
573 itr->next = temp->next;
575 // finished with report so free it
577 Condition_Unlock ( ReportCond );
579 // yield control of CPU is another thread is waiting
582 //Condition_Unlock ( ReportCond );
588 * Used for single threaded reporting
590 void process_report ( ReportHeader *report ) {
591 if ( report != NULL ) {
592 if ( reporter_process_report( report ) ) {
599 * Process reports starting with "reporthdr"
601 int reporter_process_report ( ReportHeader *reporthdr ) {
604 // Recursively process reports
605 if ( reporthdr->next != NULL ) {
606 if ( reporter_process_report( reporthdr->next ) ) {
607 // If we are done with this report then free it
608 ReportHeader *temp = reporthdr->next;
609 reporthdr->next = reporthdr->next->next;
614 if ( (reporthdr->report.type & SETTINGS_REPORT) != 0 ) {
615 reporthdr->report.type &= ~SETTINGS_REPORT;
616 return reporter_print( &reporthdr->report, SETTINGS_REPORT, 1 );
617 } else if ( (reporthdr->report.type & CONNECTION_REPORT) != 0 ) {
618 reporthdr->report.type &= ~CONNECTION_REPORT;
619 reporter_print( &reporthdr->report, CONNECTION_REPORT,
620 (reporthdr->report.type == 0 ? 1 : 0) );
621 if ( reporthdr->multireport != NULL && isMultipleReport( (&reporthdr->report) )) {
622 if ( (reporthdr->multireport->report->type & CONNECTION_REPORT) != 0 ) {
623 reporthdr->multireport->report->type &= ~CONNECTION_REPORT;
624 reporter_print( reporthdr->multireport->report, CONNECTION_REPORT,
625 (reporthdr->report.type == 0 ? 1 : 0) );
628 } else if ( (reporthdr->report.type & SERVER_RELAY_REPORT) != 0 ) {
629 reporthdr->report.type &= ~SERVER_RELAY_REPORT;
630 return reporter_print( &reporthdr->report, SERVER_RELAY_REPORT, 1 );
632 if ( (reporthdr->report.type & TRANSFER_REPORT) != 0 ) {
633 // If there are more packets to process then handle them
634 if ( reporthdr->reporterindex >= 0 ) {
635 // Need to make sure we do not pass the "agent"
636 while ( reporthdr->reporterindex != reporthdr->agentindex - 1 ) {
637 if ( reporthdr->reporterindex == NUM_REPORT_STRUCTS - 1 ) {
638 if ( reporthdr->agentindex == 0 ) {
641 reporthdr->reporterindex = 0;
644 reporthdr->reporterindex++;
646 if ( reporter_handle_packet( reporthdr ) ) {
647 // No more packets to process
648 reporthdr->reporterindex = -1;
653 // If the agent is done with the report then free it
654 if ( reporthdr->agentindex == -1 ) {
662 * Updates connection stats
664 int reporter_handle_packet( ReportHeader *reporthdr ) {
665 ReportStruct *packet = &reporthdr->data[reporthdr->reporterindex];
666 ReporterData *data = &reporthdr->report;
667 Transfer_Info *stats = &reporthdr->report.info;
670 data->cntDatagrams++;
671 // If this is the last packet set the endTime
672 if ( packet->packetID < 0 ) {
673 data->packetTime = packet->packetTime;
675 if ( reporthdr->report.mThreadMode != kMode_Client ) {
676 data->TotalLen += packet->packetLen;
679 // update recieved amount and time
680 data->packetTime = packet->packetTime;
681 reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
682 data->TotalLen += packet->packetLen;
683 if ( packet->packetID != 0 ) {
688 // from RFC 1889, Real Time Protocol (RTP)
689 // J = J + ( | D(i-1,i) | - J ) / 16
690 transit = TimeDifference( packet->packetTime, packet->sentTime );
691 if ( data->lastTransit != 0.0 ) {
692 deltaTransit = transit - data->lastTransit;
693 if ( deltaTransit < 0.0 ) {
694 deltaTransit = -deltaTransit;
696 stats->jitter += (deltaTransit - stats->jitter) / (16.0);
698 data->lastTransit = transit;
700 // packet loss occured if the datagram numbers aren't sequential
701 if ( packet->packetID != data->PacketID + 1 ) {
702 if ( packet->packetID < data->PacketID + 1 ) {
703 data->cntOutofOrder++;
705 data->cntError += packet->packetID - data->PacketID - 1;
708 // never decrease datagramID (e.g. if we get an out-of-order packet)
709 if ( packet->packetID > data->PacketID ) {
710 data->PacketID = packet->packetID;
715 // Print a report if appropriate
716 return reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
720 * Handles summing of threads
722 void reporter_handle_multiple_reports( MultiHeader *reporthdr, Transfer_Info *stats, int force ) {
723 if ( reporthdr != NULL ) {
724 if ( reporthdr->threads > 1 ) {
726 Transfer_Info *current = NULL;
727 // Search for start Time
728 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
729 current = &reporthdr->data[i];
730 if ( current->startTime == stats->startTime ) {
734 if ( current->startTime != stats->startTime ) {
735 // Find first available
736 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
737 current = &reporthdr->data[i];
738 if ( current->startTime < 0 ) {
742 current->cntDatagrams = stats->cntDatagrams;
743 current->cntError = stats->cntError;
744 current->cntOutofOrder = stats->cntOutofOrder;
745 current->TotalLen = stats->TotalLen;
746 current->mFormat = stats->mFormat;
747 current->endTime = stats->endTime;
748 current->jitter = stats->jitter;
749 current->startTime = stats->startTime;
752 current->cntDatagrams += stats->cntDatagrams;
753 current->cntError += stats->cntError;
754 current->cntOutofOrder += stats->cntOutofOrder;
755 current->TotalLen += stats->TotalLen;
756 current->mFormat = stats->mFormat;
757 if ( current->endTime < stats->endTime ) {
758 current->endTime = stats->endTime;
760 if ( current->jitter < stats->jitter ) {
761 current->jitter = stats->jitter;
764 if ( current->free == reporthdr->threads ) {
765 void *reserved = reporthdr->report->info.reserved_delay;
766 current->free = force;
767 memcpy( &reporthdr->report->info, current, sizeof(Transfer_Info) );
768 current->startTime = -1;
769 reporthdr->report->info.reserved_delay = reserved;
770 reporter_print( reporthdr->report, MULTIPLE_REPORT, force );
778 * Prints reports conditionally
780 int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force ) {
782 stats->info.cntOutofOrder = stats->cntOutofOrder;
783 // assume most of the time out-of-order packets are not
784 // duplicate packets, so conditionally subtract them from the lost packets.
785 stats->info.cntError = stats->cntError;
786 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
787 stats->info.cntError -= stats->info.cntOutofOrder;
789 stats->info.cntDatagrams = (isUDP(stats) ? stats->PacketID : stats->cntDatagrams);
790 stats->info.TotalLen = stats->TotalLen;
791 stats->info.startTime = 0;
792 stats->info.endTime = TimeDifference( stats->packetTime, stats->startTime );
793 stats->info.free = 1;
794 reporter_print( stats, TRANSFER_REPORT, force );
795 if ( isMultipleReport(stats) ) {
796 reporter_handle_multiple_reports( multireport, &stats->info, force );
798 } else while ((stats->intervalTime.tv_sec != 0 ||
799 stats->intervalTime.tv_usec != 0) &&
800 TimeDifference( stats->nextTime,
801 stats->packetTime ) < 0 ) {
802 stats->info.cntOutofOrder = stats->cntOutofOrder - stats->lastOutofOrder;
803 stats->lastOutofOrder = stats->cntOutofOrder;
804 // assume most of the time out-of-order packets are not
805 // duplicate packets, so conditionally subtract them from the lost packets.
806 stats->info.cntError = stats->cntError - stats->lastError;
807 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
808 stats->info.cntError -= stats->info.cntOutofOrder;
810 stats->lastError = stats->cntError;
811 stats->info.cntDatagrams = (isUDP( stats ) ? stats->PacketID - stats->lastDatagrams :
812 stats->cntDatagrams - stats->lastDatagrams);
813 stats->lastDatagrams = (isUDP( stats ) ? stats->PacketID : stats->cntDatagrams);
814 stats->info.TotalLen = stats->TotalLen - stats->lastTotal;
815 stats->lastTotal = stats->TotalLen;
816 stats->info.startTime = stats->info.endTime;
817 stats->info.endTime = TimeDifference( stats->nextTime, stats->startTime );
818 TimeAdd( stats->nextTime, stats->intervalTime );
819 stats->info.free = 0;
820 reporter_print( stats, TRANSFER_REPORT, force );
821 if ( isMultipleReport(stats) ) {
822 reporter_handle_multiple_reports( multireport, &stats->info, force );
829 * This function handles multiple format printing by sending to the
830 * appropriate dispatch function
832 int reporter_print( ReporterData *stats, int type, int end ) {
834 case TRANSFER_REPORT:
835 statistics_reports[stats->mode]( &stats->info );
836 if ( end != 0 && isPrintMSS( stats ) && !isUDP( stats ) ) {
840 case SERVER_RELAY_REPORT:
841 serverstatistics_reports[stats->mode]( &stats->connection, &stats->info );
843 case SETTINGS_REPORT:
844 settings_reports[stats->mode]( stats );
846 case CONNECTION_REPORT:
847 stats->info.reserved_delay = connection_reports[stats->mode](
849 stats->info.transferID );
851 case MULTIPLE_REPORT:
852 multiple_reports[stats->mode]( &stats->info );
855 fprintf( stderr, "Printing type not implemented! No Output\n" );
861 /* -------------------------------------------------------------------
862 * Report the MSS and MTU, given the MSS (or a guess thereof)
863 * ------------------------------------------------------------------- */
865 // compare the MSS against the (MTU - 40) to (MTU - 80) bytes.
866 // 40 byte IP header and somewhat arbitrarily, 40 more bytes of IP options.
868 #define checkMSS_MTU( inMSS, inMTU ) (inMTU-40) >= inMSS && inMSS >= (inMTU-80)
870 void PrintMSS( ReporterData *stats ) {
871 int inMSS = getsock_tcp_mss( stats->info.transferID );
874 printf( report_mss_unsupported, stats->info.transferID );
879 if ( checkMSS_MTU( inMSS, 1500 ) ) {
882 } else if ( checkMSS_MTU( inMSS, 4352 ) ) {
885 } else if ( checkMSS_MTU( inMSS, 9180 ) ) {
888 } else if ( checkMSS_MTU( inMSS, 65280 ) ) {
891 } else if ( checkMSS_MTU( inMSS, 576 ) ) {
894 printf( warn_no_pathmtu );
897 net = "unknown interface";
901 stats->info.transferID, inMSS, mtu, net );
907 } /* end extern "C" */