Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port all remaining OVS functions to libovsdb #768

Merged
merged 10 commits into from
Apr 18, 2024
15 changes: 7 additions & 8 deletions internal/server/device/nic_bridged.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,12 @@ func (d *nicBridged) setupOVSBridgePortVLANs(hostName string) error {
// Order is important here, as vlan_mode is set to "access", assuming that vlan.tagged is not used.
// If vlan.tagged is specified, then we expect it to also change the vlan_mode as needed.
if d.config["vlan"] != "none" {
err := vswitch.BridgePortSet(hostName, "vlan_mode=access", fmt.Sprintf("tag=%s", d.config["vlan"]))
vlanID, err := strconv.Atoi(d.config["vlan"])
if err != nil {
return err
}

err = vswitch.UpdateBridgePortVLANs(context.TODO(), hostName, "access", vlanID, nil)
if err != nil {
return err
}
Expand All @@ -1567,12 +1572,6 @@ func (d *nicBridged) setupOVSBridgePortVLANs(hostName string) error {
return err
}

var vlanIDs []string

for _, intNetworkVLAN := range intNetworkVLANs {
vlanIDs = append(vlanIDs, strconv.Itoa(intNetworkVLAN))
}

vlanMode := "trunk" // Default to only allowing tagged frames (drop untagged frames).
if d.config["vlan"] != "none" {
// If untagged vlan mode isn't "none" then allow untagged frames for port's 'native' VLAN.
Expand All @@ -1583,7 +1582,7 @@ func (d *nicBridged) setupOVSBridgePortVLANs(hostName string) error {
// Also set the vlan_mode as needed from above.
// Must come after the PortSet command used for setting "vlan" mode above so that the correct
// vlan_mode is retained.
err = vswitch.BridgePortSet(hostName, fmt.Sprintf("vlan_mode=%s", vlanMode), fmt.Sprintf("trunks=%s", strings.Join(vlanIDs, ",")))
err = vswitch.UpdateBridgePortVLANs(context.TODO(), hostName, vlanMode, 0, intNetworkVLANs)
if err != nil {
return err
}
Expand Down
16 changes: 13 additions & 3 deletions internal/server/device/nic_ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ func (d *nicOVN) Start() (*deviceConfig.RunConfig, error) {
return nil, fmt.Errorf("Failed to connect to OVS: %w", err)
}

if !vswitch.HardwareOffloadingEnabled() {
offload, err := vswitch.GetHardwareOffload(context.TODO())
if err != nil {
return nil, err
}

if !offload {
return nil, fmt.Errorf("SR-IOV acceleration requires hardware offloading be enabled in OVS")
}

Expand Down Expand Up @@ -484,7 +489,12 @@ func (d *nicOVN) Start() (*deviceConfig.RunConfig, error) {
return nil, fmt.Errorf("Failed to connect to OVS: %w", err)
}

if !vswitch.HardwareOffloadingEnabled() {
offload, err := vswitch.GetHardwareOffload(context.TODO())
if err != nil {
return nil, err
}

if !offload {
return nil, fmt.Errorf("SR-IOV acceleration requires hardware offloading be enabled in OVS")
}

Expand Down Expand Up @@ -1169,7 +1179,7 @@ func (d *nicOVN) setupHostNIC(hostName string, ovnPortName ovn.OVNSwitchPort, up
revert.Add(func() { _ = vswitch.DeleteBridgePort(context.TODO(), integrationBridge, hostName) })

// Link OVS port to OVN logical port.
err = vswitch.InterfaceAssociateOVNSwitchPort(hostName, string(ovnPortName))
err = vswitch.AssociateInterfaceOVNSwitchPort(context.TODO(), hostName, string(ovnPortName))
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions internal/server/network/driver_ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func (n *ovn) getUnderlayInfo() (uint32, net.IP, error) {
return 0, nil, fmt.Errorf("Failed to connect to OVS: %w", err)
}

encapIP, err := vswitch.OVNEncapIP()
encapIP, err := vswitch.GetOVNEncapIP(context.TODO())
if err != nil {
return 0, nil, fmt.Errorf("Failed getting OVN enscapsulation IP from OVS: %w", err)
}
Expand Down Expand Up @@ -1374,7 +1374,7 @@ func (n *ovn) startUplinkPortBridgeNative(uplinkNet Network, bridgeDevice string
}

// Associate OVS bridge to logical OVN provider.
err = vswitch.OVNBridgeMappingAdd(vars.ovsBridge, uplinkNet.Name())
err = vswitch.AddOVNBridgeMapping(context.TODO(), vars.ovsBridge, uplinkNet.Name())
if err != nil {
return fmt.Errorf("Failed to associate uplink OVS bridge %q to OVN provider %q: %w", vars.ovsBridge, uplinkNet.Name(), err)
}
Expand All @@ -1398,7 +1398,7 @@ func (n *ovn) startUplinkPortBridgeOVS(uplinkNet Network, bridgeDevice string) e
return fmt.Errorf("Failed to connect to OVS: %w", err)
}

err = vswitch.OVNBridgeMappingAdd(bridgeDevice, uplinkNet.Name())
err = vswitch.AddOVNBridgeMapping(context.TODO(), bridgeDevice, uplinkNet.Name())
if err != nil {
return fmt.Errorf("Failed to associate uplink OVS bridge %q to OVN provider %q: %w", bridgeDevice, uplinkNet.Name(), err)
}
Expand Down Expand Up @@ -1520,7 +1520,7 @@ func (n *ovn) startUplinkPortPhysical(uplinkNet Network) error {
}

// Associate OVS bridge to logical OVN provider.
err = vswitch.OVNBridgeMappingAdd(vars.ovsBridge, uplinkNet.Name())
err = vswitch.AddOVNBridgeMapping(context.TODO(), vars.ovsBridge, uplinkNet.Name())
if err != nil {
return fmt.Errorf("Failed to associate uplink OVS bridge %q to OVN provider %q: %w", vars.ovsBridge, uplinkNet.Name(), err)
}
Expand Down Expand Up @@ -1632,7 +1632,7 @@ func (n *ovn) deleteUplinkPortBridgeNative(uplinkNet Network) error {
return fmt.Errorf("Failed to connect to OVS: %w", err)
}

err = vswitch.OVNBridgeMappingDelete(vars.ovsBridge, uplinkNet.Name())
err = vswitch.RemoveOVNBridgeMapping(context.TODO(), vars.ovsBridge, uplinkNet.Name())
if err != nil {
return err
}
Expand Down Expand Up @@ -1682,7 +1682,7 @@ func (n *ovn) deleteUplinkPortBridgeOVS(uplinkNet Network, ovsBridge string) err
return fmt.Errorf("Failed to connect to OVS: %w", err)
}

err = vswitch.OVNBridgeMappingDelete(ovsBridge, uplinkNet.Name())
err = vswitch.RemoveOVNBridgeMapping(context.TODO(), ovsBridge, uplinkNet.Name())
if err != nil {
return err
}
Expand Down Expand Up @@ -1729,7 +1729,7 @@ func (n *ovn) deleteUplinkPortPhysical(uplinkNet Network) error {
if !uplinkUsed {
releaseIF = true

err = vswitch.OVNBridgeMappingDelete(vars.ovsBridge, uplinkNet.Name())
err = vswitch.RemoveOVNBridgeMapping(context.TODO(), vars.ovsBridge, uplinkNet.Name())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/network/network_utils_sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func SRIOVFindFreeVFAndRepresentor(state *state.State, ovsBridgeName string) (st
}

// Get all ports on the integration bridge.
ports, err := vswitch.BridgePortList(ovsBridgeName)
ports, err := vswitch.GetBridgePorts(context.TODO(), ovsBridgeName)
if err != nil {
return "", "", "", -1, fmt.Errorf("Failed to get port list: %w", err)
}
Expand Down
Loading
Loading