forked from keysightgems/Huawei_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIxia_NetNgpfIsis.tcl
More file actions
434 lines (376 loc) · 10.9 KB
/
Ixia_NetNgpfIsis.tcl
File metadata and controls
434 lines (376 loc) · 10.9 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
# Copyright (c) Ixia technologies 2010-2011, Inc.
# Release Version 1.1
#===============================================================================
# Change made
# Version 1.0
# 1. Create
# Version 1.1.14.58
# 2. Add ipv4_addr ipv4_gw ipv4_prefix_len ipv6_addr ipv6_gw ipv6_prefix_len in config
# 3. Add SimulatedRoute class
class IsisSession {
inherit RouterEmulationObject
constructor { port { hIsisSession NULL } } {}
method reborn {} {}
method config { args } {}
method get_stats {} {}
method advertise_topo {} {}
method withdraw_topo {} {}
public variable mac_addr
}
body IsisSession::get_stats {} {
set tag "body IsisSession::get_stats [info script]"
Deputs "----- TAG: $tag -----"
set root [ixNet getRoot]
set view {::ixNet::OBJ-/statistics/view:"BGP Aggregated Statistics"}
# set view [ ixNet getF $root/statistics view -caption "Port Statistics" ]
Deputs "view:$view"
set captionList [ ixNet getA $view/page -columnCaptions ]
Deputs "caption list:$captionList"
set port_name [ lsearch -exact $captionList {Stat Name} ]
set session_conf [ lsearch -exact $captionList {Sess. Configured} ]
set session_succ [ lsearch -exact $captionList {Sess. Up} ]
set flap [ lsearch -exact $captionList {Session Flap Count} ]
set ret [ GetStandardReturnHeader ]
set stats [ ixNet getA $view/page -rowValues ]
Deputs "stats:$stats"
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"
foreach row $stats {
eval {set row} $row
Deputs "row:$row"
Deputs "portname:[ lindex $row $port_name ]"
if { [ string length $card ] == 1 } {
set card "0$card"
}
if { [ string length $port ] == 1 } {
set port "0$port"
}
if { "${chassis}/Card${card}/Port${port}" != [ lindex $row $port_name ] } {
continue
}
set statsItem "session_conf"
set statsVal [ lindex $row $session_conf ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "session_succ"
set statsVal [ lindex $row $session_succ ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "flap"
set statsVal [ lindex $row $flap ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
Deputs "ret:$ret"
}
return $ret
}
body IsisSession::reborn {} {
set tag "body IsisSession::reborn [info script]"
Deputs "----- TAG: $tag -----"
#-- add isis protocol
Deputs "hPort:$hPort"
set handle [ ixNet add $hPort/protocols/isis router ]
ixNet setA $handle -name $this
ixNet commit
set handle [ ixNet remapIds $handle ]
Deputs "handle:$handle"
#-- add router interface
set intList [ ixNet getL $hPort interface ]
if { [ llength $intList ] } {
set interface [ lindex $intList 0 ]
} else {
set interface [ ixNet add $hPort interface ]
ixNet setA $interface -enabled True
ixNet commit
set interface [ ixNet remapIds $interface ]
Deputs "port interface:$interface"
}
ixNet setA $hPort/protocols/isis -enabled True
ixNet setA $handle -enabled True
ixNet commit
#-- add vlan
set vlan [ ixNet add $interface vlan ]
ixNet commit
#-- port/protocols/isis/router/interface
set rb_interface [ ixNet add $handle interface ]
ixNet setM $rb_interface \
-interfaceId $interface \
-enableConnectedToDut True \
-enabled True
ixNet commit
set rb_interface [ ixNet remapIds $rb_interface ]
Deputs "rb_interface:$rb_interface"
set protocol isis
}
body IsisSession::constructor { port { hIsisSession NULL } } {
set tag "body IsisSession::constructor [info script]"
Deputs "----- TAG: $tag -----"
global errNumber
#-- enable protocol
set portObj [ GetObject $port ]
Deputs "port:$portObj"
if { [ catch {
set hPort [ $portObj cget -handle ]
Deputs "port handle: $hPort"
} ] } {
error "$errNumber(1) Port Object in IsisSession ctor"
}
Deputs "initial port..."
if { $hIsisSession == "NULL" } {
set hIsisSession [GetObjNameFromString $this "NULL"]
}
Deputs "----- hIsisSession: $hIsisSession, hPort: $hPort -----"
if { $hIsisSession != "NULL" } {
set handle [GetValidHandleObj "isis" $hIsisSession $hPort]
Deputs "----- handle: $handle -----"
if { $handle != "" } {
set handleName [ ixNet getA $handle -name ]
}
}
if { ![info exists handle] || $handle == ""} {
set handleName $this
set handle ""
reborn
}
Deputs "Step10"
}
body IsisSession::config { args } {
set tag "body IsisSession::config [info script]"
Deputs "----- TAG: $tag -----"
set sys_id "64:01:00:01:00:00"
# in case the handle was removed
if { $handle == "" } {
reborn
}
Deputs "Args:$args "
foreach { key value } $args {
set key [string tolower $key]
switch -exact -- $key {
-sys_id -
-system_id {
set sys_id $value
}
-network_type {
set value [string tolower $value]
switch $value {
p2p {
set value pointToPoint
}
p2mp {
set value pointToMultipoint
}
default {
set value broadcast
}
}
set network_type $value
}
-discard_lsp {
set discard_lsp $value
}
-interface_metric -
-metric {
set metric $value
}
-enable_wide_metric {
set enable_wide_metric $value
}
-hello_interval {
set hello_interval $value
}
-dead_interval {
set dead_interval $value
}
-vlan_id {
set vlan_id $value
}
-lsp_refreshtime {
set lsp_refreshtime $value
}
-lsp_lifetime {
set lsp_lifetime $value
}
-mac_addr {
set value [ MacTrans $value ]
if { [ IsMacAddress $value ] } {
set mac_addr $value
} else {
Deputs "wrong mac addr: $value"
error "$errNumber(1) key:$key value:$value"
}
}
-ipv6_addr {
set ipv6_addr $value
}
-ipv6_gw {
set ipv6_gw $value
}
-ipv6_prefix_len {
set ipv6_prefix_len $value
}
-ip_version {
set ip_version $value
}
-level {
set level $value
}
-ipv4_addr {
set ipv4_addr $value
}
-ipv4_prefix_len {
set ipv4_prefix_len $value
}
-ipv4_gw {
set ipv4_gw $value
}
}
}
if { [ info exists ip_version ] } {
if { [ string tolower $ip_version ] == "ipv6" } {
if { [ llength [ ixNet getL $interface ipv4 ] ] } {
ixNet remove [ ixNet getL $interface ipv4 ]
ixNet commit
}
} else {
if { ![ llength [ ixNet getL $interface ipv4 ] ] } {
ixNet add $interface ipv4
ixNet commit
}
}
}
if { [ info exists ipv4_addr ] } {
ixNet setA [ ixNet getL $interface ipv4 ] \
-ip $ipv4_addr
}
if { [ info exists ipv4_prefix_len ] } {
ixNet setA [ ixNet getL $interface ipv4 ] \
-maskWidth $ipv4_prefix_len
}
if { [ info exists ipv4_gw ] } {
ixNet setA [ ixNet getL $interface ipv4 ] \
-gateway $ipv4_gw
}
if { [ info exists ipv6_addr ] } {
ixNet setA [ ixNet getL $interface ipv6 ] \
-ip $ipv6_addr
}
if { [ info exists ipv6_prefix_len ] } {
ixNet setA [ ixNet getL $interface ipv6 ] \
-prefixLength $ipv6_prefix_len
}
if { [ info exists ipv6_gw ] } {
ixNet setA [ ixNet getL $interface ipv6 ] \
-gateway $ipv6_gw
}
if { [ info exists level ] } {
switch [ string tolower $level ] {
l1 {
set level level1
}
l2 {
set level level2
}
l12 {
set level level1Level2
}
}
ixNet setA $rb_interface -level $level
}
if { [ info exists sys_id ] } {
while { [ ixNet getF $hPort/protocols/isis router -systemId "[ split $sys_id : ]" ] != "" } {
Deputs "sys_id: $sys_id"
set sys_id [ IncrMacAddr $sys_id "00:00:00:00:00:01" ]
}
Deputs "sys_id: $sys_id"
ixNet setA $handle -systemId $sys_id
}
if { [ info exists enable_wide_metric ] } {
ixNet setA $handle -enableWideMetric $enable_wide_metric
}
if { [ info exists network_type ] } {
ixNet setA $rb_interface -networkType $network_type
}
if { [ info exists discard_lsp ] } {
ixNet setA $handle -enableDiscardLearnedLsps $discard_lsp
}
if { [ info exists metric ] } {
ixNet setA $rb_interface -metric $metric
}
if { [ info exists hello_interval ] } {
ixNet setA $rb_interface -level1HelloTime $hello_interval
}
if { [ info exists dead_interval ] } {
ixNet setA $rb_interface -level1DeadTime $dead_interval
}
if { [ info exists vlan_id ] } {
set vlan [ixNet getL $interface vlan]
ixNet setA $vlan -vlanId $vlan_id
}
if { [ info exists lsp_refreshtime ] } {
ixNet setA $handle -lspRefreshRate $lsp_refreshtime
}
if { [ info exists lsp_lifetime ] } {
ixNet setA $handle -lspLifeTime $lsp_lifetime
}
if { [ info exists mac_addr ] } {
Deputs "interface:$interface mac_addr:$mac_addr"
ixNet setA $interface/ethernet -macAddress $mac_addr
}
ixNet commit
return [GetStandardReturnHeader]
}
body IsisSession::advertise_topo {} {
set tag "body IsisSession::advertise_topo [info script]"
Deputs "----- TAG: $tag -----"
foreach route [ ixNet getL $handle routeRange ] {
ixNet setA $route -enabled True
}
if {[info exists hNetworkRange ]} {
ixNet setA $hNetworkRange -enabled True
}
ixNet commit
return [GetStandardReturnHeader]
}
body IsisSession::withdraw_topo {} {
set tag "body IsisSession::withdraw_topo [info script]"
Deputs "----- TAG: $tag -----"
foreach route [ ixNet getL $handle routeRange ] {
ixNet setA $route -enabled False
}
if {[info exists hNetworkRange ]} {
ixNet setA $hNetworkRange -enabled False
}
ixNet commit
return [GetStandardReturnHeader]
}
class SimulatedRoute {
inherit SimulatedSummaryRoute
constructor { router } { chain $router } {}
method config { args } {}
}
body SimulatedRoute::config { args } {
global errorInfo
global errNumber
set tag "body SimulatedRoute::config [info script]"
Deputs "----- TAG: $tag -----"
eval chain $args
foreach { key value } $args {
set key [string tolower $key]
switch -exact -- $key {
-route_type {
set route_type $value
}
}
}
if { [ info exists route_type ] } {
if { [ string tolower $route_type ] == "internal" } {
set route_origin false
} else {
set route_origin true
}
ixNet setA $handle -routeOrigin $route_origin
}
ixNet commit
}