-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathshow_interface.py
More file actions
executable file
·5198 lines (4356 loc) · 213 KB
/
show_interface.py
File metadata and controls
executable file
·5198 lines (4356 loc) · 213 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
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
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''show_interface.py
NXOS parsers for the following show commands:
* show interface
* show interface {interface}
* show ip interface {interface} vrf {vrf}
* show ip interface {interface} vrf all
* show ip interface vrf {vrf}
* show ip interface vrf all
* show vrf {vrf} interface {interface}
* show vrf all interface {interface}
* show vrf {vrf} interface
* show vrf all interface
* show interface switchport
* show interface {interface} switchport
* show ipv6 interface {interface} vrf {vrf}
* show ipv6 interface {interface} vrf all
* show ipv6 interface vrf {vrf}
* show ipv6 interface vrf all
* show ip interface brief
* show ip interface brief | include Vlan
* show interface brief
* show interface {interface} brief
* show running-config interface {interface}
* show running-config | section ^interface
* show nve interface {interface} detail
* show ip interface brief vrf all | include {ip}
* show ip interface brief vrf all
* show interface description
* show interface {interface} description
* show interface status
* show interface {interface} status
* show interface capabilities
* show interface {interface} capabilities
* show interface transceiver
* show interface {interface} transceiver
* show interface transceiver details
* show interface {interface} transceiver details
* show interface fec
* show interface hardware-mappings
'''
# python
import re
# metaparser
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Schema, Any, Optional, ListOf
# import parser utils
from genie.libs.parser.utils.common import Common
# ===========================
# Schema for 'show interface'
# ===========================
class ShowInterfaceSchema(MetaParser):
"""Schema for show interface"""
schema = {
Any(): {
Optional("description"): str,
Optional("types"): str,
Optional("parent_interface"): str,
"oper_status": str,
Optional("admin_state"): str,
Optional("dedicated_interface"): bool,
Optional("line_protocol"): str,
Optional("autostate"): bool,
Optional("link_state"): str,
Optional("phys_address"): str,
Optional("port_speed"): str,
Optional("port_speed_unit"): str,
Optional("mtu"): int,
"enabled": bool,
Optional("mac_address"): str,
Optional("auto_negotiate"): bool,
Optional("fec_mode"): str,
Optional("duplex_mode"): str,
Optional("port_mode"): str,
Optional("auto_mdix"): str,
Optional("switchport_monitor"): str,
Optional("efficient_ethernet"): str,
Optional("last_link_flapped"): str,
Optional("last_clear_counters"): str,
Optional("interface_reset"): int,
Optional("ethertype"): str,
Optional("beacon"): str,
Optional("medium"): str,
Optional("reliability"): str,
Optional("txload"): str,
Optional("rxload"): str,
Optional("delay"): int,
Optional("media_type"): str,
Optional("flow_control"): {
Optional("receive"): bool,
Optional("send"): bool,
},
Optional("port_channel"): {
Optional("port_channel_member"): bool,
Optional("port_channel_int"): str,
Optional("port_channel_member_intfs"): list,
},
Optional("bandwidth"): int,
Optional("counters"): {
Optional("rate"): {
Optional("load_interval"): int,
Optional("in_rate"): int,
Optional("in_rate_pkts"): int,
Optional("out_rate"): int,
Optional("out_rate_pkts"): int,
Optional("in_rate_bps"): int,
Optional("in_rate_pps"): int,
Optional("out_rate_bps"): int,
Optional("out_rate_pps"): int,
},
Optional("in_unicast_pkts"): int,
Optional("in_multicast_pkts"): int,
Optional("in_broadcast_pkts"): int,
Optional("in_discards"): int,
Optional("in_crc_errors"): int,
Optional("in_oversize_frames"): int,
Optional("in_pkts"): int,
Optional("in_mac_pause_frames"): int,
Optional("in_jumbo_packets"): int,
Optional("in_storm_suppression_packets"): int,
Optional("in_storm_suppression_bytes"): int,
Optional("in_runts"): int,
Optional("in_oversize_frame"): int,
Optional("in_overrun"): int,
Optional("in_underrun"): int,
Optional("in_ignored"): int,
Optional("in_watchdog"): int,
Optional("in_bad_etype_drop"): int,
Optional("in_unknown_protos"): int,
Optional("in_if_down_drop"): int,
Optional("in_with_dribble"): int,
Optional("in_discard"): int,
Optional("in_octets"): int,
Optional("in_errors"): int,
Optional("in_short_frame"): int,
Optional("in_no_buffer"): int,
Optional("out_pkts"): int,
Optional("out_unicast_pkts"): int,
Optional("out_multicast_pkts"): int,
Optional("out_broadcast_pkts"): int,
Optional("out_discard"): int,
Optional("out_octets"): int,
Optional("out_jumbo_packets"): int,
Optional("out_errors"): int,
Optional("out_collision"): int,
Optional("out_deferred"): int,
Optional("out_late_collision"): int,
Optional("out_lost_carrier"): int,
Optional("out_no_carrier"): int,
Optional("out_babble"): int,
Optional("last_clear"): str,
Optional("tx"): bool,
Optional("rx"): bool,
Optional("out_mac_pause_frames"): int,
},
Optional("encapsulations"): {
Optional("encapsulation"): str,
Optional("first_dot1q"): str,
Optional("native_vlan"): int,
},
Optional("ipv4"): {
Any(): {
Optional("ip"): str,
Optional("prefix_length"): str,
Optional("secondary"): bool,
Optional("route_tag"): str,
},
},
},
}
# ===========================
# Parser for 'show interface'
# ===========================
class ShowInterface(ShowInterfaceSchema):
"""Parser for show interface, show interface <interface>"""
cli_command = ['show interface', 'show interface {interface}']
exclude = [
'in_unicast_pkts',
'out_unicast_pkts',
'in_octets',
'out_octets',
'in_pkts',
'out_pkts',
'in_multicast_pkts',
'out_multicast_pkts',
'in_rate',
'out_rate',
'in_broadcast_pkts',
'out_broadcast_pkts',
'last_link_flapped',
'in_rate_pkts',
'out_rate_pkts',
'out_rate_bps',
'in_rate_bps',
'interface_reset',
'in_rate_pps',
'out_rate_pps',
'last_clear',
'out_jumbo_packets',
'in_jumbo_packets',
'rxload',
'txload',
'in_errors',
'mac_address',
'phys_address',
'in_crc_errors',
'reliability']
def cli(self, interface="", output=None):
if output is None:
if interface:
cmd = self.cli_command[1].format(interface=interface)
else:
cmd = self.cli_command[0]
output = self.device.execute(cmd)
# Ethernet2/1.10 is down (Administratively down)
# Vlan1 is down (Administratively down), line protocol is down, autostate enabled
# Vlan200 is down (VLAN/BD is down), line protocol is down, autostate enabled
# Vlan23 is administratively down (Administratively down), line protocol is down, autostate enabled
# Vlan3378 is down (VLAN/BD does not exist), line protocol is down, autostate enabled
# Ethernet2/2 is up
# Ethernet1/10 is down (Link not connected)
# Ethernet1/1 is down (DCX-No ACK in 100 PDUs)
# Ethernet1/3 is down (XCVR not inserted)
# Ethernet1/2 is down (SFP validation failed)
# Ethernet1/4 is down (SFP not inserted)
# Ethernet1/11 is down (inactive)
# Ethernet1/12 is down (Transceiver validation failed)
# Ethernet1/13 is down (SFP validation failed)
# Ethernet1/13 is down (Channel admin down)
# Ethernet140/1/26 is down (linkFlapErrDisabled, port: error)
p1 = re.compile(r'^(?P<interface>\S+)\s*is\s*'
r'(?P<link_state>(down|up|'
r'inactive|Transceiver +validation +failed|'
r'SFP +validation +failed|Channel +admin +down))?'
r'(administratively\s+(?P<admin_1>(down)))?\s*'
r'(\(Administratively\s*(?P<admin_2>(down))\))?'
r'(\(VLAN\/BD\s+((is\s+(down|up))|does\s+not\s+exist)\))?'
r'(,\s*line\s+protocol\s+is\s+(?P<line_protocol>\w+))?'
r'(,\s+autostate\s+(?P<autostate>\S+))?'
r'(\(No\s+operational\s+members\))?'
r'(\(Transceiver\s+validation\s+failed\))?'
r'(\(Channel\s+admin\s+down\))?'
r'(\(Link\s+not\s+connected\))?'
r'(\(SFP\s+validation\s+failed\))?'
r'(\(SFP\s+not\s+inserted\))?'
r'(\(SFP\s+checksum\s+error\))?'
r'(\(suspended\(.*\)\))?'
r'(\(\S+ErrDisabled\))?'
r'(\(XCVR\s+not\s+inserted\))?'
r'(\(No\s+operational\s+members\))?'
r'(\(.*ACK.*\))?'
r'(\(inactive\))?'
r'(\(Hardware\s+failure\))?'
r'(\(linkFlapErrDisabled, +port: +error\))?$')
# admin state is up
# admin state is up,
# admin state is up, Dedicated Interface
# admin state is up, Dedicated Interface, [parent interface is Ethernet2/1]
p2 = re.compile(r'^admin +state +is'
r' +(?P<admin_state>([a-zA-Z0-9\/\.]+))(?:,)?'
r'(?: +(?P<dedicated_intf>(Dedicated Interface)))?'
r'(?:, +\[parent +interface +is'
r' +(?P<parent_intf>(\S+))\])?$')
# Dedicated Interface
p2_1 = re.compile(r'^Dedicated Interface$')
# Belongs to Po1
p2_2 = re.compile(r'^Belongs *to *(?P<port_channel_int>[a-zA-Z0-9]+)$')
# Hardware: Ethernet, address: 5254.00ff.9c38 (bia 5254.00ff.9c38)
p3 = re.compile(r'^Hardware: *(?P<types>[a-zA-Z0-9\/\s]+),'
r' *address: *(?P<mac_address>[a-z0-9\.]+)'
r' *\(bia *(?P<phys_address>[a-z0-9\.]+)\)$')
# Hardware is EtherSVI, address is 547f.ee6d.7d7c
p3_1 = re.compile(r'^Hardware is *(?P<types>[a-zA-Z0-9\/\s]+), '
r'address is *(?P<mac_address>[a-z0-9\.]+)$')
# Description: desc
p4 = re.compile(r'^Description:\s*(?P<description>.*)$')
# Description: VLAN information Internet Address is 10.10.10.1/24
p4_1 = re.compile(r'^Description:\s*(?P<description>.*)'
r'\s+Internet\s+Address\s+is\s+(?P<ip>[0-9\.]+)'
r'\/(?P<prefix_length>[0-9]+)$')
# Internet Address is 10.4.4.4/24 secondary tag 10
p5 = re.compile(r'^Internet *Address *is *(?P<ip>[0-9\.]+)'
r'\/(?P<prefix_length>[0-9]+)'
r'(?: *(?P<secondary>(secondary)))?(?: *tag'
r' *(?P<route_tag>[0-9]+))?$')
# MTU 1600 bytes, BW 768 Kbit, DLY 3330 usec
# MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec,
# MTU 1500 bytes, BW 1000000 Kbit
# MTU 600 bytes, BW 10000000 Kbit , DLY 10 usec
p6 = re.compile(r'^MTU *(?P<mtu>[0-9]+) *bytes, *BW'
r' *(?P<bandwidth>[0-9]+) *Kbit( *, *DLY'
r' *(?P<delay>[0-9]+) *usec)?,?$')
# MTU 1500 bytes, BW 40000000 Kbit,, BW 40000000 Kbit, DLY 10 usec
p6_1 = re.compile(r'^MTU *(?P<mtu>[0-9]+) *bytes, *BW'
r' *(?P<bandwidth>[0-9]+) *Kbit, *,? *BW'
r' *([0-9]+) *Kbit, *DLY'
r' *(?P<delay>[0-9]+) *usec$')
# reliability 255/255, txload 1/255, rxload 1/255
p7 = re.compile(r'^reliability *(?P<reliability>[0-9\/]+),'
r' *txload *(?P<txload>[0-9\/]+),'
r' *rxload *(?P<rxload>[0-9\/]+)$')
# Encapsulation 802.1Q Virtual LAN, Vlan ID 10, medium is broadcast
# Encapsulation 802.1Q Virtual LAN, Vlan ID 20, medium is p2p
# Encapsulation ARPA, medium is broadcast
p8 = re.compile(r'^Encapsulation *(?P<encapsulation>[a-zA-Z0-9\.\s]+),'
r' *medium *is *(?P<medium>[a-zA-Z]+)$')
p8_1 = re.compile(r'^Encapsulation *(?P<encapsulation>[a-zA-Z0-9\.\s]+),'
r' *Vlan *ID *(?P<first_dot1q>[0-9]+),'
r' *medium *is *(?P<medium>[a-z0-9]+)$')
# Encapsulation ARPA, loopback not set
p8_2 = re.compile(r'^Encapsulation *(?P<encapsulation>[a-zA-Z0-9\.\s]+),'
r' *([\w\s]+)$')
# Port mode is routed
p9 = re.compile(r'^Port *mode *is *(?P<port_mode>[a-z]+)$')
# auto-duplex, auto-speed
p10_1 = re.compile(r'^auto-duplex, +auto-speed$')
# full-duplex, 1000 Mb/s
# auto-duplex, auto-speed
# full-duplex, 1000 Mb/s, media type is 1G
# auto-duplex, auto-speed, media type is 10G
p10 = re.compile(r'^(?P<duplex_mode>[a-z]+)-duplex, *(?P<port_speed>[a-z0-9\-]+) *'
r'(?P<unit>[G|M]b/s)?(?:, +media +type +is (?P<media_type>\w+))?$')
# Beacon is turned off
p11 = re.compile(r'^Beacon *is *turned *(?P<beacon>[a-z]+)$')
# Auto-Negotiation is turned off
# Auto-Negotiation is turned off FEC mode is Auto
# Auto-Negotiation is turned on
# Auto-Negotiation is turned on FEC mode is Auto
p12 = re.compile(r'^Auto-Negotiation is turned (?P<auto_negotiate>(off|on))'
r'(?: *FEC mode is (?P<fec_mode>(Auto)))?$')
# Input flow-control is off, output flow-control is off
# Input flow-control is off, output flow-control is on
p13 = re.compile(r'^Input *flow-control *is *(?P<receive>(off|on)+),'
r' *output *flow-control *is *(?P<send>(off|on)+)$')
# Auto-mdix is turned off
p14 = re.compile(r'^Auto-mdix *is *turned *(?P<auto_mdix>[a-z]+)$')
# Switchport monitor is off
p15 = re.compile(r'^Switchport *monitor *is *(?P<switchport_monitor>[a-z]+)$')
# EtherType is 0x8100
p16 = re.compile(r'^EtherType *is *(?P<ethertype>[a-z0-9]+)$')
# Members in this channel: Eth1/15, Eth1/16
# Members in this channel: Eth1/28
p38 = re.compile(r'^Members +in +this +channel *: *'
r'(?P<port_channel_member_intfs>[\w\/\.\-\,\s]+)$')
# EEE (efficient-ethernet) : n/a
p17 = re.compile(r'^EEE *\(efficient-ethernet\) *:'
r' *(?P<efficient_ethernet>[A-Za-z\/]+)$')
# Last link flapped 00:07:28
# Last link flapped 15week(s) 5day(s)
p18 = re.compile(r'^Last *link *flapped'
r' *(?P<last_link_flapped>[\S ]+)$')
# Last clearing of "show interface" counters never
# Last clearing of "show interface" counters 00:15:42
# Last clearing of "show interface" counters 69w4d
p19 = re.compile(r'^Last +clearing +of +\"show interface\" '
r'+counters +(?P<last_clear_counters>[a-z0-9\:]+)$')
# 1 interface resets
p20 = re.compile(r'^(?P<interface_reset>[0-9]+) *interface'
r' *resets$')
# 1 minute input rate 0 bits/sec, 0 packets/sec
p21 = re.compile(r'^(?P<load_interval>[0-9\#]+)'
r' *(minute|second|minutes|seconds) *input *rate'
r' *(?P<in_rate>[0-9]+) *bits/sec,'
r' *(?P<in_rate_pkts>[0-9]+) *packets/sec$')
# 1 minute output rate 24 bits/sec, 0 packets/sec
p22 = re.compile(r'^(?P<load_interval>[0-9\#]+)'
r' *(minute|second|minutes|seconds) *output'
r' *rate *(?P<out_rate>[0-9]+)'
r' *bits/sec, *(?P<out_rate_pkts>[0-9]+)'
r' *packets/sec$')
# input rate 0 bps, 0 pps; output rate 0 bps, 0 pps
p23 = re.compile(r'^input *rate *(?P<in_rate_bps>[0-9]+) *bps,'
r' *(?P<in_rate_pps>[0-9]+) *pps; *output *rate'
r' *(?P<out_rate_bps>[0-9]+) *bps,'
r' *(?P<out_rate_pps>[0-9]+) *pps$')
# RX
# Rx
p23_1 = re.compile(r'^(?P<rx>(RX|Rx))$')
# 0 unicast packets 0 multicast packets 0 broadcast packets
p24 = re.compile(r'^(?P<in_unicast_pkts>[0-9]+) +unicast +packets'
r' +(?P<in_multicast_pkts>[0-9]+) +multicast +packets'
r' +(?P<in_broadcast_pkts>[0-9]+) +broadcast +packets$')
# 0 input packets 0 bytes
# 607382344 input packets 445986207 unicast packets 132485585 multicast packets
p25 = re.compile(r'^(?P<in_pkts>[0-9]+) +input +packets(?: '
r'+(?P<in_octets>[0-9]+) +bytes)?(?: +(?P<in_unicast_pkts>[0-9]+) '
r'+unicast +packets +(?P<in_multicast_pkts>[0-9]+) +multicast +packets)?$')
# 0 jumbo packets 0 storm suppression packets
# 1 jumbo packets 0 storm suppression bytes
p26 = re.compile(r'^(?P<in_jumbo_packets>[0-9]+) +jumbo +packets '
r'+(?P<in_storm_suppression>[0-9]+) +storm +suppression +(?P<type>(packets|bytes))$')
# 0 runts 0 giants 0 CRC/FCS 0 no buffer
# 0 runts 0 giants 0 CRC 0 no buffer
p27 = re.compile(r'^(?P<in_runts>[0-9]+) *runts'
r' *(?P<in_oversize_frame>[0-9]+) *giants'
r' *(?P<in_crc_errors>[0-9]+) *CRC(/FCS)?'
r' *(?P<in_no_buffer>[0-9]+) *no *buffer$')
# 0 input error 0 short frame 0 overrun 0 underrun 0 ignored
p28 = re.compile(r'^(?P<in_errors>[0-9]+) *input *error'
r' *(?P<in_short_frame>[0-9]+) *short *frame'
r' *(?P<in_overrun>[0-9]+) *overrun *(?P<in_underrun>[0-9]+)'
r' *underrun *(?P<in_ignored>[0-9]+) *ignored$')
# 0 watchdog 0 bad etype drop 0 bad proto drop 0 if down drop
p29 = re.compile(r'^(?P<in_watchdog>[0-9]+) *watchdog'
r' *(?P<in_bad_etype_drop>[0-9]+)'
r' *bad *etype *drop *(?P<in_unknown_protos>[0-9]+)'
r' *bad *proto'
r' *drop *(?P<in_if_down_drop>[0-9]+) *if *down *drop$')
# 0 input with dribble 0 input discard
p30 = re.compile(r'^(?P<in_with_dribble>[0-9]+) *input *with'
r' *dribble *(?P<in_discard>[0-9]+) *input *discard$')
# 0 Rx pause
p31 = re.compile(r'^(?P<in_mac_pause_frames>[0-9]+) *Rx *pause$')
# TX
p31_1 = re.compile(r'^(?P<tx>(TX|Tx))$')
# 0 unicast packets 0 multicast packets 0 broadcast packets
p32 = re.compile(r'^(?P<out_unicast_pkts>[0-9]+) *unicast *packets'
r' *(?P<out_multicast_pkts>[0-9]+) *multicast *packets'
r' *(?P<out_broadcast_pkts>[0-9]+) *broadcast *packets$')
# 0 output packets 0 bytes
p33 = re.compile(r'^(?P<out_pkts>[0-9]+) *output *packets'
r' *(?P<out_octets>[0-9]+) *bytes$')
# 0 jumbo packets
p34 = re.compile(r'^(?P<out_jumbo_packets>[0-9]+) *jumbo *packets$')
# 0 output error 0 collision 0 deferred 0 late collision
p35 = re.compile(r'^(?P<out_errors>[0-9]+) *output *error'
r' *(?P<out_collision>[0-9]+) *collision'
r' *(?P<out_deferred>[0-9]+) *deferred'
r' *(?P<out_late_collision>[0-9]+)'
r' *late *collision$')
# 0 lost carrier 0 no carrier 0 babble 0 output discard
p36 = re.compile(r'^(?P<out_lost_carrier>[0-9]+) *lost *carrier'
r' *(?P<out_no_carrier>[0-9]+) *no *carrier'
r' *(?P<out_babble>[0-9]+) *babble'
r' *(?P<out_discard>[0-9]+) *output *discard$')
# 0 Tx pause
p37 = re.compile(r'^(?P<out_mac_pause_frames>[0-9]+) *Tx *pause$')
# Members in this channel: Eth1/15, Eth1/16
# Members in this channel: Eth1/28
p38 = re.compile(r'^Members +in +this +channel *: *'
r'(?P<port_channel_member_intfs>[\w\/\.\-\,\s]+)$')
# 28910552 broadcast packets 63295517997 bytes
p39 = re.compile(r'^(?P<in_broadcast_pkts>[0-9]+) +broadcast +packets +(?P<in_octets>[0-9]+) +bytes$')
interface_dict = {}
rx = False
tx = False
for line in output.splitlines():
line = line.replace('\t', ' ')
line = line.strip()
# Ethernet2/1.10 is down (Administratively down)
# Vlan1 is down (Administratively down), line protocol is down, autostate enabled
# Vlan200 is down (VLAN/BD is down), line protocol is down, autostate enabled
# Vlan23 is administratively down (Administratively down), line protocol is down, autostate enabled
# Ethernet2/2 is up
# Ethernet1/10 is down (Link not connected)
# Ethernet1/3 is down (XCVR not inserted)
# Ethernet1/1 is down (DCX-No ACK in 100 PDUs)
m = p1.match(line)
if m:
group = m.groupdict()
interface = group['interface']
if interface not in interface_dict:
interface_dict[interface] = {}
interface_dict[interface]['port_channel'] = {}
interface_dict[interface]['port_channel']['port_channel_member'] = False
if group['link_state']:
interface_dict[interface]['link_state'] = group['link_state']
if 'oper_status' not in interface_dict[interface]:
interface_dict[interface]['oper_status'] = group['link_state']
if group['admin_1']:
interface_dict[interface]['enabled'] = False
elif group['admin_2']:
interface_dict[interface]['enabled'] = False
else:
interface_dict[interface]['enabled'] = True
if group['line_protocol']:
interface_dict[interface]['line_protocol'] = group['line_protocol']
if 'oper_status' not in interface_dict[interface]:
interface_dict[interface]['oper_status'] = group['line_protocol']
if group['autostate']:
interface_dict[interface]['autostate'] = True if group['autostate'] == 'enabled' else False
continue
# admin state is up
# admin state is up,
# admin state is up, Dedicated Interface
# admin state is up, Dedicated Interface, [parent interface is Ethernet2/1]
m = p2.match(line)
if m:
# admin_state
admin_state = m.groupdict()['admin_state']
interface_dict[interface]['admin_state'] = admin_state
if admin_state == 'up':
interface_dict[interface]['enabled'] = True
# dedicated_interface
if m.groupdict()['dedicated_intf']:
interface_dict[interface]['dedicated_interface'] = True
# parent_interface
if m.groupdict()['parent_intf']:
interface_dict[interface]['parent_interface'] = \
m.groupdict()['parent_intf']
continue
# Dedicated Interface
m = p2_1.match(line)
if m:
interface_dict[interface]['dedicated_interface'] = True
continue
# Belongs to Po1
m = p2_2.match(line)
if m:
port_channel_int = str(m.groupdict()['port_channel_int'])
if 'port_channel' not in interface_dict[interface]:
interface_dict[interface]['port_channel'] = {}
interface_dict[interface]['port_channel'] \
['port_channel_member'] = True
interface_dict[interface]['port_channel'] \
['port_channel_int'] = Common.convert_intf_name(port_channel_int)
continue
# Hardware: Ethernet, address: 5254.00ff.9c38 (bia 5254.00ff.9c38)
m = p3.match(line)
if m:
types = m.groupdict()['types']
mac_address = m.groupdict()['mac_address']
phys_address = m.groupdict()['phys_address']
interface_dict[interface]['types'] = types
interface_dict[interface] \
['mac_address'] = mac_address
interface_dict[interface] \
['phys_address'] = phys_address
continue
# Hardware is EtherSVI, address is 547f.ee6d.7d7c
m = p3_1.match(line)
if m:
types = m.groupdict()['types']
interface_dict[interface]['types'] = types
mac_address = m.groupdict()['mac_address']
interface_dict[interface] \
['mac_address'] = mac_address
continue
# Description: VLAN information Internet Address is 10.10.10.1/24
m = p4_1.match(line)
if m:
group = m.groupdict()
description = group['description']
interface_dict[interface]['description'] = description
ip = group['ip']
prefix_length = str(m.groupdict()['prefix_length'])
address = ip + '/' + prefix_length
interface_dict[interface].setdefault('ipv4', {})
add_dict = interface_dict[interface]['ipv4']. \
setdefault(address, {})
add_dict['ip'] = ip
add_dict['prefix_length'] = prefix_length
continue
# Description: desc
m = p4.match(line)
if m:
description = m.groupdict()['description']
interface_dict[interface]['description'] = description
continue
# Internet Address is 10.4.4.4/24 secondary tag 10
m = p5.match(line)
if m:
ip = m.groupdict()['ip']
prefix_length = str(m.groupdict()['prefix_length'])
secondary = m.groupdict()['secondary']
route_tag = m.groupdict()['route_tag']
# address = ipv4+prefix_length
address = ip + '/' + prefix_length
if 'ipv4' not in interface_dict[interface]:
interface_dict[interface]['ipv4'] = {}
if address not in interface_dict[interface]['ipv4']:
interface_dict[interface]['ipv4'][address] = {}
interface_dict[interface]['ipv4'][address] \
['ip'] = ip
interface_dict[interface]['ipv4'][address] \
['prefix_length'] = prefix_length
if secondary:
interface_dict[interface]['ipv4'][address] \
['secondary'] = True
if route_tag:
interface_dict[interface]['ipv4'][address] \
['route_tag'] = route_tag
continue
# MTU 1600 bytes, BW 768 Kbit, DLY 3330 usec
# MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec,
# MTU 1500 bytes, BW 1000000 Kbit
m = p6.match(line)
if m:
mtu = int(m.groupdict()['mtu'])
bandwidth = int(m.groupdict()['bandwidth'])
if m.groupdict()['delay']:
interface_dict[interface]['delay'] = int(m.groupdict()['delay'])
interface_dict[interface]['mtu'] = mtu
interface_dict[interface]['bandwidth'] = bandwidth
continue
# MTU 1500 bytes, BW 40000000 Kbit,, BW 40000000 Kbit, DLY 10 usec
m = p6_1.match(line)
if m:
mtu = int(m.groupdict()['mtu'])
bandwidth = int(m.groupdict()['bandwidth'])
interface_dict[interface]['mtu'] = mtu
interface_dict[interface]['bandwidth'] = bandwidth
interface_dict[interface]['delay'] = int(m.groupdict()['delay'])
continue
# reliability 255/255, txload 1/255, rxload 1/255
m = p7.match(line)
if m:
reliability = m.groupdict()['reliability']
txload = m.groupdict()['txload']
rxload = m.groupdict()['rxload']
interface_dict[interface]['reliability'] = reliability
interface_dict[interface]['txload'] = txload
interface_dict[interface]['rxload'] = rxload
continue
# Encapsulation 802.1Q Virtual LAN, Vlan ID 10, medium is broadcast
# Encapsulation 802.1Q Virtual LAN, Vlan ID 20, medium is p2p
# Encapsulation ARPA, medium is broadcast
m = p8.match(line)
if m:
encapsulation = m.groupdict()['encapsulation'].lower()
encapsulation = encapsulation.replace("802.1q virtual lan", "dot1q")
medium = m.groupdict()['medium']
if 'encapsulations' not in interface_dict[interface]:
interface_dict[interface]['encapsulations'] = {}
interface_dict[interface]['encapsulations'] \
['encapsulation'] = encapsulation
interface_dict[interface]['medium'] = medium
continue
m = p8_1.match(line)
if m:
encapsulation = m.groupdict()['encapsulation'].lower()
encapsulation = encapsulation.replace("802.1q virtual lan", "dot1q")
first_dot1q = str(m.groupdict()['first_dot1q'])
medium = m.groupdict()['medium']
if 'encapsulations' not in interface_dict[interface]:
interface_dict[interface]['encapsulations'] = {}
interface_dict[interface]['encapsulations'] \
['encapsulation'] = encapsulation
interface_dict[interface]['encapsulations'] \
['first_dot1q'] = first_dot1q
interface_dict[interface]['medium'] = medium
continue
# Encapsulation ARPA, loopback not set
m = p8_2.match(line)
if m:
encapsulation = m.groupdict()['encapsulation'].lower()
if 'encapsulations' not in interface_dict[interface]:
interface_dict[interface]['encapsulations'] = {}
interface_dict[interface]['encapsulations'] \
['encapsulation'] = encapsulation
continue
# Port mode is routed
m = p9.match(line)
if m:
port_mode = m.groupdict()['port_mode']
interface_dict[interface]['port_mode'] = port_mode
continue
# auto-duplex, auto-speed
m = p10_1.match(line)
if m:
# not caring for this line
continue
# full-duplex, 1000 Mb/s
# auto-duplex, auto-speed
# full-duplex, 1000 Mb/s, media type is 1G
# auto-duplex, auto-speed, media type is 10G
m = p10.match(line)
if m:
duplex_mode = m.groupdict()['duplex_mode'].lower()
port_speed = m.groupdict()['port_speed']
if m.groupdict()['media_type']:
interface_dict[interface]['media_type'] = m.groupdict()['media_type']
else:
media_type = None
interface_dict[interface]['duplex_mode'] = duplex_mode
interface_dict[interface]['port_speed'] = port_speed
if m.groupdict()['unit']:
interface_dict[interface]['port_speed_unit'] = m.groupdict()['unit']
continue
# Beacon is turned off
m = p11.match(line)
if m:
beacon = m.groupdict()['beacon']
interface_dict[interface]['beacon'] = beacon
continue
# Auto-Negotiation is turned off
m = p12.match(line)
if m:
auto_negotiation = m.groupdict()['auto_negotiate']
interface_dict[interface]['auto_negotiate'] = True if auto_negotiation == 'on' else False
if m.groupdict()['fec_mode']:
interface_dict[interface]['fec_mode'] = m.groupdict()['fec_mode']
continue
# Input flow-control is off, output flow-control is off
m = p13.match(line)
if m:
receive = m.groupdict()['receive']
send = m.groupdict()['send']
if 'flow_control' not in interface_dict[interface]:
interface_dict[interface]['flow_control'] = {}
interface_dict[interface]['flow_control']['receive'] = True if receive == 'on' else False
interface_dict[interface]['flow_control']['send'] = True if send == 'on' else False
continue
# Auto-mdix is turned off
m = p14.match(line)
if m:
auto_mdix = m.groupdict()['auto_mdix']
interface_dict[interface]['auto_mdix'] = auto_mdix
continue
# Switchport monitor is off
m = p15.match(line)
if m:
switchport_monitor = m.groupdict()['switchport_monitor']
interface_dict[interface]['switchport_monitor'] = switchport_monitor
continue
# EtherType is 0x8100
m = p16.match(line)
if m:
ethertype = m.groupdict()['ethertype']
interface_dict[interface]['ethertype'] = ethertype
continue
# Members in this channel: Eth1/15, Eth1/16
# Members in this channel: Eth1/28
m = p38.match(line)
if m:
port_channel_member_intfs = m.groupdict()['port_channel_member_intfs']
if port_channel_member_intfs:
if 'port_channel' not in interface_dict[interface]:
interface_dict[interface]['port_channel'] = {}
interface_dict[interface]['port_channel']['port_channel_member'] = True
interface_dict[interface]['port_channel']['port_channel_member_intfs'] =\
[Common.convert_intf_name(item) for item in port_channel_member_intfs.split(',')]
continue
# EEE (efficient-ethernet) : n/a
m = p17.match(line)
if m:
efficient_ethernet = m.groupdict()['efficient_ethernet']
interface_dict[interface]['efficient_ethernet'] = efficient_ethernet
continue
# Last link flapped 00:07:28
m = p18.match(line)
if m:
last_link_flapped = m.groupdict()['last_link_flapped']
interface_dict[interface]['last_link_flapped'] \
= last_link_flapped
continue
# Last clearing of "show interface" counters never
m = p19.match(line)
if m:
last_clear = m.groupdict()['last_clear_counters']
interface_dict[interface]['last_clear_counters'] = last_clear
continue
# 1 interface resets
m = p20.match(line)
if m:
interface_reset = int(m.groupdict()['interface_reset'])
interface_dict[interface]['interface_reset'] = interface_reset
continue
# 1 minute input rate 0 bits/sec, 0 packets/sec
m = p21.match(line)
if m:
load_interval = int(m.groupdict()['load_interval'])
in_rate = int(m.groupdict()['in_rate'])
in_rate_pkts = int(m.groupdict()['in_rate_pkts'])
if 'counters' not in interface_dict[interface]:
interface_dict[interface]['counters'] = {}
if 'rate' not in interface_dict[interface]['counters']:
interface_dict[interface]['counters']['rate'] = {}
interface_dict[interface]['counters']['rate'] \
['load_interval'] = load_interval
interface_dict[interface]['counters']['rate'] \
['in_rate'] = in_rate
interface_dict[interface]['counters']['rate'] \
['in_rate_pkts'] = in_rate_pkts
continue
# 1 minute output rate 24 bits/sec, 0 packets/sec
m = p22.match(line)
if m:
load_interval = int(m.groupdict()['load_interval'])
out_rate = int(m.groupdict()['out_rate'])
out_rate_pkts = int(m.groupdict()['out_rate_pkts'])
interface_dict[interface]['counters']['rate'] \
['load_interval'] = load_interval
interface_dict[interface]['counters']['rate'] \
['out_rate'] = out_rate
interface_dict[interface]['counters']['rate'] \
['out_rate_pkts'] = out_rate_pkts
continue
# input rate 0 bps, 0 pps; output rate 0 bps, 0 pps
m = p23.match(line)
if m:
in_rate_bps = int(m.groupdict()['in_rate_bps'])
in_rate_pps = int(m.groupdict()['in_rate_pps'])
out_rate_bps = int(m.groupdict()['out_rate_bps'])
out_rate_pps = int(m.groupdict()['out_rate_pps'])
if 'counters' not in interface_dict[interface]:
interface_dict[interface]['counters'] = {}
if 'rate' not in interface_dict[interface]['counters']:
interface_dict[interface]['counters']['rate'] = {}
interface_dict[interface]['counters']['rate'] \
['in_rate_bps'] = in_rate_bps
interface_dict[interface]['counters']['rate'] \
['in_rate_pps'] = in_rate_pps
interface_dict[interface]['counters']['rate'] \
['out_rate_bps'] = out_rate_bps
interface_dict[interface]['counters']['rate'] \
['out_rate_pps'] = out_rate_pps
continue
# RX
# Rx
m = p23_1.match(line)
if m:
rx = m.groupdict()['rx']
if 'counters' not in interface_dict[interface]:
interface_dict[interface]['counters'] = {}
interface_dict[interface]['counters']['rx'] = True
continue
if rx:
# 0 unicast packets 0 multicast packets 0 broadcast packets
m = p24.match(line)
if m:
in_unicast_pkts = int(m.groupdict()['in_unicast_pkts'])
in_multicast_pkts = int(m.groupdict()['in_multicast_pkts'])
in_broadcast_pkts = int(m.groupdict()['in_broadcast_pkts'])
interface_dict[interface]['counters']['in_unicast_pkts'] = in_unicast_pkts
interface_dict[interface]['counters']['in_multicast_pkts'] = in_multicast_pkts
interface_dict[interface]['counters']['in_broadcast_pkts'] = in_broadcast_pkts
try:
interface_dict[interface]['counters']['last_clear'] = last_clear
except Exception:
pass
continue
# 0 input packets 0 bytes
# 607382344 input packets 445986207 unicast packets 132485585 multicast packets
m = p25.match(line)
if m:
group = m.groupdict()
if 'counters' not in interface_dict[interface]:
interface_dict[interface]['counters'] = {}
interface_dict[interface]['counters']['in_pkts'] = int(group['in_pkts'])
if group['in_octets']:
interface_dict[interface]['counters']['in_octets'] = int(group['in_octets'])
if group['in_unicast_pkts']:
interface_dict[interface]['counters']['in_unicast_pkts'] = int(group['in_unicast_pkts'])
if group['in_multicast_pkts']:
interface_dict[interface]['counters']['in_multicast_pkts'] = int(group['in_multicast_pkts'])
continue
# 28910552 broadcast packets 63295517997 bytes
m = p39.match(line)
if m:
in_octets = int(m.groupdict()['in_octets'])
interface_dict[interface]['counters']['in_octets'] = in_octets
in_broadcast_pkts = int(m.groupdict()['in_broadcast_pkts'])
interface_dict[interface]['counters']['in_broadcast_pkts'] = in_broadcast_pkts
# 0 jumbo packets 0 storm suppression packets
m = p26.match(line)
if m:
in_storm_suppression = int(m.groupdict()['in_storm_suppression'])
if m.groupdict()['type'] == 'packets':