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;
456 * Update the ReportRoot to include this report.
458 Condition_Lock( ReportCond );
459 reporthdr->next = ReportRoot;
460 ReportRoot = reporthdr;
461 Condition_Signal( &ReportCond );
462 Condition_Unlock( ReportCond );
465 * Process the report in this thread
467 reporthdr->next = NULL;
468 process_report ( reporthdr );
471 FAIL(1, "Out of Memory!!\n", agent);
477 * ReportServerUDP will generate a report of the UDP
478 * statistics as reported by the server on the client
481 void ReportServerUDP( thread_Settings *agent, server_hdr *server ) {
482 if ( (ntohl(server->flags) & HEADER_VERSION1) != 0 &&
483 isServerReport( agent ) ) {
485 * Create in one big chunk
487 ReportHeader *reporthdr = malloc( sizeof(ReportHeader) );
488 Transfer_Info *stats = &reporthdr->report.info;
490 if ( reporthdr != NULL ) {
491 stats->transferID = agent->mSock;
492 stats->groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
494 reporthdr->agentindex = -1;
495 reporthdr->reporterindex = -1;
497 reporthdr->report.type = SERVER_RELAY_REPORT;
498 reporthdr->report.mode = agent->mReportMode;
499 stats->mFormat = agent->mFormat;
500 stats->jitter = ntohl( server->jitter1 );
501 stats->jitter += ntohl( server->jitter2 ) / (double)rMillion;
502 stats->TotalLen = (((max_size_t) ntohl( server->total_len1 )) << 32) +
503 ntohl( server->total_len2 );
504 stats->startTime = 0;
505 stats->endTime = ntohl( server->stop_sec );
506 stats->endTime += ntohl( server->stop_usec ) / (double)rMillion;
507 stats->cntError = ntohl( server->error_cnt );
508 stats->cntOutofOrder = ntohl( server->outorder_cnt );
509 stats->cntDatagrams = ntohl( server->datagrams );
510 stats->mUDP = (char)kMode_Server;
511 reporthdr->report.connection.peer = agent->local;
512 reporthdr->report.connection.local = agent->peer;
516 * Update the ReportRoot to include this report.
518 Condition_Lock( ReportCond );
519 reporthdr->next = ReportRoot;
520 ReportRoot = reporthdr;
521 Condition_Signal( &ReportCond );
522 Condition_Unlock( ReportCond );
525 * Process the report in this thread
527 reporthdr->next = NULL;
528 process_report ( reporthdr );
531 FAIL(1, "Out of Memory!!\n", agent);
537 * This function is called only when the reporter thread
538 * This function is the loop that the reporter thread processes
540 void reporter_spawn( thread_Settings *thread ) {
542 // This section allows for safe exiting with Ctrl-C
543 Condition_Lock ( ReportCond );
544 if ( ReportRoot == NULL ) {
545 // Allow main thread to exit if Ctrl-C is received
547 Condition_Wait ( &ReportCond );
548 // Stop main thread from exiting until done with all reports
549 thread_unsetignore();
551 Condition_Unlock ( ReportCond );
554 if ( ReportRoot != NULL ) {
555 ReportHeader *temp = ReportRoot;
556 //Condition_Unlock ( ReportCond );
557 if ( reporter_process_report ( temp ) ) {
558 // This section allows for more reports to be added while
559 // the reporter is processing reports without needing to
560 // stop the reporter or immediately notify it
561 Condition_Lock ( ReportCond );
562 if ( temp == ReportRoot ) {
564 ReportRoot = temp->next;
567 ReportHeader *itr = ReportRoot;
568 while ( itr->next != temp ) {
571 itr->next = temp->next;
573 // finished with report so free it
575 Condition_Unlock ( ReportCond );
576 Condition_Signal( &ReportDoneCond );
580 Condition_Signal( &ReportDoneCond );
583 //Condition_Unlock ( ReportCond );
589 * Used for single threaded reporting
591 void process_report ( ReportHeader *report ) {
592 if ( report != NULL ) {
593 if ( reporter_process_report( report ) ) {
600 * Process reports starting with "reporthdr"
602 int reporter_process_report ( ReportHeader *reporthdr ) {
605 // Recursively process reports
606 if ( reporthdr->next != NULL ) {
607 if ( reporter_process_report( reporthdr->next ) ) {
608 // If we are done with this report then free it
609 ReportHeader *temp = reporthdr->next;
610 reporthdr->next = reporthdr->next->next;
615 if ( (reporthdr->report.type & SETTINGS_REPORT) != 0 ) {
616 reporthdr->report.type &= ~SETTINGS_REPORT;
617 return reporter_print( &reporthdr->report, SETTINGS_REPORT, 1 );
618 } else if ( (reporthdr->report.type & CONNECTION_REPORT) != 0 ) {
619 reporthdr->report.type &= ~CONNECTION_REPORT;
620 reporter_print( &reporthdr->report, CONNECTION_REPORT,
621 (reporthdr->report.type == 0 ? 1 : 0) );
622 if ( reporthdr->multireport != NULL && isMultipleReport( (&reporthdr->report) )) {
623 if ( (reporthdr->multireport->report->type & CONNECTION_REPORT) != 0 ) {
624 reporthdr->multireport->report->type &= ~CONNECTION_REPORT;
625 reporter_print( reporthdr->multireport->report, CONNECTION_REPORT,
626 (reporthdr->report.type == 0 ? 1 : 0) );
629 } else if ( (reporthdr->report.type & SERVER_RELAY_REPORT) != 0 ) {
630 reporthdr->report.type &= ~SERVER_RELAY_REPORT;
631 return reporter_print( &reporthdr->report, SERVER_RELAY_REPORT, 1 );
633 if ( (reporthdr->report.type & TRANSFER_REPORT) != 0 ) {
634 // If there are more packets to process then handle them
635 if ( reporthdr->reporterindex >= 0 ) {
636 // Need to make sure we do not pass the "agent"
637 while ( reporthdr->reporterindex != reporthdr->agentindex - 1 ) {
638 if ( reporthdr->reporterindex == NUM_REPORT_STRUCTS - 1 ) {
639 if ( reporthdr->agentindex == 0 ) {
642 reporthdr->reporterindex = 0;
645 reporthdr->reporterindex++;
647 if ( reporter_handle_packet( reporthdr ) ) {
648 // No more packets to process
649 reporthdr->reporterindex = -1;
654 // If the agent is done with the report then free it
655 if ( reporthdr->agentindex == -1 ) {
663 * Updates connection stats
665 int reporter_handle_packet( ReportHeader *reporthdr ) {
666 ReportStruct *packet = &reporthdr->data[reporthdr->reporterindex];
667 ReporterData *data = &reporthdr->report;
668 Transfer_Info *stats = &reporthdr->report.info;
671 // update received amount and time
672 data->TotalLen += packet->packetLen;
673 data->packetTime = packet->packetTime;
674 data->cntDatagrams++;
676 if (packet->packetID < 0) {
677 // This is the last packet (FIN)
679 if (isConnectionLess(&reporthdr->report)) {
680 // connectionless protocols don't count the last payload
681 if (reporthdr->report.mThreadMode == kMode_Client)
682 data->TotalLen -= packet->packetLen;
684 // connection-oriented protocols dont't count the FIN
685 data->cntDatagrams--;
687 } else if ( packet->packetID != 0 ) {
688 // UDP or DCCP packet
689 double transit, deltaTransit;
691 // from RFC 1889, Real Time Protocol (RTP)
692 // J = J + ( | D(i-1,i) | - J ) / 16
693 transit = TimeDifference( packet->packetTime, packet->sentTime );
694 if ( data->lastTransit != 0.0 ) {
695 deltaTransit = transit - data->lastTransit;
696 if ( deltaTransit < 0.0 ) {
697 deltaTransit = -deltaTransit;
699 stats->jitter += (deltaTransit - stats->jitter) / (16.0);
701 data->lastTransit = transit;
703 // packet loss occured if the datagram numbers aren't sequential
704 if ( packet->packetID != data->PacketID + 1 ) {
705 if ( packet->packetID < data->PacketID + 1 ) {
706 data->cntOutofOrder++;
708 data->cntError += packet->packetID - data->PacketID - 1;
711 // never decrease datagramID (e.g. if we get an out-of-order packet)
712 if ( packet->packetID > data->PacketID ) {
713 data->PacketID = packet->packetID;
716 // Print a report if appropriate
717 return reporter_condprintstats( &reporthdr->report, reporthdr->multireport, finished );
721 * Handles summing of threads
723 void reporter_handle_multiple_reports( MultiHeader *reporthdr, Transfer_Info *stats, int force ) {
724 if ( reporthdr != NULL ) {
725 if ( reporthdr->threads > 1 ) {
727 Transfer_Info *current = NULL;
728 // Search for start Time
729 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
730 current = &reporthdr->data[i];
731 if ( current->startTime == stats->startTime ) {
735 if ( current->startTime != stats->startTime ) {
736 // Find first available
737 for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
738 current = &reporthdr->data[i];
739 if ( current->startTime < 0 ) {
743 current->cntDatagrams = stats->cntDatagrams;
744 current->cntError = stats->cntError;
745 current->cntOutofOrder = stats->cntOutofOrder;
746 current->TotalLen = stats->TotalLen;
747 current->mFormat = stats->mFormat;
748 current->endTime = stats->endTime;
749 current->jitter = stats->jitter;
750 current->startTime = stats->startTime;
753 current->cntDatagrams += stats->cntDatagrams;
754 current->cntError += stats->cntError;
755 current->cntOutofOrder += stats->cntOutofOrder;
756 current->TotalLen += stats->TotalLen;
757 current->mFormat = stats->mFormat;
758 if ( current->endTime < stats->endTime ) {
759 current->endTime = stats->endTime;
761 if ( current->jitter < stats->jitter ) {
762 current->jitter = stats->jitter;
765 if ( current->free == reporthdr->threads ) {
766 void *reserved = reporthdr->report->info.reserved_delay;
767 current->free = force;
768 memcpy( &reporthdr->report->info, current, sizeof(Transfer_Info) );
769 current->startTime = -1;
770 reporthdr->report->info.reserved_delay = reserved;
771 reporter_print( reporthdr->report, MULTIPLE_REPORT, force );
779 * Prints reports conditionally
781 int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force ) {
783 stats->info.cntOutofOrder = stats->cntOutofOrder;
784 // assume most of the time out-of-order packets are not
785 // duplicate packets, so conditionally subtract them from the lost packets.
786 stats->info.cntError = stats->cntError;
787 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
788 stats->info.cntError -= stats->info.cntOutofOrder;
790 if (isConnectionLess(stats))
791 stats->info.cntDatagrams = stats->PacketID;
793 stats->info.cntDatagrams = stats->cntDatagrams;
794 stats->info.TotalLen = stats->TotalLen;
795 stats->info.startTime = 0;
796 stats->info.endTime = TimeDifference( stats->packetTime, stats->startTime );
797 stats->info.free = 1;
798 reporter_print( stats, TRANSFER_REPORT, force );
799 if ( isMultipleReport(stats) ) {
800 reporter_handle_multiple_reports( multireport, &stats->info, force );
802 } else while ((stats->intervalTime.tv_sec != 0 ||
803 stats->intervalTime.tv_usec != 0) &&
804 TimeDifference( stats->nextTime,
805 stats->packetTime ) < 0 ) {
806 stats->info.cntOutofOrder = stats->cntOutofOrder - stats->lastOutofOrder;
807 stats->lastOutofOrder = stats->cntOutofOrder;
808 // assume most of the time out-of-order packets are not
809 // duplicate packets, so conditionally subtract them from the lost packets.
810 stats->info.cntError = stats->cntError - stats->lastError;
811 if ( stats->info.cntError > stats->info.cntOutofOrder ) {
812 stats->info.cntError -= stats->info.cntOutofOrder;
814 stats->lastError = stats->cntError;
815 if (isConnectionLess(stats)) {
816 stats->info.cntDatagrams = stats->PacketID - stats->lastDatagrams;
817 stats->lastDatagrams = stats->PacketID;
819 stats->info.cntDatagrams = stats->cntDatagrams - stats->lastDatagrams;
820 stats->lastDatagrams = stats->cntDatagrams;
822 stats->info.TotalLen = stats->TotalLen - stats->lastTotal;
823 stats->lastTotal = stats->TotalLen;
824 stats->info.startTime = stats->info.endTime;
825 stats->info.endTime = TimeDifference( stats->nextTime, stats->startTime );
826 TimeAdd( stats->nextTime, stats->intervalTime );
827 stats->info.free = 0;
828 reporter_print( stats, TRANSFER_REPORT, force );
829 if ( isMultipleReport(stats) ) {
830 reporter_handle_multiple_reports( multireport, &stats->info, force );
837 * This function handles multiple format printing by sending to the
838 * appropriate dispatch function
840 int reporter_print( ReporterData *stats, int type, int end ) {
842 case TRANSFER_REPORT:
843 statistics_reports[stats->mode]( &stats->info );
844 if ( end != 0 && isPrintMSS( stats ) && !isConnectionLess( stats ) ) {
848 case SERVER_RELAY_REPORT:
849 serverstatistics_reports[stats->mode]( &stats->connection, &stats->info );
851 case SETTINGS_REPORT:
852 settings_reports[stats->mode]( stats );
854 case CONNECTION_REPORT:
855 stats->info.reserved_delay = connection_reports[stats->mode](
857 stats->info.transferID );
859 case MULTIPLE_REPORT:
860 multiple_reports[stats->mode]( &stats->info );
863 fprintf( stderr, "Printing type not implemented! No Output\n" );
869 /* -------------------------------------------------------------------
870 * Report the MSS and MTU, given the MSS (or a guess thereof)
871 * This works for connection-oriented protocols only: it expects
872 * the protocol to be either TCP or DCCP and will give error otherwise
873 * ------------------------------------------------------------------- */
875 // compare the MSS against the (MTU - 40) to (MTU - 80) bytes.
876 // 40 byte IP header and somewhat arbitrarily, 40 more bytes of IP options.
878 #define checkMSS_MTU( inMSS, inMTU ) (inMTU-40) >= inMSS && inMSS >= (inMTU-80)
880 void PrintMSS( ReporterData *stats )
882 int inMSS = stats->mProtocol == kProto_TCP
883 ? getsock_tcp_mss( stats->info.transferID )
884 : getsock_dccp_mps( stats->info.transferID );
887 printf( report_mss_unsupported, stats->info.transferID );
892 if ( checkMSS_MTU( inMSS, 1500 ) ) {
895 } else if ( checkMSS_MTU( inMSS, 4352 ) ) {
898 } else if ( checkMSS_MTU( inMSS, 9180 ) ) {
901 } else if ( checkMSS_MTU( inMSS, 65280 ) ) {
904 } else if ( checkMSS_MTU( inMSS, 576 ) ) {
907 printf( warn_no_pathmtu );
910 net = "unknown interface";
914 stats->info.transferID, inMSS, mtu, net );
920 } /* end extern "C" */