Documentation
¶
Overview ¶
Package ofclient implements a minimal OpenFlow 1.3 client over a Unix socket. Supports: Hello handshake, PORT_DESC multipart for name→number resolution, FLOW_MOD add and delete with OXM_OF_IN_PORT and OXM_OF_TUNNEL_ID fields, and automatic OFPT_ECHO_REPLY to keep the OVS connection alive.
Index ¶
- Constants
- func BuildActionsOutput(portNo uint32) []byte
- func BuildActionsRegMove(nBits, srcOfs, dstOfs uint16, srcOXMID, dstOXMID uint32) []byte
- func BuildActionsResubmitTable(tableID uint8) []byte
- func BuildActionsSetFieldTunnelID(vni uint64) []byte
- func BuildActionsSetMetadata(value uint64) []byte
- func BuildActionsSetReg0(value uint32) []byte
- func BuildActionsSetTunDst(ipBE uint32) []byte
- func BuildMatch(inPortNo uint32, vni uint64, hasTunnel bool) []byte
- func BuildMatchAdvanced(inPort uint32, metadata uint64, hasMetadata bool, reg0 uint32, hasReg0 bool, ...) []byte
- func BuildMatchTunSrc(inPortNo uint32, ip uint32) []byte
- func OxmIDInPort() uint32
- func OxmIDMetadata() uint32
- func OxmIDReg0() uint32
- func OxmIDReg1() uint32
- func OxmIDTunIPv4Dst() uint32
- func OxmIDTunIPv4Src() uint32
- func OxmIDTunnelID() uint32
- func OxmInPort(portNo uint32) []byte
- func OxmMetadata(value uint64) []byte
- func OxmReg0(value uint32) []byte
- func OxmReg1(value uint32) []byte
- func OxmTunIPv4Dst(ip uint32) []byte
- func OxmTunIPv4Src(ip uint32) []byte
- func OxmTunnelID(vni uint64) []byte
- func StalePortNumbers(before, after map[string]uint32) []uint32
- type Client
- func (c *Client) Close() error
- func (c *Client) FlowAdd(tableID uint8, priority uint16, match, actions []byte) error
- func (c *Client) FlowDelete(tableID uint8, match []byte) error
- func (c *Client) FlowDeleteOutPort(portNo uint32) error
- func (c *Client) FlowDeleteStrict(tableID uint8, priority uint16, match []byte) error
- func (c *Client) FlowDeleteTable(tableID uint8) error
- func (c *Client) PortNo(name string) (uint32, error)
- func (c *Client) Ports() map[string]uint32
- func (c *Client) RefreshPorts() error
- func (c *Client) SetErrorHandler(h func(xid uint32, errType, errCode uint16))
Constants ¶
const NxVendorID = 0x00002320
NxVendorID is the experimenter ID assigned to the Nicira-extension family.
Variables ¶
This section is empty.
Functions ¶
func BuildActionsOutput ¶
BuildActionsOutput encodes a single OFPAT_OUTPUT action (16 bytes).
func BuildActionsRegMove ¶
BuildActionsRegMove encodes NXAST_REG_MOVE: copy `nBits` bits starting at srcOfs of srcOXM into dstOfs of dstOXM. OXM IDs are 4-byte headers (no value).
Wire format: OFPAT_EXPERIMENTER/24 + vendor(4) + subtype(2) + n_bits(2) + src_ofs(2) + dst_ofs(2) + src_oxm_id(4) + dst_oxm_id(4) = 24 bytes.
func BuildActionsResubmitTable ¶
BuildActionsResubmitTable encodes NXAST_RESUBMIT_TABLE: re-run lookup in table `tableID` with the original in_port. Spec §7 uses this between pipeline stages (resubmit(,1), resubmit(,3), resubmit(,5), resubmit(,6)).
Wire format: OFPAT_EXPERIMENTER(0xffff)/16 + vendor(4) + subtype(2) + in_port(2) + table_id(1) + pad(3) = 16 bytes.
func BuildActionsSetFieldTunnelID ¶
BuildActionsSetFieldTunnelID encodes OFPAT_SET_FIELD for tunnel_id=vni (16 bytes).
func BuildActionsSetMetadata ¶
BuildActionsSetMetadata encodes OFPAT_SET_FIELD for OXM_OF_METADATA. 4-byte action header + 4 OXM hdr + 8 value = 16 bytes (already 8-aligned).
func BuildActionsSetReg0 ¶
BuildActionsSetReg0 encodes OFPAT_SET_FIELD for NXM_NX_REG0. 4-byte action header + 4 OXM hdr + 4 value = 12 bytes; pad to 16 (8-aligned). Used in t0 to mark packet origin: 0 = local port, 1 = arrived from Geneve.
func BuildActionsSetTunDst ¶
BuildActionsSetTunDst encodes OFPAT_SET_FIELD for NXM_NX_TUN_IPV4_DST. 4-byte action header + 4 OXM hdr + 4 IP = 12 bytes; pad to 16 (8-aligned).
func BuildMatch ¶
BuildMatch builds an ofp_match (OXM type) for in_port and optionally tunnel_id. Result is padded to a multiple of 8 bytes.
func BuildMatchAdvanced ¶
func BuildMatchAdvanced( inPort uint32, metadata uint64, hasMetadata bool, reg0 uint32, hasReg0 bool, reg1 uint32, hasReg1 bool, tunID uint64, hasTunID bool, ) []byte
BuildMatchAdvanced extends BuildMatch with metadata + reg0 + reg1 matches. Any zero-value parameter (matchMetadata=false / hasReg0=false / hasReg1=false) is omitted. inPort=0 means no in_port match.
func BuildMatchTunSrc ¶
BuildMatchTunSrc is BuildMatch with the tunnel source address (NXM_NX_TUN_IPV4_SRC) added: in_port plus the IPv4 source of the outer header of a tunnelled packet. ip is the address in host byte order (as OxmTunIPv4Src takes it).
func OxmIDMetadata ¶
func OxmIDMetadata() uint32
OxmIDMetadata is the 4-byte header for OXM_OF_METADATA (field 2).
func OxmIDTunIPv4Dst ¶
func OxmIDTunIPv4Dst() uint32
OxmIDTunIPv4Dst is the 4-byte header for NXM_NX_TUN_IPV4_DST.
func OxmIDTunIPv4Src ¶
func OxmIDTunIPv4Src() uint32
OxmIDTunIPv4Src is the 4-byte header for NXM_NX_TUN_IPV4_SRC.
func OxmIDTunnelID ¶
func OxmIDTunnelID() uint32
OxmIDTunnelID is the 4-byte header for OXM_OF_TUNNEL_ID.
func OxmInPort ¶
OxmInPort encodes OXM_OF_IN_PORT (class=0x8000, field=0, length=4). Returns 8 bytes: 4-byte header + 4-byte value.
func OxmMetadata ¶
OxmMetadata encodes OXM_OF_METADATA (class=0x8000, field=2, 8 bytes). Used as the canonical VNI carrier across the pipeline. Field code 2 is OFPXMT_OFB_METADATA; field 4 is ETH_SRC and made OVS reject the FLOW_MOD.
func OxmTunIPv4Dst ¶
OxmTunIPv4Dst encodes NXM_NX_TUN_IPV4_DST (class=0x0001, field=32, 4 bytes).
func OxmTunIPv4Src ¶
OxmTunIPv4Src encodes NXM_NX_TUN_IPV4_SRC (class=0x0001, field=31, 4 bytes).
func OxmTunnelID ¶
OxmTunnelID encodes OXM_OF_TUNNEL_ID (class=0x8000, field=38, length=8). Returns 12 bytes: 4-byte header + 8-byte value.
func StalePortNumbers ¶
StalePortNumbers lists the port numbers that were in use before a refresh and are not the same port after it: the port is gone, or the number now belongs to another name. Flows that name such a number must be removed before the number is used again.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a minimal OpenFlow 1.3 client connected to an OVS bridge management socket. A background goroutine reads all incoming messages, replies to OFPT_ECHO_REQUEST automatically, and dispatches PORT_DESC replies to a waiting queryPortDesc call.
func Connect ¶
Connect connects to the OVS bridge management socket and performs the OF 1.3 handshake. sockPath is e.g. "/run/openvswitch/br-ovs.mgmt". Retries for up to 30 seconds (socket appears after vswitchd creates the bridge).
func (*Client) FlowAdd ¶
FlowAdd sends an OFPT_FLOW_MOD OFPFC_ADD for a flow with the given match and actions.
func (*Client) FlowDelete ¶
FlowDelete sends an OFPT_FLOW_MOD OFPFC_DELETE (non-strict) for a flow matching match.
func (*Client) FlowDeleteOutPort ¶
FlowDeleteOutPort deletes the flows of every table that output to the port number.
func (*Client) FlowDeleteStrict ¶
FlowDeleteStrict deletes the one flow with exactly this match and priority.
func (*Client) FlowDeleteTable ¶
FlowDeleteTable deletes every flow of a table.
func (*Client) PortNo ¶
PortNo returns the OpenFlow port number for a named port, or error if unknown.
func (*Client) Ports ¶
Ports returns a copy of the port map (name to number) as of the last refresh.
func (*Client) RefreshPorts ¶
RefreshPorts re-sends PORT_DESC multipart and updates the portMap.
func (*Client) SetErrorHandler ¶
SetErrorHandler registers a callback for asynchronous OFPT_ERROR messages (rejected FLOW_MODs, etc.). Must be set before flows are programmed.