Skip to content

Commit

Permalink
Connecting a remote interface without creating a VLAN on top (#546)
Browse files Browse the repository at this point in the history
Fix issue: cmd-nse-remote-vlan/#18
Do not create vlan sub-interface when VLAN-ID is set to 0

Signed-off-by: Laszlo Kiraly <laszlo.kiraly@est.tech>
  • Loading branch information
ljkiraly authored May 23, 2022
1 parent c70a247 commit 54e80e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
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

0 comments on commit 54e80e0

Please sign in to comment.