diff --git a/Tiltfile b/Tiltfile
index 833106ca9..8f07d1c8d 100644
--- a/Tiltfile
+++ b/Tiltfile
@@ -165,7 +165,7 @@ k8s_yaml('./config/samples/v1alpha1_prefixset.yaml')
k8s_resource(new_name='ccloud-prefixset', objects=['ccloud-prefixset:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
k8s_yaml('./config/samples/v1alpha1_routingpolicy.yaml')
-k8s_resource(new_name='bgp-import-policy', objects=['bgp-import-policy:routingpolicy', 'internal-networks:prefixset', 'partner-networks:prefixset', 'blocked-networks:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
+k8s_resource(new_name='bgp-import-policy', objects=['bgp-import-policy:routingpolicy', 'internal-networks:prefixset', 'partner-networks:prefixset', 'blocked-networks:prefixset', 'communityset-regular:communityset', 'communityset-extended:communityset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
k8s_yaml('./config/samples/cisco/nx/v1alpha1_vpcdomain.yaml')
k8s_resource(new_name='vpcdomain', objects=['leaf1-vpcdomain:vpcdomain', 'leaf1-vrfvpckeepalive:vrf', 'eth1-30:interface', 'vpc-peer-link:interfaceconfig', 'eth1-31:interface','eth1-32:interface', 'po1:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
diff --git a/api/core/v1alpha1/routingpolicy_types.go b/api/core/v1alpha1/routingpolicy_types.go
index 2c1983c34..b21b20247 100644
--- a/api/core/v1alpha1/routingpolicy_types.go
+++ b/api/core/v1alpha1/routingpolicy_types.go
@@ -197,6 +197,18 @@ type SetASPathReplace struct {
Replacement intstr.IntOrString `json:"replacement"`
}
+// CommunityOperation defines whether communities are added to the route's existing
+// set (Add) or replace it (Replace).
+// +kubebuilder:validation:Enum=Add;Replace
+type CommunityOperation string
+
+const (
+ // CommunityOperationAdd appends the communities to the route's existing set.
+ CommunityOperationAdd CommunityOperation = "Add"
+ // CommunityOperationReplace overwrites the route's communities with the configured set.
+ CommunityOperationReplace CommunityOperation = "Replace"
+)
+
// SetCommunityAction defines the action to set BGP standard communities.
type SetCommunityAction struct {
// Communities is the list of BGP standard communities to set.
@@ -205,6 +217,12 @@ type SetCommunityAction struct {
// +required
// +kubebuilder:validation:MinItems=1
Communities []string `json:"communities"`
+
+ // Operation controls whether attributes are added (Add) to the communities or
+ // if the communities attributes are replaced (Replace).
+ // +optional
+ // +kubebuilder:default=Replace
+ Operation CommunityOperation `json:"operation,omitempty"`
}
// SetExtCommunityAction defines the action to set BGP extended communities.
@@ -215,6 +233,12 @@ type SetExtCommunityAction struct {
// +required
// +kubebuilder:validation:MinItems=1
Communities []string `json:"communities"`
+
+ // Operation controls whether the communities are added to the route's existing
+ // communities (Add) or replace them (Replace).
+ // +optional
+ // +kubebuilder:default=Replace
+ Operation CommunityOperation `json:"operation,omitempty"`
}
// RoutingPolicyStatus defines the observed state of RoutingPolicy.
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 16ce19744..bb2729aa2 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
@@ -227,6 +227,15 @@ spec:
type: string
minItems: 1
type: array
+ operation:
+ default: Replace
+ description: |-
+ Operation controls whether attributes are added (Add) to the communities or
+ if the communities attributes are replaced (Replace).
+ enum:
+ - Add
+ - Replace
+ type: string
required:
- communities
type: object
@@ -243,6 +252,15 @@ spec:
type: string
minItems: 1
type: array
+ operation:
+ default: Replace
+ description: |-
+ Operation controls whether the communities are added to the route's existing
+ communities (Add) or replace them (Replace).
+ enum:
+ - Add
+ - Replace
+ type: string
required:
- communities
type: object
diff --git a/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml b/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml
index 12ea86c2a..1971bfc54 100644
--- a/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml
+++ b/config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml
@@ -224,6 +224,15 @@ spec:
type: string
minItems: 1
type: array
+ operation:
+ default: Replace
+ description: |-
+ Operation controls whether attributes are added (Add) to the communities or
+ if the communities attributes are replaced (Replace).
+ enum:
+ - Add
+ - Replace
+ type: string
required:
- communities
type: object
@@ -240,6 +249,15 @@ spec:
type: string
minItems: 1
type: array
+ operation:
+ default: Replace
+ description: |-
+ Operation controls whether the communities are added to the route's existing
+ communities (Add) or replace them (Replace).
+ enum:
+ - Add
+ - Replace
+ type: string
required:
- communities
type: object
diff --git a/config/samples/v1alpha1_routingpolicy.yaml b/config/samples/v1alpha1_routingpolicy.yaml
index 658514f72..483b609d8 100644
--- a/config/samples/v1alpha1_routingpolicy.yaml
+++ b/config/samples/v1alpha1_routingpolicy.yaml
@@ -23,9 +23,11 @@ spec:
communities:
- "65137:100"
- "65137:200"
+ operation: Add
setExtCommunity:
communities:
- "65137:100"
+ operation: Replace
- sequence: 20
conditions:
matchPrefixSet:
diff --git a/docs/api-reference/index.md b/docs/api-reference/index.md
index 445427db0..2c28e8f47 100644
--- a/docs/api-reference/index.md
+++ b/docs/api-reference/index.md
@@ -1398,6 +1398,26 @@ _Appears in:_
| `regex` _string_ | Regex is a POSIX extended regular expression matching BGP community values. | | MinLength: 1
Required: \{\}
|
+#### CommunityOperation
+
+_Underlying type:_ _string_
+
+CommunityOperation defines whether communities are added to the route's existing
+set (Add) or replace it (Replace).
+
+_Validation:_
+- Enum: [Add Replace]
+
+_Appears in:_
+- [SetCommunityAction](#setcommunityaction)
+- [SetExtCommunityAction](#setextcommunityaction)
+
+| Field | Description |
+| --- | --- |
+| `Add` | CommunityOperationAdd appends the communities to the route's existing set.
|
+| `Replace` | CommunityOperationReplace overwrites the route's communities with the configured set.
|
+
+
#### CommunitySet
@@ -4390,6 +4410,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `communities` _string array_ | Communities is the list of BGP standard communities to set.
The communities must be in the format defined by [RFC 1997].
[RFC 1997]: https://datatracker.ietf.org/doc/html/rfc1997 | | MinItems: 1
Required: \{\}
|
+| `operation` _[CommunityOperation](#communityoperation)_ | Operation controls whether attributes are added (Add) to the communities or
if the communities attributes are replaced (Replace). | Replace | Enum: [Add Replace]
Optional: \{\}
|
#### SetExtCommunityAction
@@ -4406,6 +4427,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `communities` _string array_ | Communities is the list of BGP extended communities to set.
The communities must be in the format defined by [RFC 4360].
[RFC 4360]: https://datatracker.ietf.org/doc/html/rfc4360 | | MinItems: 1
Required: \{\}
|
+| `operation` _[CommunityOperation](#communityoperation)_ | Operation controls whether the communities are added to the route's existing
communities (Add) or replace them (Replace). | Replace | Enum: [Add Replace]
Optional: \{\}
|
#### Severity
diff --git a/internal/provider/cisco/nxos/provider.go b/internal/provider/cisco/nxos/provider.go
index 3f837433b..fb8990ec5 100644
--- a/internal/provider/cisco/nxos/provider.go
+++ b/internal/provider/cisco/nxos/provider.go
@@ -2890,12 +2890,12 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure
if stmt.Actions.BgpActions != nil {
if stmt.Actions.BgpActions.SetCommunity != nil {
- if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
+ if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Operation); err != nil {
return err
}
}
if stmt.Actions.BgpActions.SetExtCommunity != nil {
- if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
+ if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Operation); err != nil {
return err
}
}
diff --git a/internal/provider/cisco/nxos/routemap.go b/internal/provider/cisco/nxos/routemap.go
index d0b3f433c..92e76d4a8 100644
--- a/internal/provider/cisco/nxos/routemap.go
+++ b/internal/provider/cisco/nxos/routemap.go
@@ -27,11 +27,13 @@ type RouteMapEntry struct {
Action Action `json:"action"`
Order int32 `json:"order"`
SrttItems struct {
+ Additive AdminSt `json:"additive"`
ItemItems struct {
ItemList gnmiext.List[ExtCommItem, *ExtCommItem] `json:"Item-list,omitzero"`
} `json:"item-items,omitzero"`
} `json:"srtt-items,omitzero"`
SregcommItems struct {
+ Additive AdminSt `json:"additive"`
NoCommAttr AdminSt `json:"noCommAttr"`
ItemItems struct {
ItemList gnmiext.List[string, *CommItem] `json:"Item-list,omitzero"`
@@ -73,7 +75,7 @@ type RouteMapEntry struct {
func (e *RouteMapEntry) Key() int32 { return e.Order }
-func (e *RouteMapEntry) SetCommunities(communities []string) error {
+func (e *RouteMapEntry) SetCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
for _, comm := range communities {
c, err := Community(comm)
if err != nil {
@@ -82,10 +84,14 @@ func (e *RouteMapEntry) SetCommunities(communities []string) error {
e.SregcommItems.NoCommAttr = AdminStDisabled
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: c})
}
+ e.SregcommItems.Additive = AdminStDisabled
+ if operation == v1alpha1.CommunityOperationAdd {
+ e.SregcommItems.Additive = AdminStEnabled
+ }
return nil
}
-func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
+func (e *RouteMapEntry) SetExtCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
for _, comm := range communities {
c, err := RouteTarget(comm)
if err != nil {
@@ -93,6 +99,10 @@ func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
}
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: c, Scope: RtExtComScopeTransitive})
}
+ e.SrttItems.Additive = AdminStDisabled
+ if operation == v1alpha1.CommunityOperationAdd {
+ e.SrttItems.Additive = AdminStEnabled
+ }
return nil
}
diff --git a/internal/provider/cisco/nxos/routemap_test.go b/internal/provider/cisco/nxos/routemap_test.go
index bf1b3fe14..53190273b 100644
--- a/internal/provider/cisco/nxos/routemap_test.go
+++ b/internal/provider/cisco/nxos/routemap_test.go
@@ -9,7 +9,9 @@ func init() {
e := &RouteMapEntry{}
e.Order = 10
e.Action = ActionPermit
+ e.SrttItems.Additive = AdminStDisabled
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: "route-target:as2-nn2:65137:107", Scope: RtExtComScopeTransitive})
+ e.SregcommItems.Additive = AdminStDisabled
e.SregcommItems.NoCommAttr = AdminStDisabled
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: "regular:as2-nn2:65137:107"})
e.MrtdstItems.RsrtDstAttItems.RsRtDstAttList.Set(&RsRtDstAtt{TDn: "/System/rpm-items/pfxlistv4-items/RuleV4-list[name='PL-CLOUD07']"})
@@ -141,4 +143,28 @@ func init() {
comboRM.Name = "RM-COMBINED-MATCH"
comboRM.EntItems.EntryList.Set(comboEntry)
Register("route_map_combined_match", comboRM)
+
+ commAdditiveEntry := &RouteMapEntry{}
+ commAdditiveEntry.Order = 10
+ commAdditiveEntry.Action = ActionPermit
+ if err := commAdditiveEntry.SetCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
+ panic(err)
+ }
+
+ commAdditiveRM := &RouteMap{}
+ commAdditiveRM.Name = "RM-COMMUNITY-ADDITIVE"
+ commAdditiveRM.EntItems.EntryList.Set(commAdditiveEntry)
+ Register("route_map_community_additive", commAdditiveRM)
+
+ extCommAdditiveEntry := &RouteMapEntry{}
+ extCommAdditiveEntry.Order = 10
+ extCommAdditiveEntry.Action = ActionPermit
+ if err := extCommAdditiveEntry.SetExtCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
+ panic(err)
+ }
+
+ extCommAdditiveRM := &RouteMap{}
+ extCommAdditiveRM.Name = "RM-EXTCOMMUNITY-ADDITIVE"
+ extCommAdditiveRM.EntItems.EntryList.Set(extCommAdditiveEntry)
+ Register("route_map_extcommunity_additive", extCommAdditiveRM)
}
diff --git a/internal/provider/cisco/nxos/testdata/route_map.json b/internal/provider/cisco/nxos/testdata/route_map.json
index 89ab01b6c..ef3a60c0a 100644
--- a/internal/provider/cisco/nxos/testdata/route_map.json
+++ b/internal/provider/cisco/nxos/testdata/route_map.json
@@ -10,6 +10,7 @@
"action": "permit",
"order": 10,
"srtt-items": {
+ "additive": "disabled",
"item-items": {
"Item-list": [
{
@@ -20,6 +21,7 @@
}
},
"sregcomm-items": {
+ "additive": "disabled",
"noCommAttr": "disabled",
"item-items": {
"Item-list": [
diff --git a/internal/provider/cisco/nxos/testdata/route_map_community_additive.json b/internal/provider/cisco/nxos/testdata/route_map_community_additive.json
new file mode 100644
index 000000000..ed6739768
--- /dev/null
+++ b/internal/provider/cisco/nxos/testdata/route_map_community_additive.json
@@ -0,0 +1,33 @@
+{
+ "rpm-items": {
+ "rtmap-items": {
+ "Rule-list": [
+ {
+ "name": "RM-COMMUNITY-ADDITIVE",
+ "ent-items": {
+ "Entry-list": [
+ {
+ "action": "permit",
+ "order": 10,
+ "sregcomm-items": {
+ "additive": "enabled",
+ "noCommAttr": "disabled",
+ "item-items": {
+ "Item-list": [
+ {
+ "community": "regular:as2-nn2:65000:10"
+ },
+ {
+ "community": "regular:as2-nn2:65000:20"
+ }
+ ]
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/internal/provider/cisco/nxos/testdata/route_map_community_additive.json.txt b/internal/provider/cisco/nxos/testdata/route_map_community_additive.json.txt
new file mode 100644
index 000000000..287df5916
--- /dev/null
+++ b/internal/provider/cisco/nxos/testdata/route_map_community_additive.json.txt
@@ -0,0 +1,2 @@
+route-map RM-COMMUNITY-ADDITIVE permit 10
+ set community 65000:10 65000:20 additive
diff --git a/internal/provider/cisco/nxos/testdata/route_map_extcommunity_additive.json b/internal/provider/cisco/nxos/testdata/route_map_extcommunity_additive.json
new file mode 100644
index 000000000..eac70fd81
--- /dev/null
+++ b/internal/provider/cisco/nxos/testdata/route_map_extcommunity_additive.json
@@ -0,0 +1,34 @@
+{
+ "rpm-items": {
+ "rtmap-items": {
+ "Rule-list": [
+ {
+ "name": "RM-EXTCOMMUNITY-ADDITIVE",
+ "ent-items": {
+ "Entry-list": [
+ {
+ "action": "permit",
+ "order": 10,
+ "srtt-items": {
+ "additive": "enabled",
+ "item-items": {
+ "Item-list": [
+ {
+ "community": "route-target:as2-nn2:65000:10",
+ "scope": "transitive"
+ },
+ {
+ "community": "route-target:as2-nn2:65000:20",
+ "scope": "transitive"
+ }
+ ]
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/internal/provider/cisco/nxos/testdata/route_map_extcommunity_additive.json.txt b/internal/provider/cisco/nxos/testdata/route_map_extcommunity_additive.json.txt
new file mode 100644
index 000000000..db8f936dd
--- /dev/null
+++ b/internal/provider/cisco/nxos/testdata/route_map_extcommunity_additive.json.txt
@@ -0,0 +1,2 @@
+route-map RM-EXTCOMMUNITY-ADDITIVE permit 10
+ set extcommunity rt 65000:10 65000:20 additive
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 40c111325..d60f84fff 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
@@ -97,6 +97,20 @@ spec:
matchSetOption: Any
actions:
routeDisposition: AcceptRoute
+ - sequence: 50
+ actions:
+ routeDisposition: AcceptRoute
+ bgpActions:
+ setCommunity:
+ communities:
+ - "65000:10"
+ - "65000:20"
+ operation: Add
+ setExtCommunity:
+ communities:
+ - "65000:10"
+ - "65000:20"
+ operation: Replace
-- state/preload --
{
@@ -246,6 +260,39 @@ spec:
]
}
}
+ },
+ {
+ "action": "permit",
+ "order": 50,
+ "srtt-items": {
+ "additive": "disabled",
+ "item-items": {
+ "Item-list": [
+ {
+ "community": "route-target:as2-nn2:65000:10",
+ "scope": "transitive"
+ },
+ {
+ "community": "route-target:as2-nn2:65000:20",
+ "scope": "transitive"
+ }
+ ]
+ }
+ },
+ "sregcomm-items": {
+ "additive": "enabled",
+ "noCommAttr": "disabled",
+ "item-items": {
+ "Item-list": [
+ {
+ "community": "regular:as2-nn2:65000:10"
+ },
+ {
+ "community": "regular:as2-nn2:65000:20"
+ }
+ ]
+ }
+ }
}
]
}