From e49dac0fe85507ef21d2f5d9af4c700e779ebe1b Mon Sep 17 00:00:00 2001 From: Fred Rolland Date: Mon, 6 Jan 2025 09:03:16 +0200 Subject: [PATCH] Support mtu_request for OVS For using non-default MTU, OVS supports "mtu_request" field when adding a port to the bridge. eg: https://docs.openvswitch.org/en/latest/topics/dpdk/jumbo-frames/ Signed-off-by: Fred Rolland --- api/v1/helper.go | 4 ++++ api/v1/sriovnetworknodepolicy_types.go | 2 ++ api/v1/zz_generated.deepcopy.go | 5 +++++ ...iovnetwork.openshift.io_sriovnetworknodepolicies.yaml | 4 ++++ ...sriovnetwork.openshift.io_sriovnetworknodestates.yaml | 8 ++++++++ ...iovnetwork.openshift.io_sriovnetworknodepolicies.yaml | 4 ++++ ...sriovnetwork.openshift.io_sriovnetworknodestates.yaml | 8 ++++++++ pkg/host/internal/bridge/ovs/models.go | 1 + pkg/host/internal/bridge/ovs/ovs.go | 6 ++++++ pkg/host/internal/bridge/ovs/ovs_test.go | 7 +++++++ pkg/host/internal/bridge/ovs/test_db.ovsschema | 9 +++++++++ 11 files changed, 58 insertions(+) diff --git a/api/v1/helper.go b/api/v1/helper.go index 300992acb..b6baed012 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -483,6 +483,10 @@ func (p *SriovNetworkNodePolicy) ApplyBridgeConfig(state *SriovNetworkNodeState) Interface: p.Spec.Bridge.OVS.Uplink.Interface, }}, } + if p.Spec.Mtu > 0 { + mtu := p.Spec.Mtu + ovsBridge.Uplinks[0].Interface.MTURequest = &mtu + } log.Info("Update bridge for interface", "name", iface.Name, "bridge", ovsBridge.Name) // We need to keep slices with bridges ordered to avoid unnecessary updates in the K8S API. diff --git a/api/v1/sriovnetworknodepolicy_types.go b/api/v1/sriovnetworknodepolicy_types.go index 40c53e0bf..a4417ed65 100644 --- a/api/v1/sriovnetworknodepolicy_types.go +++ b/api/v1/sriovnetworknodepolicy_types.go @@ -125,6 +125,8 @@ type OVSInterfaceConfig struct { ExternalIDs map[string]string `json:"externalIDs,omitempty"` // other_config field in the Interface table in OVSDB OtherConfig map[string]string `json:"otherConfig,omitempty"` + // mtu_request field in the Interface table in OVSDB + MTURequest *int `json:"mtuRequest,omitempty"` } // SriovNetworkNodePolicyStatus defines the observed state of SriovNetworkNodePolicy diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 0209c0573..0d9d3c4cf 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -264,6 +264,11 @@ func (in *OVSInterfaceConfig) DeepCopyInto(out *OVSInterfaceConfig) { (*out)[key] = val } } + if in.MTURequest != nil { + in, out := &in.MTURequest, &out.MTURequest + *out = new(int) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OVSInterfaceConfig. diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml index 36c1050ea..524c5124e 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml @@ -81,6 +81,10 @@ spec: description: external_ids field in the Interface table in OVSDB type: object + mtuRequest: + description: mtu_request field in the Interface table + in OVSDB + type: integer options: additionalProperties: type: string diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml index 31ddf3bf1..7535346ef 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml @@ -102,6 +102,10 @@ spec: description: external_ids field in the Interface table in OVSDB type: object + mtuRequest: + description: mtu_request field in the Interface + table in OVSDB + type: integer options: additionalProperties: type: string @@ -237,6 +241,10 @@ spec: description: external_ids field in the Interface table in OVSDB type: object + mtuRequest: + description: mtu_request field in the Interface + table in OVSDB + type: integer options: additionalProperties: type: string diff --git a/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml b/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml index 36c1050ea..524c5124e 100644 --- a/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml +++ b/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml @@ -81,6 +81,10 @@ spec: description: external_ids field in the Interface table in OVSDB type: object + mtuRequest: + description: mtu_request field in the Interface table + in OVSDB + type: integer options: additionalProperties: type: string diff --git a/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml b/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml index 31ddf3bf1..7535346ef 100644 --- a/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml +++ b/deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml @@ -102,6 +102,10 @@ spec: description: external_ids field in the Interface table in OVSDB type: object + mtuRequest: + description: mtu_request field in the Interface + table in OVSDB + type: integer options: additionalProperties: type: string @@ -237,6 +241,10 @@ spec: description: external_ids field in the Interface table in OVSDB type: object + mtuRequest: + description: mtu_request field in the Interface + table in OVSDB + type: integer options: additionalProperties: type: string diff --git a/pkg/host/internal/bridge/ovs/models.go b/pkg/host/internal/bridge/ovs/models.go index 4bd356312..234a4ef32 100644 --- a/pkg/host/internal/bridge/ovs/models.go +++ b/pkg/host/internal/bridge/ovs/models.go @@ -36,6 +36,7 @@ type InterfaceEntry struct { Options map[string]string `ovsdb:"options"` ExternalIDs map[string]string `ovsdb:"external_ids"` OtherConfig map[string]string `ovsdb:"other_config"` + MTURequest *int `ovsdb:"mtu_request"` } // PortEntry represents some fields of the object in the Port table diff --git a/pkg/host/internal/bridge/ovs/ovs.go b/pkg/host/internal/bridge/ovs/ovs.go index 7ad8a3e8c..e4bae9f81 100644 --- a/pkg/host/internal/bridge/ovs/ovs.go +++ b/pkg/host/internal/bridge/ovs/ovs.go @@ -156,6 +156,7 @@ func (o *ovs) CreateOVSBridge(ctx context.Context, conf *sriovnetworkv1.OVSConfi Options: conf.Uplinks[0].Interface.Options, ExternalIDs: conf.Uplinks[0].Interface.ExternalIDs, OtherConfig: conf.Uplinks[0].Interface.OtherConfig, + MTURequest: conf.Uplinks[0].Interface.MTURequest, }); err != nil { funcLog.Error(err, "CreateOVSBridge(): failed to add uplink interface to the bridge") return err @@ -592,6 +593,10 @@ func (o *ovs) getCurrentBridgeState(ctx context.Context, dbClient client.Client, OtherConfig: updateMap(knownConfigUplink.Interface.OtherConfig, iface.OtherConfig), }, }} + if iface.MTURequest != nil { + mtu := *iface.MTURequest + currentConfig.Uplinks[0].Interface.MTURequest = &mtu + } return currentConfig, nil } @@ -707,6 +712,7 @@ func getClient(ctx context.Context) (client.Client, error) { &interfaceEntry.Options, &interfaceEntry.ExternalIDs, &interfaceEntry.OtherConfig, + &interfaceEntry.MTURequest, ), client.WithTable(portEntry, &portEntry.UUID, diff --git a/pkg/host/internal/bridge/ovs/ovs_test.go b/pkg/host/internal/bridge/ovs/ovs_test.go index 666fe9218..66be5e8ed 100644 --- a/pkg/host/internal/bridge/ovs/ovs_test.go +++ b/pkg/host/internal/bridge/ovs/ovs_test.go @@ -27,6 +27,7 @@ import ( ) func getManagedBridges() map[string]*sriovnetworkv1.OVSConfigExt { + mtu := 5000 return map[string]*sriovnetworkv1.OVSConfigExt{ "br-0000_d8_00.0": { Name: "br-0000_d8_00.0", @@ -43,6 +44,7 @@ func getManagedBridges() map[string]*sriovnetworkv1.OVSConfigExt { ExternalIDs: map[string]string{"iface_externalID_key": "iface_externalID_value"}, OtherConfig: map[string]string{"iface_otherConfig_key": "iface_otherConfig_value"}, Options: map[string]string{"iface_options_key": "iface_options_value"}, + MTURequest: &mtu, }, }}, }, @@ -83,6 +85,7 @@ func (t *testDBEntries) GetCreateOperations(c client.Client) []ovsdb.Operation { } func getDefaultInitialDBContent() *testDBEntries { + mtu := 5000 iface := &InterfaceEntry{ Name: "enp216s0f0np0", UUID: uuid.NewString(), @@ -90,6 +93,7 @@ func getDefaultInitialDBContent() *testDBEntries { ExternalIDs: map[string]string{"iface_externalID_key": "iface_externalID_value"}, OtherConfig: map[string]string{"iface_otherConfig_key": "iface_otherConfig_value"}, Options: map[string]string{"iface_options_key": "iface_options_value"}, + MTURequest: &mtu, } port := &PortEntry{ Name: "enp216s0f0np0", @@ -156,6 +160,7 @@ func validateDBConfig(dbContent *testDBEntries, conf *sriovnetworkv1.OVSConfigEx Expect(iface.Type).To(Equal(conf.Uplinks[0].Interface.Type)) Expect(iface.OtherConfig).To(Equal(conf.Uplinks[0].Interface.OtherConfig)) Expect(iface.ExternalIDs).To(Equal(conf.Uplinks[0].Interface.ExternalIDs)) + Expect(iface.MTURequest).To(Equal(conf.Uplinks[0].Interface.MTURequest)) } var _ = Describe("OVS", func() { @@ -457,6 +462,7 @@ var _ = Describe("OVS", func() { initialDBContent := getDefaultInitialDBContent() initialDBContent.Bridge[0].ExternalIDs = nil initialDBContent.Bridge[0].OtherConfig = nil + initialDBContent.Interface[0].MTURequest = nil createInitialDBContent(ctx, ovsClient, initialDBContent) conf := getManagedBridges() store.EXPECT().GetManagedOVSBridges().Return(conf, nil) @@ -465,6 +471,7 @@ var _ = Describe("OVS", func() { Expect(ret).To(HaveLen(1)) Expect(ret[0].Bridge.ExternalIDs).To(BeEmpty()) Expect(ret[0].Bridge.OtherConfig).To(BeEmpty()) + Expect(ret[0].Uplinks[0].Interface.MTURequest).To(BeNil()) }) }) Context("RemoveOVSBridge", func() { diff --git a/pkg/host/internal/bridge/ovs/test_db.ovsschema b/pkg/host/internal/bridge/ovs/test_db.ovsschema index 46c59dd0c..2b7a96a9a 100644 --- a/pkg/host/internal/bridge/ovs/test_db.ovsschema +++ b/pkg/host/internal/bridge/ovs/test_db.ovsschema @@ -105,6 +105,15 @@ }, "type": { "type": "string" + }, + "mtu_request":{ + "type": { + "key": { + "minInteger":1, + "type": "integer" + }, + "min": 0 + } } }, "indexes": [