ipnet

package
v0.0.0-...-2d08fe4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Overview

Package ipnet 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 (

	// DefaultVxlanBVIInterfaceName name of the VXLAN interface for the default pod network.
	DefaultVxlanBVIInterfaceName = vxlanBVIInterfacePrefix

	// VxlanVniPoolName is name for the ID pool of VXLAN VNIs
	VxlanVniPoolName = "vni"
)

VXLANs

View Source
const (

	// DefaultPodNetworkName is the network name dedicated to the default pod network
	DefaultPodNetworkName = "default"
)

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of IPNet.

Functions

This section is empty.

Types

type API

type API interface {
	// GetPodIfNames looks up logical interface names that correspond to the interfaces
	// associated with the given local pod name + namespace.
	GetPodIfNames(podNamespace string, podName string) (vppIfName, linuxIfName, loopIfName string, exists bool)

	// GetPodCustomIfNames looks up logical interface name that corresponds to the custom interface
	// with specified name and type associated with the given local pod name + namespace.
	GetPodCustomIfNames(podNamespace, podName, customIfName string) (ifName string, linuxIfName string, exists bool)

	// GetExternalIfName returns logical name that corresponds to the specified external interface name and VLAN ID.
	GetExternalIfName(extIfName string, vlan uint32) (ifName string)

	// GetPodCustomIfNetworkName returns the name of custom network which should contain given
	// pod custom interface or error otherwise. This supports both type of pods, remote and local
	GetPodCustomIfNetworkName(podID podmodel.ID, ifName string) (string, error)

	// GetExternalIfNetworkName returns the name of custom network which should contain given
	// external interface or error otherwise.
	GetExternalIfNetworkName(ifName string) (string, error)

	// GetPodByIf looks up name and namespace 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 no-overlay interconnect mode).
	GetVxlanBVIIfName() string

	// GetOrAllocateVxlanVNI returns the allocated VXLAN VNI number for the given network.
	// Allocates a new VNI if not already allocated.
	GetOrAllocateVxlanVNI(networkName string) (vni uint32, err error)

	// ReleaseVxlanVNI releases the allocated VXLAN VNI number for the given network.
	ReleaseVxlanVNI(networkName string) (err error)

	// GetOrAllocateVrfID returns the allocated VRF ID number for the given network.
	// Allocates a new VRF ID if not already allocated.
	GetOrAllocateVrfID(networkName string) (vrf uint32, err error)

	// ReleaseVrfID releases the allocated VRF ID number for the given network.
	ReleaseVrfID(networkName string) (err error)
}

API defines methods provided by IPNet 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
	IDAlloc       idalloc.API
	IPAM          ipam.API
	NodeSync      nodesync.API
	PodManager    podmanager.API
	DeviceManager devicemanager.API
	VPPIfPlugin   vpp_ifplugin.API
	LinuxNsPlugin linux_nsplugin.API
	GoVPP         GoVPP
	HTTPHandlers  rest.HTTPHandlers
	RemoteDB      nodesync.KVDBWithAtomic
}

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 ipnet 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 IPNet

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

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

func NewPlugin

func NewPlugin(opts ...Option) *IPNet

NewPlugin creates a new Plugin with the provides Options

func (*IPNet) Close

func (n *IPNet) Close() error

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

func (*IPNet) DescribeInternalData

func (n *IPNet) DescribeInternalData() string

DescribeInternalData describes the internal state of IPNet plugin. Used for Verification Resync.

func (*IPNet) GetExternalIfName

func (n *IPNet) GetExternalIfName(extIfName string, vlan uint32) (ifName string)

GetExternalIfName returns logical name that corresponds to the specified external interface name and VLAN ID.

func (*IPNet) GetExternalIfNetworkName

func (n *IPNet) GetExternalIfNetworkName(ifName string) (string, error)

GetExternalIfNetworkName returns the name of custom network which should contain given external interface or error otherwise.

func (*IPNet) GetHostIPs

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

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

func (*IPNet) GetHostInterconnectIfName

func (n *IPNet) GetHostInterconnectIfName() string

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

func (*IPNet) GetNodeIP

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

GetNodeIP returns the IP address of this node.

func (*IPNet) GetOrAllocateVrfID

func (n *IPNet) GetOrAllocateVrfID(networkName string) (vrf uint32, err error)

GetOrAllocateVrfID returns the allocated VRF ID number for the given network. Allocates a new VRF ID if not already allocated.

func (*IPNet) GetOrAllocateVxlanVNI

func (n *IPNet) GetOrAllocateVxlanVNI(networkName string) (vni uint32, err error)

GetOrAllocateVxlanVNI returns the allocated VXLAN VNI number for the given network. Allocates a new VNI if not already allocated.

func (*IPNet) GetPodByIf

func (n *IPNet) 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 (*IPNet) GetPodCustomIfNames

func (n *IPNet) GetPodCustomIfNames(podNamespace, podName, customIfName string) (ifName string, linuxIfName string,
	exists bool)

GetPodCustomIfNames looks up logical interface name that corresponds to the custom interface with specified name and type associated with the given local pod name + namespace.

func (*IPNet) GetPodCustomIfNetworkName

func (n *IPNet) GetPodCustomIfNetworkName(podID podmodel.ID, ifName string) (string, error)

GetPodCustomIfNetworkName returns the name of custom network which should contain given pod custom interface or error otherwise. This supports both type of pods, remote and local

func (*IPNet) GetPodIfNames

func (n *IPNet) GetPodIfNames(podNamespace string, podName string) (vppIfName, linuxIfName, loopIfName string,
	exists bool)

GetPodIfNames looks up logical interface names that correspond to the interfaces associated with the given local pod name + namespace.

func (*IPNet) GetVxlanBVIIfName

func (n *IPNet) 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 no overlay mode).

func (*IPNet) HandlesEvent

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

HandlesEvent selects:

  • any Resync event (extra action for NodeIPv4Change)
  • AddPod and DeletePod (CNI)
  • POD k8s state changes
  • POD custom interfaces update
  • custom network update
  • external interfaces update
  • NodeUpdate for other nodes
  • Shutdown event

func (*IPNet) Init

func (n *IPNet) Init() error

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

func (*IPNet) ReleaseVrfID

func (n *IPNet) ReleaseVrfID(networkName string) (err error)

ReleaseVrfID releases the allocated VRF ID number for the given network.

func (*IPNet) ReleaseVxlanVNI

func (n *IPNet) ReleaseVxlanVNI(networkName string) (err error)

ReleaseVxlanVNI releases the allocated VXLAN VNI number for the given network.

func (*IPNet) Resync

func (n *IPNet) 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 (*IPNet) Revert

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

Revert is called for AddPod.

func (IPNet) StateToString

func (s IPNet) StateToString() string

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

func (*IPNet) Update

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

Update is called for:

  • AddPod and DeletePod (CNI)
  • POD k8s state changes
  • 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(*IPNet)

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.

type PodCustomIfUpdate

type PodCustomIfUpdate struct {
	PodID       podmodel.ID
	Labels      map[string]string
	Annotations map[string]string
}

PodCustomIfUpdate is triggered when pod custom interfaces configuration needs to be updated.

func (*PodCustomIfUpdate) Direction

Direction is forward.

func (*PodCustomIfUpdate) Done

func (ev *PodCustomIfUpdate) Done(error)

Done is NOOP.

func (*PodCustomIfUpdate) GetName

func (ev *PodCustomIfUpdate) GetName() string

GetName returns name of the PodCustomIfUpdate event.

func (*PodCustomIfUpdate) IsBlocking

func (ev *PodCustomIfUpdate) IsBlocking() bool

IsBlocking returns false.

func (*PodCustomIfUpdate) Method

Method is Update.

func (*PodCustomIfUpdate) String

func (ev *PodCustomIfUpdate) String() string

String describes PodCustomIfUpdate event.

func (*PodCustomIfUpdate) TransactionType

func (ev *PodCustomIfUpdate) TransactionType() controller.UpdateTransactionType

TransactionType is RevertOnFailure.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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