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

use vfconfig metadata for storing VF and veth interface name #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require (
github.com/golang/protobuf v1.5.2
github.com/networkservicemesh/api v1.0.1-0.20210811070028-10403c0f20c8
github.com/networkservicemesh/sdk v0.5.1-0.20210827110808-c2178d55e7a9
github.com/networkservicemesh/sdk-kernel v0.0.0-20210827111123-3641f2295562
github.com/networkservicemesh/sdk-sriov v0.0.0-20210827111445-4aa6b43ea849
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20210805134717-4eed62af8e0e
github.com/networkservicemesh/sdk-kernel v0.0.0-20210829205539-eba0791ab5ef
github.com/networkservicemesh/sdk-sriov v0.0.0-20210830075447-a20f8ee43eee
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20210826171620-f06c53111a31
github.com/pkg/errors v0.9.1
github.com/vishvananda/netlink v1.1.1-0.20210518155637-4cb3795f2ccb
google.golang.org/grpc v1.35.0
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
)
109 changes: 61 additions & 48 deletions go.sum

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions pkg/networkservice/chains/xconnectns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/connectioncontextkernel"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/inject"
"github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/resourcepool"
"github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/vfconfig"

"github.com/networkservicemesh/sdk-sriov/pkg/sriov"
"github.com/networkservicemesh/sdk-sriov/pkg/sriov/config"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
Expand Down Expand Up @@ -90,7 +90,6 @@ func newEndPoint(ctx context.Context, name string, authzServer, resourcePoolServ
metadata.NewServer(),
recvfd.NewServer(),
sendfd.NewServer(),
vfconfig.NewServer(),
// Statically set the url we use to the unix file socket for the NSMgr
clienturl.NewServer(clientURL),
heal.NewServer(ctx,
Expand All @@ -116,8 +115,6 @@ func newEndPoint(ctx context.Context, name string, authzServer, resourcePoolServ
// mechanisms
kernel.NewClient(bridgeName),
resourcePoolClient,
// uncomment when vfconfig client chain element available
// vfconfig.NewClient(),
vxlan.NewClient(tunnelIP, bridgeName, vxlanInterfacesMutex, vxlanInterfaces),
recvfd.NewClient(),
sendfd.NewClient(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/mechanisms/kernel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *kernelClient) Close(ctx context.Context, conn *networkservice.Connectio
ovsPortInfo, exists := ifnames.Load(ctx, metadata.IsClient(c))
if exists {
if !ovsPortInfo.IsVfRepresentor {
kernelMechErr = resetVeth(logger, conn, c.bridgeName, metadata.IsClient(c))
kernelMechErr = resetVeth(ctx, logger, conn, c.bridgeName, metadata.IsClient(c))
} else {
kernelMechErr = resetVF(logger, ovsPortInfo, c.bridgeName)
}
Expand Down
43 changes: 31 additions & 12 deletions pkg/networkservice/mechanisms/kernel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/vfconfig"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
"github.com/pkg/errors"
Expand All @@ -35,9 +36,11 @@ import (
)

const (
srcPrefix = "tapsrc"
dstPrefix = "tapdst"
cVETHMTU = 16000
ovsPortSrcPrefix = "tapsrc"
ovsPortDstPrefix = "tapdst"
contPortSrcPrefix = "contsrc"
contPortDstPrefix = "contdst"
cVETHMTU = 16000
)

func setupVeth(ctx context.Context, logger log.Logger, conn *networkservice.Connection, bridgeName string, isClient bool) error {
Expand All @@ -48,8 +51,17 @@ func setupVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn
if _, ok := ifnames.Load(ctx, isClient); ok {
return nil
}
contIfName := mechanism.GetInterfaceName()
hostIfName := GetOvsInterfaceName(conn, isClient)

// use intermediate contIfName to avoid interface name collision with parallel service requests from other clients.
var hostIfName, contIfName string
if isClient {
hostIfName = GetVethPeerName(conn, ovsPortDstPrefix, true)
contIfName = GetVethPeerName(conn, contPortDstPrefix, true)
} else {
hostIfName = GetVethPeerName(conn, ovsPortSrcPrefix, false)
contIfName = GetVethPeerName(conn, contPortSrcPrefix, false)
}

if err := createInterfaces(contIfName, hostIfName); err != nil {
return err
}
Expand All @@ -68,12 +80,20 @@ func setupVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn
" error: %v", hostIfName, err)
return err
}

vfconfig.Store(ctx, isClient, &vfconfig.VFConfig{VFInterfaceName: contIfName})
ifnames.Store(ctx, isClient, &ifnames.OvsPortInfo{PortName: hostIfName, PortNo: portNo, IsTunnelPort: false})

return nil
}

func resetVeth(logger log.Logger, conn *networkservice.Connection, bridgeName string, isClient bool) error {
ifaceName := GetOvsInterfaceName(conn, isClient)
func resetVeth(ctx context.Context, logger log.Logger, conn *networkservice.Connection, bridgeName string, isClient bool) error {
var ifaceName string
if isClient {
ifaceName = GetVethPeerName(conn, ovsPortDstPrefix, true)
} else {
ifaceName = GetVethPeerName(conn, ovsPortSrcPrefix, false)
}
/* delete the port from ovs bridge */
stdout, stderr, err := util.RunOVSVsctl("del-port", bridgeName, ifaceName)
if err != nil {
Expand All @@ -95,6 +115,7 @@ func resetVeth(logger log.Logger, conn *networkservice.Connection, bridgeName st
if err := netlink.LinkDel(ifaceLink); err != nil {
return errors.Errorf("local: failed to delete the VETH pair - %v", err)
}
vfconfig.Delete(ctx, isClient)
return nil
}

Expand Down Expand Up @@ -135,16 +156,14 @@ func newVETH(srcName, dstName string) *netlink.Veth {
}
}

// GetOvsInterfaceName get ovs interface name for the given connection.
func GetOvsInterfaceName(conn *networkservice.Connection, isClient bool) string {
// GetVethPeerName get appropriate veth peer interface name for the given connection.
func GetVethPeerName(conn *networkservice.Connection, ifPrefix string, isClient bool) string {
namingConn := conn.Clone()
prefix := srcPrefix
namingConn.Id = namingConn.GetPrevPathSegment().GetId()
if isClient {
prefix = dstPrefix
namingConn.Id = namingConn.GetNextPathSegment().GetId()
}
name := fmt.Sprintf("%s-%s", prefix, conn.GetId())
name := fmt.Sprintf("%s-%s", ifPrefix, conn.GetId())
if len(name) > kernel.LinuxIfMaxLength {
name = name[:kernel.LinuxIfMaxLength]
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/networkservice/mechanisms/kernel/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func (k *kernelServer) Request(ctx context.Context, request *networkservice.Netw
_, exists := request.GetConnection().GetMechanism().GetParameters()[resourcepool.TokenIDKey]
if !exists && !isEstablished {
if err := setupVeth(ctx, logger, request.Connection, k.bridgeName, metadata.IsClient(k)); err != nil {
_ = resetVeth(logger, request.Connection, k.bridgeName, metadata.IsClient(k))
_ = resetVeth(ctx, logger, request.Connection, k.bridgeName, metadata.IsClient(k))
return nil, err
}
}
conn, err := next.Server(ctx).Request(ctx, request)
if err != nil && !exists && !isEstablished {
_ = resetVeth(logger, request.Connection, k.bridgeName, metadata.IsClient(k))
_ = resetVeth(ctx, logger, request.Connection, k.bridgeName, metadata.IsClient(k))
return nil, err
}
if exists && !isEstablished {
Expand All @@ -74,7 +74,7 @@ func (k *kernelServer) Close(ctx context.Context, conn *networkservice.Connectio
ovsPortInfo, exists := ifnames.LoadAndDelete(ctx, metadata.IsClient(k))
if exists {
if !ovsPortInfo.IsVfRepresentor {
kernelServerErr = resetVeth(logger, conn, k.bridgeName, metadata.IsClient(k))
kernelServerErr = resetVeth(ctx, logger, conn, k.bridgeName, metadata.IsClient(k))
} else {
kernelServerErr = resetVF(logger, ovsPortInfo, k.bridgeName)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/networkservice/mechanisms/kernel/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package kernel

import (
"context"
"errors"

"github.com/Mellanox/sriovnet"
"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand All @@ -40,7 +41,11 @@ func setupVF(ctx context.Context, logger log.Logger, conn *networkservice.Connec
if _, ok := ifnames.Load(ctx, isClient); ok {
return nil
}
vfConfig := vfconfig.Config(ctx)

vfConfig, exists := vfconfig.Load(ctx, isClient)
if !exists {
return errors.New("vfconfig not found")
}
// get smart VF representor interface. This is a host net device which represents
// smart VF attached inside the container by device plugin. It can be considered
// as one end of veth pair whereas other end is smartVF. The VF representor would
Expand Down