From 42e3d2c6bdec268bdcfb9114ee18d5cb3405d43d Mon Sep 17 00:00:00 2001 From: Ivo Gosemann Date: Fri, 16 Oct 2026 14:11:31 +0200 Subject: [PATCH] add Match(Ext-)Communities to RoutingPolicy & NXOS support Signed-off-by: Ivo Gosemann --- api/core/v1alpha1/groupversion_info.go | 4 + api/core/v1alpha1/routingpolicy_types.go | 32 + api/core/v1alpha1/zz_generated.deepcopy.go | 26 + ...olicies.networking.metal.ironcore.dev.yaml | 64 ++ ...ng.metal.ironcore.dev_routingpolicies.yaml | 64 ++ config/samples/v1alpha1_routingpolicy.yaml | 52 ++ docs/api-reference/index.md | 38 ++ .../core/routingpolicy_controller.go | 169 +++++- .../core/routingpolicy_controller_test.go | 559 +++++++++++++++++- internal/provider/cisco/nxos/provider.go | 2 + internal/provider/cisco/nxos/routemap.go | 46 ++ internal/provider/cisco/nxos/routemap_test.go | 54 ++ .../testdata/route_map_combined_match.json | 48 ++ .../route_map_combined_match.json.txt | 5 + .../testdata/route_map_communityset_all.json | 29 + .../route_map_communityset_all.json.txt | 2 + .../testdata/route_map_communityset_any.json | 29 + .../route_map_communityset_any.json.txt | 2 + .../route_map_extcommunityset_all.json | 29 + .../route_map_extcommunityset_all.json.txt | 2 + .../route_map_extcommunityset_any.json | 29 + .../route_map_extcommunityset_any.json.txt | 2 + internal/provider/provider.go | 8 + .../routingpolicy.txtar | 114 ++++ 24 files changed, 1402 insertions(+), 7 deletions(-) create mode 100644 internal/provider/cisco/nxos/testdata/route_map_combined_match.json create mode 100644 internal/provider/cisco/nxos/testdata/route_map_combined_match.json.txt create mode 100644 internal/provider/cisco/nxos/testdata/route_map_communityset_all.json create mode 100644 internal/provider/cisco/nxos/testdata/route_map_communityset_all.json.txt create mode 100644 internal/provider/cisco/nxos/testdata/route_map_communityset_any.json create mode 100644 internal/provider/cisco/nxos/testdata/route_map_communityset_any.json.txt create mode 100644 internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json create mode 100644 internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json.txt create mode 100644 internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json create mode 100644 internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json.txt diff --git a/api/core/v1alpha1/groupversion_info.go b/api/core/v1alpha1/groupversion_info.go index a0df9acab..b841ffd39 100644 --- a/api/core/v1alpha1/groupversion_info.go +++ b/api/core/v1alpha1/groupversion_info.go @@ -289,6 +289,10 @@ const ( const ( // PrefixSetNotFoundReason indicates that a referenced PrefixSet was not found. PrefixSetNotFoundReason = "PrefixSetNotFound" + // CommunitySetNotFoundReason indicates that a referenced CommunitySet was not found. + CommunitySetNotFoundReason = "CommunitySetNotFound" + // InvalidCommunitySetTypeReason indicates that a referenced CommunitySet is of the wrong type (standard vs extended). + InvalidCommunitySetTypeReason = "InvalidCommunitySetType" // SecretNotFoundReason indicates that a referenced Secret was not found. SecretNotFoundReason = "SecretNotFound" // RemoteEndpointUnreachableReason indicates that the remote object storage endpoint is not reachable. diff --git a/api/core/v1alpha1/routingpolicy_types.go b/api/core/v1alpha1/routingpolicy_types.go index 4e234423e..2c1983c34 100644 --- a/api/core/v1alpha1/routingpolicy_types.go +++ b/api/core/v1alpha1/routingpolicy_types.go @@ -63,6 +63,14 @@ type PolicyConditions struct { // MatchPrefixSet matches routes against a PrefixSet resource. // +optional MatchPrefixSet *PrefixSetMatchCondition `json:"matchPrefixSet,omitempty"` + + // MatchCommunitySet matches routes against a CommunitySet resource. + // +optional + MatchCommunitySet *CommunitySetMatchCondition `json:"matchCommunitySet,omitempty"` + + // MatchExtendedCommunitySet matches routes against a CommunitySet resource of type Extended. + // +optional + MatchExtendedCommunitySet *CommunitySetMatchCondition `json:"matchExtendedCommunitySet,omitempty"` } // PrefixSetMatchCondition defines the condition for matching against a PrefixSet. @@ -73,6 +81,30 @@ type PrefixSetMatchCondition struct { PrefixSetRef LocalObjectReference `json:"prefixSetRef"` } +// CommunitySetMatchCondition defines the condition for matching against a CommunitySet. +type CommunitySetMatchCondition struct { + // CommunitySetRef references a CommunitySet in the same namespace. + // The CommunitySet must exist and belong to the same device. + // +required + CommunitySetRef LocalObjectReference `json:"communitySetRef"` + + // MatchSetOption defines if the route must match 'Any' or 'All' of the community members in the set. + // +optional + // +kubebuilder:default=Any + MatchSetOption MatchSetOption `json:"matchSetOption,omitempty"` +} + +// MatchSetOption defines how a route's attributes are compared against a referenced set. +// +kubebuilder:validation:Enum=Any;All +type MatchSetOption string + +const ( + // MatchSetOptionAny matches a route carrying at least one member of the referenced set. + MatchSetOptionAny MatchSetOption = "Any" + // MatchSetOptionAll matches only a route carrying every member of the referenced set. + MatchSetOptionAll MatchSetOption = "All" +) + // PolicyActions defines the actions to take when a policy statement matches. // +kubebuilder:validation:XValidation:rule="self.routeDisposition == 'AcceptRoute' || !has(self.bgpActions)",message="bgpActions cannot be specified when routeDisposition is RejectRoute" type PolicyActions struct { diff --git a/api/core/v1alpha1/zz_generated.deepcopy.go b/api/core/v1alpha1/zz_generated.deepcopy.go index 50819327a..49784dcb0 100644 --- a/api/core/v1alpha1/zz_generated.deepcopy.go +++ b/api/core/v1alpha1/zz_generated.deepcopy.go @@ -1334,6 +1334,22 @@ func (in *CommunitySetList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CommunitySetMatchCondition) DeepCopyInto(out *CommunitySetMatchCondition) { + *out = *in + out.CommunitySetRef = in.CommunitySetRef +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommunitySetMatchCondition. +func (in *CommunitySetMatchCondition) DeepCopy() *CommunitySetMatchCondition { + if in == nil { + return nil + } + out := new(CommunitySetMatchCondition) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CommunitySetSpec) DeepCopyInto(out *CommunitySetSpec) { *out = *in @@ -4034,6 +4050,16 @@ func (in *PolicyConditions) DeepCopyInto(out *PolicyConditions) { *out = new(PrefixSetMatchCondition) **out = **in } + if in.MatchCommunitySet != nil { + in, out := &in.MatchCommunitySet, &out.MatchCommunitySet + *out = new(CommunitySetMatchCondition) + **out = **in + } + if in.MatchExtendedCommunitySet != nil { + in, out := &in.MatchExtendedCommunitySet, &out.MatchExtendedCommunitySet + *out = new(CommunitySetMatchCondition) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PolicyConditions. diff --git a/charts/network-operator/templates/crd/routingpolicies.networking.metal.ironcore.dev.yaml b/charts/network-operator/templates/crd/routingpolicies.networking.metal.ironcore.dev.yaml index 122aaef88..16ce19744 100644 --- a/charts/network-operator/templates/crd/routingpolicies.networking.metal.ironcore.dev.yaml +++ b/charts/network-operator/templates/crd/routingpolicies.networking.metal.ironcore.dev.yaml @@ -270,6 +270,70 @@ spec: Conditions define the match criteria for this statement. If no conditions are specified, the statement matches all routes. properties: + matchCommunitySet: + description: MatchCommunitySet matches routes against a + CommunitySet resource. + properties: + communitySetRef: + description: |- + CommunitySetRef references a CommunitySet in the same namespace. + The CommunitySet must exist and belong to the same device. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + maxLength: 63 + minLength: 1 + type: string + required: + - name + type: object + x-kubernetes-map-type: atomic + matchSetOption: + default: Any + description: MatchSetOption defines if the route must + match 'Any' or 'All' of the community members in the + set. + enum: + - Any + - All + type: string + required: + - communitySetRef + type: object + matchExtendedCommunitySet: + description: MatchExtendedCommunitySet matches routes against + a CommunitySet resource of type Extended. + properties: + communitySetRef: + description: |- + CommunitySetRef references a CommunitySet in the same namespace. + The CommunitySet must exist and belong to the same device. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + maxLength: 63 + minLength: 1 + type: string + required: + - name + type: object + x-kubernetes-map-type: atomic + matchSetOption: + default: Any + description: MatchSetOption defines if the route must + match 'Any' or 'All' of the community members in the + set. + enum: + - Any + - All + type: string + required: + - communitySetRef + type: object matchPrefixSet: description: MatchPrefixSet matches routes against a PrefixSet resource. diff --git a/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml b/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml index 27bc8c122..12ea86c2a 100644 --- a/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml +++ b/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml @@ -267,6 +267,70 @@ spec: Conditions define the match criteria for this statement. If no conditions are specified, the statement matches all routes. properties: + matchCommunitySet: + description: MatchCommunitySet matches routes against a + CommunitySet resource. + properties: + communitySetRef: + description: |- + CommunitySetRef references a CommunitySet in the same namespace. + The CommunitySet must exist and belong to the same device. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + maxLength: 63 + minLength: 1 + type: string + required: + - name + type: object + x-kubernetes-map-type: atomic + matchSetOption: + default: Any + description: MatchSetOption defines if the route must + match 'Any' or 'All' of the community members in the + set. + enum: + - Any + - All + type: string + required: + - communitySetRef + type: object + matchExtendedCommunitySet: + description: MatchExtendedCommunitySet matches routes against + a CommunitySet resource of type Extended. + properties: + communitySetRef: + description: |- + CommunitySetRef references a CommunitySet in the same namespace. + The CommunitySet must exist and belong to the same device. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + maxLength: 63 + minLength: 1 + type: string + required: + - name + type: object + x-kubernetes-map-type: atomic + matchSetOption: + default: Any + description: MatchSetOption defines if the route must + match 'Any' or 'All' of the community members in the + set. + enum: + - Any + - All + type: string + required: + - communitySetRef + type: object matchPrefixSet: description: MatchPrefixSet matches routes against a PrefixSet resource. diff --git a/config/samples/v1alpha1_routingpolicy.yaml b/config/samples/v1alpha1_routingpolicy.yaml index 174c139d5..658514f72 100644 --- a/config/samples/v1alpha1_routingpolicy.yaml +++ b/config/samples/v1alpha1_routingpolicy.yaml @@ -72,6 +72,22 @@ spec: bgpActions: setASPath: asNumber: 65000 + - sequence: 80 + conditions: + matchCommunitySet: + communitySetRef: + name: communityset-regular + matchSetOptions: All + actions: + routeDisposition: AcceptRoute + - sequence: 90 + conditions: + matchExtendedCommunitySet: + communitySetRef: + name: communityset-extended + matchSetOptions: All + actions: + routeDisposition: AcceptRoute - sequence: 100 actions: routeDisposition: AcceptRoute @@ -129,3 +145,39 @@ spec: maskLengthRange: min: 25 max: 32 +--- +apiVersion: networking.metal.ironcore.dev/v1alpha1 +kind: CommunitySet +metadata: + labels: + app.kubernetes.io/name: network-operator + app.kubernetes.io/managed-by: kustomize + name: communityset-regular +spec: + deviceRef: + name: leaf1 + name: example-communityset + type: Standard + members: + - sequence: 5 + regex: "50000:[0-9][0-9]" + - sequence: 10 + regex: "65001:[0-9]+" +--- +apiVersion: networking.metal.ironcore.dev/v1alpha1 +kind: CommunitySet +metadata: + labels: + app.kubernetes.io/name: network-operator + app.kubernetes.io/managed-by: kustomize + name: communityset-extended +spec: + deviceRef: + name: leaf1 + name: example-extcommunityset + type: Extended + members: + - sequence: 5 + regex: "65200:[0-9][0-9]" + - sequence: 15 + regex: "65300:[0-9]+" diff --git a/docs/api-reference/index.md b/docs/api-reference/index.md index 5523fc29b..445427db0 100644 --- a/docs/api-reference/index.md +++ b/docs/api-reference/index.md @@ -1417,6 +1417,23 @@ CommunitySet is the Schema for the communitysets API. | `status` _[CommunitySetStatus](#communitysetstatus)_ | | | Optional: \{\}
| +#### CommunitySetMatchCondition + + + +CommunitySetMatchCondition defines the condition for matching against a CommunitySet. + + + +_Appears in:_ +- [PolicyConditions](#policyconditions) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `communitySetRef` _[LocalObjectReference](#localobjectreference)_ | CommunitySetRef references a CommunitySet in the same namespace.
The CommunitySet must exist and belong to the same device. | | Required: \{\}
| +| `matchSetOption` _[MatchSetOption](#matchsetoption)_ | MatchSetOption defines if the route must match 'Any' or 'All' of the community members in the set. | Any | Enum: [Any All]
Optional: \{\}
| + + #### CommunitySetSpec @@ -2919,6 +2936,7 @@ _Appears in:_ - [BannerSpec](#bannerspec) - [BorderGatewaySpec](#bordergatewayspec) - [CertificateSpec](#certificatespec) +- [CommunitySetMatchCondition](#communitysetmatchcondition) - [CommunitySetSpec](#communitysetspec) - [ConfigBackupSpec](#configbackupspec) - [ConsoleConnectionSpec](#consoleconnectionspec) @@ -3092,6 +3110,24 @@ _Appears in:_ | `max` _integer_ | Maximum mask length. | | Maximum: 128
Minimum: 0
Required: \{\}
| +#### MatchSetOption + +_Underlying type:_ _string_ + +MatchSetOption defines how a route's attributes are compared against a referenced set. + +_Validation:_ +- Enum: [Any All] + +_Appears in:_ +- [CommunitySetMatchCondition](#communitysetmatchcondition) + +| Field | Description | +| --- | --- | +| `Any` | MatchSetOptionAny matches a route carrying at least one member of the referenced set.
| +| `All` | MatchSetOptionAll matches only a route carrying every member of the referenced set.
| + + #### MultiChassis @@ -3647,6 +3683,8 @@ _Appears in:_ | Field | Description | Default | Validation | | --- | --- | --- | --- | | `matchPrefixSet` _[PrefixSetMatchCondition](#prefixsetmatchcondition)_ | MatchPrefixSet matches routes against a PrefixSet resource. | | Optional: \{\}
| +| `matchCommunitySet` _[CommunitySetMatchCondition](#communitysetmatchcondition)_ | MatchCommunitySet matches routes against a CommunitySet resource. | | Optional: \{\}
| +| `matchExtendedCommunitySet` _[CommunitySetMatchCondition](#communitysetmatchcondition)_ | MatchExtendedCommunitySet matches routes against a CommunitySet resource of type Extended. | | Optional: \{\}
| #### PolicyStatement diff --git a/internal/controller/core/routingpolicy_controller.go b/internal/controller/core/routingpolicy_controller.go index 86bd794c1..628be127c 100644 --- a/internal/controller/core/routingpolicy_controller.go +++ b/internal/controller/core/routingpolicy_controller.go @@ -55,6 +55,7 @@ type RoutingPolicyReconciler struct { // +kubebuilder:rbac:groups=networking.metal.ironcore.dev,resources=routingpolicies,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=networking.metal.ironcore.dev,resources=routingpolicies/status,verbs=get;update;patch // +kubebuilder:rbac:groups=networking.metal.ironcore.dev,resources=routingpolicies/finalizers,verbs=update +// +kubebuilder:rbac:groups=networking.metal.ironcore.dev,resources=communitysets,verbs=get;list;watch // +kubebuilder:rbac:groups=events.k8s.io,resources=events,verbs=create;patch // Reconcile is part of the main kubernetes reconciliation loop which aims to @@ -200,7 +201,11 @@ func (r *RoutingPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, nil } -var routingPolicyPrefixSetRefKey = ".spec.statements[].conditions.matchPrefixSet.prefixSetRef.name" +var ( + routingPolicyPrefixSetRefKey = ".spec.statements[].conditions.matchPrefixSet.prefixSetRef.name" + routingPolicyCommunitySetRefKey = ".spec.statements[].conditions.matchCommunitySet.communitySetRef.name" + routingPolicyExtendedCommunitySetRefKey = ".spec.statements[].conditions.matchExtendedCommunitySet.communitySetRef.name" +) // SetupWithManager sets up the controller with the Manager. func (r *RoutingPolicyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error { @@ -227,6 +232,38 @@ func (r *RoutingPolicyReconciler) SetupWithManager(ctx context.Context, mgr ctrl return err } + if err := mgr.GetFieldIndexer().IndexField(ctx, &v1alpha1.RoutingPolicy{}, routingPolicyCommunitySetRefKey, func(obj client.Object) []string { + rp := obj.(*v1alpha1.RoutingPolicy) + var names []string + for _, stmt := range rp.Spec.Statements { + if stmt.Conditions == nil { + continue + } + if stmt.Conditions.MatchCommunitySet != nil { + names = append(names, stmt.Conditions.MatchCommunitySet.CommunitySetRef.Name) + } + } + return names + }); err != nil { + return err + } + + if err := mgr.GetFieldIndexer().IndexField(ctx, &v1alpha1.RoutingPolicy{}, routingPolicyExtendedCommunitySetRefKey, func(obj client.Object) []string { + rp := obj.(*v1alpha1.RoutingPolicy) + var names []string + for _, stmt := range rp.Spec.Statements { + if stmt.Conditions == nil { + continue + } + if stmt.Conditions.MatchExtendedCommunitySet != nil { + names = append(names, stmt.Conditions.MatchExtendedCommunitySet.CommunitySetRef.Name) + } + } + return names + }); err != nil { + return err + } + if err := mgr.GetFieldIndexer().IndexField(ctx, &v1alpha1.RoutingPolicy{}, v1alpha1.DeviceRefIndexKey, func(obj client.Object) []string { o := obj.(*v1alpha1.RoutingPolicy) return []string{o.Spec.DeviceRef.Name} @@ -265,6 +302,20 @@ func (r *RoutingPolicyReconciler) SetupWithManager(ctx context.Context, mgr ctrl }, }), ). + // Watches enqueues RoutingPolicies for changes in referenced CommunitySet resources. + // Only triggers on create and delete events since CommunitySet names are immutable. + Watches( + &v1alpha1.CommunitySet{}, + handler.EnqueueRequestsFromMapFunc(r.communitySetToRoutingPolicy), + builder.WithPredicates(predicate.Funcs{ + UpdateFunc: func(e event.UpdateEvent) bool { + return false + }, + GenericFunc: func(e event.GenericEvent) bool { + return false + }, + }), + ). // Watches enqueues RoutingPolicies for updates in referenced Device resources. // Triggers on create, delete, and update events when the device's effective pause state changes. Watches( @@ -354,6 +405,46 @@ func (r *RoutingPolicyReconciler) reconcileStatements(ctx context.Context, s *ro PrefixSet: prefixSet, }) } + if stmt.Conditions != nil && stmt.Conditions.MatchCommunitySet != nil { + cs := stmt.Conditions.MatchCommunitySet + communitySet, err := r.reconcileCommunitySet(ctx, s, cs) + if err != nil { + return nil, err + } + if communitySet.Spec.Type != v1alpha1.CommunitySetTypeStandard { + conditions.Set(s.RoutingPolicy, metav1.Condition{ + Type: v1alpha1.ReadyCondition, + Status: metav1.ConditionFalse, + Reason: v1alpha1.InvalidCommunitySetTypeReason, + Message: fmt.Sprintf("CommunitySet for MatchCommunitySet condition must be of type Standard, but %q is of type %q", communitySet.Name, communitySet.Spec.Type), + }) + return nil, reconcile.TerminalError(fmt.Errorf("CommunitySet for MatchCommunitySet condition must be of type Standard, but %q is of type %q", communitySet.Name, communitySet.Spec.Type)) + } + cond = append(cond, provider.MatchCommunitySetCondition{ + CommunitySet: communitySet, + MatchAll: cs.MatchSetOption == v1alpha1.MatchSetOptionAll, + }) + } + if stmt.Conditions != nil && stmt.Conditions.MatchExtendedCommunitySet != nil { + cs := stmt.Conditions.MatchExtendedCommunitySet + communitySet, err := r.reconcileCommunitySet(ctx, s, cs) + if err != nil { + return nil, err + } + if communitySet.Spec.Type != v1alpha1.CommunitySetTypeExtended { + conditions.Set(s.RoutingPolicy, metav1.Condition{ + Type: v1alpha1.ReadyCondition, + Status: metav1.ConditionFalse, + Reason: v1alpha1.InvalidCommunitySetTypeReason, + Message: fmt.Sprintf("CommunitySet for MatchExtendedCommunitySet condition must be of type Extended, but %q is of type %q", communitySet.Name, communitySet.Spec.Type), + }) + return nil, reconcile.TerminalError(fmt.Errorf("CommunitySet for MatchExtendedCommunitySet condition must be of type Extended, but %q is of type %q", communitySet.Name, communitySet.Spec.Type)) + } + cond = append(cond, provider.MatchCommunitySetCondition{ + CommunitySet: communitySet, + MatchAll: cs.MatchSetOption == v1alpha1.MatchSetOptionAll, + }) + } statements = append(statements, provider.PolicyStatement{ Sequence: stmt.Sequence, @@ -399,6 +490,40 @@ func (r *RoutingPolicyReconciler) reconcilePrefixSet(ctx context.Context, s *rou return prefixSet, nil } +// reconcileCommunitySet ensures that the referenced CommunitySet exists and belongs to the same device as the RoutingPolicy. +func (r *RoutingPolicyReconciler) reconcileCommunitySet(ctx context.Context, s *routingPolicyScope, c *v1alpha1.CommunitySetMatchCondition) (*v1alpha1.CommunitySet, error) { + key := client.ObjectKey{ + Name: c.CommunitySetRef.Name, + Namespace: s.RoutingPolicy.Namespace, + } + + communitySet := new(v1alpha1.CommunitySet) + if err := r.Get(ctx, key, communitySet); err != nil { + if apierrors.IsNotFound(err) { + conditions.Set(s.RoutingPolicy, metav1.Condition{ + Type: v1alpha1.ReadyCondition, + Status: metav1.ConditionFalse, + Reason: v1alpha1.CommunitySetNotFoundReason, + Message: fmt.Sprintf("referenced CommunitySet %q not found", key), + }) + return nil, reconcile.TerminalError(fmt.Errorf("referenced CommunitySet %q not found", key)) + } + return nil, fmt.Errorf("failed to get referenced CommunitySet %q: %w", key, err) + } + + if communitySet.Spec.DeviceRef.Name != s.Device.Name { + conditions.Set(s.RoutingPolicy, metav1.Condition{ + Type: v1alpha1.ReadyCondition, + Status: metav1.ConditionFalse, + Reason: v1alpha1.CrossDeviceReferenceReason, + Message: fmt.Sprintf("referenced CommunitySet %q does not belong to device %q", communitySet.Name, s.Device.Name), + }) + return nil, reconcile.TerminalError(fmt.Errorf("referenced CommunitySet %q does not belong to device %q", communitySet.Name, s.Device.Name)) + } + + return communitySet, nil +} + func (r *RoutingPolicyReconciler) finalize(ctx context.Context, s *routingPolicyScope) (reterr error) { if err := s.Provider.Connect(ctx, s.Connection); err != nil { return fmt.Errorf("failed to connect to provider: %w", err) @@ -447,6 +572,48 @@ func (r *RoutingPolicyReconciler) prefixSetToRoutingPolicy(ctx context.Context, return requests } +// communitySetToRoutingPolicy is a [handler.MapFunc] to be used to enqueue requests for reconciliation +// for RoutingPolicies when their referenced CommunitySet(s) change. +func (r *RoutingPolicyReconciler) communitySetToRoutingPolicy(ctx context.Context, obj client.Object) []ctrl.Request { + communitySet, ok := obj.(*v1alpha1.CommunitySet) + if !ok { + panic(fmt.Sprintf("Expected a CommunitySet but got a %T", obj)) + } + + if communitySet.Spec.Type == v1alpha1.CommunitySetTypeExtended { + return r.getRoutingPoliciesForCommunitySet(ctx, communitySet, routingPolicyCommunitySetRefKey) + } + return r.getRoutingPoliciesForCommunitySet(ctx, communitySet, routingPolicyExtendedCommunitySetRefKey) +} + +func (r *RoutingPolicyReconciler) getRoutingPoliciesForCommunitySet(ctx context.Context, communitySet *v1alpha1.CommunitySet, indexKey string) []ctrl.Request { + log := ctrl.LoggerFrom(ctx, "CommunitySet", klog.KObj(communitySet)) + routingPolicies := new(v1alpha1.RoutingPolicyList) + if err := r.List(ctx, routingPolicies, client.InNamespace(communitySet.Namespace), client.MatchingFields{indexKey: communitySet.Spec.Name}); err != nil { + log.Error(err, "Failed to list RoutingPolicies") + return nil + } + + requests := []ctrl.Request{} + for i := range routingPolicies.Items { + rp := &routingPolicies.Items[i] + for _, stmt := range rp.Spec.Statements { + if stmt.Conditions != nil { + if stmt.Conditions.MatchCommunitySet != nil && stmt.Conditions.MatchCommunitySet.CommunitySetRef.Name == communitySet.Name { + log.V(2).Info("Enqueuing RoutingPolicy for reconciliation", "RoutingPolicy", klog.KObj(rp)) + requests = append(requests, ctrl.Request{ + Name: rp.Name, + Namespace: rp.Namespace, + }) + break + } + } + } + } + + return requests +} + // deviceToRoutingPolicies is a [handler.MapFunc] to be used to enqueue requests for reconciliation // for RoutingPolicies when their referenced Device's effective pause state changes. func (r *RoutingPolicyReconciler) deviceToRoutingPolicies(ctx context.Context, obj client.Object) []ctrl.Request { diff --git a/internal/controller/core/routingpolicy_controller_test.go b/internal/controller/core/routingpolicy_controller_test.go index 1814acf64..b689c52f7 100644 --- a/internal/controller/core/routingpolicy_controller_test.go +++ b/internal/controller/core/routingpolicy_controller_test.go @@ -20,13 +20,14 @@ import ( var _ = Describe("RoutingPolicy Controller", func() { Context("When reconciling a resource", func() { var ( - name string - key client.ObjectKey + name string + key client.ObjectKey + device *v1alpha1.Device ) BeforeEach(func() { By("Creating a Device resource for testing") - device := &v1alpha1.Device{ + device = &v1alpha1.Device{ GenerateName: "test-routingpolicy-", Namespace: metav1.NamespaceDefault, Spec: v1alpha1.DeviceSpec{ @@ -66,15 +67,23 @@ var _ = Describe("RoutingPolicy Controller", func() { g.Expect(errors.IsNotFound(err)).To(BeTrue()) }).Should(Succeed()) + By("Cleaning up the CommunitySet resource") + cs := &v1alpha1.CommunitySet{} + cs.Name = name + cs.Namespace = metav1.NamespaceDefault + Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, cs))).To(Succeed()) + By("Waiting for CommunitySet resource to be fully deleted") + Eventually(func(g Gomega) { + err := k8sClient.Get(ctx, client.ObjectKey{Name: name, Namespace: metav1.NamespaceDefault}, &v1alpha1.CommunitySet{}) + g.Expect(errors.IsNotFound(err)).To(BeTrue()) + }).Should(Succeed()) + By("Verifying the RoutingPolicy is removed from the provider") Eventually(func(g Gomega) { g.Expect(testDevices.StateFor(name).RoutingPolicies.Has(name)).To(BeFalse(), "Provider shouldn't have RoutingPolicy configured anymore") }).Should(Succeed()) By("Cleaning up the Device resource") - device := &v1alpha1.Device{} - device.Name = name - device.Namespace = metav1.NamespaceDefault Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, device))).To(Succeed()) }) @@ -403,5 +412,543 @@ var _ = Describe("RoutingPolicy Controller", func() { g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) }).Should(Succeed()) }) + + It("Should successfully reconcile a RoutingPolicy with CommunitySet match condition", func() { + By("Creating a CommunitySet resource") + cs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "CS-BLUE", + Type: v1alpha1.CommunitySetTypeStandard, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, cs)).To(Succeed()) + + By("Creating a RoutingPolicy with CommunitySet match condition using matchSetOptions ALL") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + MatchSetOption: v1alpha1.MatchSetOptionAll, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets successful status conditions") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionTrue)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + + By("Verifying the RoutingPolicy is configured in the provider") + Eventually(func(g Gomega) { + g.Expect(testDevices.StateFor(device.Name).RoutingPolicies.Has(name)).To(BeTrue(), "Provider should have RoutingPolicy configured") + }).Should(Succeed()) + }) + + It("Should handle non-existing CommunitySet reference", func() { + By("Creating a RoutingPolicy referencing non-existing CommunitySet") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: "non-existing-communityset"}, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets CommunitySet not found status") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionFalse)) + g.Expect(resource.Status.Conditions[0].Reason).To(Equal(v1alpha1.CommunitySetNotFoundReason)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + }) + + It("Should handle CommunitySet type Extended used for MatchCommunitySet condition", func() { + By("Creating a CommunitySet resource") + cs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "CS-BLUE", + Type: v1alpha1.CommunitySetTypeExtended, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, cs)).To(Succeed()) + By("Creating a RoutingPolicy referencing invalid CommunitySet for MatchExtendedCommunitySet condition") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets CommunitySet invalid status") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionFalse)) + g.Expect(resource.Status.Conditions[0].Reason).To(Equal(v1alpha1.InvalidCommunitySetTypeReason)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + }) + + It("Should handle CommunitySet on different device", func() { + By("Creating a CommunitySet on a different device") + cs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: "different-device"}, + Name: "CS-BLUE", + Type: v1alpha1.CommunitySetTypeStandard, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, cs)).To(Succeed()) + + By("Creating a RoutingPolicy referencing the cross-device CommunitySet") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + MatchSetOption: v1alpha1.MatchSetOptionAll, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets cross-device reference status") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionFalse)) + g.Expect(resource.Status.Conditions[0].Reason).To(Equal(v1alpha1.CrossDeviceReferenceReason)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + }) + + It("Should successfully reconcile a RoutingPolicy with ExtCommunitySet match condition", func() { + By("Creating an ExtCommunitySet resource") + ecs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "RT-BLUE", + Type: v1alpha1.CommunitySetTypeExtended, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, ecs)).To(Succeed()) + + By("Creating a RoutingPolicy with ExtCommunitySet match condition") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchExtendedCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets successful status conditions") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionTrue)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + + By("Verifying the RoutingPolicy is configured in the provider") + Eventually(func(g Gomega) { + g.Expect(testDevices.StateFor(device.Name).RoutingPolicies.Has(name)).To(BeTrue(), "Provider should have RoutingPolicy configured") + }).Should(Succeed()) + }) + + It("Should handle non-existing ExtCommunitySet reference", func() { + By("Creating a RoutingPolicy referencing non-existing ExtCommunitySet") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchExtendedCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: "non-existing-extcommunityset"}, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets ExtCommunitySet not found status") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionFalse)) + g.Expect(resource.Status.Conditions[0].Reason).To(Equal(v1alpha1.CommunitySetNotFoundReason)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + }) + + It("Should successfully reconcile a RoutingPolicy combining prefix, community and ext-community matches", func() { + By("Creating a PrefixSet resource") + ps := &v1alpha1.PrefixSet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.PrefixSetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "PL-DEVICE-V4", + Entries: []v1alpha1.PrefixEntry{ + { + Sequence: 10, + Prefix: v1alpha1.IPPrefix{Prefix: netip.MustParsePrefix("10.0.0.0/8")}, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, ps)).To(Succeed()) + + By("Creating a CommunitySet resource for standard community") + cs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "CS-BLUE", + Type: v1alpha1.CommunitySetTypeStandard, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, cs)).To(Succeed()) + + By("Creating an CommunitySet resource for extended community") + ecs := &v1alpha1.CommunitySet{ + Name: name + "-extended", + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "RT-BLUE", + Type: v1alpha1.CommunitySetTypeExtended, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, ecs)).To(Succeed()) + + By("Creating a RoutingPolicy combining all three match conditions in one statement") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchPrefixSet: &v1alpha1.PrefixSetMatchCondition{ + PrefixSetRef: v1alpha1.LocalObjectReference{Name: name}, + }, + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + }, + MatchExtendedCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name + "-extended"}, + MatchSetOption: v1alpha1.MatchSetOptionAll, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the controller sets successful status conditions") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionTrue)) + g.Expect(resource.Status.Conditions[1].Type).To(Equal(v1alpha1.PausedCondition)) + g.Expect(resource.Status.Conditions[1].Status).To(Equal(metav1.ConditionFalse)) + }).Should(Succeed()) + + By("Verifying the RoutingPolicy is configured in the provider") + Eventually(func(g Gomega) { + g.Expect(testDevices.StateFor(device.Name).RoutingPolicies.Has(name)).To(BeTrue(), "Provider should have RoutingPolicy configured") + }).Should(Succeed()) + }) + + It("Should re-evaluate the RoutingPolicy when CommunitySet membership changes", func() { + By("Creating a CommunitySet resource") + cs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "CS-BLUE", + Type: v1alpha1.CommunitySetTypeStandard, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, cs)).To(Succeed()) + + By("Creating a RoutingPolicy referencing the CommunitySet") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the RoutingPolicy is configured in the provider") + Eventually(func(g Gomega) { + g.Expect(testDevices.StateFor(device.Name).RoutingPolicies.Has(name)).To(BeTrue(), "Provider should have RoutingPolicy configured") + }).Should(Succeed()) + + By("Recording the current generation observed by the controller") + resource := &v1alpha1.RoutingPolicy{} + Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + var initialConditionTime metav1.Time + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).ToNot(BeEmpty()) + initialConditionTime = resource.Status.Conditions[0].LastTransitionTime + g.Expect(initialConditionTime.IsZero()).To(BeFalse()) + }).Should(Succeed()) + + By("Updating the CommunitySet membership") + Eventually(func(g Gomega) { + current := &v1alpha1.CommunitySet{} + g.Expect(k8sClient.Get(ctx, key, current)).To(Succeed()) + current.Spec.Members = []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}, {Sequence: 20, Regex: "65137:200"}} + g.Expect(k8sClient.Update(ctx, current)).To(Succeed()) + }).Should(Succeed()) + + By("Verifying the RoutingPolicy remains configured after the membership change") + Eventually(func(g Gomega) { + g.Expect(testDevices.StateFor(device.Name).RoutingPolicies.Has(name)).To(BeTrue(), "Provider should still have RoutingPolicy configured") + }).Should(Succeed()) + }) + + It("Should reconverge when a CommunitySet match condition is removed from a statement", func() { + By("Creating a CommunitySet resource") + cs := &v1alpha1.CommunitySet{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: "CS-BLUE", + Type: v1alpha1.CommunitySetTypeStandard, + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, cs)).To(Succeed()) + + By("Creating an ExtCommunitySet resource") + ecs := &v1alpha1.CommunitySet{ + Name: name + "-extended", + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.CommunitySetSpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Type: v1alpha1.CommunitySetTypeExtended, + Name: "RT-BLUE", + Members: []v1alpha1.CommunityMember{{Sequence: 10, Regex: "65137:100"}}, + }, + } + Expect(k8sClient.Create(ctx, ecs)).To(Succeed()) + + By("Creating a RoutingPolicy matching both the CommunitySet and ExtCommunitySet") + rp := &v1alpha1.RoutingPolicy{ + Name: name, + Namespace: metav1.NamespaceDefault, + Spec: v1alpha1.RoutingPolicySpec{ + DeviceRef: v1alpha1.LocalObjectReference{Name: name}, + Name: name, + Statements: []v1alpha1.PolicyStatement{ + { + Sequence: 10, + Conditions: &v1alpha1.PolicyConditions{ + MatchCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: name}, + }, + MatchExtendedCommunitySet: &v1alpha1.CommunitySetMatchCondition{ + CommunitySetRef: v1alpha1.LocalObjectReference{Name: ecs.Name}, + }, + }, + Actions: v1alpha1.PolicyActions{ + RouteDisposition: v1alpha1.AcceptRoute, + }, + }, + }, + }, + } + Expect(k8sClient.Create(ctx, rp)).To(Succeed()) + + By("Verifying the RoutingPolicy reaches Ready with both conditions") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Status.Conditions).To(HaveLen(2)) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionTrue)) + }).Should(Succeed()) + + By("Removing the matchCommunitySet condition from the statement") + Eventually(func(g Gomega) { + current := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, current)).To(Succeed()) + current.Spec.Statements[0].Conditions.MatchCommunitySet = nil + g.Expect(k8sClient.Update(ctx, current)).To(Succeed()) + }).Should(Succeed()) + + By("Deleting the CommunitySet to prove it is no longer referenced") + Expect(k8sClient.Delete(ctx, cs)).To(Succeed()) + + By("Verifying the RoutingPolicy stays Ready driven only by the remaining ExtCommunitySet match") + Eventually(func(g Gomega) { + resource := &v1alpha1.RoutingPolicy{} + g.Expect(k8sClient.Get(ctx, key, resource)).To(Succeed()) + g.Expect(resource.Spec.Statements[0].Conditions.MatchCommunitySet).To(BeNil()) + g.Expect(resource.Status.Conditions[0].Type).To(Equal(v1alpha1.ReadyCondition)) + g.Expect(resource.Status.Conditions[0].Status).To(Equal(metav1.ConditionTrue)) + }).Should(Succeed()) + + By("Verifying the RoutingPolicy remains configured in the provider") + Eventually(func(g Gomega) { + g.Expect(testDevices.StateFor(device.Name).RoutingPolicies.Has(name)).To(BeTrue(), "Provider should still have RoutingPolicy configured") + }).Should(Succeed()) + }) }) }) diff --git a/internal/provider/cisco/nxos/provider.go b/internal/provider/cisco/nxos/provider.go index 99ad6439b..3f837433b 100644 --- a/internal/provider/cisco/nxos/provider.go +++ b/internal/provider/cisco/nxos/provider.go @@ -2872,6 +2872,8 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure switch v := cond.(type) { case provider.MatchPrefixSetCondition: e.SetPrefixSet(v.PrefixSet.Spec.Name, v.PrefixSet.Is6()) + case provider.MatchCommunitySetCondition: + e.SetCommunitySet(v.CommunitySet.Spec.Name, v.CommunitySet.Spec.Type, v.MatchAll) default: return fmt.Errorf("routing policy: unsupported condition type %T", cond) } diff --git a/internal/provider/cisco/nxos/routemap.go b/internal/provider/cisco/nxos/routemap.go index 475ba7ee8..d0b3f433c 100644 --- a/internal/provider/cisco/nxos/routemap.go +++ b/internal/provider/cisco/nxos/routemap.go @@ -4,6 +4,7 @@ package nxos import ( + "github.com/ironcore-dev/network-operator/api/core/v1alpha1" "github.com/ironcore-dev/network-operator/internal/transport/gnmiext" ) @@ -41,6 +42,18 @@ type RouteMapEntry struct { RsRtDstAttList gnmiext.List[string, *RsRtDstAtt] `json:"RsRtDstAtt-list,omitzero"` } `json:"rsrtDstAtt-items,omitzero"` } `json:"mrtdst-items,omitzero"` + MregcommItems struct { + Criteria matchCriteria `json:"criteria"` + RsregCommAttItems struct { + RsRegCommAttList gnmiext.List[string, *RsCommAtt] `json:"RsRegCommAtt-list,omitzero"` + } `json:"rsregCommAtt-items,omitzero"` + } `json:"mregcomm-items,omitzero"` + MextcommItems struct { + Criteria matchCriteria `json:"criteria"` + RsextCommAttItems struct { + RsExtCommAttList gnmiext.List[string, *RsCommAtt] `json:"RsExtCommAtt-list,omitzero"` + } `json:"rsextCommAtt-items,omitzero"` + } `json:"mextcomm-items,omitzero"` SetASPathPrependItems struct { AS string `json:"as"` } `json:"setaspathprepend-items,omitzero"` @@ -91,12 +104,45 @@ func (e *RouteMapEntry) SetPrefixSet(name string, isV6 bool) { e.MrtdstItems.RsrtDstAttItems.RsRtDstAttList.Set(&RsRtDstAtt{TDn: tdn}) } +type matchCriteria string + +const ( + matchCriteriaExact matchCriteria = "exact" + matchCriteriaSubGroup matchCriteria = "sub-group" +) + +func (e *RouteMapEntry) SetCommunitySet(name string, t v1alpha1.CommunitySetType, all bool) { + if t == v1alpha1.CommunitySetTypeStandard { + e.MregcommItems.RsregCommAttItems.RsRegCommAttList.Set(&RsCommAtt{ + TDn: "/System/rpm-items/rtregcom-items/Rule-list[name='" + name + "']", + }) + e.MregcommItems.Criteria = matchCriteriaSubGroup + if all { + e.MregcommItems.Criteria = matchCriteriaExact + } + } else { + e.MextcommItems.RsextCommAttItems.RsExtCommAttList.Set(&RsCommAtt{ + TDn: "/System/rpm-items/rtextcom-items/Rule-list[name='" + name + "']", + }) + e.MextcommItems.Criteria = matchCriteriaSubGroup + if all { + e.MextcommItems.Criteria = matchCriteriaExact + } + } +} + type RsRtDstAtt struct { TDn string `json:"tDn"` } func (r *RsRtDstAtt) Key() string { return r.TDn } +type RsCommAtt struct { + TDn string `json:"tDn"` +} + +func (r *RsCommAtt) Key() string { return r.TDn } + type CommItem struct { Community string `json:"community"` } diff --git a/internal/provider/cisco/nxos/routemap_test.go b/internal/provider/cisco/nxos/routemap_test.go index a08ae2018..bf1b3fe14 100644 --- a/internal/provider/cisco/nxos/routemap_test.go +++ b/internal/provider/cisco/nxos/routemap_test.go @@ -3,6 +3,8 @@ package nxos +import "github.com/ironcore-dev/network-operator/api/core/v1alpha1" + func init() { e := &RouteMapEntry{} e.Order = 10 @@ -87,4 +89,56 @@ func init() { pfxV6RM.Name = "RM-PREFIXSET-V6" pfxV6RM.EntItems.EntryList.Set(pfxV6Entry) Register("route_map_prefixset_v6", pfxV6RM) + + commAnyEntry := &RouteMapEntry{} + commAnyEntry.Order = 10 + commAnyEntry.Action = ActionPermit + commAnyEntry.SetCommunitySet("CS-BLUE", v1alpha1.CommunitySetTypeStandard, false) + + commAnyRM := &RouteMap{} + commAnyRM.Name = "RM-COMMUNITYSET-ANY" + commAnyRM.EntItems.EntryList.Set(commAnyEntry) + Register("route_map_communityset_any", commAnyRM) + + commAllEntry := &RouteMapEntry{} + commAllEntry.Order = 10 + commAllEntry.Action = ActionPermit + commAllEntry.SetCommunitySet("CS-BLUE", v1alpha1.CommunitySetTypeStandard, true) + + commAllRM := &RouteMap{} + commAllRM.Name = "RM-COMMUNITYSET-ALL" + commAllRM.EntItems.EntryList.Set(commAllEntry) + Register("route_map_communityset_all", commAllRM) + + extCommAnyEntry := &RouteMapEntry{} + extCommAnyEntry.Order = 10 + extCommAnyEntry.Action = ActionPermit + extCommAnyEntry.SetCommunitySet("RT-BLUE", v1alpha1.CommunitySetTypeExtended, false) + + extCommAnyRM := &RouteMap{} + extCommAnyRM.Name = "RM-EXTCOMMUNITYSET-ANY" + extCommAnyRM.EntItems.EntryList.Set(extCommAnyEntry) + Register("route_map_extcommunityset_any", extCommAnyRM) + + extCommAllEntry := &RouteMapEntry{} + extCommAllEntry.Order = 10 + extCommAllEntry.Action = ActionPermit + extCommAllEntry.SetCommunitySet("RT-BLUE", v1alpha1.CommunitySetTypeExtended, true) + + extCommAllRM := &RouteMap{} + extCommAllRM.Name = "RM-EXTCOMMUNITYSET-ALL" + extCommAllRM.EntItems.EntryList.Set(extCommAllEntry) + Register("route_map_extcommunityset_all", extCommAllRM) + + comboEntry := &RouteMapEntry{} + comboEntry.Order = 10 + comboEntry.Action = ActionPermit + comboEntry.SetPrefixSet("PL-DEVICE-V4", false) + comboEntry.SetCommunitySet("CS-BLUE", v1alpha1.CommunitySetTypeStandard, false) + comboEntry.SetCommunitySet("RT-BLUE", v1alpha1.CommunitySetTypeExtended, true) + + comboRM := &RouteMap{} + comboRM.Name = "RM-COMBINED-MATCH" + comboRM.EntItems.EntryList.Set(comboEntry) + Register("route_map_combined_match", comboRM) } diff --git a/internal/provider/cisco/nxos/testdata/route_map_combined_match.json b/internal/provider/cisco/nxos/testdata/route_map_combined_match.json new file mode 100644 index 000000000..85c284ed4 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_combined_match.json @@ -0,0 +1,48 @@ +{ + "rpm-items": { + "rtmap-items": { + "Rule-list": [ + { + "name": "RM-COMBINED-MATCH", + "ent-items": { + "Entry-list": [ + { + "action": "permit", + "order": 10, + "mrtdst-items": { + "rsrtDstAtt-items": { + "RsRtDstAtt-list": [ + { + "tDn": "/System/rpm-items/pfxlistv4-items/RuleV4-list[name='PL-DEVICE-V4']" + } + ] + } + }, + "mregcomm-items": { + "criteria": "sub-group", + "rsregCommAtt-items": { + "RsRegCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtregcom-items/Rule-list[name='CS-BLUE']" + } + ] + } + }, + "mextcomm-items": { + "criteria": "exact", + "rsextCommAtt-items": { + "RsExtCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtextcom-items/Rule-list[name='RT-BLUE']" + } + ] + } + } + } + ] + } + } + ] + } + } +} diff --git a/internal/provider/cisco/nxos/testdata/route_map_combined_match.json.txt b/internal/provider/cisco/nxos/testdata/route_map_combined_match.json.txt new file mode 100644 index 000000000..9bedc4b9e --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_combined_match.json.txt @@ -0,0 +1,5 @@ +route-map RM-COMBINED-MATCH permit 10 + match ip address prefix-list PL-DEVICE-V4 + match community CS-BLUE CS-RED + match community CS-GREEN exact-match + match extcommunity RT-BLUE exact-match diff --git a/internal/provider/cisco/nxos/testdata/route_map_communityset_all.json b/internal/provider/cisco/nxos/testdata/route_map_communityset_all.json new file mode 100644 index 000000000..48ed23943 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_communityset_all.json @@ -0,0 +1,29 @@ +{ + "rpm-items": { + "rtmap-items": { + "Rule-list": [ + { + "name": "RM-COMMUNITYSET-ALL", + "ent-items": { + "Entry-list": [ + { + "action": "permit", + "order": 10, + "mregcomm-items": { + "criteria": "exact", + "rsregCommAtt-items": { + "RsRegCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtregcom-items/Rule-list[name='CS-BLUE']" + } + ] + } + } + } + ] + } + } + ] + } + } +} diff --git a/internal/provider/cisco/nxos/testdata/route_map_communityset_all.json.txt b/internal/provider/cisco/nxos/testdata/route_map_communityset_all.json.txt new file mode 100644 index 000000000..53d9fc754 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_communityset_all.json.txt @@ -0,0 +1,2 @@ +route-map RM-COMMUNITYSET-ALL permit 10 + match community CS-BLUE exact-match diff --git a/internal/provider/cisco/nxos/testdata/route_map_communityset_any.json b/internal/provider/cisco/nxos/testdata/route_map_communityset_any.json new file mode 100644 index 000000000..100f8f074 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_communityset_any.json @@ -0,0 +1,29 @@ +{ + "rpm-items": { + "rtmap-items": { + "Rule-list": [ + { + "name": "RM-COMMUNITYSET-ANY", + "ent-items": { + "Entry-list": [ + { + "action": "permit", + "order": 10, + "mregcomm-items": { + "criteria": "sub-group", + "rsregCommAtt-items": { + "RsRegCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtregcom-items/Rule-list[name='CS-BLUE']" + } + ] + } + } + } + ] + } + } + ] + } + } +} diff --git a/internal/provider/cisco/nxos/testdata/route_map_communityset_any.json.txt b/internal/provider/cisco/nxos/testdata/route_map_communityset_any.json.txt new file mode 100644 index 000000000..162225b11 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_communityset_any.json.txt @@ -0,0 +1,2 @@ +route-map RM-COMMUNITYSET-ANY permit 10 + match community CS-BLUE diff --git a/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json new file mode 100644 index 000000000..1bea3d6c3 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json @@ -0,0 +1,29 @@ +{ + "rpm-items": { + "rtmap-items": { + "Rule-list": [ + { + "name": "RM-EXTCOMMUNITYSET-ALL", + "ent-items": { + "Entry-list": [ + { + "action": "permit", + "order": 10, + "mextcomm-items": { + "criteria": "exact", + "rsextCommAtt-items": { + "RsExtCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtextcom-items/Rule-list[name='RT-BLUE']" + } + ] + } + } + } + ] + } + } + ] + } + } +} diff --git a/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json.txt b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json.txt new file mode 100644 index 000000000..6a941ad1e --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_all.json.txt @@ -0,0 +1,2 @@ +route-map RM-EXTCOMMUNITYSET-ALL permit 10 + match extcommunity RT-BLUE exact-match diff --git a/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json new file mode 100644 index 000000000..d2f5128c4 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json @@ -0,0 +1,29 @@ +{ + "rpm-items": { + "rtmap-items": { + "Rule-list": [ + { + "name": "RM-EXTCOMMUNITYSET-ANY", + "ent-items": { + "Entry-list": [ + { + "action": "permit", + "order": 10, + "mextcomm-items": { + "criteria": "sub-group", + "rsextCommAtt-items": { + "RsExtCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtextcom-items/Rule-list[name='RT-BLUE']" + } + ] + } + } + } + ] + } + } + ] + } + } +} diff --git a/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json.txt b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json.txt new file mode 100644 index 000000000..9f335db62 --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/route_map_extcommunityset_any.json.txt @@ -0,0 +1,2 @@ +route-map RM-EXTCOMMUNITYSET-ANY permit 10 + match extcommunity RT-BLUE diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 3ac7d4550..0397e1e95 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -760,6 +760,14 @@ type MatchPrefixSetCondition struct { func (MatchPrefixSetCondition) isPolicyCondition() {} +type MatchCommunitySetCondition struct { + CommunitySet *v1alpha1.CommunitySet + // MatchAll is true when matchSetOptions is All (criteria "exact"); false for Any. + MatchAll bool +} + +func (MatchCommunitySetCondition) isPolicyCondition() {} + type DeleteRoutingPolicyRequest struct { Name string } diff --git a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/routingpolicy.txtar b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/routingpolicy.txtar index 7f2d8460f..40c111325 100644 --- a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/routingpolicy.txtar +++ b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/routingpolicy.txtar @@ -26,6 +26,36 @@ spec: - sequence: 10 prefix: "2001:db8::/32" +-- communitysets/test-communityset -- +apiVersion: networking.metal.ironcore.dev/v1alpha1 +kind: CommunitySet +metadata: + name: test-communityset + namespace: default +spec: + deviceRef: + name: device + name: BGP-COMMUNITY + type: Standard + members: + - sequence: 5 + regex: "50000:[0-9][0-9]" + +-- extcommunitysets/test-extcommunityset -- +apiVersion: networking.metal.ironcore.dev/v1alpha1 +kind: CommunitySet +metadata: + name: test-extcommunityset + namespace: default +spec: + deviceRef: + name: device + name: BGP-EXT-COMMUNITY + type: Extended + members: + - sequence: 5 + regex: "65200:[0-9][0-9]" + -- routingpolicies/rm-import -- apiVersion: networking.metal.ironcore.dev/v1alpha1 kind: RoutingPolicy @@ -51,6 +81,22 @@ spec: name: test-prefixset-v6 actions: routeDisposition: AcceptRoute + - sequence: 30 + conditions: + matchCommunitySet: + communitySetRef: + name: test-communityset + matchSetOption: All + actions: + routeDisposition: AcceptRoute + - sequence: 40 + conditions: + matchExtendedCommunitySet: + communitySetRef: + name: test-extcommunityset + matchSetOption: Any + actions: + routeDisposition: AcceptRoute -- state/preload -- { @@ -107,6 +153,40 @@ spec: } ] }, + "rtregcom-items": { + "Rule-list": [ + { + "name": "BGP-COMMUNITY", + "mode": "regex", + "ent-items": { + "Entry-list": [ + { + "order": 5, + "action": "permit", + "regex": "50000:[0-9][0-9]" + } + ] + } + } + ] + }, + "rtextcom-items": { + "Rule-list": [ + { + "name": "BGP-EXT-COMMUNITY", + "mode": "regex", + "ent-items": { + "Entry-list": [ + { + "order": 5, + "action": "permit", + "regex": "65200:[0-9][0-9]" + } + ] + } + } + ] + }, "rtmap-items": { "Rule-list": [ { @@ -138,6 +218,34 @@ spec: ] } } + }, + { + "action": "permit", + "order": 30, + "mregcomm-items": { + "criteria": "exact", + "rsregCommAtt-items": { + "RsRegCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtregcom-items/Rule-list[name='BGP-COMMUNITY']" + } + ] + } + } + }, + { + "action": "permit", + "order": 40, + "mextcomm-items": { + "criteria":"sub-group", + "rsextCommAtt-items": { + "RsExtCommAtt-list": [ + { + "tDn": "/System/rpm-items/rtextcom-items/Rule-list[name='BGP-EXT-COMMUNITY']" + } + ] + } + } } ] } @@ -162,6 +270,12 @@ spec: "pfxlistv6-items": { "RuleV6-list": [] }, + "rtregcom-items": { + "Rule-list": [] + }, + "rtextcom-items": { + "Rule-list": [] + }, "rtmap-items": { "Rule-list": [] }