-
Notifications
You must be signed in to change notification settings - Fork 16
/
EZ_IRF TCL script for HP 5900
958 lines (940 loc) · 41.6 KB
/
EZ_IRF TCL script for HP 5900
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
###############################################################################
# EZ-IRF Script for HP 5900 Series switches
# Author: Olaf Borowski, Hewlett-Packard Co.
# Version: 1.6
# Revision history: 1.0 = Initial coding
# 1.1 = added ASIC determination code
# 1.2 = added input checking
# 1.3 = added 'save_configuration' before activating IRF
# 1.4 = added command line version to interactive mode
# 1.5 = changed interface naming to standard "ten1/0/1"
# 1.6 = some code cleanup
#
#
# This script is provided with no support or guarantees.
# You may use it, modify and distribute with no restrictions
# as long as original author is mentioned.
#
# Script is designed to make it easier to configure IRF on 5900 series switches
# Copy EZ_IRF.tcl to internal flash of device
#
# Usage: (in TCLSH)
# <HP-5900-1-tcl>source EZ_IRF.tcl
#
# Script can be used in "interactive mode" or "command-line mode"
#
###############################################################################
#
### Definition of fixed varialbes
### start
set current_irf_member_id ""
set question_m "Please enter new Member ID.....................:"
set question_p "Please enter new Priority......................: "
set question_d "Please enter new Domain ID.....................: "
set question_i "Please enter new Virtual IRF Interface.........: "
set question_e "Please enter Ethernet Ports \(Members\)..........: "
set err_msg(member_id) "Invalid Member ID..............................: "
set err_msg(priority) "Invalid Priority...............................: "
set err_msg(domain_id) "Invalid Domain ID..............................: "
set err_msg(irf_port) "Invalid IRF-Port...............................: "
set err_msg(irf_member) "Invalid IRF Member Ports.......................: "
set err_msg(if_syntax) "Invalid Interface syntax.......................: "
set err_msg(if_combo) "Invalid combination of ports...................: "
set err_msg(span_asic) "Invalid ASIC combination, please re-enter....... "
set err_msg(arg_count) "Invalid number of arguments, re-enter..........: "
set err_msg(cli_invalid) "Invalid command line input, re-enter...........: "
set msg(exit) "Exiting script.................................. "
set question_y_n "Ready to proceed <y/n>?"
set range_m_min 1
set range_m_max 10
set range_p_min 1
set range_p_max 32
set range_d_min 0
set range_d_max 4294967295
set range_e_T_min 1
set range_e_T_max 48
set range_e_F_min 49
set range_e_F_max 52
set pattern_10G {^XGE[1-9][0]?[/][0-9][/][0-9]*}
set pattern_40G {^FGE[1-9][0]?[/][0-9][/][0-9]*}
set pattern_10G_dec {^ten[1-9][0]?[/][0-9][/]}
set AsicType Trident
### end
#
### Definition of global variables
### start
set TenGIG 0
set FortyGIG 0
set port_string [list]
set asic_ports [list]
set ten_gig_ints [list]
set forty_gig_ints [list]
set irf_port "1/1"
set arguments ""
set argument_count 0
# array will contain parameters for IRF configuration
# inital parameters are set
array set param {
m 1
p 1
d 0
i "1/1"
e ""
}
### end
#
### Definition of ARRAY for ASIC grouping (what port == what ASIC)
### start
set asic(1) {1 2 3 4}
set asic(2) {5 6 7 8}
set asic(3) {9 10 11 12}
set asic(4) {13 14 15 16}
set asic(5) {17 18 19 20}
set asic(6) {21 22 23 24}
set asic(7) {25 26 27 28}
set asic(8) {29 30 31 32}
set asic(9) {33 34 35 36}
set asic(10) {37 38 39 40}
set asic(11) {41 42 43 44}
set asic(12) {45 46 47 48}
### end
#
###############################################################################
#
#******************************************************************************
# Procedure definitions start
#******************************************************************************
#
###############################################################################
### procedure to clear screen
###########################################################################
proc clearscreen {} {
flush stdout
puts "\x1B\x5B\x32\x4A\x1B\x5B\x30\x3B\x30\x48"
}
###############################################################################
### procedure to get current MemberID
###########################################################################
proc get_current_member_id {} {
set CMO [exec dis irf]
set MEMBERIDIDX [string first "*+" $CMO]
set temp [string range $CMO 62 63]
set ::current_irf_member_id [string trim $temp]
}
###############################################################################
### procedure to get 10Gig interfaces of switch
###########################################################################
proc get_tengig_int {} {
set int_list [exec display interface brief | include XGE]
foreach int $int_list {
set match_flag [regexp -- $::pattern_10G $int match]
if {$match_flag != 0} {
set interface_name [string replace $match 0 2 ten]
lappend ::ten_gig_ints $interface_name
}
}
}
###############################################################################
#### procedure to get 40Gig interfaces of switch
###########################################################################
proc get_fortygig_int {} {
set int_list [exec display interface brief | include FGE]
foreach int $int_list {
set match_flag [regexp -- $::pattern_40G $int match]
if {$match_flag != 0} {
set interface_name [string replace $match 0 2 for]
lappend ::forty_gig_ints $interface_name
}
}
}
###############################################################################
### procedure to reboot unit
###########################################################################
proc exec_reboot {} {
set cli0 [ ::comware::create-cli ]
::comware::write-cli $cli0 "reboot force"
::comware::write-cli $cli0 "y"
::comware::write-cli $cli0 "end"
::comware::destroy-cli $cli0
}
###############################################################################
### procedure renumber IRF-Member-ID
###########################################################################
proc renumber {current new} {
set cli0 [ ::comware::create-cli ]
::comware::write-cli $cli0 "system-view"
::comware::write-cli $cli0 "irf mem $current ren $new"
::comware::write-cli $cli0 "y"
::comware::write-cli $cli0 "end"
::comware::destroy-cli $cli0
}
###############################################################################
### procedure to set Domain ID
###########################################################################
proc set_domain_id {domain_id} {
set cli1 [ ::comware::create-cli ]
::comware::write-cli $cli1 "system-view"
::comware::write-cli $cli1 "irf domain $domain_id"
::comware::write-cli $cli1 "end"
::comware::destroy-cli $cli1
}
###############################################################################
### procedure to set IRF priority
###########################################################################
proc set_irf_priority {member_id irf_priority} {
set cli1 [ ::comware::create-cli ]
::comware::write-cli $cli1 "system-view"
::comware::write-cli $cli1 "irf member $member_id priority $irf_priority"
::comware::write-cli $cli1 "end"
::comware::destroy-cli $cli1
}
###############################################################################
### procedure to create Virtual IRF port and add members
###########################################################################
proc set_irf_port {irf_port member_port} {
set cli1 [ ::comware::create-cli ]
::comware::write-cli $cli1 "system-view"
::comware::write-cli $cli1 "irf-port $irf_port"
::comware::write-cli $cli1 "port group interface $member_port"
::comware::write-cli $cli1 "end"
::comware::destroy-cli $cli1
}
###############################################################################
### procedure to activate IRF
###########################################################################
proc activate_irf {} {
set cli1 [ ::comware::create-cli ]
::comware::write-cli $cli1 "system-view"
::comware::write-cli $cli1 "irf-port-configuration active"
::comware::write-cli $cli1 "end"
::comware::destroy-cli $cli1
}
###############################################################################
### procedure to shutdown or undo shutdown all ports on the box
###########################################################################
proc shut_undo_shut {mem_id action} {
if {$action == "shut"} {
puts " Interfaces ten$mem_id/0/1 to ten$mem_id/0/48......................................."
puts " Interfaces for$mem_id/0/49 to for$mem_id/0/52......................................"
set cli0 [ ::comware::create-cli ]
::comware::write-cli $cli0 "system-view"
::comware::write-cli $cli0 "int range ten$mem_id/0/1 to ten$mem_id/0/48"
::comware::write-cli $cli0 "shutdown"
::comware::write-cli $cli0 "int range for$mem_id/0/49 to for$mem_id/0/52"
::comware::write-cli $cli0 "shutdown"
::comware::write-cli $cli0 "end"
::comware::destroy-cli $cli0
}
if {$action == "undo"} {
puts " Interfaces ten$mem_id/0/1 to ten$mem_id/0/48......................................."
puts " Interfaces for$mem_id/0/49 to for$mem_id/0/52......................................"
set cli0 [ ::comware::create-cli ]
::comware::write-cli $cli0 "system-view"
::comware::write-cli $cli0 "int range ten$mem_id/0/1 to ten$mem_id/0/48"
::comware::write-cli $cli0 "undo shutdown"
::comware::write-cli $cli0 "int range for$mem_id/0/49 to for$mem_id/0/52"
::comware::write-cli $cli0 "undo shutdown"
::comware::write-cli $cli0 "end"
::comware::destroy-cli $cli0
}
}
###############################################################################
### procedure to save configuration
###########################################################################
proc save_configuration {} {
set cli0 [ ::comware::create-cli ]
::comware::write-cli $cli0 "save force"
::comware::write-cli $cli0 "end"
::comware::destroy-cli $cli0
}
###############################################################################
### procedure to get Yes or No answer
###########################################################################
proc get_ui_yes_no {string_to_print} {
puts $string_to_print
set input [gets stdin]
switch -- $input {
y { return 1 }
n { return 0 }
q { error $::msg(exit) }
default {get_ui_yes_no $string_to_print}
}
}
###############################################################################
### procedure to print welcome message
###########################################################################
proc print_welcome_msg {} {
puts "
###############################################################################\
# #\
# EZ-IRF #\
# #\
# This script is intended to simplify the setup of IRF. #\
# #\
# Options: Interactive mode or Command line mode #\
# #\
# - Interactive mode: Parameters are entered one by one, with help #\
# #\
# - Command line mode: Parameter are enters in one line, no help #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of command line mode
###########################################################################
proc print_usage_cli {} {
puts "
###############################################################################\
# #\
# EZ IRF command line usage #\
# #\
# #\
# -m = Member ID...............<1-10> #\
# -p = Priority................<1-32> #\
# -d = Domain ID...............<0-4294967295> #\
# -i = virtual IRF Port .......<1/1 or 1/2 or 2/1 or 2/2> #\
# -e = Ethernet ports..........<ten1/0/1,ten1/0/2 or for1/0/49> etc. #\
# #\
# Example: -m1 -p30 -d0 -i1/1 -eten1/0/1,ten1/0/2 #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of script
###########################################################################
proc print_interactive_usage {} {
puts "
###############################################################################\
# #\
# EZ-IRF Interactive parameters entry #\
# #\
# Parameter the have to be entered: #\
# #\
# Member ID...............<1-10> #\
# Priority................<1-32> #\
# Domain ID...............<0-4294967295> #\
# Virtual IRF Port .......<1/1 or 1/2 or 2/1 or 2/2> #\
# Ethernet ports..........<tenx/y/z,forx/y/z> #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of Member ID
###########################################################################
proc print_usage_member_id {} {
puts "
###############################################################################\
# #\
# Member ID: #\
# #\
# Member ID...............Range: <1-10> #\
# #\
# The Member ID is the unit number of the IRF Stack. #\
# By default, the Member ID is \"1\" #\
# Current Member ID of the unit: $::current_irf_member_id #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of Priority
###########################################################################
proc print_usage_priority {} {
puts "
###############################################################################\
# #\
# IRF Priority: #\
# #\
# IRF Priority...............Range: <1-32> #\
# #\
# The IRF Priority determines the priority of the \"Master\" election #\
# in an IRF stack. 1 = lowest, 32 = highest
# By default, the IRF Priority is \"1\" #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of Domain ID
###########################################################################
proc print_usage_domain_id {} {
puts "
###############################################################################\
# #\
# IRF Domain ID: #\
# #\
# IRF Domain ID...............Range: <0-4294967295> #\
# #\
# The IRF Domain ID determines what IRF Domain the unit belongs to. #\
# If you have 2 pairs of IRF stacks and you want them to operate #\
# indenpendently, configure different Domain ID on each pair. #\
# Otherwise, the 4 units will become one stack consisting of 4 units. #\
# By default, the IRF Domain ID is \"0\" #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of Domain ID
###########################################################################
proc print_usage_irf_port {} {
puts "
###############################################################################\
# #\
# Virtual IRF-Port: #\
# #\
# Virtual IRF Port...............Range: <1/1, 1/2, 2,1, 2/2> #\
# #\
# The Virtual IRF port defines the connection to the neighboring #\
# switch. X/1 has to connect to X/2 on the neighboring switch. #\
# Example: 1/1 has to connect to 2/2 or #\
# 1/2 has to connect to 2/1 #\
# In the next section, you will add the physical ports that will be #\
# associated with the Virtual IRF Port #\
# By default, no Virtual IRF port is defined #\
# #\
###############################################################################\
"
puts ""
}
###############################################################################
### procedure to print usage of Ethernet Interfaces
###########################################################################
proc print_usage_port_member {} {
puts "
###############################################################################\
# #\
# Virtual IRF member ports: #\
# #\
# Virtual IRF Port member ports....Range: <available Ethernet Ports> #\
# #\
# The Virtual IRF member ports are Ethernet ports that are associated #\
# with a Virtual IRF port. For Ten Gigabit Ethernet, all ports have #\
# to be associated with the same ASIC. #\
# Example: Port 1,2,3,4 are associated with ASIC 1 #\
# Port membership cannot span ASICs!!!!!! \(Port 1\) and Port \(5\) is #\
# is not a valid configuration. For Forty Gigabit interfaces, this #\
# restriction does not exist for \(ports > 48\) #\
# By default, no ports are assigned. #\
# Input: Ethernet port seperated by \",\" #\
# Example: ten1/0/1,ten1/0/2 or for1/0/49,for1/0/50 #\
# #\
###############################################################################\
"
}
###############################################################################
### procedure to get user input
###########################################################################
proc get_user_input {prompt} {
puts ""
puts $prompt
set input [gets stdin]
if {$input == "q"} {
error $::msg(exit)
} else {
return $input
}
}
###############################################################################
### procedure to get input for Member ID
###########################################################################
proc get_ui_member_id {} {
set user_input [get_user_input $::question_m]
set check_range_result [check_range $user_input $::range_m_min $::range_m_max]
if {$check_range_result != 1} {
puts "$::err_msg(member_id) $user_input"
set ::param(m) ""
return 0
} else {
set ::param(m) $user_input
;# input is valid and within range. Set global value
puts ""
if {$::param(m) != $::current_irf_member_id} {
puts "Current IRF Member ID:....$::current_irf_member_id"
puts "New IRF Member ID:........$::param(m)"
puts ""
puts "Need to re-boot the unit to apply new IRF Member ID............................."
puts "Re-run script after re-number..................................................."
puts ""
puts "Applying re-number command ....................................................."
puts ""
renumber $::current_irf_member_id $::param(m)
puts ""
puts "Done, rebooting now............................................................."
puts ""
exec_reboot
}
}
return 1
}
###############################################################################
### procedure to check input for validity (within range)
###########################################################################
proc check_range {input min max} {
set chk_digit [string is digit $input] ;# check if input is only digits
if {$chk_digit == 1 } {
if {($input >=$min ) && ($input <= $max)} { ;# within range
return 1
} else {
#puts "Outside of range: $min <=> $max, re-enter"
return 0
}
} else {
return 0
}
}
###############################################################################
### procedure to get input for Priority
###########################################################################
proc get_ui_priority {} {
set user_input [get_user_input $::question_p]
set check_range_result [check_range $user_input $::range_p_min $::range_p_max]
if {$check_range_result != 1} {
puts "$::err_msg(priority) $user_input"
set ::param(p) ""
return 0
} else {
set ::param(p) $user_input
return 1
}
}
###############################################################################
### procedure to get input for Domain ID
###########################################################################
proc get_ui_domain_id {} {
set user_input [get_user_input $::question_d]
set check_range_result [check_range $user_input $::range_d_min $::range_d_max]
if {$check_range_result != 1} {
puts "$::err_msg(domain_id) $user_input"
set ::param(d) ""
return 0
} else {
set ::param(d) $user_input
return 1
}
}
###############################################################################
### procedure to get input for Virtual IRF interface
###########################################################################
proc get_ui_irf_port {} {
set user_input [get_user_input $::question_i]
set verif_irf_port_result [verify_irf_port $user_input]
if {$verif_irf_port_result != 1} {
puts "$::err_msg(irf_port) $user_input"
set ::param(i) ""
return 0
}
set ::param(i) $user_input
return 1
}
###############################################################################
### procedure to check for valid input of Virtual IRF port
###########################################################################
proc verify_irf_port {user_input} {
if {$user_input == "1/1" || $user_input == "1/2" || \
$user_input == "2/1" || $user_input == "2/2"} {
return 1
} else {
return 0
}
}
###############################################################################
#### procedure to check if port syntax is valid and classify 10G or 40G
###########################################################################
proc check_port_valid {user_input} {
foreach int $user_input {
set match [lsearch $::ten_gig_ints $int] ;# not 10G interface
if {$match == -1} {
set match [lsearch -exact $::forty_gig_ints $int]
if {$match == -1} { ;# not 10G or 40G interface
set ::FortyGIG 0
set ::TenGIG 0
return 0
} else { ;# is fortygig interface
set ::FortyGIG 1
}
} else { ;# is tengig interface
if {$match != -1 } {
set ::TenGIG 1
}
}
}
return 1
}
###############################################################################
#### procedure to process IRF Member Ports
###########################################################################
proc process_irf_member_ports {port_list} {
set check_port_valid_result [check_port_valid $port_list]
if {$check_port_valid_result != 1} {
puts "$::err_msg(irf_member) $port_list"
return 0
}
set check_port_combination_result [check_port_combination]
if {$check_port_combination_result != 1} {
puts "$::err_msg(if_combo) $port_list"
return 0
}
if {$::TenGIG == 0 && $::FortyGIG == 1} {
# only FortyGIG interfaces, nothing special. Set param(e) to sorted user input
set ::param(e) [lsort -dictionary $port_list]
return 1
}
if {$::AsicType == "Trident" && $::TenGIG == 1} {
# need to check if 10G ports are on same Asic
set get_asic_association_result [get_asic_association $port_list]
if {$get_asic_association_result == 0} {
puts "$::err_msg(span_asic) $port_list"
return 0
}
set used_asic $get_asic_association_result
foreach port $::asic($used_asic) {
lappend ports_to_configure ten$::current_irf_member_id/0/$port
}
set ::param(e) [lsort -dictionary $ports_to_configure]
return 1
}
}
###############################################################################
#### procedure to get list of Virtual IRF Member Ethernet Ports
###########################################################################
proc get_ui_irf_member_ports {} {
set process_irf_member_ports_result 0
while {$process_irf_member_ports_result != 1} {
set user_input [get_user_input $::question_e]
set port_list [split $user_input ","]
set process_irf_member_ports_result [process_irf_member_ports $port_list]
}
return 1
}
###############################################################################
#### procedure to check for valid port combination
###########################################################################
proc check_port_combination {} {
if {$::TenGIG == 1 && $::FortyGIG == 1} {
set ::TenGIG 0
set ::FortyGIG 0
return 0
} else {
return 1
}
}
###############################################################################
#### procedure to get Asic to Port association
###########################################################################
proc get_asic_association {port_list} {
global pattern_10G_dec
global dec_port_list
global asic
# build a list of ports (decimal numbers), strip the tenx/y/
set dec_port_list {}
foreach port $port_list {
set index [string last "/" $port]
set decimal_port [string replace $port 0 $index ""]
lappend dec_port_list $decimal_port
}
# $dec_port_list now has a list of ethernet port (decimal, like 1,3,7)
set asic_num [get_asic [lindex $dec_port_list 0]] ;# set the number of first asic
foreach temp_port $dec_port_list {
set next_asic [get_asic $temp_port]
if {$next_asic != $asic_num} {
return 0
}
}
return $asic_num
}
###############################################################################
### procedure to get what ASIC the port belongs to
###########################################################################
proc get_asic {temp_port} {
for {set A 1} { $A < 13} {incr A} {
set result [lsearch -index 0 $::asic($A) $temp_port]
if {$result ne -1} {
#Aputs "Port: $temp_port belongs to ASIC: $A"
return $A
}
}
}
###############################################################################
#### procedure to print parameters
###########################################################################
proc print_parameters {} {
clearscreen
global param
puts "IRF Member ID..................................: $param(m)"
puts "IRF Priority...................................: $param(p)"
puts "IRF Domain ID..................................: $param(d)"
puts "Virtual IRF-Port...............................: $param(i)"
foreach port $::param(e) {
puts "Ethernet Ports.................................: $port"
}
}
puts ""
###############################################################################
### procedure to get parameters interactivly
###########################################################################
proc interactive {} {
print_interactive_usage ;# print interactive usage of script
puts ""
set ready_to_proceed [get_ui_yes_no $::question_y_n]
if {$ready_to_proceed == 0} {
error "Re-run scripts when ready"
}
#
clearscreen
###########################################################################
print_usage_member_id ;# print usage for Member ID
puts ""
set result 0
while {$result != 1} {
set result [get_ui_member_id] ;# get new Member ID
}
puts ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
###########################################################################
print_usage_priority ;# print usage for IRF Priority
puts ""
set result 0
while {$result != 1} {
set result [get_ui_priority] ;# get new IRF priority value
}
puts ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
###########################################################################
print_usage_domain_id ;# print usage for Domain ID
puts ""
set result 0
while {$result != 1} {
set result [get_ui_domain_id] ;# get new Domain ID
}
puts ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
###########################################################################
print_usage_irf_port
puts ""
set result 0
while {$result != 1} {
set result [get_ui_irf_port]
}
puts ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
###########################################################################
print_usage_port_member ;# print usage for Domain ID
puts ""
set result 0
while {$result != 1} {
set result [get_ui_irf_member_ports] ;# get member ports
}
puts ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}
##### end procedure to get parameters interactively
###############################################################################
### procedure to get cli parameters and process them
###########################################################################
proc get_cli_input {} {
global param
puts "Please enter all parameters on one line............."
puts ""
set ::arguments [gets stdin]
set ::argument_count [llength $::arguments]
if {$::argument_count == 1 && $::arguments == "q"} {
error "Exiting script.............................."
}
if {$::argument_count != 5} {
puts "$::err_msg(arg_count) $::arguments" ;# number of parameters incorrect
set ::arguments ""
set ::argument_count 0
return 0
}
foreach arg $::arguments {
set prefix [string range $arg 0 1]
switch -- $prefix {
"-m" {set param(m) [string range $arg 2 end]}
"-p" {set param(p) [string range $arg 2 end]}
"-d" {set param(d) [string range $arg 2 end]}
"-i" {set param(i) [string range $arg 2 end]}
"-e" {set param(e) [string range $arg 2 end]}
default {
puts "Invalid parameter in command-line..........: $::arguments"
return 0
}
}
}
# must be valid number of parameters and right prefix
#verify each parameter
set check_range_result [check_range $::param(m) $::range_m_min $::range_m_max]
if {$check_range_result != 1} {
puts "$::err_msg(member_id) $::param(m)"
return 0
}
if {$check_range_result != 1} {
puts "$::err_msg(cli_invalid) "
set ::arguments ""
set ::argument_count 0
return 0
}
if {$::current_irf_member_id != $::param(m)} {
puts ""
puts "Current IRF Member ID:....$::current_irf_member_id"
puts "New IRF Member ID:........$::param(m)"
puts ""
puts "Need to re-boot the unit to apply new IRF Member ID............................"
puts "Re-run script after re-number.................................................."
puts ""
puts "Applying re-number command ...................................................."
puts ""
renumber $::current_irf_member_id $::param(m)
puts ""
puts "Done, rebooting now............................................................"
puts ""
exec_reboot
}
set check_range_result [check_range $::param(p) $::range_p_min $::range_p_max]
if {$check_range_result != 1} {
puts "$::err_msg(priority) $::param(p)"
set ::param(p) ""
return 0
}
set check_range_result [check_range $::param(d) $::range_d_min $::range_d_max]
if {$check_range_result != 1} {
puts "$::err_msg(domain_id) $::param(d)"
return 0
}
if {$::param(i) == "1/1" || $::param(i) == "1/2" || \
$::param(i) == "2/1" || $::param(i) == "2/2"} {
# parameter correct
} else {
puts "$::err_msg(irf_port) $::param(i)"
return 0
}
set port_list [split $::param(e) ","]
set process_irf_member_ports_result [process_irf_member_ports $port_list]
if {$process_irf_member_ports_result != 1} {
return 0
}
return 1
}
###############################################################################
#******************************************************************************
# Procedure definitions end
#******************************************************************************
#
###############################################################################
###############################################################################
### Main Code
###############################################################################
#get a list of TenGIG interfaces or the unit. "dis int br | include XGE"
get_tengig_int
#get a list of FortyGIG interfaces or the unit. "dis int br | include FGE"
get_fortygig_int
#get current Member ID of unit. "dis irf", parse "*+"
get_current_member_id
clearscreen
print_welcome_msg
set string_to_print "Ready to proceed in Interactive mode <y/n>? "
set answer [get_ui_yes_no $string_to_print]
set return_val 0
switch -- $answer {
puts "Answer: $answer"
1 { interactive }
0 {
clearscreen
print_usage_cli
while { $return_val == 0} {
set ::param(m) 0
set ::param(p) 0
set ::param(d) 0
set ::param(i) ""
set ::param(e) ""
set return_val [get_cli_input]
}
}
default {get_ui_yes_no $string_to_print}
}
#
# done with either cli or interactive
print_parameters
puts ""
#
### shut down all port, just to be save
#
puts "Shutting down all ports on the unit............................................"
puts ""
set action "shut"
shut_undo_shut $::current_irf_member_id $action
puts ""
puts "You can now physically connect all ports......................................."
puts ""
#
### set IRF Priority
#
puts "Setting IRF-Priority..........................................................."
set_irf_priority $::current_irf_member_id $param(p)
#
### set Domain ID
#
puts "Setting Domain ID.............................................................."
set_domain_id $param(d)
#
### create virtual IRF-Port and assign the Ethernet ports to it
#
puts ""
puts "Creating Virutal IRF-Port and adding Ethernet ports............................"
puts ""
foreach member_port $::param(e) {
puts " Adding port: $member_port to IRF-Port: $param(i)"
set_irf_port $param(i) $member_port
}
puts ""
#
### re-enabling all ports
#
puts "Re-enabling all ports on the unit.............................................."
puts ""
################# renenable all ports now
unset action
set action "undo"
shut_undo_shut $current_irf_member_id $action
puts ""
#
### saving configuration before activating since IRF merge will automatically reboot
#
puts "Saving configuration now......................................................."
save_configuration
#
### activate IRF
#
puts "Activating IRF ................................................................"
activate_irf
#
### save configuration again since main box will not reboot and "undo shut" should be saved
#
puts "Saving configuration again....................................................."
save_configuration
#
### display the IRF configuration
#
puts ""
puts "Displaying IRF configuration..................................................."
puts ""
puts "###########################################################################"
puts "# dis irf #"
puts "###########################################################################"
dis irf
puts "###########################################################################"
puts "# dis irf configuration #"
puts "###########################################################################"
dis irf configuration
puts "###########################################################################"
puts ""
puts "Done..........................................................................."