Skip to content

Commit c5e1c01

Browse files
committed
Add setNextHop ipAddr action to RoutingPolicy BGP actions
1 parent 2f0a30e commit c5e1c01

14 files changed

Lines changed: 246 additions & 13 deletions

File tree

‎api/core/v1alpha1/routingpolicy_types.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const (
130130
)
131131

132132
// BgpActions defines BGP-specific actions for a policy statement.
133-
// +kubebuilder:validation:XValidation:rule="has(self.setCommunity) || has(self.setExtCommunity) || has(self.setASPath)",message="at least one BGP action must be specified"
133+
// +kubebuilder:validation:XValidation:rule="has(self.setCommunity) || has(self.setExtCommunity) || has(self.setASPath) || has(self.setNextHop)",message="at least one BGP action must be specified"
134134
type BgpActions struct {
135135
// SetCommunity configures BGP standard community attributes.
136136
// +optional
@@ -143,6 +143,17 @@ type BgpActions struct {
143143
// SetASPath configures modifications to the BGP AS path attribute.
144144
// +optional
145145
SetASPath *SetASPathAction `json:"setASPath,omitempty"`
146+
147+
// SetNextHop configures the BGP next-hop for advertised routes.
148+
// +optional
149+
SetNextHop *SetNextHopAction `json:"setNextHop,omitempty"`
150+
}
151+
152+
// SetNextHopAction defines how to replace the BGP next-hop for advertised routes.
153+
type SetNextHopAction struct {
154+
// IPAddr specifies the next-hop IP address to set for advertised routes.
155+
// +required
156+
IPAddr IPAddr `json:"ipAddr"`
146157
}
147158

148159
// SetASPathAction defines actions to modify the BGP AS path attribute.

‎api/core/v1alpha1/zz_generated.deepcopy.go‎

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

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

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

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

Lines changed: 13 additions & 1 deletion
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: 13 additions & 1 deletion
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,22 @@ spec:
183183
regex: "65200:[0-9][0-9]"
184184
- sequence: 15
185185
regex: "65300:[0-9]+"
186+
---
187+
apiVersion: networking.metal.ironcore.dev/v1alpha1
188+
kind: RoutingPolicy
189+
metadata:
190+
labels:
191+
app.kubernetes.io/name: network-operator
192+
app.kubernetes.io/managed-by: kustomize
193+
name: bgp-next-hop-self
194+
spec:
195+
deviceRef:
196+
name: leaf1
197+
name: BGP-NEXT-HOP-SELF
198+
statements:
199+
- sequence: 10
200+
actions:
201+
routeDisposition: AcceptRoute
202+
bgpActions:
203+
setNextHop:
204+
ipAddr: 10.0.0.1

‎docs/api-reference/index.md‎

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

‎internal/controller/core/suite_test.go‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ type DeviceState struct {
487487
PIM *v1alpha1.PIM
488488
BGP *v1alpha1.BGP
489489
BGPVRF *v1alpha1.VRF
490-
BGPValidation func(*provider.EnsureBGPRequest) error
491490
BGPPeers sets.Set[string]
492491
BGPPeerPolicies map[v1alpha1.BGPAddressFamilyType]*v1alpha1.RoutingPolicy
493492
BGPPeerError error
@@ -921,11 +920,6 @@ func (p *Provider) EnsureBGP(_ context.Context, req *provider.EnsureBGPRequest)
921920
s := p.devices.StateFor(p.deviceName)
922921
s.Lock()
923922
defer s.Unlock()
924-
if s.BGPValidation != nil {
925-
if err := s.BGPValidation(req); err != nil {
926-
return err
927-
}
928-
}
929923
s.BGP = req.BGP
930924
s.BGPVRF = req.VRF
931925
return nil

‎internal/provider/cisco/iosxr/route_policies.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/apimachinery/pkg/util/intstr"
1515

1616
"github.com/ironcore-dev/network-operator/api/core/v1alpha1"
17+
"github.com/ironcore-dev/network-operator/internal/apistatus"
1718
"github.com/ironcore-dev/network-operator/internal/provider"
1819
"github.com/ironcore-dev/network-operator/internal/transport/gnmiext"
1920
)
@@ -153,6 +154,12 @@ func (al *Actions) String() string {
153154

154155
func NewActions(actions v1alpha1.PolicyActions) (Actions, error) {
155156
var result Actions
157+
if actions.BgpActions != nil && actions.BgpActions.SetNextHop != nil {
158+
return result, apistatus.NewUnsupportedFieldError(apistatus.FieldViolation{
159+
Field: "spec.statements[].actions.bgpActions.setNextHop",
160+
Description: "iosxr provider does not support setting the BGP next-hop",
161+
})
162+
}
156163

157164
if actions.BgpActions != nil && actions.BgpActions.SetCommunity != nil {
158165
result.Actions = append(result.Actions, &CommAction{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,7 @@ func (p *Provider) DeletePrefixSet(ctx context.Context, req *provider.DeletePref
29102910
return p.client.Delete(ctx, s)
29112911
}
29122912

2913+
// EnsureRoutingPolicy installs the route-map definition and its statement actions.
29132914
func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.EnsureRoutingPolicyRequest) error {
29142915
rm := new(RouteMap)
29152916
rm.Name = req.Name
@@ -2938,6 +2939,10 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure
29382939
}
29392940

29402941
if stmt.Actions.BgpActions != nil {
2942+
if stmt.Actions.BgpActions.SetNextHop != nil {
2943+
nextHop := stmt.Actions.BgpActions.SetNextHop
2944+
e.NhItems.SetNhList.Set(&RouteMapNextHop{Addr: nextHop.IPAddr.String()})
2945+
}
29412946
if stmt.Actions.BgpActions.SetCommunity != nil {
29422947
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Operation); err != nil {
29432948
return err

0 commit comments

Comments
 (0)