Skip to content

Commit

Permalink
Support mtu_request for OVS
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rollandf committed Jan 8, 2025
1 parent eb2fa5f commit e49dac0
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions api/v1/sriovnetworknodepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/host/internal/bridge/ovs/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/host/internal/bridge/ovs/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions pkg/host/internal/bridge/ovs/ovs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
},
}},
},
Expand Down Expand Up @@ -83,13 +85,15 @@ func (t *testDBEntries) GetCreateOperations(c client.Client) []ovsdb.Operation {
}

func getDefaultInitialDBContent() *testDBEntries {
mtu := 5000
iface := &InterfaceEntry{
Name: "enp216s0f0np0",
UUID: uuid.NewString(),
Type: "dpdk",
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",
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/host/internal/bridge/ovs/test_db.ovsschema
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@
},
"type": {
"type": "string"
},
"mtu_request":{
"type": {
"key": {
"minInteger":1,
"type": "integer"
},
"min": 0
}
}
},
"indexes": [
Expand Down

0 comments on commit e49dac0

Please sign in to comment.