Skip to content
Snippets Groups Projects
Select Git revision
  • a19bd25688f27510a63b4e4d945610daf03c17cc
  • master default
  • ui-handover
  • ui-update-yang
  • inventory-manager-netbox
  • heiss_bachelor_thesis
  • proto-getters
  • 392-remove-renovate
  • renovate/go.mongodb.org-mongo-driver-2.x
  • renovate/github.com-bufbuild-protovalidate-go-0.x
  • renovate/google.golang.org-genproto-googleapis-api-digest
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/eslint-9.x-lockfile
  • renovate/eslint-plugin-react-7.x-lockfile
  • renovate/dompurify-3.x-lockfile
  • renovate/testing-library-react-16.x-lockfile
  • renovate/eslint-plugin-prettier-5.x-lockfile
  • renovate/react-dom-18.x-lockfile
  • renovate/eslint-plugin-react-hooks-5.x-lockfile
  • renovate/testing-library-user-event-14.x-lockfile
  • renovate/reduxjs-toolkit-2.x-lockfile
  • renovate/github.com-openconfig-gnmi-0.x
  • 0.1.0
23 results

gnmi_transport.go

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    gnmi_transport.go 14.36 KiB
    package nucleus
    
    import (
    	"context"
    	"fmt"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/change"
    	tpInterface "code.fbi.h-da.de/danet/gosdn/controller/interfaces/transport"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
    
    	ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/customerrs"
    	"code.fbi.h-da.de/danet/gosdn/controller/nucleus/types"
    	"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
    	gpb "github.com/openconfig/gnmi/proto/gnmi"
    	"github.com/openconfig/goyang/pkg/yang"
    	"github.com/openconfig/ygot/util"
    	"github.com/openconfig/ygot/ygot"
    	"github.com/openconfig/ygot/ytypes"
    	log "github.com/sirupsen/logrus"
    
    	tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
    )
    
    // Gnmi implements the Transport interface and provides an SBI with the
    // possibility to access a gNMI endpoint.
    type Gnmi struct {
    	SetNode   func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
    	RespChan  chan *gpb.SubscribeResponse
    	Unmarshal func([]byte, *gpb.Path, ygot.GoStruct, ...ytypes.UnmarshalOpt) error
    	Options   *tpb.TransportOption
    	client    gpb.GNMIClient
    	config    *gnmi.Config
    }
    
    // newGnmiTransport takes a struct of GnmiTransportOptions and returns a Gnmi
    // transport based on the values of it.
    // Do not call directly. Use NewTransport() instead.
    func newGnmiTransport(opts *tpb.TransportOption, sbi southbound.SouthboundInterface) (*Gnmi, error) {
    	if opts == nil || sbi == nil {
    		return nil, &customerrs.InvalidParametersError{
    			Func:  newGnmiTransport,
    			Param: "'opts' and 'sbi' can not be nil",
    		}
    	} else if opts.TransportOption == nil {
    		return nil, &customerrs.InvalidParametersError{
    			Func:  newGnmiTransport,
    			Param: "'opts.TransportOption' can not be nil",
    		}
    	}
    
    	gnmiConfig := &gnmi.Config{
    		Addr:        opts.Address,
    		Password:    opts.Password,
    		Username:    opts.Username,
    		TLS:         opts.Tls,
    		Encoding:    gpb.Encoding_JSON_IETF,
    		Compression: opts.GetGnmiTransportOption().GetCompression(),
    	}
    	c, err := gnmi.Dial(gnmiConfig)
    	if err != nil {
    		return nil, err
    	}
    
    	log.WithFields(log.Fields{
    		"target": opts.Address,
    		"tls":    opts.Tls,
    	}).Info("building new gNMI transport")