Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/greearb/xorp.ct
Browse files Browse the repository at this point in the history
  • Loading branch information
RUN administrator committed Oct 18, 2012
2 parents 062a90d + 19d2db7 commit afdd3ae
Show file tree
Hide file tree
Showing 34 changed files with 428 additions and 8,393 deletions.
4 changes: 2 additions & 2 deletions xorp/etc/templates/bgp.tp
Expand Up @@ -834,7 +834,7 @@ policy {
}
med {
%help: short "Set the BGP MED attribute";
%allow-operator: ":" "=" "sub" "add";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=med $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand All @@ -845,7 +845,7 @@ policy {
}
localpref {
%help: short "Set the local preference";
%allow-operator: ":" "=" "sub" "add";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=localpref $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand Down
2 changes: 1 addition & 1 deletion xorp/etc/templates/ospfv2.tp
Expand Up @@ -555,7 +555,7 @@ policy {
then {
metric {
%help: short "Set the metric value";
%allow-operator: ":" "=" "sub" "add";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=metric $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand Down
2 changes: 1 addition & 1 deletion xorp/etc/templates/ospfv3.tp
Expand Up @@ -430,7 +430,7 @@ policy {
then {
metric {
%help: short "Set the metric value";
%allow-operator: ":" "=" "sub" "add";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=metric $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand Down
2 changes: 1 addition & 1 deletion xorp/etc/templates/policy.tp
Expand Up @@ -276,7 +276,7 @@ policy {

tag {
%help: short "Tag value";
%allow-operator: ":" "=" "add" "sub";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=tag $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand Down
2 changes: 1 addition & 1 deletion xorp/etc/templates/rip.tp
Expand Up @@ -339,7 +339,7 @@ policy {
then {
metric {
%help: short "Set the metric value";
%allow-operator: ":" "=" "sub" "add";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=metric $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand Down
2 changes: 1 addition & 1 deletion xorp/etc/templates/ripng.tp
Expand Up @@ -287,7 +287,7 @@ policy {
then {
metric {
%help: short "Set the metric value";
%allow-operator: ":" "=" "sub" "add";
%allow-operator: ":" "=" "sub" "add" "mul" "div" "lshift" "rshift" "bit_and" "bit_or" "bit_xor" "+=" "-=" "*=" "/=" "<<=" ">>=" "&=" "|=" "^=";
%set: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=metric $(<>) $(@);";
%delete: xrl "$(policy.targetname)/policy/0.1/update_term_block?policy:txt=$(policy-statement.@)&term:txt=$(term.@)&block:u32=2&order:txt=$(#)&statement:txt=";
}
Expand Down
32 changes: 30 additions & 2 deletions xorp/policy/SConscript
Expand Up @@ -32,6 +32,7 @@ is_shared = env.has_key('SHAREDLIBS')
env.AppendUnique(CPPPATH = [
'#',
'$BUILDDIR',
env['xorp_sourcedir'], #this is needed for lex and yacc generated files
])

env.PrependUnique(LIBPATH = [
Expand Down Expand Up @@ -85,7 +86,36 @@ env.Replace(RPATH = [
env.Literal(env['xorp_module_rpath'])
])

# Automatically generate flex and yacc files

#Create yacc files
yacc_env = env.Clone()

# bison on BSD generates headers files with .h suffix,
# while on other OSs it generates header files with .hh suffix
#
# But, on FreeBSD at least, if you don't do the .hh suffix, it doesn't even
# build a .h file of any type --Ben
yacc_env.Replace(YACCHXXFILESUFFIX='.hh')

yacc_env.AppendUnique(YACCFLAGS='-d')

yacc_env.AppendUnique(YACCFLAGS='-ppolicy_parser')

policy_yacc = yacc_env.CXXFile(target='y.policy_parser_tab.cc',
source='policy.yy')

#create lex files
lex_env = env.Clone()

lex_env.AppendUnique(LEXFLAGS='-Ppolicy_parser')

policy_lex = lex_env.CXXFile(target='lex.policy_parser.cc',
source='policy.ll')

libxorp_policy_srcs = [
policy_lex[0],
policy_yacc[0],
'code.cc',
'code_generator.cc',
'code_list.cc',
Expand All @@ -111,8 +141,6 @@ libxorp_policy_srcs = [
'visitor_semantic.cc',
'visitor_test.cc',
'xrl_target.cc',
'yacc.yy_policy_parser.cc',
'lex.yy_policy_parser.cc'
]

######
Expand Down
31 changes: 29 additions & 2 deletions xorp/policy/backend/SConscript
Expand Up @@ -26,7 +26,36 @@ is_shared = env.has_key('SHAREDLIBS')

env.AppendUnique(CPPPATH = [ '#' ])

# Automatically generate flex and yacc files

#Create yacc files
yacc_env = env.Clone()

# bison on BSD generates headers files with .h suffix,
# while on other OSs it generates header files with .hh suffix
#
# But, on FreeBSD at least, if you don't do the .hh suffix, it doesn't even
# build a .h file of any type --Ben
yacc_env.Replace(YACCHXXFILESUFFIX='.hh')

yacc_env.AppendUnique(YACCFLAGS='-d')

yacc_env.AppendUnique(YACCFLAGS='-ppolicy_backend_parser')

backend_yacc = yacc_env.CXXFile(target='y.policy_backend_parser_tab.cc',
source='backend.yy')

#create lex files
lex_env = env.Clone()

lex_env.AppendUnique(LEXFLAGS='-Ppolicy_backend_parser')

backend_lex = lex_env.CXXFile(target='lex.policy_backend_parser.cc',
source='backend.ll')

libpbesrcs = [
backend_lex[0],
backend_yacc[0],
'iv_exec.cc',
'policy_filter.cc',
'policy_filters.cc',
Expand All @@ -36,8 +65,6 @@ libpbesrcs = [
'single_varrw.cc',
'version_filter.cc',
'version_filters.cc',
'lex.yy_policy_backend_parser.cc',
'yacc.yy_policy_backend_parser.cc'
]

if not (env.has_key('disable_profile') and env['disable_profile']):
Expand Down
41 changes: 26 additions & 15 deletions xorp/policy/backend/backend.l → xorp/policy/backend/backend.ll
Expand Up @@ -5,12 +5,17 @@

#include "libxorp/xorp.h"
#include "policy/common/policy_utils.hh"
#include "policy_backend_parser.hh"
#include "yacc.yy_policy_backend_parser.cc.h"
#include "policy/backend/policy_backend_parser.hh"

#define yyparse yy_policy_backend_parserparse
#define yyerror yy_policy_backend_parsererror
#define yylval yy_policy_backend_parserlval
#if defined(NEED_LEX_H_HACK)
#include "y.policy_backend_parser_tab.cc.h"
#else
#include "y.policy_backend_parser_tab.hh"
#endif

#define yyparse policy_backend_parserparse
#define yyerror policy_backend_parsererror
#define yylval policy_backend_parserlval

using namespace policy_utils;
using namespace policy_backend_parser;
Expand All @@ -28,13 +33,13 @@ SUBR* policy_backend_parser::_yy_subr;
namespace {
string _last_error;
unsigned _parser_lineno;
}
}

%}
%option noyywrap
%option nounput
%option prefix="yy_policy_backend_parser"
%option outfile="lex.yy_policy_backend_parser.cc"
%option prefix="policy_backend_parser"
%option outfile="lex.policy_backend_parser.cc"
%option never-interactive
%x STR
%%
Expand Down Expand Up @@ -65,6 +70,8 @@ namespace {
"SUBR_START" { return YY_SUBR_START; }
"SUBR_END" { return YY_SUBR_END; }

"<<" { return YY_LSHIFT; }
">>" { return YY_RSHIFT; }
"==" { return YY_EQ; }
"!=" { return YY_NE; }
"<" { return YY_LT; }
Expand All @@ -74,24 +81,28 @@ namespace {
"+" { return YY_ADD; }
"\-" { return YY_SUB; }
"*" { return YY_MUL; }
"/" { return YY_DIV; }
"&" { return YY_BITAND; }
"|" { return YY_BITOR; }
"^" { return YY_BITXOR; }
"\n" { _parser_lineno++; return YY_NEWLINE; }
[[:blank:]]+ /* eat blanks */
[^\"[:blank:]\n]+ {
[^\"[:blank:]\n]+ {
yylval.c_str = strdup(yytext);
return YY_ARG;
}
return YY_ARG;
}
\" BEGIN(STR);
<STR>\" BEGIN(INITIAL);
<STR>[^\"]+ { yylval.c_str = strdup(yytext);
_parser_lineno += count_nl(yytext);
_parser_lineno += count_nl(yytext);
return YY_ARG;
}
}
%%
Expand Down Expand Up @@ -137,7 +148,7 @@ policy_backend_parser::policy_backend_parse(vector<PolicyInstr*>& outpolicies,
// get rid of temporary parse object not yet bound to policies
delete_vector(_yy_terms);
delete_vector(_yy_instructions);
}
}
// good parse
else {
// all terms should be bound to policies
Expand All @@ -150,4 +161,4 @@ policy_backend_parser::policy_backend_parse(vector<PolicyInstr*>& outpolicies,
}
return res;
}
}
36 changes: 22 additions & 14 deletions xorp/policy/backend/backend.y → xorp/policy/backend/backend.yy
Expand Up @@ -9,10 +9,10 @@
#include "policy/common/varrw.hh"
#include "policy/common/element_factory.hh"
#include "policy/common/operator.hh"
#include "policy_backend_parser.hh"
#include "instruction.hh"
#include "term_instr.hh"
#include "policy_instr.hh"
#include "policy/backend/policy_backend_parser.hh"
#include "policy/backend/instruction.hh"
#include "policy/backend/term_instr.hh"
#include "policy/backend/policy_instr.hh"

extern int yylex(void);
extern void yyerror(const char*);
Expand All @@ -35,6 +35,8 @@ static ElementFactory _ef;
%token YY_EQ YY_NE YY_LT YY_GT YY_LE YY_GE
%token YY_NOT YY_AND YY_OR YY_XOR YY_HEAD YY_CTR YY_NE_INT
%token YY_ADD YY_SUB YY_MUL
%token YY_DIV YY_LSHIFT YY_RSHIFT
%token YY_BITAND YY_BITOR YY_BITXOR
%token YY_ONFALSE_EXIT
%token YY_REGEX
%token YY_LOAD YY_STORE
Expand All @@ -47,14 +49,14 @@ static ElementFactory _ef;
program:
program policy { _yy_policies->push_back($2); }
| program subroutine
| program set
| program set
| /* empty */
;

set:
YY_SET YY_ARG YY_ARG YY_ARG YY_NEWLINE
YY_SET YY_ARG YY_ARG YY_ARG YY_NEWLINE
{
// XXX: doesn't delete old
// XXX: doesn't delete old
(*_yy_sets)[$3] = _ef.create($2, $4);
free($2); free($3); free($4);
}
Expand Down Expand Up @@ -86,32 +88,32 @@ policy: YY_POLICY_START YY_ARG YY_NEWLINE terms YY_POLICY_END YY_NEWLINE

terms:
terms YY_TERM_START YY_ARG YY_NEWLINE statements YY_TERM_END YY_NEWLINE {

TermInstr* ti = new TermInstr($3,_yy_instructions);
_yy_instructions = new vector<Instruction*>();
_yy_terms->push_back(ti);
free($3);
}
| /* empty */
| /* empty */
;

statements:
statements:
statements statement YY_NEWLINE
| /* empty */
;


statement:
YY_PUSH YY_ARG YY_ARG {
Instruction* i = new Push(_ef.create($2,$3));
Instruction* i = new Push(_ef.create($2,$3));
_yy_instructions->push_back(i);
free($2); free($3);
}
free($2); free($3);
}
| YY_PUSH_SET YY_ARG {
_yy_instructions->push_back(new PushSet($2));
free($2);
}

| YY_ONFALSE_EXIT {
_yy_instructions->push_back(new OnFalseExit());
}
Expand Down Expand Up @@ -169,6 +171,12 @@ statement:
| YY_ADD { _yy_instructions->push_back(new NaryInstr(new OpAdd)); }
| YY_SUB { _yy_instructions->push_back(new NaryInstr(new OpSub)); }
| YY_MUL { _yy_instructions->push_back(new NaryInstr(new OpMul)); }
| YY_DIV { _yy_instructions->push_back(new NaryInstr(new OpDiv)); }
| YY_LSHIFT { _yy_instructions->push_back(new NaryInstr(new OpLShift)); }
| YY_RSHIFT { _yy_instructions->push_back(new NaryInstr(new OpRShift)); }
| YY_BITAND { _yy_instructions->push_back(new NaryInstr(new OpBitAnd)); }
| YY_BITOR { _yy_instructions->push_back(new NaryInstr(new OpBitOr)); }
| YY_BITXOR { _yy_instructions->push_back(new NaryInstr(new OpBitXor)); }
| YY_HEAD { _yy_instructions->push_back(new NaryInstr(new OpHead));}
| YY_CTR { _yy_instructions->push_back(new NaryInstr(new OpCtr));}
| YY_NE_INT { _yy_instructions->push_back(new NaryInstr(new OpNEInt));}
Expand Down

0 comments on commit afdd3ae

Please sign in to comment.