-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnettest_dlpi.c
3798 lines (3188 loc) · 122 KB
/
nettest_dlpi.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
/****************************************************************/
/* */
/* nettest_dlpi.c */
/* */
/* the actual test routines... */
/* */
/* send_dlpi_co_stream() perform a CO DLPI stream test */
/* recv_dlpi_co_stream() */
/* send_dlpi_co_rr() perform a CO DLPI req/res */
/* recv_dlpi_co_rr() */
/* send_dlpi_cl_stream() perform a CL DLPI stream test */
/* recv_dlpi_cl_stream() */
/* send_dlpi_cl_rr() perform a CL DLPI req/res */
/* recv_dlpi_cl_rr() */
/* */
/****************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef WANT_DLPI
char nettest_dlpi_id[]="\
@(#)nettest_dlpi.c (c) Copyright 1993,1995,2004 Hewlett-Packard Co. Version 2.4.3";
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <malloc.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/poll.h>
#ifdef __osf__
#include <sys/dlpihdr.h>
#else /* __osf__ */
#include <sys/dlpi.h>
#ifdef __hpux__
#include <sys/dlpi_ext.h>
#endif /* __hpux__ */
#endif /* __osf__ */
#include "netlib.h"
#include "netsh.h"
#include "nettest_dlpi.h"
/* these are some variables global to all the DLPI tests. declare */
/* them static to make them global only to this file */
static int
rsw_size, /* remote send window size */
rrw_size, /* remote recv window size */
lsw_size, /* local send window size */
lrw_size, /* local recv window size */
req_size = 100, /* request size */
rsp_size = 200, /* response size */
send_size, /* how big are individual sends */
recv_size; /* how big are individual receives */
int
loc_ppa = 4, /* the ppa for the local interface, */
/* as shown as the NM Id in lanscan */
rem_ppa = 4, /* the ppa for the remote interface */
dlpi_sap = 84; /* which 802.2 SAP should we use? */
char loc_dlpi_device[32] = "/dev/dlpi";
char rem_dlpi_device[32] = "/dev/dlpi";
char dlpi_usage[] = "\n\
Usage: netperf [global options] -- [test options] \n\
\n\
CO/CL DLPI Test Options:\n\
-D dev[,dev] Set the local/remote DLPI device file name\n\
-h Display this text\n\
-M bytes Set the recv size (DLCO_STREAM, DLCL_STREAM)\n\
-m bytes Set the send size (DLCO_STREAM, DLCL_STREAM)\n\
-p loc[,rem] Set the local/remote PPA for the test\n\
-R bytes Set response size (DLCO_RR, DLCL_RR)\n\
-r bytes Set request size (DLCO_RR, DLCL_RR)\n\
-s sap Set the 802.2 sap for the test\n\
-W send[,recv] Set remote send/recv window sizes\n\
-w send[,recv] Set local send/recv window 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 routine implements the CO 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_dlpi_co_stream()
{
char *tput_title = "\
Recv Send Send \n\
Window Window Message Elapsed \n\
Size Size Size Time Throughput \n\
frames frames 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\
Window Window Message Elapsed Send Recv Send Recv\n\
Size Size Size Time Throughput local remote local remote\n\
frames frames 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 /* WANT_INTERVALS */
/* 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. */
struct ring_elt *send_ring;
char *message;
char *message_ptr;
struct strbuf send_message;
char dlsap[BUFSIZ];
int dlsap_len;
int *message_int_ptr;
int message_offset;
int malloc_size;
int len;
int nummessages;
int send_descriptor;
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 dlpi_co_stream_request_struct *dlpi_co_stream_request;
struct dlpi_co_stream_response_struct *dlpi_co_stream_response;
struct dlpi_co_stream_results_struct *dlpi_co_stream_result;
dlpi_co_stream_request =
(struct dlpi_co_stream_request_struct *)netperf_request.content.test_specific_data;
dlpi_co_stream_response =
(struct dlpi_co_stream_response_struct *)netperf_response.content.test_specific_data;
dlpi_co_stream_result =
(struct dlpi_co_stream_results_struct *)netperf_response.content.test_specific_data;
if ( print_headers ) {
fprintf(where,"DLPI CO 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 descriptor */
send_descriptor = dl_open(loc_dlpi_device,loc_ppa);
if (send_descriptor < 0){
perror("netperf: send_dlpi_co_stream: dlpi stream data descriptor");
exit(1);
}
/* bind the puppy and get the assigned dlsap */
dlsap_len = BUFSIZ;
if (dl_bind(send_descriptor,
dlpi_sap, DL_CODLS, dlsap, &dlsap_len) != 0) {
fprintf(where,"send_dlpi_co_rr: bind failure\n");
fflush(where);
exit(1);
}
if (debug) {
fprintf(where,"send_dlpi_co_stream: send_descriptor obtained...\n");
}
#ifdef DL_HP_SET_LOCAL_WIN_REQ
if (lsw_size > 0) {
if (debug > 1) {
fprintf(where,"netperf: send_dlpi_co_stream: window send size altered from system default...\n");
fprintf(where," send: %d\n",lsw_size);
}
}
if (lrw_size > 0) {
if (debug > 1) {
fprintf(where,
"netperf: send_dlpi_co_stream: window recv size altered from system default...\n");
fprintf(where," recv: %d\n",lrw_size);
}
}
/* Now, we will find-out what the size actually became, and report */
/* that back to the user. If the call fails, we will just report a -1 */
/* back to the initiator for the recv buffer size. */
if (debug) {
fprintf(where,
"netperf: send_dlpi_co_stream: window sizes determined...\n");
fprintf(where," send: %d recv: %d\n",lsw_size,lrw_size);
ffluch(where);
}
#else /* DL_HP_SET_LOCAL_WIN_REQ */
lsw_size = -1;
lrw_size = -1;
#endif /* DL_HP_SET_LOCAL_WIN_REQ */
/* we should pick a default send_size, it should not be larger than */
/* the min of the two interface MTU's, and should perhaps default to */
/* the Interface MTU, but for now, we will default it to 1024... if */
/* someone wants to change this, the should change the corresponding */
/* lines in the recv_dlpi_co_stream routine */
if (send_size == 0) {
send_size = 1024;
}
/* set-up the data buffer with the requested alignment and offset. */
/* After we have calculated the proper starting address, we want to */
/* put that back into the message variable so we go back to the */
/* proper place. note that this means that only the first send is */
/* guaranteed to be at the alignment specified by the -a parameter. I */
/* think that this is a little more "real-world" than what was found */
/* in previous versions. 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 = (lsw_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);
send_message.maxlen = send_size;
send_message.len = send_size;
send_message.buf = send_ring->buffer_ptr;
/* 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. */
netperf_request.content.request_type = DO_DLPI_CO_STREAM;
dlpi_co_stream_request->send_win_size = rsw_size;
dlpi_co_stream_request->recv_win_size = rrw_size;
dlpi_co_stream_request->receive_size = recv_size;
dlpi_co_stream_request->recv_alignment= remote_recv_align;
dlpi_co_stream_request->recv_offset = remote_recv_offset;
dlpi_co_stream_request->measure_cpu = remote_cpu_usage;
dlpi_co_stream_request->cpu_rate = remote_cpu_rate;
dlpi_co_stream_request->ppa = rem_ppa;
dlpi_co_stream_request->sap = dlpi_sap;
dlpi_co_stream_request->dev_name_len = strlen(rem_dlpi_device);
strcpy(dlpi_co_stream_request->dlpi_device,
rem_dlpi_device);
#ifdef __alpha
/* ok - even on a DEC box, strings are strings. I didn't really want */
/* to ntohl the words of a string. since I don't want to teach the */
/* send_ and recv_ _request and _response routines about the types, */
/* I will put "anti-ntohl" calls here. I imagine that the "pure" */
/* solution would be to use XDR, but I am still leary of being able */
/* to find XDR libs on all platforms I want running netperf. raj */
{
int *charword;
int *initword;
int *lastword;
initword = (int *) dlpi_co_stream_request->dlpi_device;
lastword = initword + ((strlen(rem_dlpi_device) + 3) / 4);
for (charword = initword;
charword < lastword;
charword++) {
*charword = ntohl(*charword);
}
}
#endif /* __alpha */
if (test_time) {
dlpi_co_stream_request->test_length = test_time;
}
else {
dlpi_co_stream_request->test_length = test_bytes;
}
#ifdef DIRTY
dlpi_co_stream_request->dirty_count = rem_dirty_count;
dlpi_co_stream_request->clean_count = rem_clean_count;
#endif /* DIRTY */
if (debug > 1) {
fprintf(where,
"netperf: send_dlpi_co_stream: requesting DLPI CO stream test\n");
}
send_request();
/* The response from the remote will contain all of the relevant */
/* 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 TCP tests. */
recv_response();
if (!netperf_response.content.serv_errno) {
if (debug)
fprintf(where,"remote listen done.\n");
rrw_size = dlpi_co_stream_response->recv_win_size;
rsw_size = dlpi_co_stream_response->send_win_size;
remote_cpu_usage= dlpi_co_stream_response->measure_cpu;
remote_cpu_rate = dlpi_co_stream_response->cpu_rate;
}
else {
Set_errno(netperf_response.content.serv_errno);
perror("netperf: remote error");
exit(1);
}
/* Connect up to the remote port on the data descriptor */
if(dl_connect(send_descriptor,
dlpi_co_stream_response->station_addr,
dlpi_co_stream_response->station_addr_len) != 0) {
fprintf(where,"recv_dlpi_co_stream: connect failure\n");
fflush(where);
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 /* DIRTY */
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. */
message_int_ptr = (int *)message_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((putmsg(send_descriptor,
0,
&send_message,
0)) != 0) {
if (errno == EINTR)
break;
perror("netperf: data send error");
exit(1);
}
send_ring = send_ring->next;
send_message.buf = send_ring->buffer_ptr;
#ifdef WANT_INTERVALS
for (interval_count = 0;
interval_count < interval_wate;
interval_count++);
#endif /* WANT_INTERVALS */
if (debug > 4) {
fprintf(where,"netperf: send_clpi_co_stream: putmsg called ");
fprintf(where,"len is %d\n",send_message.len);
fflush(where);
}
nummessages++;
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. this needs a little work - there is no three-way */
/* handshake with type two as there is with TCP, so there really */
/* should be a message exchange here. however, we will finesse it by */
/* saying that the tests shoudl run for a while. */
if (debug) {
fprintf(where,"sending test end signal \n");
fflush(where);
}
send_message.len = (send_size - 1);
if (send_message.len == 0) send_message.len = 2;
if((putmsg(send_descriptor,
0,
&send_message,
0)) != 0) {
perror("netperf: data send error");
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? */
/* 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 TCP 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) + (double) 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 = dlpi_co_stream_result->cpu_util;
remote_service_demand = calc_service_demand(bytes_sent,
0.0,
remote_cpu_utilization,
dlpi_co_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 */
rrw_size, /* remote recvbuf size */
lsw_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 */
rrw_size, /* remote recvbuf size */
lsw_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 */
/* TCP 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)dlpi_co_stream_result->recv_calls,
dlpi_co_stream_result->recv_calls);
}
}
/* This is the server-side routine for the tcp stream test. It is */
/* implemented as one routine. I could break things-out somewhat, but */
/* didn't feel it was necessary. */
int
recv_dlpi_co_stream()
{
int data_descriptor;
int flags = 0;
int measure_cpu;
int bytes_received;
int receive_calls;
float elapsed_time;
struct ring_elt *recv_ring;
char *message_ptr;
char *message;
int *message_int_ptr;
struct strbuf recv_message;
int dirty_count;
int clean_count;
int i;
struct dlpi_co_stream_request_struct *dlpi_co_stream_request;
struct dlpi_co_stream_response_struct *dlpi_co_stream_response;
struct dlpi_co_stream_results_struct *dlpi_co_stream_results;
dlpi_co_stream_request = (struct dlpi_co_stream_request_struct *)netperf_request.content.test_specific_data;
dlpi_co_stream_response = (struct dlpi_co_stream_response_struct *)netperf_response.content.test_specific_data;
dlpi_co_stream_results = (struct dlpi_co_stream_results_struct *)netperf_response.content.test_specific_data;
if (debug) {
fprintf(where,"netserver: recv_dlpi_co_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. */
netperf_response.content.response_type = DLPI_CO_STREAM_RESPONSE;
/* We now alter the message_ptr variable to be at the desired */
/* alignment with the desired offset. */
if (debug > 1) {
fprintf(where,"recv_dlpi_co_stream: requested alignment of %d\n",
dlpi_co_stream_request->recv_alignment);
fflush(where);
}
/* Grab a descriptor to listen on, and then listen on it. */
if (debug > 1) {
fprintf(where,"recv_dlpi_co_stream: grabbing a descriptor...\n");
fflush(where);
}
#ifdef __alpha
/* ok - even on a DEC box, strings are strings. I din't really want */
/* to ntohl the words of a string. since I don't want to teach the */
/* send_ and recv_ _request and _response routines about the types, */
/* I will put "anti-ntohl" calls here. I imagine that the "pure" */
/* solution would be to use XDR, but I am still leary of being able */
/* to find XDR libs on all platforms I want running netperf. raj */
{
int *charword;
int *initword;
int *lastword;
initword = (int *) dlpi_co_stream_request->dlpi_device;
lastword = initword + ((dlpi_co_stream_request->dev_name_len + 3) / 4);
for (charword = initword;
charword < lastword;
charword++) {
*charword = htonl(*charword);
}
}
#endif /* __alpha */
data_descriptor = dl_open(dlpi_co_stream_request->dlpi_device,
dlpi_co_stream_request->ppa);
if (data_descriptor < 0) {
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
/* Let's get an address assigned to this descriptor so we can tell the */
/* initiator how to reach the data descriptor. There may be a desire to */
/* nail this descriptor to a specific address in a multi-homed, */
/* multi-connection situation, but for now, we'll ignore the issue */
/* and concentrate on single connection testing. */
/* bind the sap and retrieve the dlsap assigned by the system */
dlpi_co_stream_response->station_addr_len = 14; /* arbitrary */
if (dl_bind(data_descriptor,
dlpi_co_stream_request->sap,
DL_CODLS,
(char *)dlpi_co_stream_response->station_addr,
&dlpi_co_stream_response->station_addr_len) != 0) {
fprintf(where,"recv_dlpi_co_stream: bind failure\n");
fflush(where);
exit(1);
}
/* The initiator may have wished-us to modify the socket buffer */
/* sizes. We should give it a shot. If he didn't ask us to change the */
/* sizes, we should let him know what sizes were in use at this end. */
/* If none of this code is compiled-in, then we will tell the */
/* initiator that we were unable to play with the socket buffer by */
/* setting the size in the response to -1. */
#ifdef DL_HP_SET_LOCAL_WIN_REQ
if (dlpi_co_stream_request->recv_win_size) {
}
/* Now, we will find-out what the size actually became, and report */
/* that back to the user. If the call fails, we will just report a -1 */
/* back to the initiator for the recv buffer size. */
#else /* the system won't let us play with the buffers */
dlpi_co_stream_response->recv_win_size = -1;
#endif /* DL_HP_SET_LOCAL_WIN_REQ */
/* what sort of sizes did we end-up with? */
/* this bit of code whould default to the Interface MTU */
if (dlpi_co_stream_request->receive_size == 0) {
recv_size = 1024;
}
else {
recv_size = dlpi_co_stream_request->receive_size;
}
/* tell the other fellow what our receive size became */
dlpi_co_stream_response->receive_size = recv_size;
/* just a little prep work for when we may have to behave like the */
/* sending side... */
message = (char *)malloc(recv_size * 2);
if (message == NULL) {
printf("malloc(%d) failed!\n", recv_size * 2);
exit(1);
}
message_ptr = ALIGN_BUFFER(message, dlpi_co_stream_request->recv_alignment, dlpi_co_stream_request->recv_offset);
recv_message.maxlen = recv_size;
recv_message.len = 0;
recv_message.buf = message_ptr;
if (debug > 1) {
fprintf(where,
"recv_dlpi_co_stream: receive alignment and offset set...\n");
fflush(where);
}
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. */
dlpi_co_stream_response->cpu_rate = 0.0; /* assume no cpu */
if (dlpi_co_stream_request->measure_cpu) {
dlpi_co_stream_response->measure_cpu = 1;
dlpi_co_stream_response->cpu_rate =
calibrate_local_cpu(dlpi_co_stream_request->cpu_rate);
}
send_response();
/* accept a connection on this file descriptor. at some point, */
/* dl_accept will "do the right thing" with the last two parms, but */
/* for now it ignores them, so we will pass zeros. */
if(dl_accept(data_descriptor, 0, 0) != 0) {
fprintf(where,
"recv_dlpi_co_stream: error in accept, errno %d\n",
errno);
fflush(where);
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
if (debug) {
fprintf(where,"netserver:recv_dlpi_co_stream: connection accepted\n");
fflush(where);
}
/* Now it's time to start receiving data on the connection. We will */
/* first grab the apropriate counters and then start grabbing. */
cpu_start(dlpi_co_stream_request->measure_cpu);
#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 = dlpi_co_stream_request->dirty_count;
clean_count = dlpi_co_stream_request->clean_count;
message_int_ptr = (int *)message_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 */
recv_message.len = recv_size;
while (recv_message.len == recv_size) {
if (getmsg(data_descriptor,
0,
&recv_message,
&flags) != 0) {
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
bytes_received += recv_message.len;
receive_calls++;
if (debug) {
fprintf(where,
"netserver:recv_dlpi_co_stream: getmsg accepted %d bytes\n",
recv_message.len);
fflush(where);
}
#ifdef DIRTY
message_int_ptr = (int *)message_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. */
/* should perform a disconnect to signal the sender that */
/* we have received all the data sent. */
if (close(data_descriptor) == -1) {
netperf_response.content.serv_errno = errno;
send_response();
exit(1);
}
cpu_stop(dlpi_co_stream_request->measure_cpu,&elapsed_time);
/* send the results to the sender */
if (debug) {
fprintf(where,
"recv_dlpi_co_stream: got %d bytes\n",
bytes_received);
fprintf(where,
"recv_dlpi_co_stream: got %d recvs\n",
receive_calls);
fflush(where);
}
dlpi_co_stream_results->bytes_received = bytes_received;
dlpi_co_stream_results->elapsed_time = elapsed_time;
dlpi_co_stream_results->recv_calls = receive_calls;
if (dlpi_co_stream_request->measure_cpu) {
dlpi_co_stream_results->cpu_util = calc_cpu_util(0.0);
};
if (debug > 1) {
fprintf(where,
"recv_dlpi_co_stream: test complete, sending results.\n");
fflush(where);
}
send_response();
}
/*********************************/
int send_dlpi_co_rr(char remote_host[])
{
char *tput_title = "\
Local /Remote\n\
Window Size Request Resp. Elapsed Trans.\n\