Skip to content

Commit 37e3c78

Browse files
feat: Implement BFD for BGPPeers
Signed-off-by: Sven Rosenzweig <sven.rosenzweig@sap.com>
1 parent c0e37bf commit 37e3c78

11 files changed

Lines changed: 242 additions & 40 deletions

File tree

‎api/core/v1alpha1/bfd_types.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package v1alpha1 contains API Schema definitions for the networking.metal.ironcore.dev v1alpha1 API group.
5+
// +kubebuilder:validation:Required
6+
// +kubebuilder:object:generate=true
7+
// +groupName=networking.metal.ironcore.dev
8+
package v1alpha1
9+
10+
import (
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
)
13+
14+
// BFD defines the Bidirectional Forwarding Detection configuration for an interface.
15+
type BFD struct {
16+
// Enabled indicates whether BFD is enabled on the interface.
17+
// +required
18+
Enabled bool `json:"enabled"`
19+
20+
// DesiredMinimumTxInterval is the minimum interval between transmission of BFD control
21+
// packets that the operator desires. This value is advertised to the peer.
22+
// The actual interval used is the maximum of this value and the remote
23+
// required-minimum-receive interval value.
24+
// +optional
25+
// +kubebuilder:validation:Type=string
26+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
27+
DesiredMinimumTxInterval *metav1.Duration `json:"desiredMinimumTxInterval,omitempty"`
28+
29+
// RequiredMinimumReceive is the minimum interval between received BFD control packets
30+
// that this system should support. This value is advertised to the remote peer to
31+
// indicate the maximum frequency between BFD control packets that is acceptable
32+
// to the local system.
33+
// +optional
34+
// +kubebuilder:validation:Type=string
35+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
36+
RequiredMinimumReceive *metav1.Duration `json:"requiredMinimumReceive,omitempty"`
37+
38+
// DetectionMultiplier is the number of packets that must be missed to declare
39+
// this session as down. The detection interval for the BFD session is calculated
40+
// by multiplying the value of the negotiated transmission interval by this value.
41+
// +optional
42+
// +kubebuilder:validation:Minimum=1
43+
// +kubebuilder:validation:Maximum=255
44+
DetectionMultiplier *int32 `json:"detectionMultiplier,omitempty"`
45+
}

‎api/core/v1alpha1/bgp_peer_types.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ type BGPPeerSpec struct {
6464
// LocalAS configures the local AS number and how it factors into BGP announcements for this peer.
6565
// +optional
6666
LocalAS *LocalAS `json:"localAS,omitempty"`
67+
68+
// BFD defines the Bidirectional Forwarding Detection configuration for the interface.
69+
// BFD is only applicable for Layer 3 interfaces.
70+
// +optional
71+
BFD *BFD `json:"bfd,omitempty"`
6772
}
6873

6974
// LocalAS defines the local AS configuration and how it factors in BGP announcements.

‎api/core/v1alpha1/interface_types.go‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -266,39 +266,6 @@ type InterfaceIPv4Unnumbered struct {
266266
InterfaceRef LocalObjectReference `json:"interfaceRef"`
267267
}
268268

269-
// BFD defines the Bidirectional Forwarding Detection configuration for an interface.
270-
type BFD struct {
271-
// Enabled indicates whether BFD is enabled on the interface.
272-
// +required
273-
Enabled bool `json:"enabled"`
274-
275-
// DesiredMinimumTxInterval is the minimum interval between transmission of BFD control
276-
// packets that the operator desires. This value is advertised to the peer.
277-
// The actual interval used is the maximum of this value and the remote
278-
// required-minimum-receive interval value.
279-
// +optional
280-
// +kubebuilder:validation:Type=string
281-
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
282-
DesiredMinimumTxInterval *metav1.Duration `json:"desiredMinimumTxInterval,omitempty"`
283-
284-
// RequiredMinimumReceive is the minimum interval between received BFD control packets
285-
// that this system should support. This value is advertised to the remote peer to
286-
// indicate the maximum frequency between BFD control packets that is acceptable
287-
// to the local system.
288-
// +optional
289-
// +kubebuilder:validation:Type=string
290-
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
291-
RequiredMinimumReceive *metav1.Duration `json:"requiredMinimumReceive,omitempty"`
292-
293-
// DetectionMultiplier is the number of packets that must be missed to declare
294-
// this session as down. The detection interval for the BFD session is calculated
295-
// by multiplying the value of the negotiated transmission interval by this value.
296-
// +optional
297-
// +kubebuilder:validation:Minimum=1
298-
// +kubebuilder:validation:Maximum=255
299-
DetectionMultiplier *int32 `json:"detectionMultiplier,omitempty"`
300-
}
301-
302269
// Ethernet defines the ethernet-specific configuration for physical interfaces.
303270
type Ethernet struct {
304271
// FECMode specifies the Forward Error Correction mode for the interface.

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

Lines changed: 5 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: 36 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_bgppeers.yaml‎

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

‎docs/api-reference/index.md‎

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ type BGPPeer struct {
7171
Name string `json:"vrf-name"`
7272
RD RouteDistinguisher `json:"rd,omitzero"`
7373
Neighbors NeighborList `json:"neighbors,omitzero"`
74+
BFD *BFD `json:"bfd,omitzero"`
75+
}
76+
77+
type BFD struct {
78+
MinInterval uint32 `json:"minimum-interval,omitempty"`
79+
Multiplier uint32 `json:"multiplier,omitempty"`
7480
}
7581

7682
// ActivatedAddressFamilies is required for IOS XR to activate the Address-Family under the BGP process

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"math"
1011
"net"
1112
"time"
1213

1314
"github.com/ironcore-dev/network-operator/api/core/v1alpha1"
15+
"github.com/ironcore-dev/network-operator/internal/apistatus"
1416
"github.com/ironcore-dev/network-operator/internal/deviceutil"
1517
"github.com/ironcore-dev/network-operator/internal/provider"
1618
"github.com/ironcore-dev/network-operator/internal/transport/gnmiext"
@@ -477,6 +479,31 @@ func (p *Provider) EnsureBGPPeer(ctx context.Context, req *provider.EnsureBGPPee
477479
RD: rd,
478480
}
479481

482+
if req.BGPPeer.Spec.BFD != nil && req.BGPPeer.Spec.BFD.Enabled {
483+
bfd := &BFD{}
484+
if req.BGPPeer.Spec.BFD.RequiredMinimumReceive != nil {
485+
ms := req.BGPPeer.Spec.BFD.RequiredMinimumReceive.Duration
486+
if ms < 0 || ms > math.MaxUint32 {
487+
return apistatus.NewInvalidArgumentError(apistatus.FieldViolation{
488+
Field: "spec.bfd.requiredMinimumReceive",
489+
Description: "BFD minimum receive interval must be between 0ms and 4294967295ms",
490+
})
491+
}
492+
bfd.MinInterval = uint32(ms)
493+
}
494+
if req.BGPPeer.Spec.BFD.DetectionMultiplier != nil {
495+
multiplier := *req.BGPPeer.Spec.BFD.DetectionMultiplier
496+
if multiplier < 0 {
497+
return apistatus.NewInvalidArgumentError(apistatus.FieldViolation{
498+
Field: "spec.bfd.detectionMultiplier",
499+
Description: "BFD detection multiplier must be non-negative",
500+
})
501+
}
502+
bfd.Multiplier = uint32(multiplier)
503+
}
504+
peer.BFD = bfd
505+
}
506+
480507
if req.BGPPeer.Spec.AddressFamilies != nil && (req.BGPPeer.Spec.AddressFamilies.Ipv6Unicast != nil || req.BGPPeer.Spec.AddressFamilies.L2vpnEvpn != nil) {
481508
return errors.New("bgp peer: ipv6 unicast or l2vpnEvpn address family is currently not supported")
482509
}

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

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
nxv1alpha1 "github.com/ironcore-dev/network-operator/api/cisco/nx/v1alpha1"
1313
"github.com/ironcore-dev/network-operator/api/core/v1alpha1"
14+
"github.com/ironcore-dev/network-operator/internal/apistatus"
1415
"github.com/ironcore-dev/network-operator/internal/transport/gnmiext"
1516
)
1617

@@ -187,22 +188,74 @@ func (af *BGPDomAfItem) SetMultipath(m *v1alpha1.BGPMultipath) error {
187188
}
188189

189190
type BGPPeer struct {
190-
VRFName string `json:"-"`
191-
Addr string `json:"addr"`
192-
AdminSt AdminSt `json:"adminSt"`
193-
Asn string `json:"asn"`
194-
AsnType PeerAsnType `json:"asnType"`
195-
Name string `json:"name,omitempty"`
196-
SrcIf string `json:"srcIf,omitempty"`
191+
VRFName string `json:"-"`
192+
Addr string `json:"addr"`
193+
Name string `json:"name,omitempty"`
194+
AdminSt AdminSt `json:"adminSt"`
195+
Asn string `json:"asn"`
196+
AsnType PeerAsnType `json:"asnType"`
197+
SrcIf string `json:"srcIf,omitempty"`
198+
199+
// BFD enablement
200+
PeerControl string `json:"ctrl"`
201+
// Bfd Type: none (default), single-hop, multi-hop
202+
// Rely on default, if peer is directly connected then a single hop session is selected,
203+
// if the peer is not connected then a multi hop session type is selected
204+
BfdType string `json:"bfdType"`
205+
BfdMultihop *BGPNeighborBfd `json:"mhbfdintvl-items,omitzero"`
206+
197207
LocalAsnItems struct {
198208
AsnPropagate AsnPropagate `json:"asnPropagate"`
199209
LocalAsn string `json:"localAsn"`
200210
} `json:"localasn-items,omitzero"`
211+
201212
AfItems struct {
202213
PeerAfList gnmiext.List[AddressFamily, *BGPPeerAfItem] `json:"PeerAf-list,omitzero"`
203214
} `json:"af-items,omitzero"`
204215
}
205216

217+
type BGPNeighborBfd struct {
218+
DetectMult uint32 `json:"multiplier"`
219+
MinRxIntvlMs uint32 `json:"minRxMs"`
220+
MinTxIntvlMs uint32 `json:"minTxMs"`
221+
}
222+
223+
func NewBGPNeighborBfd(peer *v1alpha1.BGPPeerSpec) (*BGPNeighborBfd, error) {
224+
bfd := &BGPNeighborBfd{}
225+
if peer.BFD.DetectionMultiplier != nil {
226+
multiplier := *peer.BFD.DetectionMultiplier
227+
if multiplier < 0 {
228+
return nil, apistatus.NewInvalidArgumentError(apistatus.FieldViolation{
229+
Field: "spec.bfd.detectionMultiplier",
230+
Description: "BFD detection multiplier must be non-negative",
231+
})
232+
}
233+
bfd.DetectMult = uint32(multiplier)
234+
}
235+
if peer.BFD.RequiredMinimumReceive != nil {
236+
ms := peer.BFD.RequiredMinimumReceive.Duration
237+
238+
if ms < 250 || ms > 999 {
239+
return nil, apistatus.NewInvalidArgumentError(apistatus.FieldViolation{
240+
Field: "spec.bfd.requiredMinimumReceive",
241+
Description: "BFD minimum receive interval must be between 250ms and 999ms",
242+
})
243+
}
244+
bfd.MinRxIntvlMs = uint32(ms)
245+
}
246+
if peer.BFD.DesiredMinimumTxInterval != nil {
247+
ms := peer.BFD.DesiredMinimumTxInterval.Duration
248+
if ms < 250 || ms > 999 {
249+
return nil, apistatus.NewInvalidArgumentError(apistatus.FieldViolation{
250+
Field: "spec.bfd.desiredMinimumTxInterval",
251+
Description: "BFD desired minimum transmit interval must be between 250ms and 999ms",
252+
})
253+
}
254+
bfd.MinTxIntvlMs = uint32(ms)
255+
}
256+
return bfd, nil
257+
}
258+
206259
type AsnPropagate string
207260

208261
const (
@@ -362,6 +415,13 @@ const (
362415

363416
const RouteReflectorClient = "rr-client"
364417

418+
const (
419+
// PeerControlBFD enables BFD on BGP peer
420+
PeerControlBFD = "bfd"
421+
// BfdTypeNone relies on default BFD session type selection
422+
BfdTypeNone = "none"
423+
)
424+
365425
type BorderGatewayPeerType string
366426

367427
const (

0 commit comments

Comments
 (0)