Skip to content

Commit 7a9bf32

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 515de6e commit 7a9bf32

12 files changed

Lines changed: 228 additions & 4 deletions

‎api/core/v1alpha1/routingpolicy_types.go‎

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

217+
// CommunityOptions defines whether communities are added to the route's existing
218+
// set (ADD) or replace it (REPLACE).
219+
// +kubebuilder:validation:Enum=ADD;REPLACE
220+
type CommunityOptions string
221+
222+
const (
223+
// CommunityOptionsAdd appends the communities to the route's existing set.
224+
CommunityOptionsAdd CommunityOptions = "ADD"
225+
// CommunityOptionsReplace overwrites the route's communities with the configured set.
226+
CommunityOptionsReplace CommunityOptions = "REPLACE"
227+
)
228+
217229
// SetCommunityAction defines the action to set BGP standard communities.
218230
type SetCommunityAction struct {
219231
// Communities is the list of BGP standard communities to set.
@@ -222,6 +234,12 @@ type SetCommunityAction struct {
222234
// +required
223235
// +kubebuilder:validation:MinItems=1
224236
Communities []string `json:"communities"`
237+
238+
// Options controls whether the communities are added to the route's existing
239+
// communities (ADD) or replace them (REPLACE).
240+
// +optional
241+
// +kubebuilder:default=REPLACE
242+
Options CommunityOptions `json:"options,omitempty"`
225243
}
226244

227245
// SetExtCommunityAction defines the action to set BGP extended communities.
@@ -232,6 +250,12 @@ type SetExtCommunityAction struct {
232250
// +required
233251
// +kubebuilder:validation:MinItems=1
234252
Communities []string `json:"communities"`
253+
254+
// Options controls whether the communities are added to the route's existing
255+
// communities (ADD) or replace them (REPLACE).
256+
// +optional
257+
// +kubebuilder:default=REPLACE
258+
Options CommunityOptions `json:"options,omitempty"`
235259
}
236260

237261
// 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
@@ -2576,12 +2576,12 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure
25762576

25772577
if stmt.Actions.BgpActions != nil {
25782578
if stmt.Actions.BgpActions.SetCommunity != nil {
2579-
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
2579+
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Options); err != nil {
25802580
return err
25812581
}
25822582
}
25832583
if stmt.Actions.BgpActions.SetExtCommunity != nil {
2584-
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
2584+
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Options); err != nil {
25852585
return err
25862586
}
25872587
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package nxos
55

66
import (
7+
"github.com/ironcore-dev/network-operator/api/core/v1alpha1"
78
"github.com/ironcore-dev/network-operator/internal/transport/gnmiext"
89
)
910

@@ -26,11 +27,13 @@ type RouteMapEntry struct {
2627
Action Action `json:"action"`
2728
Order int32 `json:"order"`
2829
SrttItems struct {
30+
Additive AdminSt `json:"additive,omitempty"`
2931
ItemItems struct {
3032
ItemList gnmiext.List[ExtCommItem, *ExtCommItem] `json:"Item-list,omitzero"`
3133
} `json:"item-items,omitzero"`
3234
} `json:"srtt-items,omitzero"`
3335
SregcommItems struct {
36+
Additive AdminSt `json:"additive,omitempty"`
3437
NoCommAttr AdminSt `json:"noCommAttr"`
3538
ItemItems struct {
3639
ItemList gnmiext.List[string, *CommItem] `json:"Item-list,omitzero"`
@@ -72,7 +75,7 @@ type RouteMapEntry struct {
7275

7376
func (e *RouteMapEntry) Key() int32 { return e.Order }
7477

75-
func (e *RouteMapEntry) SetCommunities(communities []string) error {
78+
func (e *RouteMapEntry) SetCommunities(communities []string, options v1alpha1.CommunityOptions) error {
7679
for _, comm := range communities {
7780
c, err := Community(comm)
7881
if err != nil {
@@ -81,17 +84,23 @@ func (e *RouteMapEntry) SetCommunities(communities []string) error {
8184
e.SregcommItems.NoCommAttr = AdminStDisabled
8285
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: c})
8386
}
87+
if options == v1alpha1.CommunityOptionsAdd {
88+
e.SregcommItems.Additive = AdminStEnabled
89+
}
8490
return nil
8591
}
8692

87-
func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
93+
func (e *RouteMapEntry) SetExtCommunities(communities []string, options v1alpha1.CommunityOptions) error {
8894
for _, comm := range communities {
8995
c, err := RouteTarget(comm)
9096
if err != nil {
9197
return err
9298
}
9399
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: c, Scope: RtExtComScopeTransitive})
94100
}
101+
if options == v1alpha1.CommunityOptionsAdd {
102+
e.SrttItems.Additive = AdminStEnabled
103+
}
95104
return nil
96105
}
97106

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package nxos
55

6+
import "github.com/ironcore-dev/network-operator/api/core/v1alpha1"
7+
68
func init() {
79
e := &RouteMapEntry{}
810
e.Order = 10
@@ -139,4 +141,28 @@ func init() {
139141
comboRM.Name = "RM-COMBINED-MATCH"
140142
comboRM.EntItems.EntryList.Set(comboEntry)
141143
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)
142168
}
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)