ovs

package
v0.0.0-...-0f13360 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

README

ovs

Package ovs is a client library for Open vSwitch which enables programmatic control of the virtual switch.

Package ovs is a wrapper around the ovs-vsctl and ovs-ofctl utilities, but in the future, it may speak OVSDB and OpenFlow directly with the same interface.

// Create a *ovs.Client.  Specify ovs.OptionFuncs to customize it.
c := ovs.New(
    // Prepend "sudo" to all commands.
    ovs.Sudo(),
)

// $ sudo ovs-vsctl --may-exist add-br ovsbr0
if err := c.VSwitch.AddBridge("ovsbr0"); err != nil {
    log.Fatalf("failed to add bridge: %v", err)
}

// $ sudo ovs-ofctl add-flow ovsbr0 priority=100,ip,actions=drop
err := c.OpenFlow.AddFlow("ovsbr0", &ovs.Flow{
    Priority: 100,
    Protocol: ovs.ProtocolIPv4,
    Actions:  []ovs.Action{ovs.Drop()},
})
if err != nil {
    log.Fatalf("failed to add flow: %v", err)
}

Documentation

Overview

Package ovs is a client library for Open vSwitch which enables programmatic control of the virtual switch.

Index

Constants

View Source
const (
	// FlowFormatNXMTableID is a flow format which allows Nicira Extended match
	// with the ability to place a flow in a specific table.
	FlowFormatNXMTableID = "NXM+table_id"

	// FlowFormatOXMOpenFlow14 is a flow format which allows Open vSwitch
	// extensible match.
	FlowFormatOXMOpenFlow14 = "OXM-OpenFlow14"
)
View Source
const (
	ProtocolOpenFlow10 = "OpenFlow10"
	ProtocolOpenFlow11 = "OpenFlow11"
	ProtocolOpenFlow12 = "OpenFlow12"
	ProtocolOpenFlow13 = "OpenFlow13"
	ProtocolOpenFlow14 = "OpenFlow14"
	ProtocolOpenFlow15 = "OpenFlow15"
)

Protocol constants for use with Protocols and BridgeOptions.

View Source
const (
	// DefaultIngressRatePolicing is used to disable the ingress policing,
	// which is the default behavior.
	DefaultIngressRatePolicing = int64(-1)

	// DefaultIngressBurstPolicing is to change the ingress policing
	// burst to the default size, 1000 kb.
	DefaultIngressBurstPolicing = int64(-1)
)
View Source
const (
	// AnyTable is a special table value to match flows in any table.
	AnyTable = -1
)
View Source
const (
	// PortLOCAL is a special in_port value which refers to the local port
	// of an OVS bridge.
	PortLOCAL = -1
)
View Source
const VLANNone = 0xffff

VLANNone is a special value which indicates that DataLinkVLAN should only match packets with no VLAN tag specified.

Variables

View Source
var (
	// ErrInvalidFlowStats is returned when flow statistics from 'ovs-ofctl
	// dump-aggregate' do not match the expected output format.
	ErrInvalidFlowStats = errors.New("invalid flow statistics")
)
View Source
var (
	// ErrInvalidPortRange is returned when there's a port range that invalid.
	ErrInvalidPortRange = errors.New("invalid port range")
)
View Source
var (
	// ErrInvalidPortStats is returned when port statistics from 'ovs-ofctl
	// dump-ports' do not match the expected output format.
	ErrInvalidPortStats = errors.New("invalid port statistics")
)
View Source
var (
	// ErrInvalidTable is returned when tables from 'ovs-ofctl dump-tables'
	// do not match the expected output format.
	ErrInvalidTable = errors.New("invalid openflow table")
)

Functions

func IsPortNotExist

func IsPortNotExist(err error) bool

IsPortNotExist checks if err is of type Error and is caused by asking OVS for information regarding a non-existent port.

func SetState

func SetState(state CTState) string

SetState sets the specified CTState flag. This helper should be used with ConnectionTrackingState.

func SetTCPFlag

func SetTCPFlag(flag TCPFlag) string

SetTCPFlag sets the specified TCPFlag. This helper should be used with TCPFlags.

func UnsetState

func UnsetState(state CTState) string

UnsetState unsets the specified CTState flag. This helper should be used with ConnectionTrackingState.

func UnsetTCPFlag

func UnsetTCPFlag(flag TCPFlag) string

UnsetTCPFlag unsets the specified TCPFlag. This helper should be used with TCPFlags.

Types

type Action

type Action interface {
	encoding.TextMarshaler
	fmt.GoStringer
}

An Action is a type which can be marshaled into an OpenFlow action. Actions can be used with Flows to perform operations when the Flow matches an input packet.

Actions must also implement fmt.GoStringer for code generation purposes.

func Conjunction

func Conjunction(id int, dimensionNumber int, dimensionSize int) Action

Conjunction associates a flow with a certain conjunction ID to match on more than one dimension across multiple set matches.

func ConnectionTracking

func ConnectionTracking(args string) Action

ConnectionTracking sends a packet through the host's connection tracker.

func DecTTL

func DecTTL() Action

DecTTL decrements the TTL of a packet.

func Drop

func Drop() Action

Drop immediately discards the packet. It must be the only Action specified when used.

func Flood

func Flood() Action

Flood outputs the packet on all switch ports other than the port on which it was received, which have flooding enabled.

func InPort

func InPort() Action

InPort outputs the packet on the port from which it was received.

func Load

func Load(value string, field string) Action

Load loads the specified value into the specified field. If either string is empty, an error is returned.

func Local

func Local() Action

Local outputs the packet on the local port, which corresponds to the network device that has the same name as the bridge.

func ModDataLinkDestination

func ModDataLinkDestination(addr net.HardwareAddr) Action

ModDataLinkDestination modifies the data link destination of a packet.

func ModDataLinkSource

func ModDataLinkSource(addr net.HardwareAddr) Action

ModDataLinkSource modifies the data link source of a packet.

func ModNetworkDestination

func ModNetworkDestination(ip net.IP) Action

ModNetworkDestination modifies the destination IPv4 address of a packet.

func ModNetworkSource

func ModNetworkSource(ip net.IP) Action

ModNetworkSource modifies the source IPv4 address of a packet.

func ModTransportDestinationPort

func ModTransportDestinationPort(port uint16) Action

ModTransportDestinationPort modifies the destination port of a packet.

func ModTransportSourcePort

func ModTransportSourcePort(port uint16) Action

ModTransportSourcePort modifies the source port of a packet.

func ModVLANVID

func ModVLANVID(vid int) Action

ModVLANVID modifies the VLAN ID (VID) on a packet. It adds a VLAN tag if one is not already present. vid must be a valid VLAN VID, within the range of 0 to 4095.

func Move

func Move(src string, dst string) Action

Move copies the named bits from field src to field dst. If either string is empty, an error is returned.

func Normal

func Normal() Action

Normal subjects the packet to the device's normal L2/L3 processing.

func Output

func Output(port int) Action

Output outputs the packet to the specified switch port. Use InPortLocal to output the packet to the LOCAL port. port must either be a non-negative integer.

func Resubmit

func Resubmit(port int, table int) Action

Resubmit resubmits a packet for further processing by matching flows with the specified port and table. If port or table are zero, they are set to empty in the output Action. If both are zero, an error is returned.

func ResubmitPort

func ResubmitPort(port int) Action

ResubmitPort resubmits a packet into the current table with its context modified to look like it originated from the specified openflow port ID.

func SetField

func SetField(value string, field string) Action

SetField overwrites the specified field with the specified value. If either string is empty, an error is returned.

func SetTunnel

func SetTunnel(tunnelID uint64) Action

SetTunnel sets the tunnel id, e.g. VNI if vxlan is the tunnel protocol.

func StripVLAN

func StripVLAN() Action

StripVLAN strips the VLAN tag from a packet, if one is present.

type BitRange

type BitRange struct {
	Value uint16
	Mask  uint16
}

A BitRange is a representation of a range of values from base value with a bitmask applied.

type BridgeOptions

type BridgeOptions struct {
	// Protocols specifies the OpenFlow protocols the bridge should use.
	Protocols []string

	// Hwaddr specifies the MAC address of the Internal bridge interface.
	Hwaddr string
}

An BridgeOptions enables configuration of a bridge.

type CTState

type CTState string

CTState is a connection tracking state, which can be used with the ConnectionTrackingState function.

const (
	CTStateNew         CTState = "new"
	CTStateEstablished CTState = "est"
	CTStateRelated     CTState = "rel"
	CTStateReply       CTState = "rpl"
	CTStateInvalid     CTState = "inv"
	CTStateTracked     CTState = "trk"
)

List of common CTState constants available in OVS 2.5. Reference the ovs-ofctl man-page for a description of each one.

type Client

type Client struct {
	// OpenFlow wraps functionality of the 'ovs-ofctl' binary.
	OpenFlow *OpenFlowService

	// VSwitch wraps functionality of the 'ovs-vsctl' binary.
	VSwitch *VSwitchService
	// contains filtered or unexported fields
}

A Client is a client type which enables programmatic control of Open vSwitch.

func New

func New(options ...OptionFunc) *Client

New creates a new Client with zero or more OptionFunc configurations applied.

type Error

type Error struct {
	Out []byte
	Err error
}

An Error is an error returned when shelling out to an Open vSwitch control program. It captures the combined stdout and stderr as well as the exit code.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of an Error.

type ExecFunc

type ExecFunc func(cmd string, args ...string) ([]byte, error)

An ExecFunc is a function which accepts input arguments and returns raw byte output and an error. ExecFuncs are swappable to enable testing without OVS installed.

type FailMode

type FailMode string

A FailMode is a failure mode which Open vSwitch uses when it cannot contact a controller.

const (
	FailModeStandalone FailMode = "standalone"
	FailModeSecure     FailMode = "secure"
)

FailMode constants which can be used in OVS configurations.

type Flow

type Flow struct {
	Priority    int
	Protocol    Protocol
	InPort      int
	Matches     []Match
	Table       int
	IdleTimeout int
	Cookie      uint64
	Actions     []Action
}

A Flow is an OpenFlow flow meant for adding flows to a software bridge. It can be marshaled to and from its textual form for use with Open vSwitch.

func (*Flow) MarshalText

func (f *Flow) MarshalText() ([]byte, error)

MarshalText marshals a Flow into its textual form.

func (*Flow) MatchFlow

func (f *Flow) MatchFlow() *MatchFlow

MatchFlow converts Flow into MatchFlow.

func (*Flow) UnmarshalText

func (f *Flow) UnmarshalText(b []byte) error

UnmarshalText unmarshals flow text into a Flow.

type FlowError

type FlowError struct {
	// Str indicates the string, if any, that caused the flow to
	// fail while unmarshaling.
	Str string

	// Err indicates the error that halted flow marshaling or unmarshaling.
	Err error
}

A FlowError is an error encountered while marshaling or unmarshaling a Flow.

func (*FlowError) Error

func (e *FlowError) Error() string

Error returns the string representation of a FlowError.

type FlowStats

type FlowStats struct {
	PacketCount uint64
	ByteCount   uint64
}

FlowStats contains a variety of statistics about an Open vSwitch port, including its port ID and numbers about packet receive and transmit operations.

func (*FlowStats) UnmarshalText

func (f *FlowStats) UnmarshalText(b []byte) error

UnmarshalText unmarshals a FlowStats from textual form.

type FlowTransaction

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

A FlowTransaction is a transaction used when adding or deleting multiple flows using an Open vSwitch flow bundle.

func (*FlowTransaction) Add

func (tx *FlowTransaction) Add(flows ...*Flow)

Add pushes zero or more Flows on to the transaction, to be added by Open vSwitch. If any of the flows are invalid, Add becomes a no-op and the error will be surfaced when Commit is called.

func (*FlowTransaction) Commit

func (tx *FlowTransaction) Commit() error

Commit finalizes an AddFlowTransaction, returning any errors that may have occurred while adding flows. Commit must be called at the end of a successful transaction, but may return an error if one was encountered during a call to Add.

func (*FlowTransaction) Delete

func (tx *FlowTransaction) Delete(flows ...*MatchFlow)

Delete pushes zero or more MatchFlows on to the transaction, to be deleted by Open vSwitch. If any of the flows are invalid, Delete becomes a no-op and the error will be surfaced when Commit is called.

func (*FlowTransaction) Discard

func (tx *FlowTransaction) Discard(err error) error

Discard discards the contents of an AddFlowTransaction, returning an error wrapping the input error. Discard should be called if any operations fail in the middle of an AddFlowTransaction function.

type InterfaceOptions

type InterfaceOptions struct {
	// Type specifies the Open vSwitch interface type.
	Type InterfaceType

	// Peer specifies an interface to peer with when creating a patch interface.
	Peer string

	// IngressRatePolicing specifies the maximum rate for data received on
	// this interface in kbps.  Data received faster than this rate is dropped.
	// Set to 0 (the default) to disable policing.
	IngressRatePolicing int64

	// IngressBurstPolicing specifies the maximum burst size for data received on
	// this interface in kb.  The default burst size if set to 0 is 1000 kb.
	// This value has no effect if IngressRatePolicing is set to 0.  Specifying
	// a larger burst size lets the algorithm be more forgiving, which is important
	// for protocols like TCP that react severely to dropped packets.  The burst
	// size should be at least the size of the interface's MTU.  Specifying a
	// value that is numerically at least as large as 10% of IngressRatePolicing
	// helps TCP come closer to achieving the full rate.
	IngressBurstPolicing int64

	// RemoteIP can be populated when the interface is a tunnel interface type
	// for example "stt" or "vxlan". It specifies the remote IP address with which to
	// form tunnels when traffic is sent to this port. Optionally it could be set to
	// "flow" which expects the flow to set tunnel destination.
	RemoteIP string

	// Key can be populated when the interface is a tunnel interface type
	// for example "stt" or "vxlan". It specifies the tunnel ID to attach to
	// tunneled traffic leaving this interface. Optionally it could be set to
	// "flow" which expects the flow to set tunnel ID.
	Key string
}

An InterfaceOptions struct enables configuration of an Interface.

type InterfaceType

type InterfaceType string

An InterfaceType is a network interface type recognized by Open vSwitch.

const (
	InterfaceTypeGRE      InterfaceType = "gre"
	InterfaceTypeInternal InterfaceType = "internal"
	InterfaceTypePatch    InterfaceType = "patch"
	InterfaceTypeSTT      InterfaceType = "stt"
	InterfaceTypeVXLAN    InterfaceType = "vxlan"
)

InterfaceType constants which can be used in OVS configurations.

type Match

type Match interface {
	encoding.TextMarshaler
	fmt.GoStringer
}

A Match is a type which can be marshaled into an OpenFlow packet matching statement. Matches can be used with Flows to match specific packet types and fields.

Matches must also implement fmt.GoStringer for code generation purposes.

func ARPOperation

func ARPOperation(oper uint16) Match

ARPOperation matches packets with the specified ARP operation matching oper.

func ARPSourceHardwareAddress

func ARPSourceHardwareAddress(addr net.HardwareAddr) Match

ARPSourceHardwareAddress matches packets with an ARP source hardware address (SHA) matching addr.

func ARPSourceProtocolAddress

func ARPSourceProtocolAddress(ip string) Match

ARPSourceProtocolAddress matches packets with an ARP source protocol address (SPA) IPv4 address or IPv4 CIDR block matching addr.

func ARPTargetHardwareAddress

func ARPTargetHardwareAddress(addr net.HardwareAddr) Match

ARPTargetHardwareAddress matches packets with an ARP target hardware address (THA) matching addr.

func ARPTargetProtocolAddress

func ARPTargetProtocolAddress(ip string) Match

ARPTargetProtocolAddress matches packets with an ARP target protocol address (TPA) IPv4 address or IPv4 CIDR block matching addr.

func ConjunctionID

func ConjunctionID(id uint32) Match

ConjunctionID matches flows that have matched all dimension of a conjunction inside of the openflow table.

func ConnectionTrackingMark

func ConnectionTrackingMark(mark, mask uint32) Match

ConnectionTrackingMark matches a metadata associated with a connection tracking entry

func ConnectionTrackingState

func ConnectionTrackingState(state ...string) Match

ConnectionTrackingState matches packets using their connection state, when connection tracking is enabled on the host. Use the SetState and UnsetState functions to populate the parameter list for this function.

func ConnectionTrackingZone

func ConnectionTrackingZone(zone uint16) Match

ConnectionTrackingZone is a mechanism to define separate connection tracking contexts.

func DataLinkDestination

func DataLinkDestination(addr string) Match

DataLinkDestination matches packets with a destination hardware address and optional wildcard mask matching addr.

func DataLinkSource

func DataLinkSource(addr string) Match

DataLinkSource matches packets with a source hardware address and optional wildcard mask matching addr.

func DataLinkType

func DataLinkType(etherType uint16) Match

DataLinkType matches packets with the specified EtherType.

func DataLinkVLAN

func DataLinkVLAN(vid int) Match

DataLinkVLAN matches packets with the specified VLAN ID matching vid.

func ICMPType

func ICMPType(typ uint8) Match

ICMPType matches packets with the specified ICMP type matching typ.

func IPv6Destination

func IPv6Destination(ip string) Match

IPv6Destination matches packets with a destination IPv6 address or IPv6 CIDR block matching ip.

func IPv6Source

func IPv6Source(ip string) Match

IPv6Source matches packets with a source IPv6 address or IPv6 CIDR block matching ip.

func NeighborDiscoverySourceLinkLayer

func NeighborDiscoverySourceLinkLayer(addr net.HardwareAddr) Match

NeighborDiscoverySourceLinkLayer matches packets with an IPv6 neighbor solicitation source link-layer address matching addr.

func NeighborDiscoveryTarget

func NeighborDiscoveryTarget(ip string) Match

NeighborDiscoveryTarget matches packets with an IPv6 neighbor discovery target IPv6 address or IPv6 CIDR block matching ip.

func NeighborDiscoveryTargetLinkLayer

func NeighborDiscoveryTargetLinkLayer(addr net.HardwareAddr) Match

NeighborDiscoveryTargetLinkLayer matches packets with an IPv6 neighbor solicitation target link-layer address matching addr.

func NetworkDestination

func NetworkDestination(ip string) Match

NetworkDestination matches packets with a destination IPv4 address or IPv4 CIDR block matching ip.

func NetworkProtocol

func NetworkProtocol(num uint8) Match

NetworkProtocol matches packets with the specified IP or IPv6 protocol number matching num. For example, specifying 1 when a Flow's Protocol is IPv4 matches ICMP packets, or 58 when Protocol is IPv6 matches ICMPv6 packets.

func NetworkSource

func NetworkSource(ip string) Match

NetworkSource matches packets with a source IPv4 address or IPv4 CIDR block matching ip.

func TCPFlags

func TCPFlags(flags ...string) Match

TCPFlags matches packets using their enabled TCP flags, when matching TCP flags on a TCP segment. Use the SetTCPFlag and UnsetTCPFlag functions to populate the parameter list for this function.

func TransportDestinationMaskedPort

func TransportDestinationMaskedPort(port uint16, mask uint16) Match

TransportDestinationMaskedPort matches packets with a transport layer (TCP/UDP) destination port matching a masked port range.

func TransportDestinationPort

func TransportDestinationPort(port uint16) Match

TransportDestinationPort matches packets with a transport layer (TCP/UDP) destination port matching port.

func TransportSourceMaskedPort

func TransportSourceMaskedPort(port uint16, mask uint16) Match

TransportSourceMaskedPort matches packets with a transport layer (TCP/UDP) source port matching a masked port range.

func TransportSourcePort

func TransportSourcePort(port uint16) Match

TransportSourcePort matches packets with a transport layer (TCP/UDP) source port matching port.

func TunnelID

func TunnelID(id uint64) Match

TunnelID returns a Match that matches the given ID exactly.

func TunnelIDWithMask

func TunnelIDWithMask(id, mask uint64) Match

TunnelIDWithMask returns a Match with specified ID and mask.

func VLANTCI

func VLANTCI(tci, mask uint16) Match

VLANTCI matches packets based on their VLAN tag control information, using the specified TCI and optional mask value.

type MatchFlow

type MatchFlow struct {
	Protocol Protocol
	InPort   int
	Matches  []Match
	Table    int

	// Cookie indicates a cookie value to use when matching flows.
	Cookie uint64

	// CookieMask is a mask used alongside Cookie to enable matching flows
	// which match a mask.  If CookieMask is not set, Cookie will be matched
	// exactly.
	CookieMask uint64
}

A MatchFlow is an OpenFlow flow intended for flow deletion. It can be marshaled to its textual form for use with Open vSwitch.

func (*MatchFlow) MarshalText

func (f *MatchFlow) MarshalText() ([]byte, error)

MarshalText marshals a MatchFlow into its textual form.

type MatchFlowError

type MatchFlowError struct {
	// Str indicates the string, if any, that caused the flow to
	// fail while unmarshaling.
	Str string

	// Err indicates the error that halted flow marshaling or unmarshaling.
	Err error
}

A MatchFlowError is an error encountered while marshaling or unmarshaling a MatchFlow.

func (*MatchFlowError) Error

func (e *MatchFlowError) Error() string

Error returns the string representation of a MatchFlowError.

type OpenFlowService

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

An OpenFlowService is used in a Client to execute 'ovs-ofctl' commands.

func (*OpenFlowService) AddFlow

func (o *OpenFlowService) AddFlow(bridge string, flow *Flow) error

AddFlow adds a Flow to a bridge attached to Open vSwitch.

func (*OpenFlowService) AddFlowBundle

func (o *OpenFlowService) AddFlowBundle(bridge string, fn func(tx *FlowTransaction) error) error

AddFlowBundle creates an Open vSwitch flow bundle and enables adding and removing flows to and from the specified bridge using a FlowTransaction. This function enables atomic addition and deletion of flows to and from Open vSwitch.

func (*OpenFlowService) DelFlows

func (o *OpenFlowService) DelFlows(bridge string, flow *MatchFlow) error

DelFlows removes flows that match MatchFlow from a bridge attached to Open vSwitch.

If flow is nil, all flows will be deleted from the specified bridge.

func (*OpenFlowService) DumpAggregate

func (o *OpenFlowService) DumpAggregate(bridge string, flow *MatchFlow) (*FlowStats, error)

DumpAggregate retrieves statistics about the specified flow attached to the specified bridge.

func (*OpenFlowService) DumpFlows

func (o *OpenFlowService) DumpFlows(bridge string) ([]*Flow, error)

DumpFlows retrieves statistics about all flows for the specified bridge. If a table has no active flows and has not been used for a lookup or matched by an incoming packet, it is filtered from the output.

func (*OpenFlowService) DumpPort

func (o *OpenFlowService) DumpPort(bridge string, port string) (*PortStats, error)

DumpPort retrieves statistics about the specified port attached to the specified bridge.

func (*OpenFlowService) DumpPorts

func (o *OpenFlowService) DumpPorts(bridge string) ([]*PortStats, error)

DumpPorts retrieves statistics about all ports attached to the specified bridge.

func (*OpenFlowService) DumpTables

func (o *OpenFlowService) DumpTables(bridge string) ([]*Table, error)

DumpTables retrieves statistics about all tables for the specified bridge. If a table has no active flows and has not been used for a lookup or matched by an incoming packet, it is filtered from the output.

func (*OpenFlowService) ModPort

func (o *OpenFlowService) ModPort(bridge string, port string, action PortAction) error

ModPort modifies the specified characteristics for the specified port.

type OptionFunc

type OptionFunc func(c *Client)

An OptionFunc is a function which can apply configuration to a Client.

func Debug

func Debug(enable bool) OptionFunc

Debug returns an OptionFunc which enables debugging output for the Client type.

func Exec

func Exec(fn ExecFunc) OptionFunc

Exec returns an OptionFunc which sets an ExecFunc for use with a Client. This function should typically only be used in tests.

func FlowFormat

func FlowFormat(format string) OptionFunc

FlowFormat specifies the flow format to be used when shelling to 'ovs-ofctl'.

func Pipe

func Pipe(fn PipeFunc) OptionFunc

Pipe returns an OptionFunc which sets a PipeFunc for use with a Client. This function should typically only be used in tests.

func Protocols

func Protocols(versions []string) OptionFunc

Protocols specifies one or more OpenFlow protocol versions to be used when shelling to 'ovs-ofctl'.

func SetSSLParam

func SetSSLParam(pkey string, cert string, cacert string) OptionFunc

SetSSLParam configures SSL authentication using a private key, certificate, and CA certificate for use with ovs-ofctl.

func SetTCPParam

func SetTCPParam(addr string) OptionFunc

SetTCPParam configures the OVSDB connection using a TCP format ip:port for use with all ovs-vsctl commands.

func Sudo

func Sudo() OptionFunc

Sudo specifies that "sudo" should be prefixed to all OVS commands.

func Timeout

func Timeout(seconds int) OptionFunc

Timeout returns an OptionFunc which sets a timeout in seconds for all Open vSwitch interactions.

type PipeFunc

type PipeFunc func(stdin io.Reader, cmd string, args ...string) ([]byte, error)

A PipeFunc is a function which accepts an input stdin stream, command, and arguments, and returns command output and an error. PipeFuncs are swappable to enable testing without OVS installed.

type PortAction

type PortAction string

A PortAction is a port actions to change the port characteristics of the specific port through the ModPort API.

const (
	PortActionUp           PortAction = "up"
	PortActionDown         PortAction = "down"
	PortActionSTP          PortAction = "stp"
	PortActionNoSTP        PortAction = "no-stp"
	PortActionReceive      PortAction = "receive"
	PortActionNoReceive    PortAction = "no-receive"
	PortActionReceiveSTP   PortAction = "receive-stp"
	PortActionNoReceiveSTP PortAction = "no-receive-stp"
	PortActionForward      PortAction = "forward"
	PortActionNoForward    PortAction = "no-forward"
	PortActionFlood        PortAction = "flood"
	PortActionNoFlood      PortAction = "no-flood"
	PortActionPacketIn     PortAction = "packet-in"
	PortActionNoPacketIn   PortAction = "no-packet-in"
)

PortAction constants for ModPort API.

type PortRange

type PortRange struct {
	Start uint16
	End   uint16
}

An PortRange represents a range of ports expressed in 16 bit integers. The start and end values of this range are inclusive.

func (*PortRange) BitwiseMatch

func (r *PortRange) BitwiseMatch() ([]BitRange, error)

BitwiseMatch returns an array of BitRanges that represent the range of integers in the PortRange.

type PortStats

type PortStats struct {
	// PortID specifies the OVS port ID which this PortStats refers to.
	PortID int

	// Received and Transmitted contain information regarding the number
	// of received and transmitted packets, bytes, etc.
	// OVS stores all of these counters as uint64 values.
	Received    PortStatsReceive
	Transmitted PortStatsTransmit
}

PortStats contains a variety of statistics about an Open vSwitch port, including its port ID and numbers about packet receive and transmit operations.

func (*PortStats) UnmarshalText

func (p *PortStats) UnmarshalText(b []byte) error

UnmarshalText unmarshals a PortStats from textual form as output by 'ovs-ofctl dump-ports':

port  1: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
         tx pkts=0, bytes=0, drop=0, errs=0, coll=0

type PortStatsReceive

type PortStatsReceive struct {
	Packets uint64
	Bytes   uint64
	Dropped uint64
	Errors  uint64
	Frame   uint64
	Over    uint64
	CRC     uint64
}

PortStatsReceive contains information regarding the number of received packets, bytes, etc.

type PortStatsTransmit

type PortStatsTransmit struct {
	Packets    uint64
	Bytes      uint64
	Dropped    uint64
	Errors     uint64
	Collisions uint64
}

PortStatsTransmit contains information regarding the number of transmitted packets, bytes, etc.

type Protocol

type Protocol string

A Protocol is an OpenFlow protocol designation accepted by Open vSwitch.

const (
	ProtocolARP    Protocol = "arp"
	ProtocolICMPv4 Protocol = "icmp"
	ProtocolICMPv6 Protocol = "icmp6"
	ProtocolIPv4   Protocol = "ip"
	ProtocolIPv6   Protocol = "ipv6"
	ProtocolTCPv4  Protocol = "tcp"
	ProtocolTCPv6  Protocol = "tcp6"
	ProtocolUDPv4  Protocol = "udp"
	ProtocolUDPv6  Protocol = "udp6"
)

Protocol constants which can be used in OVS flow configurations.

type TCPFlag

type TCPFlag string

TCPFlag represents a flag in the TCP header, which can be used with the TCPFlags function.

const (
	TCPFlagURG TCPFlag = "urg"
	TCPFlagACK TCPFlag = "ack"
	TCPFlagPSH TCPFlag = "psh"
	TCPFlagRST TCPFlag = "rst"
	TCPFlagSYN TCPFlag = "syn"
	TCPFlagFIN TCPFlag = "fin"
)

RFC 793 TCP Flags

type Table

type Table struct {
	ID      int
	Name    string
	Wild    string
	Max     int
	Active  int
	Lookup  uint64
	Matched uint64
}

A Table is an Open vSwitch table.

func (*Table) UnmarshalText

func (t *Table) UnmarshalText(b []byte) error

UnmarshalText unmarshals a Table from textual form as output by 'ovs-ofctl dump-tables':

0: classifier: wild=0x3fffff, max=1000000, active=0
               lookup=0, matched=0

type TransportPortRanger

type TransportPortRanger interface {
	MaskedPorts() ([]Match, error)
}

A TransportPortRanger represents a port range that can be expressed as an array of bitwise matches.

func TransportDestinationPortRange

func TransportDestinationPortRange(startPort uint16, endPort uint16) TransportPortRanger

TransportDestinationPortRange represent a port range intended for a transport protocol destination port.

func TransportSourcePortRange

func TransportSourcePortRange(startPort uint16, endPort uint16) TransportPortRanger

TransportSourcePortRange represent a port range intended for a transport protocol source port.

type VSwitchGetService

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

A VSwitchGetService is used in a VSwitchService to execute 'ovs-vsctl get' subcommands.

func (*VSwitchGetService) Bridge

func (v *VSwitchGetService) Bridge(bridge string) (BridgeOptions, error)

Bridge gets configuration for a bridge and returns the values through a BridgeOptions struct.

func (*VSwitchGetService) PortID

func (v *VSwitchGetService) PortID(portName string) (int, error)

PortID gets OVS port ID for a given textual port name.

type VSwitchService

type VSwitchService struct {
	// Get wraps functionality of the 'ovs-vsctl get' subcommand.
	Get *VSwitchGetService

	// Set wraps functionality of the 'ovs-vsctl set' subcommand.
	Set *VSwitchSetService
	// contains filtered or unexported fields
}

A VSwitchService is used in a Client to execute 'ovs-vsctl' commands.

func (*VSwitchService) AddBridge

func (v *VSwitchService) AddBridge(bridge string) error

AddBridge attaches a bridge to Open vSwitch. The bridge may or may not already exist.

func (*VSwitchService) AddPort

func (v *VSwitchService) AddPort(bridge string, port string) error

AddPort attaches a port to a bridge on Open vSwitch. The port may or may not already exist.

func (*VSwitchService) DeleteBridge

func (v *VSwitchService) DeleteBridge(bridge string) error

DeleteBridge detaches a bridge from Open vSwitch. The bridge may or may not already exist.

func (*VSwitchService) DeletePort

func (v *VSwitchService) DeletePort(bridge string, port string) error

DeletePort detaches a port from a bridge on Open vSwitch. The port may or may not already exist.

func (*VSwitchService) GetController

func (v *VSwitchService) GetController(bridge string) (string, error)

GetController gets the controller address for this bridge.

func (*VSwitchService) GetFailMode

func (v *VSwitchService) GetFailMode(bridge string) (FailMode, error)

GetFailMode gets the FailMode for the specified bridge.

func (*VSwitchService) ListBridges

func (v *VSwitchService) ListBridges() ([]string, error)

ListBridges lists the bridges in Open vSwitch.

func (*VSwitchService) ListPorts

func (v *VSwitchService) ListPorts(bridge string) ([]string, error)

ListPorts lists the ports in Open vSwitch.

func (*VSwitchService) PortToBridge

func (v *VSwitchService) PortToBridge(port string) (string, error)

PortToBridge attempts to determine which bridge a port is attached to. If port does not exist, an error will be returned, which can be checked using IsPortNotExist.

func (*VSwitchService) SetController

func (v *VSwitchService) SetController(bridge string, address string) error

SetController sets the controller for this bridge so that ovs-ofctl can use this address to communicate.

func (*VSwitchService) SetFailMode

func (v *VSwitchService) SetFailMode(bridge string, mode FailMode) error

SetFailMode sets the specified FailMode for the specified bridge.

type VSwitchSetService

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

A VSwitchSetService is used in a VSwitchService to execute 'ovs-vsctl set' subcommands.

func (*VSwitchSetService) Bridge

func (v *VSwitchSetService) Bridge(bridge string, options BridgeOptions) error

Bridge sets configuration for a bridge using the values from a BridgeOptions struct.

func (*VSwitchSetService) Interface

func (v *VSwitchSetService) Interface(ifi string, options InterfaceOptions) error

Interface sets configuration for an interface using the values from an InterfaceOptions struct.

Jump to

Keyboard shortcuts

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