client

package
v0.0.0-...-800520f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Overview

Package client defines a gRIBI stub client implementation in Go.

Index

Constants

This section is empty.

Variables

View Source
var (

	// BusyLoopDelay specifies a delay that should be used when looping around pending
	// transactions. By default, the client tries not to busy loop, but this can introduce
	// artificial delays when benchmarking server operations. It is NOT RECOMMENDED to
	// change the default value other than when measuring convergence time at the client.
	BusyLoopDelay = 100 * time.Millisecond

	// TreatRIBACKAsCompletedInFIBACKMode allows the caller to modify the client behaviour
	// to treat a RIB ACK from the target as the end of an operation even though the session
	// has requested FIB_ACK. This allows benchmarking of the time to receive a RIB_ACK from
	// a server in FIB_ACK mode. In production clients that require FIB_ACK it is ACTIVELY
	// HARMFUL to change this value, since the client will consider a server to have converged
	// on receipt of a RIB_ACK despite the fact that the session requested FIB_ACK.
	TreatRIBACKAsCompletedInFIBACKMode = false
)

Functions

func AllPrimaryClients

func AllPrimaryClients() *allPrimaryClients

AllPrimaryClients is an option that is used when creating a new client that specifies that this client will be part of a group of clients that are all considered primary sources of routing information.

In this mode of operation, the server is expected to store all entries that are written to it over gRIBI regardless of their source client. If multiple clients write the same entry, selection amongst them is done based on the lowest client identifier (the remote address when expressed as a 128-bit number) as per the explanation in https://github.com/openconfig/gribi/blob/master/doc/motivation.md#tying-injected-entries-to-the-liveliness-of-grpc-client

func ElectedPrimaryClient

func ElectedPrimaryClient(initialID *spb.Uint128) *electedPrimaryClient

ElectedPrimaryClient is an option used when creating a new client that specifies that this client will be part of a group of clients elect a master amongst them, such that exactly one client is considered the primary source of routing information. The server is not expected to know any of the details of this election process - but arbitrates based on a supplied election ID (expressed as a 128-bit number). The client with the highest election ID is considered the primary and hence has active entries within the device's RIB.

The initial election ID to be used is stored

func FIBACK

func FIBACK() *fibACK

FIBACK indicates that the client should request that the server sends acknowledgements for gRIBI transactions only after they have been programmed into the FIB. By default, a gRIBI server will send an acknowledgement when the entry has been installed into the RIB.

func PersistEntries

func PersistEntries() *persistEntries

PersistEntries indicates that the client should request that the server persists entries after it has disconnected. By default, a gRIBI server will purge all entries when the client disconnects. This persistence mode may only be used when the redundancy mode is AllPrimaryClients.

Types

type Client

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

Client is a wrapper for the gRIBI client.

func New

func New(opts ...Opt) (*Client, error)

New creates a new gRIBI client with the specified set of options. The options provided control parameters that live for the lifetime of the client, such as those that are within the session parameters. A new client, or error, is returned.

func (*Client) AckResult

func (c *Client) AckResult(res ...*OpResult) error

AckResult allows a caller to acknowledge a specific result in the client's queue removing it from the queue stored in the client. If results are not acknowledged, the client will store all results indefinitely.

func (*Client) AwaitConverged

func (c *Client) AwaitConverged(ctx context.Context) error

AwaitConverged waits until the client is converged and writes to the supplied channel. The function blocks until such time as the client returns or when the context is done.

func (*Client) Close

func (c *Client) Close() error

Close disconnects the underlying gRPC connection to the gRIBI server.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes a Modify RPC to the client and sends the initial session parameters/election ID if required. The Modify RPC is stored within the client such that it can be used for subsequent calls - such that Connect must be called before subsequent operations that should send to the target.

An error is returned if the Modify RPC cannot be established or there is an error response to the initial messages that are sent on the connection.

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, addr string, opts ...DialOpt) error

Dial dials the server specified in the addr string, using the specified set of dial options.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done returns a channel which is written to when the client is disconnected from the server. It can be used to trigger reconnections.

func (*Client) Flush

func (c *Client) Flush(ctx context.Context, req *spb.FlushRequest) (*spb.FlushResponse, error)

Flush implements the gRIBI Flush RPC.

func (*Client) Get

func (c *Client) Get(ctx context.Context, sreq *spb.GetRequest) (*spb.GetResponse, error)

Get implements the Get RPC to the gRIBI server. It takes an input context and a GetRequest and returns a single GetResponse with all contained results within it.

func (*Client) Pending

func (c *Client) Pending() ([]PendingRequest, error)

Pending returns the set of AFTOperations that are pending response from the target, it returns a slice of PendingRequest interfaces which describes the contents of the pending queues.

func (*Client) Q

func (c *Client) Q(m *spb.ModifyRequest)

Q enqueues a ModifyRequest to be sent to the target.

func (*Client) ReplaceStub

func (c *Client) ReplaceStub(stub spb.GRIBIClient) error

ReplaceStub replaces the gRPC stub used by the client only if the client is not in a sending state.

func (*Client) Reset

func (c *Client) Reset()

Reset clears the client's transient state - is is recommended to call this method between reconnections at a server to clear pending queues and results which are no longer valid.

func (*Client) Results

func (c *Client) Results() ([]*OpResult, error)

Results returns the set of ModifyResponses that have been received from the target.

func (*Client) StartSending

func (c *Client) StartSending()

StartSending toggles the client to begin sending messages that are in the send queue (enqued by Q) to the connection established by Connect.

func (*Client) Status

func (c *Client) Status() (*ClientStatus, error)

Status returns a composite status of the client at the time that the caller specified.

func (*Client) StopSending

func (c *Client) StopSending()

StopSending toggles the client to stop sending messages to the server, meaning that entries that are enqueued will be stored until StartSending is called.

func (*Client) UseStub

func (c *Client) UseStub(stub spb.GRIBIClient) error

UseStub instructs the client to use the gRPC stub implementing the GRIBIClient service.

type ClientErr

type ClientErr struct {
	Send, Recv []error
}

ClientError encapsulates send and receive errors for the client.

func (*ClientErr) Error

func (c *ClientErr) Error() string

Error implements the error interface.

type ClientStatus

type ClientStatus struct {
	// Timestamp expressed in nanoseconds since the epoch that the status was retrieved.
	Timestamp int64
	// PendingTransactions is the slice of pending operations on the client.
	PendingTransactions []PendingRequest
	Results             []*OpResult
	SendErrs            []error
	ReadErrs            []error
}

ClientStatus is the overview status of the client, timestamped according to the time at which the state was retrieved.

type DialOpt

type DialOpt interface {
	// contains filtered or unexported methods
}

DialOpt specifies options that can be used when dialing the gRIBI server specified by the client.

type ElectionReqDetails

type ElectionReqDetails struct {
	// Timestamp is the time at which the update was sent, specified in nanoseconds
	// since the epoch.
	Timestamp int64
	// ID is the election ID that was sent to the server. This can be used to determine
	// whether the response shows that this client actually became the master.
	ID *spb.Uint128
}

ElectionReqDetails stores the details of an individual election update that was sent to the server.

type OpDetailsResults

type OpDetailsResults struct {
	// Type is the type of the operation (i.e., ADD, MODIFY, DELETE)
	Type constants.OpType

	// NextHopIndex is the identifier for a next-hop modified by the operation.
	NextHopIndex uint64
	// NextHopGroupID is the identifier for a next-hop-group modified by the
	// operation.
	NextHopGroupID uint64
	// IPv4Prefix is the IPv4 prefix modified by the operation.
	IPv4Prefix string
	// IPv6Prefix is the IPv6 prefix modified by the operation.
	IPv6Prefix string
	// MPLSLabel is the MPLS label that was modified by the operation.
	MPLSLabel uint64
}

OpDetailsResults provides details of an operation for use in the results.

func (*OpDetailsResults) String

func (o *OpDetailsResults) String() string

String returns a human-readable form of the OpDetailsResults

type OpResult

type OpResult struct {
	// Timestamp is the timestamp that the result was received.
	Timestamp int64
	// Latency is the latency of the request from the server. This is calculated
	// based on the time that the request was sent to the client (became pending)
	// and the time that the response was received from the server. It is expressed
	// in nanoseconds.
	Latency int64

	// CurrentServerElectionID indicates that the message that was received from the server
	// was an ModifyResponse sent in response to an updated election ID, its value is the
	// current master election ID (maximum election ID seen from any client) reported from
	// the server.
	CurrentServerElectionID *spb.Uint128

	// SessionParameters contains the parameters that were received from the server in
	// response to the parameters sent to the server.
	SessionParameters *spb.SessionParametersResult

	// OperationID indicates that the message that was received from the server was a
	// ModifyResponse sent in response to an AFTOperation, its value is the ID of the
	// operation to which it corresponds.
	OperationID uint64

	// ClientError describes an error that is internal to the client.
	ClientError string

	// ProgrammingResult stores the result of an AFT operation on the server.
	ProgrammingResult spb.AFTResult_Status

	// Details stores detailed information about the operation over the ID
	// and the result.
	Details *OpDetailsResults
}

OpResult stores details pertaining to a result that was received from the server.

func (*OpResult) String

func (o *OpResult) String() string

String returns a string for an OpResult for debugging purposes.

type Opt

type Opt interface {
	// contains filtered or unexported methods
}

Opt is an interface that is implemented for all options that can be supplied when creating a new client. This captures parameters that are sent at the start of a gRIBI session that

type PendingOp

type PendingOp struct {
	// Timestamp is the timestamp that the operation was queued at.
	Timestamp int64
	// Op is the operation that the pending request pertains to.
	Op *spb.AFTOperation
}

PendingOp stores details pertaining to a pending request in the client.

type PendingRequest

type PendingRequest interface {
	// contains filtered or unexported methods
}

PendingRequest is an interface implemented by all types that can be reported back to callers describing a pending request in the client.

type SessionParamReqDetails

type SessionParamReqDetails struct {
	// Timestamp is the time at which the update was sent, specified in nanoseconds
	// since the epoch.
	Timestamp int64
	// Outgoing is the parameters that were sent to the server.
	Outgoing *spb.SessionParameters
}

SessionParamReqDetails stores the details of an individual session parameters update that was sent to the server.

Jump to

Keyboard shortcuts

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