| author | "Tomas Zeman <tzeman@volny.cz>" |
| Thu, 26 Nov 2009 09:29:42 +0100 | |
| changeset 12 | 0b509f26f4d3 |
| parent 11 | c170b1da9b6e |
| child 13 | 30f4c4346810 |
| permissions | -rw-r--r-- |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
1 |
# Grammar for Cisco devices |
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
2 |
# Configuration is expected to be preprocessed via following command: |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
3 |
# perl -ne '/(^\s*)(\S.*)$/; print length($1)." $2\n"' |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
4 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
5 |
#<autotree> |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
6 |
{ # perl code follows
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
7 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
8 |
$::res = {};
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
9 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
10 |
# Returns pointer to context hasref as specified by ctx stack. |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
11 |
# @param ctx_path array of ctx stack. |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
12 |
sub ctx {
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
13 |
my @ctx_path = @_; |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
14 |
my $ptr = $::res; |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
15 |
foreach my $part (@ctx_path) {
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
16 |
$ptr->{$part} = {} unless exists ($ptr->{$part});
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
17 |
$ptr = $ptr->{$part};
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
18 |
} |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
19 |
return $ptr; |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
20 |
} |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
21 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
22 |
} # end of perl code |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
23 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
24 |
file: <skip: qr/[^\S\n]*/> # Ignore non-newline whitespace |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
25 |
line(s) eofile |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
26 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
27 |
line: s_controller |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
28 |
| s_interface |
| 12 | 29 |
| s_vrf |
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
30 |
| indent comment |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
31 |
| indent cmdline |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
32 |
| indent emptyline |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
33 |
| <error> |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
34 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
35 |
emptyline: eol |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
36 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
37 |
comment: /!.*/ eol |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
38 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
39 |
cmdline: l_hostname eol |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
40 |
| l_hash eol |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
41 |
| word(s) eol |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
42 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
43 |
word: /[0-9a-zA-Z:\/_\#\"\.,+<>()&{}-]+/
|
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
44 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
45 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
46 |
type: /\w+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
47 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
48 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
49 |
num: /\d+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
50 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
51 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
52 |
indent: /\d+/ |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
53 |
{ $item[1] }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
54 |
|
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
55 |
range: /\d+/"-"/\d+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
56 |
{ { from => $item[1], to => $item[3] } }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
57 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
58 |
keyword: /[\w-]+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
59 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
60 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
61 |
identifier: /[0-9a-zA-Z:_-]+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
62 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
63 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
64 |
quoted_text: <perl_quotelike> |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
65 |
{ $item[1][2] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
66 |
| /[0-9a-zA-Z:\/_\#\"\.,-]+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
67 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
68 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
69 |
value: /[0-9a-zA-Z:\/_\#\"\.,-]+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
70 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
71 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
72 |
eofile: /^\Z/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
73 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
74 |
eol: /\n/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
75 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
76 |
rest_of_line: word(s) |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
77 |
| eol |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
78 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
79 |
# section |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
80 |
section: cmdline(s) "!" |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
81 |
{ print "section\n"; }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
82 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
83 |
l_section: /[1-9]/ word(s) eol |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
84 |
| /[1-9]/ "!" eol |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
85 |
| /[1-9]/ eol |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
86 |
| <error> |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
87 |
|
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
88 |
# Lines w/ hash (passwd, secret etc) |
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
89 |
l_hash: word(s) /\S+/ word(s) |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
90 |
| word(s) /\S+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
91 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
92 |
# Hostname |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
93 |
l_hostname: "hostname" identifier |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
94 |
{ $::res->{hostname} = $item{identifier} }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
95 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
96 |
# Description |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
97 |
l_description: "description" /[^\n]+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
98 |
{ $arg{ctx}->{description} = $item[2] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
99 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
100 |
# controller section |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
101 |
controller_num: /\d+\/\d+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
102 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
103 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
104 |
s_controller: "0" "controller" type controller_num eol s_controller_l[ctx => ctx('controller', $item{controller_num}) ](s) "0" "!" eol
|
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
105 |
{ $::res->{controller}->{$item{controller_num}}->{type} = $item{type} }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
106 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
107 |
s_controller_l: "1" s_controller_content[ctx => $arg{ctx}] eol
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
108 |
| l_section |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
109 |
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
110 |
s_controller_content: l_description[ctx => $arg{ctx}]
|
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
111 |
| "channel-group" num "timeslots" range |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
112 |
{ $arg{ctx}->{"channel-group"}->{$item{num}}->{ts} = $item{range} }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
113 |
| "channel-group" num "unframed" |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
114 |
{ $arg{ctx}->{"channel-group"}->{$item{num}}->{unframed} = 1 }
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
115 |
| "framing" keyword |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
116 |
{ $arg{ctx}->{framing} = $item{keyword} }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
117 |
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
118 |
# Vlan range |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
119 |
vlan_s_range: /\d+/"-"/\d+/ |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
120 |
{
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
121 |
for (my $i = $item[1]; $i <= $item[3]; $i++) {
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
122 |
$arg{ctx}->{$arg{key}}->{$i} = 1; }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
123 |
} |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
124 |
| /\d+/ |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
125 |
{ $arg{ctx}->{$arg{key}}->{$item[1]} = 1 }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
126 |
vlan_range: vlan_s_range","vlan_range |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
127 |
| vlan_s_range |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
128 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
129 |
# interface section |
| 12 | 130 |
iface_name: /\w+(-\w+)?\d+[0-9\/\.:]*/ |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
131 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
132 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
133 |
s_interface: "0" "interface" iface_name /\S*/ eol s_interface_l[ctx => ctx("interface", $item{iface_name}) ](s) "0" "!" eol
|
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
134 |
{
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
135 |
$::res->{interface}->{$item{iface_name}}->{type} = $item[4]
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
136 |
if length($item[4]) > 0 |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
137 |
} |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
138 |
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
139 |
ip: /\d+\.\d+\.\d+\.\d+/ |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
140 |
{ $item[1] }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
141 |
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
142 |
s_interface_l: "1" s_interface_content[ctx => $arg{ctx}] eol
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
143 |
| l_section |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
144 |
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
145 |
s_interface_content: l_description[ctx => $arg{ctx}]
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
146 |
| /(no)?/ "shutdown" |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
147 |
{ $arg{ctx}->{shutdown} = ($item[1] eq 'no') ? 0 : 1 }
|
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
148 |
| "ip" "address" ip ip |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
149 |
{ $arg{ctx}->{ip} = $item[3]; $arg{ctx}->{mask} = $item[3] }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
150 |
| "encapsulation" keyword /\S*/ |
|
10
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
151 |
{
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
152 |
$arg{ctx}->{encap} = $item[2];
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
153 |
$arg{ctx}->{encap_param} = $item[3] if length($item[3]) > 0
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
154 |
} |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
155 |
| "frame-relay" keyword keyword |
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
156 |
{ $arg{ctx}->{"frame-relay"} = {type => $item[2], value => $item[3]} }
|
|
91148603fd70
added cisco.grammar: parse hostname, controllers, interfaces
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff
changeset
|
157 |
| "bandwidth" num |
|
11
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
158 |
{ $arg{ctx}->{bandwidth} = $item{num} }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
159 |
| "ip" "vrf" "forwarding" word |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
160 |
{ $arg{ctx}->{"ip-vrf-fwd"} = $item{word} }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
161 |
| "switchport" "mode" /access|trunk/ |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
162 |
{ $arg{ctx}->{"switchport-mode"} = $item[3] }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
163 |
| "switchport" "access" "vlan" num |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
164 |
{ $arg{ctx}->{vlan} = $item{num} }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
165 |
| "switchport" "trunk" "encapsulation" keyword |
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
166 |
{ $arg{ctx}->{"trunk-encap"} = $item{keyword} }
|
|
c170b1da9b6e
cisco.grammar: refactored to use indentation markers fro proper in-section parsing; more controller, interface properties
"Tomas Zeman <tzeman@volny.cz>"
parents:
10
diff
changeset
|
167 |
| "switchport" "trunk" "allowed" "vlan" vlan_range[ctx => $arg{ctx}, key => "vlan"]
|
| 12 | 168 |
| "channel-group" num "mode" keyword |
169 |
{ $arg{ctx}->{"channel-group"}->{$item{num}}->{mode} = $item{keyword} }
|
|
170 |
| "ip" "vrf" "forwarding" word |
|
171 |
{ $arg{ctx}->{"ip-vrf-fwd"} = $item{word} }
|
|
172 |
||
173 |
# vrf section |
|
174 |
s_vrf: "0" "ip" "vrf" keyword eol s_vrf_l[ctx => ctx("vrf", $item{keyword}) ](s) "0" "!" eol
|
|
175 |
||
176 |
s_vrf_l: "1" s_vrf_content[ctx => $arg{ctx}] eol
|
|
177 |
| l_section |
|
178 |
||
179 |
rd_val: /\d+:\d+/ |
|
180 |
{ $item[1] }
|
|
181 |
||
182 |
s_vrf_content: l_description[ctx => $arg{ctx}]
|
|
183 |
| "rd" rd_val |
|
184 |
{ $arg{ctx}->{rd} = $item{rd_val} }
|
|
185 |
| "export" "map" keyword |
|
186 |
{ $arg{ctx}->{"export-map"} = $item{keyword} }
|
|
187 |
| "route-target" /export|import/ rd_val |
|
188 |
{
|
|
189 |
$arg{ctx}->{"route-target"}->{$item[2]} = []
|
|
190 |
unless exists $arg{ctx}->{"route-target"}->{$item[2]};
|
|
191 |
push @{$arg{ctx}->{"route-target"}->{$item[2]}}, $item{rd_val};
|
|
192 |
} |
|
193 |