-
Notifications
You must be signed in to change notification settings - Fork 0
/
nettest_unix.c
3431 lines (2871 loc) · 108 KB
/
nettest_unix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef lint
#define WANT_UNIX
#define DIRTY
#define WANT_INTERVALS
#endif /* lint */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef WANT_UNIX
char nettest_unix_id[]="\
@(#)nettest_unix.c (c) Copyright 1994-2007 Hewlett-Packard Co. Version 2.4.3";
/****************************************************************/
/* */
/* nettest_bsd.c */
/* */
/* the BSD sockets parsing routine... */
/* */
/* scan_unix_args() */
/* */
/* the actual test routines... */
/* */
/* send_stream_stream() perform a stream stream test */
/* recv_stream_stream() */
/* send_stream_rr() perform a stream request/response */
/* recv_stream_rr() */
/* send_dg_stream() perform a dg stream test */
/* recv_dg_stream() */
/* send_dg_rr() perform a dg request/response */
/* recv_dg_rr() */
/* loc_cpu_rate() determine the local cpu maxrate */
/* rem_cpu_rate() find the remote cpu maxrate */
/* */
/****************************************************************/
/* at some point, I might want to go-in and see if I really need all */
/* these includes, but for the moment, we'll let them all just sit */
/* there. raj 8/94 */
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef WIN32
#include <sys/ipc.h>
#include <sys/socket.h>
#include <errno.h>
#include <signal.h>
#include <sys/un.h>
#include <unistd.h>
#else /* WIN32 */
#include <process.h>
#include <winsock2.h>
#include <windows.h>
#endif /* WIN32 */
#include <string.h>
#include <time.h>
#include <sys/time.h>
#ifdef NOSTDLIBH
#include <malloc.h>
#else /* NOSTDLIBH */
#include <stdlib.h>
#endif /* NOSTDLIBH */
#include <sys/stat.h>
#include "netlib.h"
#include "netsh.h"
#include "nettest_unix.h"
/* these variables are specific to the UNIX sockets tests. declare */
/* them static to make them global only to this file. */
#define UNIX_PRFX "netperf."
#define UNIX_LENGTH_MAX 0xFFFF - 28
static char
path_prefix[32];
static int
rss_size, /* remote socket send buffer size */
rsr_size, /* remote socket recv buffer size */
lss_size_req, /* requested local socket send buffer size */
lsr_size_req, /* requested local socket recv buffer size */
lss_size, /* local socket send buffer size */
lsr_size, /* local socket recv buffer size */
req_size = 1, /* request size */
rsp_size = 1, /* response size */
send_size, /* how big are individual sends */
recv_size; /* how big are individual receives */
/* different options for the sockets */
char unix_usage[] = "\n\
Usage: netperf [global options] -- [test options] \n\
\n\
STREAM/DG UNIX Sockets Test Options:\n\
-h Display this text\n\
-m bytes Set the send size (STREAM_STREAM, DG_STREAM)\n\
-M bytes Set the recv size (STREAM_STREAM, DG_STREAM)\n\
-p dir Set the directory where pipes are created\n\
-r req,res Set request,response size (STREAM_RR, DG_RR)\n\
-s send[,recv] Set local socket send/recv buffer sizes\n\
-S send[,recv] Set remote socket send/recv buffer sizes\n\
\n\
For those options taking two parms, at least one must be specified;\n\
specifying one value without a comma will set both parms to that\n\
value, specifying a value with a leading comma will set just the second\n\
parm, a value with a trailing comma will set just the first. To set\n\
each parm to unique values, specify both and separate them with a\n\
comma.\n";
/* this routing initializes all the test specific variables */
static void
init_test_vars()
{
rss_size = 0;
rsr_size = 0;
lss_size_req = 0;
lsr_size_req = 0;
lss_size = 0;
lsr_size = 0;
req_size = 1;
rsp_size = 1;
send_size = 0;
recv_size = 0;
strcpy(path_prefix,"/tmp");
}
/* This routine will create a data (listen) socket with the apropriate */
/* options set and return it to the caller. this replaces all the */
/* duplicate code in each of the test routines and should help make */
/* things a little easier to understand. since this routine can be */
/* called by either the netperf or netserver programs, all output */
/* should be directed towards "where." family is generally AF_UNIX, */
/* and type will be either SOCK_STREAM or SOCK_DGRAM */
SOCKET
create_unix_socket(int family, int type)
{
SOCKET temp_socket;
int sock_opt_len;
/*set up the data socket */
temp_socket = socket(family,
type,
0);
if (temp_socket == INVALID_SOCKET){
fprintf(where,
"netperf: create_unix_socket: socket: %d\n",
errno);
fflush(where);
exit(1);
}
if (debug) {
fprintf(where,"create_unix_socket: socket %d obtained...\n",temp_socket);
fflush(where);
}
/* Modify the local socket size. The reason we alter the send buffer */
/* size here rather than when the connection is made is to take care */
/* of decreases in buffer size. Decreasing the window size after */
/* connection establishment is a STREAM no-no. Also, by setting the */
/* buffer (window) size before the connection is established, we can */
/* control the STREAM MSS (segment size). The MSS is never more that 1/2 */
/* the minimum receive buffer size at each half of the connection. */
/* This is why we are altering the receive buffer size on the sending */
/* size of a unidirectional transfer. If the user has not requested */
/* that the socket buffers be altered, we will try to find-out what */
/* their values are. If we cannot touch the socket buffer in any way, */
/* we will set the values to -1 to indicate that. */
set_sock_buffer(temp_socket, SEND_BUFFER, lss_size_req, &lss_size);
set_sock_buffer(temp_socket, RECV_BUFFER, lsr_size_req, &lsr_size);
return(temp_socket);
}
/* This routine implements the STREAM unidirectional data transfer test */
/* (a.k.a. stream) for the sockets interface. It receives its */
/* parameters via global variables from the shell and writes its */
/* output to the standard output. */
void
send_stream_stream(char remote_host[])
{
char *tput_title = "\
Recv Send Send \n\
Socket Socket Message Elapsed \n\
Size Size Size Time Throughput \n\
bytes bytes bytes secs. %s/sec \n\n";
char *tput_fmt_0 =
"%7.2f\n";
char *tput_fmt_1 =
"%5d %5d %6d %-6.2f %7.2f \n";
char *cpu_title = "\
Recv Send Send Utilization Service Demand\n\
Socket Socket Message Elapsed Send Recv Send Recv\n\
Size Size Size Time Throughput local remote local remote\n\
bytes bytes bytes secs. %-8.8s/s %% %% us/KB us/KB\n\n";
char *cpu_fmt_0 =
"%6.3f\n";
char *cpu_fmt_1 =
"%5d %5d %6d %-6.2f %7.2f %-6.2f %-6.2f %-6.3f %-6.3f\n";
char *ksink_fmt = "\n\
Alignment Offset %-8.8s %-8.8s Sends %-8.8s Recvs\n\
Local Remote Local Remote Xfered Per Per\n\
Send Recv Send Recv Send (avg) Recv (avg)\n\
%5d %5d %5d %5d %6.4g %6.2f %6d %6.2f %6d\n";
float elapsed_time;
#ifdef WANT_INTERVALS
int interval_count;
#endif
/* what we want is to have a buffer space that is at least one */
/* send-size greater than our send window. this will insure that we */
/* are never trying to re-use a buffer that may still be in the hands */
/* of the transport. This buffer will be malloc'd after we have found */
/* the size of the local senc socket buffer. We will want to deal */
/* with alignment and offset concerns as well. */
#ifdef DIRTY
int *message_int_ptr;
#endif
#include <sys/stat.h>
struct ring_elt *send_ring;
int len = 0;
int nummessages;
SOCKET send_socket;
int bytes_remaining;
/* with links like fddi, one can send > 32 bits worth of bytes */
/* during a test... ;-) */
double bytes_sent;
#ifdef DIRTY
int i;
#endif /* DIRTY */
float local_cpu_utilization;
float local_service_demand;
float remote_cpu_utilization;
float remote_service_demand;
double thruput;
struct sockaddr_un server;
struct stream_stream_request_struct *stream_stream_request;
struct stream_stream_response_struct *stream_stream_response;
struct stream_stream_results_struct *stream_stream_result;
stream_stream_request =
(struct stream_stream_request_struct *)netperf_request.content.test_specific_data;
stream_stream_response =
(struct stream_stream_response_struct *)netperf_response.content.test_specific_data;
stream_stream_result =
(struct stream_stream_results_struct *)netperf_response.content.test_specific_data;
/* since we are now disconnected from the code that established the */
/* control socket, and since we want to be able to use different */
/* protocols and such, we are passed the name of the remote host and */
/* must turn that into the test specific addressing information. */
bzero((char *)&server,
sizeof(server));
server.sun_family = AF_UNIX;
if ( print_headers ) {
fprintf(where,"STREAM STREAM TEST\n");
if (local_cpu_usage || remote_cpu_usage)
fprintf(where,cpu_title,format_units());
else
fprintf(where,tput_title,format_units());
}
/* initialize a few counters */
nummessages = 0;
bytes_sent = 0.0;
times_up = 0;
/*set up the data socket */
send_socket = create_unix_socket(AF_UNIX,
SOCK_STREAM);
if (send_socket == INVALID_SOCKET){
perror("netperf: send_stream_stream: stream stream data socket");
exit(1);
}
if (debug) {
fprintf(where,"send_stream_stream: send_socket obtained...\n");
}
/* at this point, we have either retrieved the socket buffer sizes, */
/* or have tried to set them, so now, we may want to set the send */
/* size based on that (because the user either did not use a -m */
/* option, or used one with an argument of 0). If the socket buffer */
/* size is not available, we will set the send size to 4KB - no */
/* particular reason, just arbitrary... */
if (send_size == 0) {
if (lss_size > 0) {
send_size = lss_size;
}
else {
send_size = 4096;
}
}
/* set-up the data buffer ring with the requested alignment and offset. */
/* note also that we have allocated a quantity */
/* of memory that is at least one send-size greater than our socket */
/* buffer size. We want to be sure that there are at least two */
/* buffers allocated - this can be a bit of a problem when the */
/* send_size is bigger than the socket size, so we must check... the */
/* user may have wanted to explicitly set the "width" of our send */
/* buffers, we should respect that wish... */
if (send_width == 0) {
send_width = (lss_size/send_size) + 1;
if (send_width == 1) send_width++;
}
send_ring = allocate_buffer_ring(send_width,
send_size,
local_send_align,
local_send_offset);
/* If the user has requested cpu utilization measurements, we must */
/* calibrate the cpu(s). We will perform this task within the tests */
/* themselves. If the user has specified the cpu rate, then */
/* calibrate_local_cpu will return rather quickly as it will have */
/* nothing to do. If local_cpu_rate is zero, then we will go through */
/* all the "normal" calibration stuff and return the rate back.*/
if (local_cpu_usage) {
local_cpu_rate = calibrate_local_cpu(local_cpu_rate);
}
/* Tell the remote end to do a listen. The server alters the socket */
/* paramters on the other side at this point, hence the reason for */
/* all the values being passed in the setup message. If the user did */
/* not specify any of the parameters, they will be passed as 0, which */
/* will indicate to the remote that no changes beyond the system's */
/* default should be used. Alignment is the exception, it will */
/* default to 1, which will be no alignment alterations. */
netperf_request.content.request_type = DO_STREAM_STREAM;
stream_stream_request->send_buf_size = rss_size;
stream_stream_request->recv_buf_size = rsr_size;
stream_stream_request->receive_size = recv_size;
stream_stream_request->recv_alignment = remote_recv_align;
stream_stream_request->recv_offset = remote_recv_offset;
stream_stream_request->measure_cpu = remote_cpu_usage;
stream_stream_request->cpu_rate = remote_cpu_rate;
if (test_time) {
stream_stream_request->test_length = test_time;
}
else {
stream_stream_request->test_length = test_bytes;
}
#ifdef DIRTY
stream_stream_request->dirty_count = rem_dirty_count;
stream_stream_request->clean_count = rem_clean_count;
#endif /* DIRTY */
if (debug > 1) {
fprintf(where,
"netperf: send_stream_stream: requesting STREAM stream test\n");
}
send_request();
/* The response from the remote will contain all of the relevant */
/* socket parameters for this test type. We will put them back into */
/* the variables here so they can be displayed if desired. The */
/* remote will have calibrated CPU if necessary, and will have done */
/* all the needed set-up we will have calibrated the cpu locally */
/* before sending the request, and will grab the counter value right */
/* after the connect returns. The remote will grab the counter right */
/* after the accept call. This saves the hassle of extra messages */
/* being sent for the STREAM tests. */
recv_response();
if (!netperf_response.content.serv_errno) {
if (debug)
fprintf(where,"remote listen done.\n");
rsr_size = stream_stream_response->recv_buf_size;
rss_size = stream_stream_response->send_buf_size;
remote_cpu_usage = stream_stream_response->measure_cpu;
remote_cpu_rate = stream_stream_response->cpu_rate;
strcpy(server.sun_path,stream_stream_response->unix_path);
}
else {
Set_errno(netperf_response.content.serv_errno);
perror("netperf: send_stream_stream: remote error");
exit(1);
}
/*Connect up to the remote port on the data socket */
if (connect(send_socket,
(struct sockaddr *)&server,
sizeof(server)) == INVALID_SOCKET){
perror("netperf: send_stream_stream: data socket connect failed");
printf(" path: %s\n",server.sun_path);
exit(1);
}
/* Data Socket set-up is finished. If there were problems, either the */
/* connect would have failed, or the previous response would have */
/* indicated a problem. I failed to see the value of the extra */
/* message after the accept on the remote. If it failed, we'll see it */
/* here. If it didn't, we might as well start pumping data. */
/* Set-up the test end conditions. For a stream test, they can be */
/* either time or byte-count based. */
if (test_time) {
/* The user wanted to end the test after a period of time. */
times_up = 0;
bytes_remaining = 0;
start_timer(test_time);
}
else {
/* The tester wanted to send a number of bytes. */
bytes_remaining = test_bytes;
times_up = 1;
}
/* The cpu_start routine will grab the current time and possibly */
/* value of the idle counter for later use in measuring cpu */
/* utilization and/or service demand and thruput. */
cpu_start(local_cpu_usage);
/* We use an "OR" to control test execution. When the test is */
/* controlled by time, the byte count check will always return false. */
/* When the test is controlled by byte count, the time test will */
/* always return false. When the test is finished, the whole */
/* expression will go false and we will stop sending data. */
#ifdef DIRTY
/* initialize the random number generator for putting dirty stuff */
/* into the send buffer. raj */
srand((int) getpid());
#endif
while ((!times_up) || (bytes_remaining > 0)) {
#ifdef DIRTY
/* we want to dirty some number of consecutive integers in the buffer */
/* we are about to send. we may also want to bring some number of */
/* them cleanly into the cache. The clean ones will follow any dirty */
/* ones into the cache. at some point, we might want to replace */
/* the rand() call with something from a table to reduce our call */
/* overhead during the test, but it is not a high priority item. */
message_int_ptr = (int *)(send_ring->buffer_ptr);
for (i = 0; i < loc_dirty_count; i++) {
*message_int_ptr = rand();
message_int_ptr++;
}
for (i = 0; i < loc_clean_count; i++) {
loc_dirty_count = *message_int_ptr;
message_int_ptr++;
}
#endif /* DIRTY */
if((len=send(send_socket,
send_ring->buffer_ptr,
send_size,
0)) != send_size) {
if ((len >=0) || (errno == EINTR)) {
/* the test was interrupted, must be the end of test */
break;
}
perror("netperf: data send error");
printf("len was %d\n",len);
exit(1);
}
#ifdef WANT_INTERVALS
for (interval_count = 0;
interval_count < interval_wate;
interval_count++);
#endif
/* now we want to move our pointer to the next position in the */
/* data buffer...we may also want to wrap back to the "beginning" */
/* of the bufferspace, so we will mod the number of messages sent */
/* by the send width, and use that to calculate the offset to add */
/* to the base pointer. */
nummessages++;
send_ring = send_ring->next;
if (bytes_remaining) {
bytes_remaining -= send_size;
}
}
/* The test is over. Flush the buffers to the remote end. We do a */
/* graceful release to insure that all data has been taken by the */
/* remote. */
if (close(send_socket) == -1) {
perror("netperf: send_stream_stream: cannot close socket");
exit(1);
}
/* this call will always give us the elapsed time for the test, and */
/* will also store-away the necessaries for cpu utilization */
cpu_stop(local_cpu_usage,&elapsed_time); /* was cpu being */
/* measured and how */
/* long did we really */
/* run? */
/* Get the statistics from the remote end. The remote will have */
/* calculated service demand and all those interesting things. If it */
/* wasn't supposed to care, it will return obvious values. */
recv_response();
if (!netperf_response.content.serv_errno) {
if (debug)
fprintf(where,"remote results obtained\n");
}
else {
Set_errno(netperf_response.content.serv_errno);
perror("netperf: remote error");
exit(1);
}
/* We now calculate what our thruput was for the test. In the future, */
/* we may want to include a calculation of the thruput measured by */
/* the remote, but it should be the case that for a STREAM stream test, */
/* that the two numbers should be *very* close... We calculate */
/* bytes_sent regardless of the way the test length was controlled. */
/* If it was time, we needed to, and if it was by bytes, the user may */
/* have specified a number of bytes that wasn't a multiple of the */
/* send_size, so we really didn't send what he asked for ;-) */
bytes_sent = ((double) send_size * (double) nummessages) + len;
thruput = calc_thruput(bytes_sent);
if (local_cpu_usage || remote_cpu_usage) {
/* We must now do a little math for service demand and cpu */
/* utilization for the system(s) */
/* Of course, some of the information might be bogus because */
/* there was no idle counter in the kernel(s). We need to make */
/* a note of this for the user's benefit...*/
if (local_cpu_usage) {
if (local_cpu_rate == 0.0) {
fprintf(where,"WARNING WARNING WARNING WARNING WARNING WARNING WARNING!\n");
fprintf(where,"Local CPU usage numbers based on process information only!\n");
fflush(where);
}
local_cpu_utilization = calc_cpu_util(0.0);
local_service_demand = calc_service_demand(bytes_sent,
0.0,
0.0,
0);
}
else {
local_cpu_utilization = -1.0;
local_service_demand = -1.0;
}
if (remote_cpu_usage) {
if (remote_cpu_rate == 0.0) {
fprintf(where,"DANGER DANGER DANGER DANGER DANGER DANGER DANGER!\n");
fprintf(where,"Remote CPU usage numbers based on process information only!\n");
fflush(where);
}
remote_cpu_utilization = stream_stream_result->cpu_util;
remote_service_demand = calc_service_demand(bytes_sent,
0.0,
remote_cpu_utilization,
stream_stream_result->num_cpus);
}
else {
remote_cpu_utilization = -1.0;
remote_service_demand = -1.0;
}
/* We are now ready to print all the information. If the user */
/* has specified zero-level verbosity, we will just print the */
/* local service demand, or the remote service demand. If the */
/* user has requested verbosity level 1, he will get the basic */
/* "streamperf" numbers. If the user has specified a verbosity */
/* of greater than 1, we will display a veritable plethora of */
/* background information from outside of this block as it it */
/* not cpu_measurement specific... */
switch (verbosity) {
case 0:
if (local_cpu_usage) {
fprintf(where,
cpu_fmt_0,
local_service_demand);
}
else {
fprintf(where,
cpu_fmt_0,
remote_service_demand);
}
break;
case 1:
case 2:
fprintf(where,
cpu_fmt_1, /* the format string */
rsr_size, /* remote recvbuf size */
lss_size, /* local sendbuf size */
send_size, /* how large were the sends */
elapsed_time, /* how long was the test */
thruput, /* what was the xfer rate */
local_cpu_utilization, /* local cpu */
remote_cpu_utilization, /* remote cpu */
local_service_demand, /* local service demand */
remote_service_demand); /* remote service demand */
break;
}
}
else {
/* The tester did not wish to measure service demand. */
switch (verbosity) {
case 0:
fprintf(where,
tput_fmt_0,
thruput);
break;
case 1:
case 2:
fprintf(where,
tput_fmt_1, /* the format string */
rsr_size, /* remote recvbuf size */
lss_size, /* local sendbuf size */
send_size, /* how large were the sends */
elapsed_time, /* how long did it take */
thruput);/* how fast did it go */
break;
}
}
/* it would be a good thing to include information about some of the */
/* other parameters that may have been set for this test, but at the */
/* moment, I do not wish to figure-out all the formatting, so I will */
/* just put this comment here to help remind me that it is something */
/* that should be done at a later time. */
if (verbosity > 1) {
/* The user wanted to know it all, so we will give it to him. */
/* This information will include as much as we can find about */
/* STREAM statistics, the alignments of the sends and receives */
/* and all that sort of rot... */
fprintf(where,
ksink_fmt,
"Bytes",
"Bytes",
"Bytes",
local_send_align,
remote_recv_align,
local_send_offset,
remote_recv_offset,
bytes_sent,
bytes_sent / (double)nummessages,
nummessages,
bytes_sent / (double)stream_stream_result->recv_calls,
stream_stream_result->recv_calls);
}
}
/* This is the server-side routine for the stream stream test. It is */
/* implemented as one routine. I could break things-out somewhat, but */
/* didn't feel it was necessary. */
void
recv_stream_stream()
{
struct sockaddr_un myaddr_un, peeraddr_un;
SOCKET s_listen,s_data;
int addrlen;
int len;
int receive_calls = 0;
float elapsed_time;
int bytes_received;
struct ring_elt *recv_ring;
#ifdef DIRTY
char *message_ptr;
int *message_int_ptr;
int dirty_count;
int clean_count;
int i;
#endif
struct stream_stream_request_struct *stream_stream_request;
struct stream_stream_response_struct *stream_stream_response;
struct stream_stream_results_struct *stream_stream_results;
stream_stream_request =
(struct stream_stream_request_struct *)netperf_request.content.test_specific_data;
stream_stream_response =
(struct stream_stream_response_struct *)netperf_response.content.test_specific_data;
stream_stream_results =
(struct stream_stream_results_struct *)netperf_response.content.test_specific_data;
if (debug) {
fprintf(where,"netserver: recv_stream_stream: entered...\n");
fflush(where);
}
/* We want to set-up the listen socket with all the desired */
/* parameters and then let the initiator know that all is ready. If */
/* socket size defaults are to be used, then the initiator will have */
/* sent us 0's. If the socket sizes cannot be changed, then we will */
/* send-back what they are. If that information cannot be determined, */
/* then we send-back -1's for the sizes. If things go wrong for any */
/* reason, we will drop back ten yards and punt. */
/* If anything goes wrong, we want the remote to know about it. It */
/* would be best if the error that the remote reports to the user is */
/* the actual error we encountered, rather than some bogus unexpected */
/* response type message. */
if (debug) {
fprintf(where,"recv_stream_stream: setting the response type...\n");
fflush(where);
}
netperf_response.content.response_type = STREAM_STREAM_RESPONSE;
if (debug) {
fprintf(where,"recv_stream_stream: the response type is set...\n");
fflush(where);
}
/* We now alter the message_ptr variable to be at the desired */
/* alignment with the desired offset. */
if (debug) {
fprintf(where,"recv_stream_stream: requested alignment of %d\n",
stream_stream_request->recv_alignment);
fflush(where);
}
/* Let's clear-out our sockaddr for the sake of cleanlines. Then we */
/* can put in OUR values !-) At some point, we may want to nail this */
/* socket to a particular network-level address, but for now, */
/* INADDR_ANY should be just fine. */
bzero((char *)&myaddr_un,
sizeof(myaddr_un));
myaddr_un.sun_family = AF_UNIX;
/* Grab a socket to listen on, and then listen on it. */
if (debug) {
fprintf(where,"recv_stream_stream: grabbing a socket...\n");
fflush(where);
}
/* create_unix_socket expects to find some things in the global */
/* variables, so set the globals based on the values in the request. */
/* once the socket has been created, we will set the response values */
/* based on the updated value of those globals. raj 7/94 */
lss_size_req = stream_stream_request->send_buf_size;
lsr_size_req = stream_stream_request->recv_buf_size;
s_listen = create_unix_socket(AF_UNIX,
SOCK_STREAM);
if (s_listen == INVALID_SOCKET) {
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
/* Let's get an address assigned to this socket so we can tell the */
/* initiator how to reach the data socket. There may be a desire to */
/* nail this socket to a specific IP address in a multi-homed, */
/* multi-connection situation, but for now, we'll ignore the issue */
/* and concentrate on single connection testing. */
strcpy(myaddr_un.sun_path,tempnam(path_prefix,"netperf."));
if (debug) {
fprintf(where,"selected a path of %s\n",myaddr_un.sun_path);
fflush(where);
}
if (bind(s_listen,
(struct sockaddr *)&myaddr_un,
sizeof(myaddr_un)) == SOCKET_ERROR) {
netperf_response.content.serv_errno = errno;
fprintf(where,"could not bind to path\n");
close(s_listen);
send_response();
exit(1);
}
chmod(myaddr_un.sun_path, 0666);
/* what sort of sizes did we end-up with? */
if (stream_stream_request->receive_size == 0) {
if (lsr_size > 0) {
recv_size = lsr_size;
}
else {
recv_size = 4096;
}
}
else {
recv_size = stream_stream_request->receive_size;
}
/* we want to set-up our recv_ring in a manner analagous to what we */
/* do on the sending side. this is more for the sake of symmetry */
/* than for the needs of say copy avoidance, but it might also be */
/* more realistic - this way one could conceivably go with a */
/* double-buffering scheme when taking the data an putting it into */
/* the filesystem or something like that. raj 7/94 */
if (recv_width == 0) {
recv_width = (lsr_size/recv_size) + 1;
if (recv_width == 1) recv_width++;
}
recv_ring = allocate_buffer_ring(recv_width,
recv_size,
stream_stream_request->recv_alignment,
stream_stream_request->recv_offset);
if (debug) {
fprintf(where,"recv_stream_stream: receive alignment and offset set...\n");
fflush(where);
}
/* Now, let's set-up the socket to listen for connections */
if (listen(s_listen, 5) == SOCKET_ERROR) {
netperf_response.content.serv_errno = errno;
close(s_listen);
send_response();
exit(1);
}
/* now get the port number assigned by the system */
addrlen = sizeof(myaddr_un);
if (getsockname(s_listen,
(struct sockaddr *)&myaddr_un,
&addrlen) == SOCKET_ERROR){
netperf_response.content.serv_errno = errno;
close(s_listen);
send_response();
exit(1);
}
/* Now myaddr_un contains the path */
/* returned to the sender also implicitly telling the sender that the */
/* socket buffer sizing has been done. */
strcpy(stream_stream_response->unix_path,myaddr_un.sun_path);
netperf_response.content.serv_errno = 0;
/* But wait, there's more. If the initiator wanted cpu measurements, */
/* then we must call the calibrate routine, which will return the max */
/* rate back to the initiator. If the CPU was not to be measured, or */
/* something went wrong with the calibration, we will return a -1 to */
/* the initiator. */
stream_stream_response->cpu_rate = 0.0; /* assume no cpu */
if (stream_stream_request->measure_cpu) {
stream_stream_response->measure_cpu = 1;
stream_stream_response->cpu_rate =
calibrate_local_cpu(stream_stream_request->cpu_rate);
}
/* before we send the response back to the initiator, pull some of */
/* the socket parms from the globals */
stream_stream_response->send_buf_size = lss_size;
stream_stream_response->recv_buf_size = lsr_size;
stream_stream_response->receive_size = recv_size;
send_response();
addrlen = sizeof(peeraddr_un);
if ((s_data=accept(s_listen,
(struct sockaddr *)&peeraddr_un,
&addrlen)) == INVALID_SOCKET) {
/* Let's just punt. The remote will be given some information */
close(s_listen);
exit(1);
}
/* Now it's time to start receiving data on the connection. We will */
/* first grab the apropriate counters and then start grabbing. */
cpu_start(stream_stream_request->measure_cpu);
/* The loop will exit when the sender does a shutdown, which will */
/* return a length of zero */
#ifdef DIRTY
/* we want to dirty some number of consecutive integers in the buffer */
/* we are about to recv. we may also want to bring some number of */
/* them cleanly into the cache. The clean ones will follow any dirty */
/* ones into the cache. */
dirty_count = stream_stream_request->dirty_count;
clean_count = stream_stream_request->clean_count;
message_int_ptr = (int *)recv_ring->buffer_ptr;
for (i = 0; i < dirty_count; i++) {
*message_int_ptr = rand();
message_int_ptr++;
}
for (i = 0; i < clean_count; i++) {
dirty_count = *message_int_ptr;
message_int_ptr++;
}
#endif /* DIRTY */
bytes_received = 0;
while ((len = recv(s_data, recv_ring->buffer_ptr, recv_size, 0)) != 0) {
if (len == SOCKET_ERROR) {
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
bytes_received += len;
receive_calls++;
/* more to the next buffer in the recv_ring */
recv_ring = recv_ring->next;
#ifdef DIRTY
message_int_ptr = (int *)(recv_ring->buffer_ptr);
for (i = 0; i < dirty_count; i++) {
*message_int_ptr = rand();
message_int_ptr++;
}
for (i = 0; i < clean_count; i++) {
dirty_count = *message_int_ptr;
message_int_ptr++;
}
#endif /* DIRTY */
}
/* The loop now exits due to zero bytes received. we will have */
/* counted one too many messages received, so decrement the */
/* receive_calls counter by one. raj 7/94 */
receive_calls--;
/* perform a shutdown to signal the sender that */
/* we have received all the data sent. raj 4/93 */
if (shutdown(s_data,1) == SOCKET_ERROR) {
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
cpu_stop(stream_stream_request->measure_cpu,&elapsed_time);
/* send the results to the sender */
if (debug) {
fprintf(where,
"recv_stream_stream: got %d bytes\n",
bytes_received);
fprintf(where,