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

Connecting a remote interface without creating a VLAN on top #546

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
56 changes: 39 additions & 17 deletions pkg/networkservice/mechanisms/vlan/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"git.fd.io/govpp.git/api"

interfaces "github.com/edwarnicke/govpp/binapi/interface"
"github.com/edwarnicke/govpp/binapi/interface_types"
"github.com/pkg/errors"

"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand All @@ -43,13 +44,13 @@ func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.
if ok {
return nil
}
now := time.Now()
via := conn.GetLabels()[viaLabel]
hostIFName, ok := deviceNames[via]
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,
Expand Down Expand Up @@ -77,37 +78,58 @@ func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.
WithField("vppapi", "SwInterfaceDetails").Debug("skipped")
continue
}
now = time.Now()

swIfIndex := details.SwIfIndex
vlanID := mechanism.GetVlanID()
vlanSubif := &interfaces.CreateVlanSubif{
SwIfIndex: swIfIndex,
VlanID: vlanID,
}

rsp, err := interfaces.NewServiceClient(vppConn).CreateVlanSubif(ctx, vlanSubif)
if err != nil {
return errors.WithStack(err)
if vlanID != 0 {
vlanIfIndex, shouldReturn, returnValue := vppAddSubIf(ctx, vppConn, swIfIndex, 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)
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("HostInterfaceIndex", swIfIndex).
WithField("VlanID", vlanID).
WithField("vppapi", "CreateVlanSubIf").Debug("completed")

ifindex.Store(ctx, true, rsp.SwIfIndex)
return nil
}
return errors.Errorf("no interface name found %s", hostIFName)
}
return 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{
SwIfIndex: swIfIndex,
VlanID: vlanID,
}

rsp, err := interfaces.NewServiceClient(vppConn).CreateVlanSubif(ctx, vlanSubif)
if err != nil {
return nil, true, errors.WithStack(err)
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("HostInterfaceIndex", swIfIndex).
WithField("SubInterfaceIndex", rsp.SwIfIndex).
WithField("VlanID", vlanID).
WithField("vppapi", "CreateVlanSubIf").Debug("completed")
return &rsp.SwIfIndex, false, nil
}
func delSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection) error {
if mechanism := vlanmech.ToMechanism(conn.GetMechanism()); mechanism != nil {
swIfIndex, ok := ifindex.Load(ctx, true)
if !ok {
return nil
}

if mechanism.GetVlanID() == 0 {
ifindex.Delete(ctx, true)
return nil
}
now := time.Now()
vlanSubif := &interfaces.DeleteSubif{
SwIfIndex: swIfIndex,
Expand Down
8 changes: 7 additions & 1 deletion pkg/networkservice/mechanisms/vlan/l2vtr/common.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 @@ -33,6 +33,9 @@ import (

func enableVtr(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
Expand All @@ -58,6 +61,9 @@ func enableVtr(ctx context.Context, conn *networkservice.Connection, vppConn api

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
Expand Down