diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-16 21:45:27 -0500 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-17 23:22:55 -0500 |
commit | 93d1dca70aa0ae3b34050d24ad7462b8757213bf (patch) | |
tree | 29c369dfb6d2180e62bf51a5819eff8644bbc81a /table/policy.go | |
parent | 24e397b0f65b1c5294ea711a953501fda944411d (diff) |
config: simplify route-disposition configuration
before:
```yaml
actions:
route-disposition:
accept-route: true
reject-route: false
```
after
```yaml
action:
router-disposition: accept-route
```
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/policy.go')
-rw-r--r-- | table/policy.go | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/table/policy.go b/table/policy.go index 1d055b57..994ff4d8 100644 --- a/table/policy.go +++ b/table/policy.go @@ -1725,14 +1725,16 @@ func (a *RoutingAction) String() string { } func NewRoutingAction(c config.RouteDisposition) (*RoutingAction, error) { - if c.AcceptRoute == c.RejectRoute && c.AcceptRoute { - return nil, fmt.Errorf("invalid route disposition") - } else if !c.AcceptRoute && !c.RejectRoute { + var accept bool + switch c { + case config.RouteDisposition(""), config.ROUTE_DISPOSITION_NONE: return nil, nil - } - accept := false - if c.AcceptRoute && !c.RejectRoute { + case config.ROUTE_DISPOSITION_ACCEPT_ROUTE: accept = true + case config.ROUTE_DISPOSITION_REJECT_ROUTE: + accept = false + default: + return nil, fmt.Errorf("invalid route disposition") } return &RoutingAction{ AcceptRoute: accept, @@ -2341,11 +2343,6 @@ func (s *Statement) Apply(path *Path, options *PolicyOptions) (RouteType, *Path) } //Routing action if s.RouteAction == nil || reflect.ValueOf(s.RouteAction).IsNil() { - log.WithFields(log.Fields{ - "Topic": "Policy", - "Path": path, - "PolicyName": s.Name, - }).Warn("route action is nil") return ROUTE_TYPE_NONE, path } p := s.RouteAction.Apply(path, options) @@ -2399,7 +2396,13 @@ func (s *Statement) ToConfig() *config.Statement { act := config.Actions{} if s.RouteAction != nil && !reflect.ValueOf(s.RouteAction).IsNil() { a := s.RouteAction.(*RoutingAction) - act.RouteDisposition = config.RouteDisposition{AcceptRoute: a.AcceptRoute, RejectRoute: !a.AcceptRoute} + if a.AcceptRoute { + act.RouteDisposition = config.ROUTE_DISPOSITION_ACCEPT_ROUTE + } else { + act.RouteDisposition = config.ROUTE_DISPOSITION_REJECT_ROUTE + } + } else { + act.RouteDisposition = config.ROUTE_DISPOSITION_NONE } for _, a := range s.ModActions { switch a.(type) { |