()
| 3458 | } |
| 3459 | |
| 3460 | func (s *Statement) ToConfig() *oc.Statement { |
| 3461 | return &oc.Statement{ |
| 3462 | Name: s.Name, |
| 3463 | Conditions: func() oc.Conditions { |
| 3464 | cond := oc.Conditions{} |
| 3465 | for _, c := range s.Conditions { |
| 3466 | switch v := c.(type) { |
| 3467 | case *PrefixCondition: |
| 3468 | cond.MatchPrefixSet = oc.MatchPrefixSet{PrefixSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} |
| 3469 | case *NeighborCondition: |
| 3470 | cond.MatchNeighborSet = oc.MatchNeighborSet{NeighborSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} |
| 3471 | case *CommunityCountCondition: |
| 3472 | cond.BgpConditions.CommunityCount = oc.CommunityCount{Operator: oc.IntToAttributeComparisonMap[int(v.operator)], Value: v.count} |
| 3473 | case *AsPathLengthCondition: |
| 3474 | cond.BgpConditions.AsPathLength = oc.AsPathLength{Operator: oc.IntToAttributeComparisonMap[int(v.operator)], Value: v.length} |
| 3475 | case *AsPathCondition: |
| 3476 | cond.BgpConditions.MatchAsPathSet = oc.MatchAsPathSet{AsPathSet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} |
| 3477 | case *CommunityCondition: |
| 3478 | cond.BgpConditions.MatchCommunitySet = oc.MatchCommunitySet{CommunitySet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} |
| 3479 | case *ExtCommunityCondition: |
| 3480 | cond.BgpConditions.MatchExtCommunitySet = oc.MatchExtCommunitySet{ExtCommunitySet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} |
| 3481 | case *LargeCommunityCondition: |
| 3482 | cond.BgpConditions.MatchLargeCommunitySet = oc.MatchLargeCommunitySet{LargeCommunitySet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} |
| 3483 | case *NextHopCondition: |
| 3484 | l := make([]netip.Addr, 0, len(v.set.list)) |
| 3485 | for _, n := range v.set.list { |
| 3486 | if n.Addr().Is4() || n.Addr().Is6() { |
| 3487 | l = append(l, n.Addr()) |
| 3488 | } |
| 3489 | } |
| 3490 | cond.BgpConditions.NextHopInList = l |
| 3491 | case *RpkiValidationCondition: |
| 3492 | cond.BgpConditions.RpkiValidationResult = v.result |
| 3493 | case *RouteTypeCondition: |
| 3494 | cond.BgpConditions.RouteType = v.typ |
| 3495 | case *OriginCondition: |
| 3496 | cond.BgpConditions.OriginEq = v.origin |
| 3497 | case *AfiSafiInCondition: |
| 3498 | res := make([]oc.AfiSafiType, 0, len(v.routeFamilies)) |
| 3499 | for _, rf := range v.routeFamilies { |
| 3500 | res = append(res, oc.AfiSafiType(rf.String())) |
| 3501 | } |
| 3502 | cond.BgpConditions.AfiSafiInList = res |
| 3503 | case *LocalPreqEqCondition: |
| 3504 | cond.BgpConditions.LocalPrefEq = v.localPref |
| 3505 | case *MedEqCondition: |
| 3506 | cond.BgpConditions.MedEq = v.med |
| 3507 | } |
| 3508 | } |
| 3509 | return cond |
| 3510 | }(), |
| 3511 | Actions: func() oc.Actions { |
| 3512 | act := oc.Actions{} |
| 3513 | if s.RouteAction != nil && !reflect.ValueOf(s.RouteAction).IsNil() { |
| 3514 | a := s.RouteAction.(*RoutingAction) |
| 3515 | if a.AcceptRoute { |
| 3516 | act.RouteDisposition = oc.ROUTE_DISPOSITION_ACCEPT_ROUTE |
| 3517 | } else { |
no test coverage detected