Skip to content

Commit 5ef44c6

Browse files
authored
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 e75317a commit 5ef44c6

12 files changed

Lines changed: 225 additions & 4 deletions

File tree

‎api/core/v1alpha1/routingpolicy_types.go‎

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

198+
// CommunityOptions defines whether communities are added to the route's existing
199+
// set (ADD) or replace it (REPLACE).
200+
// +kubebuilder:validation:Enum=ADD;REPLACE
201+
type CommunityOptions string
202+
203+
const (
204+
// CommunityOptionsAdd appends the communities to the route's existing set.
205+
CommunityOptionsAdd CommunityOptions = "ADD"
206+
// CommunityOptionsReplace overwrites the route's communities with the configured set.
207+
CommunityOptionsReplace CommunityOptions = "REPLACE"
208+
)
209+
198210
// SetCommunityAction defines the action to set BGP standard communities.
199211
type SetCommunityAction struct {
200212
// Communities is the list of BGP standard communities to set.
@@ -203,6 +215,12 @@ type SetCommunityAction struct {
203215
// +required
204216
// +kubebuilder:validation:MinItems=1
205217
Communities []string `json:"communities"`
218+
219+
// Options controls whether the communities are added to the route's existing
220+
// communities (ADD) or replace them (REPLACE).
221+
// +optional
222+
// +kubebuilder:default=REPLACE
223+
Options CommunityOptions `json:"options,omitempty"`
206224
}
207225

208226
// SetExtCommunityAction defines the action to set BGP extended communities.
@@ -213,6 +231,12 @@ type SetExtCommunityAction struct {
213231
// +required
214232
// +kubebuilder:validation:MinItems=1
215233
Communities []string `json:"communities"`
234+
235+
// Options controls whether the communities are added to the route's existing
236+
// communities (ADD) or replace them (REPLACE).
237+
// +optional
238+
// +kubebuilder:default=REPLACE
239+
Options CommunityOptions `json:"options,omitempty"`
216240
}
217241

218242
// 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+
options: ADD
2627
setExtCommunity:
2728
communities:
2829
- "65137:100"
30+
options: ADD
2931
- sequence: 20
3032
conditions:
3133
matchPrefixSet:

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

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

28222822
if stmt.Actions.BgpActions != nil {
28232823
if stmt.Actions.BgpActions.SetCommunity != nil {
2824-
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
2824+
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Options); err != nil {
28252825
return err
28262826
}
28272827
}
28282828
if stmt.Actions.BgpActions.SetExtCommunity != nil {
2829-
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
2829+
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Options); err != nil {
28302830
return err
28312831
}
28322832
}

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

Lines changed: 10 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,omitempty"`
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,omitempty"`
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, options v1alpha1.CommunityOptions) error {
7779
for _, comm := range communities {
7880
c, err := Community(comm)
7981
if err != nil {
@@ -82,17 +84,23 @@ func (e *RouteMapEntry) SetCommunities(communities []string) error {
8284
e.SregcommItems.NoCommAttr = AdminStDisabled
8385
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: c})
8486
}
87+
if options == v1alpha1.CommunityOptionsAdd {
88+
e.SregcommItems.Additive = AdminStEnabled
89+
}
8590
return nil
8691
}
8792

88-
func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
93+
func (e *RouteMapEntry) SetExtCommunities(communities []string, options v1alpha1.CommunityOptions) error {
8994
for _, comm := range communities {
9095
c, err := RouteTarget(comm)
9196
if err != nil {
9297
return err
9398
}
9499
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: c, Scope: RtExtComScopeTransitive})
95100
}
101+
if options == v1alpha1.CommunityOptionsAdd {
102+
e.SrttItems.Additive = AdminStEnabled
103+
}
96104
return nil
97105
}
98106

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,28 @@ func init() {
141141
comboRM.Name = "RM-COMBINED-MATCH"
142142
comboRM.EntItems.EntryList.Set(comboEntry)
143143
Register("route_map_combined_match", comboRM)
144+
145+
commAdditiveEntry := &RouteMapEntry{}
146+
commAdditiveEntry.Order = 10
147+
commAdditiveEntry.Action = ActionPermit
148+
if err := commAdditiveEntry.SetCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOptionsAdd); err != nil {
149+
panic(err)
150+
}
151+
152+
commAdditiveRM := &RouteMap{}
153+
commAdditiveRM.Name = "RM-COMMUNITY-ADDITIVE"
154+
commAdditiveRM.EntItems.EntryList.Set(commAdditiveEntry)
155+
Register("route_map_community_additive", commAdditiveRM)
156+
157+
extCommAdditiveEntry := &RouteMapEntry{}
158+
extCommAdditiveEntry.Order = 10
159+
extCommAdditiveEntry.Action = ActionPermit
160+
if err := extCommAdditiveEntry.SetExtCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOptionsAdd); err != nil {
161+
panic(err)
162+
}
163+
164+
extCommAdditiveRM := &RouteMap{}
165+
extCommAdditiveRM.Name = "RM-EXTCOMMUNITY-ADDITIVE"
166+
extCommAdditiveRM.EntItems.EntryList.Set(extCommAdditiveEntry)
167+
Register("route_map_extcommunity_additive", extCommAdditiveRM)
144168
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"rpm-items": {
3+
"rtmap-items": {
4+
"Rule-list": [
5+
{
6+
"name": "RM-COMMUNITY-ADDITIVE",
7+
"ent-items": {
8+
"Entry-list": [
9+
{
10+
"action": "permit",
11+
"order": 10,
12+
"sregcomm-items": {
13+
"additive": "enabled",
14+
"noCommAttr": "disabled",
15+
"item-items": {
16+
"Item-list": [
17+
{
18+
"community": "regular:as2-nn2:65000:10"
19+
},
20+
{
21+
"community": "regular:as2-nn2:65000:20"
22+
}
23+
]
24+
}
25+
}
26+
}
27+
]
28+
}
29+
}
30+
]
31+
}
32+
}
33+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
route-map RM-COMMUNITY-ADDITIVE permit 10
2+
set community 65000:10 65000:20 additive
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"rpm-items": {
3+
"rtmap-items": {
4+
"Rule-list": [
5+
{
6+
"name": "RM-EXTCOMMUNITY-ADDITIVE",
7+
"ent-items": {
8+
"Entry-list": [
9+
{
10+
"action": "permit",
11+
"order": 10,
12+
"srtt-items": {
13+
"additive": "enabled",
14+
"item-items": {
15+
"Item-list": [
16+
{
17+
"community": "route-target:as2-nn2:65000:10",
18+
"scope": "transitive"
19+
},
20+
{
21+
"community": "route-target:as2-nn2:65000:20",
22+
"scope": "transitive"
23+
}
24+
]
25+
}
26+
}
27+
}
28+
]
29+
}
30+
}
31+
]
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)