From a4f2e5902860ca1fa70c76e0ffd5289293c5ca57 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Tue, 20 Oct 2015 12:06:32 +0900 Subject: policy: fix how to apply policy to follow openconfig description OpenConfig model says for Route policy evaluation: Evaluation of each policy definition proceeds by evaluating its corresponding individual policy statements in order. When a condition statement in a policy statement is satisfied, the corresponding action statement is executed. If the action statement has either accept-route or reject-route actions, policy evaluation of the current policy definition stops, and no further policy definitions in the chain are evaluated. Signed-off-by: ISHIDA Wataru --- table/policy.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'table/policy.go') diff --git a/table/policy.go b/table/policy.go index 809bb984..7698bad6 100644 --- a/table/policy.go +++ b/table/policy.go @@ -1893,6 +1893,13 @@ func (s *Statement) Apply(path *Path) (RouteType, *Path) { "PolicyName": s.Name, }).Debug("statement evaluate : ", result) if result { + if len(s.ModActions) != 0 { + // apply all modification actions + path = path.Clone(path.Owner, path.IsWithdraw) + for _, action := range s.ModActions { + path = action.Apply(path) + } + } //Routing action if s.RouteAction == nil { log.WithFields(log.Fields{ @@ -1900,21 +1907,13 @@ func (s *Statement) Apply(path *Path) (RouteType, *Path) { "Path": path, "PolicyName": s.Name, }).Warn("route action is nil") - return ROUTE_TYPE_REJECT, path + return ROUTE_TYPE_NONE, path } p := s.RouteAction.Apply(path) if p == nil { return ROUTE_TYPE_REJECT, path } - if len(s.ModActions) == 0 { - return ROUTE_TYPE_ACCEPT, path - } - // apply all modification actions - cloned := path.Clone(p.Owner, p.IsWithdraw) - for _, action := range s.ModActions { - cloned = action.Apply(cloned) - } - return ROUTE_TYPE_ACCEPT, cloned + return ROUTE_TYPE_ACCEPT, path } return ROUTE_TYPE_NONE, path } @@ -2253,7 +2252,8 @@ func (p *Policy) Name() string { // subsequent conditions are skipped. func (p *Policy) Apply(path *Path) (RouteType, *Path) { for _, stmt := range p.Statements { - result, path := stmt.Apply(path) + var result RouteType + result, path = stmt.Apply(path) if result != ROUTE_TYPE_NONE { return result, path } -- cgit v1.2.3