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

Remove deprecated API for watching VPPAPI events #798

Merged
merged 6 commits into from
Feb 20, 2024
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
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/networkservicemesh/govpp v0.0.0-20240130152300-43babf54855b
github.com/networkservicemesh/sdk v0.5.1-0.20240212105149-b1a3e26da857
github.com/networkservicemesh/sdk-kernel v0.0.0-20240212105448-f9f740175836
github.com/networkservicemesh/vpphelper v0.0.0-20230901145133-a14aecebd1cb
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/thanhpk/randstr v1.0.4
Expand All @@ -27,11 +26,6 @@ require (
google.golang.org/protobuf v1.31.0
)

require (
github.com/edwarnicke/log v1.0.0 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
)

require (
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
Expand Down
100 changes: 0 additions & 100 deletions go.sum

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions pkg/networkservice/chains/forwarder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,12 @@ import (
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/xconnect/l2bridgedomain"
)

// Connection aggregates the api.Connection and api.ChannelProvider interfaces
type Connection interface {
api.Connection
api.ChannelProvider
}

type xconnectNSServer struct {
endpoint.Endpoint
}

// NewServer - returns an implementation of the xconnectns network service
func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn Connection, tunnelIP net.IP, options ...Option) endpoint.Endpoint {
func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn api.Connection, tunnelIP net.IP, options ...Option) endpoint.Endpoint {
opts := &forwarderOptions{
name: "forwarder-vpp-" + uuid.New().String(),
authorizeServer: authorize.NewServer(authorize.Any()),
Expand Down
4 changes: 3 additions & 1 deletion pkg/networkservice/mechanisms/memif/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2021-2023 Doc.ai and/or its affiliates.
//
// Copyright (c) 2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,7 +50,7 @@ type memifClient struct {
}

// NewClient provides a NetworkServiceClient chain elements that support the memif Mechanism
func NewClient(chainCtx context.Context, vppConn Connection, options ...Option) networkservice.NetworkServiceClient {
func NewClient(chainCtx context.Context, vppConn api.Connection, options ...Option) networkservice.NetworkServiceClient {
opts := &memifOptions{}
for _, o := range options {
o(opts)
Expand Down
8 changes: 1 addition & 7 deletions pkg/networkservice/mechanisms/memif/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -43,12 +43,6 @@ import (
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
)

// Connection aggregates the api.Connection and api.ChannelProvider interfaces
type Connection interface {
api.Connection
api.ChannelProvider
}

// NetNSInfo contains shared info for server and client
type NetNSInfo struct {
netNS netns.NsHandle
Expand Down
7 changes: 4 additions & 3 deletions pkg/networkservice/mechanisms/memif/memifrxmode/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -22,6 +22,7 @@ import (
"context"

"github.com/pkg/errors"
"go.fd.io/govpp/api"
"google.golang.org/grpc"

"github.com/golang/protobuf/ptypes/empty"
Expand All @@ -38,11 +39,11 @@ import (

type memifrxmodeClient struct {
chainCtx context.Context
vppConn Connection
vppConn api.Connection
}

// NewClient provides a NetworkServiceClient chain elements that support the memif Mechanism
func NewClient(chainCtx context.Context, vppConn Connection) networkservice.NetworkServiceClient {
func NewClient(chainCtx context.Context, vppConn api.Connection) networkservice.NetworkServiceClient {
return &memifrxmodeClient{
chainCtx: chainCtx,
vppConn: vppConn,
Expand Down
25 changes: 6 additions & 19 deletions pkg/networkservice/mechanisms/memif/memifrxmode/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -31,32 +31,19 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/log"
)

// Connection aggregates the api.Connection and api.ChannelProvider interfaces
type Connection interface {
api.Connection
api.ChannelProvider
}

func setRxMode(ctx context.Context, vppConn Connection, swIfIndex interface_types.InterfaceIndex) error {
apiChannel, err := vppConn.NewAPIChannelBuffered(256, 256)
if err != nil {
return errors.Wrap(err, "failed to get new channel for communication with VPP via govpp core")
}

notifCh := make(chan api.Message, 256)
subscription, err := apiChannel.SubscribeNotification(notifCh, &interfaces.SwInterfaceEvent{})
func setRxMode(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex) error {
watcher, err := vppConn.WatchEvent(ctx, &interfaces.SwInterfaceEvent{})
if err != nil {
return errors.Wrap(err, "failed to subscribe for receiving of the specified notification messages via provided Go channel")
return errors.Wrap(err, "failed to watch interfaces.SwInterfaceEvent")
}

go func() {
defer apiChannel.Close()
defer func() { _ = subscription.Unsubscribe() }()
defer func() { watcher.Close() }()
for {
select {
case <-ctx.Done():
return
case rawMsg := <-notifCh:
case rawMsg := <-watcher.Events():
if msg, ok := rawMsg.(*interfaces.SwInterfaceEvent); ok &&
msg.SwIfIndex == swIfIndex &&
msg.Flags&interface_types.IF_STATUS_API_FLAG_LINK_UP != 0 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/networkservice/mechanisms/memif/memifrxmode/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2024 Cisco and/or its affiliates.
NikitaSkrynnik marked this conversation as resolved.
Show resolved Hide resolved
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
7 changes: 4 additions & 3 deletions pkg/networkservice/mechanisms/memif/memifrxmode/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -22,6 +22,7 @@ import (
"context"

"github.com/pkg/errors"
"go.fd.io/govpp/api"

"github.com/golang/protobuf/ptypes/empty"

Expand All @@ -37,11 +38,11 @@ import (

type memifrxmodeServer struct {
chainCtx context.Context
vppConn Connection
vppConn api.Connection
}

// NewServer - create a new memifProxy server chain element
func NewServer(chainCtx context.Context, vppConn Connection) networkservice.NetworkServiceServer {
func NewServer(chainCtx context.Context, vppConn api.Connection) networkservice.NetworkServiceServer {
return &memifrxmodeServer{
chainCtx: chainCtx,
vppConn: vppConn,
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/mechanisms/memif/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -46,7 +46,7 @@ type memifServer struct {
}

// NewServer provides a NetworkServiceServer chain elements that support the memif Mechanism
func NewServer(chainCtx context.Context, vppConn Connection, options ...Option) networkservice.NetworkServiceServer {
func NewServer(chainCtx context.Context, vppConn api.Connection, options ...Option) networkservice.NetworkServiceServer {
opts := new(memifOptions)
for _, o := range options {
o(opts)
Expand Down
7 changes: 4 additions & 3 deletions pkg/networkservice/up/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
// Copyright (c) 2020-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -24,6 +24,7 @@ import (

"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"go.fd.io/govpp/api"
"google.golang.org/grpc"

"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand All @@ -39,15 +40,15 @@ import (

type upClient struct {
ctx context.Context
vppConn Connection
vppConn api.Connection
loadIfIndex ifIndexFunc

inited uint32
initMutex sync.Mutex
}

// NewClient provides a NetworkServiceClient chain elements that 'up's the swIfIndex
func NewClient(ctx context.Context, vppConn Connection, opts ...Option) networkservice.NetworkServiceClient {
func NewClient(ctx context.Context, vppConn api.Connection, opts ...Option) networkservice.NetworkServiceClient {
o := &options{
loadIfIndex: ifindex.Load,
}
Expand Down
29 changes: 8 additions & 21 deletions pkg/networkservice/up/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -30,24 +30,12 @@ import (
"go.fd.io/govpp/api"
)

// Connection - simply combines tha api.Connection and api.ChannelProvider interfaces
type Connection interface {
api.Connection
api.ChannelProvider
}

func up(ctx context.Context, vppConn Connection, loadIfIndex ifIndexFunc, isClient bool) error {
func up(ctx context.Context, vppConn api.Connection, loadIfIndex ifIndexFunc, isClient bool) error {
swIfIndex, ok := loadIfIndex(ctx, isClient)
if !ok {
return nil
}

apiChannel, err := vppConn.NewAPIChannelBuffered(256, 256)
if err != nil {
return errors.Wrap(err, "failed to get new channel for communication with VPP via govpp core")
}
defer apiChannel.Close()

now := time.Now()
if _, err := interfaces.NewServiceClient(vppConn).SwInterfaceSetFlags(ctx, &interfaces.SwInterfaceSetFlags{
SwIfIndex: swIfIndex,
Expand All @@ -61,20 +49,19 @@ func up(ctx context.Context, vppConn Connection, loadIfIndex ifIndexFunc, isClie
WithField("vppapi", "SwInterfaceSetFlags").Debug("completed")

if waitTillUp, ok := Load(ctx, isClient); ok && waitTillUp {
if err := waitForUpLinkUp(ctx, vppConn, apiChannel, swIfIndex); err != nil {
if err := waitForUpLinkUp(ctx, vppConn, swIfIndex); err != nil {
return err
}
}
return nil
}

func waitForUpLinkUp(ctx context.Context, vppConn api.Connection, apiChannel api.Channel, swIfIndex interface_types.InterfaceIndex) error {
notifCh := make(chan api.Message, 256)
subscription, err := apiChannel.SubscribeNotification(notifCh, &interfaces.SwInterfaceEvent{})
func waitForUpLinkUp(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex) error {
watcher, err := vppConn.WatchEvent(ctx, &interfaces.SwInterfaceEvent{})
if err != nil {
return errors.Wrap(err, "failed to subscribe for receiving of the specified notification messages via provided Go channel")
return errors.Wrap(err, "failed to watch interfaces.SwInterfaceEvent")
}
defer func() { _ = subscription.Unsubscribe() }()
defer func() { watcher.Close() }()

now := time.Now()
dc, err := interfaces.NewServiceClient(vppConn).SwInterfaceDump(ctx, &interfaces.SwInterfaceDump{
Expand Down Expand Up @@ -105,7 +92,7 @@ func waitForUpLinkUp(ctx context.Context, vppConn api.Connection, apiChannel api
select {
case <-ctx.Done():
return errors.Wrap(ctx.Err(), "provided context is done")
case rawMsg := <-notifCh:
case rawMsg := <-watcher.Events():
if msg, ok := rawMsg.(*interfaces.SwInterfaceEvent); ok &&
msg.SwIfIndex == swIfIndex &&
msg.Flags&interface_types.IF_STATUS_API_FLAG_LINK_UP != 0 {
Expand Down
7 changes: 4 additions & 3 deletions pkg/networkservice/up/ipsecup/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -21,6 +21,7 @@ import (
"context"

"github.com/pkg/errors"
"go.fd.io/govpp/api"
"google.golang.org/grpc"

"github.com/golang/protobuf/ptypes/empty"
Expand All @@ -34,11 +35,11 @@ import (

type ipsecUpClient struct {
ctx context.Context
vppConn Connection
vppConn api.Connection
}

// NewClient provides a NetworkServiceClient chain element that waits the 'up' of the IPSec interface
func NewClient(ctx context.Context, vppConn Connection) networkservice.NetworkServiceClient {
func NewClient(ctx context.Context, vppConn api.Connection) networkservice.NetworkServiceClient {
return &ipsecUpClient{
ctx: ctx,
vppConn: vppConn,
Expand Down
24 changes: 6 additions & 18 deletions pkg/networkservice/up/ipsecup/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -30,28 +30,16 @@ import (
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex"
)

// Connection - simply combines tha api.Connection and api.ChannelProvider interfaces
type Connection interface {
api.Connection
api.ChannelProvider
}

func waitForUpLinkUp(ctx context.Context, vppConn Connection, isClient bool) error {
func waitForUpLinkUp(ctx context.Context, vppConn api.Connection, isClient bool) error {
swIfIndex, ok := ifindex.Load(ctx, isClient)
if !ok {
return nil
}
apiChannel, err := vppConn.NewAPIChannelBuffered(256, 256)
if err != nil {
return errors.Wrap(err, "failed to get new channel for communication with VPP via govpp core")
}
defer apiChannel.Close()
notifCh := make(chan api.Message, 256)
subscription, err := apiChannel.SubscribeNotification(notifCh, &interfaces.SwInterfaceEvent{})
watcher, err := vppConn.WatchEvent(ctx, &interfaces.SwInterfaceEvent{})
if err != nil {
return errors.Wrap(err, "failed to subscribe for receiving of the specified notification messages via provided Go channel")
return errors.Wrap(err, "failed to watch interfaces.SwInterfaceEvent")
}
defer func() { _ = subscription.Unsubscribe() }()
defer func() { watcher.Close() }()

now := time.Now()
dc, err := interfaces.NewServiceClient(vppConn).SwInterfaceDump(ctx, &interfaces.SwInterfaceDump{
Expand Down Expand Up @@ -82,7 +70,7 @@ func waitForUpLinkUp(ctx context.Context, vppConn Connection, isClient bool) err
select {
case <-ctx.Done():
return errors.Wrap(ctx.Err(), "provided context is done")
case rawMsg := <-notifCh:
case rawMsg := <-watcher.Events():
if msg, ok := rawMsg.(*interfaces.SwInterfaceEvent); ok &&
msg.SwIfIndex == swIfIndex &&
msg.Flags&interface_types.IF_STATUS_API_FLAG_LINK_UP != 0 {
Expand Down
Loading
Loading