Skip to content

Commit 7fa3dfd

Browse files
committed
add support for set community additive
add option to enable setting community and extcommunity additive instead of replacing the list. Signed-off-by: Ivo Gosemann <ivo.gosemann@sap.com>
1 parent 51dd0f4 commit 7fa3dfd

15 files changed

Lines changed: 245 additions & 5 deletions

File tree

‎Tiltfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ k8s_yaml('./config/samples/v1alpha1_prefixset.yaml')
165165
k8s_resource(new_name='ccloud-prefixset', objects=['ccloud-prefixset:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
166166

167167
k8s_yaml('./config/samples/v1alpha1_routingpolicy.yaml')
168-
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'])
168+
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'])
169169

170170
k8s_yaml('./config/samples/cisco/nx/v1alpha1_vpcdomain.yaml')
171171
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'])

‎api/core/v1alpha1/routingpolicy_types.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ type SetASPathReplace struct {
197197
Replacement intstr.IntOrString `json:"replacement"`
198198
}
199199

200+
// CommunityOperation defines whether communities are added to the route's existing
201+
// set (Add) or replace it (Replace).
202+
// +kubebuilder:validation:Enum=Add;Replace
203+
type CommunityOperation string
204+
205+
const (
206+
// CommunityOperationAdd appends the communities to the route's existing set.
207+
CommunityOperationAdd CommunityOperation = "Add"
208+
// CommunityOperationReplace overwrites the route's communities with the configured set.
209+
CommunityOperationReplace CommunityOperation = "Replace"
210+
)
211+
200212
// SetCommunityAction defines the action to set BGP standard communities.
201213
type SetCommunityAction struct {
202214
// Communities is the list of BGP standard communities to set.
@@ -205,6 +217,12 @@ type SetCommunityAction struct {
205217
// +required
206218
// +kubebuilder:validation:MinItems=1
207219
Communities []string `json:"communities"`
220+
221+
// Operation controls whether attributes are added (Add) to the communities or
222+
// if the communities attributes are replaced (Replace).
223+
// +optional
224+
// +kubebuilder:default=Replace
225+
Operation CommunityOperation `json:"operation,omitempty"`
208226
}
209227

210228
// SetExtCommunityAction defines the action to set BGP extended communities.
@@ -215,6 +233,12 @@ type SetExtCommunityAction struct {
215233
// +required
216234
// +kubebuilder:validation:MinItems=1
217235
Communities []string `json:"communities"`
236+
237+
// Operation controls whether the communities are added to the route's existing
238+
// communities (Add) or replace them (Replace).
239+
// +optional
240+
// +kubebuilder:default=Replace
241+
Operation CommunityOperation `json:"operation,omitempty"`
218242
}
219243

220244
// RoutingPolicyStatus defines the observed state of RoutingPolicy.

‎charts/network-operator/templates/crd/routingpolicies.networking.metal.ironcore.dev.yaml‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/samples/v1alpha1_routingpolicy.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ spec:
2323
communities:
2424
- "65137:100"
2525
- "65137:200"
26+
operation: Add
2627
setExtCommunity:
2728
communities:
2829
- "65137:100"
30+
operation: Replace
2931
- sequence: 20
3032
conditions:
3133
matchPrefixSet:

‎docs/api-reference/index.md‎

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/provider/cisco/nxos/provider.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,12 +2888,12 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure
28882888

28892889
if stmt.Actions.BgpActions != nil {
28902890
if stmt.Actions.BgpActions.SetCommunity != nil {
2891-
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
2891+
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Operation); err != nil {
28922892
return err
28932893
}
28942894
}
28952895
if stmt.Actions.BgpActions.SetExtCommunity != nil {
2896-
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
2896+
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Operation); err != nil {
28972897
return err
28982898
}
28992899
}

‎internal/provider/cisco/nxos/routemap.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ type RouteMapEntry struct {
2727
Action Action `json:"action"`
2828
Order int32 `json:"order"`
2929
SrttItems struct {
30+
Additive AdminSt `json:"additive"`
3031
ItemItems struct {
3132
ItemList gnmiext.List[ExtCommItem, *ExtCommItem] `json:"Item-list,omitzero"`
3233
} `json:"item-items,omitzero"`
3334
} `json:"srtt-items,omitzero"`
3435
SregcommItems struct {
36+
Additive AdminSt `json:"additive"`
3537
NoCommAttr AdminSt `json:"noCommAttr"`
3638
ItemItems struct {
3739
ItemList gnmiext.List[string, *CommItem] `json:"Item-list,omitzero"`
@@ -73,7 +75,7 @@ type RouteMapEntry struct {
7375

7476
func (e *RouteMapEntry) Key() int32 { return e.Order }
7577

76-
func (e *RouteMapEntry) SetCommunities(communities []string) error {
78+
func (e *RouteMapEntry) SetCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
7779
for _, comm := range communities {
7880
c, err := Community(comm)
7981
if err != nil {
@@ -82,17 +84,25 @@ func (e *RouteMapEntry) SetCommunities(communities []string) error {
8284
e.SregcommItems.NoCommAttr = AdminStDisabled
8385
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: c})
8486
}
87+
e.SregcommItems.Additive = AdminStDisabled
88+
if operation == v1alpha1.CommunityOperationAdd {
89+
e.SregcommItems.Additive = AdminStEnabled
90+
}
8591
return nil
8692
}
8793

88-
func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
94+
func (e *RouteMapEntry) SetExtCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
8995
for _, comm := range communities {
9096
c, err := RouteTarget(comm)
9197
if err != nil {
9298
return err
9399
}
94100
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: c, Scope: RtExtComScopeTransitive})
95101
}
102+
e.SrttItems.Additive = AdminStDisabled
103+
if operation == v1alpha1.CommunityOperationAdd {
104+
e.SrttItems.Additive = AdminStEnabled
105+
}
96106
return nil
97107
}
98108

‎internal/provider/cisco/nxos/routemap_test.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ func init() {
99
e := &RouteMapEntry{}
1010
e.Order = 10
1111
e.Action = ActionPermit
12+
e.SrttItems.Additive = AdminStDisabled
1213
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: "route-target:as2-nn2:65137:107", Scope: RtExtComScopeTransitive})
14+
e.SregcommItems.Additive = AdminStDisabled
1315
e.SregcommItems.NoCommAttr = AdminStDisabled
1416
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: "regular:as2-nn2:65137:107"})
1517
e.MrtdstItems.RsrtDstAttItems.RsRtDstAttList.Set(&RsRtDstAtt{TDn: "/System/rpm-items/pfxlistv4-items/RuleV4-list[name='PL-CLOUD07']"})
@@ -141,4 +143,28 @@ func init() {
141143
comboRM.Name = "RM-COMBINED-MATCH"
142144
comboRM.EntItems.EntryList.Set(comboEntry)
143145
Register("route_map_combined_match", comboRM)
146+
147+
commAdditiveEntry := &RouteMapEntry{}
148+
commAdditiveEntry.Order = 10
149+
commAdditiveEntry.Action = ActionPermit
150+
if err := commAdditiveEntry.SetCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
151+
panic(err)
152+
}
153+
154+
commAdditiveRM := &RouteMap{}
155+
commAdditiveRM.Name = "RM-COMMUNITY-ADDITIVE"
156+
commAdditiveRM.EntItems.EntryList.Set(commAdditiveEntry)
157+
Register("route_map_community_additive", commAdditiveRM)
158+
159+
extCommAdditiveEntry := &RouteMapEntry{}
160+
extCommAdditiveEntry.Order = 10
161+
extCommAdditiveEntry.Action = ActionPermit
162+
if err := extCommAdditiveEntry.SetExtCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
163+
panic(err)
164+
}
165+
166+
extCommAdditiveRM := &RouteMap{}
167+
extCommAdditiveRM.Name = "RM-EXTCOMMUNITY-ADDITIVE"
168+
extCommAdditiveRM.EntItems.EntryList.Set(extCommAdditiveEntry)
169+
Register("route_map_extcommunity_additive", extCommAdditiveRM)
144170
}

‎internal/provider/cisco/nxos/testdata/route_map.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"action": "permit",
1111
"order": 10,
1212
"srtt-items": {
13+
"additive": "disabled",
1314
"item-items": {
1415
"Item-list": [
1516
{
@@ -20,6 +21,7 @@
2021
}
2122
},
2223
"sregcomm-items": {
24+
"additive": "disabled",
2325
"noCommAttr": "disabled",
2426
"item-items": {
2527
"Item-list": [

0 commit comments

Comments
 (0)