forked from keysightgems/Huawei_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIxia_NetNgpfPim.tcl
More file actions
759 lines (631 loc) · 19.2 KB
/
Ixia_NetNgpfPim.tcl
File metadata and controls
759 lines (631 loc) · 19.2 KB
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
# Copyright (c) Ixia technologies 2010-2011, Inc.
# Release Version 1.0
#===============================================================================
# Change made
# Version 1.0
# 1. Create
class PimSession {
inherit RouterEmulationObject
public variable hInt
constructor { port { hPim NULL } } {
global errNumber
set tag "body PimSession::ctor [info script]"
Deputs "----- TAG: $tag -----"
set portObj [ GetObject $port ]
if {[ catch {
set hPort [ $portObj cget -handle ]
} ] } {
error "$errNumber(1) Port Object in rip ctor"
}
if {[ixNet getA $hPort/protocols/pimsm -enabled]} {
} else {
ixNet setM $hPort/protocols/pimsm -enabled True
ixNet commit
}
if { $hPim == "NULL" } {
set hPim [GetObjNameFromString $this "NULL"]
}
if { $hPim != "NULL" } {
set handle [GetValidHandleObj "pim_router" $hPim $hPort]
Deputs "----- handle: $handle -----"
}
if { $handle != "" } {
set handleName [ ixNet getA $handle -name ]
set rb_interface [ ixNet getL $hPort interface ]
array set interface [ list ]
set hInt [lindex [ixNet getL $handle interface] 0 ]
set int [ixNet getA $hInt -interfaces]
set interface($int) $hInt
}
#-- add pimsm protocol
if { $handle == "" } {
set handle [ ixNet add $hPort/protocols/pimsm router ]
ixNet setA $handle -Enabled True
ixNet commit
set handle [ ixNet remapIds $handle ]
ixNet setA $handle -name $this
set rb_interface [ ixNet getL $hPort interface ]
array set interface [ list ]
generate_interface
}
}
method config { args } {}
method get_status {} {}
method get_stats {} {}
method send_bsm {} {}
method generate_interface { args } {
set tag "body RipSession::generate_interface [info script]"
Deputs "----- TAG: $tag -----"
foreach int $rb_interface {
set hInt [ ixNet add $handle interface ]
ixNet setM $hInt -interfaces $int -enabled True
ixNet commit
set interface($int) $hInt
}
}
}
class PimGroup {
inherit NetObject
public variable hJoinPrune
public variable hSource
public variable rb_interface
constructor { router } {
global errNumber
global LoadConfigMode
set tag "body PimGroup::ctor [info script]"
Deputs "----- TAG: $tag -----"
set routerObj [ GetObject $router ]
if { [ catch {
set hRouter [ $routerObj cget -handle ]
} ] } {
error "$errNumber(1) Router Object in PimGroup ctor"
}
set rb_interface [ ixNet getL $hRouter interface ]
set hJoinPrune ""
if { $LoadConfigMode } {
set RPAddr [GetObjNameFromString $this "NULL"]
set hJoinPruneList [ ixNet getL $rb_interface joinPrune ]
if { $RPAddr != "NULL" && $hJoinPruneList != "" } {
foreach hJ $hJoinPruneList {
set rp_addr [ixNet getA $hJ -rpAddress ]
if { $rp_addr == $RPAddr } {
set hJoinPrune $hJ
break
}
}
}
}
if { $hJoinPrune == "" } {
foreach int $rb_interface {
set hJoinPrune [ ixNet add $rb_interface joinPrune ]
ixNet commit
}
foreach int $rb_interface {
set hSource [ ixNet add $rb_interface source ]
ixNet commit
}
}
}
method config { args } {}
method send_join {} {}
method send_prune {} {}
}
body PimSession::config { args } {
global errorInfo
global errNumber
set bi_dir_option_set NO
set Bootstrap_message_interval 60
set bsr_priority 1
set dr_priority 1
set enable_bsr NO
set gen_id_mode FIXED
set hello_hold_time 105
set hello_interval 30
set join_prune_hold_time 60
set join_prune_interval 60
set ip_version Ipv4
set tag "body PimSession::config [info script]"
Deputs "----- TAG: $tag -----"
foreach { key value } $args {
set key [string tolower $key]
switch -exact -- $key {
-router_id {
set router_id $value
}
-bi_dir_option_set {
set value [string toupper $value]
set bi_dir_option_set $value
}
-bootstrap_message_interval {
set bootstrap_message_interval $value
}
-bsr_priority {
set bsr_priority $value
}
-dr_priority {
set dr_priority $value
}
-enable_bsr {
set value [string toupper $value]
set enable_bsr $value
}
-gen_id_mode {
set value [string toupper $value]
set gen_id_mode $value
}
-hello_hold_time {
set hello_hold_time $value
}
-hello_interval {
set hello_interval $value
}
-join_prune_hold_time {
set join_prune_hold_time $value
}
-join_prune_interval {
set join_prune_interval $value
}
-ip_version {
set value [string tolower $value]
set ip_version $value
}
# Can not find in ixNetwork
-pim_mode {
set pim_mode $value
}
-upstream_neighbor {
set upstream_neighbor $value
}
}
}
ixNet setM $handle -enabled True
if { [ info exists router_id ] } {
ixNet setA $handle -routerId $router_id
ixNet commit
}
if { [ info exists bi_dir_option_set ] } {
switch $bi_dir_option_set {
NO {
set bi_dir_option_set False
}
YES {
set bi_dir_option_set True
}
}
foreach int $rb_interface {
ixNet setA $interface($int) -sendBiDirCapableOption $bi_dir_option_set
}
}
if { [ info exists bootstrap_message_interval ] } {
foreach int $rb_interface {
set aa [ixNet getA $interface($int) -bootstrapEnable ]
if {[ixNet getA $interface($int) -bootstrapEnable ]} {
} else {
ixNet setA $interface($int) -bootstrapEnable True
}
ixNet setA $interface($int) -bootstrapInterval $bootstrap_message_interval
}
}
if { [ info exists bsr_priority ] } {
foreach int $rb_interface {
if {[ixNet getA $interface($int) -bootstrapEnable ]} {
} else {
ixNet setA $interface($int) -bootstrapEnable true
}
ixNet setA $interface($int) -bootstrapPriority $bsr_priority
}
}
if { [ info exists dr_priority ] } {
ixNet setA $handle -drPriority $dr_priority
}
if { [ info exists enable_bsr ] } {
switch $enable_bsr {
NO {
set enable_bsr False
}
YES {
set enable_bsr True
}
}
foreach int $rb_interface {
ixNet setA $interface($int) -bootstrapEnable $enable_bsr
}
ixNet commit
}
if { [ info exists gen_id_mode ] } {
switch $gen_id_mode {
FIXED {
set gen_id_mode constant
}
INCREMENT {
set gen_id_mode incremental
}
RANDOM {
set gen_id_mode random
}
}
foreach int $rb_interface {
ixNet setA $interface($int) -generationIdMode $gen_id_mode
}
ixNet commit
}
if { [ info exists hello_hold_time ] } {
foreach int $rb_interface {
ixNet setA $interface($int) -helloHoldTime $hello_hold_time
}
ixNet commit
}
if { [ info exists hello_interval ] } {
foreach int $rb_interface {
ixNet setA $interface($int) -helloInterval $hello_interval
}
}
if { [ info exists join_prune_hold_time ] } {
ixNet setA $handle -joinPruneHoldTime $join_prune_hold_time
}
if { [ info exists join_prune_interval ] } {
ixNet setA $handle -joinPruneInterval $join_prune_interval
}
if { [ info exists ip_version ] } {
switch $ip_version {
ipv4 {
set ip_version ipv4
}
ipv6 {
set ip_version ipv6
}
}
foreach int $rb_interface {
ixNet setA $interface($int) -addressFamily $ip_version
}
}
if { [ info exists upstream_neighbor ] } {
foreach int $rb_interface {
ixNet setM $interface($int) \
-autoPickUpstreamNeighbor False \
-upstreamNeighbor $upstream_neighbor
}
}
ixNet commit
# Workaround for hello_hold_time setting
if { [ info exists hello_hold_time ] } {
foreach int $rb_interface {
ixNet setA $interface($int) -helloHoldTime $hello_hold_time
}
ixNet commit
}
# Workaround for join_prune_hold_time
if { [ info exists join_prune_hold_time ] } {
ixNet setA $handle -joinPruneHoldTime $join_prune_hold_time
ixNet commit
}
return [GetStandardReturnHeader]
}
body PimSession::get_status {} {
set tag "body PimSession::get_status [info script]"
Deputs "----- TAG: $tag -----"
set root [ixNet getRoot]
Deputs "root $root"
set view {::ixNet::OBJ-/statistics/view:"PIMSM Aggregated Statistics"}
Deputs "view $view"
after 5000
set captionList [ ixNet getA $view/page -columnCaptions ]
Deputs "captionList $captionList"
set name_index [ lsearch -exact $captionList {Stat Name} ]
set rtrsconf_index [ lsearch -exact $captionList {Rtrs. Configured} ]
set rtrsrun_index [ lsearch -exact $captionList {Rtrs. Running} ]
set nbrslear_index [ lsearch -exact $captionList {Nbrs. Learnt} ]
set hellotx_index [ lsearch -exact $captionList {Hellos Tx} ]
set stats [ ixNet getA $view/page -rowValues ]
Deputs "stats:$stats"
set portFound 0
foreach row $stats {
eval {set row} $row
Deputs "row:$row"
Deputs "port index:$name_index"
set rowPortName [ lindex $row $name_index ]
Deputs "row port name:$name_index"
set connectionInfo [ ixNet getA $hPort -connectionInfo ]
Deputs "connectionInfo :$connectionInfo"
regexp -nocase {chassis=\"([0-9\.]+)\" card=\"([0-9\.]+)\" port=\"([0-9\.]+)\"} $connectionInfo match chassis card port
Deputs "chas:$chassis card:$card port:$port"
set portName ${chassis}/Card${card}/Port${port}
Deputs "filter name: $portName"
# 192.168.0.110/Card1/Port7
# 192.168.0.110/Card01/Port07
regexp -nocase {([0-9\.]+)/Card([0-9\.]+)/Port([0-9\.]+)} $rowPortName match rchassis rcard rport
Deputs "rchass:$rchassis rcard:$rcard rport:$rport"
if {$chassis == $rchassis && $card == $rcard && $port == $rport} {
set portFound 1
break
}
}
set status "down"
if { $portFound } {
set rtrsconf [ lindex $row $rtrsconf_index ]
set rtrsrun [ lindex $row $rtrsrun_index ]
set nbrslear [ lindex $row $nbrslear_index ]
set hellotx [ lindex $row $hellotx_index ]
if { $rtrsconf != "" && $rtrsconf == 0 } {
set status "NO_STATE"
}
if { $rtrsrun != "" && $rtrsrun == 0 } {
set status "STOPPED"
} else {
set status "STARTED"
}
if { $nbrslear != "" && $nbrslear != 0 } {
set status "NEIGHBOR"
}
if { $hellotx != "" && $hellotx != 0} {
set status "HELLO"
}
# if {} {
# set status "DR"
# }
}
set ret [ GetStandardReturnHeader ]
set ret $ret[ GetStandardReturnBody "status" $status ]
return $ret
}
body PimSession::get_stats {} {
set tag "body PimSession::get_stats [info script]"
Deputs "----- TAG: $tag -----"
set root [ixNet getRoot]
Deputs "root $root"
set view {::ixNet::OBJ-/statistics/view:"PIMSM Aggregated Statistics"}
after 5000
set captionList [ ixNet getA $view/page -columnCaptions ]
Deputs "captionList $captionList"
set name_index [ lsearch -exact $captionList {Stat Name} ]
set nbrslear_index [ lsearch -exact $captionList {Nbrs. Learnt} ]
set bspmsgrx_index [ lsearch -exact $captionList {Bootstrap Msg Rx} ]
set hellorx_index [ lsearch -exact $captionList {Hellos Rx} ]
set regrx_index [ lsearch -exact $captionList {Register Rx} ]
set regstoprx_index [ lsearch -exact $captionList {RegisterStop Rx} ]
set bspmsgtx_index [ lsearch -exact $captionList {Bootstrap Msg Tx} ]
set hellotx_index [ lsearch -exact $captionList {Hellos Tx} ]
set regtx_index [ lsearch -exact $captionList {Register Tx} ]
set regstoptx_index [ lsearch -exact $captionList {RegisterStop Tx} ]
set stats [ ixNet getA $view/page -rowValues ]
Deputs "stats:$stats"
set portFound 0
foreach row $stats {
eval {set row} $row
Deputs "row:$row"
Deputs "port index:$name_index"
set rowPortName [ lindex $row $name_index ]
Deputs "row port name:$name_index"
set connectionInfo [ ixNet getA $hPort -connectionInfo ]
Deputs "connectionInfo :$connectionInfo"
regexp -nocase {chassis=\"([0-9\.]+)\" card=\"([0-9\.]+)\" port=\"([0-9\.]+)\"} $connectionInfo match chassis card port
Deputs "chas:$chassis card:$card port:$port"
set portName ${chassis}/Card${card}/Port${port}
Deputs "filter name: $portName"
# 192.168.0.110/Card1/Port7
# 192.168.0.110/Card01/Port07
regexp -nocase {([0-9\.]+)/Card([0-9\.]+)/Port([0-9\.]+)} $rowPortName match rchassis rcard rport
Deputs "rchass:$rchassis rcard:$rcard rport:$rport"
if {$chassis == $rchassis && $card == $rcard && $port == $rport} {
set portFound 1
break
}
}
set ret "Status : true\nLog : \n"
if { $portFound } {
set statsItem "neighbor_count"
set statsVal [ lindex $row $nbrslear_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_bootstrap_count"
set statsVal [ lindex $row $bspmsgrx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_hello_count"
set statsVal [ lindex $row $hellorx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_register_count"
set statsVal [ lindex $row $regrx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_register_stop_count"
set statsVal [ lindex $row $regstoprx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_bootstrap_count"
set statsVal [ lindex $row $bspmsgtx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_hello_count"
set statsVal [ lindex $row $hellotx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_register_count"
set statsVal [ lindex $row $regtx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_register_stop_count"
set statsVal [ lindex $row $regstoptx_index ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
# Can not find in ixNet,so set N/A
set statsItem "rx_assert_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_cand_rp_advert_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_group_rp_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_group_sg_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_group_sgrpt_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_group_starg_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "rx_join_prune_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_assert_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_cand_rp_advert_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_group_rp_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_group_sg_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_group_sgrpt_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_group_starg_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "tx_join_prune_count"
set statsVal "N/A"
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
}
Deputs "ret:$ret"
return $ret
}
body PimSession::send_bsm {} {
global errorInfo
global errNumber
set tag "body PimSession::send_bsm [info script]"
Deputs "----- TAG: $tag -----"
foreach int $rb_interface {
ixNet setA $interface($int) -supportUnicastBootstrap True
}
ixNet commit
return [GetStandardReturnHeader]
}
body PimGroup::config { args } {
global errorInfo
global errNumber
set enabling_pruning no
set group_type starg
set tag "body PimGroup::config [info script]"
Deputs "----- TAG: $tag -----"
foreach { key value } $args {
set key [string tolower $key]
switch -exact -- $key {
-enabling_pruning {
set value [string toupper $value]
set enabling_pruning $value
}
-group_type {
set value [string toupper $value]
set group_type $value
}
-rp_ip_addr {
set rp_ip_addr $value
}
-group {
set group $value
}
}
}
if { [ info exists enabling_pruning ] } {
switch $enabling_pruning {
NO {
set enabling_pruning False
}
YES {
set enabling_pruning True
}
}
foreach int $rb_interface {
ixNet setA $hJoinPrune -enabled $enabling_pruning
}
}
if { [ info exists group_type ] } {
switch $group_type {
STARG {
set group_type g
}
SG {
set group_type sg
}
STARSTARRP {
set group_type rp
}
}
foreach int $rb_interface {
ixNet setA $hJoinPrune -groupRange $group_type
}
}
if { [ info exists rp_ip_addr ] } {
foreach int $rb_interface {
ixNet setA $hJoinPrune -rpAddress $rp_ip_addr
puts "hJoinPrune is: $hJoinPrune"
}
}
if { [ info exists group ] } {
set group [ GetObject $group ]
$group configure -handle $hSource
if { $group == ""} {
return [GetErrorReturnHeader "No valid object found...-group $group"]
}
ixNet setA $hSource -enabled True
set source_ip [ $group cget -source_ip ]
set source_num [ $group cget -source_num ]
set group_ip [ $group cget -group_ip ]
set group_num [ $group cget -group_num ]
set group_modbit [ $group cget -group_modbit ]
ixNet setM $hSource \
-enabled True \
-sourceAddress $source_ip \
-sourceCount $source_num \
-groupAddress $group_ip \
-groupCount $group_num \
-groupMaskWidth $group_modbit
} else {
return [GetErrorReturnHeader "Madatory parameter needed...-group"]
}
ixNet commit
return [GetStandardReturnHeader]
}
body PimGroup::send_join {} {
global errorInfo
global errNumber
set tag "body PimGroup::send_join [info script]"
Deputs "----- TAG: $tag -----"
foreach int $rb_interface {
ixNet setA $hJoinPrune -enabled True
}
ixNet commit
return [GetStandardReturnHeader]
}
body PimGroup::send_prune {} {
global errorInfo
global errNumber
set tag "body PimGroup::send_prune [info script]"
Deputs "----- TAG: $tag -----"
foreach int $rb_interface {
ixNet setA $hJoinPrune -enabled False
}
ixNet commit
return [GetStandardReturnHeader]
}