forked from greearb/lanforge-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lf_nfs_io.pl
executable file
·1307 lines (1195 loc) · 47.1 KB
/
lf_nfs_io.pl
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
#!/usr/bin/perl -w
#
# This program is used to stress test the LANforge system, and may be used as
# an example for others who wish to automate LANforge tests.
# This script sets up connections of types:
# lf, lf_udp, lf_tcp, custom_ether, custom_udp, custom_tcp, l4 (http, https, ftp and fileIO)
# across real ports and MACVLAN ports on one or more machines.
# It then continously starts and stops the connections.
package main;
$| = 1; # Un-buffer output
use strict;
use warnings;
use Carp;
use Net::Telnet ();
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
use Scalar::Util; #::looks_like_number;
use lib '/home/lanforge/scripts'; # this is pedantic necessity for the following use statements
use LANforge::Port;
use LANforge::Utils;
use LANforge::Endpoint;
use Net::Telnet ();
use Net::Ping;
use Getopt::Long;
use Time::HiRes ('sleep');
use Socket;
use Data::Dumper;
use POSIX;
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## package variables below
use constant NL => "\n";
use constant NA => "NA";
use constant AUTO => "AUTO";
use constant READ => "read";
use constant WRITE => "write";
use constant DHCP => "DHCP";
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
our $report_timer = 8000; # Set report timer for all tests created in ms, i.e. 8 seconds
our $lfmgr_host = undef;
our $lfmgr_port = 4001;
our $resource = 1;
our $quiet = 1;
our $group = undef;
our $tmp_group = "";
our $tmp_group_min = 0;
our $tmp_group_max = 0;
our $action = undef;
our $nfs_mnt = undef;
our $nfs_list = undef;
our $local_mnt = AUTO;
our $first_mvlan_ip = undef; #"10.26.1.10";
our $netmask = "255.255.255.0";
our $parent_port = undef;
our $utils = undef;
our $shelf_num = 1;
our $DEBUG = 0;
our $sleep_after_wo = 15; # Second to sleep after starting writers (before starting readers)
our $D_PAUSE = 3;
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
# File-IO configuration defaults
our $quiesce_after_files = 0;
our $min_rw_size = "512";
our $max_rw_size = "65536";
our $use_crc = "yes";
our $min_read_bps = "1000000"; # 1Mbps
our $max_read_bps = "2000000"; # 2Mbps
our $num_files = 2;
our $min_file_size = 1024 * 1024;
our $max_file_size = 1024 * 1024 * 2;
our $min_write_bps = "3000000"; # 3Mbps
our $max_write_bps = "4000000"; # 4Mbps
our $mount_options = "NONE";
our $skip_writers = 0;
our $skip_readers = 0;
our $endp_options = "";
our $default_fio_flags = 0x7;
our $computed_fio_flags = $default_fio_flags;
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
# below are sorted names and associated endpoints
# the third argument can be used as the default parent
# port for the mac-vlans for that group
our %group_names = (
#"group1" => [ 1, 20, 'eth1'],
#"group2" => [ 21, 40, 'eth1'],
#"group3" => [ 41, 60, 'eth1'],
#"group4" => [ 1, 1, 'eth1'],
#"group5" => [ 2, 2, 'eth1']
);
our $prefix = "";
our $fast_forward_ep = 0; # set this to 1 to leave exiting file endpoints alone
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
our %mnt_map = ();
our %file_endpoints = ();
our %cross_connects = ();
our %test_groups = ();
our %all_file_ep = ();
our %mac_vlans = ();
our %vlan_ips = ();
# These are set based on group chosen.
our $qty_mac_vlans = 0;
our $start = 0; # First idx, inclusive
our $stop = 0; # Last idx
our $fe_type = "nfs4";
our %fe_types = (
"generic" => "fe_generic",
"nfs" => "fe_nfs",
"nfs4" => "fe_nfs4",
"cifs" => "fe_cifs",
"iscsi" => "fe_iscsi",
"cifs_v6" => "fe_cifs/ip6",
"nfs_v6" => "fe_nfs/ip6",
"nfs4_v6" => "fe_nfs4/ip6",
"smb2" => "fe_smb2",
"smb2_v6" => "fe_smb2/ip6",
"smb21" => "fe_smb21",
"smb21_v6" => "fe_smb21/ip6",
"smb3" => "fe_smb30",
"smb3_v6" => "fe_smb30/ip6"
);
our %fio_flags = (
"CHECK_MOUNT" => 0x1,
"AUTO_MOUNT" => 0x2,
"AUTO_UNMOUNT" => 0x4,
"O_DIRECT" => 0x8,
"UNLINK_BW" => 0x10,
"O_LARGEFILE" => 0x20,
"UNMOUNT_FORCE" => 0x40,
"UNMOUNT_LAZY" => 0x80,
"USE_FSTATFS" => 0x100,
"O_APPEND" => 0x200,
"syncwrite" => 0x800,
"syncclose" => 0x1000,
"direct" => 0x8,
"largefile" => 0x20,
"append" => 0x200,
"crc" => 0x400,
"unlink" => 0x10,
"verify" => 0x1,
"automount" => 0x2,
"unmount" => 0x4,
"lazyun" => 0x80,
"forceun" => 0x40,
"fstatfs" => 0x100,
);
sub ipSummary {
my $first;
if((!defined $::first_mvlan_ip ) || ("$::first_mvlan_ip" eq "")) {
$first = "0.0.0.0";
}
else {
$first = $::first_mvlan_ip;
}
my $linestart = " # ";
my $summary = NL;
for my $name (sort keys %::group_names) {
$summary .= $linestart.$name.": ";
my $a = addrtoint( $first ) + $::group_names{ $name }->[0] -1;
my $b = addrtoint( $first ) + $::group_names{ $name }->[1] -1;
$summary .= inttoaddr( $a )." - ".inttoaddr( $b ).NL;
}
return $summary;
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## Usage ==
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
my $first = ($::first_mvlan_ip) ? $::first_mvlan_ip : "0.0.0.0";
my $usage = "$0 [--mgr {host-name | IP}]
[--mgr_port {ip port ($lfmgr_port)}]
[--resource {resource ($resource)}]
[--action {list_groups|new_group|run_group|stop_group|del_group}]
# list_groups: list test groups
# new_group: creates connections and places them in a new test group
# run_group: assemble and start writer then reader group
# stop_group: quiece writer then reader group
# del_group: delete reader then writer file endpoints
[--nfs_mnt|nfs_mount {[IP|host-name]:/path}]
# 192.168.1.1:/foo
# filehost:/home/fileio
[--nfs_list {local file}]\t# list of nfs mountpoints
# Will be modulo distributed among groups mac vlans
# Obviates --nfs_mnt; examples:
# --nfs_list ./my-list-of-mounts
# --nfs_list /tmp/mnt-list
# File format:
# 10.20.30.40:/a/b/c
# filehost:/z/y
[--parent_port {parent eth port}]\t# parent of mac vlans
[--first_mvlan_ip {ip ($first)}]\t# mvlan ips: ".ipSummary()."
# dhcp: use this value to request dhcp
# 1.2.3.4,a.b.c.d,w.x.y.z: use this set of IP addresses.
# set length must match the --min/--max interval
[--netmask {mask ($netmask)}]\t#mac-vlan netmask
[--group {name}] # test group base name, creates:
# <group>_wo for writers and
# <group>_ro for readers
[--prefix {name}] # endpoint prefix other than group name
[--min_rw_size ($min_rw_size)]\t# in bytes
[--max_rw_size ($max_rw_size)]\t# in bytes
[--use_crc {yes|no}]
[--min_read_bps ($min_read_bps)]\t# in bps, 2000000 = 1Mbps
[--max_read_bps ($max_read_bps)]\t# in bps, 2000000 = 2Mbps
[--num_files ($num_files)]\t# files per writer
[--quiesce_after_files ($quiesce_after_files)]\t# files to read/write before stopping test.
# O == infinite (default)
[--skip_readers ($skip_readers)]\t# Should we not create reader connections: 0 | 1
[--skip_writers ($skip_readers)]\t# Should we not create writer connections: 0 | 1
[--min_file_size ($min_file_size)]\t# in bytes
[--max_file_size ($max_file_size)]\t# in bytes
[--min_write_bps ($min_write_bps)]\t# in bps, 3000000 = 3Mbps
[--max_write_bps ($max_write_bps)]\t# in bps, 4000000 = 4Mbps
[--mount_options ($mount_options)]\t# as per nfs(1)
[--tmp_group {name}]\t# for specifying ad-hoc group, you will see group <name>
[--min 1-n]\t# first macvlan in tmp group
[--max 1-n]\t# last macvlan in tmp group
[--endp_type {generic,nfs,nfs4,cifs,iscsi,cifs_v6,nfs_v6,nfs4_v6,smb2,smb2_v6,smb21,smb21_v6,smb3,smb3_v6}]
# generic fe_generic Uses unspecified file protocol
# nfs fe_nfs NFSv3 mount
# nfs4 fe_nfs4 NFSv4 mount
# cifs fe_cifs CIFS (Samba) mount
# iscsi fe_iscsi ISCSI mount
# cifs_v6 fe_cifs/ip6 IPv6 CIFS mount
# nfs_v6 fe_nfs/ip6 NFSv3 IPv6 mount
# nfs4_v6 fe_nfs4/ip6 NFSv4 IPv6 mount
# smb2 fe_smb2 SMB v2.0 mount
# smb2_v6 fe_smb2/ip6 SMB v2.0 IPv6 mount
# smb21 fe_smb21 SMB v2.1 mount
# smb21_v6 fe_smb21/ip6 SMB v2.1 IPv6 mount
# smb3 fe_smb30 SMB v3.0 mount
# smb3_v6 fe_smb30/ip6 SMB v3.0 IPv6 mount
[--mount_options ...]\t# CIFS or NFS mount(8) options, like 'rsize=1048576,wsize=1048576,async'
[--endp_options {syncafter|syncbefore|direct|largefile|append|crc|unlink|verify|automount|unmount|lazyun|forceun|fstatfs}]
# syncwrite sync after each write
# syncclose sync before close
# direct O_DIRECT, disable read/write buffering
# largefile O_LARGEFILE, enable writing files >4GB on 32-bit systems
# append start writing at the end of the file, not at the start
# crc 32bit CRC calculation on every buffer read/write
# unlink remove file before writing it
# verify verify mountpoint is associated with correct port
# automount attempt to mount filesystem if it is not mounted
# unmount attempt unmount when stopping test
# lazyun use the '-l' mount(8) switch that unmounts file locally
# forceun use the '-f' mount(8) switch that forces filesystem unmount
# fstatfs verify mount options, will stop test if fstatfs returns error
# If you endp_options, set all the options you need:
# verify,automount,unmount,direct,largefile,unmount are most used
List Test Groups:
$0 --mgr 10.0.0.1 --resource 1 --action list_groups
Create a new NFS test group:
$0 --mgr 10.0.0.1 --resource 1 --action new_group --group group1 \\
--parent_port eth2 --prefix smallreads \\
--nfs_mnt 192.168.48.5:/fire \\
--ips 192.168.48.10,192.168.48.13,192.168.48.14,192.168.48.15,192.168.48.16,192.168.48.17 \\
--netmask 255.255.255.0 \\
--min_rw_size 1048576 --max_rw_size 1048576 \\
--endp_options verify,automount,unmount,direct,largefile \\
--mount_options 'rsize=1048576,wsize=1048576,async'
Create a new SMB3 test group:
$0 --mgr localhost --action new_group --group tg_smb3 \\
--parent_port eth3 --prefix s3 \\
--endp_type smb3 --remote_mnt //10.0.0.1/fio \\
--first_mvlan_ip 10.0.0.10 --min 0 --max 11 \\
--netmask 255.255.255.0 \\
--min_rw_size 1048576 --max_rw_size 1048576 \\
--min_file_size 1073741824 --max_file_size 1073741824 \\
--endp_options='verify,automount,unmount,direct,largefile' \\
--mount_options='username=lanforge,password=lanforge,soft,rsize=1048576,wsize=1048576,noblocksend'
$0 --mgr 10.0.0.1 --resource 1 --action run_group --group group1 \\
--parent_port eth2 --netmask 255.255.0.0 \\
--nfs_mnt 10.40.10.1:/fire \\
--num_files 20 --min_file_size 4096 --max_file_size 524288 \\
--min_write_bps 1000000 --max_write 900000000
$0 --mgr 10.0.0.1 --resource 1 \\
--action stop_group --group group1
$0 --mgr 10.0.0.1 --resource 1 \\
--action del_group --group group1
$0 --mgr 10.0.0.1 --resource 1 \\
--action run_group --group group2 --parent_port eth9 \\
--first_mvlan_ip 172.168.90.1 --netmask 255.255.0.0 \\
--nfs_list ./nfsexports.txt \\
--num_files 20 --min_file_size 4096 --max_file_size 524288 \\
--min_write_bps 1000000 --max_write 900000000
$0 --mgr 10.0.0.1 --resource 1 \\
--action run_group --group group1 \\
--nfs_mnt 192.168.99.99:/fire \\
--mount_options sync,hard,timeo=120,retrans=4
$0 --mgr 10.0.0.1 --resource 1 --action run_group \\
--tmp_group lag1 --min 1 --max 2 --parent_port eth1 \\
--first_mvlan_ip 10.30.0.10 \\
--nfs_mnt 10.30.0.1:/tmp
$0 --mgr 10.0.0.1 --resource 1 \\
--action stop_group --tmp_group lag1 --min 1 --max 2 --parent_port eth1
";
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## ip_to_a/a_to_ip
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub addrtoint {
return( unpack( "N", pack( "C4", split( /[.]/,$_[0]) ) ) );
};
sub inttoaddr {
return( join( ".", unpack( "C4", pack( "N", $_[0] ) ) ) );
};
sub show_test_groups {
my $cmd = "show_group all";
$::utils->doCmd($cmd);
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## Open connection to the LANforge server, configure our utils.
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub init {
my $conn = new Net::Telnet(Timeout => 20,
Prompt => '/default\@btbits\>\>/');
$conn->open(Host => $::lfmgr_host,
Port => $::lfmgr_port,
Timeout => 10);
$conn->waitfor("/btbits\>\>/");
$conn->max_buffer_length(1024 * 1024 * 10); # 10M buffer
$::utils = new LANforge::Utils();
$::utils->connect($lfmgr_host, $lfmgr_port);
# query for test group names
# print Dumper(\%::group_names);
if ($::action ne "list_groups") {
if ( 1 > (keys %::group_names)) {
# print Dumper(\keys(%::group_names));
die("No test group names appear to be specified.");
}
if ($::group && $::group ne "") {
# print Dumper(\$::group_names);
my $ra_bounds = $::group_names{ $::group };
if (!(defined $ra_bounds) || @$ra_bounds < 2) {
die("please specify test group name");
}
$::start = @$ra_bounds[0];
$::stop = @$ra_bounds[1];
$::qty_mac_vlans = ($::stop - $::start) + 1;
#print "group [$group] vlans: $::stop - $::start = $::qty_mac_vlans\n" if($::DEBUG);
}
}
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## set a port or mvlan up or down
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub fmt_port_up_down {
my ($resource, $port_id, $state) = @_;
my $cur_flags = 0;
if ($state eq "down") {
$cur_flags |= 0x1; # port down
}
# Specify the interest flags so LANforge knows which flag bits to pay attention to.
my $ist_flags = 0;
$ist_flags |= 0x2; # check current flags
$ist_flags |= 0x800000; # port down
my $cmd = $::utils->fmt_cmd("set_port", 1, $resource, $port_id, NA,
NA, NA, NA, "$cur_flags",
NA, NA, NA, NA, "$ist_flags");
return $cmd;
} # ~port up/down
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## Create mac_vlans if they do not exist.
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub preparePorts {
do_err_exit("First mac vlan IP is not set. Please set --first_mvlan_ip.")
unless ((defined $::first_mvlan_ip) && ("$::first_mvlan_ip" ne ""));
do_err_exit( "preparePorts: Unnamed parent port. Please set \$parent_port")
unless((defined $::parent_port) && ("$::parent_port" ne ""));
my $sleep_after = 0;
my %all_ports = ();
# build list of MAC VLANS
print "shelf_num $::shelf_num, resource $::resource\n" if ($::DEBUG);
my @ports = $::utils->getPortListing( 1, $::resource +0);
#if ($::DEBUG) {
# print Dumper(["ports:", \@ports]);
# die("look!");
#}
print "Debug: discovered ports:" if($::DEBUG);
for my $rh_port (@ports) {
print " $rh_port->{'dev'}" if($::DEBUG);
$all_ports{ $rh_port->{'dev'} } = $rh_port;
next unless ( $rh_port->{'dev'} eq $::parent_port );
}
print "\n" if($::DEBUG);
do_err_exit("preparePorts: Failed to populate ports list, please debug.")
unless (keys %all_ports > 0);
if (keys(%::group_names) < 1) {
do_err_exit("group_names is unpopulated");
}
my $i;
my %new_items = ();
my $ra_bounds = $::group_names{ $group };
my $ip_string = $::first_mvlan_ip;
my @ip_list = ();
my $start_int = 0;
my $next_ip;
if ($ip_string =~ /dhcp/i ) {
$ip_string = DHCP;
}
elsif ($ip_string =~ /[,]/ ) {
@ip_list = split(',', $ip_string);
die("Please provide at least as many IP addresses as mvlans, bye.")
if (@ip_list < $main::qty_mac_vlans);
}
else {
$start_int = addrtoint($ip_string);
}
if (($::qty_mac_vlans + $::start) < 1) {
do_err_exit("preparePorts: expects a positive, non-zero number of mvlans to create. Cannot continue.");
}
for ($i = 0 + $::start; $i < $::qty_mac_vlans + $::start; $i++) {
my $devname = $::parent_port."#".$i;
if ($ip_string eq DHCP) {
$next_ip = $ip_string;
}
if (@ip_list > 0) {
# print Dumper(["iplist:", \@ip_list]);
$next_ip = $ip_list[$i];
}
else {
print "start_str[$ip_string] start_int[$start_int] i[$i]\n" if ($::DEBUG);
$next_ip = inttoaddr( $start_int + $i -1);
}
print "next_ip[$next_ip]\n" if ($::DEBUG);
$::vlan_ips{ $devname } = $next_ip;
$::mac_vlans{ $devname } = 0;
if ( defined $all_ports{ $devname }) {
$::mac_vlans{ $devname } = 1;
}
else { # create mac_vlan
my $mac_addr = mac();
my $cmd = $::utils->fmt_cmd( "add_mvlan", $::shelf_num,
$::resource, $::parent_port, $mac_addr, $i);
print " + ".$cmd.NL if ($::DEBUG);
$::utils->doCmd($cmd);
sleep(0.1);
}
$new_items{ $devname } = 1;
$sleep_after++;
} #~for
if ( keys %new_items > 0 ) {
print "Creating ".(keys %new_items)." new ports:...";
my $report_timer = 2500;
# set the port IP
for my $new_item (keys(%new_items)) {
my $ip = NA;
my $cmd_flags = 0x0;
my $current = 0x0;
my $interesting = 0x0 | 0x4 | 0x8;
if ($ip_string ne DHCP) {
$ip = $::vlan_ips{ $new_item };
}
else {
$current = 0x80000000;
$interesting = 0x2 | 0x4000;
}
my $cmd = $::utils->fmt_cmd("set_port",
$::shelf_num, $::resource, $new_item, $ip,
$::netmask, NA, $cmd_flags, $current, NA,
NA, NA, NA, $interesting, $report_timer,
NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA);
if ($::DEBUG) {
print NL." $new_item $ip: $cmd ";
}
else {
print ".";
}
$::utils->doCmd($cmd);
sleep(0.1);
$sleep_after++;
my @ports = $::utils->getPortListing($::shelf_num, $::resource);
for my $rh_port (@ports) {
$::all_ports{ $rh_port->{'dev'} } = $rh_port; #reset ports
}
}
print NL."Created ".(keys %new_items)." new mac vlans".NL;
}
if ($sleep_after > 10) {
$sleep_after = $sleep_after / 2;
}
if ($sleep_after) {
print "\nSleeping: $sleep_after seconds to allow ports to be created and configured.\n";
for $i (1..$sleep_after) { sleep(1); print "."; }
print NL;
}
# check that the port is up by trying to run a ping from it
if ( defined $::nfs_mnt && "$::nfs_mnt" ne "") {
my ($nfs_name) = split(/:/, $::nfs_mnt );
if (($::lfmgr_host ne "localhost") ||($::lfmgr_host ne "127.0.0.1")) {
print "We suggest using this script local to the manager. We cannot tell remote mgr to ping nfs system.";
}
else {
print "Emitting one ping from each mvlan reduces failed mounts:";
foreach my $name (reverse sort keys %new_items) {
my $rh_p = $::all_ports{ $name };
my $ip = $rh_p->{'ip_addr'};
#my $ping = "ping -n -c1 -w1 -W1 -I $ip $nfs_name";
print "ping $ip".NL if ($::DEBUG);
my $ping = Net::Ping->new('tcp', 1);
$ping->bind($ip);
$ping->port_number(scalar(getservbyname("nfs", "tcp")));
my $counter = 5;
while( $counter > 0 ) {
if ($ping->ping($nfs_name)) {
print ".";
$counter = 0;
}
else {
print "$nfs_name did not ack nfs packet from $ip".NL;
$counter --;
sleep(0.2);
}
}
$ping->close();
undef($ping);
#$ping->close();
}
}
}
print NL;
} # ~preparePorts
sub notBlank {
my ($name, $value) = @_;
if((!defined $name) || ("$name" eq "")) {
print "Name itself is blank, value[$value]".NL;
}
if((!defined $value) || ("$value" eq "")) {
print "Value of $name is blank".NL;
}
#die if($::DEBUG);
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## prepareFileEndp - creates requested file endpoints if they do not exist,
## creates implied FIO endpoints if they dont exist and adds endpoints
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub prepareFileEndpoints {
do_err_exit("prepareFileEndpoints: Unnamed parent port. Please set \$parent_port")
unless((defined $::parent_port) && ("$::parent_port" ne ""));
do_err_exit("prepareFileEndpoints: Blank all_ports array. Please run preparePorts() first.")
unless( keys %::all_ports > 1 );
do_err_exit("prepareFileEndpoints: Blank mac_vlans array. Please run preparePorts() first.")
unless( keys %::mac_vlans > 0 );
if((defined $::nfs_list) && ("$::nfs_list" ne "")) {
if((keys %::mnt_map) < 1) {
do_err_exit("prepareFileEndpoints: empty --nfs_list. Provide mountpoints in [$::nfs_list]");
}
}
elsif((! defined $::nfs_mnt) || ("$::nfs_mnt" eq "")) {
do_err_exit("prepareFileEndpoints: undefined --nfs_mnt. Please specify --nfs_mnt first");
}
my %all_file_endpoints = ();
my %all_cross_connects = ();
my %endpoints_mvlans = ();
my @new_file_endpoints = ();
my @new_cross_connects = ();
my $ep_name = undef;
my @prefixes = ();
for my $grp (sort(keys %::group_names)) {
my $name_prefix = $grp;
my $name_prefix_ = "${grp}_";
if ($::prefix ne "") {
$name_prefix = $::prefix;
$name_prefix_ = $::prefix."_";
}
push(@prefixes, $name_prefix_);
my $ra_bounds = $::group_names{ $grp };
print "skip_writers[$::skip_writers] skip_readers[$::skip_readers]" if ($::DEBUG);
sleep(3) if($::DEBUG);
for my $i (@$ra_bounds[0]..@$ra_bounds[1]) {
if (! $::skip_writers) {
$ep_name = $name_prefix_."wo_".sprintf( "%03d", $i);
$all_file_endpoints{ $ep_name } = 0;
$endpoints_mvlans{ $ep_name } = $::parent_port."#".$i;
$all_cross_connects{ $ep_name } = 0;
}
if (! $::skip_readers) {
$ep_name = $name_prefix_."ro_".sprintf( "%03d", $i);
$all_file_endpoints{ $ep_name } = 0;
$endpoints_mvlans{ $ep_name } = $::parent_port."#".$i;
$all_cross_connects{ $ep_name } = 0;
}
}
}
print NL."Reading endpoints...";
my $endpoint_str = $::utils->doCmd("nc_show_endpoints all all");
my @endpoint_lines = split(/\n/, $endpoint_str);
if ($::fast_forward_ep) {
for my $line (@endpoint_lines) {
$line =~ m/Endpoint \[(.*?)\]/; # proves this ep exists
next if(! $1);
$all_file_endpoints{ $1 } = 1;
}
}
my $interesting_prefixes_regex = join('|', @prefixes);
for my $ep_name (sort(keys %all_file_endpoints)) {
print " $ep_name [".$all_file_endpoints{$ep_name}."] " if ($::DEBUG);
if ($all_file_endpoints{$ep_name} == 0 ){
#print "check regex: $ep_name ~ $interesting_prefixes_regex\n";
if( $ep_name =~ /^$interesting_prefixes_regex/ ){
push( @new_file_endpoints, $ep_name );
}
# print Dumper(["new_file_endpoints:", \@new_file_endpoints]);
}
}
if (@new_file_endpoints < 1) {
die("Unable to detect new file endpoint names, please debug.");
}
# assert we have sufficient remote_mnt entries
for my $ep_name (@new_file_endpoints) {
my $mvlan = $endpoints_mvlans{ $ep_name };
my $remote_mnt = $::mnt_map{ $mvlan };
notBlank( $mvlan, $remote_mnt );
}
if (@new_file_endpoints > 0) {
print "Creating ".@new_file_endpoints." new file endpoints...";
my $endpoint_type = "lf";
my $ip_port = "-1";
my $bursty = "no";
my $rand_pkt_sz = "no";
my $remote_mnt = undef;
for my $ep_name (@new_file_endpoints) {
my $mvlan = $endpoints_mvlans{ $ep_name };
$remote_mnt = $::mnt_map{ $mvlan };
my $read_write = ($ep_name =~ /_ro_/)? READ : WRITE;
my $rw_prefix = $ep_name;
$rw_prefix =~ s/_ro_/_wo_/;
my $prefix = ($read_write eq WRITE) ? AUTO : $rw_prefix;
my $directory = ($read_write eq WRITE) ? AUTO : '/mnt/lf/'.$rw_prefix;
my $min_write_rt = ($read_write eq READ ) ? "0" : $::min_write_bps;
my $max_write_rt = ($read_write eq READ ) ? "0" : $::max_write_bps;
my $min_read_rt = ($read_write eq WRITE ) ? "0" : $::min_read_bps;
my $max_read_rt = ($read_write eq WRITE ) ? "0" : $::max_read_bps;
my $pattern = "increasing"; #($read_write eq "read" ) ? NA : "increasing";
my $mount_retry_nap = 3500;
my $mount_dir = "NA";
# we do not want anything 'blank' in this
my @names=qw(ep_name
::shelf_num
::resource
mvlan
min_read_rt
max_read_rt
min_write_rt
max_write_rt
pattern
directory
prefix
remote_mnt
mount_options
mount_dir
mount_retry_nap);
my @values=($ep_name,
$::shelf_num,
$::resource,
$mvlan,
$min_read_rt,
$max_read_rt,
$min_write_rt,
$max_write_rt,
$pattern,
$directory,
$prefix,
$remote_mnt,
$mount_options,
$mount_dir,
$mount_retry_nap);
for (my $i=0; $i<@names; $i++) {
notBlank($names[$i], $values[$i]);
}
my $cmd = $::utils->fmt_cmd(
"add_file_endp", $ep_name, $::shelf_num, $::resource, $mvlan,
$::fe_types{$::fe_type}, $min_read_rt, $max_read_rt, $min_write_rt, $max_write_rt,
$pattern, $directory, $prefix, $remote_mnt, $mount_options,
$computed_fio_flags, $mount_dir, NA, $mount_retry_nap);
print " + " . $cmd.NL if ($::DEBUG);
$::utils->doCmd($cmd);
sleep(0.05); # if ($::DEBUG);
print ".";
$cmd = $::utils->fmt_cmd( "set_fe_info", $ep_name,
$min_rw_size, $max_rw_size, $num_files, $min_file_size, $max_file_size,
$directory, $prefix, $read_write, $quiesce_after_files);
print " + " . $cmd.NL if ($::DEBUG);
$::utils->doCmd($cmd);
sleep(0.1); # if ($::DEBUG);
print "\bo";
$::utils->doCmd($::utils->fmt_cmd( "set_endp_quiesce", $ep_name, 5));
sleep(0.1);
print "\bO";
$::utils->doCmd($::utils->fmt_cmd( "set_endp_report_timer", $ep_name, 1000));
sleep(0.1);
print "\b*";
$::utils->doCmd($::utils->fmt_cmd( "set_endp_flag", $ep_name, "ClearPortOnStart", 0));
sleep(0.1);
print "\b|";
my $cx_name = "CX_".$ep_name;
my $tg_name = $::group.(($read_write eq READ) ? "_ro" : "_wo");
my $tm_name = "default_tm"; #= $::group.(($read_write eq READ) ? "_ro" : "_wo");
my $tx_endp = $ep_name;
my $rx_endp = NA;
my $add_cx = $::utils->fmt_cmd( "add_cx", $cx_name, $tm_name, $tx_endp, $rx_endp );
my $set_cx = $::utils->fmt_cmd( "set_cx_report_timer", $tm_name, $cx_name, "1000", "cxonly");
my $add_tgcx = $::utils->fmt_cmd( "add_tgcx", $tg_name, $cx_name );
print $add_tgcx.NL if ($::DEBUG);
print $add_cx.NL if ($::DEBUG);
print $set_cx.NL if ($::DEBUG);
$::utils->doCmd($add_cx);
sleep(0.1);
print "\bi";
$::utils->doCmd($set_cx);
sleep(0.1);
print "\b:";
$::utils->doCmd($add_tgcx);
sleep(0.1);
print "\b.";
} #~for
print "\nAdded ".@new_file_endpoints." endpoints to group $::group\n";
sleep(3);
} #~if need to create file endpoints
} #~prepareFileEndpoints
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## prepareExportList - assemble the list of nfs exports from either
## the nfs_list resource or the nfs_mnt option
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub prepareExportList {
if ((defined $::nfs_list) && ("$::nfs_list" ne "")) {
open(my $fh, "<", $::nfs_list) or do_err_exit("Unable to open [$::nfs_list]. Cannot continue.");
my @lines = ();
while(<$fh>) {
chomp;
next if (/^\s*[#;]/);
next if (/^\s*$/);
s/^\s+//;
s/\s+$//;
if (/[0-9a-zA-Z.-]+:\/.*$/) {
push( @lines, $_ );
}
}
close($fh);
if (@lines < 1) {
do_err_exit("Unable to find lines that look like nfs mount points in [$::nfs_list]. Cannot continue.");
}
my $i = 0;
for my $mvlan (sort keys %::mac_vlans) {
$::mnt_map{ $mvlan } = $lines[ $i ];
print " mapping $mvlan => ".$lines[ $i ].NL if($::DEBUG);
$i = ++$i % @lines;
}
}
elsif ((defined $::nfs_mnt) && ("$::nfs_mnt" ne "")) {
for my $mvlan (sort keys %::mac_vlans) {
$::mnt_map{ $mvlan } = $::nfs_mnt;
}
}
else {
do_err_exit("Niether --nfs_list or --nfs_mnt are specified. Cannot continue.");
}
if ((keys %::mnt_map) < 1) {
do_err_exit("prepareExportList: unable to build map of mount entries. Cannot continue.");
}
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## prepareGroups - creates requested test group if it does not exist,
## file-endpoints will be created expecting these refs
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub prepareTestGroups {
my @new_items = ();
my $test_group_str = $::utils->doCmd("show_group all");
my @test_group_lines = split(/\n/, $test_group_str );
my %test_groups = ();
for my $group_name (sort(keys %::group_names)) {
$test_groups{ $group_name } = 0;
}
for my $line ( @test_group_lines) {
if ($line =~ /TestGroup name: ([^\[]+)\s*\[.*$/) {
$test_groups{ $1 } = 1;
}
}
for my $group_name (keys %test_groups) {
if ($test_groups{$group_name} == 0 ) {
push(@new_items, $group_name);
}
}
if (@new_items > 0 ) {
sleep(5);
for my $group_name (@new_items) {
$::utils->doCmd($::utils->fmt_cmd("add_group", $group_name."_wo", NA, NA)) if (!$::skip_writers);
$::utils->doCmd($::utils->fmt_cmd("add_group", $group_name."_ro", NA, NA)) if (!$::skip_readers);
#print " + tg $group_name ";
}
}
} # ~prepareTestGroups
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## generates random mac address
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub mac {
my $rv = "00:";
for (my $i=0; $i<5; $i++) {
$rv.=sprintf("%02X",int(rand(255))).(($i<4)?':':'');
}
return $rv;
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## list ports
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub showGroups {
my @ports = $::utils->getPortListing($::shelf_num, $::resource);
print "in show groups, found $#ports ports\n" if ($::DEBUG);
for my $group_name ( sort(keys(%::group_names))) {
print "show groups, $group_name _ro\n" if ($::DEBUG);
my $cmd = $::utils->fmt_cmd("show_group", $group_name."_ro");
print $::utils->doCmd($cmd);
print "show groups, $group_name _wo\n" if ($::DEBUG);
$cmd = $::utils->fmt_cmd("show_group", $group_name."_wo");
print $::utils->doCmd($cmd);
}
print "\n";
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## start the writers then start the readers
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub runGroup {
my $cmd;
if (!$::skip_writers) {
$cmd = "start_group ".$::group."_wo";
$::utils->doCmd($cmd);
print "Starting ".$::group."_wo...";
for my $i ( 1..$sleep_after_wo ) { sleep(1); print "."; }
print "...started".NL;
}
if (!$::skip_readers) {
$cmd = "start_group ".$::group."_ro";
$::utils->doCmd($cmd);
print "Starting ".$::group."_ro ...";
for my $i ( 1..3 ) { sleep(1); print "."; }
print "...started".NL;
}
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## stop writers then stop readers
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub stopGroup {
my $cmd;
if (!($::skip_writers || $skip_readers)) {
print NL."Quiesceing all connections...";
$cmd = "quiesce_group all";
$::utils->doCmd($cmd);
}
if (!$::skip_writers) {
print NL."Quiesceing writers...";
$cmd = "quiesce_group ".$::group."_wo";
$::utils->doCmd($cmd);
}
if (!$::skip_readers) {
print NL."Quiesceing readers...";
$cmd = "quiesce_group ".$::group."_ro";
$::utils->doCmd($cmd);
}
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## poll the set of connections to see if they are 'stopped'
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub pollCxForStop {
my $cmd;
my $lines;
my $num_lines = 0;
my $num_counted = 0;
my $num_stopped = 0;
my $upper_limit = 60;
my $attempts = 0;
while( $num_counted == 0 || ($num_counted != $num_stopped)) {
return 0 if ($attempts > $upper_limit);
sleep(2);
$attempts++;
$cmd = $::utils->fmt_cmd("show_cx", "all", "all");
$lines = $::utils->doCmd($cmd);
$num_counted = 0;
$num_stopped = 0;
for my $line (split(NL, $lines)) {
next unless ($line =~ /CX_.*?_[wr]o_\d+/);
$num_counted ++;
my @h = split(/ +/, $line);
$num_stopped += ($h[10] eq "STOPPED") ? 1 : 0;
print "${h[2]} target:${h[8]} reported:${h[10]} counted:$num_counted stopped:$num_stopped attempts: $attempts".NL if ($::DEBUG);
}
print " counted:$num_counted stopped:$num_stopped attempts: $attempts".NL if ($::DEBUG);
}
return 1;
}
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## stop the group,
## delete the file endpoints from the group,
## then delete the group
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
sub deleteGroup {
if ((!defined $::group) || ("$::group" eq "")) {
do_err_exit("Cannot delete group if --group unspecified.");
}
my $group_name = undef;
if( @_ < 1 ) {
if ( $::skip_readers || $::skip_writers) {
if (!$::skip_readers) {
print "send Delete Group $group_name to $::group _ro \n" if ($::DEBUG);
deleteGroup( $::group."_ro") ;
}
if (!$::skip_writers) {
print "send Delete Group $group_name to $::group _wo \n" if ($::DEBUG);
deleteGroup( $::group."_wo");
}
return;
}
$group_name = $::group;
}
else {
($group_name) = @_;
}
print "Delete Group $group_name\n" if ($::DEBUG);
my %cx_names = ();