ipv4net

package
v2.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package ipv4net configures VPP-based IPv4 network connectivity between Kubernetes pods and nodes.

TODO: cleanup config The plugin is configurable via its config file that can be specified using `-contiv-config="<path to config>` argument when running the contiv-agent. This is usually being injected into the vswitch POD by a config map inside of the k8s deployment file of the contiv-VPP k8s networking plugin (see contiv-agent-cfg ConfigMap in ../../k8s/contiv-vpp.yaml).

Based on the configuration, the plugin can wire PODs in 2 different ways:

1. VETH-based pod-VPP connectivity (default)

Each POD is wired to VPP using a virtual ethernet interface pair, where one end is connected to VPP using AF_PACKET interface and the other end is placed into the POD's network namespace:

+-------------------------------------------------+ | vSwitch VPP host.go | +--------------+ | +--------------+ | | VETH VPP |____________| VETH Host | | routing | | | | | | +--------------+ | +--------------+ | +------+ +------+ | | | AF1 | | AFn | | | | | ... | | | | +------+ +------+ | | ^ | | | | +------|------------------------------------------+

    v
+------------+
|            |
| VETH1-VPP  |
|            |
+------------+
    ^
    |              pod.go

+------|------------+ | NS1 v | | +------------+ | | | | | | | VETH1-POD | | | | | | | +------------+ | | | +-------------------+

2. TAP-based pod-VPP connectivity

Each POD is wired to VPP using a TAP interface created on VPP. Can be turned on by setting the UseTAPInterfaces: True in the config file. Legacy and the new virtio-based TAP interfaces are supported, the latter can be turned on by setting the TAPInterfaceVersion: 2.

+-------------------------------------------------+ | vSwitch VPP host.go | +--------------+ | +--------------+ | | VETH VPP |____________| VETH Host | | routing | | | | | | +--------------+ | +--------------+ | +-------+ +-------+ | | | TAP1 | | TAPn | | | | | ... | | | | +-------+ +-------+ | | ^ | | | | +------|------------------------------------------+

|
|              pod.go

+------|------------+ | NS1 v | | +------------+ | | | | | | | TAP1-POD | | | | | | | +------------+ | | | +-------------------+

Plugin Structure ================

The plugin consists of these components:

  1. Plugin base: - plugin_*.go: plugin definition and setup - node_events.go: handler of changes in nodes within the k8s cluster (node add / delete)

  2. Remote CNI Server - the main logic of the plugin that is in charge of wiring the PODs.

  3. Node ID Allocator - manages allocation/deallocation of unique number identifying a node within the k8s cluster. Allocated identifier is used as an input of the IPAM calculations.

  4. IPAM module (separate package, described in its own doc.go) - provides node-local IP address assignments.

  5. Helper functions: - host.go: provides host-related helper functions and VPP-Agent NB API builders - pod.go: provides POD-related helper functions and VPP-Agent NB API builders

Additionally, the package provides REST endpoint for getting some of the IPAM-related information for the node on the URL: GET /contiv/v1/ipam.

Example:

$ curl localhost:9999/contiv/v1/ipam
{
  "nodeId": 1,
  "nodeName": "vagrant-arch.vagrantup.com",
  "nodeIP": "192.168.16.1",
  "podSubnetThisNode": "10.1.1.0/24",
  "vppHostNetwork": "172.30.1.0/24"
}

Index

Constants

View Source
const (

	// HostInterconnectTAPinVPPLogicalName is the logical name of the TAP interface
	// connecting host stack with VPP
	//  - VPP side
	HostInterconnectTAPinVPPLogicalName = "tap-vpp2"

	// HostInterconnectTAPinLinuxLogicalName is the logical name of the TAP interface
	// connecting host stack with VPP
	//  - Linux side
	HostInterconnectTAPinLinuxLogicalName = "tap-vpp1"

	// HostInterconnectTAPinLinuxHostName is the physical name of the TAP interface
	// connecting host stack with VPP
	//  - the Linux side
	HostInterconnectTAPinLinuxHostName = "vpp1"
)

VPP - Host interconnect

View Source
const (
	// Prefix is versioned prefix for REST urls
	Prefix = "/contiv/v1/"
	// PluginURL is versioned URL (using prefix) for IPAM REST endpoint
	PluginURL = Prefix + "ipam"
)
View Source
const (

	// VxlanBVIInterfaceName is the name of the VXLAN BVI interface.
	VxlanBVIInterfaceName = "vxlanBVI"
)

VXLANs

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of IPv4Net.

Functions

This section is empty.

Types

type API

type API interface {
	// GetIfName looks up logical interface name that corresponds to the interface
	// associated with the given pod.
	GetIfName(podNamespace string, podName string) (name string, exists bool)

	// GetPodByIf looks up podName and podNamespace that is associated with logical interface name.
	// The method can be called from outside of the main event loop.
	GetPodByIf(ifname string) (podNamespace string, podName string, exists bool)

	// GetNodeIP returns the IP+network address of this node.
	GetNodeIP() (ip net.IP, network *net.IPNet)

	// GetHostIPs returns all IP addresses of this node present in the host network namespace (Linux).
	GetHostIPs() []net.IP

	// GetHostInterconnectIfName returns the name of the TAP/AF_PACKET interface
	// interconnecting VPP with the host stack.
	GetHostInterconnectIfName() string

	// GetVxlanBVIIfName returns the name of an BVI interface facing towards VXLAN tunnels to other hosts.
	// Returns an empty string if VXLAN is not used (in L2 interconnect mode).
	GetVxlanBVIIfName() string
}

API defines methods provided by IPv4Net plugin for use by other plugins to query IPv4 network-related information. Apart from GetPodByIf, these methods should not be accessed from outside of the main event loop!

type Deps

type Deps struct {
	infra.PluginDeps
	EventLoop    controller.EventLoop
	ServiceLabel servicelabel.ReaderAPI
	ContivConf   contivconf.API
	IPAM         ipam.API
	NodeSync     nodesync.API
	PodManager   podmanager.API
	VPPIfPlugin  vpp_ifplugin.API
	GoVPP        GoVPP
	HTTPHandlers rest.HTTPHandlers
}

Deps groups the dependencies of the plugin.

type GoVPP

type GoVPP interface {
	// NewAPIChannel returns a new API channel for communication with VPP via govpp.
	NewAPIChannel() (govpp.Channel, error)

	// NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp.
	NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (govpp.Channel, error)
}

GoVPP is the interface of govppmux plugin replicated here to avoid direct dependency on vppapiclient.h for other plugins that import ipv4net just to read some constants etc.

type HostLinkIPsDumpClb

type HostLinkIPsDumpClb func() ([]net.IP, error)

HostLinkIPsDumpClb is callback for dumping all IP addresses assigned to interfaces in the host stack.

type IPAMData

type IPAMData struct {
	NodeID            uint32                        `json:"nodeId"`
	NodeName          string                        `json:"nodeName"`
	NodeIP            string                        `json:"nodeIP"`
	PodSubnetThisNode string                        `json:"podSubnetThisNode"`
	VppHostNetwork    string                        `json:"vppHostNetwork"`
	Config            *contivconf.IPAMConfigForJSON `json:"config"`
}

IPAMData defines attributes exposed by the IPAM REST handler.

type IPv4Net

type IPv4Net struct {
	Deps
	// contains filtered or unexported fields
}

IPv4Net plugin builds configuration to be applied by ligato/VPP-agent for VPP-based IPv4 network connectivity between Kubernetes pods and nodes.

func NewPlugin

func NewPlugin(opts ...Option) *IPv4Net

NewPlugin creates a new Plugin with the provides Options

func (*IPv4Net) Close

func (n *IPv4Net) Close() error

Close is called by the plugin infra upon agent cleanup. It cleans up the resources allocated by the plugin.

func (*IPv4Net) GetHostIPs

func (n *IPv4Net) GetHostIPs() []net.IP

GetHostIPs returns all IP addresses of this node present in the host network namespace (Linux).

func (*IPv4Net) GetHostInterconnectIfName

func (n *IPv4Net) GetHostInterconnectIfName() string

GetHostInterconnectIfName returns the name of the TAP/AF_PACKET interface interconnecting VPP with the host stack.

func (*IPv4Net) GetIfName

func (n *IPv4Net) GetIfName(podNamespace string, podName string) (name string, exists bool)

GetIfName looks up logical interface name that corresponds to the interface associated with the given POD name.

func (*IPv4Net) GetNodeIP

func (n *IPv4Net) GetNodeIP() (ip net.IP, network *net.IPNet)

GetNodeIP returns the IP address of this node.

func (*IPv4Net) GetPodByIf

func (n *IPv4Net) GetPodByIf(ifName string) (podNamespace string, podName string, exists bool)

GetPodByIf looks up podName and podNamespace that is associated with logical interface name. The method can be called from outside of the main event loop.

func (*IPv4Net) GetVxlanBVIIfName

func (n *IPv4Net) GetVxlanBVIIfName() string

GetVxlanBVIIfName returns the name of an BVI interface facing towards VXLAN tunnels to other hosts. Returns an empty string if VXLAN is not used (in L2 interconnect mode).

func (*IPv4Net) HandlesEvent

func (n *IPv4Net) HandlesEvent(event controller.Event) bool

HandlesEvent selects:

  • any Resync event (extra action for NodeIPv4Change)
  • AddPod and DeletePod
  • NodeUpdate for other nodes
  • Shutdown event

func (*IPv4Net) Init

func (n *IPv4Net) Init() error

Init initializes attributes/callbacks used to access the plugin-external state. Internal state is initialized later by the first resync.

func (*IPv4Net) Resync

func (n *IPv4Net) Resync(event controller.Event, kubeStateData controller.KubeStateData,
	resyncCount int, txn controller.ResyncOperations) error

Resync is called by Controller to handle event that requires full re-synchronization. For startup resync, resyncCount is 1. Higher counter values identify run-time resync.

func (*IPv4Net) Revert

func (n *IPv4Net) Revert(event controller.Event) error

Revert is called for AddPod.

func (IPv4Net) StateToString

func (s IPv4Net) StateToString() string

StateToString returns human-readable string representation of the ipv4net plugin internal state. The method cannot be called String(), otherwise it overloads the Stringer from PluginDeps.

func (*IPv4Net) Update

func (n *IPv4Net) Update(event controller.Event, txn controller.UpdateOperations) (change string, err error)

Update is called for:

  • AddPod and DeletePod
  • NodeUpdate for other nodes
  • Shutdown event

type NodeIPv4Change

type NodeIPv4Change struct {
	NodeIP    net.IP
	NodeIPNet *net.IPNet
	DefaultGw net.IP
}

NodeIPv4Change is triggered when DHCP-assigned IPv4 address of the node changes.

func (*NodeIPv4Change) Done

func (ev *NodeIPv4Change) Done(error)

Done is NOOP.

func (*NodeIPv4Change) GetName

func (ev *NodeIPv4Change) GetName() string

GetName returns name of the NodeIPv4Change event.

func (*NodeIPv4Change) IsBlocking

func (ev *NodeIPv4Change) IsBlocking() bool

IsBlocking returns false.

func (*NodeIPv4Change) Method

Method is UpstreamResync.

func (*NodeIPv4Change) String

func (ev *NodeIPv4Change) String() string

String describes NodeIPv4Change event.

type Option

type Option func(*IPv4Net)

Option is a function that acts on a Plugin to inject Dependencies or configuration

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

Jump to

Keyboard shortcuts

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