From 7e9a676d117c00b84afe0a3a75650290b8e2631e Mon Sep 17 00:00:00 2001 From: Yurii Levchenko Date: Fri, 13 Nov 2026 09:32:30 +0100 Subject: [PATCH 1/2] Add L2RIB duplicate host IP address detection to NX-OS System Adds the `l2rib` field to the NX-OS `System` CRD, exposing the four parameters of "l2rib dup-host-ip-addr-detection": move count, detection window, recovery timeout, and recovery count. The provider realizes this via a new `HMMFwdEvpn` struct written to System/hmm-items/fwdinst-items/evpn-items using PATCH semantics so that `FabricFwd`'s data at the parent path is not clobbered. The struct implements `Defaultable` so reset writes platform defaults (5/180/30/5) rather than deleting the subtree. Signed-off-by: Yurii Levchenko --- api/cisco/nx/v1alpha1/system_types.go | 43 ++++++++ .../nx/v1alpha1/zz_generated.deepcopy.go | 16 +++ ...x.cisco.networking.metal.ironcore.dev.yaml | 48 +++++++++ ...networking.metal.ironcore.dev_systems.yaml | 48 +++++++++ config/samples/cisco/nx/v1alpha1_system.yaml | 5 + internal/provider/cisco/nxos/l2rib.go | 42 ++++++++ internal/provider/cisco/nxos/l2rib_test.go | 14 +++ internal/provider/cisco/nxos/provider.go | 18 +++- .../provider/cisco/nxos/testdata/l2rib.json | 13 +++ .../system.txtar | 22 +++++ .../system_dhcp_override.txtar | 22 +++++ .../system_dhcp_override_deprecated.txtar | 22 +++++ .../system_l2rib.txtar | 98 +++++++++++++++++++ 13 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 internal/provider/cisco/nxos/l2rib.go create mode 100644 internal/provider/cisco/nxos/l2rib_test.go create mode 100644 internal/provider/cisco/nxos/testdata/l2rib.json create mode 100644 test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_l2rib.txtar diff --git a/api/cisco/nx/v1alpha1/system_types.go b/api/cisco/nx/v1alpha1/system_types.go index ea0fe06a9..313319ede 100644 --- a/api/cisco/nx/v1alpha1/system_types.go +++ b/api/cisco/nx/v1alpha1/system_types.go @@ -56,6 +56,13 @@ type SystemSpec struct { // +optional // +kubebuilder:default={relayServerIdOverrideDisable:false} DHCP DHCP `json:"dhcp,omitzero"` + + // L2RIB groups L2RIB (Layer-2 Routing Information Base) system settings. + // Configures duplicate host IP address detection + // (CLI: "l2rib dup-host-ip-addr-detection"). + // +optional + // +kubebuilder:default={moves:5,durationSeconds:180,recoveryTimeoutSeconds:30,recoveryCount:5} + L2RIB L2RIB `json:"l2rib,omitzero"` } // DHCP groups DHCP-related system settings. These require the dhcp feature, @@ -71,6 +78,42 @@ type DHCP struct { RelayServerIDOverrideDisable bool `json:"relayServerIdOverrideDisable"` } +// L2RIB groups L2RIB duplicate host IP address detection settings, +// realized as "l2rib dup-host-ip-addr-detection" on the device. +type L2RIB struct { + // Moves is the number of host IP moves allowed within DurationSeconds before + // the host IP address is flagged as a duplicate (CLI: num-moves). + // +optional + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=1000 + // +kubebuilder:default=5 + Moves int32 `json:"moves"` + + // DurationSeconds is the detection window in seconds during which moves are + // counted (CLI: num-moves-interval). + // +optional + // +kubebuilder:validation:Minimum=2 + // +kubebuilder:validation:Maximum=36000 + // +kubebuilder:default=180 + DurationSeconds int32 `json:"durationSeconds"` + + // RecoveryTimeoutSeconds is the time in seconds after which a duplicate-marked + // host IP address is re-evaluated (CLI: retry-timeout). Minimum is 30. + // +optional + // +kubebuilder:validation:Minimum=30 + // +kubebuilder:validation:Maximum=36000 + // +kubebuilder:default=30 + RecoveryTimeoutSeconds int32 `json:"recoveryTimeoutSeconds"` + + // RecoveryCount is the number of recovery attempts before the duplicate + // detection is considered permanent (CLI: retry-count). + // +optional + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=3000 + // +kubebuilder:default=5 + RecoveryCount int32 `json:"recoveryCount"` +} + // SystemStatus defines the observed state of System. type SystemStatus struct { // The conditions are a list of status objects that describe the state of the Banner. diff --git a/api/cisco/nx/v1alpha1/zz_generated.deepcopy.go b/api/cisco/nx/v1alpha1/zz_generated.deepcopy.go index d58bf025b..5a00710e8 100644 --- a/api/cisco/nx/v1alpha1/zz_generated.deepcopy.go +++ b/api/cisco/nx/v1alpha1/zz_generated.deepcopy.go @@ -923,6 +923,21 @@ func (in *KeepAlive) DeepCopy() *KeepAlive { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *L2RIB) DeepCopyInto(out *L2RIB) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new L2RIB. +func (in *L2RIB) DeepCopy() *L2RIB { + if in == nil { + return nil + } + out := new(L2RIB) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LLDPConfig) DeepCopyInto(out *LLDPConfig) { *out = *in @@ -1371,6 +1386,7 @@ func (in *SystemSpec) DeepCopyInto(out *SystemSpec) { *out = *in out.DeviceRef = in.DeviceRef out.DHCP = in.DHCP + out.L2RIB = in.L2RIB } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SystemSpec. diff --git a/charts/network-operator/templates/crd/systems.nx.cisco.networking.metal.ironcore.dev.yaml b/charts/network-operator/templates/crd/systems.nx.cisco.networking.metal.ironcore.dev.yaml index ff0792bec..82ef5dc4b 100644 --- a/charts/network-operator/templates/crd/systems.nx.cisco.networking.metal.ironcore.dev.yaml +++ b/charts/network-operator/templates/crd/systems.nx.cisco.networking.metal.ironcore.dev.yaml @@ -106,6 +106,54 @@ spec: maximum: 9216 minimum: 1501 type: integer + l2rib: + default: + durationSeconds: 180 + moves: 5 + recoveryCount: 5 + recoveryTimeoutSeconds: 30 + description: |- + L2RIB groups L2RIB (Layer-2 Routing Information Base) system settings. + Configures duplicate host IP address detection + (CLI: "l2rib dup-host-ip-addr-detection"). + properties: + durationSeconds: + default: 180 + description: |- + DurationSeconds is the detection window in seconds during which moves are + counted (CLI: num-moves-interval). + format: int32 + maximum: 36000 + minimum: 2 + type: integer + moves: + default: 5 + description: |- + Moves is the number of host IP moves allowed within DurationSeconds before + the host IP address is flagged as a duplicate (CLI: num-moves). + format: int32 + maximum: 1000 + minimum: 1 + type: integer + recoveryCount: + default: 5 + description: |- + RecoveryCount is the number of recovery attempts before the duplicate + detection is considered permanent (CLI: retry-count). + format: int32 + maximum: 3000 + minimum: 1 + type: integer + recoveryTimeoutSeconds: + default: 30 + description: |- + RecoveryTimeoutSeconds is the time in seconds after which a duplicate-marked + host IP address is re-evaluated (CLI: retry-timeout). Minimum is 30. + format: int32 + maximum: 36000 + minimum: 30 + type: integer + type: object relayServerIdOverrideDisable: default: false description: |- diff --git a/config/crd/bases/nx.cisco.networking.metal.ironcore.dev_systems.yaml b/config/crd/bases/nx.cisco.networking.metal.ironcore.dev_systems.yaml index c25ac11a8..2071f2790 100644 --- a/config/crd/bases/nx.cisco.networking.metal.ironcore.dev_systems.yaml +++ b/config/crd/bases/nx.cisco.networking.metal.ironcore.dev_systems.yaml @@ -103,6 +103,54 @@ spec: maximum: 9216 minimum: 1501 type: integer + l2rib: + default: + durationSeconds: 180 + moves: 5 + recoveryCount: 5 + recoveryTimeoutSeconds: 30 + description: |- + L2RIB groups L2RIB (Layer-2 Routing Information Base) system settings. + Configures duplicate host IP address detection + (CLI: "l2rib dup-host-ip-addr-detection"). + properties: + durationSeconds: + default: 180 + description: |- + DurationSeconds is the detection window in seconds during which moves are + counted (CLI: num-moves-interval). + format: int32 + maximum: 36000 + minimum: 2 + type: integer + moves: + default: 5 + description: |- + Moves is the number of host IP moves allowed within DurationSeconds before + the host IP address is flagged as a duplicate (CLI: num-moves). + format: int32 + maximum: 1000 + minimum: 1 + type: integer + recoveryCount: + default: 5 + description: |- + RecoveryCount is the number of recovery attempts before the duplicate + detection is considered permanent (CLI: retry-count). + format: int32 + maximum: 3000 + minimum: 1 + type: integer + recoveryTimeoutSeconds: + default: 30 + description: |- + RecoveryTimeoutSeconds is the time in seconds after which a duplicate-marked + host IP address is re-evaluated (CLI: retry-timeout). Minimum is 30. + format: int32 + maximum: 36000 + minimum: 30 + type: integer + type: object relayServerIdOverrideDisable: default: false description: |- diff --git a/config/samples/cisco/nx/v1alpha1_system.yaml b/config/samples/cisco/nx/v1alpha1_system.yaml index 575558d0e..2204fe87d 100644 --- a/config/samples/cisco/nx/v1alpha1_system.yaml +++ b/config/samples/cisco/nx/v1alpha1_system.yaml @@ -13,3 +13,8 @@ spec: vlanLongName: true dhcp: relayServerIdOverrideDisable: true + l2rib: + moves: 5 + durationSeconds: 180 + recoveryTimeoutSeconds: 30 + recoveryCount: 5 diff --git a/internal/provider/cisco/nxos/l2rib.go b/internal/provider/cisco/nxos/l2rib.go new file mode 100644 index 000000000..76656d9b9 --- /dev/null +++ b/internal/provider/cisco/nxos/l2rib.go @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +package nxos + +import "github.com/ironcore-dev/network-operator/internal/transport/gnmiext" + +var ( + _ gnmiext.DataElement = (*HMMFwdEvpn)(nil) + _ gnmiext.Defaultable = (*HMMFwdEvpn)(nil) +) + +const ( + hmmFwdEvpnDefaultMoves uint16 = 5 + hmmFwdEvpnDefaultDuration uint16 = 180 + hmmFwdEvpnDefaultRecoveryTimeout uint16 = 30 + hmmFwdEvpnDefaultRecoveryCount uint16 = 5 +) + +// HMMFwdEvpn represents the L2RIB duplicate host IP address detection settings +// ("l2rib dup-host-ip-addr-detection"). +// Writes System/hmm-items/fwdinst-items/evpn-items. Must use only PATCH operations +// so that FabricFwd's data at the parent path is not clobbered. +type HMMFwdEvpn struct { + AdminSt AdminSt `json:"adminSt"` + DdHmmoves uint16 `json:"ddHmmoves"` + DdHnsecs uint16 `json:"ddHnsecs"` + Dhrtimeout uint16 `json:"dhrtimeout"` + Dhrcount uint16 `json:"dhrcount"` +} + +func (*HMMFwdEvpn) XPath() string { + return "System/hmm-items/fwdinst-items/evpn-items" +} + +func (h *HMMFwdEvpn) Default() { + h.AdminSt = AdminStEnabled + h.DdHmmoves = hmmFwdEvpnDefaultMoves + h.DdHnsecs = hmmFwdEvpnDefaultDuration + h.Dhrtimeout = hmmFwdEvpnDefaultRecoveryTimeout + h.Dhrcount = hmmFwdEvpnDefaultRecoveryCount +} diff --git a/internal/provider/cisco/nxos/l2rib_test.go b/internal/provider/cisco/nxos/l2rib_test.go new file mode 100644 index 000000000..17b9c3a40 --- /dev/null +++ b/internal/provider/cisco/nxos/l2rib_test.go @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +package nxos + +func init() { + Register("l2rib", &HMMFwdEvpn{ + AdminSt: AdminStEnabled, + DdHmmoves: 10, + DdHnsecs: 300, + Dhrtimeout: 60, + Dhrcount: 3, + }) +} diff --git a/internal/provider/cisco/nxos/provider.go b/internal/provider/cisco/nxos/provider.go index 30080177b..799eeac8b 100644 --- a/internal/provider/cisco/nxos/provider.go +++ b/internal/provider/cisco/nxos/provider.go @@ -3595,7 +3595,22 @@ func (p *Provider) EnsureSystemSettings(ctx context.Context, s *nxv1alpha1.Syste sys := new(SystemJumboMTU) *sys = SystemJumboMTU(s.Spec.JumboMTU) - sb.Patch(long, res, sys) + + l2rib := new(HMMFwdEvpn) + l2rib.Default() + if s.Spec.L2RIB.Moves != 0 { + l2rib.DdHmmoves = uint16(s.Spec.L2RIB.Moves) //nolint:gosec // validated: max 1000 fits uint16 + } + if s.Spec.L2RIB.DurationSeconds != 0 { + l2rib.DdHnsecs = uint16(s.Spec.L2RIB.DurationSeconds) //nolint:gosec // validated: max 36000 fits uint16 + } + if s.Spec.L2RIB.RecoveryTimeoutSeconds != 0 { + l2rib.Dhrtimeout = uint16(s.Spec.L2RIB.RecoveryTimeoutSeconds) //nolint:gosec // validated: max 36000 fits uint16 + } + if s.Spec.L2RIB.RecoveryCount != 0 { + l2rib.Dhrcount = uint16(s.Spec.L2RIB.RecoveryCount) //nolint:gosec // validated: max 3000 fits uint16 + } + sb.Patch(long, res, sys, l2rib) // The override leaf lives under the dhcp feature tree, which only exists while the // feature is enabled. Read the current feature state to decide how to realize it. @@ -3631,6 +3646,7 @@ func (p *Provider) ResetSystemSettings(ctx context.Context) error { new(VLANReservation), new(SystemJumboMTU), new(DHCPRelayServerIDOverrideDisable), + new(HMMFwdEvpn), ) } diff --git a/internal/provider/cisco/nxos/testdata/l2rib.json b/internal/provider/cisco/nxos/testdata/l2rib.json new file mode 100644 index 000000000..1454aa5cb --- /dev/null +++ b/internal/provider/cisco/nxos/testdata/l2rib.json @@ -0,0 +1,13 @@ +{ + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 10, + "ddHnsecs": 300, + "dhrtimeout": 60, + "dhrcount": 3 + } + } + } +} diff --git a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system.txtar b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system.txtar index 502562623..e04dfb4e3 100644 --- a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system.txtar +++ b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system.txtar @@ -41,6 +41,17 @@ spec: "inst-items": { "systemJumboMtu": 9214 } + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } } } } @@ -66,6 +77,17 @@ spec: "inst-items": { "systemJumboMtu": 9216 } + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } } } } diff --git a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override.txtar b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override.txtar index b3dea3e78..c373ce59b 100644 --- a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override.txtar +++ b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override.txtar @@ -57,6 +57,17 @@ spec: "inst-items": { "relayInformationOptionServerIdOverrideDisableEnabled": 1 } + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } } } } @@ -89,6 +100,17 @@ spec: }, "dhcp-items": { "inst-items": {} + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } } } } diff --git a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override_deprecated.txtar b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override_deprecated.txtar index 7d723e819..d9554498c 100644 --- a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override_deprecated.txtar +++ b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_dhcp_override_deprecated.txtar @@ -56,6 +56,17 @@ spec: "inst-items": { "relayInformationOptionServerIdOverrideDisableEnabled": 1 } + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } } } } @@ -88,6 +99,17 @@ spec: }, "dhcp-items": { "inst-items": {} + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } } } } diff --git a/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_l2rib.txtar b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_l2rib.txtar new file mode 100644 index 000000000..653b32ca8 --- /dev/null +++ b/test/gnmi/testdata/nx.cisco.networking.metal.ironcore.dev/system_l2rib.txtar @@ -0,0 +1,98 @@ +-- systems/system-config -- +apiVersion: nx.cisco.networking.metal.ironcore.dev/v1alpha1 +kind: System +metadata: + name: system-config + namespace: default +spec: + deviceRef: + name: device + jumboMtu: 9214 + reservedVlan: 3968 + vlanLongName: false + l2rib: + moves: 10 + durationSeconds: 300 + recoveryTimeoutSeconds: 60 + recoveryCount: 3 + +-- state/preload -- +{ + "System": { + "procsys-items": { + "bootTime": "1700000000" + } + } +} + +-- state/expect -- + +{ + "System": { + "procsys-items": { + "bootTime": "1700000000" + }, + "vlanmgr-items": { + "inst-items": { + "longName": false + } + }, + "bd-items": { + "resvlan-items": { + "sysVlan": 3968 + } + }, + "ethpm-items": { + "inst-items": { + "systemJumboMtu": 9214 + } + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 10, + "ddHnsecs": 300, + "dhrtimeout": 60, + "dhrcount": 3 + } + } + } + } +} + +-- state/delete -- + +{ + "System": { + "procsys-items": { + "bootTime": "1700000000" + }, + "vlanmgr-items": { + "inst-items": { + "longName": false + } + }, + "bd-items": { + "resvlan-items": { + "sysVlan": 3968 + } + }, + "ethpm-items": { + "inst-items": { + "systemJumboMtu": 9216 + } + }, + "hmm-items": { + "fwdinst-items": { + "evpn-items": { + "adminSt": "enabled", + "ddHmmoves": 5, + "ddHnsecs": 180, + "dhrtimeout": 30, + "dhrcount": 5 + } + } + } + } +} From 236e43bdf872f127cdfb8d1fc21d5d142ebc29c6 Mon Sep 17 00:00:00 2001 From: Yurii Levchenko Date: Fri, 13 Nov 2026 10:03:16 +0100 Subject: [PATCH 2/2] Simplify L2RIB provider struct initialization with cmp.Or Signed-off-by: Yurii Levchenko --- internal/provider/cisco/nxos/provider.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/internal/provider/cisco/nxos/provider.go b/internal/provider/cisco/nxos/provider.go index 799eeac8b..f0171c9fc 100644 --- a/internal/provider/cisco/nxos/provider.go +++ b/internal/provider/cisco/nxos/provider.go @@ -3596,21 +3596,13 @@ func (p *Provider) EnsureSystemSettings(ctx context.Context, s *nxv1alpha1.Syste sys := new(SystemJumboMTU) *sys = SystemJumboMTU(s.Spec.JumboMTU) - l2rib := new(HMMFwdEvpn) - l2rib.Default() - if s.Spec.L2RIB.Moves != 0 { - l2rib.DdHmmoves = uint16(s.Spec.L2RIB.Moves) //nolint:gosec // validated: max 1000 fits uint16 - } - if s.Spec.L2RIB.DurationSeconds != 0 { - l2rib.DdHnsecs = uint16(s.Spec.L2RIB.DurationSeconds) //nolint:gosec // validated: max 36000 fits uint16 - } - if s.Spec.L2RIB.RecoveryTimeoutSeconds != 0 { - l2rib.Dhrtimeout = uint16(s.Spec.L2RIB.RecoveryTimeoutSeconds) //nolint:gosec // validated: max 36000 fits uint16 - } - if s.Spec.L2RIB.RecoveryCount != 0 { - l2rib.Dhrcount = uint16(s.Spec.L2RIB.RecoveryCount) //nolint:gosec // validated: max 3000 fits uint16 - } - sb.Patch(long, res, sys, l2rib) + sb.Patch(long, res, sys, &HMMFwdEvpn{ + AdminSt: AdminStEnabled, + DdHmmoves: cmp.Or(uint16(s.Spec.L2RIB.Moves), hmmFwdEvpnDefaultMoves), //nolint:gosec // validated: max 1000 fits uint16 + DdHnsecs: cmp.Or(uint16(s.Spec.L2RIB.DurationSeconds), hmmFwdEvpnDefaultDuration), //nolint:gosec // validated: max 36000 fits uint16 + Dhrtimeout: cmp.Or(uint16(s.Spec.L2RIB.RecoveryTimeoutSeconds), hmmFwdEvpnDefaultRecoveryTimeout), //nolint:gosec // validated: max 36000 fits uint16 + Dhrcount: cmp.Or(uint16(s.Spec.L2RIB.RecoveryCount), hmmFwdEvpnDefaultRecoveryCount), //nolint:gosec // validated: max 3000 fits uint16 + }) // The override leaf lives under the dhcp feature tree, which only exists while the // feature is enabled. Read the current feature state to decide how to realize it.