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

Change xconnect to bridge domain in case of remote vlan #634

Merged
merged 1 commit into from
Nov 16, 2022
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
git.fd.io/govpp.git v0.3.6-0.20210927044411-385ccc0d8ba9
github.com/edwarnicke/govpp v0.0.0-20220509171552-731995b8f574
github.com/edwarnicke/govpp v0.0.0-20221023154218-ef9a6adf6930
github.com/edwarnicke/serialize v1.0.7
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/edwarnicke/exechelper v1.0.2 h1:dD49Ui2U0FBFxxhalnKw6vLS0P0TkgnXBRvKL/xmC5w=
github.com/edwarnicke/exechelper v1.0.2/go.mod h1:/T271jtNX/ND4De6pa2aRy2+8sNtyCDB1A2pp4M+fUs=
github.com/edwarnicke/govpp v0.0.0-20220509171552-731995b8f574 h1:2lYhLBDjflBOPJLd/42txk9QlSkVep6p1vKzlvkCKOI=
github.com/edwarnicke/govpp v0.0.0-20220509171552-731995b8f574/go.mod h1:kHDnxA+SSNFeMEHz7xvhub1zvx4mOTRlWWRCay2n5NM=
github.com/edwarnicke/govpp v0.0.0-20221023154218-ef9a6adf6930 h1:/gS3gW7jV6ljzWcnHGxu1Yn1guxtwq8IuwJpK5TUl1w=
github.com/edwarnicke/govpp v0.0.0-20221023154218-ef9a6adf6930/go.mod h1:kHDnxA+SSNFeMEHz7xvhub1zvx4mOTRlWWRCay2n5NM=
github.com/edwarnicke/grpcfd v1.1.2 h1:2b8kCABQ1+JjSKGDoHadqSW7whCeTXMqtyo6jmB5B8k=
github.com/edwarnicke/grpcfd v1.1.2/go.mod h1:rHihB9YvNMixz8rS+ZbwosI2kj65VLkeyYAI2M+/cGA=
github.com/edwarnicke/serialize v0.0.0-20200705214914-ebc43080eecf/go.mod h1:XvbCO/QGsl3X8RzjBMoRpkm54FIAZH5ChK2j+aox7pw=
Expand Down
2 changes: 2 additions & 0 deletions pkg/networkservice/chains/forwarder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import (
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/tag"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/up"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/xconnect"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/xconnect/l2bridgedomain"
)

// Connection aggregates the api.Connection and api.ChannelProvider interfaces
Expand Down Expand Up @@ -111,6 +112,7 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn
stats.NewServer(ctx, opts.statsOpts...),
up.NewServer(ctx, vppConn),
xconnect.NewServer(vppConn),
l2bridgedomain.NewServer(vppConn),
connectioncontextkernel.NewServer(),
ethernetcontext.NewVFServer(),
tag.NewServer(ctx, vppConn),
Expand Down
4 changes: 1 addition & 3 deletions pkg/networkservice/mechanisms/vlan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/postpone"

"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vlan/hwaddress"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vlan/l2vtr"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vlan/mtu"
)
Expand All @@ -49,7 +48,6 @@ type vlanClient struct {
// NewClient returns a VLAN client chain element
func NewClient(vppConn api.Connection, domain2Device map[string]string) networkservice.NetworkServiceClient {
return chain.NewNetworkServiceClient(
hwaddress.NewClient(vppConn),
mtu.NewClient(vppConn),
l2vtr.NewClient(vppConn),
&vlanClient{
Expand Down Expand Up @@ -89,6 +87,6 @@ func (v *vlanClient) Request(ctx context.Context, request *networkservice.Networ
}

func (v *vlanClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
_ = delSubIf(ctx, conn, v.vppConn)
delSubIf(ctx, conn)
return next.Client(ctx).Close(ctx, conn, opts...)
}
117 changes: 57 additions & 60 deletions pkg/networkservice/mechanisms/vlan/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package vlan
import (
"context"
"io"
"strings"
"time"

"git.fd.io/govpp.git/api"
Expand Down Expand Up @@ -49,57 +50,69 @@ func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.
if !ok {
return errors.Errorf("no interface name for label %s", via)
}

now := time.Now()
client, err := interfaces.NewServiceClient(vppConn).SwInterfaceDump(ctx, &interfaces.SwInterfaceDump{
NameFilterValid: true,
NameFilter: hostIFName,
})
vlanID := mechanism.GetVlanID()
hostSwIfIndex, vlanSwIfIndex, err := getHostOrVlanInterface(ctx, vppConn, hostIFName, vlanID)
if err != nil {
return errors.Wrapf(err, "error attempting to get interface dump client to set vlan subinterface on %q", hostIFName)
return err
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("HostInterfaceName", hostIFName).
WithField("vppapi", "SwInterfaceDump").Debug("completed")

for {
details, err := client.Recv()
if err == io.EOF {
break
}
if err != nil {
return errors.Wrapf(err, "error attempting to get interface details to set vlan subinterface on %q", hostIFName)
}

if (hostIFName != details.InterfaceName) && (afPacketNamePrefix+hostIFName != details.InterfaceName) {
if vlanID != 0 {
if vlanSwIfIndex != 0 {
log.FromContext(ctx).
WithField("InterfaceName", details.InterfaceName).
WithField("vppapi", "SwInterfaceDetails").Debug("skipped")
continue
}

swIfIndex := details.SwIfIndex
vlanID := mechanism.GetVlanID()
if vlanID != 0 {
vlanIfIndex, shouldReturn, returnValue := vppAddSubIf(ctx, vppConn, swIfIndex, vlanID)
WithField("VlanInterfaceIndex", vlanSwIfIndex).Debug("Vlan Interface already created")
ifindex.Store(ctx, true, vlanSwIfIndex)
} else {
newVlanIfIndex, shouldReturn, returnValue := vppAddSubIf(ctx, vppConn, hostSwIfIndex, vlanID)
if shouldReturn {
return returnValue
}
ifindex.Store(ctx, true, *vlanIfIndex)
} else {
log.FromContext(ctx).
WithField("HostInterfaceIndex", swIfIndex).
WithField("Details", details).Debug("QinQ disabled")
ifindex.Store(ctx, true, swIfIndex)
ifindex.Store(ctx, true, *newVlanIfIndex)
}
return nil
} else {
log.FromContext(ctx).
WithField("HostInterfaceIndex", hostSwIfIndex).Debug("QinQ disabled")
ifindex.Store(ctx, true, hostSwIfIndex)
}
return errors.Errorf("no interface name found %s", hostIFName)
/* Store vlanID used by bridge domain server */
Store(ctx, true, vlanID)
}
return nil
}

func getHostOrVlanInterface(ctx context.Context, vppConn api.Connection, hostIFName string, vlanID uint32) (hostSwIfIndex, vlanSwIfIndex interface_types.InterfaceIndex, err error) {
now := time.Now()
client, err := interfaces.NewServiceClient(vppConn).SwInterfaceDump(ctx, &interfaces.SwInterfaceDump{
NameFilterValid: true,
NameFilter: hostIFName,
})
if err != nil {
return 0, 0, errors.Wrapf(err, "error attempting to get interface dump client to set vlan subinterface on %q", hostIFName)
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("HostInterfaceName", hostIFName).
WithField("vppapi", "SwInterfaceDump").Debug("completed")
for {
details, err := client.Recv()
if err == io.EOF {
break
}
if err != nil {
return 0, 0, errors.Wrapf(err, "error attempting to get interface details to set vlan subinterface on %q", hostIFName)
}
if (vlanID != 0) && strings.Contains(details.InterfaceName, hostIFName) && (details.Type == interface_types.IF_API_TYPE_SUB) && (details.SubID == vlanID) {
return 0, details.SwIfIndex, nil
}
if (hostIFName == details.InterfaceName) || (afPacketNamePrefix+hostIFName == details.InterfaceName) {
hostSwIfIndex = details.SwIfIndex
}
}

if hostSwIfIndex == 0 {
return 0, 0, errors.Errorf("no interface name found %s", hostIFName)
}
return hostSwIfIndex, 0, nil
}

func vppAddSubIf(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex, vlanID uint32) (*interface_types.InterfaceIndex, bool, error) {
now := time.Now()
vlanSubif := &interfaces.CreateVlanSubif{
Expand All @@ -119,30 +132,14 @@ func vppAddSubIf(ctx context.Context, vppConn api.Connection, swIfIndex interfac
WithField("vppapi", "CreateVlanSubIf").Debug("completed")
return &rsp.SwIfIndex, false, nil
}
func delSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection) error {
func delSubIf(ctx context.Context, conn *networkservice.Connection) {
if mechanism := vlanmech.ToMechanism(conn.GetMechanism()); mechanism != nil {
swIfIndex, ok := ifindex.Load(ctx, true)
_, ok := ifindex.Load(ctx, true)
if !ok {
return nil
}

if mechanism.GetVlanID() == 0 {
ifindex.Delete(ctx, true)
return nil
return
}
now := time.Now()
vlanSubif := &interfaces.DeleteSubif{
SwIfIndex: swIfIndex,
}
_, err := interfaces.NewServiceClient(vppConn).DeleteSubif(ctx, vlanSubif)
if err != nil {
return errors.WithStack(err)
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("HostInterfaceIndex", swIfIndex).
WithField("vppapi", "DeleteSubif").Debug("completed")
/* Delete sub-interface together with the l2 bridge */
ifindex.Delete(ctx, true)
Delete(ctx, true)
}
return nil
}
72 changes: 0 additions & 72 deletions pkg/networkservice/mechanisms/vlan/hwaddress/client.go

This file was deleted.

64 changes: 0 additions & 64 deletions pkg/networkservice/mechanisms/vlan/hwaddress/common.go

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/networkservice/mechanisms/vlan/l2vtr/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -61,6 +61,5 @@ func (v *l2vtrClient) Request(ctx context.Context, request *networkservice.Netwo
}

func (v *l2vtrClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
_ = disableVtr(ctx, conn, v.vppConn)
return next.Client(ctx).Close(ctx, conn, opts...)
}
26 changes: 0 additions & 26 deletions pkg/networkservice/mechanisms/vlan/l2vtr/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,3 @@ func enableVtr(ctx context.Context, conn *networkservice.Connection, vppConn api
}
return nil
}

func disableVtr(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection) error {
if mechanism := vlanmech.ToMechanism(conn.GetMechanism()); mechanism != nil {
if mechanism.GetVlanID() == 0 {
return nil
}
swIfIndex, ok := ifindex.Load(ctx, true)
if !ok {
return nil
}
now := time.Now()

if _, err := l2.NewServiceClient(vppConn).L2InterfaceVlanTagRewrite(ctx, &l2.L2InterfaceVlanTagRewrite{
SwIfIndex: swIfIndex,
VtrOp: L2VtrDisabled,
}); err != nil {
return errors.WithStack(err)
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("SwIfIndex", swIfIndex).
WithField("operation", "DISABLE").
WithField("vppapi", "L2InterfaceVlanTagRewrite").Debug("completed")
}
return nil
}
Loading