From 8ca218c37ce0cdcd08f7ec1a2a2167c06b98ce49 Mon Sep 17 00:00:00 2001 From: Sergey Matov Date: Wed, 28 Feb 2024 17:34:49 +0400 Subject: [PATCH] Fallback option for MCLAG/ESLAG --- api/wiring/v1alpha2/connection_types.go | 4 ++++ .../crd/bases/agent.githedgehog.com_agents.yaml | 10 ++++++++++ .../bases/wiring.githedgehog.com_connections.yaml | 10 ++++++++++ docs/api.md | 2 ++ pkg/agent/dozer/bcm/plan.go | 8 +++++++- pkg/agent/dozer/bcm/spec_pc_config.go | 15 ++++++++------- pkg/agent/dozer/dozer.go | 1 + 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/api/wiring/v1alpha2/connection_types.go b/api/wiring/v1alpha2/connection_types.go index 64ac386b..ecb7b089 100644 --- a/api/wiring/v1alpha2/connection_types.go +++ b/api/wiring/v1alpha2/connection_types.go @@ -129,6 +129,8 @@ type ConnMCLAG struct { Links []ServerToSwitchLink `json:"links,omitempty"` // ServerFacingConnectionConfig defines any server-facing connection (unbundled, bundled, mclag, etc.) configuration ServerFacingConnectionConfig `json:",inline"` + // Fallback is the optional flag that used to idicate one of the links in LACP port channel to be used as a fallback link + Fallback bool `json:"fallback,omitempty"` } // ConnESLAG defines the ESLAG connection (port channel, single server to 2-4 switches with multiple links) @@ -138,6 +140,8 @@ type ConnESLAG struct { Links []ServerToSwitchLink `json:"links,omitempty"` // ServerFacingConnectionConfig defines any server-facing connection (unbundled, bundled, eslag, etc.) configuration ServerFacingConnectionConfig `json:",inline"` + // Fallback is the optional flag that used to idicate one of the links in LACP port channel to be used as a fallback link + Fallback bool `json:"fallback,omitempty"` } // SwitchToSwitchLink defines the switch-to-switch link diff --git a/config/crd/bases/agent.githedgehog.com_agents.yaml b/config/crd/bases/agent.githedgehog.com_agents.yaml index bf4f4dde..d88fae44 100644 --- a/config/crd/bases/agent.githedgehog.com_agents.yaml +++ b/config/crd/bases/agent.githedgehog.com_agents.yaml @@ -235,6 +235,11 @@ spec: description: ESLAG defines the ESLAG connection (port channel, single server to 2-4 switches with multiple links) properties: + fallback: + description: Fallback is the optional flag that used to + idicate one of the links in LACP port channel to be used + as a fallback link + type: boolean links: description: Links is the list of server-to-switch links items: @@ -399,6 +404,11 @@ spec: description: MCLAG defines the MCLAG connection (port channel, single server to pair of switches with multiple links) properties: + fallback: + description: Fallback is the optional flag that used to + idicate one of the links in LACP port channel to be used + as a fallback link + type: boolean links: description: Links is the list of server-to-switch links items: diff --git a/config/crd/bases/wiring.githedgehog.com_connections.yaml b/config/crd/bases/wiring.githedgehog.com_connections.yaml index fa692504..2d4dbf17 100644 --- a/config/crd/bases/wiring.githedgehog.com_connections.yaml +++ b/config/crd/bases/wiring.githedgehog.com_connections.yaml @@ -93,6 +93,11 @@ spec: description: ESLAG defines the ESLAG connection (port channel, single server to 2-4 switches with multiple links) properties: + fallback: + description: Fallback is the optional flag that used to idicate + one of the links in LACP port channel to be used as a fallback + link + type: boolean links: description: Links is the list of server-to-switch links items: @@ -244,6 +249,11 @@ spec: description: MCLAG defines the MCLAG connection (port channel, single server to pair of switches with multiple links) properties: + fallback: + description: Fallback is the optional flag that used to idicate + one of the links in LACP port channel to be used as a fallback + link + type: boolean links: description: Links is the list of server-to-switch links items: diff --git a/docs/api.md b/docs/api.md index d0828aec..d98f3740 100644 --- a/docs/api.md +++ b/docs/api.md @@ -711,6 +711,7 @@ _Appears in:_ | --- | --- | | `links` _[ServerToSwitchLink](#servertoswitchlink) array_ | Links is the list of server-to-switch links | | `mtu` _integer_ | MTU is the MTU to be configured on the switch port or port channel | +| `fallback` _boolean_ | Fallback is the optional flag that used to idicate one of the links in LACP port channel to be used as a fallback link | #### ConnExternal @@ -783,6 +784,7 @@ _Appears in:_ | --- | --- | | `links` _[ServerToSwitchLink](#servertoswitchlink) array_ | Links is the list of server-to-switch links | | `mtu` _integer_ | MTU is the MTU to be configured on the switch port or port channel | +| `fallback` _boolean_ | Fallback is the optional flag that used to idicate one of the links in LACP port channel to be used as a fallback link | #### ConnMCLAGDomain diff --git a/pkg/agent/dozer/bcm/plan.go b/pkg/agent/dozer/bcm/plan.go index 148df864..e8712ddc 100644 --- a/pkg/agent/dozer/bcm/plan.go +++ b/pkg/agent/dozer/bcm/plan.go @@ -894,12 +894,14 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { connType := "" var mtu *uint16 var links []wiringapi.ServerToSwitchLink + var fallback bool if conn.MCLAG != nil { connType = "MCLAG" if conn.MCLAG.MTU != 0 { mtu = uint16Ptr(conn.MCLAG.MTU) } + fallback = conn.MCLAG.Fallback links = conn.MCLAG.Links } else if conn.Bundled != nil { connType = "Bundled" @@ -912,6 +914,7 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { if conn.ESLAG.MTU != 0 { mtu = uint16Ptr(conn.ESLAG.MTU) } + fallback = conn.ESLAG.Fallback links = conn.ESLAG.Links } else { continue @@ -950,6 +953,9 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { spec.MCLAGInterfaces[connPortChannelName] = &dozer.SpecMCLAGInterface{ DomainID: MCLAG_DOMAIN_ID, } + spec.PortChannelConfigs[connPortChannelName] = &dozer.SpecPortChannelConfig{ + Fallback: boolPtr(fallback), + } } else if connType == "ESLAG" { mac, err := net.ParseMAC(agent.Spec.Config.ESLAGMACBase) if err != nil { @@ -967,9 +973,9 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { binary.BigEndian.PutUint64(newMACVal, macVal) mac = newMACVal[2:] - spec.PortChannelConfigs[connPortChannelName] = &dozer.SpecPortChannelConfig{ SystemMAC: stringPtr(mac.String()), + Fallback: boolPtr(fallback), } esi := strings.ReplaceAll(agent.Spec.Config.ESLAGESIPrefix+mac.String(), ":", "") diff --git a/pkg/agent/dozer/bcm/spec_pc_config.go b/pkg/agent/dozer/bcm/spec_pc_config.go index 3945d403..e723a969 100644 --- a/pkg/agent/dozer/bcm/spec_pc_config.go +++ b/pkg/agent/dozer/bcm/spec_pc_config.go @@ -17,13 +17,16 @@ var specPortChannelConfigsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecPort var specPortChannelConfigEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{ Summary: "PortChannel Config %s", - Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/system_mac", + Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]", UpdateWeight: ActionWeightPortChannelConfigUpdate, DeleteWeight: ActionWeightPortChannelConfigDelete, Marshal: func(key string, value *dozer.SpecPortChannelConfig) (ygot.ValidatedGoStruct, error) { - return &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{ - SystemMac: value.SystemMAC, - }, nil + ret := &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{} + if value.SystemMAC != nil { + ret.SystemMac = value.SystemMAC + } + ret.Fallback = value.Fallback + return ret, nil }, } @@ -50,12 +53,10 @@ func unmarshalActualPortChannelConfigs(ocVal *oc.SonicPortchannel_SonicPortchann } for name, portChannel := range ocVal.PORTCHANNEL.PORTCHANNEL_LIST { - if portChannel.SystemMac == nil { - continue - } portChannelConfigs[name] = &dozer.SpecPortChannelConfig{ SystemMAC: portChannel.SystemMac, + Fallback: portChannel.Fallback, } } diff --git a/pkg/agent/dozer/dozer.go b/pkg/agent/dozer/dozer.go index fbd5ac0a..bd1d807b 100644 --- a/pkg/agent/dozer/dozer.go +++ b/pkg/agent/dozer/dozer.go @@ -367,6 +367,7 @@ type SpecSuppressVLANNeigh struct{} type SpecPortChannelConfig struct { SystemMAC *string `json:"systemMAC,omitempty"` + Fallback *bool `json:"fallback,omitempty"` } type SpecLSTGroup struct {