govppmux

package
v1.0.4 Latest Latest
Warning

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

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

README

GoVPP Mux

The govppmux is a Core Agent Plugin which allows other plugins to access VPP independently on each other by means of connection multiplexing.

Any plugin (core or external) that interacts with VPP can ask govppmux to get its own, potentially customized, communication channel to running VPP instance. Behind the scenes, all channels share the same connection created during the plugin initialization using govpp core.

API

Connection

Parameters of the VPP connection are fixed and cannot be configured. GoVPP connects to that instance of VPP which uses the default shared memory segment prefix. This is because it is assumed that there is really only a single VPP running in a sand-boxed environment together with the agent (e.g. through containerization)

Multiplexing

NewAPIChannel returns a new API channel for communication with VPP via govpp core. It uses default buffer sizes for the request and reply Go channels (by default both are 100 messages long).

If it is expected that the VPP may get overloaded at peak loads, for example if the user plugin sends configuration requests in bulks, then it is recommended to use NewAPIChannelBuffered and increase the buffer size for requests appropriately. Similarly, NewAPIChannelBuffered allows to configure the size of the buffer for responses. This is also useful since the buffer for responses is also used to carry VPP notifications and statistics which may temporarily rapidly grow in size and frequency. By increasing the reply channel size, the probability of dropping messages from VPP decreases at the cost of increased memory footprint.

Example

The following example shows how to dump VPP interfaces using a multi-response request:

// Create a new VPP channel with the default configuration.
plugin.vppCh, err = govppmux.NewAPIChannel()
if err != nil {
    // Handle error condition...
}
// Close VPP channel.
defer safeclose.Close(plugin.vppCh)

req := &interfaces.SwInterfaceDump{}
reqCtx := plugin.vppCh.SendMultiRequest(req)

for {
    msg := &interfaces.SwInterfaceDetails{}
    stop, err := reqCtx.ReceiveReply(msg)
    if err != nil {
        // Handle error condition...
    }

    // Break out of the loop in case there are no more messages.
    if stop {
        break
    }

    log.Info("Found interface with sw_if_index=", msg.SwIfIndex)
    // Process the message...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API added in v1.0.4

type API interface {
	// NewAPIChannel returns a new API channel for communication with VPP via govpp core.
	// It uses default buffer sizes for the request and reply Go channels.
	//
	// Example of binary API call from some plugin using GOVPP:
	//      ch, _ := govpp_mux.NewAPIChannel()
	//      ch.SendRequest(req).ReceiveReply
	NewAPIChannel() (*api.Channel, error)

	// NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp core.
	// It allows to specify custom buffer sizes for the request and reply Go channels.
	//
	// Example of binary API call from some plugin using GOVPP:
	//      ch, _ := govpp_mux.NewAPIChannelBuffered(100, 100)
	//      ch.SendRequest(req).ReceiveReply
	NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (*api.Channel, error)
}

API for other plugins to get connectivity to VPP

type Deps added in v1.0.2

type Deps struct {
	local.PluginInfraDeps // inject
}

Deps is here to group injected dependencies of plugin to not mix with other plugin fields.

type GOVPPPlugin

type GOVPPPlugin struct {
	Deps // inject
	// contains filtered or unexported fields
}

GOVPPPlugin implements the govppmux plugin interface.

func FromExistingAdapter

func FromExistingAdapter(vppAdapter adapter.VppAdapter) *GOVPPPlugin

FromExistingAdapter is used mainly for testing purposes.

func (*GOVPPPlugin) Close

func (plugin *GOVPPPlugin) Close() error

Close cleans up the resources allocated by the govppmux plugin.

func (*GOVPPPlugin) Init

func (plugin *GOVPPPlugin) Init() error

Init is the entry point called by Agent Core. A single binary-API connection to VPP is established.

func (*GOVPPPlugin) NewAPIChannel

func (plugin *GOVPPPlugin) NewAPIChannel() (*api.Channel, error)

NewAPIChannel returns a new API channel for communication with VPP via govpp core. It uses default buffer sizes for the request and reply Go channels.

Example of binary API call from some plugin using GOVPP:

ch, _ := govpp_mux.NewAPIChannel()
ch.SendRequest(req).ReceiveReply

func (*GOVPPPlugin) NewAPIChannelBuffered

func (plugin *GOVPPPlugin) NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (*api.Channel, error)

NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp core. It allows to specify custom buffer sizes for the request and reply Go channels.

Example of binary API call from some plugin using GOVPP:

ch, _ := govpp_mux.NewAPIChannelBuffered(100, 100)
ch.SendRequest(req).ReceiveReply

Jump to

Keyboard shortcuts

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