libsnnet

package
v0.0.0-...-194264a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

README

Simple Node Network Library

Overview

The Simple Node Network Library (libsnnet) implements a simple SDN controller. The library implements all the networking setup primitives required in Ciao.

libsnnet currently provides the following capabilities

  • Creation of multiple isolated tenant overlay L2 networks
  • Auto assignment of IP Addresses for VM's and containers
  • Support for Virtual Machine (QEMU)and Container workloads
    • Containers and VMs that belong to the same tenant are placed in the same L2 overlay network and connect to each other seamlessly
  • Ability to perform inbound and outbound NAT to/from the workloads
  • A built in docker Network and IPAM plugin to allow interworking between Docker logical networks and the ciao L2 overlay Network

It tries to rely on interfaces directly exposed by the kernel vs using user space tools to ensure maximum portability. The implementation maintains local state on leaf nodes vs relying on centralized state. It also uses local state to perform any network re-configuration in the event of a launcher crash or restart

Currently the library supports creation of bridges, GRE tunnels, VM and Container compatible interfaces (VNICs) on nodes. It also provides and the ability to attach tunnels and VNICs to bridges.

The implementation also provides the ability to interconnect these bridges across nodes creating L2 Overlay networks.

Roles

The library supports node specific networking initialization capabilities. It currently supports setup of Compute Nodes (CN), Network Nodes (NN) and Compute Node Concentrator Instances (CNCI)

Compute Node

A compute node typically runs VM and Container workloads. The library provides API's to perform network initialization as well as network interface creation and overlay network linking.

Network Node

The tenant overlay networks are linked together to Network Nodes. The Network Node switch and route traffic between the tenant bridges and subnets distributed across multiple Compute Nodes.

CNCI

Compute Node Concentrators or CNCIs are Virtual Machines running on Network Nodes which handle subsets of traffic belonging to a single tenant. A single network node can run multiple CNCI's limited by the Compute and Network needs of the CNCIs. All tenant level switching and routing for a given tenant is handled isolated from other tenants using the CNCI's. The CNCIs also implement tenant specific firewall and NAT rules. In the future they may be extended to perform traffic shaping.

Testing

The libsnnet library exposes API's that are used by the launcher and other components of ciao. However the library also includes a reasonably comprehensive unit test framework. The tests can be run as follows

sudo ip link add testdummy type dummy
sudo ip addr add 198.51.100.1/24 dev testdummy
export SNNET_ENV=198.51.100.0/24
export FWIFINT_ENV=testdummy

sudo ip link add extdummy type dummy
sudo ip addr add 203.0.113.1/24 dev extdummy
export FWIF_ENV=extdummy

sudo -E go test --tags travis -v --short

Note: Some of the API's require Docker 1.11+ to be installed on the test system. Please install Docker to ensure that all the unit tests pass.

These tests also help identify any regressions due to changes in the netlink library or the docker Network and IPAM plugin frameworks.

Documentation

Index

Constants

View Source
const (
	CnAPITimeout = 6
)

CnAPITimeout default controls the API timeout

View Source
const (
	MACPrefix = "02:00" //Prefix for all private MAC addresses

)

Various configuration options

Variables

View Source
var CnMaxAPIConcurrency = 8

CnMaxAPIConcurrency default controls internal API concurrency. It determines how many API's are being actively processed. Can be over-ridden prior to init.

View Source
var DockerPluginCfg = struct {
	Name    string
	Dir     string
	Addr    string
	DataDir string
	DbFile  string
	Timeout time.Duration
}{
	Name:    "ciao",
	Dir:     "/etc/docker/plugins",
	Addr:    "127.0.0.1:9999",
	DataDir: "/var/lib/ciao/networking",
	DbFile:  "docker_plugin.db",
	Timeout: 1 * time.Second,
}

DockerPluginCfg controls plugin attributes these may be overridden by the caller if needed

View Source
var Logger = clogger.CiaoLog(clogger.CiaoNullLogger{})

Logger is a global variable exported to be set by the package importing libsnnet package, in order to let it decide which logger it wants to use.

Functions

func DebugSSHPortForIP

func DebugSSHPortForIP(ip net.IP) (int, error)

DebugSSHPortForIP provides a utility routine that returns the ssh port on the tenant CNCI that can be used to reach a tenant instance with a given IP address

func DockerHandler

func DockerHandler(d *DockerPlugin,
	fn func(*DockerPlugin, http.ResponseWriter, *http.Request)) http.HandlerFunc

DockerHandler is the default handler for unhandled events It returns error to the caller

func DumpIPTables

func DumpIPTables() string

DumpIPTables provides a utility routine that returns the current state of the iptables

func EqualNetSlice

func EqualNetSlice(slice1, slice2 []string) bool

EqualNetSlice compare 2 network slices

func Routing

func Routing(action FwAction) error

Routing enable or disables routing echo 0 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/ip_forward

func WipeDockerPluginDB

func WipeDockerPluginDB() error

WipeDockerPluginDB deletes the database. The function assumes that the database is not open

Types

type APIError

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

APIError indicates that the networking call failed. However the system is still consistent and the networking layer has performed appropriate cleanup

func NewAPIError

func NewAPIError(s string) APIError

NewAPIError is a recoverable error

func (APIError) Error

func (e APIError) Error() string

type Attrs

type Attrs struct {
	LinkName string // Locally unique device name
	TenantID string // UUID of the tenant the device belongs to
	// Auto generated. Combination of UUIDs and other params.
	// Typically assigned to the alias
	// It is both locally and globally unique
	// Fully qualifies the device and its role
	GlobalID string
	MACAddr  *net.HardwareAddr
}

Attrs contains fields common to all device types

type Bridge

type Bridge struct {
	Attrs
	Link *netlink.Bridge
}

Bridge represents a ciao Bridge

func NewBridge

func NewBridge(id string) (*Bridge, error)

NewBridge is used to initialize the bridge properties This has to be called prior to Create() or GetDevice()

func (*Bridge) AddIP

func (b *Bridge) AddIP(ip *net.IPNet) error

AddIP Adds an IP Address to the bridge

func (*Bridge) Create

func (b *Bridge) Create() error

Create instantiates a new bridge.

func (*Bridge) DelIP

func (b *Bridge) DelIP(ip *net.IPNet) error

DelIP Deletes an IP Address assigned to the bridge

func (*Bridge) Destroy

func (b *Bridge) Destroy() error

Destroy an existing bridge

func (*Bridge) Disable

func (b *Bridge) Disable() error

Disable the bridge

func (*Bridge) Enable

func (b *Bridge) Enable() error

Enable the bridge

func (*Bridge) GetDevice

func (b *Bridge) GetDevice() error

GetDevice associates the bridge with an existing bridge with that GlobalId. If there are multiple bridges incorrectly created with the same id, it will associate the bridge with the first

type CNContainerEvent

type CNContainerEvent int