socketclient

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package socketclient is a pure Go implementation of adapter.VppAPI, which uses unix domain sockets as the transport for connecting to the VPP binary API.

The current implementation only supports VPP binary API, the VPP stats API is not supported and clients still have to use vppapiclient for retrieving stats.

Requirements

The socketclient connects to unix domain socket defined in VPP configuration.

It is enabled by default at /run/vpp/api.sock by the following config section:

socksvr {
	socket-name default
}

If you want to use custom socket path:

socksvr {
	socket-name /run/vpp/api.sock
}

Index

Constants

View Source
const (
	// DefaultSocketName is default VPP API socket file path.
	DefaultSocketName = "/run/vpp/api.sock"
	// DefaultClientName is used for identifying client in socket registration
	DefaultClientName = "govppsock"
)

Variables

View Source
var (

	// DefaultConnectTimeout is default timeout for connecting
	DefaultConnectTimeout = time.Second * 3
	// DefaultDisconnectTimeout is default timeout for discconnecting
	DefaultDisconnectTimeout = time.Millisecond * 100
	// MaxWaitReady defines maximum duration of waiting for socket file
	MaxWaitReady = time.Second * 3
)

Functions

func SetLogger

func SetLogger(logger logrus.FieldLogger)

SetLogger sets global logger.

Types

type Client

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

func NewVppClient

func NewVppClient(socket string) *Client

NewVppClient returns a new Client using socket. If socket is empty string DefaultSocketName is used.

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) Disconnect

func (c *Client) Disconnect() error

func (*Client) GetMsgID

func (c *Client) GetMsgID(msgName string, msgCrc string) (uint16, error)

func (*Client) SendMsg

func (c *Client) SendMsg(context uint32, data []byte) error

func (*Client) SetClientName

func (c *Client) SetClientName(name string)

SetClientName sets a client name used for identification.

func (*Client) SetConnectTimeout

func (c *Client) SetConnectTimeout(t time.Duration)

SetConnectTimeout sets timeout used during connecting.

func (*Client) SetDisconnectTimeout

func (c *Client) SetDisconnectTimeout(t time.Duration)

SetDisconnectTimeout sets timeout used during disconnecting.

func (*Client) SetMsgCallback

func (c *Client) SetMsgCallback(cb adapter.MsgCallback)

SetMsgCallback sets the callback for incoming messages.

func (*Client) WaitReady

func (c *Client) WaitReady() error

WaitReady checks if the socket file exists and if it does not exist waits for it for the duration defined by MaxWaitReady.

Jump to

Keyboard shortcuts

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