ciena.grammar
changeset 1 7e38ef20071f
child 2 7b9f165f3a45
equal deleted inserted replaced
0:b93558664b93 1:7e38ef20071f
       
     1 # Grammar for Ciena devices
       
     2 
       
     3 <autotree>
       
     4 { # perl code follows
       
     5 
       
     6 $::res = {};
       
     7 $::res->{port} ={};
       
     8 $::res->{sub_port} ={};
       
     9 $::res->{pm} = {
       
    10 	instance => {},
       
    11 	service => {},
       
    12 	'sub-port' => {},
       
    13 };
       
    14 $::res->{pbt} = {
       
    15 	reserved => {},	# reserved bvids
       
    16 	'bridge-mac' => {},
       
    17 };
       
    18 $::res->{'pbt-service'} = {};
       
    19 $::res->{'pbt-tunnel-group'} = {};
       
    20 
       
    21 
       
    22 # local (current line) attribute-value-list, ie. property value
       
    23 my $avl = {};
       
    24 
       
    25 # Consumes attribute value list.
       
    26 # @param type Type (port/sub_port/etc).
       
    27 # @param id Identifier, eg. port number.
       
    28 sub consume_avl {
       
    29 	my ($type, $id) = (@_);
       
    30 	$::res->{$type}->{$id} = {} unless exists $::res->{$type}->{$id};
       
    31 	foreach my $k (keys %$avl) {
       
    32 		$::res->{$type}->{$id}->{$k} = $avl->{$k};
       
    33 	}
       
    34 	$avl = {};
       
    35 }
       
    36 
       
    37 # Consumes attribute value list into supplied pointer (into hash).
       
    38 # @param ptr Pointer where AVL will be stored.
       
    39 # @param id Identifier, eg. port number.
       
    40 sub consume_avl_ptr {
       
    41 	my ($ptr, $id) = (@_);
       
    42 	$ptr->{$id} = {} unless exists $ptr->{$id};
       
    43 	foreach my $k (keys %$avl) {
       
    44 		$ptr->{$id}->{$k} = $avl->{$k};
       
    45 	}
       
    46 	$avl = {};
       
    47 }
       
    48 
       
    49 } # end of perl code
       
    50 
       
    51 file:		<skip: qr/[^\S\n]*/>	# Ignore non-newline whitespace
       
    52 		line(s) eofile
       
    53 
       
    54 line: 		emptyline
       
    55 		| comment
       
    56 		| cmdline 
       
    57 		| <error>
       
    58 
       
    59 emptyline:	eol
       
    60 
       
    61 comment: 	/^\!.*/ eol
       
    62 
       
    63 cmdline:	l_hostname
       
    64 		| l_port
       
    65 		| l_sub_port
       
    66 		| l_pm
       
    67 		| l_pbt
       
    68 		| word(s) eol
       
    69 
       
    70 word:		/[0-9a-zA-Z:\/_\#\"\.,-]+/
       
    71 		{ $item[1] }
       
    72 
       
    73 identifier:	/[0-9a-zA-Z:_-]+/
       
    74 		{ $item[1] }
       
    75 
       
    76 quoted_text:	<perl_quotelike>
       
    77 		{ $item[1][2] }
       
    78 		| /[0-9a-zA-Z:\/_\#\"\.,-]+/
       
    79 		{ $item[1] }
       
    80 
       
    81 value:		/[0-9a-zA-Z:\/_\#\"\.,-]+/
       
    82 		{ $item[1] }
       
    83 
       
    84 eofile:		/^\Z/
       
    85 
       
    86 eol:		/\n/
       
    87 
       
    88 rest_of_line:	word(s)
       
    89 		| eol
       
    90 
       
    91 # Hostname
       
    92 l_hostname:	"system" "set" "host-name" identifier
       
    93 		{ $::res->{hostname} = $item{identifier} }
       
    94 
       
    95 # Port
       
    96 l_port:		"port" /disable|set/ "port" port_num avls
       
    97 		{
       
    98 		$avl->{action} = $item[2];
       
    99 		consume_avl("port", $item{port_num}); 
       
   100 		}
       
   101 
       
   102 port_num:	/\d+(\/\d+)?/
       
   103 		{ $item[1] }
       
   104 
       
   105 avls:		avl(s)
       
   106 		| eol
       
   107 
       
   108 avl:		"description" quoted_text
       
   109 		{ $avl->{description} = $item{quoted_text}; }
       
   110 		| word value
       
   111 		{ $avl->{$item{word}} = $item{value}; }
       
   112 # Sub-port
       
   113 l_sub_port:	"sub-port" /add|create/ "sub-port" identifier avls
       
   114 		{
       
   115 		$avl->{action} = $item[2];
       
   116 		consume_avl("sub_port", $item{identifier}); 
       
   117 		}
       
   118 
       
   119 # PM
       
   120 l_pm:		"pm" "enable" "pm-instance" identifier
       
   121 		{ $::res->{pm}->{instance}->{$item{identifier}} = "enabled" }
       
   122 		| "pm" "create" /service|sub-port/ identifier avls
       
   123 		{
       
   124 		$::res->{pm}->{$item[3]}->{$item{identifier}} = {};
       
   125 		consume_avl_ptr($::res->{pm}->{$item[3]}, $item{identifier});
       
   126 		}
       
   127 
       
   128 # PBT
       
   129 bvid:		/\d+/
       
   130 		{ $item[1] }
       
   131 
       
   132 mac:		/\d{12}|(\d\d:){5}\d\d/
       
   133 		{ $item[1] }
       
   134 
       
   135 l_pbt:		"pbt" "reserve" "bvid" bvid
       
   136 		{ $::res->{pbt}->{reserved}->{$item{bvid}} = 1 }
       
   137 		| "pbt" "set" "bridge-mac" mac avls
       
   138 		{
       
   139 		$::res->{pbt}->{'bridge-mac'}->{$item{mac}} = {};
       
   140 		consume_avl_ptr($::res->{pbt}->{'bridge-mac'}, $item{mac})
       
   141 		}
       
   142 		| "pbt" "service" "create" "service" identifier avls
       
   143 		{ consume_avl("pbt-service", $item{identifier}) }
       
   144 		| "pbt" "tunnel-group" "create" "group" identifier avls
       
   145 		{ consume_avl("pbt-tunnel-group", $item{identifier}) }