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->mWinSize = agent->mWinSize;
160 data->flags = agent->flags;
161 data->mProtocol = agent->mProtocol;
162 data->mThreadMode = agent->mThreadMode;
163 data->mode = agent->mReportMode;
164 data->info.mFormat = agent->mFormat;
165 data->info.mTTL = agent->mTTL;
166 if ( isPacketOriented( agent ) ) {
167 multihdr->report->info.mUDP = (char)agent->mThreadMode;
169 if ( isConnectionReport( agent ) ) {
170 data->type |= CONNECTION_REPORT;
171 data->connection.peer = agent->peer;
172 data->connection.local = agent->local;
176 FAIL(1, "Out of Memory!!\n", agent);
183 * BarrierClient allows for multiple stream clients to be syncronized
185 void BarrierClient( ReportHeader *agent ) {
186 Condition_Lock(agent->multireport->barrier);
187 agent->multireport->threads--;
188 if ( agent->multireport->threads == 0 ) {
189 // last one set time and wake up everyone
190 gettimeofday( &(agent->multireport->startTime), NULL );
191 Condition_Broadcast( &agent->multireport->barrier );
193 Condition_Wait( &agent->multireport->barrier );
195 agent->multireport->threads++;
196 Condition_Unlock( agent->multireport->barrier );
197 agent->report.startTime = agent->multireport->startTime;
198 agent->report.nextTime = agent->report.startTime;
199 TimeAdd( agent->report.nextTime, agent->report.intervalTime );
203 * InitReport is called by a transfer agent (client or
204 * server) to setup the needed structures to communicate
207 ReportHeader* InitReport( thread_Settings *agent ) {
208 ReportHeader *reporthdr = NULL;
209 ReporterData *data = NULL;
210 if ( isDataReport( agent ) ) {
212 * Create in one big chunk
214 reporthdr = malloc( sizeof(ReportHeader) +
215 NUM_REPORT_STRUCTS * sizeof(ReportStruct) );
216 if ( reporthdr != NULL ) {
217 // Only need to make sure the headers are clean
218 memset( reporthdr, 0, sizeof(ReportHeader));
219 reporthdr->data = (ReportStruct*)(reporthdr+1);
220 reporthdr->multireport = agent->multihdr;
221 data = &reporthdr->report;
222 reporthdr->reporterindex = NUM_REPORT_STRUCTS - 1;
223 data->info.transferID = agent->mSock;
224 data->info.groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
226 data->info.congAlgo = agent->congAlgo;
227 data->type = TRANSFER_REPORT;
228 if ( agent->mInterval != 0.0 ) {
229 struct timeval *interval = &data->intervalTime;
230 interval->tv_sec = (long) agent->mInterval;
231 interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec)
234 data->mHost = agent->mHost;
235 data->mLocalhost = agent->mLocalhost;
236 data->mBufLen = agent->mBufLen;
237 data->mMSS = agent->mMSS;
238 data->mWinSize = agent->mWinSize;
239 data->flags = agent->flags;
240 data->mProtocol = agent->mProtocol;
241 data->mThreadMode = agent->mThreadMode;
242 data->mode = agent->mReportMode;
243 data->info.mFormat = agent->mFormat;
244 data->info.mTTL = agent->mTTL;
245 if ( isPacketOriented( 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;
264 data->info.congAlgo = agent->congAlgo;
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.local = agent->local;
274 FAIL(1, "Out of Memory!!\n", agent);
277 if ( isConnectionReport( agent ) || isDataReport( agent ) ) {
281 * Update the ReportRoot to include this report.
283 if ( reporthdr->report.mThreadMode == kMode_Client &&
284 reporthdr->multireport != NULL ) {
285 // syncronize watches on my mark......
286 BarrierClient( reporthdr );
288 if ( reporthdr->multireport != NULL && isMultipleReport( agent )) {
289 reporthdr->multireport->threads++;
290 if ( reporthdr->multireport->report->startTime.tv_sec == 0 ) {
291 gettimeofday( &(reporthdr->multireport->report->startTime), NULL );
293 reporthdr->report.startTime = reporthdr->multireport->report->startTime;
296 gettimeofday( &(reporthdr->report.startTime), NULL );
298 reporthdr->report.nextTime = reporthdr->report.startTime;
299 TimeAdd( reporthdr->report.nextTime, reporthdr->report.intervalTime );
301 Condition_Lock( ReportCond );
302 reporthdr->next = ReportRoot;
303 ReportRoot = reporthdr;
304 Condition_Signal( &ReportCond );
305 Condition_Unlock( ReportCond );
308 gettimeofday( &(reporthdr->report.startTime), NULL );
310 * Process the report in this thread
312 reporthdr->next = NULL;
313 process_report ( reporthdr );
316 if ( !isDataReport( agent ) ) {
323 * ReportPacket is called by a transfer agent to record
324 * the arrival or departure of a "packet" (for TCP it
325 * will actually represent many packets). This needs to
326 * be as simple and fast as possible as it gets called for
329 void ReportPacket( ReportHeader* agent, ReportStruct *packet ) {
330 if ( agent != NULL ) {
331 int index = agent->reporterindex;
333 * First find the appropriate place to put the information
335 if ( agent->agentindex == NUM_REPORT_STRUCTS ) {
336 // Just need to make sure that reporter is not on the first
338 while ( index == 0 ) {
339 Condition_Signal( &ReportCond );
340 Condition_Wait( &ReportDoneCond );
341 index = agent->reporterindex;
343 agent->agentindex = 0;
345 // Need to make sure that reporter is not about to be "lapped"
346 while ( index - 1 == agent->agentindex ) {
347 Condition_Signal( &ReportCond );
348 Condition_Wait( &ReportDoneCond );
349 index = agent->reporterindex;
352 // Put the information there
353 memcpy( agent->data + agent->agentindex, packet, sizeof(ReportStruct) );
355 // Updating agentindex MUST be the last thing done
359 * Process the report in this thread
361 process_report ( agent );
367 * CloseReport is called by a transfer agent to finalize
368 * the report and signal transfer is over.
370 void CloseReport( ReportHeader *agent, ReportStruct *packet ) {
371 if ( agent != NULL) {
373 * Using PacketID of -1 ends reporting
375 packet->packetID = -1;
376 packet->packetLen = 0;
377 ReportPacket( agent, packet );
378 packet->packetID = agent->report.cntDatagrams;
383 * EndReport signifies the agent no longer is interested
384 * in the report. Calls to GetReport will no longer be
387 void EndReport( ReportHeader *agent ) {
388 if ( agent != NULL ) {
389 int index = agent->reporterindex;
390 while ( index != -1 ) {
392 index = agent->reporterindex;
394 agent->agentindex = -1;
397 * Process the report in this thread
399 process_report ( agent );
405 * GetReport is called by the agent after a CloseReport
406 * but before an EndReport to get the stats generated
407 * by the reporter thread.
409 Transfer_Info *GetReport( ReportHeader *agent ) {
410 int index = agent->reporterindex;
411 while ( index != -1 ) {
413 index = agent->reporterindex;
415 return &agent->report.info;
419 * ReportSettings will generate a summary report for
420 * settings being used with Listeners or Clients
422 void ReportSettings( thread_Settings *agent ) {
423 if ( isSettingsReport( agent ) ) {
425 * Create in one big chunk
427 ReportHeader *reporthdr = malloc( sizeof(ReportHeader) );
429 if ( reporthdr != NULL ) {
430 ReporterData *data = &reporthdr->report;
431 data->info.transferID = agent->mSock;
432 data->info.groupID = -1;
433 reporthdr->agentindex = -1;
434 reporthdr->reporterindex = -1;
436 data->mHost = agent->mHost;
437 data->mLocalhost = agent->mLocalhost;
438 data->mode = agent->mReportMode;
439 data->type = SETTINGS_REPORT;
440 data->mBufLen = agent->mBufLen;
441 data->mMSS = agent->mMSS;
442 data->mWinSize = agent->mWinSize;
443 data->flags = agent->flags;
444 data->mProtocol = agent->mProtocol;
445 data->mThreadMode = agent->mThreadMode;
446 data->mPort = agent->mPort;
447 data->mMcastIface = agent->mMcastIface;
448 data->info.mFormat = agent->mFormat;
449 data->info.mTTL = agent->mTTL;
450 data->info.congAlgo = agent->congAlgo;
451 data->connection.peer = agent->peer;
452 data->connection.local = agent->local;
453 data->mCCID=agent->mCCID;
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.local = agent->peer;
517 * Update the ReportRoot to include this report.
519 Condition_Lock( ReportCond );
520 reporthdr->next = ReportRoot;
521 ReportRoot = reporthdr;
522 Condition_Signal( &ReportCond );
523 Condition_Unlock( ReportCond );
526 * Process the report in this thread
528 reporthdr->next = NULL;
529 process_report ( reporthdr );
532 FAIL(1, "Out of Memory!!\n", agent);
538 * This function is called only when the reporter thread
539 * This function is the loop that the reporter thread processes
541 void reporter_spawn( thread_Settings *thread ) {
543 // This section allows for safe exiting with Ctrl-C
544 Condition_Lock ( ReportCond );
545 if ( ReportRoot == NULL ) {
546 // Allow main thread to exit if Ctrl-C is received
548 Condition_Wait ( &ReportCond );
549 // Stop main thread from exiting until done with all reports
550 thread_unsetignore();
552 Condition_Unlock ( ReportCond );
555 if ( ReportRoot != NULL ) {
556 ReportHeader *temp = ReportRoot;
557 //Condition_Unlock ( ReportCond );
558 if ( reporter_process_report ( temp ) ) {
559 // This section allows for more reports to be added while
560 // the reporter is processing reports without needing to
561 // stop the reporter or immediately notify it
562 Condition_Lock ( ReportCond );
563 if ( temp == ReportRoot ) {
565 ReportRoot = temp->next;
568 ReportHeader *itr = ReportRoot;
569 while ( itr->next != temp ) {
572 itr->next = temp->next;
574 // finished with report so free it
576 Condition_Unlock ( ReportCond );
577 Condition_Signal( &ReportDoneCond );
581 Condition_Signal( &ReportDoneCond );
584 //Condition_Unlock ( ReportCond );
590 * Used for single threaded reporting
592 void process_report ( ReportHeader *report ) {
593 if ( report != NULL ) {
594 if ( reporter_process_report( report ) ) {
601 * Process reports starting with "reporthdr"
603 int reporter_process_report ( ReportHeader *reporthdr ) {
606 // Recursively process reports
607 if ( reporthdr->next != NULL ) {
608 if ( reporter_process_report( reporthdr->next ) ) {
609 // If we are done with this report then free it
610 ReportHeader *temp = reporthdr->next;
611 reporthdr->next = reporthdr->next->next;
616 if ( (reporthdr->report.type & SETTINGS_REPORT) != 0 ) {
617 reporthdr->report.type &= ~SETTINGS_REPORT;
618 return reporter_print( &reporthdr->report, SETTINGS_REPORT, 1 );
619 } else if ( (reporthdr->report.type & CONNECTION_REPORT) != 0 ) {
620 reporthdr->report.type &= ~CONNECTION_REPORT;
621 reporter_print( &reporthdr->report, CONNECTION_REPORT,
622 (reporthdr->report.type == 0 ? 1 : 0) );
623 if ( reporthdr->multireport != NULL && isMultipleReport( (&reporthdr->report) )) {
624 if ( (reporthdr->multireport->report->type & CONNECTION_REPORT) != 0 ) {
625 reporthdr->multireport->report->type &= ~CONNECTION_REPORT;
626 reporter_print( reporthdr->multireport->report, CONNECTION_REPORT,
627 (reporthdr->report.type == 0 ? 1 : 0) );
630 } else if ( (reporthdr->report.type & SERVER_RELAY_REPORT) != 0 ) {
631 reporthdr->report.type &= ~SERVER_RELAY_REPORT;
632 return reporter_print( &reporthdr->report, SERVER_RELAY_REPORT, 1 );
634 if ( (reporthdr->report.type & TRANSFER_REPORT) != 0 ) {
635 // If there are more packets to process then handle them
636 if ( reporthdr->reporterindex >= 0 ) {
637 // Need to make sure we do not pass the "agent"
638 while ( reporthdr->reporterindex != reporthdr->agentindex - 1 ) {
639 if ( reporthdr->reporterindex == NUM_REPORT_STRUCTS - 1 ) {
640 if ( reporthdr->agentindex == 0 ) {
643 reporthdr->reporterindex = 0;
646 reporthdr->reporterindex++;
648 if ( reporter_handle_packet( reporthdr ) ) {
649 // No more packets to process
650 reporthdr->reporterindex = -1;
655 // If the agent is done with the report then free it
656 if ( reporthdr->agentindex == -1 ) {
664 * Updates connection stats
666 int reporter_handle_packet( ReportHeader *reporthdr ) {
667 ReportStruct *packet = &reporthdr->data[reporthdr->reporterindex];
668 ReporterData *data = &reporthdr->report;
669 Transfer_Info *stats = &reporthdr->report.info;
672 // update received amount and time
673 data->TotalLen += packet->packetLen;
674 data->packetTime = packet->packetTime;
675 data->cntDatagrams++;
677 if (packet->packetID < 0) {
678 // This is the last packet (FIN)
680 if (isConnectionLess(&reporthdr->report)) {
681 // connectionless protocols don't count the last payload
682 if (reporthdr->report.mThreadMode == kMode_Client)
683 data->TotalLen -= packet->packetLen;
685 // connection-oriented protocols dont't count the FIN
686 data->cntDatagrams--;
688 } else if ( packet->packetID != 0 ) {
689 // UDP or DCCP packet
690 double transit, deltaTransit;
692 // from RFC 1889, Real Time Protocol (RTP)
693 // J = J + ( | D(i-1,i) | - J ) / 16
694 transit = TimeDifference( packet->packetTime, packet->sentTime );
695 if ( data->lastTransit != 0.0 ) {
696 deltaTransit = transit - data->lastTransit;
697 if ( deltaTransit < 0.0 ) {
698 deltaTransit = -deltaTransit;
700 stats->jitter += (deltaTransit - stats->jitter) / (16.0);
702 data->lastTransit = transit;
704 // packet loss occured if the datagram numbers aren't sequential
705 if ( packet->packetID != data->PacketID + 1 ) {
706 if ( packet->packetID < data->PacketID + 1 ) {
707 data->cntOutofOrder++;
709 data->cntError += packet->packetID - data->PacketID - 1;
712 // never decrease datagramID (e.g. if we get an out-of-order packet)
713 if ( packet->packetID > data->PacketID ) {
714 data->PacketID = packet->packetID;
717 // Print a report if appropriate
718 return reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
722 * Handles summing of threads
724 void reporter_handle_multiple_reports( MultiHeader *reporthdr, Transfer_Info *stats, int force ) {
725 if ( reporthdr != NULL ) {
726 if ( reporthdr->threads > 1 ) {
728 Transfer_Info *current = NULL;
729 // Search for start Time
730 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
731 current = &reporthdr->data[i];
732 if ( current->startTime == stats->startTime ) {
736 if ( current->startTime != stats->startTime ) {
737 // Find first available
738 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
739 current = &reporthdr->data[i];
740 if ( current->startTime < 0 ) {
744 current->cntDatagrams = stats->cntDatagrams;
745 current->cntError = stats->cntError;
746 current->cntOutofOrder = stats->cntOutofOrder;
747 current->TotalLen = stats->TotalLen;
748 current->mFormat = stats->mFormat;
749 current->endTime = stats->endTime;
750 current->jitter = stats->jitter;
751 current->startTime = stats->startTime;
754 current->cntDatagrams += stats->cntDatagrams;
755 current->cntError += stats->cntError;
756 current->cntOutofOrder += stats->cntOutofOrder;
757 current->TotalLen += stats->TotalLen;
758 current->mFormat = stats->mFormat;
759 if ( current->endTime < stats->endTime ) {
760 current->endTime = stats->endTime;
762 if ( current->jitter < stats->jitter ) {
763 current->jitter = stats->jitter;
766 if ( current->free == reporthdr->threads ) {
767 void *reserved = reporthdr->report->info.reserved_delay;
768 current->free = force;
769 memcpy( &reporthdr->report->info, current, sizeof(Transfer_Info) );
770 current->startTime = -1;
771 reporthdr->report->info.reserved_delay = reserved;
772 reporter_print( reporthdr->report, MULTIPLE_REPORT, force );
780 * Prints reports conditionally
782 int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force ) {
784 stats->info.cntOutofOrder = stats->cntOutofOrder;
785 // assume most of the time out-of-order packets are not
786 // duplicate packets, so conditionally subtract them from the lost packets.
787 stats->info.cntError = stats->cntError;
788 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
789 stats->info.cntError -= stats->info.cntOutofOrder;
791 if (isConnectionLess(stats))
792 stats->info.cntDatagrams = stats->PacketID;
794 stats->info.cntDatagrams = 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 if (isConnectionLess(stats)) {
817 stats->info.cntDatagrams = stats->PacketID - stats->lastDatagrams;
818 stats->lastDatagrams = stats->PacketID;
820 stats->info.cntDatagrams = stats->cntDatagrams - stats->lastDatagrams;
821 stats->lastDatagrams = stats->cntDatagrams;
823 stats->info.TotalLen = stats->TotalLen - stats->lastTotal;
824 stats->lastTotal = stats->TotalLen;
825 stats->info.startTime = stats->info.endTime;
826 stats->info.endTime = TimeDifference( stats->nextTime, stats->startTime );
827 TimeAdd( stats->nextTime, stats->intervalTime );
828 stats->info.free = 0;
829 reporter_print( stats, TRANSFER_REPORT, force );
830 if ( isMultipleReport(stats) ) {
831 reporter_handle_multiple_reports( multireport, &stats->info, force );
838 * This function handles multiple format printing by sending to the
839 * appropriate dispatch function
841 int reporter_print( ReporterData *stats, int type, int end ) {
843 case TRANSFER_REPORT:
844 statistics_reports[stats->mode]( &stats->info );
845 if ( end != 0 && isPrintMSS( stats ) && !isConnectionLess( stats ) ) {
849 case SERVER_RELAY_REPORT:
850 serverstatistics_reports[stats->mode]( &stats->connection, &stats->info );
852 case SETTINGS_REPORT:
853 settings_reports[stats->mode]( stats );
855 case CONNECTION_REPORT:
856 stats->info.reserved_delay = connection_reports[stats->mode](
858 stats->info.transferID );
860 case MULTIPLE_REPORT:
861 multiple_reports[stats->mode]( &stats->info );
864 fprintf( stderr, "Printing type not implemented! No Output\n" );
870 /* -------------------------------------------------------------------
871 * Report the MSS and MTU, given the MSS (or a guess thereof)
872 * This works for connection-oriented protocols only: it expects
873 * the protocol to be either TCP or DCCP and will give error otherwise
874 * ------------------------------------------------------------------- */
876 // compare the MSS against the (MTU - 40) to (MTU - 80) bytes.
877 // 40 byte IP header and somewhat arbitrarily, 40 more bytes of IP options.
879 #define checkMSS_MTU( inMSS, inMTU ) (inMTU-40) >= inMSS && inMSS >= (inMTU-80)
881 void PrintMSS( ReporterData *stats )
883 int inMSS = stats->mProtocol == kProto_TCP
884 ? getsock_tcp_mss( stats->info.transferID )
885 : getsock_dccp_mps( stats->info.transferID );
888 printf( report_mss_unsupported, stats->info.transferID );
893 if ( checkMSS_MTU( inMSS, 1500 ) ) {
896 } else if ( checkMSS_MTU( inMSS, 4352 ) ) {
899 } else if ( checkMSS_MTU( inMSS, 9180 ) ) {
902 } else if ( checkMSS_MTU( inMSS, 65280 ) ) {
905 } else if ( checkMSS_MTU( inMSS, 576 ) ) {
908 printf( warn_no_pathmtu );
911 net = "unknown interface";
915 stats->info.transferID, inMSS, mtu, net );
921 } /* end extern "C" */