datastore

package
v0.0.0-...-986d81d Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package datastore contains the structs and logic to handle accessing and managing a backend datastore. The datastore contains all network mappings for the nodes participating in the quantum network, as well as global configuration for the network.

The design of the datastore module is to expose a single method that represents accessing a network mapping. This is wrapped in a simple interface to allow for extending quantum to support multiple backends in the future.

The basic architecture is to have an in memory map object that is synchronized in the background. This allows the read only worker threads efficient access to the data, while still ensuring data consistency.

Currently supported datastores:

https://github.com/coreos/etcd (Both v2 and v3 api's)

The data structure itself is as follows:

Key: Private ip of the node
Value: json serialized mapping object

Etcd Example:
quantum/nodes/10.99.0.1
{
  "machineID": "b8fc945e893cfd55dc6170b6a4f6471d5790fa279e020410f435759ba9e3f0c5",
  "privateIP": "10.99.0.1",
  "publicKey": "EZOUpfx4N0LvU8A9\/b5seoUSm7+sOvWr8uE7zRATijU=",
  "ipv4": "172.18.0.2",
  "ipv6": "fd00:dead:beef::2",
  "port": 1099
}

Index

Constants

View Source
const (
	// ETCDV2Datastore will tell quantum to use etcd as the backend datastore.
	ETCDV2Datastore = "etcdv2"

	// ETCDV3Datastore will tell quantum to use etcd as the backend datastore.
	ETCDV3Datastore = "etcdv3"

	// MOCKDatastore will tell quantum to use a moked out backend datastore for testing.
	MOCKDatastore = "mock"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Datastore

type Datastore interface {
	// Init should handle setting up the datastore connections, and initializing the mappings/local mapping.
	Init() error

	// Mapping should return the mapping and true if it exists, if not the mapping should be nil and false should be returned along with it.
	Mapping(ip uint32) (*common.Mapping, bool)

	// GatewayMapping should retun the mapping and true if it exists specifically for destinations outside of the quantum network, if the mapping doesn't exist it will return nil and false.
	GatewayMapping() (*common.Mapping, bool)

	// Start should kick off any routines that need to run in the background to groom the mappings and manage the datastore state.
	Start()

	// Stop should fully shutdown all operation and ensure that all connections are terminated gracefully.
	Stop()
}

Datastore interface for quantum to use for retrieving mapping data from the backend datastore.

func New

func New(datastoreType string, cfg *common.Config) (Datastore, error)

New generates a datastore object based on the passed in Type and user configuration.

type EtcdV2

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

EtcdV2 datastore struct for interacting with the coreos etcd key/value datastore using the v2 api.

func (*EtcdV2) GatewayMapping

func (etcd *EtcdV2) GatewayMapping() (*common.Mapping, bool)

GatewayMapping should retun the mapping and true if it exists specifically for destinations outside of the quantum network, if the mapping doesn't exist it will return nil and false.

func (*EtcdV2) Init

func (etcd *EtcdV2) Init() error

Init the Etcd datastore which will open any necessary connections, preform an initial sync of the datastore, and define the local mapping in the datastore.

func (*EtcdV2) Mapping

func (etcd *EtcdV2) Mapping(ip uint32) (*common.Mapping, bool)

Mapping returns a mapping and true based on the supplied uint32 representation of an ipv4 address if it exists within the datastore, otherwise it returns nil for the mapping and false.

func (*EtcdV2) Start

func (etcd *EtcdV2) Start()

Start periodic synchronization, and DHCP lease refresh with the datastore, as well as start watching for changes in network topology.

func (*EtcdV2) Stop

func (etcd *EtcdV2) Stop()

Stop synchronizing with the backend and shutdown open connections.

type EtcdV3

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

EtcdV3 datastore struct for interacting with the coreos etcd key/value datastore using the v3 api.

func (*EtcdV3) GatewayMapping

func (etcd *EtcdV3) GatewayMapping() (*common.Mapping, bool)

GatewayMapping should retun the mapping and true if it exists specifically for destinations outside of the quantum network, if the mapping doesn't exist it will return nil and false.

func (*EtcdV3) Init

func (etcd *EtcdV3) Init() error

Init the Etcd datastore which will open any necessary connections, preform an initial sync of the datastore, and define the local mapping in the datastore.

func (*EtcdV3) Mapping

func (etcd *EtcdV3) Mapping(ip uint32) (*common.Mapping, bool)

Mapping returns a mapping and true based on the supplied uint32 representation of an ipv4 address if it exists within the datastore, otherwise it returns nil for the mapping and false.

func (*EtcdV3) Start

func (etcd *EtcdV3) Start()

Start periodic synchronization, and DHCP lease refresh with the datastore, as well as start watching for changes in network topology.

func (*EtcdV3) Stop

func (etcd *EtcdV3) Stop()

Stop synchronizing with the backend and shutdown open connections.

type Mock

type Mock struct {
	InternalMapping        *common.Mapping
	InternalGatewayMapping *common.Mapping
}

Mock datastore struct for testing.

func (*Mock) GatewayMapping

func (mock *Mock) GatewayMapping() (*common.Mapping, bool)

GatewayMapping always returns the internal mapping and true.

func (*Mock) Init

func (mock *Mock) Init() error

Init which is a noop.

func (*Mock) Mapping

func (mock *Mock) Mapping(ip uint32) (*common.Mapping, bool)

Mapping always returns the internal mapping and true.

func (*Mock) Start

func (mock *Mock) Start()

Start which is a noop.

func (*Mock) Stop

func (mock *Mock) Stop()

Stop which is a noop.

type Type

type Type int

Type represents the datastore backend to use for synchronizing mapping objects over the quantum network.

Jump to

Keyboard shortcuts

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