diff options
author | Marcin Ptaszyński <marcin.ptaszynski@ntti3.com> | 2018-06-05 14:44:53 -0700 |
---|---|---|
committer | Marcin Ptaszyński <marcin.ptaszynski@ntti3.com> | 2018-06-13 20:53:17 -0700 |
commit | 5fbd0cb24324f1569377ce5c627bb2db97b76ce7 (patch) | |
tree | 4c646607888f8a46b9f9d2ecedfc3f6759950eda /table/policy.go | |
parent | 964bb04e22fdbf430d9810f5b362d7844b81e251 (diff) |
table: support AfiSafiIn Policy Condition match
Diffstat (limited to 'table/policy.go')
-rw-r--r-- | table/policy.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/table/policy.go b/table/policy.go index 770eb81b..da564abd 100644 --- a/table/policy.go +++ b/table/policy.go @@ -157,6 +157,7 @@ const ( CONDITION_ROUTE_TYPE CONDITION_LARGE_COMMUNITY CONDITION_NEXT_HOP + CONDITION_AFI_SAFI_IN ) type ActionType int @@ -1955,6 +1956,58 @@ func NewRouteTypeCondition(c config.RouteType) (*RouteTypeCondition, error) { }, nil } +type AfiSafiInCondition struct { + routeFamilies []bgp.RouteFamily +} + +func (c *AfiSafiInCondition) Type() ConditionType { + return CONDITION_AFI_SAFI_IN +} + +func (c *AfiSafiInCondition) Evaluate(path *Path, _ *PolicyOptions) bool { + for _, rf := range c.routeFamilies { + if path.GetRouteFamily() == rf { + return true + } + } + return false +} + +func (c *AfiSafiInCondition) Set() DefinedSet { + return nil +} + +func (c *AfiSafiInCondition) Name() string { return "" } + +func (c *AfiSafiInCondition) String() string { + tmp := make([]string, 0, len(c.routeFamilies)) + for _, afiSafi := range c.routeFamilies { + tmp = append(tmp, afiSafi.String()) + } + return strings.Join(tmp, " ") +} + +func NewAfiSafiInCondition(afiSafInConfig []config.AfiSafiType) (*AfiSafiInCondition, error) { + if afiSafInConfig == nil { + return nil, nil + } + + routeFamilies := make([]bgp.RouteFamily, 0, len(afiSafInConfig)) + for _, afiSafiValue := range afiSafInConfig { + if err := afiSafiValue.Validate(); err != nil { + return nil, err + } + rf, err := bgp.GetRouteFamily(string(afiSafiValue)) + if err != nil { + return nil, err + } + routeFamilies = append(routeFamilies, rf) + } + return &AfiSafiInCondition{ + routeFamilies: routeFamilies, + }, nil +} + type Action interface { Type() ActionType Apply(*Path, *PolicyOptions) *Path @@ -2652,6 +2705,13 @@ func (s *Statement) ToConfig() *config.Statement { case *RouteTypeCondition: v := c.(*RouteTypeCondition) cond.BgpConditions.RouteType = v.typ + case *AfiSafiInCondition: + v := c.(*AfiSafiInCondition) + res := make([]config.AfiSafiType, 0, len(v.routeFamilies)) + for _, rf := range v.routeFamilies { + res = append(res, config.AfiSafiType(rf.String())) + } + cond.BgpConditions.AfiSafiInList = res } } return cond @@ -2853,6 +2913,9 @@ func NewStatement(c config.Statement) (*Statement, error) { func() (Condition, error) { return NewNextHopCondition(c.Conditions.BgpConditions.NextHopInList) }, + func() (Condition, error) { + return NewAfiSafiInCondition(c.Conditions.BgpConditions.AfiSafiInList) + }, } cs = make([]Condition, 0, len(cfs)) for _, f := range cfs { @@ -3227,6 +3290,7 @@ func (r *RoutingPolicy) validateCondition(v Condition) (err error) { c.set = i.(*LargeCommunitySet) } case CONDITION_NEXT_HOP: + case CONDITION_AFI_SAFI_IN: case CONDITION_AS_PATH_LENGTH: case CONDITION_RPKI: } |