Skip to content

Commit

Permalink
nsm: bump to github.com/networkservicemesh/networkservicemesh master
Browse files Browse the repository at this point in the history
  • Loading branch information
lebauce committed Sep 13, 2021
1 parent ef3b1c8 commit 666258f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion config/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/casbin/casbin/log"
"github.com/casbin/casbin/model"
"github.com/casbin/casbin/persist"
etcd "github.com/coreos/etcd/client"
etcd "go.etcd.io/etcd/client/v2"

"github.com/skydive-project/skydive/graffiti/logging"
"github.com/skydive-project/skydive/graffiti/rbac"
Expand Down
43 changes: 25 additions & 18 deletions topology/probes/nsm/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ package nsm
import (
"fmt"

localconn "github.com/networkservicemesh/networkservicemesh/controlplane/api/local/connection"
remoteconn "github.com/networkservicemesh/networkservicemesh/controlplane/api/remote/connection"
conn "github.com/networkservicemesh/networkservicemesh/controlplane/api/connection"

"github.com/skydive-project/skydive/graffiti/filters"
"github.com/skydive-project/skydive/graffiti/graph"
Expand All @@ -33,8 +32,8 @@ import (
type connection interface {
addEdge(*graph.Graph)
delEdge(*graph.Graph)
getSource() *localconn.Connection
getDest() *localconn.Connection
getSource() *conn.Connection
getDest() *conn.Connection
getInodes() (int64, int64)
isCrossConnectOwner(string, string) bool
printCrossConnect() string
Expand All @@ -43,15 +42,15 @@ type connection interface {

type baseConnectionPair struct {
payload string
src *localconn.Connection
dst *localconn.Connection
src *conn.Connection
dst *conn.Connection
}

func (b *baseConnectionPair) getSource() *localconn.Connection {
func (b *baseConnectionPair) getSource() *conn.Connection {
return b.src
}

func (b *baseConnectionPair) getDest() *localconn.Connection {
func (b *baseConnectionPair) getDest() *conn.Connection {
return b.dst
}

Expand Down Expand Up @@ -96,9 +95,9 @@ type localConnectionPair struct {
// A remote connection is composed of two cross-connects
type remoteConnectionPair struct {
baseConnectionPair
remote *remoteconn.Connection // the remote connection shared between the two corss-connects
srcCc *crossConnect // The id of the cross-connect with a local connection as source
dstCc *crossConnect // The id of the cross-connect with a local connection as destination
remote *conn.Connection // the remote connection shared between the two corss-connects
srcCc *crossConnect // The id of the cross-connect with a local connection as source
dstCc *crossConnect // The id of the cross-connect with a local connection as destination

}

Expand Down Expand Up @@ -171,15 +170,15 @@ func (l *localConnectionPair) createMetadata() graph.Metadata {
NetworkService: l.getSource().GetNetworkService(),
Source: LocalConnectionMetadata{
BaseConnectionMetadata: BaseConnectionMetadata{
MechanismType: l.getSource().GetMechanism().GetType().String(),
MechanismType: l.getSource().GetMechanism().GetType(),
MechanismParameters: l.getSource().GetMechanism().GetParameters(),
Labels: l.getSource().GetLabels(),
},
},
Destination: LocalConnectionMetadata{
IP: l.getDest().GetContext().GetIpContext().GetDstIpAddr(),
BaseConnectionMetadata: BaseConnectionMetadata{
MechanismType: l.getDest().GetMechanism().GetType().String(),
MechanismType: l.getDest().GetMechanism().GetType(),
MechanismParameters: l.getDest().GetMechanism().GetParameters(),
Labels: l.getDest().GetLabels(),
},
Expand Down Expand Up @@ -248,6 +247,14 @@ func (r *remoteConnectionPair) delEdge(g *graph.Graph) {
}

func (r *remoteConnectionPair) createMetadata() graph.Metadata {
var srcNsmgr string
var dstNsmgr string
if len(r.remote.GetSourceNetworkServiceManagerName()) > 0 {
srcNsmgr = r.remote.GetSourceNetworkServiceManagerName()
}
if len(r.remote.GetDestinationNetworkServiceManagerName()) > 1 {
dstNsmgr = r.remote.GetDestinationNetworkServiceManagerName()
}
metadata := graph.Metadata{
"NSM": &EdgeMetadata{
BaseNSMMetadata: BaseNSMMetadata{
Expand All @@ -256,15 +263,15 @@ func (r *remoteConnectionPair) createMetadata() graph.Metadata {
Source: LocalConnectionMetadata{
IP: r.getSource().GetContext().GetIpContext().GetSrcIpAddr(),
BaseConnectionMetadata: BaseConnectionMetadata{
MechanismType: r.getSource().GetMechanism().GetType().String(),
MechanismType: r.getSource().GetMechanism().GetType(),
MechanismParameters: r.getSource().GetMechanism().GetParameters(),
Labels: r.getSource().GetLabels(),
},
},
Destination: LocalConnectionMetadata{
IP: r.getDest().GetContext().GetIpContext().GetDstIpAddr(),
BaseConnectionMetadata: BaseConnectionMetadata{
MechanismType: r.getDest().GetMechanism().GetType().String(),
MechanismType: r.getDest().GetMechanism().GetType(),
MechanismParameters: r.getDest().GetMechanism().GetParameters(),
Labels: r.getDest().GetLabels(),
},
Expand All @@ -275,12 +282,12 @@ func (r *remoteConnectionPair) createMetadata() graph.Metadata {
DestinationCrossConnectID: r.dstCc.ID,
Via: RemoteConnectionMetadata{
BaseConnectionMetadata: BaseConnectionMetadata{
MechanismType: r.remote.GetMechanism().GetType().String(),
MechanismType: r.remote.GetMechanism().GetType(),
MechanismParameters: r.remote.GetMechanism().GetParameters(),
Labels: r.remote.GetLabels(),
},
SourceNSM: r.remote.GetSourceNetworkServiceManagerName(),
DestinationNSM: r.remote.GetDestinationNetworkServiceManagerName(),
SourceNSM: srcNsmgr,
DestinationNSM: dstNsmgr,
NetworkServiceEndpoint: r.remote.GetNetworkServiceEndpointName(),
},
},
Expand Down
23 changes: 12 additions & 11 deletions topology/probes/nsm/nsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
conn "github.com/networkservicemesh/networkservicemesh/controlplane/api/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/connection/mechanisms/common"
cc "github.com/networkservicemesh/networkservicemesh/controlplane/api/crossconnect"
localconn "github.com/networkservicemesh/networkservicemesh/controlplane/api/local/connection"
remoteconn "github.com/networkservicemesh/networkservicemesh/controlplane/api/remote/connection"
v1 "github.com/networkservicemesh/networkservicemesh/k8s/pkg/apis/networkservice/v1alpha1"
"github.com/networkservicemesh/networkservicemesh/k8s/pkg/networkservice/clientset/versioned"
"github.com/networkservicemesh/networkservicemesh/k8s/pkg/networkservice/informers/externalversions"
"github.com/networkservicemesh/networkservicemesh/pkg/tools"
"google.golang.org/grpc"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -145,7 +146,7 @@ func (p *Probe) Stop() {
}

func (p *Probe) getNSMgrClient(url string) (cc.MonitorCrossConnectClient, error) {
conn, err := dial(context.Background(), "tcp", url)
conn, err := tools.DialTCP(url)
if err != nil {
logging.GetLogger().Errorf("NSM: unable to create grpc dialer, error: %+v", err)
return nil, err
Expand Down Expand Up @@ -194,14 +195,14 @@ func (p *Probe) monitorCrossConnects(url string) {
switch {
case lSrc != nil && rSrc == nil && lDst != nil && rDst == nil:
logging.GetLogger().Debugf("NSM: Got local to local CrossConnect: %s", cconnStr)
if !isDelMsg && (lSrc.GetState() == localconn.State_DOWN || lDst.GetState() == localconn.State_DOWN) {
if !isDelMsg && (lSrc.GetState() == conn.State_DOWN || lDst.GetState() == conn.State_DOWN) {
logging.GetLogger().Debugf("NSM: one connection of the cross connect %s is in DOWN state, don't affect the skydive connections", cconn.GetId())
continue
}
p.onConnLocalLocal(event.GetType(), cconn, url)
case lSrc == nil && rSrc != nil && lDst != nil && rDst == nil:
logging.GetLogger().Debugf("NSM: Got remote to local CrossConnect: %s", cconnStr)
if !isDelMsg && (rSrc.GetState() == remoteconn.State_DOWN || lDst.GetState() == localconn.State_DOWN) {
if !isDelMsg && (rSrc.GetState() == conn.State_DOWN || lDst.GetState() == conn.State_DOWN) {
logging.GetLogger().Debugf("NSM: one connection of the cross connect %s is in DOWN state, don't affect the skydive connections", cconn.GetId())
continue
}
Expand All @@ -212,7 +213,7 @@ func (p *Probe) monitorCrossConnects(url string) {
p.onConnRemoteLocal(event.GetType(), cconn, url)
case lSrc != nil && rSrc == nil && lDst == nil && rDst != nil:
logging.GetLogger().Debugf("NSM: Got local to remote CrossConnect: %s", cconnStr)
if !isDelMsg && (lSrc.GetState() == localconn.State_DOWN || rDst.GetState() == remoteconn.State_DOWN) {
if !isDelMsg && (lSrc.GetState() == conn.State_DOWN || rDst.GetState() == conn.State_DOWN) {
logging.GetLogger().Debugf("NSM: one connection of the cross connect %s is in DOWN state, don't affect the skydive connections", cconn.GetId())
continue
}
Expand Down Expand Up @@ -242,8 +243,8 @@ func (p *Probe) onConnLocalLocal(t cc.CrossConnectEventType, xconn *cc.CrossConn
},
baseConnectionPair: baseConnectionPair{
payload: xconn.GetPayload(),
src: xconn.GetLocalSource(),
dst: xconn.GetLocalDestination(),
src: xconn.GetSource(),
dst: xconn.GetDestination(),
},
}
p.addConnection(l)
Expand Down Expand Up @@ -419,7 +420,7 @@ func (p *Probe) getConnection(url string, id string) (connection, int) {
return nil, 0
}

func (p *Probe) getConnectionWithRemote(remote *remoteconn.Connection) (*remoteConnectionPair, int) {
func (p *Probe) getConnectionWithRemote(remote *conn.Connection) (*remoteConnectionPair, int) {
// the probe has to be locked before calling this function

// since the remote crossconnect id is issued by the responder to the connection request,
Expand Down Expand Up @@ -466,8 +467,8 @@ func dial(ctx context.Context, network string, address string) (*grpc.ClientConn
}

//TODO: consider moving this function to nsm helper functions in the local/connection package
func getLocalInode(conn *localconn.Connection) (int64, error) {
inodeStr, ok := conn.Mechanism.Parameters[localconn.NetNsInodeKey]
func getLocalInode(c *conn.Connection) (int64, error) {
inodeStr, ok := c.Mechanism.Parameters[common.NetNsInodeKey]
if !ok {
err := errors.New("NSM: no inodes in the connection parameters")
logging.GetLogger().Error(err)
Expand Down
47 changes: 21 additions & 26 deletions topology/probes/nsm/nsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,50 @@ import (
"strconv"
"testing"

conn "github.com/networkservicemesh/networkservicemesh/controlplane/api/connection"
mcommon "github.com/networkservicemesh/networkservicemesh/controlplane/api/connection/mechanisms/common"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/connection/mechanisms/memif"
cc "github.com/networkservicemesh/networkservicemesh/controlplane/api/crossconnect"
localconn "github.com/networkservicemesh/networkservicemesh/controlplane/api/local/connection"
remoteconn "github.com/networkservicemesh/networkservicemesh/controlplane/api/remote/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/common"
"github.com/skydive-project/skydive/config"
"github.com/skydive-project/skydive/graffiti/graph"
)

const ns = "ns_test"

func createLocalConn() *localconn.Connection {
mech := &localconn.Mechanism{
Type: localconn.MechanismType_DEFAULT_INTERFACE,
func createLocalConn() *conn.Connection {
mech := &conn.Mechanism{
Type: memif.MECHANISM,
Parameters: make(map[string]string),
}

c := &localconn.Connection{
c := &conn.Connection{
NetworkService: ns,
Mechanism: mech,
Labels: make(map[string]string),
Path: common.Strings2Path("local"),
}
return c
}

func createLocalSource() *cc.CrossConnect_LocalSource {
func createLocalSource() *conn.Connection {
c := createLocalConn()
c.Id = "id_src_conn"

localSrc := &cc.CrossConnect_LocalSource{LocalSource: c}
return localSrc
return c
}

func createLocalDest() *cc.CrossConnect_LocalDestination {
func createLocalDest() *conn.Connection {
c := createLocalConn()
c.Id = "id_src_conn"

localDst := &cc.CrossConnect_LocalDestination{LocalDestination: c}
return localDst
return c
}

func createConnectionLocalOnly(inodeSrc string, inodeDst string) *cc.CrossConnect {

localSrc := createLocalSource()
localSrc.LocalSource.GetMechanism().Parameters[localconn.NetNsInodeKey] = inodeSrc
localSrc.GetMechanism().Parameters[mcommon.NetNsInodeKey] = inodeSrc

localDst := createLocalDest()
localDst.LocalDestination.GetMechanism().Parameters[localconn.NetNsInodeKey] = inodeDst
localDst.GetMechanism().Parameters[mcommon.NetNsInodeKey] = inodeDst

cconn := &cc.CrossConnect{
Id: "CrossConnectID",
Expand All @@ -82,32 +80,29 @@ func createConnectionLocalOnly(inodeSrc string, inodeDst string) *cc.CrossConnec

func createConnectionWithRemote(inodeSrc string, inodeDst string) (*cc.CrossConnect, *cc.CrossConnect) {
localSrc := createLocalSource()
localSrc.LocalSource.GetMechanism().Parameters[localconn.NetNsInodeKey] = inodeSrc
localSrc.GetMechanism().Parameters[mcommon.NetNsInodeKey] = inodeSrc

localDst := createLocalDest()
localDst.LocalDestination.GetMechanism().Parameters[localconn.NetNsInodeKey] = inodeDst
localDst.GetMechanism().Parameters[mcommon.NetNsInodeKey] = inodeDst

remote := &remoteconn.Connection{
remote := &conn.Connection{
Id: strconv.Itoa(rand.Int()),
NetworkService: ns,
Labels: make(map[string]string),
Path: common.Strings2Path("remote", "nsm"),
}

remoteDst := &cc.CrossConnect_RemoteDestination{RemoteDestination: remote}

cconn1 := &cc.CrossConnect{
Id: strconv.Itoa(rand.Int()),
Payload: "CrossConnectPayload",
Source: localSrc,
Destination: remoteDst,
Destination: remote,
}

remoteSrc := &cc.CrossConnect_RemoteSource{RemoteSource: remote}

cconn2 := &cc.CrossConnect{
Id: strconv.Itoa(rand.Int()),
Payload: "CrossConnectPayload",
Source: remoteSrc,
Source: remote,
Destination: localDst,
}

Expand Down

0 comments on commit 666258f

Please sign in to comment.