Skip to content

Commit

Permalink
Provides a possible way to set interface's type of one port (#252)
Browse files Browse the repository at this point in the history
* Provides a possible way to set interface's type of one port when cni call func 'attachIfaceToBridge’.In order to accommodate this function, also expanded type NetConf for ovs-cni.The availability of the afxdp type interface has been verified.

Signed-off-by: wangyueyu <[email protected]>

* Add test Content with interfaces of type system

Signed-off-by: wangyueyu <[email protected]>

Signed-off-by: wangyueyu <[email protected]>
Co-authored-by: wangyueyu <[email protected]>
  • Loading branch information
wangyueyu64 and wangyueyu authored Jan 3, 2023
1 parent 3019a1a commit 9b91227
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
12 changes: 12 additions & 0 deletions docs/cni-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ Another example with a trunk port and jumbo frames:
}
```

Another example with a port which has an interface of type system:

```json
{
"name": "overlaynet",
"type": "ovs",
"bridge": "mynet1",
"interface_type": "system"
}
```

## Network Configuration Reference

* `name` (string, required): the name of the network.
Expand All @@ -46,6 +57,7 @@ Another example with a trunk port and jumbo frames:
* `trunk` (optional): List of VLAN ID's and/or ranges of accepted VLAN
ID's.
* `ofport_request` (integer, optional): request a static OpenFlow port number in range 1 to 65,279
* `interface_type` (string, optional): type of the interface belongs to ports. if value is "", ovs will use default interface of type 'internal'
* `configuration_path` (optional): configuration file containing ovsdb
socket file path, etc.

Expand Down
11 changes: 8 additions & 3 deletions pkg/ovsdb/ovsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (ovsd *OvsDriver) ovsdbTransact(ops []ovsdb.Operation) ([]ovsdb.OperationRe
// **************** OVS driver API ********************

// CreatePort Create an internal port in OVS
func (ovsd *OvsBridgeDriver) CreatePort(intfName, contNetnsPath, contIfaceName, ovnPortName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string) error {
intfUUID, intfOp, err := createInterfaceOperation(intfName, ofportRequest, ovnPortName)
func (ovsd *OvsBridgeDriver) CreatePort(intfName, contNetnsPath, contIfaceName, ovnPortName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, intfType string) error {
intfUUID, intfOp, err := createInterfaceOperation(intfName, ofportRequest, ovnPortName, intfType)
if err != nil {
return err
}
Expand Down Expand Up @@ -782,13 +782,18 @@ func (ovsd *OvsDriver) isMirrorExistsByConditions(conditions []ovsdb.Condition)
return true, nil
}

func createInterfaceOperation(intfName string, ofportRequest uint, ovnPortName string) (ovsdb.UUID, *ovsdb.Operation, error) {
func createInterfaceOperation(intfName string, ofportRequest uint, ovnPortName string, intfType string) (ovsdb.UUID, *ovsdb.Operation, error) {
intfUUIDStr := fmt.Sprintf("Intf%s", intfName)
intfUUID := ovsdb.UUID{GoUUID: intfUUIDStr}

intf := make(map[string]interface{})
intf["name"] = intfName

// Configure interface type if not nil
if intfType != "" {
intf["type"] = intfType
}

// Configure interface ID for ovn
if ovnPortName != "" {
oMap, err := ovsdb.NewOvsMap(map[string]string{"iface-id": ovnPortName})
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func getBridgeName(bridgeName, ovnPort string) (string, error) {
return "", fmt.Errorf("failed to get bridge name")
}

func attachIfaceToBridge(ovsDriver *ovsdb.OvsBridgeDriver, hostIfaceName string, contIfaceName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, contNetnsPath string, ovnPortName string) error {
err := ovsDriver.CreatePort(hostIfaceName, contNetnsPath, contIfaceName, ovnPortName, ofportRequest, vlanTag, trunks, portType)
func attachIfaceToBridge(ovsDriver *ovsdb.OvsBridgeDriver, hostIfaceName string, contIfaceName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, intfType string, contNetnsPath string, ovnPortName string) error {
err := ovsDriver.CreatePort(hostIfaceName, contNetnsPath, contIfaceName, ovnPortName, ofportRequest, vlanTag, trunks, portType, intfType)
if err != nil {
return err
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func CmdAdd(args *skel.CmdArgs) error {
}
}

if err = attachIfaceToBridge(ovsDriver, hostIface.Name, contIface.Name, netconf.OfportRequest, vlanTagNum, trunks, portType, args.Netns, ovnPort); err != nil {
if err = attachIfaceToBridge(ovsDriver, hostIface.Name, contIface.Name, netconf.OfportRequest, vlanTagNum, trunks, portType, netconf.InterfaceType, args.Netns, ovnPort); err != nil {
return err
}

Expand Down
47 changes: 45 additions & 2 deletions pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/k8snetworkplumbingwg/ovs-cni/pkg/config"
"math/rand"
"net"
"os/exec"
Expand Down Expand Up @@ -71,6 +72,7 @@ type Net040 struct {
IPAM *IPAMConfig `json:"ipam"`
VlanTag *uint `json:"vlan"`
Trunk []*types.Trunk `json:"trunk,omitempty"`
InterfaceType string `json:"interface_type"`
RawPrevResult map[string]interface{} `json:"prevResult,omitempty"`
PrevResult types040.Result `json:"-"`
}
Expand All @@ -83,6 +85,7 @@ type NetCurrent struct {
IPAM *IPAMConfig `json:"ipam"`
VlanTag *uint `json:"vlan"`
Trunk []*types.Trunk `json:"trunk,omitempty"`
InterfaceType string `json:"interface_type"`
RawPrevResult map[string]interface{} `json:"prevResult,omitempty"`
PrevResult current.Result `json:"-"`
}
Expand All @@ -92,6 +95,7 @@ const vlanID = 100
const mtu = 1456
const defaultMTU = 1500
const IFNAME = "eth0"
const systemType = "system"

var _ = BeforeSuite(func() {
output, err := exec.Command("ovs-vsctl", "show").CombinedOutput()
Expand Down Expand Up @@ -319,7 +323,9 @@ var testFunc = func(version string) {
Expect(hostLink).To(BeNil())

By("Checking that the port on OVS bridge was deleted")
brPorts, err := listBridgePorts(bridgeName)
netconf, err := config.LoadConf(args.StdinData)
Expect(err).NotTo(HaveOccurred())
brPorts, err := listBridgePorts(netconf.BrName)
Expect(err).NotTo(HaveOccurred())
Expect(len(brPorts)).To(Equal(0))
}
Expand Down Expand Up @@ -357,7 +363,9 @@ var testFunc = func(version string) {
Expect(hostLink.Attrs().HardwareAddr).To(Equal(hostHwaddr))

By("Checking that the host iface is connected as a port to the bridge")
brPorts, err := listBridgePorts(bridgeName)
netconf, err := config.LoadConf(args.StdinData)
Expect(err).NotTo(HaveOccurred())
brPorts, err := listBridgePorts(netconf.BrName)
Expect(err).NotTo(HaveOccurred())
Expect(brPorts).To(Equal([]string{hostIface.Name}))

Expand Down Expand Up @@ -696,6 +704,41 @@ var testFunc = func(version string) {
}, time.Minute, 100*time.Millisecond).Should(Equal(true))
})
})
Context("with interface of type system for port", func() {
conf := fmt.Sprintf(`{
"cniVersion": "%s",
"name": "mynet",
"type": "ovs",
"bridge": "%s",
"interface_type": "%s"
}`, version, bridgeName, systemType)
It("should successfully complete ADD and DEL commands", func() {
targetNs := newNS()
defer func() {
closeNS(targetNs)
}()
hostIfName, result := testAdd(conf, false, false, "", targetNs)
testCheck(conf, result, targetNs)
testDel(conf, hostIfName, targetNs, true)
})
})
Context("without interface type on port", func() {
conf := fmt.Sprintf(`{
"cniVersion": "%s",
"name": "mynet",
"type": "ovs",
"bridge": "%s"
}`, version, bridgeName)
It("should successfully complete ADD, CHECK and DEL commands", func() {
targetNs := newNS()
defer func() {
closeNS(targetNs)
}()
hostIfName, result := testAdd(conf, false, false, "", targetNs)
testCheck(conf, result, targetNs)
testDel(conf, hostIfName, targetNs, true)
})
})
Context("specify trunk with multiple ranges", func() {
trunks := `[ {"minID": 10, "maxID": 12}, {"minID": 19, "maxID": 20} ]`
It("testSplitVlanIds method should return with specifed values in the range", func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type NetConf struct {
Trunk []*Trunk `json:"trunk,omitempty"`
DeviceID string `json:"deviceID"` // PCI address of a VF in valid sysfs format
OfportRequest uint `json:"ofport_request"` // OpenFlow port number in range 1 to 65,279
InterfaceType string `json:"interface_type"` // The type of interface on ovs.
ConfigurationPath string `json:"configuration_path"`
SocketFile string `json:"socket_file"`
LinkStateCheckRetries int `json:"link_state_check_retries"`
Expand Down

0 comments on commit 9b91227

Please sign in to comment.