vci

package module
v0.0.0-...-d31791d Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT, MPL-2.0 Imports: 15 Imported by: 17

README

VCI repository

Please see docs, especially Overview for details.

Documentation

Overview

Package vci implements an interface to the Vyatta Component Infrastructure. VCI is a common interface to YANG modeled portions of the system. VCI provides a model concept that allow for implementing multiple YANG models by a single component. A model is a group of YANG modules that are considered to be one of the component's data-models. A component may need more than one module to effectively do it's job, the model concept is used to group these modules together so when new configration is sent to the component it receives all the information it requires. See the docs directory for more detailed information on the general operation of VCI.

The package consists of a few parts:

(1) Components that are interfaces to portions of the system
    that can be accessed by VCI clients.
(2) Client that provides a conveinent library for talking to components.
(3) Subscriptions that provide a mechanism for controlling the receipt of
    notifications.
(4) A few error types that allow one to create errors that conform to
    RFC6020's described errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitNotification

func EmitNotification(
	moduleName, name string, val interface{},
) error

EmitNotification connects to the transport sends the notification then disconnects from the transport. If sending multiple notifications using a Client is a more efficient options.

Types

type Client

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

The Client supplies an encapsulated mechanism for performing operations on the VCI bus.

func Dial

func Dial() (*Client, error)

Dial is the constructor for the default VCI client. It will return a client that can speak on the standard bus configuration.

func (*Client) Call

func (c *Client) Call(moduleName, rpcName string, input interface{}) *RPCCall

Call will initiate a call to an RPC specified by the YANG module name and the RPC name. This will return a promise that can be fulfilled when the result is needed. The input object is marshalled using the RFC7951 encoder.

func (*Client) CallWithMetadata

func (c *Client) CallWithMetadata(
	moduleName, rpcName string, metadata RPCMetadata, input interface{},
) *RPCCall

CallWithMetadata will initiate a call to an RPC specified by the YANG module name and the RPC name. This will return a promise that can be fulfilled when the result is needed. Additonal meta data may be provided via the RPCMetaData object. The input object is marshalled using the RFC7951 encoder.

func (*Client) CheckConfigForModel

func (c *Client) CheckConfigForModel(
	modelName string,
	object interface{},
) error

CheckConfigForModel will validate the configuration for the given model, using the model's component's registered Check method, marshalling the config from the provided object using the RFC7951 encoder.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to VCI.

func (*Client) Emit

func (c *Client) Emit(
	moduleName, notificationName string,
	object interface{},
) error

Emit will allow one to send to a notification specified by the YANG module name and the notification name. The supplied object will be marshalled using the RFC7951 encoder. If the object does not match the YANG schema for the notificaiton an error will be returned.

func (*Client) SetConfigForModel

func (c *Client) SetConfigForModel(
	modelName string,
	object interface{},
) error

SetConfigForModel will set the configuration for the given model, using the model's component's registered Set method, marshallling the config from the provided object using the RFC7951 encoder.

func (*Client) StoreConfigByModelInto

func (c *Client) StoreConfigByModelInto(
	modelName string,
	object interface{},
) error

StoreConfigByModelInto will retrieve the configuration for a supplied model and unmarshal it into the supplied object using the RFC7951 decoder.

func (*Client) StoreStateByModelInto

func (c *Client) StoreStateByModelInto(
	modelName string,
	object interface{},
) error

StoreStateByModelInto will retrieve the operational state for a supplied model and unmarshal it into the supplied object using the RFC7951 decoder.

func (*Client) Subscribe

func (c *Client) Subscribe(
	moduleName, notificationName string,
	subscriber interface{},
) *Subscription

Subscribe will allow one to subscribe to a notification specified by the YANG module name and the notification name. This takes a subscriber which may be one of:

(1) a function that takes any type as its input.
    The notification will be unmarshalled into the type
    using the RFC7951 decoder.
(2) a send channel of any type. The notification will be
    unmarshalled into the type by the RFC7951 decoder.

Any other type for a subscriber will signal an error on subscription.

type Component

type Component interface {
	// Model creates a new Model attached to this component.
	Model(model string) Model
	// Run attaches the component to the underlying transport
	// and begins the processing of messages destined for this
	// component.
	Run() error
	// Subscribe begins listening to a notification. When
	// a message is received it will be passed to the subscriber.
	// A subscribers is a function of any type. The notification
	// message will be unmarshalled into the type by the RFC7951
	// decoder.
	Subscribe(mod, name string, subscriber interface{}) error
	// Unsubscribe removes the listener for a particular notification.
	Unsubscribe(mod, name string) error
	// LookupSubscription will provide the Subscription representation
	// of a notification listener. This can be used to tweak the queuing
	// policies associated with the listener.
	LookupSubscription(mod, name string) *Subscription
	// Client provides access to the component's client representation
	// this is useful for sharing a client between the component and
	// the implementation so that the implementation can use the same
	// connection to the transport as the component.
	Client() *Client
	// Wait blocks until the component terminates its execution. If there was
	// an error during component execution it will be returned from Wait.
	Wait() error
	// Stop terminates the component execution. It will close all transport
	// connections and disconnect the component from the bus.
	Stop() error
}

A Component represents an interface for a portion of the data-model. It maps the user accessible model of the system to the concrete model of the service that implements the functionallity.

func NewComponent

func NewComponent(name string) Component

NewComponent creates a concrete representation of the Component interface and returns the opaque Component so it may be used. Refer to the Component interface documentation for more information.

type Model

type Model interface {
	// Config attaches a configuration handler to the model.
	// This handler must implement three methods:
	//   (1) Set(config T) error
	//       This method applies the configuration supplied to
	//       the underlying service.
	//   (2) Check(config T) error
	//       This method validates the configuration supplied
	//       against a set of constraints that cannot be modeled in YANG.
	//   (3) Get() (T, error)
	//       This method returns the configuration in a form that matches
	//       the data-model.
	// where T is any type that can be marshalled by the RFC7951
	// encoder.
	Config(object interface{}) Model
	// State attaches an operational state handler to the model.
	// This handler must implement one method:
	//   (1) Get() (T, error)
	//       This method returns the configuration in a form that matches
	//       the data-model.
	// where T is any type that can be marshalled by the RFC7951
	// encoder.
	State(object interface{}) Model
	// RPC attaches a set of RPCs to the model for a particular module name.
	// This handler must be one of the following forms:
	//   (1) A map from string to func(input T1) (output T2, error).
	//       In this form all methods are exposed with the names provided
	//       in the map.
	//   (2) An object with only methods of the following form:
	//       Name(input T1) (output T2, error)
	//       Names will be converted from the Go style CamelCase
	//       to the standard YANG convention of camel-case.
	//   (3) A map from string to func(meta RPCMetadata, input T1) (output T2, error).
	//       In this form all methods are exposed with the names provided
	//       in the map.
	//   (4) An object with only methods of the following form:
	//       Name(meta RPCMetadata, input T1) (output T2, error)
	//       Names will be converted from the Go style CamelCase
	//       to the standard YANG convention of camel-case.
	// where T1, T2 are any types that can be marshalled by the
	// RFC7951 encoder.
	// The RPCs must implement the functionallity specified in the YANG model
	// and must conform to the model in both input and output.
	RPC(moduleName string, object interface{}) Model
}

A Model represents a self-consistent set of YANG models. The Model can have configuration, operational data, and RPCs associated with it. The objects registered to receieve messages for the configuration, operational data, and RPCs implement the functionallity to map the user level data-model to the underlying system model.

type PathError

type PathError struct {
	Path    string
	Message string
}

func (*PathError) Error

func (e *PathError) Error() string

type RPCCall

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

The RPCCall represents a promise to return the result of the RPC call upon request. RPCs happen asynchronously until the methods are called on this object.

func CallRPC

func CallRPC(
	moduleName, rpcName string,
	input interface{},
) *RPCCall

CallRPC calls the RPC corresponding to moduleName and rpcName using input as the input to the RPC. This provides a single shot RPC call without maintaining a client connection but it is more costly to call an RPC this way.

func (*RPCCall) StoreOutputInto

func (c *RPCCall) StoreOutputInto(object interface{}) error

StoreOutputInto will unmarshal the output tree of the RPC into the supplied object using the RFC7951 decoder or an error if an error occurred during the call.

type RPCMetadata

type RPCMetadata struct {
	Pid    int32
	Uid    uint32
	User   string
	Groups []string
}

RPCMetaData provides additional context to the recipient of an RPC call. Since the VCI client library is to be used only from trusted sources to make calls we can provide components with some additional trusted context such as the user making the call.

type Subscription

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

The Subscription type represents a process that listens for notifications and reports them to the subscriber. The input for this process is a queue of messages delivered from the bus. By default the queue for the subscriber is unbounded. Flow control policies can be set before the process is started or may be set at any point during processing.

func (*Subscription) BlockAfterLimit

func (s *Subscription) BlockAfterLimit(limit int) *Subscription

BlockAfterLimit causes a limit to be placed on the backlog of notifications that the subscriber will receive, any overrun will block the sender.

func (*Subscription) Cancel

func (s *Subscription) Cancel() error

Cancel cancels the subscription, stopping the process.

func (*Subscription) Coalesce

func (s *Subscription) Coalesce() *Subscription

Coalesce collapses notifications if the sender overruns the receiver. In some situations one need not be concerned with intermediate states so they can be collapsed so the last notification is always received by the subscriber.

func (*Subscription) Deliver

func (s *Subscription) Deliver(encodedData string) error

Deliver will place the notificaiton on the input queue for the subscription.

func (*Subscription) DropAfterLimit

func (s *Subscription) DropAfterLimit(limit int) *Subscription

DropAfterLimit causes a limit to be placed on the backlog of notifications that the subscriber will receive, any overrun will be dropped.

func (*Subscription) RemoveLimit

func (s *Subscription) RemoveLimit() *Subscription

RemoveLimit lifts the limits imposed by Coalesce, DropAfterLimit, or BlockAfterLimit. This resets the Subscription's queue to be unbounded.

func (*Subscription) Run

func (s *Subscription) Run() error

Run causes the process to start.

func (*Subscription) StoreLastNotificationInto

func (s *Subscription) StoreLastNotificationInto(object interface{}) error

StoreLastNotificationInto allows one to retrieve the last notification that was sent if caching is enabled.

func (*Subscription) ToggleCaching

func (s *Subscription) ToggleCaching() *Subscription

ToggleCaching toggles cacheing of the last notification.

Directories

Path Synopsis
internal
queue
Package queue implements a set of synchronization queues and some generic algorithms that will operate on these queues.
Package queue implements a set of synchronization queues and some generic algorithms that will operate on these queues.
tools

Jump to

Keyboard shortcuts

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