ovsdb

package module
v1.0.2-0...-040cf3e Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

OVSDB Management Protocol (RFC 7047) Client Library

This Go library implements a client for the Open vSwitch Database Management Protocol.

Overview

The client can be used for communicating with:

  • Open vSwitch database
  • OVN Northbound and Southbound databases
  • Application services

The following tables describe the implementation state for the protocol's RPC methods and database operations.

RFC Section Method Implemented?
4.1.1. List Databases (list_dbs)
4.1.2. Get Schema (get_schema)
4.1.3. Transact (transact) ✅ ⚠ select operation only
4.1.4. Cancel
4.1.5. Monitor
4.1.6. Update Notification
4.1.7. Monitor Cancellation
4.1.8. Lock Operations
4.1.9. Locked Notification
4.1.10. Stolen Notification
4.1.11. Echo (echo)
RFC Section Operation Implemented?
5.2.1. Insert
5.2.2. Select
5.2.3. Update
5.2.4. Mutate
5.2.5. Delete
5.2.6. Wait
5.2.7. Commit
5.2.8. Abort
5.2.9. Comment
5.2.10. Assert

Additionally, the library implements the following application calls:

  • list-commands
  • cluster/status
  • coverage/show

The goals of the OWNERS is:

  • implementing all methods and operations described in the RPC
  • documenting all the implemented methods and operations
  • achieving and maintaining test coverage of 80% or higher, and
  • providing ongoing support

There are alternatives to this client library. The following list contains notable libraries written in Go:

Currently, the best example how to use the library is OVN Exporter for Prometheus.

Documentation

Overview

Package ovsdb implements OVSDB (JSON-RPC 1.0) Client per RFC 7047.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint   string
	Timeout    int
	MaxRetries int
	Schemas    map[string]Schema
	References map[string]map[string]map[string]string
	// contains filtered or unexported fields
}

Client DOCS-TBD

func NewClient

func NewClient(s string, t int) (Client, error)

NewClient TODO

func (*Client) Close

func (cli *Client) Close() error

Close TODO

func (*Client) DatabaseExists

func (c *Client) DatabaseExists(dbName string) error

DatabaseExists - DOCS-TBD

func (*Client) Databases

func (c *Client) Databases() ([]string, error)

Databases - DOCS-TBD

func (*Client) Echo

func (c *Client) Echo(s string) error

Echo - TODO

func (*Client) GetSchema

func (c *Client) GetSchema(s string) (Schema, error)

GetSchema - TODO

func (*Client) Transact

func (c *Client) Transact(db string, query string) (Result, error)

Transact - TODO

type ClusterPeer

type ClusterPeer struct {
	ID         string
	Address    string
	NextIndex  uint64
	MatchIndex uint64
	Connection struct {
		Inbound  int
		Outbound int
	}
}

ClusterPeer contains information about a cluster peer.

type ClusterState

type ClusterState struct {
	ID           string
	UUID         string
	Database     string
	ClusterID    string
	ClusterUUID  string
	Address      string
	Status       int
	Role         int
	Term         uint64
	IsLeaderSelf int
	IsVotedSelf  int
	Log          struct {
		Low  uint64
		High uint64
	}
	NextIndex           uint64
	MatchIndex          uint64
	NotCommittedEntries uint64
	NotAppliedEntries   uint64
	Peers               map[string]*ClusterPeer
	Connections         struct {
		Inbound  int
		Outbound int
	}
}

ClusterState contains information about the state of a cluster of a server perspective.

type Column

type Column struct {
	Type      interface{} `json:"type"`
	Ephemeral bool        `json:"ephemeral"`
	Mutable   bool        `json:"mutable"`
}

Column - TODO

type Condition

type Condition struct {
	Column   string
	Function string
	Value    string
	Type     string
}

Condition represents condition for select operation, as described in [Notation](https://tools.ietf.org/html/rfc7047#section-5.1) section. The meaning of the <function> depends on the type of <column>.

func NewCondition

func NewCondition(s []string) (Condition, error)

NewCondition - DOCS-TBD

func (Condition) MarshalJSON

func (c Condition) MarshalJSON() ([]byte, error)

MarshalJSON - DOCS-TBD

func (*Condition) Parse

func (c *Condition) Parse(s string) error

Parse - DOCS-TBD

type Error

type Error struct {
	Message string `json:"error"`
	Details string `json:"details"`
	Syntax  string `json:"syntax"`
}

Error - TODO

func (*Error) String

func (e *Error) String() string

type Operation

type Operation struct {
	Name       string      `json:"op"`
	Table      string      `json:"table"`
	Conditions []Condition `json:"where"`
	Columns    []string    `json:"columns,omitempty"`
}

Operation represents Transact Method, as described in https://tools.ietf.org/html/rfc7047#section-4.1.3

func NewOperation

func NewOperation(query string) (Operation, error)

NewOperation - TODO

func (*Operation) Parse

func (t *Operation) Parse(i string) error

Parse - TODO

func (*Operation) Validate

func (t *Operation) Validate() error

Validate - TODO

type OvnChassis

type OvnChassis struct {
	UUID      string
	Name      string
	IPAddress net.IP
	Encaps    struct {
		UUID  string
		Proto string
	}
	Up       int
	Ports    []string
	Switches []string
}

OvnChassis represent an OVN chassis.

type OvnClient

type OvnClient struct {
	Database struct {
		Northbound OvsDatabase
		Southbound OvsDatabase
		Vswitch    OvsDatabase
	}
	Service struct {
		Northd   OvsDaemon
		Vswitchd OvsDaemon
	}
	Timeout int
	System  struct {
		ID       string
		RunDir   string
		Hostname string
		Type     string
		Version  string
	}
}

OvnClient holds connection to all OVN databases.

func NewOvnClient

func NewOvnClient() *OvnClient

NewOvnClient creates an instance of a client for OVN stack.

func (*OvnClient) AppListCommands

func (cli *OvnClient) AppListCommands(db string) (map[string]bool, error)

AppListCommands returns the list of commands supported by ovs-appctl tool and the database.

func (*OvnClient) Close

func (cli *OvnClient) Close()

Close closes connections to OVN databases.

func (*OvnClient) Connect

func (cli *OvnClient) Connect() error

Connect initiates connections to OVN databases.

func (*OvnClient) GetAppClusteringInfo

func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error)

GetAppClusteringInfo returns the counters associated with clustering setup.

func (*OvnClient) GetAppCoverageMetrics

func (cli *OvnClient) GetAppCoverageMetrics(db string) (map[string]map[string]float64, error)

GetAppCoverageMetrics returns the counters of the the number of times particular events occur during a daemon's runtime. The counters include averaged per-second rates for the last few seconds, the last minute and the last hour, and the total counts of all of the coverage counters.

func (*OvnClient) GetAppMemoryMetrics

func (cli *OvnClient) GetAppMemoryMetrics(db string) (map[string]float64, error)

GetAppMemoryMetrics returns memory usage counters.

func (*OvnClient) GetChassis

func (cli *OvnClient) GetChassis() ([]*OvnChassis, error)

GetChassis returns a list of OVN chassis.

func (*OvnClient) GetLogFileEventStats

func (cli *OvnClient) GetLogFileEventStats(name string) (map[string]map[string]uint64, error)

GetLogFileEventStats TODO

func (*OvnClient) GetLogFileInfo

func (cli *OvnClient) GetLogFileInfo(name string) (OvsDataFile, error)

GetLogFileInfo TODO

func (*OvnClient) GetLogicalSwitchPorts

func (cli *OvnClient) GetLogicalSwitchPorts() ([]*OvnLogicalSwitchPort, error)

GetLogicalSwitchPorts returns a list of OVN logical switch ports.

func (*OvnClient) GetLogicalSwitches

func (cli *OvnClient) GetLogicalSwitches() ([]*OvnLogicalSwitch, error)

GetLogicalSwitches returns a list of OVN logical switches.

func (*OvnClient) GetProcessInfo

func (cli *OvnClient) GetProcessInfo(name string) (OvsProcess, error)

GetProcessInfo returns information about a service or database process.

func (*OvnClient) GetSystemID

func (cli *OvnClient) GetSystemID() error

GetSystemID TODO

func (*OvnClient) GetSystemInfo

func (cli *OvnClient) GetSystemInfo() error

GetSystemInfo returns a hash containing system information, e.g. `system_id` associated with the Open_vSwitch database.

func (*OvnClient) IsDefaultPortUp

func (cli *OvnClient) IsDefaultPortUp(db string) (int, error)

IsDefaultPortUp returns the TCP port used for database connection. If the value if greater than 0, then the port is in LISTEN state.

func (*OvnClient) IsRaftPortUp

func (cli *OvnClient) IsRaftPortUp(db string) (int, error)

IsRaftPortUp returns the TCP port used for clustering (raft). If the value if greater than 0, then the port is in LISTEN state.

func (*OvnClient) IsSslPortUp

func (cli *OvnClient) IsSslPortUp(db string) (int, error)

IsSslPortUp returns the TCP port used for secure database connection. If the value if greater than 0, then the port is in LISTEN state.

func (*OvnClient) MapPortToChassis

func (cli *OvnClient) MapPortToChassis(vteps []*OvnChassis, logicalSwitchPorts []*OvnLogicalSwitchPort)

MapPortToChassis updates logical switch ports with the entries from the chassis associated with the ports.

func (*OvnClient) MapPortToSwitch

func (cli *OvnClient) MapPortToSwitch(logicalSwitches []*OvnLogicalSwitch, logicalSwitchPorts []*OvnLogicalSwitchPort)

MapPortToSwitch update logical switch ports with the entries from the logical switches associated with the ports.

type OvnLogicalSwitch

type OvnLogicalSwitch struct {
	UUID        string `json:"uuid" yaml:"uuid"`
	Name        string `json:"name" yaml:"name"`
	TunnelKey   uint64 `json:"tunnel_key" yaml:"tunnel_key"`
	DatapathID  string
	ExternalIDs map[string]string
	Ports       []string `json:"ports" yaml:"ports"`
}

OvnLogicalSwitch holds basic information about a logical switch.

type OvnLogicalSwitchPort

type OvnLogicalSwitchPort struct {
	UUID              string
	Name              string
	MacAddress        net.HardwareAddr
	IPAddress         net.IP
	ExternalIDs       map[string]string
	Encapsulation     string
	TunnelKey         uint64
	Up                bool
	PortBindingUUID   string
	ChassisUUID       string
	ChassisIPAddress  net.IP
	DatapathUUID      string
	LogicalSwitchUUID string
	LogicalSwitchName string
}

OvnLogicalSwitchPort holds a consolidated record from both NB and SB databases about a logical switch port and the workload attached to it.

type OvsBridge

type OvsBridge struct {
	UUID                string
	Name                string
	AutoAttach          []string // TODO: unverified data type
	Controller          []string // TODO: unverified data type
	DatapathName        string   // reference from ovs-appctl dpif/show
	DatapathID          string
	DatapathType        string
	DatapathVersion     string
	ExternalIDs         map[string]string
	FailMode            string
	FloodVlans          []string          // TODO: unverified data type
	FlowTables          map[string]string // TODO: unverified data type
	Ipfix               []string          // TODO: unverified data type
	McastSnoopingEnable bool
	Mirrors             []string // TODO: unverified data type
	Netflow             []string // TODO: unverified data type
	OtherConfig         map[string]string
	Ports               []string
	Protocols           []string // TODO: unverified data type
	RstpEnable          bool
	RstpStatus          map[string]string // TODO: unverified data type
	Sflow               []string          // TODO: unverified data type
	Status              map[string]string // TODO: unverified data type
	StpEnable           bool
}

OvsBridge represents an OVS bridge. The data help by the data structure is the same as the output of `ovs-vsctl list Bridge` command.

type OvsClient

type OvsClient struct {
	Database struct {
		Vswitch OvsDatabase
	}
	Service struct {
		OvnController OvsDaemon
		Vswitchd      OvsDaemon
	}
	Timeout int
	System  struct {
		ID       string
		RunDir   string
		Hostname string
		Type     string
		Version  string
	}
}

OvsClient holds connection to OVS databases.

func NewOvsClient

func NewOvsClient() *OvsClient

NewOvsClient creates an instance of a client for OVS stack.

func (*OvsClient) AppListCommands

func (cli *OvsClient) AppListCommands(db string) (map[string]bool, error)

AppListCommands returns the list of commands supported by ovs-appctl tool and the database.

func (*OvsClient) Close

func (cli *OvsClient) Close()

Close closes connections to OVS database.

func (*OvsClient) Connect

func (cli *OvsClient) Connect() error

Connect initiates connections to OVS database.

func (*OvsClient) GetAppCoverageMetrics

func (cli *OvsClient) GetAppCoverageMetrics(db string) (map[string]map[string]float64, error)

GetAppCoverageMetrics returns the counters of the the number of times particular events occur during a daemon's runtime. The counters include averaged per-second rates for the last few seconds, the last minute and the last hour, and the total counts of all of the coverage counters.

func (*OvsClient) GetAppDatapath

func (cli *OvsClient) GetAppDatapath(db string) ([]*OvsDatapath, []*OvsBridge, []*OvsInterface, error)

GetAppDatapath returns the information about available datapaths.

func (*OvsClient) GetAppMemoryMetrics

func (cli *OvsClient) GetAppMemoryMetrics(db string) (map[string]float64, error)

GetAppMemoryMetrics returns memory usage counters.

func (*OvsClient) GetDbInterfaces

func (cli *OvsClient) GetDbInterfaces() ([]*OvsInterface, error)

GetDbInterfaces returns a list of interfaces from the Interface table of OVS database.

func (*OvsClient) GetLogFileEventStats

func (cli *OvsClient) GetLogFileEventStats(name string) (map[string]map[string]uint64, error)

GetLogFileEventStats TODO

func (*OvsClient) GetLogFileInfo

func (cli *OvsClient) GetLogFileInfo(name string) (OvsDataFile, error)

GetLogFileInfo TODO

func (*OvsClient) GetOvsFlows

func (cli *OvsClient) GetOvsFlows() ([]*OvsFlow, error)

GetOvsFlows returns a list of datapath flows of an OVS instance.

func (*OvsClient) GetProcessInfo

func (cli *OvsClient) GetProcessInfo(name string) (OvsProcess, error)

GetProcessInfo returns information about a service or database process.

func (*OvsClient) GetSystemID

func (cli *OvsClient) GetSystemID() error

GetSystemID TODO

func (*OvsClient) GetSystemInfo

func (cli *OvsClient) GetSystemInfo() error

GetSystemInfo returns a hash containing system information, e.g. `system_id` associated with the Open_vSwitch database.

func (*OvsClient) GetTunnels

func (cli *OvsClient) GetTunnels() ([]*OvsTunnel, error)

GetTunnels returns a list of tunnels originating from an OVS instance.

func (*OvsClient) IsDefaultPortUp

func (cli *OvsClient) IsDefaultPortUp(db string) (int, error)

IsDefaultPortUp returns the TCP port used for database connection. If the value if greater than 0, then the port is in LISTEN state.

func (*OvsClient) IsSslPortUp

func (cli *OvsClient) IsSslPortUp(db string) (int, error)

IsSslPortUp returns the TCP port used for secure database connection. If the value if greater than 0, then the port is in LISTEN state.

type OvsDaemon

type OvsDaemon struct {
	File struct {
		Log OvsDataFile
		Pid OvsDataFile
	}
	Process OvsProcess
	Socket  struct {
		Control string
	}
}

OvsDaemon stores information about a process or database, together with associated log and process id files.

type OvsDataFile

type OvsDataFile struct {
	Path      string
	Component string
	Info      os.FileInfo
	Reader    struct {
		Offset int64
	}
}

OvsDataFile stores information about the files related to OVS operations, e.g. log files, database files, etc.

type OvsDatabase

type OvsDatabase struct {
	Client *Client
	Name   string
	Socket struct {
		Remote  string
		Control string
		Raft    string
	}
	Port struct {
		Default int
		Ssl     int
		Raft    int
	}
	File struct {
		Log      OvsDataFile
		Data     OvsDataFile
		Pid      OvsDataFile
		SystemID OvsDataFile
	}
	Process OvsProcess
	Version string
	Schema  struct {
		Version string
	}
	// contains filtered or unexported fields
}

OvsDatabase represents an instance of OVS DB.

type OvsDatapath

type OvsDatapath struct {
	Name    string
	Lookups struct {
		Hit    float64
		Missed float64
		Lost   float64
	}
	Flows float64
	Masks struct {
		Hit      float64
		Total    float64
		HitRatio float64
	}
}

OvsDatapath represents an OVS datapath. A datapath is a collection of the ports attached to bridges. Each datapath also has associated with it a flow table that userspace populates with flows that map from keys based on packet headers and metadata to sets of actions. Importantly, a datapath is a userspace concept.

type OvsFlow

type OvsFlow struct {
	EthType    string
	Statistics struct {
		Packets float64
		Bytes   float64
		Used    float64
	}
	Flags string
	Raw   string
}

OvsFlow is a datapath flow.

func NewOvsFlowFromString

func NewOvsFlowFromString(line string) (*OvsFlow, error)

NewOvsFlowFromString retuns OvsFlow instance from an input string.

type OvsInterface

type OvsInterface struct {
	UUID                 string
	Name                 string
	Index                float64 // reference from ovs-appctl dpif/show, e.g. OVN `tunnel_key`
	BridgeName           string  // reference to datapath from ovs-appctl dpif/show
	DatapathName         string  // reference to datapath from ovs-appctl dpif/show
	AdminState           string
	Bfd                  map[string]string // TODO: unverified data type
	BfdStatus            map[string]string // TODO: unverified data type
	CfmFault             []string          // TODO: unverified data type
	CfmFaultStatus       []string          // TODO: unverified data type
	CfmFlapCount         []string          // TODO: unverified data type
	CfmHealth            []string          // TODO: unverified data type
	CfmMpid              []string          // TODO: unverified data type
	CfmRemoteMpids       []string          // TODO: unverified data type
	CfmRemoteOpState     []string          // TODO: unverified data type
	Duplex               string
	Error                []string // TODO: unverified data type
	ExternalIDs          map[string]string
	IfIndex              float64
	IngressPolicingBurst float64
	IngressPolicingRate  float64
	LacpCurrent          []string // TODO: unverified data type
	LinkResets           float64
	LinkSpeed            float64
	LinkState            string
	Lldp                 map[string]string // TODO: unverified data type
	Mac                  []string          // TODO: unverified data type
	MacInUse             string            // TODO: unverified data type
	Mtu                  float64
	MtuRequest           []string // TODO: unverified data type
	OfPort               float64
	OfPortRequest        []string // TODO: unverified data type
	Options              map[string]string
	OtherConfig          map[string]string // TODO: unverified data type
	Statistics           map[string]int
	Status               map[string]string
	Type                 string
}

OvsInterface represents an OVS interface. The data help by the data structure is the same as the output of `ovs-vsctl list Interface` command.

Reference: http://www.openvswitch.org/support/dist-docs/ovs-vswitchd.conf.db.5.html

type OvsPort

type OvsPort struct {
	UUID            string
	Name            string
	BondActiveSlave []string // TODO: unverified data type
	BondDowndelay   float64
	BondFakeIface   bool
	BondMode        []string // TODO: unverified data type
	BondUpdelay     float64
	Cvlans          []string // TODO: unverified data type
	ExternalIDs     map[string]string
	FakeBridge      bool
	Interfaces      []string
	Lacp            []string          // TODO: unverified data type
	Mac             []string          // TODO: unverified data type
	OtherConfig     map[string]string // TODO: unverified data type
	Protected       bool
	Qos             []string           // TODO: unverified data type
	RstpStatistics  map[string]float64 // TODO: unverified data type
	RstpStatus      map[string]string  // TODO: unverified data type
	Statistics      map[string]float64 // TODO: unverified data type
	Status          map[string]string  // TODO: unverified data type
	Tag             []string           // TODO: unverified data type
	Trunks          []string           // TODO: unverified data type
	VlanMode        []string           // TODO: unverified data type
}

OvsPort represents an OVS bridge. The data help by the data structure is the same as the output of `ovs-vsctl list Port` command.

type OvsProcess

type OvsProcess struct {
	ID     int
	User   string
	Group  string
	Parent struct {
		ID int
	}
}

OvsProcess stores information about a process, e.g. user and group, current parent process ids.

type OvsTunnel

type OvsTunnel struct {
	Name          string
	Encapsulation string
	ID            uint64
	Key           string
	PacketType    string
	TTL           uint64
	Checksum      bool
	RemoteIP      string
	LocalIP       string
	InKey         string
	OutKey        string
	DstPort       string
	Tos           string
	DfDefault     bool
	EgressPktMark string
	Extensions    string
	Raw           string
}

OvsTunnel is a remote tunnel endpoint.

func NewOvsTunnelFromString

func NewOvsTunnelFromString(line string) (*OvsTunnel, error)

NewOvsTunnelFromString retuns OvsTunnel instance from an input string.

type Request

type Request struct {
	Method string
	Params interface{}
}

Request - TODO

type Response

type Response struct {
	Result json.RawMessage `json:"result"`
	Error
	Seq uint64 `json:"id"`
}

Response - TODO

func (*Response) Databases

func (r *Response) Databases() ([]string, error)

Databases - TODO

func (*Response) GetSchema

func (r *Response) GetSchema() (Schema, error)

GetSchema TODO

func (*Response) String

func (r *Response) String() string

String() returns response payload as a string.

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(b []byte) error

UnmarshalJSON - TODO

type Result

type Result struct {
	Rows     []Row `json:"rows"`
	Database string
	Table    string
	Columns  map[string]string
}

Result - TODO

type RouteFilter

type RouteFilter struct {
	Entries []*RouteFilterEntry
}

RouteFilter TODO

func NewRouteFilter

func NewRouteFilter(networks []string) (*RouteFilter, error)

NewRouteFilter TODO

func NewRouteFilterExcludeGateway

func NewRouteFilterExcludeGateway(networks []string) (*RouteFilter, error)

NewRouteFilterExcludeGateway TODO

func (*RouteFilter) Add

func (rf *RouteFilter) Add(network string) error

Add TODO

func (*RouteFilter) Match

func (rf *RouteFilter) Match(ip net.IP) bool

Match TODO

type RouteFilterEntry

type RouteFilterEntry struct {
	Network    *net.IPNet
	Exclusions []*net.IPNet
}

RouteFilterEntry TODO

func NewRouteFilterEntry

func NewRouteFilterEntry(network string, excludeGateway bool) (*RouteFilterEntry, error)

NewRouteFilterEntry TODO

func (*RouteFilterEntry) Match

func (entry *RouteFilterEntry) Match(ip net.IP) bool

Match TODO

type Row

type Row map[string]interface{}

Row - TODO

func (*Row) GetColumnValue

func (r *Row) GetColumnValue(column string, columns map[string]string) (interface{}, string, error)

GetColumnValue - TODO

type Schema

type Schema struct {
	Tables   map[string]Table `json:"tables"`
	Checksum string           `json:"cksum"`
	Name     string           `json:"name"`
	Version  string           `json:"version"`
}

Schema - TODO

func (*Schema) GetColumnType

func (sc *Schema) GetColumnType(table, column string) (string, error)

GetColumnType - TODO

func (*Schema) GetColumns

func (sc *Schema) GetColumns(s string) []string

GetColumns - TODO

func (*Schema) GetColumnsTypes

func (sc *Schema) GetColumnsTypes(table string) (map[string]string, error)

GetColumnsTypes - TODO

func (*Schema) GetTables

func (sc *Schema) GetTables() []string

GetTables - TODO

type Table

type Table struct {
	Columns map[string]Column `json:"columns"`
	Indexes []interface{}     `json:"indexes"`
	MaxRows int               `json:"maxRows"`
	IsRoot  bool              `json:"isRoot"`
}

Table - TODO

type Transaction

type Transaction struct {
	Database   string
	Operations []Operation
}

Transaction - TODO

func (*Transaction) ToBytes

func (t *Transaction) ToBytes() ([]byte, int, error)

ToBytes - TODO

func (*Transaction) ToString

func (t *Transaction) ToString() (string, error)

ToString - TODO

Jump to

Keyboard shortcuts

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