Skip to content

Commit

Permalink
Change xconnect to bridge domain in case of remote vlan
Browse files Browse the repository at this point in the history
Signed-off-by: Laszlo Kiraly <laszlo.kiraly@est.tech>
  • Loading branch information
ljkiraly committed Oct 25, 2022
1 parent 1361946 commit c029a3e
Show file tree
Hide file tree
Showing 12 changed files with 533 additions and 61 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ require (
github.com/open-policy-agent/opa v0.43.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/searKing/golang/tools v1.2.29 // indirect
github.com/searKing/golang/tools/cmd/go-syncmap v1.2.30 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spiffe/go-spiffe/v2 v2.0.0 // indirect
github.com/vektah/gqlparser/v2 v2.4.6 // indirect
Expand All @@ -65,8 +67,10 @@ require (
go.opentelemetry.io/otel/trace v1.8.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.11 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,10 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/searKing/golang/tools v1.2.29 h1:gWX4aCA1+N7CfLpNd6tmBjYtecTksZFXziqbQ+AJKLo=
github.com/searKing/golang/tools v1.2.29/go.mod h1:QtwFM73H1qMKlRl0p8NRWXrNaCaffoYkNHk5YMoRyOY=
github.com/searKing/golang/tools/cmd/go-syncmap v1.2.30 h1:BpM16Td69Rj5KVZEqgLRPEF/agq4iIQp7QkbN/Q45aE=
github.com/searKing/golang/tools/cmd/go-syncmap v1.2.30/go.mod h1:99EYjageQ58gYSPT0NaeUr2Wahl7IayqwRG6ceFU+48=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
Expand Down Expand Up @@ -1124,6 +1128,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1413,6 +1419,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY=
golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
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 @@ -54,6 +54,7 @@ import (
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/ethernetcontext"

"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext/mtu"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/l2bridgedomain"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/memif"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vlan"
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
207 changes: 207 additions & 0 deletions pkg/networkservice/l2bridgedomain/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
// Copyright (c) 2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package l2bridgedomain

import (
"context"
"time"

"git.fd.io/govpp.git/api"
interfaces "github.com/edwarnicke/govpp/binapi/interface"
"github.com/edwarnicke/govpp/binapi/interface_types"
"github.com/edwarnicke/govpp/binapi/l2"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/tools/log"

"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vlan"
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
)

type bridgeDomain struct {
/* BdID */
id uint32

/* attached - attached interfaces */
attached map[interface_types.InterfaceIndex]struct{}
}

type bridgeDomainKey struct {
vlanID uint32
clientIfIndex interface_types.InterfaceIndex
}

func addBridgeDomain(ctx context.Context, vppConn api.Connection, bridges *l2BridgeDomain) error {
vlanID, ok := vlan.Load(ctx, true)
if !ok {
return nil
}
clientIfIndex, ok := ifindex.Load(ctx, true)
if !ok {
return nil
}
serverIfIndex, ok := ifindex.Load(ctx, false)
if !ok {
return nil
}

// key <vlanID, clientIfIndex> to handle the vlanID == 0 case
key := bridgeDomainKey{
vlanID: vlanID,
clientIfIndex: clientIfIndex,
}
l2Bridge, ok := bridges.Load(key)
if !ok {
bridgeID, err := addDelVppBridgeDomain(ctx, vppConn, ^uint32(0), true)
if err != nil {
return err
}
l2Bridge = &bridgeDomain{
id: bridgeID,
attached: make(map[interface_types.InterfaceIndex]struct{}),
}
bridges.Store(key, l2Bridge)
}
if _, ok = l2Bridge.attached[serverIfIndex]; !ok {
err := addDelVppInterfaceBridgeDomain(ctx, vppConn, serverIfIndex, l2Bridge.id, 1, true)
if err != nil {
return err
}
l2Bridge.attached[serverIfIndex] = struct{}{}
bridges.Store(key, l2Bridge)
}
if _, ok = l2Bridge.attached[clientIfIndex]; !ok {
err := addDelVppInterfaceBridgeDomain(ctx, vppConn, clientIfIndex, l2Bridge.id, 0, true)
if err != nil {
return err
}
l2Bridge.attached[clientIfIndex] = struct{}{}
bridges.Store(key, l2Bridge)
}
return nil
}

func delBridgeDomain(ctx context.Context, vppConn api.Connection, bridges *l2BridgeDomain) error {
if vlanID, ok := vlan.Load(ctx, true); ok {
if clientIfIndex, ok := ifindex.Load(ctx, true); ok {
key := bridgeDomainKey{
vlanID: vlanID,
clientIfIndex: clientIfIndex,
}
l2Bridge, ok := bridges.Load(key)
if !ok {
return nil
}
if serverIfIndex, okey := ifindex.Load(ctx, false); okey {
if _, ok = l2Bridge.attached[serverIfIndex]; ok {
err := addDelVppInterfaceBridgeDomain(ctx, vppConn, serverIfIndex, l2Bridge.id, 0, false)
if err != nil {
return err
}
delete(l2Bridge.attached, serverIfIndex)
}
}
if len(l2Bridge.attached) == 1 {
/* last interface -> delete the bridge and the sub-interface also */
if _, ok = l2Bridge.attached[clientIfIndex]; ok {
err := addDelVppInterfaceBridgeDomain(ctx, vppConn, clientIfIndex, l2Bridge.id, 0, false)
if err != nil {
return err
}
err = delVppSubIf(ctx, vppConn, vlanID, clientIfIndex)
if err != nil {
return err
}
delete(l2Bridge.attached, clientIfIndex)
_, err = addDelVppBridgeDomain(ctx, vppConn, l2Bridge.id, false)
if err != nil {
return err
}
bridges.Delete(key)
}
} else {
bridges.Store(key, l2Bridge)
}
}
}
return nil
}

func addDelVppBridgeDomain(ctx context.Context, vppConn api.Connection, bridgeID uint32, isAdd bool) (uint32, error) {
now := time.Now()
bridgeDomainAddDelV2 := &l2.BridgeDomainAddDelV2{
IsAdd: isAdd,
BdID: bridgeID,
Flood: true,
Forward: true,
Learn: true,
UuFlood: true,
}
rsp, err := l2.NewServiceClient(vppConn).BridgeDomainAddDelV2(ctx, bridgeDomainAddDelV2)
if err != nil {
return 0, errors.WithStack(err)
}
log.FromContext(ctx).
WithField("bridgeID", rsp.BdID).
WithField("isAdd", isAdd).
WithField("duration", time.Since(now)).
WithField("vppConn", vppConn).
WithField("vppapi", "addDelVppBridgeDomain").Info("completed")
return rsp.BdID, nil
}

func addDelVppInterfaceBridgeDomain(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex, bridgeID uint32, shg uint8, isAdd bool) error {
now := time.Now()
_, err := l2.NewServiceClient(vppConn).SwInterfaceSetL2Bridge(ctx, &l2.SwInterfaceSetL2Bridge{
RxSwIfIndex: swIfIndex,
Enable: isAdd,
BdID: bridgeID,
Shg: shg,
})
if err != nil {
return errors.WithStack(err)
}
log.FromContext(ctx).
WithField("swIfIndex", swIfIndex).
WithField("bridgeID", bridgeID).
WithField("isAdd", isAdd).
WithField("shg", shg).
WithField("duration", time.Since(now)).
WithField("vppConn", vppConn).
WithField("vppapi", "addDelVppInterfaceBridgeDomain").Info("completed")
return nil
}

func delVppSubIf(ctx context.Context, vppConn api.Connection, vlanID uint32, swIfIndex interface_types.InterfaceIndex) error {
if vlanID == 0 {
ifindex.Delete(ctx, true)
return nil
}
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("InterfaceIndex", swIfIndex).
WithField("vppapi", "DeleteSubif").Debug("completed")
return nil
}
18 changes: 18 additions & 0 deletions pkg/networkservice/l2bridgedomain/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package l2bridgedomain provides chain elements for creating l2 bridge domain in vpp and adding client and server interfaces (if present)
package l2bridgedomain
26 changes: 26 additions & 0 deletions pkg/networkservice/l2bridgedomain/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package l2bridgedomain

import (
"sync"
)

//go:generate go-syncmap -output l2_bridge_domain_map.gen.go -type l2BridgeDomain<bridgeDomainKey,*bridgeDomain>

// l2BridgeDomain - sync.Map storing *bridgeDomain values to bridgeDomainKey(VLAN-ID, clientIfIndex)
type l2BridgeDomain sync.Map
73 changes: 73 additions & 0 deletions pkg/networkservice/l2bridgedomain/l2_bridge_domain_map.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c029a3e

Please sign in to comment.