Skip to content

Commit

Permalink
Update memif mechanismPreference NetNSURL on Request (#484)
Browse files Browse the repository at this point in the history
* Update memif mechanismPreference NetNSURL on Request

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>

* fix review

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art authored Dec 28, 2021
1 parent a48785b commit 65982e6
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pkg/networkservice/mechanisms/memif/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package memif

import (
"context"
"net/url"

"git.fd.io/govpp.git/api"
"github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -63,17 +64,8 @@ func NewClient(vppConn api.Connection, options ...Option) networkservice.Network
)
}

func mechanismsContain(list []*networkservice.Mechanism, t string) bool {
for _, m := range list {
if m.Type == t {
return true
}
}
return false
}

func (m *memifClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
if !mechanismsContain(request.MechanismPreferences, memif.MECHANISM) {
if !m.updateMechanismPreferences(request) {
mechanism := memif.ToMechanism(memif.NewAbstract(m.nsInfo.netNSPath))
if m.changeNetNs {
mechanism.SetNetNSURL("")
Expand Down Expand Up @@ -115,3 +107,18 @@ func (m *memifClient) Close(ctx context.Context, conn *networkservice.Connection
_ = del(ctx, conn, m.vppConn, metadata.IsClient(m))
return next.Client(ctx).Close(ctx, conn, opts...)
}

// updateMechanismPreferences returns true if MechanismPreferences has updated
func (m *memifClient) updateMechanismPreferences(request *networkservice.NetworkServiceRequest) bool {
var updated = false
for _, p := range request.GetRequestMechanismPreferences() {
if mechanism := memif.ToMechanism(p); mechanism != nil {
mechanism.SetNetNSURL((&url.URL{Scheme: memif.FileScheme, Path: m.nsInfo.netNSPath}).String())
if m.changeNetNs {
mechanism.SetNetNSURL("")
}
updated = true
}
}
return updated
}

0 comments on commit 65982e6

Please sign in to comment.