| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 21 Aug 2012 12:10:00 +0200 | |
| changeset 38 | d925a22bbcf3 |
| parent 37 | 7174a6414069 |
| child 39 | b39ab9900b24 |
| permissions | -rw-r--r-- |
| 36 | 1 |
# Grammar for OneAccess devices |
2 |
# Configuration is expected to be preprocessed via following command: |
|
3 |
# perl -ne '/(^\s*)(\S.*)$/; print length($1)." $2\n"' |
|
4 |
# |
|
5 |
# Copyright (c) 2012 Tomas Zeman <tzeman@volny.cz> |
|
6 |
# All rights reserved. |
|
7 |
# |
|
8 |
# Redistribution and use in source and binary forms, with or without |
|
9 |
# modification, are permitted providing that the following conditions |
|
10 |
# are met: |
|
11 |
# 1. Redistributions of source code must retain the above copyright |
|
12 |
# notice, this list of conditions and the following disclaimer. |
|
13 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
14 |
# notice, this list of conditions and the following disclaimer in the |
|
15 |
# documentation and/or other materials provided with the distribution. |
|
16 |
# |
|
17 |
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
18 |
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
21 |
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
22 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
23 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
24 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
25 |
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
26 |
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
||
30 |
{ # perl code follows
|
|
31 |
||
32 |
$::res = {};
|
|
33 |
||
34 |
# Returns pointer to context hashref as specified by ctx stack. |
|
35 |
# @param ctx_path array of ctx stack. |
|
36 |
sub ctx {
|
|
37 |
return ctx_rel($::res, @_); |
|
38 |
} |
|
39 |
||
40 |
# Returns pointer to context hashref as specified by ctx stack, |
|
41 |
# relative to the supplied ctx pointer. |
|
42 |
# @param ptr current ctx pointer from which ctx build starts. |
|
43 |
# @param ctx_path array of ctx stack. |
|
44 |
sub ctx_rel {
|
|
45 |
my $ptr = shift; |
|
46 |
my @ctx_path = @_; |
|
47 |
foreach my $part (@ctx_path) {
|
|
48 |
$ptr->{$part} = {} unless exists ($ptr->{$part});
|
|
49 |
$ptr = $ptr->{$part};
|
|
50 |
} |
|
51 |
return $ptr; |
|
52 |
} |
|
53 |
||
54 |
} # end of perl code |
|
55 |
||
56 |
file: <skip: qr/[^\S\n]*/> # Ignore non-newline whitespace |
|
57 |
line(s) eofile |
|
58 |
||
59 |
line: s_controller |
|
60 |
| s_interface |
|
61 |
| l_vrf |
|
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
62 |
| l_sntp |
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
63 |
| l_syslog |
| 36 | 64 |
| indent comment |
65 |
| indent cmdline |
|
66 |
| indent emptyline |
|
67 |
| <error> |
|
68 |
||
69 |
emptyline: eol |
|
70 |
||
71 |
comment: /!.*/ eol |
|
72 |
||
73 |
cmdline: l_hostname eol |
|
74 |
| l_hash eol |
|
75 |
| word(s) eol |
|
76 |
||
77 |
word: /\S+/ # any non-space |
|
78 |
{ $item[1] }
|
|
79 |
||
80 |
type: /\w+/ |
|
81 |
{ $item[1] }
|
|
82 |
||
83 |
num: /\d+/ |
|
84 |
{ $item[1] }
|
|
85 |
||
86 |
indent: /\d+/ |
|
87 |
{ $item[1] }
|
|
88 |
||
89 |
range: /\d+/"-"/\d+/ |
|
90 |
{ { from => $item[1], to => $item[3] } }
|
|
91 |
| /\d+/ |
|
92 |
{ { from => $item[1], to => $item[1] } }
|
|
93 |
||
94 |
keyword: /[\w-]+/ |
|
95 |
{ $item[1] }
|
|
96 |
||
97 |
identifier: /[0-9a-zA-Z:_-]+/ |
|
98 |
{ $item[1] }
|
|
99 |
||
100 |
quoted_text: <perl_quotelike> |
|
101 |
{ $item[1][2] }
|
|
102 |
| /[0-9a-zA-Z:\/_\#\"\.,-]+/ |
|
103 |
{ $item[1] }
|
|
104 |
||
105 |
value: /[0-9a-zA-Z:\/_\#\"\.,-]+/ |
|
106 |
{ $item[1] }
|
|
107 |
||
108 |
eofile: /^\Z/ |
|
109 |
||
110 |
eol: /\n/ |
|
111 |
||
112 |
rest_of_line: word(s) |
|
113 |
| eol |
|
114 |
||
115 |
# section |
|
116 |
section: cmdline(s) "!" |
|
117 |
{ print "section\n"; }
|
|
118 |
||
119 |
l_section: /[1-9]/ word(s) eol |
|
120 |
| /[1-9]/ "exit" eol |
|
121 |
| /[1-9]/ eol |
|
122 |
| <error> |
|
123 |
||
124 |
# Lines w/ hash (passwd, secret etc) |
|
125 |
l_hash: word(s) /\S+/ word(s) |
|
126 |
| word(s) /\S+/ |
|
127 |
||
128 |
# Hostname |
|
129 |
l_hostname: "hostname" identifier |
|
130 |
{ $::res->{hostname} = $item{identifier} }
|
|
131 |
||
132 |
# Description |
|
133 |
l_description: "description" /[^\n]+/ |
|
134 |
{ $arg{ctx}->{description} = $item[2] }
|
|
135 |
||
136 |
# controller section |
|
137 |
controller_num: /\d+/ |
|
138 |
{ $item[1] }
|
|
139 |
||
140 |
s_controller: "0" "controller" type controller_num eol s_controller_l[ctx => ctx('controller', $item{controller_num}) ](s) "0" "exit" eol
|
|
141 |
{ $::res->{controller}->{$item{controller_num}}->{type} = $item{type} }
|
|
142 |
||
143 |
s_controller_l: "1" s_controller_content[ctx => $arg{ctx}] eol
|
|
144 |
| s_dsl_group[ctx => $arg{ctx}]
|
|
145 |
| l_section |
|
146 |
||
147 |
s_controller_content: l_description[ctx => $arg{ctx}]
|
|
148 |
| "framing" keyword |
|
149 |
{ $arg{ctx}->{framing} = $item{keyword} }
|
|
150 |
||
151 |
s_dsl_group: "2" "dsl-group" num eol s_dsl_group_l[ctx => ctx_rel($arg{ctx}, 'dsl-group', $item{num})](s) "2" "exit" eol
|
|
152 |
||
153 |
s_dsl_group_l: indent s_dsl_group_content[ctx => $arg{ctx}] eol
|
|
154 |
||
155 |
s_dsl_group_content: "autoconfig" |
|
156 |
{ $arg{ctx}->{autoconfig} = 1 }
|
|
157 |
| "execute" |
|
158 |
{ $arg{ctx}->{execute} = 1 }
|
|
159 |
| "caplist" identifier |
|
160 |
{ $arg{ctx}->{caplist} = $item{identifier} }
|
|
161 |
| "vendorspecoctets" num |
|
162 |
{ $arg{ctx}->{vendorspecoctets} = $item{num} }
|
|
163 |
||
164 |
# interface section |
|
165 |
iface_type: /[0-9a-zA-Z:-]+/ |
|
166 |
{ $item[1] }
|
|
167 |
||
168 |
iface_num: /\d+([\.\/]\d+)*/ |
|
169 |
{ $item[1] }
|
|
170 |
||
171 |
s_interface: "0" "interface" iface_type iface_num /\S*/ eol s_interface_l[ctx => ctx("interface", $item{iface_type}.":".$item{iface_num}) ](s) "0" "exit" eol
|
|
172 |
{
|
|
173 |
my $id = $item{iface_type}.":".$item{iface_num};
|
|
174 |
$::res->{interface}->{$id}->{type} = $item{iface_type};
|
|
175 |
$::res->{interface}->{$id}->{num} = $item{iface_num}
|
|
176 |
} |
|
177 |
||
178 |
ip: /\d+\.\d+\.\d+\.\d+/ |
|
179 |
{ $item[1] }
|
|
180 |
||
181 |
s_interface_l: "1" s_interface_content[ctx => $arg{ctx}] eol
|
|
182 |
| l_section |
|
183 |
||
184 |
s_interface_content: l_description[ctx => $arg{ctx}]
|
|
185 |
| /(no)?/ "shutdown" |
|
186 |
{ $arg{ctx}->{shutdown} = ($item[1] eq 'no') ? 0 : 1 }
|
|
187 |
| "ip" "address" ip ip |
|
188 |
{ $arg{ctx}->{ip} = $item[3]; $arg{ctx}->{mask} = $item[4] }
|
|
189 |
| "encapsulation" keyword /\S*/ |
|
190 |
{
|
|
191 |
$arg{ctx}->{encap} = $item[2];
|
|
192 |
$arg{ctx}->{encap_param} = $item[3] if length($item[3]) > 0
|
|
193 |
} |
|
194 |
| "bandwidth" num |
|
195 |
{ $arg{ctx}->{bandwidth} = $item{num} }
|
|
196 |
| "speed" num |
|
197 |
{ $arg{ctx}->{speed} = $item{num} }
|
|
198 |
| "ip" "vrf" "forwarding" word |
|
199 |
{ $arg{ctx}->{"ip-vrf-fwd"} = $item{word} }
|
|
200 |
| "bridge-group" num |
|
201 |
{ $arg{ctx}->{"bridge-group"} = $item{num} }
|
|
202 |
| "framing" keyword |
|
203 |
{ $arg{ctx}->{framing} = $item{keyword} }
|
|
204 |
||
205 |
# vrf |
|
206 |
l_vrf: "0" "ip" "vrf" keyword eol |
|
207 |
{ $::res->{"ip-vrf"} = $item{keyword} }
|
|
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
208 |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
209 |
via_iface: iface_type iface_num |
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
210 |
{
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
211 |
$arg{ctx}->{interface} = {
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
212 |
type => $item{iface_type},
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
213 |
num => $item{iface_num}
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
214 |
}; |
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
215 |
} |
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
216 |
| "" |
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
217 |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
218 |
# sntp |
|
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
219 |
l_sntp: "0" "sntp" "server" ip via_iface[ctx => ctx('sntp-server', $item{ip})] eol
|
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
220 |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
221 |
l_syslog: "0" "syslog" "server" ip num via_iface[ctx => ctx('syslog', 'server', $item{ip})] eol
|
|
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
222 |
| "0" "logging" "syslog" /\w+/ eol |
|
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
223 |
{ $::res->{syslog}->{level} = $item[4]; }
|
|
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
224 |