Skip to content

Commit

Permalink
Fix SwInterfaceDump filtering for interface name in case of remote vl…
Browse files Browse the repository at this point in the history
…an mechanism (#494)

Signed-off-by: Laszlo Kiraly <[email protected]>
  • Loading branch information
ljkiraly committed Jan 24, 2022
1 parent 8726a58 commit e3a8095
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions pkg/networkservice/mechanisms/vlan/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
)

const (
afPacketNamePrefix = "host-"
)

func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection, deviceNames map[string]string) error {
if mechanism := vlanmech.ToMechanism(conn.GetMechanism()); mechanism != nil {
_, ok := ifindex.Load(ctx, true)
Expand All @@ -43,7 +47,7 @@ func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.
via := conn.GetLabels()[viaLabel]
hostIFName, ok := deviceNames[via]
if !ok {
return errors.Errorf("no interface name for service domain %s", via)
return errors.Errorf("no interface name for label %s", via)
}

client, err := interfaces.NewServiceClient(vppConn).SwInterfaceDump(ctx, &interfaces.SwInterfaceDump{
Expand All @@ -66,6 +70,13 @@ func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.
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) {
log.FromContext(ctx).
WithField("InterfaceName", details.InterfaceName).
WithField("vppapi", "SwInterfaceDetails").Debug("skipped")
continue
}
now = time.Now()
swIfIndex := details.SwIfIndex
vlanID := mechanism.GetVlanID()
Expand All @@ -77,15 +88,18 @@ func addSubIf(ctx context.Context, conn *networkservice.Connection, vppConn api.
rsp, err := interfaces.NewServiceClient(vppConn).CreateVlanSubif(ctx, vlanSubif)
if err != nil {
return errors.WithStack(err)
}
log.FromContext(ctx).
WithField("duration", time.Since(now)).
WithField("HostInterfaceIndex", swIfIndex).
WithField("VlanID", vlanID).
WithField("vppapi", "CreateVlanSubIf").Debug("completed")
} else {
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)
ifindex.Store(ctx, true, rsp.SwIfIndex)
return nil
}
}
return errors.Errorf("no interface name found %s", hostIFName)
}
return nil
}
Expand Down

0 comments on commit e3a8095

Please sign in to comment.