Skip to content

Commit

Permalink
delete more of deprecated API
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Feb 20, 2024
1 parent c3992a4 commit 3b1187a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 49 deletions.
23 changes: 5 additions & 18 deletions pkg/networkservice/mechanisms/memif/memifrxmode/common.go
Original file line number Diff line number Diff line change
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
27 changes: 7 additions & 20 deletions pkg/networkservice/up/common.go
Original file line number Diff line number Diff line change
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
14 changes: 4 additions & 10 deletions pkg/networkservice/up/ipsecup/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,11 @@ func waitForUpLinkUp(ctx context.Context, vppConn Connection, isClient bool) err
if !ok {
return nil
}
apiChannel, err := vppConn.NewAPIChannelBuffered(256, 256)
watcher, err := vppConn.WatchEvent(ctx, &interfaces.SwInterfaceEvent{})
if err != nil {
return errors.Wrap(err, "failed to get new channel for communication with VPP via govpp core")
return errors.Wrap(err, "failed to watch interfaces.SwInterfaceEvent")
}
defer apiChannel.Close()
notifCh := make(chan api.Message, 256)
subscription, err := apiChannel.SubscribeNotification(notifCh, &interfaces.SwInterfaceEvent{})
if err != nil {
return errors.Wrap(err, "failed to subscribe for receiving of the specified notification messages via provided Go channel")
}
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 +76,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
2 changes: 1 addition & 1 deletion pkg/networkservice/up/peerup/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func waitForPeerUp(ctx context.Context, vppConn api.Connection, pubKey string, i
watcher, err := vppConn.WatchEvent(ctx, &wireguard.WireguardPeerEvent{})

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 wireguard.WireguardPeerEvent")
}
defer func() { watcher.Close() }()

Expand Down

0 comments on commit 3b1187a

Please sign in to comment.