diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2016-12-07 10:35:44 -0800 |
---|---|---|
committer | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2016-12-14 15:28:37 -0800 |
commit | ae496021e06452f92da8738671112597374775c1 (patch) | |
tree | 69841e23e1b679058a9265873594476c662a6246 | |
parent | 2c66865d5ee574d868284dd6a8e104ebe2aab283 (diff) |
policy: allow using invert condition in statement
Signed-off-by: Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>
-rw-r--r-- | api/grpc_server.go | 6 | ||||
-rw-r--r-- | table/policy.go | 14 |
2 files changed, 16 insertions, 4 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 395f3bc2..9a3146f1 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -1209,14 +1209,16 @@ func NewAPIStatementFromTableStruct(t *table.Statement) *Statement { func toStatementApi(s *config.Statement) *Statement { cs := &Conditions{} if s.Conditions.MatchPrefixSet.PrefixSet != "" { + o, _ := table.NewMatchOption(s.Conditions.MatchPrefixSet.MatchSetOptions) cs.PrefixSet = &MatchSet{ - Type: MatchType(s.Conditions.MatchPrefixSet.MatchSetOptions.ToInt()), + Type: MatchType(o), Name: s.Conditions.MatchPrefixSet.PrefixSet, } } if s.Conditions.MatchNeighborSet.NeighborSet != "" { + o, _ := table.NewMatchOption(s.Conditions.MatchNeighborSet.MatchSetOptions) cs.NeighborSet = &MatchSet{ - Type: MatchType(s.Conditions.MatchNeighborSet.MatchSetOptions.ToInt()), + Type: MatchType(o), Name: s.Conditions.MatchNeighborSet.NeighborSet, } } diff --git a/table/policy.go b/table/policy.go index 5916d0a3..72313007 100644 --- a/table/policy.go +++ b/table/policy.go @@ -110,6 +110,16 @@ func (o MatchOption) String() string { } } +func (o MatchOption) ConvertToMatchSetOptionsRestrictedType() config.MatchSetOptionsRestrictedType { + switch o { + case MATCH_OPTION_ANY: + return config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + case MATCH_OPTION_INVERT: + return config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT + } + return "unknown" +} + type MedActionType int const ( @@ -2363,10 +2373,10 @@ func (s *Statement) ToConfig() *config.Statement { switch c.(type) { case *PrefixCondition: v := c.(*PrefixCondition) - cond.MatchPrefixSet = config.MatchPrefixSet{PrefixSet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsRestrictedTypeMap[int(v.option)]} + cond.MatchPrefixSet = config.MatchPrefixSet{PrefixSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} case *NeighborCondition: v := c.(*NeighborCondition) - cond.MatchNeighborSet = config.MatchNeighborSet{NeighborSet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsRestrictedTypeMap[int(v.option)]} + cond.MatchNeighborSet = config.MatchNeighborSet{NeighborSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} case *AsPathLengthCondition: v := c.(*AsPathLengthCondition) cond.BgpConditions.AsPathLength = config.AsPathLength{Operator: config.IntToAttributeComparisonMap[int(v.operator)], Value: v.length} |