Documentation
¶
Overview ¶
Package server implements a gnmi server to mock a device with YANG models.
Index ¶
- func StreamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- type Config
- type Server
- func (s *Server) Capabilities(ctx context.Context, req *pb.CapabilityRequest) (*pb.CapabilityResponse, error)
- func (s *Server) Close()
- func (s *Server) Closed(local, remote net.Addr)
- func (s *Server) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse, error)
- func (s *Server) InternalUpdate(funcPtr func(modeldata ygot.ValidatedGoStruct) error) error
- func (tcb Server) OnChangeCreated(slicepath []string, changes ygot.GoStruct)
- func (tcb Server) OnChangeDeleted(slicepath []string)
- func (tcb Server) OnChangeFinished(changes ygot.GoStruct)
- func (tcb Server) OnChangeReplaced(slicepath []string, changes ygot.GoStruct)
- func (tcb Server) OnChangeStarted(changes ygot.GoStruct)
- func (s *Server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse, error)
- func (s *Server) Started(local, remote net.Addr)
- func (s *Server) Subscribe(stream pb.GNMI_SubscribeServer) error
- type Session
- type StreamProtocol
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 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) 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 ¶
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 ¶
OnStarted - callback for Telemetry subscription on data changes
func (Server) OnChangeReplaced ¶
OnChangeReplaced - callback for Telemetry subscription on data changes
func (Server) OnChangeStarted ¶
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.
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