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

do not invoke next.Close when connection not established #23

Merged
merged 2 commits into from
Sep 23, 2021
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
5 changes: 4 additions & 1 deletion pkg/networkservice/l2ovsconnect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func (c *l2ConnectClient) Request(ctx context.Context, request *networkservice.N

postponeCtxFunc := postpone.ContextWithValues(ctx)

isEstablished := request.GetConnection().GetNextPathSegment() != nil
var isEstablished bool
if endpointOvsPortInfo, exists := ifnames.Load(ctx, false); exists {
isEstablished = endpointOvsPortInfo.IsCrossConnected
}

conn, err := next.Client(ctx).Request(ctx, request, opts...)
if err != nil || isEstablished {
Expand Down
4 changes: 4 additions & 0 deletions pkg/networkservice/l2ovsconnect/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func createLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo
logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+
" stderr: %s", bridgeName, clientOvsPortInfo.PortName, stdout, stderr)
}

endpointOvsPortInfo.IsCrossConnected = true
clientOvsPortInfo.IsCrossConnected = true

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/networkservice/l2ovsconnect/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func createRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP
" stderr: %s", bridgeName, ovsTunnelPort, stdout, stderr)
}

endpointOvsPortInfo.IsCrossConnected = true
clientOvsPortInfo.IsCrossConnected = true

return nil
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/networkservice/mechanisms/kernel/smartvf_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewSmartVFServer(bridgeName string) networkservice.NetworkServiceServer {
func (k *kernelSmartVFServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
logger := log.FromContext(ctx).WithField("kernelSmartVFServer", "Request")

isEstablished := request.GetConnection().GetNextPathSegment() != nil
_, isEstablished := ifnames.Load(ctx, metadata.IsClient(k))
if !isEstablished {
if vfErr := setupVF(ctx, logger, request.GetConnection(), k.bridgeName, metadata.IsClient(k)); vfErr != nil {
return nil, vfErr
Expand All @@ -60,9 +60,10 @@ func (k *kernelSmartVFServer) Request(ctx context.Context, request *networkservi
if err != nil && !isEstablished {
closeCtx, cancelClose := postponeCtxFunc()
defer cancelClose()

if _, closeErr := k.Close(closeCtx, conn); closeErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error())
if ovsPortInfo, exists := ifnames.LoadAndDelete(closeCtx, metadata.IsClient(k)); exists {
if kernelServerErr := resetVF(logger, ovsPortInfo, k.bridgeName); kernelServerErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", kernelServerErr.Error())
}
}
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/networkservice/mechanisms/kernel/veth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func NewVethServer(bridgeName string) networkservice.NetworkServiceServer {
func (k *kernelVethServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
logger := log.FromContext(ctx).WithField("kernelVethServer", "Request")

isEstablished := request.GetConnection().GetNextPathSegment() != nil
_, isEstablished := ifnames.Load(ctx, metadata.IsClient(k))
if !isEstablished {
if err := setupVeth(ctx, logger, request.Connection, k.bridgeName, metadata.IsClient(k)); err != nil {
_ = resetVeth(ctx, logger, request.Connection, k.bridgeName, metadata.IsClient(k))
if err := setupVeth(ctx, logger, request.GetConnection(), k.bridgeName, metadata.IsClient(k)); err != nil {
_ = resetVeth(ctx, logger, request.GetConnection(), k.bridgeName, metadata.IsClient(k))
return nil, err
}
}
Expand All @@ -60,9 +60,10 @@ func (k *kernelVethServer) Request(ctx context.Context, request *networkservice.
if err != nil && !isEstablished {
closeCtx, cancelClose := postponeCtxFunc()
defer cancelClose()

if _, closeErr := k.Close(closeCtx, conn); closeErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error())
if _, exists := ifnames.LoadAndDelete(closeCtx, metadata.IsClient(k)); exists {
if kernelServerErr := resetVeth(closeCtx, logger, request.GetConnection(), k.bridgeName, metadata.IsClient(k)); kernelServerErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", kernelServerErr.Error())
}
}
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/networkservice/mechanisms/vxlan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/vxlan/vni"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/postpone"
"github.com/pkg/errors"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk-ovs/pkg/tools/ifnames"
)

type vxlanClient struct {
Expand All @@ -59,7 +62,7 @@ func (c *vxlanClient) Request(ctx context.Context, request *networkservice.Netwo
Type: vxlan.MECHANISM,
})

isEstablished := request.GetConnection().GetNextPathSegment() != nil
_, isEstablished := ifnames.Load(ctx, metadata.IsClient(c))

postponeCtxFunc := postpone.ContextWithValues(ctx)

Expand Down
9 changes: 5 additions & 4 deletions pkg/networkservice/mechanisms/vxlan/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewServer(tunnelIP net.IP, bridgeName string, mutex sync.Locker, vxlanRefCo
func (v *vxlanServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
logger := log.FromContext(ctx).WithField("vxlanServer", "Request")

isEstablished := request.GetConnection().GetNextPathSegment() != nil
_, isEstablished := ifnames.Load(ctx, metadata.IsClient(v))

if !isEstablished {
if err := add(ctx, logger, request.GetConnection(), v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v)); err != nil {
Expand All @@ -71,9 +71,10 @@ func (v *vxlanServer) Request(ctx context.Context, request *networkservice.Netwo
if err != nil && !isEstablished {
closeCtx, cancelClose := postponeCtxFunc()
defer cancelClose()

if _, closeErr := v.Close(closeCtx, conn); closeErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error())
if _, exists := ifnames.LoadAndDelete(closeCtx, metadata.IsClient(v)); exists {
if vxlanServerErr := remove(request.GetConnection(), v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v)); vxlanServerErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", vxlanServerErr.Error())
}
}
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/tools/ifnames/ifnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ type key struct{}

// OvsPortInfo ovs port info container
type OvsPortInfo struct {
PortName string
PortNo int
IsTunnelPort bool
IsVfRepresentor bool
VNI uint32
PortName string
PortNo int
IsTunnelPort bool
IsVfRepresentor bool
IsCrossConnected bool
VNI uint32
}

// Store stores ovsPortInfo for the given cross connect, isClient identfies which connection it is.
Expand Down