-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIxia_NetNgpfL2TP.tcl
More file actions
540 lines (488 loc) · 18.6 KB
/
Ixia_NetNgpfL2TP.tcl
File metadata and controls
540 lines (488 loc) · 18.6 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
# Copyright (c) Ixia technologies 2010-2011, Inc.
# Release Version 1.0
#===============================================================================
# Change made
# Version 1.0
# 1. Create
class L2tpHost {
inherit ProtocolNgpfStackObject
#public variable type
public variable optionSet
public variable rangeStats
public variable hostCnt
public variable hL2tp
public variable pppoxObj
constructor { port { onStack null } { hl2tp null } } { chain $port $onStack $hl2tp } {
set tag "L2tpHost::constructor [info script]"
Deputs "----- TAG: $tag -----"
global LoadConfigMode
set portObj [ GetObject $port ]
if { $hl2tp == "null" && $LoadConfigMode == 1 } {
set hl2tp [GetObjNameFromString $this "null"]
}
if { $hl2tp != "null" } {
set eth_hnd [GetValidNgpfHandleObj "l2tp" $hl2tp $hPort]
if { [llength $eth_hnd] == 2 } {
set handle [lindex $eth_hnd 1]
set hL2tp [lindex $eth_hnd 0]
set handleName [ ixNet getA $handle/l2tpRange -name ]
}
}
if { $handle == "" } {
set handleName $this
reborn $onStack
}
}
method reborn { { onStack null } } {}
method config { args } {}
method connect { } { start }
method disconnect { } { stop }
method abort { } {
set tag "body L2tpHost::abort [info script]"
Deputs "----- TAG: $tag -----"
ixNet exec abort $hL2tp
return [GetStandardReturnHeader]
}
method get_summary_stats {} {}
method CreateL2tpPerSessionView {} {
set tag "body L2tpHost::CreateL2tpPerSessionView [info script]"
Deputs "----- TAG: $tag -----"
set r_no [expr {int(rand()*100000)}]
set root [ixNet getRoot]
set customView [ ixNet add $root/statistics view ]
ixNet setMultiAttribute $customView -pageTimeout 25 \
-type layer23NextGenProtocol \
-caption "L2tpPerSessionView_$r_no" \
-visible true -autoUpdate true \
-viewCategory NextGenProtocol
ixNet commit
set view [lindex [ixNet remapIds $customView] 0]
set advCv [ixNet add $view "advancedCVFilters"]
set type "Per Port"
set protocol "L2TP Access Concentrator"
ixNet setMultiAttribute $advCv -grouping \"$type\" \
-protocol \{$protocol\} \
-availableFilterOptions \{$type\} \
-sortingStats {}
ixNet commit
set advCv [lindex [ixNet remapIds $advCv] 0]
set ngp [ixNet add $view layer23NextGenProtocolFilter]
ixNet setMultiAttribute $ngp -advancedFilterName \"No\ Filter\" -advancedCVFilter $advCv -protocolFilterIds [list ] -portFilterIds [list ]
ixNet commit
set ngp [lindex [ixNet remapIds $ngp] 0]
set stats [ixNet getList $view statistic]
puts $stats
foreach stat $stats {
ixNet setA $stat -scaleFactor 1
ixNet setA $stat -enabled true
ixNet setA $stat -aggregationType first
ixNet commit
}
ixNet setA $view -enabled true
ixNet commit
ixNet execute refresh $view
return $view
}
}
body L2tpHost::reborn { { onStack null } } {
set tag "body L2tpHost::reborn [info script]"
Deputs "----- TAG: $tag -----"
chain
if { [ catch {
set hPort [ $portObj cget -handle ]
} ] } {
error "$errNumber(1) Port Object in L2tpSession ctor"
}
Deputs "stack: $stack"
set sg_ethernet $stack
#-- add pppox endpoint stack
set sg_l2tp ""
set topoObjList [ixNet getL [ixNet getRoot] topology]
Deputs "topoObjList: $topoObjList"
set vportList [ixNet getL [ixNet getRoot] vport]
#set vport [ lindex $vportList end ]
if {[llength $topoObjList] != [llength $vportList]} {
foreach topoObj $topoObjList {
set vportObj [ixNet getA $topoObj -vports]
foreach vport $vportList {
if {$vportObj != $vport && $vport == $hPort} {
set vportTopoList ""
foreach topoObj $topoObjList {
set vportObj [ixNet getA $topoObj -vports]
lappend vportTopoList $vportObj
}
if {[string first $hPort $vportTopoList] == -1} {
set topoObj [ixNet add [ixNet getRoot] topology -vports $hPort]
ixNet commit
set deviceGroupObj [ixNet add $topoObj deviceGroup]
ixNet commit
ixNet setA $deviceGroupObj -multiplier 1
ixNet commit
set ethernetObj [ixNet add $deviceGroupObj ethernet]
ixNet commit
set ipv4Obj [ixNet add $ethernetObj ipv4]
ixNet commit
}
}
}
break
}
}
set topoObjList [ixNet getL [ixNet getRoot] topology]
if { [ llength $topoObjList ] == 0 } {
set topoObj [ixNet add [ixNet getRoot] topology -vports $hPort]
ixNet commit
set deviceGroupObj [ixNet add $topoObj deviceGroup]
ixNet commit
ixNet setA $deviceGroupObj -multiplier 1
ixNet commit
set ethernetObj [ixNet add $deviceGroupObj ethernet]
ixNet commit
set ipv4Obj [ixNet add $ethernetObj ipv4]
ixNet commit
set sg_l2tp [ixNet add $ipv4Obj lac]
ixNet commit
set sg_l2tp [ ixNet remapIds $sg_l2tp ]
ixNet setA $sg_l2tp -name $this
ixNet commit
set pppoxObj [ createPppox $sg_l2tp ]
array set routeBlock [ list ]
} else {
foreach topoObj $topoObjList {
set vportObj [ixNet getA $topoObj -vports]
if {$vportObj == $hPort} {
set deviceGroupList [ixNet getL $topoObj deviceGroup]
foreach deviceGroupObj $deviceGroupList {
set ethernetList [ixNet getL $deviceGroupObj ethernet]
foreach ethernetObj $ethernetList {
set ipv4Obj [ixNet getL $ethernetObj ipv4]
if { [llength $ipv4Obj] != 0 } {
set sg_l2tp [ixNet getL $ipv4Obj lac]
if {[llength $sg_l2tp] != 0} {
set sg_l2tp [ ixNet remapIds $sg_l2tp ]
set pppoxObj [ getPppoxObj $sg_l2tp ]
if {[llength $pppoxObj] != 0} {
set pppoxObj [ ixNet remapIds $pppoxObj ]
} else {
set pppoxObj [ createPppox $sg_l2tp ]
}
} else {
set sg_l2tp [ixNet add $ipv4Obj lac]
ixNet commit
set sg_l2tp [ ixNet remapIds $sg_l2tp ]
set pppoxObj [ createPppox $sg_l2tp ]
}
} else {
set ipv4Obj [ixNet add $ethernetObj ipv4]
ixNet commit
set sg_l2tp [ixNet add $ipv4Obj lac]
ixNet commit
set sg_l2tp [ ixNet remapIds $sg_l2tp ]
set pppoxObj [ createPppox $sg_l2tp ]
}
}
}
}
}
ixNet setA $sg_l2tp -name $this
ixNet commit
}
set handle $sg_l2tp
set hL2tp $sg_l2tp
ixNet commit
}
proc createPppox {sg_l2tp} {
set deviceGroupObj [GetDependentNgpfProtocolHandle $sg_l2tp "deviceGroup"]
set pppoxdeviceObj [ixNet add $deviceGroupObj deviceGroup]
ixNet commit
set pppoxdeviceObj [ ixNet remapIds $pppoxdeviceObj ]
set pppoxethernetObj [ixNet add $pppoxdeviceObj ethernet]
ixNet commit
set pppoxethernetObj [ ixNet remapIds $pppoxethernetObj ]
set pppoxObj [ixNet add $pppoxethernetObj pppoxclient]
ixNet commit
set pppoxObj [ ixNet remapIds $pppoxObj ]
return $pppoxObj
}
proc getPppoxObj {sg_l2tp} {
set deviceGroupObj [GetDependentNgpfProtocolHandle $sg_l2tp "deviceGroup"]
set pppoxdeviceObj [ixNet getL $deviceGroupObj deviceGroup]
set pppoxethernetObj [ixNet getL $pppoxdeviceObj ethernet]
set pppoxObj [ixNet getL $pppoxethernetObj pppoxclient]
return $pppoxObj
}
body L2tpHost::config { args } {
global errorInfo
global errNumber
set tag "body L2tpHost::config [info script]"
Deputs "----- TAG: $tag -----"
puts "arg: $args"
eval { chain } $args
puts "arg1: $args"
set ENcp [ list ipv4 ipv6 ipv4v6 ]
set EAuth [ list none auto chap_md5 pap ]
#param collection
Deputs "Args:$args "
foreach { key value } $args {
set key [string tolower $key]
switch -exact -- $key {
-session_per_tunnel_count {
set session_per_tunnel_count $value
}
-session_num {
set session_num $value
}
-tunnel_destination_ip {
set tunnel_destination_ip $value
}
-tunnel_authentication {
set tunnel_authentication $value
#hostname|none
}
-tunnel_host {
set tunnel_host $value
}
-tunnel_secret {
set tunnel_secret $value
}
-ipcp_encap {
set ipcp_encap [string tolower $value]
#ipv4|ipv6|ipv4v6
}
-session_auth_type {
set session_auth_type [string tolower $value]
}
-session_user {
set session_user $value
}
-session_password {
set session_password $value
}
-mru {
set mru $value
}
-ip_type {
set ip_type [string tolower $value]
if { $ip_type == "ipv4" } {
set ip_type "IPv4"
}
if { $ip_type == "ipv6" } {
set ip_type "IPv6"
}
}
-ip_address {
set ip_address $value
}
-ip_gateway {
set ip_gateway $value
}
-ip_mask {
set ip_mask $value
}
}
}
if { [ info exists ip_type ] } {
# Not required for NGPF
}
set ipObj [GetDependentNgpfProtocolHandle $handle "ipv4"]
if { [ info exists ip_address ] } {
#set ipPattern [ixNet getA [ixNet getA $ipObj -address] -pattern]
#SetMultiValues $ipObj "-address" $ipPattern $ip_address
set pppoxObj [ getPppoxObj $handle ]
if {[string first "." $ip_address] != -1} {
ixNet setM [ixNet getA $pppoxObj -clientLocalIp]/counter -start $ip_address -direction increment
ixNet commit
} else {
ixNet setM [ixNet getA $pppoxObj -clientLocalIpv6Iid]/counter -start $ip_address -direction increment
ixNet commit
}
if { [ info exists ip_gateway ] } {
if {[string first "." $ip_address] != -1} {
ixNet setM [ixNet getA $pppoxObj -clientLocalIp]/counter -step $ip_gateway
ixNet commit
} else {
ixNet setM [ixNet getA $pppoxObj -clientLocalIpv6Iid]/counter -step $ip_gateway
ixNet commit
}
}
}
if { [ info exists ip_mask ] } {
if {[string first "." $ip_mask] != -1} {
set ipMask $ip_mask
} else {
set ipMask [PrefixlenToSubnetV4 $ip_mask]
}
set ipPattern [ixNet getA [ixNet getA $pppoxObj -clientNetmask] -pattern]
SetMultiValues $pppoxObj "-clientNetmask" $ipPattern $ipMask
}
if { [ info exists session_per_tunnel_count ] } {
set deviceGroupObj [GetDependentNgpfProtocolHandle $handle "deviceGroup"]
set pppoxdeviceObj [ixNet getL $deviceGroupObj deviceGroup]
ixNet setA $pppoxdeviceObj -multiplier $session_per_tunnel_count
ixNet commit
}
if { [ info exists session_num ] } {
ixNet setA $handle -tunnelsPerInterfaceMultiplier $session_num
ixNet commit
}
if { [ info exists tunnel_destination_ip ] } {
set ipPattern [ixNet getA [ixNet getA $handle -baseLnsIp] -pattern]
SetMultiValues $handle "-baseLnsIp" $ipPattern $tunnel_destination_ip
}
if { [ info exists tunnel_authentication ] } {
if {[string first "hostname" $tunnel_authentication] != -1} {
set tunnel_authentication authenticate_hostname
} else {
set tunnel_authentication tunnel_authentication_disabled
}
set ipPattern [ixNet getA [ixNet getA $handle -tunnelAuthentication] -pattern]
SetMultiValues $handle "-tunnelAuthentication" $ipPattern $tunnel_authentication
}
if { [ info exists tunnel_host ] } {
set ipPattern [ixNet getA [ixNet getA $handle -lacHostName] -pattern]
SetMultiValues $handle "-lacHostName" $ipPattern $tunnel_host
}
if { [ info exists tunnel_secret ] } {
set ipPattern [ixNet getA [ixNet getA $handle -lacSecret] -pattern]
SetMultiValues $handle "-lacSecret" $ipPattern $tunnel_secret
}
if { [ info exists mru ] } {
set pppoxObj [ getPppoxObj $handle ]
set ipPattern [ixNet getA [ixNet getA $pppoxObj -mtu] -pattern]
SetMultiValues $pppoxObj "-mtu" $ipPattern $mru
}
if { [ info exists ipcp_encap ] } {
switch $ipcp_encap {
ipv4 {
set ipcp_encap ipv4
}
ipv6 {
set ipcp_encap ipv6
}
ipv4v6 {
set ipcp_encap "dual_stack"
}
}
set pppoxObj [ getPppoxObj $handle ]
set ipPattern [ixNet getA [ixNet getA $pppoxObj -ncpType] -pattern]
SetMultiValues $pppoxObj "-ncpType" $ipPattern $ipcp_encap
}
if { [ info exists session_auth_type ] } {
switch $session_auth_type {
paporchap {
set authentication "pap_or_chap"
set pppoxObj [ getPppoxObj $handle ]
if { [ info exists session_user ] } {
set ipPattern [ixNet getA [ixNet getA $pppoxObj -papUser] -pattern]
SetMultiValues $pppoxObj "-papUser" $ipPattern $session_user
set ipPattern [ixNet getA [ixNet getA $pppoxObj -chapName] -pattern]
SetMultiValues $pppoxObj "-chapName" $ipPattern $session_user
}
if { [ info exists session_password ] } {
set ipPattern [ixNet getA [ixNet getA $pppoxObj -papPassword] -pattern]
SetMultiValues $pppoxObj "-papPassword" $ipPattern $session_password
set ipPattern [ixNet getA [ixNet getA $pppoxObj -chapSecret] -pattern]
SetMultiValues $pppoxObj "-chapSecret" $ipPattern $session_password
}
}
pap {
set authentication pap
set pppoxObj [ getPppoxObj $handle ]
if { [ info exists session_user ] } {
set ipPattern [ixNet getA [ixNet getA $pppoxObj -papUser] -pattern]
SetMultiValues $pppoxObj "-papUser" $ipPattern $session_user
}
if { [ info exists session_password ] } {
set ipPattern [ixNet getA [ixNet getA $pppoxObj -papPassword] -pattern]
SetMultiValues $pppoxObj "-papPassword" $ipPattern $session_password
}
}
chap {
set authentication chap
set pppoxObj [ getPppoxObj $handle ]
if { [ info exists session_user ] } {
set ipPattern [ixNet getA [ixNet getA $pppoxObj -chapName] -pattern]
SetMultiValues $pppoxObj "-chapName" $ipPattern $session_user
}
if { [ info exists session_password ] } {
set ipPattern [ixNet getA [ixNet getA $pppoxObj -chapSecret] -pattern]
SetMultiValues $pppoxObj "-chapSecret" $ipPattern $session_password
}
}
none {
set authentication none
}
}
set ipPattern [ixNet getA [ixNet getA $pppoxObj -authType] -pattern]
SetMultiValues $pppoxObj "-authType" $ipPattern $authentication
}
ixNet commit
return [GetStandardReturnHeader]
}
body L2tpHost::get_summary_stats {} {
set tag "body L2tpHost::get_summary_stats [info script]"
Deputs "----- TAG: $tag -----"
set root [ixNet getRoot]
Deputs "root $root"
set viewList [ixNet getL ::ixNet::OBJ-/statistics view]
#::ixNet::OBJ-/statistics/view:"Global Protocol Statistics"
#Global Protocol Statistics
if {[string first "L2TP Access Concentrator Per Port" $viewList] != -1 } {
set protocol "L2TP Access Concentrator"
#set view [CreateNgpfProtocolView $protocol]
set view {::ixNet::OBJ-/statistics/view:"L2TP Access Concentrator Per Port"}
getStatsView $view $hPort
}
}
proc getStatsView {view {hPort}} {
after 5000
set captionList [ ixNet getA $view/page -columnCaptions ]
puts "captionList $captionList"
set port_name [ lsearch -exact $captionList {Port} ]
set attempted_count [ lsearch -exact $captionList {Sessions Total} ]
set connected_success_count [ lsearch -exact $captionList {Sessions Up} ]
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:$port_name"
set rowPortName [ lindex $row $port_name ]
Deputs "row port name:$port_name"
set connectionInfo [ ixNet getA $hPort -connectionInfo ]
Deputs "connectionInfo :$connectionInfo"
set connectionStatus [ixNet getA $hPort -connectionStatus]
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\.]+);([0-9\.]+);([0-9\.]+)} $connectionStatus match rchassis rcard rport
Deputs "rchass:$rchassis rcard:$rcard rport:$rport"
if { $card < 10 } {
set card 0$card
}
if { $port < 10 } {
set port 0$port
}
if {$chassis == $rchassis && $card == $rcard && $port == $rport} {
set portFound 1
break
}
}
set ret "Status : true\nLog : \n"
if { $portFound } {
set statsItem "attempted_count"
set statsVal [ lindex $row $attempted_count ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
set statsItem "connected_success_count"
set statsVal [ lindex $row $connected_success_count ]
Deputs "stats val:$statsVal"
set ret $ret[ GetStandardReturnBody $statsItem $statsVal ]
}
Deputs "ret:$ret"
return $ret
}