lwotg

package
v0.0.0-...-518e166 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package lwotg implements a lightweight, extensible OpenTrafficGenerator (github.com/open-traffic-generator) implementation. OpenTrafficGenerator is often abbreviated to OTG.

Index

Constants

View Source
const (
	// InterfaceHintGroupName is the name of the group that is used to
	// handle interface details.
	InterfaceHintGroupName string = "interface_map"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FlowController

type FlowController struct {
	// ID is a unique ID for the controller that allows tracing through the system.
	ID string
	// Stop is a channel used to indicate that the function that has been called should
	// cease to send or receive packets.
	Stop chan struct{}
}

FlowController acts as the control mechanism for a specific direction of a specific flow.

func NewFlowController

func NewFlowController(id string) *FlowController

NewFlowController returns an initialised FlowController.

type FlowGeneratorFn

type FlowGeneratorFn func(*otg.Flow, []*OTGIntf) (TXRXFn, bool, error)

FlowGeneratorFn is a function that takes an input OTG Flow and, if it is able to, returns a TXRXFn that controls that flow. If the function is not able to handle the flow (e.g., it is an IP flow and the function can handle only MPLS) it returns no TXRXFn, and sets the bool return argument to false. If the function can handle the flow, it returns a TXRXFn that can be used to start the flow, with the bool return argument set to true. Errors encountered whilst generating a TXRXFn for a flow that the function can return should be returned and are treated as errors that should be returned to the caller.

The arguments to a FlowGeneratorFn are as follows:

  • otg.Flow - the flow that is to be generated as described by the OTG schema.
  • []*OTGIntf - information as to the set of interfaces that are currently within the OTG configuration. This information can be used to map the flow creation functionality to the underlying interface.

type Hint

type Hint struct {
	// Group is a string used to specify a name for a set of hints that
	// are associated with one another.
	Group string
	// Key is the name of the hint.
	Key string
	// Value is the value stored for the hint.
	Value string
}

Hint is <group, key, value> tuple that can be handed to modules of the OTG implementation to perform their functions. For example, it may be used to communicate mappings between system interfaces and the names that are used in OTG for them.

type OTGIntf

type OTGIntf struct {
	// OTGEthernetName specifies the name of the interface in the OTG configuration when referred to
	// as an Ethernet port.
	OTGEthernetName string
	// OTGPortName specifies the name of the interface in the overall OTG configuration.
	OTGPortName string
	// SystemName specifies the name of the interface on the system.
	SystemName string
	// IPv4 specifies the IPv4 addresses associated with the interface.
	IPv4 []*ipAddress
}

OTGIntf describes an interface in the OTG configuration.

type Server

type Server struct {
	*otg.UnimplementedOpenapiServer
	// contains filtered or unexported fields
}

Server implements the OTG ("Openapi") server.

func New

func New() *Server

New returns a new lightweight OTG (LWOTG) server.

func (*Server) AddConfigHandler

func (s *Server) AddConfigHandler(fn func(*otg.Config) error)

AddConfigHandler adds the specified fn to the set of config handlers.

func (*Server) AddFlowHandlers

func (s *Server) AddFlowHandlers(fns ...FlowGeneratorFn)

AddFlowHandlers adds the set of flow generator functions specified to the flow handlers that are considered as candidates by the server.

func (*Server) GetConfig

func (s *Server) GetConfig(_ context.Context, _ *emptypb.Empty) (*otg.GetConfigResponse, error)

GetConfig retrieves the current OTG configuration from the lwotg instance, implementing the GetConfig RPC.

func (*Server) SetConfig

func (s *Server) SetConfig(ctx context.Context, req *otg.SetConfigRequest) (*otg.SetConfigResponse, error)

SetConfig handles the SetConfig OTG RPC. In this implementation it calls the set of configHandlers that have been registered with the server.

func (*Server) SetControlState

SetControlState handles the SetControlState OTG RPC. This implementation only supports:

  • starting and stopping all protocols, by calling the protocolHandler function that has been specified.
  • starting and stopping all traffic, by calling startTraffic and stopTraffic.

It returns an error if an unsupported option is requested.

func (*Server) SetHintChannel

func (s *Server) SetHintChannel(ch chan Hint)

SetHintChannel sets the hint channel to the specified channel.

func (*Server) SetProtocolHandler

func (s *Server) SetProtocolHandler(fn func(*otg.Config, otg.StateProtocolAll_State_Enum) error)

SetProtocolHandler sets the specified function as the function to be called when the SetControlState RPC is called with protocol related options.

type TXRXFn

type TXRXFn func(tx, rx *FlowController)

TXRXFn is a function that handles the send and receive of packets for a particular flow. When called it should begin tranmitting packets using the tx FlowController channels, and receiving them using the rx FlowController. Tx and Rx should be spawned into new goroutines and the function should return. Telemetry that is published by the flow should be written to the corresponding FlowController GNMI channel. Encountered errors should be written to the error channel.

type TXRXWrapper

type TXRXWrapper struct {
	Fn   TXRXFn
	Name string
}

Jump to

Keyboard shortcuts

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