2 * Copyright (c) 2016 Mohamed Aslan <maslan@sce.carleton.ca>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <sys/queue.h>
29 SIMPLEQ_HEAD
(list
, list_item
);
32 SIMPLEQ_ENTRY
(list_item
) next
;
38 extern
int yylex(void);
40 int yyerror(const char *, ...
);
41 static ofp_fptr check_ofp_version
(const char *);
42 static char *filename
;
43 static struct config
*conf
;
57 %token OPENFLOW VERSION
59 %token ADAPT EVERY SEC MIN
62 %token COMMA LCBRACKET RCBRACKET
89 conf
->c_nodeid
= strdup
($2);
93 listen
: LISTEN ON PORT NUMBER
{
98 controller
: CONTROLLER STRING IP STRING PORT NUMBER
{
99 //printf("CONTROLLER: %s, ip addr=%s, port=%d\n", $2, $4, $6);
101 | CONTROLLER STRING IP STRING
{
102 //printf("CONTROLLER: %s, ip addr=%s\n", $2, $4);
106 replicas
: REPLICAS NUMBER
{
107 conf
->c_nreplicas
= $2;
111 openflow
: OPENFLOW VERSION STRING
{
112 if
((conf
->c_ofp
= check_ofp_version
($3)) == NULL
) {
113 yyerror("OpenFlow version '%s' not supported.", $3);
116 conf
->c_ofp_verstr
= strdup
($3);
118 | OPENFLOW LISTEN ON PORT NUMBER
{
119 conf
->c_sw_port
= $5;
124 struct list_item
*s
= (struct list
*)malloc
(sizeof
(struct list
));
128 SIMPLEQ_INSERT_TAIL
($$
, s
, next
);
130 | str_list COMMA STRING
{
131 struct list_item
*s
= (struct list
*)malloc
(sizeof
(struct list
));
134 SIMPLEQ_INSERT_TAIL
($1, s
, next
);
138 param_list
: VAR STRING
{
139 struct list_item
*p
, *q
;
141 p
= (struct list
*)malloc
(sizeof
(struct list
));
142 q
= (struct list
*)malloc
(sizeof
(struct list
));
143 asprintf
(&p
->val
, "--%s", $1);
146 SIMPLEQ_INSERT_TAIL
($$
, p
, next
);
147 SIMPLEQ_INSERT_TAIL
($$
, q
, next
);
149 | param_list COMMA VAR STRING
{
150 struct list_item
*p
, *q
;
152 p
= (struct list
*)malloc
(sizeof
(struct list
));
153 q
= (struct list
*)malloc
(sizeof
(struct list
));
154 asprintf
(&p
->val
, "--%s", $3);
156 SIMPLEQ_INSERT_TAIL
($1, p
, next
);
157 SIMPLEQ_INSERT_TAIL
($1, q
, next
);
159 | param_list COMMA VAR LCBRACKET str_list RCBRACKET
{
160 struct list_item
*p
, *q
;
162 while
(!SIMPLEQ_EMPTY
($5)) {
163 p
= (struct list
*)malloc
(sizeof
(struct list
));
164 asprintf
(&p
->val
, "--%s", $3);
165 SIMPLEQ_INSERT_TAIL
($1, p
, next
);
166 q
= SIMPLEQ_FIRST
($5);
167 SIMPLEQ_REMOVE_HEAD
($5, next
);
168 SIMPLEQ_INSERT_TAIL
($1, q
, next
);
173 application
: APPLICATION STRING
{
174 conf
->c_app_name
= strdup
($2);
176 | APPLICATION STRING LCBRACKET param_list RCBRACKET
{
182 conf
->c_app_name
= strdup
($2);
183 SIMPLEQ_FOREACH
(p
, $4, next
)
186 argv
= (char **)reallocarray
(NULL
, argc
, sizeof
(char *));
187 argv
[0] = strdup
($2);
188 while
(!SIMPLEQ_EMPTY
($4)) {
189 p
= SIMPLEQ_FIRST
($4);
191 SIMPLEQ_REMOVE_HEAD
($4, next
);
194 conf
->c_app_argc
= argc
;
195 conf
->c_app_argv
= argv
;
199 adapt
: ADAPT EVERY NUMBER SEC
{
201 yyerror("adaptation time must be > 1.");
206 | ADAPT EVERY NUMBER MIN
{
208 yyerror("adaptation time must be > 1.");
211 conf
->c_atime
= $3 * 60;
215 learn
: LEARN FOR NUMBER SEC
{
217 yyerror("learning time must be >= 30 sec.");
222 | LEARN FOR NUMBER MIN
{
224 yyerror("use you may use seconds for learning time.");
227 conf
->c_ltime
= $3 * 60;
231 log
: LOG TO STRING
{
232 conf
->c_logfile
= strdup
($3);
238 check_ofp_version
(const char *ver
)
242 for
(i
= 0 ; i
< N_OFP_VERS
; i
++)
243 if
(!strcmp
(ver
, ofp_vers
[i
].ver
))
244 return ofp_vers
[i
].func
;
249 yyerror(const char *fmt
, ...
)
254 fprintf
(stdout
, "%s:%d: ", filename
, yylineno
);
255 vfprintf
(stdout
, fmt
, ap
);
256 fprintf
(stdout
, "\n");
263 parse_config
(struct config
*c
, const char *file
)
268 errx
(1, "parse_config");
269 if
((yyin
= fopen
(file
, "r")) == NULL
) {
270 errx
(1, "failed to load config file");
272 filename
= strdup
(file
);
274 conf
->c_app_name
= NULL
;
275 conf
->c_logfile
= NULL
;