line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::Abbrev; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
29892
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
195
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Cisco::Abbrev - Translate to/from Cisco Interface Abbreviations |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.03 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This module converts between Cisco canonical interface names |
22
|
|
|
|
|
|
|
(i.e. GigabitEthernet0/1) and the abbreviated forms often output by their |
23
|
|
|
|
|
|
|
devices (i.e. Gi0/1). |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Cisco::Abbrev; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $long = cisco_long_int('Gi0/1'); ## $long='GigabitEthernet0/1'; |
28
|
|
|
|
|
|
|
my $short = cisco_abbrev_int('GigabitEthernet0/1'); ## $short='Gi0/1'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
################################################################# |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
2
|
|
12
|
use base 'Exporter'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1169
|
|
35
|
|
|
|
|
|
|
our @EXPORT = qw( cisco_abbrev_int cisco_long_int ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our %LONG = ( |
38
|
|
|
|
|
|
|
'Fa' => 'FastEthernet', |
39
|
|
|
|
|
|
|
'Gi' => 'GigabitEthernet', |
40
|
|
|
|
|
|
|
'Te' => 'TenGigabitEthernet', |
41
|
|
|
|
|
|
|
'Et' => 'Ethernet', |
42
|
|
|
|
|
|
|
'Eth' => 'Ethernet', |
43
|
|
|
|
|
|
|
'Vl' => 'Vlan', |
44
|
|
|
|
|
|
|
'FD' => 'Fddi', |
45
|
|
|
|
|
|
|
'PortCh' => 'Port-channel', |
46
|
|
|
|
|
|
|
'Po' => 'Port-channel', |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
'Tu' => 'Tunnel', |
49
|
|
|
|
|
|
|
'Lo' => 'Loopback', |
50
|
|
|
|
|
|
|
'Vi' => 'Virtual-Access', |
51
|
|
|
|
|
|
|
'Vt' => 'Virtual-Template', |
52
|
|
|
|
|
|
|
'EO' => 'EOBC', |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
'Se' => 'Serial', |
55
|
|
|
|
|
|
|
'PO' => 'POS', |
56
|
|
|
|
|
|
|
'PosCh' => 'Pos-channel', |
57
|
|
|
|
|
|
|
'Mu' => 'Multilink', |
58
|
|
|
|
|
|
|
'AT' => 'ATM', |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
'Async' => 'Async', |
61
|
|
|
|
|
|
|
'Group-Async' => 'Group-Async', |
62
|
|
|
|
|
|
|
'MFR' => 'MFR', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
our %ABBREV = reverse %LONG; |
66
|
|
|
|
|
|
|
$ABBREV{'Port-channel'} = 'Po'; ## ambiguous |
67
|
|
|
|
|
|
|
$ABBREV{'Ethernet' } = 'Et'; ## ambiguous |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
## valid interface names and abbreviations match this regexp. |
70
|
|
|
|
|
|
|
our $VALID = qr(^[A-Z][-A-Za-z\d/:.]+$)o; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
################################################################# |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 FUNCTIONS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 cisco_long_int($abbrev) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns the canonical interface name for an abbreviated form. If the |
79
|
|
|
|
|
|
|
interface type is not recognized, returns undef. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
46
|
|
|
46
|
1
|
2173
|
sub cisco_long_int { _convert(shift, \%LONG) } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
################################################################# |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 cisco_abbrev_int($long) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the abbreviated form of the canonical interface name. If the |
90
|
|
|
|
|
|
|
interface type is not recognized, returns undef. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
36
|
|
|
36
|
1
|
11818
|
sub cisco_abbrev_int { _convert(shift, \%ABBREV) } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
################################################################# |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _convert { |
99
|
82
|
|
|
82
|
|
126
|
my ($int, $lookup) = @_; |
100
|
|
|
|
|
|
|
|
101
|
82
|
100
|
100
|
|
|
701
|
return undef unless (defined $int and $int =~ $VALID); |
102
|
|
|
|
|
|
|
|
103
|
74
|
|
|
|
|
478
|
my ($type, $pos) = $int =~ qr/^(\D+)(.*)/o; |
104
|
74
|
50
|
|
|
|
269
|
my $other = $lookup->{$type} or return undef; |
105
|
74
|
|
|
|
|
355
|
return $other.$pos; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
################################################################# |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 OTHER INTERFACE TYPES |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
If you find any interface types that this module does not handle |
113
|
|
|
|
|
|
|
correctly, please notify the author via CPAN's request system: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
kevin brintnall, C<< >> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Copyright 2008 kevin brintnall, all rights reserved. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
126
|
|
|
|
|
|
|
under the same terms as Perl itself. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; # End of Cisco::Abbrev |