diff --git a/config/rbac.go b/config/rbac.go index 6d707546f5..4df8975cc5 100644 --- a/config/rbac.go +++ b/config/rbac.go @@ -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" diff --git a/topology/probes/nsm/connection.go b/topology/probes/nsm/connection.go index 74536f2985..c2bb08bdf3 100644 --- a/topology/probes/nsm/connection.go +++ b/topology/probes/nsm/connection.go @@ -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" @@ -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 @@ -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 } @@ -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 } @@ -171,7 +170,7 @@ 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(), }, @@ -179,7 +178,7 @@ func (l *localConnectionPair) createMetadata() graph.Metadata { 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(), }, @@ -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{ @@ -256,7 +263,7 @@ 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(), }, @@ -264,7 +271,7 @@ func (r *remoteConnectionPair) createMetadata() graph.Metadata { 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(), }, @@ -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(), }, }, diff --git a/topology/probes/nsm/nsm.go b/topology/probes/nsm/nsm.go index 0b9c1a9fbe..7b31dd4bb5 100644 --- a/topology/probes/nsm/nsm.go +++ b/topology/probes/nsm/nsm.go @@ -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" @@ -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 @@ -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 } @@ -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 } @@ -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) @@ -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, @@ -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) diff --git a/topology/probes/nsm/nsm_test.go b/topology/probes/nsm/nsm_test.go index 55523a3c58..87c8e68269 100644 --- a/topology/probes/nsm/nsm_test.go +++ b/topology/probes/nsm/nsm_test.go @@ -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", @@ -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, }