forked from keysightgems/Huawei_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIxiaNgpfNet.tcl
More file actions
677 lines (649 loc) · 22.7 KB
/
IxiaNgpfNet.tcl
File metadata and controls
677 lines (649 loc) · 22.7 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
package require Itcl
package require registry
namespace import itcl::*
proc GetEnxNgpfInfo { args } {
Deputs "GetEnxInfo:$args "
global enx_portNameList
global enx_portLocationList
foreach { key value } $args {
set key [string tolower $key]
switch -exact -- $key {
-portnamelist {
set enx_portNameList $value
}
-portlocationlist {
set enx_portLocationList $value
}
}
}
}
proc GetOspfNgpfRouterHandle {handle {option 0}} {
set result [regexp {(.*)(topology:[0-9]+)/(deviceGroup:[0-9]+).*([0-9]):(.*)$} $handle match match1 match2 match3 match4]
set devHandle [join $match1/$match2/$match3]
Deputs "devHandle:$devHandle"
if {$match4 == 2} {
set returnHandle [ixNet getL $devHandle ospfv2Router]
set version 2
} elseif {$match4 == 3} {
set returnHandle [ixNet getL $devHandle ospfv3Router]
set version 3
}
if {$option != 0} {
return $version
}
return $returnHandle
}
proc GenerateProtocolsNgpfObjects { portObj } {
set tag "body Port::gen_pro_objs [info script]"
Deputs "----- TAG: $tag -----"
set portObj [GetObject $portObj]
set handle [$portObj cget -handle]
set handleName [$portObj cget -handleName]
set protocols [ixNet getL $handle protocols]
set protocolList [list bfd bgp igmp isis ldp mld ospf ospfV3 static]
foreach pro $protocolList {
set protocol [ixNet getL $protocols $pro]
# Special to handle static
set enabled [ ixNet getA $protocol -enabled ]
if { $pro == "static" && $enabled == "::ixNet::OK" } {
set enabled true
}
if { $enabled } {
switch -exact $pro {
bfd {
set bfdR [ixNet getL $protocol router]
BfdSession ${handleName}/bfd $handleName $bfdR
}
bgp {
set bgpNR [ixNet getL $protocol neighborRange]
BgpSession ${handleName}/bgp $handleName $bgpNR
}
igmp {
set igmpH [ixNet getL $protocol host]
IgmpHost ${handleName}/igmp $handleName $igmpH
}
mld {
set mldH [ixNet getL $protocol host]
MldHost ${handleName}/mld $handleName $mldH
}
isis {
set isisR [ixNet getL $protocol router]
IsisSession ${handleName}/isis $handleName $isisR
}
ldp {
set ldpR [ixNet getL $protocol router]
LdpSession ${handleName}/ldp $handleName $ldpR
}
ospf {
set ospfR [ixNet getL $protocol router]
Ospfv2Session ${handleName}/ospf $handleName $ospfR
}
ospfV3 {
set ospfV3R [ixNet getL $protocol router]
Ospfv3Session ${handleName}/ospfV3 $handleName $ospfV3R
}
static {
set staticLan [ixNet getL $protocol lan]
Host ${handleName}/static $handleName $staticLan
}
}
}
}
set protocolStack [ixNet getL $handle protocolStack]
set protocolStackList [list ipEndpoint dhcpEndpoint dhcpServerEndpoint pppoxEndpoint]
foreach proStack $protocolStackList {
set ethernet [ixNet getL $protocolStack ethernet]
if { [llength $ethernet] == 0 } {
continue
}
foreach ethernet $ethernet {
set stack [ixNet getL $ethernet $proStack]
if { $stack != "" } {
switch -exact $proStack {
dhcpEndpoint {
set ranges [ixNet getL $stack range]
foreach range $ranges {
set ipType [ixNet getA $range/dhcpRange -ipType]
set objName [ixNet getA $range/dhcpRange -name]
if { $ipType == "IPv4" } {
Dhcpv4Host $objName $handleName $stack $range
} elseif { $ipType == "IPv6" } {
Dhcpv6Host $objName $handleName $stack $range
}
}
}
dhcpServerEndpoint {
set ranges [ixNet getL $stack range]
foreach range $ranges {
set ipType [ixNet getA $range/dhcpServerRange -ipType]
set objName [ixNet getA $range/dhcpServerRange -name]
if { $ipType == "IPv4" } {
Dhcpv4Server $objName $handleName $stack $range
} elseif { $ipType == "IPv6" } {
Dhcpv6Server $objName $handleName $stack $range
}
}
}
pppoxEndpoint {
set ranges [ixNet getL $stack range]
foreach range $ranges {
set objName [ixNet getA $range/pppoxRange -name]
PppoeHost $objName $handleName $stack $range
}
}
ipEndpoint {
set ranges [ixNet getL $stack range]
foreach range $ranges {
set objName [ixNet getA $range/ipRange -name]
set ipRangeOptions [ixNet getL $protocolStack ipRangeOptions]
if { [llength $ipRangeOptions] != 0 } {
if { [ixNet getA $ipRangeOptions -ipv6AddressMode] == "autoconf" } {
Ipv6AutoConfigHost $objName $handleName $stack $range
} else {
IPoEHost $objName $handleName $stack $range
}
}
}
}
}
}
}
}
}
proc GetAllPortNgpfObj {} {
set portObj [list]
set objList [ find objects ]
foreach obj $objList {
if { [ $obj isa Port ] } {
lappend portObj [ $obj cget -handle ]
}
}
return $portObj
}
proc GetValidNgpfHandleObj { objType handle { parentHnd "" } } {
global ngpfMode
set tag "GetValidNgpfHandleObj [info script]"
Deputs "----- TAG: $tag -----"
set index 0
if { [ catch {
set index [expr $index + $handle]
} err ] } {
set index 0
}
switch -exact $objType {
port {
Deputs "check port: checkname $handle"
foreach port [ixNet getL [ixNet getRoot] vport] {
set portname [ixNet getA $port -name]
if { $port == $handle } {
return $handle
} elseif { $portname == $handle || $portname == [lindex [split $handle "::"] end] } {
Deputs "portname:$portname; checkname $handle"
return $port
} elseif { [llength [ split $handle "/" ]] == 3 } {
set realLocationInfo [ split $handle "/" ]
set assignedTo [ixNet getA $port -assignedTo]
set ModuleNo [lindex [split $assignedTo ":"] 1]
set PortNo [lindex [split $assignedTo ":"] 2]
if { $ModuleNo == [lindex $realLocationInfo 1] && $PortNo == [lindex $realLocationInfo 2]} {
return $port
}
}
}
return ""
}
traffic {
set trafficObjs [ixNet getL [ixNet getL [ixNet getRoot] traffic] trafficItem]
foreach trafficItemobj $trafficObjs {
set itemlist [ixNet getL $trafficItemobj highLevelStream]
set itemName [ixNet getA $trafficItemobj -name]
foreach trafficobj $itemlist {
set highName [ixNet getA $trafficobj -name]
if { $highName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $highName } {
return $trafficItemobj
} elseif { $itemName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $itemName || $itemName == [lindex [split $handle "::"] end] } {
return $trafficItemobj
}
# if { [ixNet getA $trafficobj -txPortName] == [ixNet getA $parentHnd -name] } {
# if { $highName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $highName } {
# return $trafficItemobj
# } elseif { $itemName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $itemName || $itemName == [lindex [split $handle "::"] end] } {
# return $trafficItemobj
# }
# }
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $trafficObjs] != 0 && [llength $trafficObjs] > $index } {
# return [lindex $trafficObjs $index]
# }
return ""
}
bfd {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols bfd]
if { [ ixNet getA $protocol -enabled ] } {
set routers [ixNet getL $protocol router]
foreach router $routers {
if { $router == $handle } {
return $handle
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $routers] > $index} {
# return [lindex $routers $index]
# }
}
return ""
}
bgp {
set topoObjList [ixNet getL [ixNet getRoot] topology]
if { [ llength $topoObjList ] != 0 } {
foreach topoObj $topoObjList {
set deviceGroupList [ixNet getL $topoObj deviceGroup]
foreach deviceObj $deviceGroupList {
set ethernetObjList [ixNet getL $deviceObj ethernet]
foreach ethernetObj $ethernetObjList {
set ipv4ObjList [ixNet getL $ethernetObj ipv4]
set ipv6ObjList [ixNet getL $ethernetObj ipv6]
if { [ llength $ipv4ObjList ] != 0 } {
foreach ipv4Obj $ipv4ObjList {
set bgpObj [ixNet getL $ipv4Obj bgpIpv4Peer]
if { $bgpObj == $handle } {
return $handle
}
#if {[ixNet getA [ixNet getA $router -interfaces] -description] == $handle} {
# return $router
#}
}
}
if { [ llength $ipv6ObjList ] != 0 } {
foreach ipv6Obj $ipv6ObjList {
set bgpObj [ixNet getL $ipv6Obj bgpIpv6Peer]
if { $bgpObj == $handle } {
return $handle
}
#if {[ixNet getA [ixNet getA $router -interfaces] -description] == $handle} {
# return $router
#}
}
}
}
}
}
}
return ""
}
simroute {
set routers [ixNet getL $parentHnd networkGroup]
foreach router $routers {
if { $router == $handle } {
return $handle
}
if {$ngpfMode == 0} {
if {[ixNet getA $router -networkAddress] == $handle} {
return $router
}
}
}
return ""
}
igmp_host {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols igmp]
if { [ ixNet getA $protocol -enabled ] } {
set hosts [ixNet getL $protocol host]
foreach host $hosts {
if { $host == $handle } {
return $handle
}
if {[ixNet getA [ixNet getA $host -interfaceId] -description] == $handle} {
return $host
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $hosts] != 0 && [llength $hosts] > $index } {
# return [lindex $hosts $index]
# }
}
return ""
}
pim_router {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols pimsm]
if { [ ixNet getA $protocol -enabled ] } {
set routers [ixNet getL $protocol router]
foreach router $routers {
if { $router == $handle } {
return $handle
}
if {[ixNet getA [ixNet getA [lindex [ixNet getL $router interface] 0] -interfaces] -description] == $handle} {
return $router
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $hosts] != 0 && [llength $hosts] > $index } {
# return [lindex $hosts $index]
# }
}
return ""
}
mld_host {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols mld]
if { [ ixNet getA $protocol -enabled ] } {
set hosts [ixNet getL $protocol host]
foreach host $hosts {
if { $host == $handle } {
return $handle
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $hosts] != 0 && [llength $hosts] > $index } {
# return [lindex $hosts $index]
# }
}
return ""
}
isis {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols isis]
if { [ ixNet getA $protocol -enabled ] } {
set routers [ixNet getL $protocol router]
foreach router $routers {
if { $router == $handle } {
return $handle
}
if {[ixNet getA [ixNet getA [lindex [ixNet getL $router interface] 0] -interfaceId] -description] == $handle} {
return $router
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $routers] > $index} {
# return [lindex $routers $index]
# }
}
return ""
}
ldp {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols ldp]
if { [ ixNet getA $protocol -enabled ] } {
set routers [ixNet getL $protocol router]
foreach router $routers {
if { $router == $handle } {
return $handle
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $routers] > $index} {
# return [lindex $routers $index]
# }
}
return ""
}
ospfv2 {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols ospf]
if { [ ixNet getA $protocol -enabled ] } {
set routers [ixNet getL $protocol router]
foreach router $routers {
if { $router == $handle } {
return $handle
}
if {[ixNet getA [ixNet getA [lindex [ixNet getL $router interface] 0] -interfaces] -description] == $handle} {
return $router
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $routers] != 0 && [llength $routers] > $index } {
# return [lindex $routers $index]
# }
}
return ""
}
ospfv3 {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols ospfV3]
if { [ ixNet getA $protocol -enabled ] } {
set routers [ixNet getL $protocol router]
foreach router $routers {
if { $router == $handle } {
return $handle
}
if {[ixNet getA [ixNet getA [lindex [ixNet getL $router interface] 0] -interfaces] -description] == $handle} {
return $router
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $routers] != 0 && [llength $routers] > $index } {
# return [lindex $routers $index]
# }
}
return ""
}
host {
set protocols [ixNet getL $parentHnd protocols]
set protocol [ixNet getL $protocols static]
if { [ ixNet getA $protocol -enabled ] == "::ixNet::OK" } {
set lans [ixNet getL $protocol lan]
foreach lan $lans {
if { $lan == $handle } {
return $handle
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $lans] > $index} {
# return [lindex $lans $index]
# }
}
return ""
}
dhcp {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set stack [ixNet getL $ethernet dhcpEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
set ipv4Ranges [list ]
foreach range $ranges {
if { [ixNet getA $range/dhcpRange -ipType] != "IPv4" } {
continue
}
lappend ipv4Ranges $range
set rangeName [ixNet getA $range/dhcpRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ipv4Ranges] > $index} {
# return [list $stack [lindex $ipv4Ranges $index]]
# }
}
return ""
}
dhcp_server {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set stack [ixNet getL $ethernet dhcpServerEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
set ipv4Ranges [list ]
foreach range $ranges {
if { [ixNet getA $range/dhcpServerRange -ipType] != "IPv4" } {
continue
}
lappend ipv4Ranges $range
set rangeName [ixNet getA $range/dhcpRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ipv4Ranges] > $index} {
# return [list $stack [lindex $ipv4Ranges $index]]
# }
}
return ""
}
dhcpv6 {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set stack [ixNet getL $ethernet dhcpEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
set ipv6Ranges [list ]
foreach range $ranges {
if { [ixNet getA $range/dhcpRange -ipType] != "IPv6" } {
continue
}
lappend ipv6Ranges $range
set rangeName [ixNet getA $range/dhcpRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ipv6Ranges] > $index} {
# return [list $stack [lindex $ipv6Ranges $index]]
# }
}
return ""
}
dhcpv6_server {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set stack [ixNet getL $ethernet dhcpServerEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
set ipv6Ranges [list ]
foreach range $ranges {
if { [ixNet getA $range/dhcpServerRange -ipType] != "IPv6" } {
continue
}
lappend ipv6Ranges $range
set rangeName [ixNet getA $range/dhcpRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ipv6Ranges] > $index} {
# return [list $stack [lindex $ipv6Ranges $index]]
# }
}
return ""
}
pppoe_host {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set stack [ixNet getL $ethernet pppoxEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
foreach range $ranges {
set rangeName [ixNet getA $range/pppoxRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ranges] > $index} {
# return [list $stack [lindex $ranges $index]]
# }
}
return ""
}
l2tp {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set ethstack [ixNet getL $ethernet ip]
if { $ethstack == "" } {
continue
}
set stack [ixNet getL $ethstack l2tpEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
foreach range $ranges {
set rangeName [ixNet getA $range/l2tpRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ranges] > $index} {
# return [list $stack [lindex $ranges $index]]
# }
}
return ""
}
ipoe_host {
set protocolStack [ixNet getL $parentHnd protocolStack]
set ipRangeOptions [ixNet getL $protocolStack ipRangeOptions]
set ethernets [ixNet getL $protocolStack ethernet]
foreach ethernet $ethernets {
set stack [ixNet getL $ethernet ipEndpoint]
if { $stack == "" } {
continue
}
set ranges [ixNet getL $stack range]
set ipoeRanges [list ]
foreach range $ranges {
if { [llength $ipRangeOptions] != 0 } {
if { [ixNet getA $ipRangeOptions -ipv6AddressMode] == "autoconf" } {
continue
}
}
lappend ipoeRanges $range
set rangeName [ixNet getA $range/ipRange -name]
if { $range == $handle } {
return [list $stack $range]
} elseif { $rangeName == $handle || [string range $handle 1 [expr [string length $handle] - 2]] == $rangeName } {
return [list $stack $range]
}
}
# set index [expr $index - 1]
# if { $index >= 0 && [llength $ipoeRanges] > $index} {
# return [list $stack [lindex $ipoeRanges $index]]
# }
}
return ""
}
default {
return ""
}
}
return ""
}
#IxDebugOn
#IxDebugCmdOn