server

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

README

gNMI model generation

  1. Add YANG modules to /yang directory.
  2. Updated go generate comment of the file in gostruct directory (e.g. gostruct/gen.sample.go).
  3. Run cd gostruct && go generate gen.sample.go to generate the model structure.
  4. Generate test code and verify it.
    • Get test code (done)
    • Set test code [FIXME]

[FIXME] Need auto generation.

Documentation

Overview

Package server implements a gnmi server to mock a device with YANG models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamInterceptor

func StreamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

StreamInterceptor - used to intercept the unary gRPC Streams

func UnaryInterceptor

func UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryInterceptor - used to intercept the unary gRPC requests and responses

Types

type Config

type Config struct {
}

Config - the gNMI server configuration

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server struct maintains the data structure for device config and implements the interface of gnmi server. It supports Capabilities, Get, and Set APIs. Typical usage:

g := grpc.NewServer()
s, err := Server.NewServer(model, config, callback)
pb.NewServer(g, s)
reflection.Register(g)
listen, err := net.Listen("tcp", ":8080")
g.Serve(listen)

For a real device, apply the config changes to the hardware in the callback function. Arguments:

newRoot: new root config to be applied on the device.
func callback(newRoot ygot.ValidatedGoStruct) error {
		// Apply the config to your device and return nil if success. return error if fails.
		//
		// Do something ...
}

func NewServer

func NewServer(m *model.Model, startup []byte, startupIsJSON, disableBundling, disableYDB bool) (*Server, error)

NewServer creates an instance of Server with given json config.

func (*Server) Capabilities

func (s *Server) Capabilities(ctx context.Context, req *pb.CapabilityRequest) (*pb.CapabilityResponse, error)

Capabilities returns supported encodings and supported models.

func (*Server) Close

func (s *Server) Close()

Close the connected YDB instance

func (*Server) Closed

func (s *Server) Closed(local, remote net.Addr)

Closed - netsession interface to receive the session closed event

func (*Server) Get

func (s *Server) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse, error)

Get implements the Get RPC in gNMI spec.

func (*Server) InternalUpdate

func (s *Server) InternalUpdate(funcPtr func(modeldata ygot.ValidatedGoStruct) error) error

InternalUpdate is an experimental feature to let the server update its internal states. Use it with your own risk.

func (Server) OnChangeCreated

func (tcb Server) OnChangeCreated(slicepath []string, changes ygot.GoStruct)

OnChangeCreated - callback for Telemetry subscription on data changes

func (Server) OnChangeDeleted

func (tcb Server) OnChangeDeleted(slicepath []string)

OnChangeDeleted - callback for Telemetry subscription on data changes

func (Server) OnChangeFinished

func (tcb Server) OnChangeFinished(changes ygot.GoStruct)

OnStarted - callback for Telemetry subscription on data changes

func (Server) OnChangeReplaced

func (tcb Server) OnChangeReplaced(slicepath []string, changes ygot.GoStruct)

OnChangeReplaced - callback for Telemetry subscription on data changes

func (Server) OnChangeStarted

func (tcb Server) OnChangeStarted(changes ygot.GoStruct)

OnChangeStarted - callback for Telemetry subscription on data changes

func (*Server) Set

func (s *Server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse, error)

Set implements the Set RPC in gNMI spec.

func (*Server) Started

func (s *Server) Started(local, remote net.Addr)

Started - netsession interface to receive the session started event

func (*Server) Subscribe

func (s *Server) Subscribe(stream pb.GNMI_SubscribeServer) error

Subscribe implements the Subscribe RPC in gNMI spec.

type Session

type Session struct {
	ID                 uint64         `json:"id,omitempty"`
	SID                string         `json:"sid,omitempty"`
	Username           string         `json:"username,omitempty"`
	Password           string         `json:"password,omitempty"`
	GrpcVer            string         `json:"grpc-ver,omitempty"`
	ContentType        string         `json:"content-type,omitempty"`
	LoginTime          time.Time      `json:"login-time,omitempty"`
	DestinationAddress string         `json:"destination-address,omitempty"`
	DestinationPort    uint16         `json:"destination-port,omitempty"`
	Protocol           StreamProtocol `json:"protocol,omitempty"`
	// contains filtered or unexported fields
}

Session - gNMI gRPC Session information managed by server

type StreamProtocol

type StreamProtocol int

StreamProtocol - The type of the subscription protocol

const (
	// StreamUserDefined - Stream subscription over user-defined RPC
	StreamUserDefined StreamProtocol = iota
	// StreamSSH - Stream subscription over SSH
	StreamSSH
	// StreamGRPC - Stream subscription over GRPC
	StreamGRPC
	// StreamJSONRPC - Stream subscription over JSON RPC
	StreamJSONRPC
	// StreamThriftRPC - Stream subscription over ThriftRPC
	StreamThriftRPC
	// StreamWebsocketRPC - Stream subscription over WebsocketRPC
	StreamWebsocketRPC
)

func (StreamProtocol) String

func (s StreamProtocol) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL