gnmiserver

package
v0.49.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package gnmiserver implements the gNMI RPC handlers shared by the `subscribe` and `collect` commands' northbound gNMI servers:

  • Subscribe RPCs are served from a cache kept in sync with the configured subscriptions.
  • Get and Set RPCs are relayed to the target(s) selected via the request Prefix.Target field. Target resolution is command specific and is provided by the caller as a TargetSelectFn.
  • Get requests with paths under the `gnmic` origin are served by the caller provided InternalGetFn, typically from the command's own configuration.

The handlers are meant to be registered on a pkg/api/server gRPC server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DefaultSampleInterval is used when a stream/sample
	// subscription requests a zero sample interval.
	DefaultSampleInterval time.Duration
	// MinSampleInterval is used when a stream/sample subscription
	// requests a non-zero sample interval lower than this value.
	MinSampleInterval time.Duration
	// MinHeartbeatInterval is used when a subscription requests a
	// non-zero heartbeat interval lower than this value.
	MinHeartbeatInterval time.Duration
	// Debug enables additional debug logs.
	Debug bool
}

Config holds the handlers' behavioral knobs, taken from the `gnmi-server` configuration section.

type Handlers

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

Handlers implements the gNMI Get, Set and Subscribe RPC handlers.

func New

func New(cfg Config, c cache.Cache, logger *slog.Logger, selectTargets TargetSelectFn, internalGet InternalGetFn) *Handlers

New creates gNMI RPC handlers. c may be nil, in which case Subscribe RPCs are rejected with an `Unimplemented` status code.

func (*Handlers) Capabilities

func (h *Handlers) Capabilities(ctx context.Context, req *gnmi.CapabilityRequest) (*gnmi.CapabilityResponse, error)

Capabilities handles a gNMI Capabilities RPC, advertising the gNMI version and the encodings the server can carry (relayed unary RPCs and cache-served subscriptions pass values through in the encoding produced by the targets).

func (*Handlers) Get

func (h *Handlers) Get(ctx context.Context, req *gnmi.GetRequest) (*gnmi.GetResponse, error)

Get handles a gNMI Get RPC. Requests with paths under the `gnmic` origin are served by the internal Get handler, other requests are relayed to the target(s) selected via the request Prefix.Target field.

func (*Handlers) Set

func (h *Handlers) Set(ctx context.Context, req *gnmi.SetRequest) (*gnmi.SetResponse, error)

Set handles a gNMI Set RPC, relaying it to the target(s) selected via the request Prefix.Target field.

func (*Handlers) Subscribe

func (h *Handlers) Subscribe(req *gnmi.SubscribeRequest, stream gnmi.GNMI_SubscribeServer) error

Subscribe handles a gNMI Subscribe RPC, serving it from the cache.

type InternalGetFn

type InternalGetFn func(ctx context.Context, req *gnmi.GetRequest) (*gnmi.GetResponse, error)

InternalGetFn serves Get requests with paths under the `gnmic` origin.

type TargetSelectFn

type TargetSelectFn func(ctx context.Context, target string) (map[string]*target.Target, func(), error)

TargetSelectFn resolves the request Prefix.Target value into a set of gNMI targets. The returned cleanup function is called once the RPC is done; it is used to release connections dialed on demand.

Jump to

Keyboard shortcuts

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