From b37d9bb56a30ee390732a530ea8e9cb174db1759 Mon Sep 17 00:00:00 2001 From: Denis Shevchenko Date: Mon, 22 May 2017 14:38:38 +0300 Subject: flowspec: handling of >2 logical elements and fixed test --- packet/bgp/bgp.go | 18 +++++++----------- test/scenario_test/flow_spec_test.py | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 12403368..34bff21a 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -2741,19 +2741,15 @@ func parseDecValuesCmd(myCmd string, validationFunc func(int) error) ([][2]int, return nil, err } case DECLogicOpNameMap[DEC_LOGIC_OP_AND], DECLogicOpNameMap[DEC_LOGIC_OP_OR]: - if bit := DECLogicOpValueMap[myCmdChar]; bit&DECLogicOp(operatorValue[0]) == 0 { - decOperatorsAndValues = append(decOperatorsAndValues, operatorValue) - if myCmdChar == DECLogicOpNameMap[DEC_LOGIC_OP_AND] { - operatorValue[0] = int(bit) - } else { - operatorValue[0] = 0 - } - operatorValue[1] = 0 - index++ + bit := DECLogicOpValueMap[myCmdChar] + decOperatorsAndValues = append(decOperatorsAndValues, operatorValue) + if myCmdChar == DECLogicOpNameMap[DEC_LOGIC_OP_AND] { + operatorValue[0] = int(bit) } else { - err := fmt.Errorf("AND or OR (space) operator appears multiple time") - return nil, err + operatorValue[0] = 0 } + operatorValue[1] = 0 + index++ case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": myLoopChar := myCmdChar loopIndex := index diff --git a/test/scenario_test/flow_spec_test.py b/test/scenario_test/flow_spec_test.py index 17a36028..2671bf5e 100644 --- a/test/scenario_test/flow_spec_test.py +++ b/test/scenario_test/flow_spec_test.py @@ -49,7 +49,7 @@ class GoBGPTestBase(unittest.TestCase): matchs = ['destination 10.0.0.0/24', 'source 20.0.0.0/24'] thens = ['discard'] e1.add_route(route='flow1', rf='ipv4-flowspec', matchs=matchs, thens=thens) - matchs2 = ['tcp-flags S', 'protocol ==tcp ==udp', "packet-length '>1000&<2000'"] + matchs2 = ['tcp-flags S', 'protocol ==tcp ==udp', "packet-length '>1000&<2000'", "source-port '!=2&!=22&!=222'"] thens2 = ['rate-limit 9600', 'redirect 0.10:100', 'mark 20', 'action sample'] g1.add_route(route='flow1', rf='ipv4-flowspec', matchs=matchs2, thens=thens2) matchs3 = ['destination 2001::/24/10', 'source 2002::/24/15'] -- cgit v1.2.3