Skip to content

Commit fd4a43b

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 625542a commit fd4a43b

14 files changed

Lines changed: 250 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
@@ -196,6 +196,18 @@ type SetASPathReplace struct {
196196
Replacement intstr.IntOrString `json:"replacement"`
197197
}
198198

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

209227
// SetExtCommunityAction defines the action to set BGP extended communities.
@@ -214,6 +232,12 @@ type SetExtCommunityAction struct {
214232
// +required
215233
// +kubebuilder:validation:MinItems=1
216234
Communities []string `json:"communities"`
235+
236+
// Options controls whether the communities are added to the route's existing
237+
// communities (Add) or replace them (Replace).
238+
// +optional
239+
// +kubebuilder:default=Replace
240+
Options CommunityOperation `json:"options,omitempty"`
217241
}
218242

219243
// 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: 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
@@ -2855,12 +2855,12 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure
28552855

28562856
if stmt.Actions.BgpActions != nil {
28572857
if stmt.Actions.BgpActions.SetCommunity != nil {
2858-
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
2858+
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Options); err != nil {
28592859
return err
28602860
}
28612861
}
28622862
if stmt.Actions.BgpActions.SetExtCommunity != nil {
2863-
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
2863+
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Options); err != nil {
28642864
return err
28652865
}
28662866
}

‎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.CommunityOptionsAdd {
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.CommunityOptionsAdd {
104+
e.SrttItems.Additive = AdminStEnabled
105+
}
96106
return nil
97107
}
98108

‎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+
}

0 commit comments

Comments
 (0)