ovs

package
v0.0.0-alpha.0....-18a57d7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ovs provides a wrapper around ovs-vsctl and ovs-ofctl

Index

Constants

View Source
const (
	OVS_OFCTL = "ovs-ofctl"
	OVS_VSCTL = "ovs-vsctl"
)

Variables

This section is empty.

Functions

func FlowMatches

func FlowMatches(flow, match *OvsFlow) bool

flowMatches tests if flow matches match. If match.ptype is ParseForAdd, then the table, priority, and all fields much match. If it is ParseForFilter, then any fields specified in match must match, but there can be additional fields in flow that are not in match.

func GroupMatches

func GroupMatches(group, match *OVSGroup) bool

GroupMatches checks if two Groups match. Returns true if the GroupIDs, Types match exactly and if the two have the same buckets regardless of order

func ParseExternalIDs

func ParseExternalIDs(externalIDs string) (map[string]string, error)

func UnparseExternalIDs

func UnparseExternalIDs(externalIDs map[string]string) string

Types

type Bucket

type Bucket struct {
	Actions []OvsField
}

type GroupType

type GroupType string
const (
	SelectGroup GroupType = "select"
)

type Interface

type Interface interface {
	// AddBridge creates the bridge associated with the interface, optionally setting
	// properties on it (as with "ovs-vsctl set Bridge ..."). If the bridge already
	// exists, this will NOT result in error since it sets --may-exist internally.
	AddBridge(properties ...string) error

	// DeleteBridge deletes the bridge associated with the interface. This always
	// calls del-br by passing the --if-exists flag so the resulting call
	// will not error out if the bridge doesn't exist
	DeleteBridge() error

	// AddPort adds an interface to the bridge, requesting the indicated port
	// number, and optionally setting properties on it (as with "ovs-vsctl set
	// Interface ..."). Returns the allocated port number (or an error).
	AddPort(port string, ofportRequest int, properties ...string) (int, error)

	// DeletePort removes an interface from the bridge. (It is not an
	// error if the interface is not currently a bridge port.)
	DeletePort(port string) error

	// DumpGroup dumps the groups table for the bridge and returns it as an array of stings
	// Currently DumpGroups is only used in testing
	DumpGroups() ([]string, error)

	// GetOFPort returns the OpenFlow port number of a given network interface
	// attached to a bridge.
	GetOFPort(port string) (int, error)

	// SetFrags sets the fragmented-packet-handling mode (as with
	// "ovs-ofctl set-frags")
	SetFrags(mode string) error

	// Create creates a record in the OVS database, as with "ovs-vsctl create" and
	// returns the UUID of the newly-created item.
	// NOTE: This only works for QoS; for all other tables the created object will
	// immediately be garbage-collected; we'd need an API that calls "create" and "set"
	// in the same "ovs-vsctl" call.
	Create(table string, values ...string) (string, error)

	// Destroy deletes the indicated record in the OVS database. It is not an error if
	// the record does not exist
	Destroy(table, record string) error

	// Get gets the indicated value from the OVS database. For multi-valued or
	// map-valued columns, the data is returned in the same format as "ovs-vsctl get".
	Get(table, record, column string) (string, error)

	// Set sets one or more columns on a record in the OVS database, as with
	// "ovs-vsctl set"
	Set(table, record string, values ...string) error

	// Clear unsets the indicated columns in the OVS database. It is not an error if
	// the value is already unset
	Clear(table, record string, columns ...string) error

	// Find finds records in the OVS database that match the given condition.
	// It returns the value of the given columns of matching records.
	Find(table string, column []string, condition string) ([]map[string]string, error)

	// FindOne is like Find but returns only a single column
	FindOne(table, column, condition string) ([]string, error)

	// DumpFlows dumps the flow table for the bridge and returns it as an array of
	// strings, one per flow. If flow is not "" then it describes the flows to dump.
	DumpFlows(flow string, args ...interface{}) ([]string, error)

	// NewTransaction begins a new OVS transaction.
	NewTransaction() Transaction

	// UpdateOVSMetrics runs a Dumpflows transaction and sets the gauge with the existing amount of flows
	UpdateOVSMetrics()
}

Interface represents an interface to OVS

func New

func New(execer exec.Interface, bridge string) (Interface, error)

New returns a new ovs.Interface

func NewFake

func NewFake(bridge string) Interface

NewFake returns a new ovs.Interface

type OVSGroup

type OVSGroup struct {
	GroupID uint32
	Type    GroupType
	Buckets []Bucket
}

OVSGroup represents an OVS group

func ParseGroup

func ParseGroup(group string) (*OVSGroup, error)

type OvsField

type OvsField struct {
	Name  string
	Value string
}

type OvsFlow

type OvsFlow struct {
	Table    int
	Priority int
	Created  time.Time
	Cookie   string
	Fields   []OvsField
	Actions  []OvsField
	// contains filtered or unexported fields
}

ovsFlow represents an OVS flow

func ParseFlow

func ParseFlow(ptype ParseType, flow string, args ...interface{}) (*OvsFlow, error)

func (*OvsFlow) FindAction

func (of *OvsFlow) FindAction(name string) (*OvsField, bool)

func (*OvsFlow) FindField

func (of *OvsFlow) FindField(name string) (*OvsField, bool)

func (*OvsFlow) NoteHasPrefix

func (of *OvsFlow) NoteHasPrefix(prefix string) bool

type ParseType

type ParseType string
const (
	ParseForAdd    ParseType = "add"
	ParseForFilter ParseType = "filter"
	ParseForDump   ParseType = "dump"
)

type Transaction

type Transaction interface {
	// AddFlow prepares adding a flow to the bridge.
	// Given flow is cached but not executed at this time.
	// The arguments are passed to fmt.Sprintf().
	AddFlow(flow string, args ...interface{})

	// DeleteFlows prepares deleting all matching flows from the bridge.
	// Given flow is cached but not executed at this time.
	// The arguments are passed to fmt.Sprintf().
	DeleteFlows(flow string, args ...interface{})

	AddGroup(groupID uint32, groupType string, buckets []string)
	DeleteGroup(groupID uint32)

	// Commit executes all cached flows as a single atomic transaction and
	// returns any error that occurred during the transaction.
	Commit() error
}

Transaction manages a single set of OVS flow modifications

Jump to

Keyboard shortcuts

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