| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 21 Aug 2012 13:01:44 +0200 | |
| changeset 41 | 7a33198be930 |
| parent 40 | dd3906ea5dc6 |
| child 42 | 89e94dd37556 |
| 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 |
|
| 40 | 61 |
| s_voice_port |
| 41 | 62 |
| s_dial_peer |
| 36 | 63 |
| l_vrf |
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
64 |
| l_sntp |
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
65 |
| l_syslog |
| 36 | 66 |
| indent comment |
67 |
| indent cmdline |
|
68 |
| indent emptyline |
|
69 |
| <error> |
|
70 |
||
71 |
emptyline: eol |
|
72 |
||
73 |
comment: /!.*/ eol |
|
74 |
||
75 |
cmdline: l_hostname eol |
|
76 |
| l_hash eol |
|
77 |
| word(s) eol |
|
78 |
||
79 |
word: /\S+/ # any non-space |
|
80 |
{ $item[1] }
|
|
81 |
||
82 |
type: /\w+/ |
|
83 |
{ $item[1] }
|
|
84 |
||
85 |
num: /\d+/ |
|
86 |
{ $item[1] }
|
|
87 |
||
88 |
indent: /\d+/ |
|
89 |
{ $item[1] }
|
|
90 |
||
91 |
range: /\d+/"-"/\d+/ |
|
92 |
{ { from => $item[1], to => $item[3] } }
|
|
93 |
| /\d+/ |
|
94 |
{ { from => $item[1], to => $item[1] } }
|
|
95 |
||
96 |
keyword: /[\w-]+/ |
|
97 |
{ $item[1] }
|
|
98 |
||
99 |
identifier: /[0-9a-zA-Z:_-]+/ |
|
100 |
{ $item[1] }
|
|
101 |
||
102 |
quoted_text: <perl_quotelike> |
|
103 |
{ $item[1][2] }
|
|
104 |
| /[0-9a-zA-Z:\/_\#\"\.,-]+/ |
|
105 |
{ $item[1] }
|
|
106 |
||
107 |
value: /[0-9a-zA-Z:\/_\#\"\.,-]+/ |
|
108 |
{ $item[1] }
|
|
109 |
||
110 |
eofile: /^\Z/ |
|
111 |
||
112 |
eol: /\n/ |
|
113 |
||
114 |
rest_of_line: word(s) |
|
115 |
| eol |
|
116 |
||
117 |
# section |
|
118 |
section: cmdline(s) "!" |
|
119 |
{ print "section\n"; }
|
|
120 |
||
121 |
l_section: /[1-9]/ word(s) eol |
|
122 |
| /[1-9]/ "exit" eol |
|
123 |
| /[1-9]/ eol |
|
124 |
| <error> |
|
125 |
||
126 |
# Lines w/ hash (passwd, secret etc) |
|
127 |
l_hash: word(s) /\S+/ word(s) |
|
128 |
| word(s) /\S+/ |
|
129 |
||
130 |
# Hostname |
|
131 |
l_hostname: "hostname" identifier |
|
132 |
{ $::res->{hostname} = $item{identifier} }
|
|
133 |
||
134 |
# Description |
|
135 |
l_description: "description" /[^\n]+/ |
|
136 |
{ $arg{ctx}->{description} = $item[2] }
|
|
137 |
||
138 |
# controller section |
|
139 |
controller_num: /\d+/ |
|
140 |
{ $item[1] }
|
|
141 |
||
142 |
s_controller: "0" "controller" type controller_num eol s_controller_l[ctx => ctx('controller', $item{controller_num}) ](s) "0" "exit" eol
|
|
143 |
{ $::res->{controller}->{$item{controller_num}}->{type} = $item{type} }
|
|
144 |
||
145 |
s_controller_l: "1" s_controller_content[ctx => $arg{ctx}] eol
|
|
146 |
| s_dsl_group[ctx => $arg{ctx}]
|
|
147 |
| l_section |
|
148 |
||
149 |
s_controller_content: l_description[ctx => $arg{ctx}]
|
|
150 |
| "framing" keyword |
|
151 |
{ $arg{ctx}->{framing} = $item{keyword} }
|
|
152 |
||
153 |
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
|
|
154 |
||
155 |
s_dsl_group_l: indent s_dsl_group_content[ctx => $arg{ctx}] eol
|
|
156 |
||
157 |
s_dsl_group_content: "autoconfig" |
|
158 |
{ $arg{ctx}->{autoconfig} = 1 }
|
|
159 |
| "execute" |
|
160 |
{ $arg{ctx}->{execute} = 1 }
|
|
161 |
| "caplist" identifier |
|
162 |
{ $arg{ctx}->{caplist} = $item{identifier} }
|
|
163 |
| "vendorspecoctets" num |
|
164 |
{ $arg{ctx}->{vendorspecoctets} = $item{num} }
|
|
165 |
||
166 |
# interface section |
|
167 |
iface_type: /[0-9a-zA-Z:-]+/ |
|
168 |
{ $item[1] }
|
|
169 |
||
170 |
iface_num: /\d+([\.\/]\d+)*/ |
|
171 |
{ $item[1] }
|
|
172 |
||
173 |
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
|
|
174 |
{
|
|
175 |
my $id = $item{iface_type}.":".$item{iface_num};
|
|
176 |
$::res->{interface}->{$id}->{type} = $item{iface_type};
|
|
177 |
$::res->{interface}->{$id}->{num} = $item{iface_num}
|
|
178 |
} |
|
179 |
||
180 |
ip: /\d+\.\d+\.\d+\.\d+/ |
|
181 |
{ $item[1] }
|
|
182 |
||
183 |
s_interface_l: "1" s_interface_content[ctx => $arg{ctx}] eol
|
|
184 |
| l_section |
|
185 |
||
186 |
s_interface_content: l_description[ctx => $arg{ctx}]
|
|
187 |
| /(no)?/ "shutdown" |
|
188 |
{ $arg{ctx}->{shutdown} = ($item[1] eq 'no') ? 0 : 1 }
|
|
189 |
| "ip" "address" ip ip |
|
190 |
{ $arg{ctx}->{ip} = $item[3]; $arg{ctx}->{mask} = $item[4] }
|
|
191 |
| "encapsulation" keyword /\S*/ |
|
192 |
{
|
|
193 |
$arg{ctx}->{encap} = $item[2];
|
|
194 |
$arg{ctx}->{encap_param} = $item[3] if length($item[3]) > 0
|
|
195 |
} |
|
196 |
| "bandwidth" num |
|
197 |
{ $arg{ctx}->{bandwidth} = $item{num} }
|
|
198 |
| "speed" num |
|
199 |
{ $arg{ctx}->{speed} = $item{num} }
|
|
200 |
| "ip" "vrf" "forwarding" word |
|
201 |
{ $arg{ctx}->{"ip-vrf-fwd"} = $item{word} }
|
|
202 |
| "bridge-group" num |
|
203 |
{ $arg{ctx}->{"bridge-group"} = $item{num} }
|
|
204 |
| "framing" keyword |
|
205 |
{ $arg{ctx}->{framing} = $item{keyword} }
|
|
|
39
b39ab9900b24
oneaccess.gramar: interface mtu, service-policy, access-group
Tomas Zeman <tzeman@volny.cz>
parents:
38
diff
changeset
|
206 |
| "ip" "mtu" num |
|
b39ab9900b24
oneaccess.gramar: interface mtu, service-policy, access-group
Tomas Zeman <tzeman@volny.cz>
parents:
38
diff
changeset
|
207 |
{ $arg{ctx}->{mtu} = $item{num} }
|
|
b39ab9900b24
oneaccess.gramar: interface mtu, service-policy, access-group
Tomas Zeman <tzeman@volny.cz>
parents:
38
diff
changeset
|
208 |
| "service-policy" /input|output/ identifier |
|
b39ab9900b24
oneaccess.gramar: interface mtu, service-policy, access-group
Tomas Zeman <tzeman@volny.cz>
parents:
38
diff
changeset
|
209 |
{ $arg{ctx}->{'service-policy'}->{$item[2]} = $item{identifier} }
|
|
b39ab9900b24
oneaccess.gramar: interface mtu, service-policy, access-group
Tomas Zeman <tzeman@volny.cz>
parents:
38
diff
changeset
|
210 |
| "ip" "access-group" identifier /in|out/ |
|
b39ab9900b24
oneaccess.gramar: interface mtu, service-policy, access-group
Tomas Zeman <tzeman@volny.cz>
parents:
38
diff
changeset
|
211 |
{ $arg{ctx}->{'access-group'}->{$item[4]} = $item{identifier} }
|
| 36 | 212 |
|
213 |
# vrf |
|
214 |
l_vrf: "0" "ip" "vrf" keyword eol |
|
215 |
{ $::res->{"ip-vrf"} = $item{keyword} }
|
|
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
216 |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
217 |
via_iface: iface_type iface_num |
|
37
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
218 |
{
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
219 |
$arg{ctx}->{interface} = {
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
220 |
type => $item{iface_type},
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
221 |
num => $item{iface_num}
|
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
222 |
}; |
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
223 |
} |
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
224 |
| "" |
|
7174a6414069
oneaccess.gramar: sntp parsing
Tomas Zeman <tzeman@volny.cz>
parents:
36
diff
changeset
|
225 |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
226 |
# sntp |
|
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
227 |
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
|
228 |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
229 |
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
|
230 |
| "0" "logging" "syslog" /\w+/ eol |
| 40 | 231 |
{ $::res->{syslog}->{level} = $item[4] }
|
232 |
||
233 |
# voice ports |
|
234 |
s_voice_port: "0" "voice-port" /\d+\/\d+/ eol s_voice_port_l[ctx => ctx('voice-port', $item[3])](s) "0" "exit" eol
|
|
235 |
||
236 |
s_voice_port_l: "1" s_voice_port_content[ctx => $arg{ctx}] eol
|
|
237 |
| l_section |
|
|
38
d925a22bbcf3
oneaccess.gramar: syslog config
Tomas Zeman <tzeman@volny.cz>
parents:
37
diff
changeset
|
238 |
|
| 40 | 239 |
s_voice_port_content: /clock-source|tone|caller-id/ identifier |
240 |
{ $arg{ctx}->{$item[1]} = $item{identifier} }
|
|
241 |
| /(no)?/ /sntp-time|power-source-one/ |
|
242 |
{ $arg{ctx}->{$item[2]} = ($item[1] eq 'no') ? 0 : 1 }
|
|
243 |
| "modify-tone" identifier /\S+/ |
|
244 |
{ $arg{ctx}->{$item[1]}->{$item{identifier}} = $item[3] }
|
|
245 |
||
| 41 | 246 |
# dial peers |
247 |
s_dial_peer: "0" "dial-peer" "voice" word num eol s_dial_peer_l[ctx => ctx('dial-peer', $item{word}.":".$item{num}), type => $item{word}, num => $item{num} ](s) "0" "exit" eol
|
|
248 |
||
249 |
s_dial_peer_l: "1" s_dial_peer_content[ctx => $arg{ctx}] eol
|
|
250 |
{
|
|
251 |
$arg{ctx}->{type} = $arg{type};
|
|
252 |
$arg{ctx}->{num} = $arg{num}
|
|
253 |
} |
|
254 |
| l_section |
|
255 |
||
256 |
s_dial_peer_content: identifier word |
|
257 |
{
|
|
258 |
if ($item[1] eq 'no') {
|
|
259 |
$arg{ctx}->{$item[2]} = 0;
|
|
260 |
} else {
|
|
261 |
$arg{ctx}->{$item[1]} = $item[2];
|
|
262 |
} |
|
263 |
} |
|
264 |
| identifier |
|
265 |
{ $arg{ctx}->{$item[1]} = 1 }
|
|
266 |