control

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPathPolicy = &pathpol.Policy{
		ACL: &pathpol.ACL{
			Entries: []*pathpol.ACLEntry{{Action: pathpol.Allow}},
		},
	}
	DefaultPerfPolicy = fingerPrintOrder{}
	DefaultPathCount  = 1
)

Default policies for session policies.

View Source
var (
	// ErrAlreadyRunning is the error returned when attempting to run a task twice.
	ErrAlreadyRunning = serrors.New("is running")
)
View Source
var (
	// ObjectDestroyedError is returned by DeviceHandle API calls if the handle has been closed
	// before or during the API call. If the device is closed while the API call is ongoing, it is
	// not guaranteed that the returned error is ObjectDestroyedError, because the device access
	// might have completed before the close, but the API call hasn't finished yet.
	ObjectDestroyedError = serrors.New("object was destroyed")
)

Functions

func PathPolicyWithAllowedInterfaces added in v0.7.0

func PathPolicyWithAllowedInterfaces(
	policy policies.PathPolicy,
	remote addr.IA,
	allowedInterfaces []uint64,
) policies.PathPolicy

PathPolicyWithAllowedInterfaces constructs a path policy that only accepts path that match the policy and that enter the remote AS on one of the allowed interfaces. An empty list of allowed interfaces indicates that all interfaces are permitted.

Types

type Aggregator

type Aggregator struct {
	// RoutingUpdateChan is the channel that the routing updates will be pushed to.
	RoutingUpdateChan chan (RemoteGateways)
	// ReportingInterval is the interval between producing the reports. If there
	// are no changes, the actual interval may be longer.
	ReportingInterval time.Duration
	// ExpiryInterval means for how long will a gateway instance be reported if it
	// is not renewed.
	ExpiryInterval time.Duration
	// contains filtered or unexported fields
}

Aggregator aggregates prefix announcements and pushes the aggregated structure to the supplied channel.

func (*Aggregator) Close

func (a *Aggregator) Close(ctx context.Context)

Close stops the internal goroutines.

func (*Aggregator) Prefixes

func (a *Aggregator) Prefixes(
	remote addr.IA,
	gateway Gateway,
	prefixes []*net.IPNet,
) error

Prefixes pushes new set of prefixes for a specific gateway.

func (*Aggregator) Run

func (a *Aggregator) Run(ctx context.Context) error

Run starts the aggregator. It must only be called once.

type ConfigPublisher

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

ConfigPublisher can be used to send configs to multiple clients via different means (channels, getters).

func (*ConfigPublisher) Publish

func (n *ConfigPublisher) Publish(sp SessionPolicies, rp *routing.Policy)

Publish notifies clients of the Publisher about new configurations. Nil values are allowed and mean the nil config is not published, this is to allow updates of only one config.

func (*ConfigPublisher) RoutingPolicy

func (n *ConfigPublisher) RoutingPolicy() *routing.Policy

RoutingPolicy returns the last routing policy that was published. The returned object is a deep-copy, and can be edited by the caller.

func (*ConfigPublisher) SubscribeRemoteIAs

func (n *ConfigPublisher) SubscribeRemoteIAs() <-chan []addr.IA

SubscribeRemoteIAs returns a channel on which remote IAs will be sent. The channel has capacity 0. If a reader is slow to process the subscription, it will prevent the Publisher from publishing new configurations.

Subscriptions happening prior to a Publish are guaranteed to return the new state read by the NotPublishify.

func (*ConfigPublisher) SubscribeRoutingPolicies added in v0.7.0

func (n *ConfigPublisher) SubscribeRoutingPolicies() <-chan *routing.Policy

func (*ConfigPublisher) SubscribeSessionPolicies

func (n *ConfigPublisher) SubscribeSessionPolicies() <-chan SessionPolicies

SubscribeSessionPolicies returns a channel on which new session policies will be sent. The channel has capacity 0. If a reader is slow to process the subscription, it will prevent the Publisher from publishing new configurations.

Subscriptions happening prior to a Publish are guaranteed to return the new state read by the NotPublishify.

type Consumer added in v0.7.0

type Consumer interface {
	// Updates returns a channel that can be used to receive route updates.
	Updates() <-chan RouteUpdate
	// Close tells the consumer to stop receiving updates (and clean up
	// allocated resources, if any).
	Close()
}

Consumer receives prefix updates via a channel.

type ConsumerFactory added in v0.7.0

type ConsumerFactory interface {
	NewConsumer() Consumer
}

type DataplaneSession

type DataplaneSession interface {
	PktWriter
	// SetPaths can be used to change the paths on which packets are sent. If a path is invalid
	// or causes MTU issues, an error is returned.
	SetPaths([]snet.Path) error
	// Close informs the session it should shut down. It does not wait for the session to close.
	Close()
}

DataplaneSession represents a packet framer sending packets along a specific path.

type DataplaneSessionFactory

type DataplaneSessionFactory interface {
	New(sessID uint8, policyID int, remoteIA addr.IA, remoteAddr net.Addr) DataplaneSession
}

DataplaneSessionFactory is used to construct a data-plane session with a specific ID towards a remote.

type DefaultEngineFactory

type DefaultEngineFactory struct {
	// PathMonitor is used by engines to construct registrations for path discovery.
	PathMonitor PathMonitor

	// ProbeConnFactory is used by engines to construct connections for sending and receiving probe
	// packets.
	ProbeConnFactory PacketConnFactory

	// DeviceManager is used to construct tunnel devices needed for forwarding and/or routing.
	DeviceManager DeviceManager

	// DataplaneSessionFactory is used to construct dataplane sessions.
	DataplaneSessionFactory DataplaneSessionFactory

	// Metrics contains the metrics that will be modified during engine operation. If empty, no
	// metrics are reported.
	Metrics EngineMetrics
}

DefaultEngineFactory is a template for creating control-plane routing engines.

func (*DefaultEngineFactory) New

func (f *DefaultEngineFactory) New(table RoutingTable,
	sessions []*SessionConfig, routingTableIndices map[int][]uint8) Worker

type Device added in v0.7.0

type Device interface {
	io.ReadWriteCloser
	// AddRoute creates a route going through the device.
	AddRoute(ctx context.Context, r *Route) error
	// DeleteRoute destroys a route going through the device.
	DeleteRoute(ctx context.Context, r *Route) error
}

Device models an object that implements the reading and writing of packets and supports the addition of IPv4 and IPv6 routes through it. To destroy the interface, call Close. Calling Close multiple times should result in an error.

type DeviceHandle added in v0.7.0

type DeviceHandle Device

DeviceHandle implements reference counting for a Device. Close should be called once for each time the DeviceHandle was obtained from a DeviceManager.

type DeviceManager added in v0.7.0

type DeviceManager interface {
	// Get returns a DeviceHandle to a Device created by the DeviceManager. The reference
	// count of the handle is increased the 1. To ensure resources are not leaked,
	// each DeviceHandle should be closed after use.
	Get(ctx context.Context, ia addr.IA) (DeviceHandle, error)
}

DeviceManager returns handles to shared device objects. If an error is returned, no resource has been created.

type DeviceOpener added in v0.7.0

type DeviceOpener interface {
	Open(ctx context.Context, ia addr.IA) (Device, error)
}

DeviceOpener can be used to open readable/writeable objects that support IPv4/IPv6 routing. Typically, this is a Linux network device.

type DeviceOpenerFunc added in v0.7.0

type DeviceOpenerFunc func(ctx context.Context, ia addr.IA) (Device, error)

DeviceOpenerFunc is a function type that implements DeviceOpener.

func (DeviceOpenerFunc) Open added in v0.7.0

func (f DeviceOpenerFunc) Open(ctx context.Context, ia addr.IA) (Device, error)

type Diagnostics added in v0.7.0

type Diagnostics struct {
	Routes []Route
}

Diagnostics is the diagnostic information about the RouteDB.

type DiagnosticsWriter

type DiagnosticsWriter interface {
	DiagnosticsWrite(io.Writer)
}

type Discoverer

type Discoverer interface {
	Gateways(ctx context.Context) ([]Gateway, error)
}

Discoverer discovers gateway instances. It must be scoped to the intended remote for the GatewayWatcher.

type Engine

type Engine struct {
	// SessionConfigs contains the configurations of sessions that are part of the context.
	SessionConfigs []*SessionConfig

	// RoutingTable contains the routing object that updates should be pushed to.
	RoutingTable RoutingTable

	// RoutingTableIndices maps routing table indices to the list of eligible
	// sessions, sorted by priority.
	RoutingTableIndices map[int][]uint8

	// PathMonitor is used to construct registrations for path discovery.
	// Run will return an error if the PathMonitor is nil.
	PathMonitor PathMonitor

	// ProbeConnFactory constructs connections to be used for sending and receiving probe packets.
	// Run will return an error if ProbeConnFactory is nil.
	ProbeConnFactory PacketConnFactory

	// DeviceManager is used to construct tunnel devices needed for forwarding and/or routing.
	DeviceManager DeviceManager

	// DataplaneSessionFactory is used to construct dataplane sessions.
	DataplaneSessionFactory DataplaneSessionFactory

	// Metrics are the metrics which are modified during the operation of the engine.
	// If empty, no metrics are reported.
	Metrics EngineMetrics
	// contains filtered or unexported fields
}

Engine contains an entire routing context for the current control-plane configuration. It constructs channels between components, starts session goroutines, and runs the router.

func (*Engine) Close

func (e *Engine) Close(ctx context.Context) error

Close stops all internal goroutines and waits for them to finish.

func (*Engine) DiagnosticsWrite

func (e *Engine) DiagnosticsWrite(w io.Writer)

DiagnosticsWrite writes diagnostics to the writer.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

Run sets up the gateway engine and starts all necessary goroutines. It returns when the setup is done.

func (*Engine) Status

func (e *Engine) Status(w io.Writer)

Status prints the status page to the writer.

type EngineController

type EngineController struct {
	// ConfigurationUpdates is the channel on which new configurations for the Gateway sessions
	// are received. Every update will lead to a fresh instance of the forwarding engine,
	// together with a new data-plane configuration. The channel must not be nil.
	ConfigurationUpdates <-chan []*SessionConfig

	// RoutingTableSwapper permits the concurrency-safe swapping of an entire routing table in the
	// data-plane. When the session builder creates a new control-plane engine, it creates a fresh
	// routing table. Once the engine is ready, the fresh routing table is swapped in place of the
	// old one. It must not be nil.
	RoutingTableSwapper RoutingTableSwapper

	// RoutingTableFactory is used by the engine controller to create a fresh routing table.
	// It must not be nil.
	RoutingTableFactory RoutingTableFactory

	// EngineFactory is used to build new engines. It must not be nil.
	EngineFactory EngineFactory

	// RoutePublisherFactory allows to publish routes from the gateway.
	// If nil, no routes will be published.
	RoutePublisherFactory PublisherFactory

	// RouteSourceIPv4 is the source hint for IPv4 routes added to the Linux routing table.
	RouteSourceIPv4 net.IP
	// RouteSourceIPv6 is the source hint for IPv6 routes added to the Linux routing table.
	RouteSourceIPv6 net.IP

	// SwapDelay is the interval between creating a new engine and setting it to be the active
	// engine. If 0, the new engine is immediately swapped in.
	SwapDelay time.Duration
	// contains filtered or unexported fields
}

EngineController listens to session configuration updates received from the configuration modules. There are no partial updates; once a new configuration comes in, the EngineController creates a new engine and replaces the old one.

The EngineController is expected to run for the lifetime of the application and does not support shutdown.

Add factories to this type if required for testing.

func (*EngineController) DiagnosticsWrite

func (c *EngineController) DiagnosticsWrite(w io.Writer)

DiagnosticsWrite writes diagnostics to the writer.

func (*EngineController) Run

func (c *EngineController) Run(ctx context.Context) error

Run starts listening on the channel for updates, and processing existing updates.

func (*EngineController) Status

func (c *EngineController) Status(w io.Writer)

Status prints the status page.

type EngineFactory

type EngineFactory interface {
	New(table RoutingTable, sessions []*SessionConfig, routingTableIndices map[int][]uint8) Worker
}

EngineFactory can be used to create a control-plane engine for a set of session configurations. The engine will push updates to the routing table.

type EngineMetrics

type EngineMetrics struct {
	SessionMetrics        SessionMetrics
	SessionMonitorMetrics SessionMonitorMetrics
	RouterMetrics         RouterMetrics
}

EngineMetrics aggregates the metrics used by various control-plane engine components.

type Event

type Event int

Event describes a health check event.

const (
	EventDown Event = iota
	EventUp
)

The different Event values.

type Gateway

type Gateway struct {
	// Control contains the control-plane address of the remote gateway.
	Control *net.UDPAddr
	// Probe contains the probing address of the remote gateway.
	Probe *net.UDPAddr
	// Data contains the data-plane address of the remote gateway.
	Data *net.UDPAddr
	// Interfaces are the last-hop SCION interfaces that should be preferred.
	Interfaces []uint64
}

Gateway represents a remote gateway instance.

func (Gateway) Equal

func (g Gateway) Equal(other Gateway) bool

type GatewayWatcher

type GatewayWatcher struct {
	// Remote is the remote AS to watch.
	Remote addr.IA
	// Discoverer is used for remote gateway discovery. It must not be nil.
	Discoverer Discoverer
	// DiscoverInterval is the time between consecutive gateway discovery
	// attempts. If zero, this defaults to 5 seconds.
	DiscoverInterval time.Duration
	// DiscoverTimeout is the timout for an individual gateway discovery
	// attempts. If zero, this defaults to 5 seconds.
	DiscoverTimeout time.Duration
	// Template serves as the template for the PrefixWatcher tasks that are
	// spawned. For each discovered gateway, a PrefixWatcher task is started
	// based on this template.
	Template PrefixWatcherConfig
	// Metrics can be used to report information about discovered remote gateways. If not
	// initialized, no metrics will be reported.
	Metrics GatewayWatcherMetrics
	// contains filtered or unexported fields
}

GatewayWatcher watches gateways in a specific remote AS.

Per discovered gateway, the watcher starts a PrefixWatcher that periodically polls the IP prefixes served by that gateway. The PrefixWatcher tasks are dynamically added and removed depending on the gateway discovery responses. The delta in the list of gateways is assumed to be empty, if a discovery attempt fails.

When the GatewayWatcher is stopped, all spawaned PrefixWatcher tasks are stopped as well.

func (*GatewayWatcher) Run

func (w *GatewayWatcher) Run(ctx context.Context) error

Run watches the remote for gateways. This method blocks until the context expires, or an irrecoverable error is encountered.

type GatewayWatcherFactory

type GatewayWatcherFactory interface {
	New(context.Context, addr.IA, GatewayWatcherMetrics) Runner
}

type GatewayWatcherMetrics

type GatewayWatcherMetrics struct {
	// Remotes is the number of remote gateways discovered in the remote AS.
	Remotes metrics.Gauge
	// RemotesChanges is the number of times the number of remotes changed.
	RemotesChanges metrics.Counter
	// DiscoveryErrors counts the errors when discovering gateway in a remote AS.
	DiscoveryErrors metrics.Counter
	// PrefixFetchErrors counts the error when fetching prefixes from gateways
	// in the remote AS.
	PrefixFetchErrors metrics.Counter
}

GatewayWatcherMetrics contains the metrics the GatewayWatcher reports.

type LegacySessionPolicyAdapter

type LegacySessionPolicyAdapter struct{}

LegacySessionPolicyAdapter parses the legacy gateway JSON configuration and adapts it into the session policies format.

func (LegacySessionPolicyAdapter) Parse

Parse parses the raw JSON into a SessionPolicies struct.

type PacketConnFactory

type PacketConnFactory interface {
	New() (net.PacketConn, error)
}

PacketConnFactory is used to construct net.PacketConn objects for control-plane communication.

type PathMonitor

type PathMonitor interface {
	Register(ctx context.Context, ia addr.IA, policies *policies.Policies,
		policyID string) PathMonitorRegistration
}

PathMonitor is used to construct registrations for path discovery.

type PathMonitorRegistration

type PathMonitorRegistration interface {
	Get() pathhealth.Selection
	Close()
}

PathMonitorRegistration provides access to the paths.

type PktWriter

type PktWriter interface {
	Write(packet gopacket.Packet)
}

PktWriter is the interface exposed by a data-plane session for forwarding packets.

type PrefixConsumer

type PrefixConsumer interface {
	Prefixes(remote addr.IA, gateway Gateway, prefixes []*net.IPNet) error
}

PrefixConsumer consumes the prefixes fetched by the PrefixWatcher.

type PrefixFetcher

type PrefixFetcher interface {
	Prefixes(ctx context.Context, gateway *net.UDPAddr) ([]*net.IPNet, error)
	Close() error
}

PrefixFetcher fetches the IP prefixes from a remote gateway.

type PrefixFetcherFactory added in v0.7.0

type PrefixFetcherFactory interface {
	NewPrefixFetcher(ctx context.Context, gateway Gateway) PrefixFetcher
}

PrefixFetcherFactory constructs a PrefixFetcher for a given remote gateway.

type PrefixWatcherConfig

type PrefixWatcherConfig struct {
	// Consumer consume the fetched prefixes. Its methods are called
	// synchroniously and should return swiftly.
	Consumer PrefixConsumer
	// PrefixFetcherFactory is used to create a IP prefix fetcher for the remote gateway.
	FetcherFactory PrefixFetcherFactory
	// PollInterval is the time between consecutive poll attempts. If zero, this
	// defaults to 5 seconds.
	PollInterval time.Duration
	// PollTimeout is the timout for an individual poll attempts. If zero, this
	// defaults to 5 seconds.
	PollTimeout time.Duration
}

PrefixWatcherConfig configures a prefix watcher that watches IP prefixes advertised by a remote gateway. The discovered IP prefixes are advertised to the prefix consumer. The watcher is stateless and does not keep track of previously discovered IP prefixes.

type PrefixesFilter

type PrefixesFilter struct {
	// LocalIA is that IA this filter is running in. It is used as from value in
	// the routing policy check.
	LocalIA addr.IA
	// Consumer is the component that consumes prefixes that are not filtered
	// out.
	Consumer PrefixConsumer
	// PolicyProvider is the provider of routing policies, must not be nil.
	PolicyProvider RoutingPolicyProvider
	// Metrics can be used to report information about accepted and rejected IP prefixes. If not
	// initialized, no metrics will be reported.
	Metrics PrefixesFilterMetrics
}

PrefixesFilter is a prefix consumer that only forwards calls that are accepted by the current routing policy.

func (PrefixesFilter) Prefixes

func (f PrefixesFilter) Prefixes(
	remote addr.IA,
	gateway Gateway,
	prefixes []*net.IPNet,
) error

Prefixes consumes the prefixes, if they are accepted by the policy they are forwarded to the registered consumer.

type PrefixesFilterMetrics

type PrefixesFilterMetrics struct {
	PrefixesAccepted metrics.Gauge
	PrefixesRejected metrics.Gauge
}

type Publisher added in v0.7.0

type Publisher interface {
	// AddRoute will export route to another routing backend. Duplicates are a no-op.
	AddRoute(route Route)
	// DeleteRoute will delete a route from another routing backend. If the route
	// doesn't exist, the deletion is a silent no-op. Only a network that is an exact
	// match (network address, subnet mask, next hop) is removed.
	DeleteRoute(route Route)
	// Close retracts all the routes published via this publisher.
	Close()
}

Publisher is the interface for announcing prefixes to other routing backends.

type PublisherFactory added in v0.7.0

type PublisherFactory interface {
	NewPublisher() Publisher
}

type RemoteGateway

type RemoteGateway struct {
	// Gateway contains the gateway specific information.
	Gateway Gateway
	// Prefixes is the list of prefixes served by this gateway.
	Prefixes []*net.IPNet
}

RemoteGateway is an entry for a single remote gateway.

type RemoteGateways

type RemoteGateways struct {
	Gateways map[addr.IA][]RemoteGateway
}

RemoteGateways defines the current discovered routing state.

type RemoteMonitor

type RemoteMonitor struct {
	// GatewayWatcherFactory is used to create remote gateway watchers.
	GatewayWatcherFactory GatewayWatcherFactory
	// IAs is a channel that is notified with the full set of IAs to watch.
	IAs <-chan []addr.IA
	// RemotesMonitored is the number of remote gateways discovered, per ISD-AS.
	// If nil, no metric is reported.
	RemotesMonitored func(addr.IA) metrics.Gauge
	// RemotesChanges is the changes to the number of remote gateways
	// discovered, per ISD-AS. If nil, no metric is reported.
	RemotesChanges func(addr.IA) metrics.Counter
	// RemoteDiscoveryErrors is the number of remote gateway discovery errors,
	// per remote ISD-AS. If nil, no metric is reported.
	RemoteDiscoveryErrors func(addr.IA) metrics.Counter
	// PrefixFetchErrors is the number of prefix fetch errors, per remote
	// ISD-AS. If nil, no metric is reported.
	PrefixFetchErrors func(addr.IA) metrics.Counter
	// contains filtered or unexported fields
}

RemoteMonitor watches for currently monitored remote ASes and creates GatewayWatchers accordingly. For all new IAs that weren't seen before new GatewayWatcher is created. For all IAs that were seen before but are not present in an update the corresponding GatewayWatcher is stopped.

func (*RemoteMonitor) Close

func (rm *RemoteMonitor) Close(ctx context.Context) error

func (*RemoteMonitor) DiagnosticsWrite added in v0.7.0

func (rm *RemoteMonitor) DiagnosticsWrite(w io.Writer)

DiagnosticsWrite writes diagnostics to the writer.

func (*RemoteMonitor) Run

func (rm *RemoteMonitor) Run(ctx context.Context) error

type Route added in v0.7.0

type Route struct {
	// Prefix is the IP address prefix of the route.
	Prefix *net.IPNet
	// NextHop is the next hop to send the packets to.
	NextHop net.IP
	// Source is the (optional) source hint for the IP route.
	Source net.IP
	// IA is the ISD-AS which contains the route prefix. For route prefixes not advertised
	// over SCION this is the Zero AS.
	IA addr.IA
}

func (*Route) String added in v0.7.0

func (r *Route) String() string

type RouteUpdate added in v0.7.0

type RouteUpdate struct {
	Route
	// IsAdd is true if the route is added. It is false when the route is removed.
	IsAdd bool
}

RouteUpdate is used to inform consumers about changes in the route database.

type Router

type Router struct {
	// RoutingTable is the dataplane routing table.
	RoutingTable RoutingTableWriter
	// RoutingTableIndices maps a routing table index to a priority-ordered list
	// of session ids.
	RoutingTableIndices map[int][]uint8
	// DataplaneSessions are the dataplane sessions.
	DataplaneSessions map[uint8]PktWriter
	// Events is the channel that session events are read from. Note that
	// session IDs sent in this channel must be associated with a session in the
	// session groups.
	Events <-chan SessionEvent
	// Metrics are the metrics of the router.
	Metrics RouterMetrics
	// contains filtered or unexported fields
}

Router contains is a session-health-aware routing table builder that manages the data-plane routing table.

func (*Router) Close

func (r *Router) Close(ctx context.Context) error

Close stops all internal goroutines.

func (*Router) DiagnosticsWrite

func (r *Router) DiagnosticsWrite(w io.Writer)

DiagnosticsWrite writes diagnostics for the router to the writer.

func (*Router) Run

func (r *Router) Run(ctx context.Context) error

Run informs the router to start reading events from its event channel and push updates to the data-plane router. It returns when the router terminates.

type RouterMetrics added in v0.7.0

type RouterMetrics struct {
	// RoutingChainHealthy indicates whether the routing chain is healthy.
	RoutingChainHealthy func(routingChain int) metrics.Gauge
	// SessionsAlive indicates the alive sessions per routing chain.
	SessionsAlive func(routingChain int) metrics.Gauge
	// SessionChanges counts the number of session changes per routing chain.
	SessionChanges func(routingChain int) metrics.Counter
	// StateChanges counts the number of state changes per routing chain.
	StateChanges func(routingChain int) metrics.Counter
}

RouterMetrics are the metrics for the gateway router.

type RoutingChain

type RoutingChain struct {
	// RemoteIA is the remote ISD-AS to which this routing chain routes, it is
	// set for informational purposes.
	RemoteIA addr.IA
	// The list of prefixes, the order is not relevant.
	Prefixes []*net.IPNet
	// TrafficMatchers defines the traffic matchers in this routing chain. The
	// matchers are evaluated in order within the chain.
	TrafficMatchers []TrafficMatcher
}

RoutingChain defines a chain in the routing table. It links a list of prefixes and a traffic class chain, defined via the TrafficMatchers list.

type RoutingPolicyProvider

type RoutingPolicyProvider interface {
	RoutingPolicy() *routing.Policy
}

RoutingPolicyProvider provides the current active routing policy.

type RoutingTable

type RoutingTable interface {
	io.Closer
	RoutingTableReader
	RoutingTableWriter
}

RoutingTable is the dataplane routing table as seen from the control plane.

func NewPublishingRoutingTable added in v0.7.0

func NewPublishingRoutingTable(rcs []*RoutingChain, rt RoutingTable,
	routePublisher Publisher, nextHop, sourceIPv4, sourceIPv6 net.IP) RoutingTable

NewPublishingRoutingTable publishes routes from rt via the routePublisher. The methods of the returned object can safely be used concurrently by multiple goroutines.

type RoutingTableFactory

type RoutingTableFactory interface {
	// New should create a routing table based on the routing chains. The
	// implementation must implement a 2 level based routing: 1. it must do a
	// longest prefix match over all prefixes, 2. for the selected prefix it
	// must evaluate the corresponding traffic matcher list, the first match
	// must be selected.
	New([]*RoutingChain) (RoutingTable, error)
}

RoutingTableFactory is used by the engine controller to create a fresh routing table.

type RoutingTableReader

type RoutingTableReader interface {
	RouteIPv4(pkt layers.IPv4) PktWriter
	RouteIPv6(pkt layers.IPv6) PktWriter
}

RoutingTableReader contains the read operations of a data-plane routing table.

type RoutingTableSwapper

type RoutingTableSwapper interface {
	SetRoutingTable(RoutingTable) io.Closer
}

RoutingTableSwapper is a concurrency-safe setter for a routing table's entire state.

type RoutingTableWriter

type RoutingTableWriter interface {
	// SetSession sets the session for the routing table index. It replaces an
	// existing session if there is already one for this index. The method
	// returns an error if the index is not known. If session is nil the method
	// returns an error.
	SetSession(index int, session PktWriter) error
	// ClearSession removes any session for the given index. If there is no
	// session for the given index it is a no-op. The method returns an
	// error if the index is not known.
	ClearSession(index int) error
}

RoutingTableWriter contains the write operations of a data-plane routing table.

type Runner

type Runner interface {
	// Run is blocking  and can be concelled via the context.
	Run(context.Context) error
}

Runner represents a runnable task.

type Session

type Session struct {
	// ID is the ID of the session. It's used for debugging and the status page.
	ID uint8
	// RemoteIA is the remote RemoteIA.
	RemoteIA addr.IA

	// Events is used by the Session to announce changes in health (i.e., remote gateway unreachable
	// or reachable). A Session starts in a Down state (for which no event is sent), and should
	// announce it is up when it is healthy.
	//
	// Run will return an error if Events is nil.
	Events chan<- SessionEvent

	// SessionMonitorEvents is the channel on each events from the session monitor arrive.
	// Close this channel to shut down the Session.
	//
	// Run will return an error if SessionMonitorEvents is nil.
	SessionMonitorEvents <-chan SessionEvent

	// PathMonitorRegistration is used to access paths from the path monitor.
	//
	// Run will return an error if Paths is nil.
	PathMonitorRegistration PathMonitorRegistration

	// PathMonitorPollInterval sets how often the path should be read from the
	// path monitor. Must be set.
	PathMonitorPollInterval time.Duration

	// DataplaneSession points to the data-plane session managed by this control-plane session.
	//
	// Run will return an error if DataplaneSession is nil.
	DataplaneSession DataplaneSession

	Metrics SessionMetrics
	// contains filtered or unexported fields
}

Session represents a point-to-point association with a remote gateway that is subject to a path policy.

Once the session is started, up and down events are read from the session monitor and forwarded on the events channel.

If the reader of the events channel is slow, Session internals might block to avoid the event being lost.

func (*Session) Run

func (s *Session) Run(ctx context.Context) error

Run starts the health checking for the remote gateway. It returns when the session terminates.

type SessionConfig

type SessionConfig struct {
	// ID is the 1-byte session identifier that will be used to identify packets
	// on the wire.
	ID uint8
	// PolicyID is the ID of the SessionPolicy that lead to the creation of the SessionConfig.
	PolicyID int
	// IA is the ISD-AS number of the remote AS.
	IA addr.IA
	// TrafficMatcher contains the conditions the IP traffic must satisfy to use
	// this session.
	TrafficMatcher pktcls.Cond
	// PerfPolicy specifies which paths should be preferred (e.g., the path with
	// the lowest latency). If unset, paths with the lowest latency are
	// preferred.
	PerfPolicy policies.PerfPolicy
	// PathPolicy specifies the path properties that paths used for this session
	// must satisfy.
	PathPolicy policies.PathPolicy
	// PathCount is the max number of paths to use.
	PathCount int
	// Gateway describes a discovered remote gateway instance.
	Gateway Gateway
	// Prefixes contains the network prefixes that are reachable through this
	// session.
	Prefixes []*net.IPNet
}

SessionConfig contains the data that describes a control-plane session.

type SessionConfigurator

type SessionConfigurator struct {
	// SessionPolicies is the channel from which traffic policy updates are read.
	SessionPolicies <-chan SessionPolicies
	// RoutingUpdates is the channel from which routing update information is
	// read.
	RoutingUpdates <-chan RemoteGateways
	// SessionConfigurations is the channel where new configurations are
	// published.
	SessionConfigurations chan<- []*SessionConfig
	// contains filtered or unexported fields
}

SessionConfigurator builds session configurations from the static traffic policy and the dynamic information from the discovery service.

func (*SessionConfigurator) Close

func (sc *SessionConfigurator) Close(ctx context.Context) error

Close stops the session configurator.

func (*SessionConfigurator) DiagnosticsWrite

func (sc *SessionConfigurator) DiagnosticsWrite(w io.Writer)

DiagnosticsWrite writes diagnostics to the writer.

func (*SessionConfigurator) Run

Run informs the session configurator to start reading from its input channels and push updates on the configuration channel. It returns when the configurator terminates.

type SessionEvent

type SessionEvent struct {
	// SessionID contains the ID of the session announcing the event.
	SessionID uint8
	// Event signals whether the Session went up or down.
	Event Event
}

SessionEvent is used by the session to inform other components of changes to health.

type SessionMetrics added in v0.7.0

type SessionMetrics struct {
	// PathChanges counts the number of times the path changed for this session.
	PathChanges metrics.Counter
}

type SessionMonitor

type SessionMonitor struct {
	// ID is the ID of the session. It's used in the probe packet and for
	// diagnostics.
	ID uint8
	// RemoteIA is the remote RemoteIA the gateway to monitor is in.
	RemoteIA addr.IA
	// ProbeAddr is the probe address of the remote gateway instance.
	ProbeAddr *net.UDPAddr
	// Events is the channel where the monitor events are published to. Note
	// that an event is only published on change. The SessionMonitor will
	// close the events channel when it shuts down.
	Events chan<- SessionEvent
	// Paths is used to access paths from the path monitor.
	Paths PathMonitorRegistration
	// ProbeConn is the connection that is used to send and receive probe
	// packets.
	ProbeConn net.PacketConn
	// ProbeInterval is the interval at which the remote is probed. Can be left
	// zero and a default value will be used.
	ProbeInterval time.Duration
	// HealthExpiration is the duration after the last successful probe after
	// which a remote is considered unhealthy.
	HealthExpiration time.Duration
	// Metrics are the metrics which are modified during the operation of the
	// monitor. If empty no metrics are reported.
	Metrics SessionMonitorMetrics
	// contains filtered or unexported fields
}

SessionMonitor monitors a session with a remote gateway instance.

func (*SessionMonitor) Close

func (m *SessionMonitor) Close(ctx context.Context) error

Close stops the session monitor.

func (*SessionMonitor) Run

func (m *SessionMonitor) Run(ctx context.Context) error

Run runs the session monitor. It blocks until Close is called..

type SessionMonitorMetrics

type SessionMonitorMetrics struct {
	// Probes is the number of sent probes.
	Probes metrics.Counter
	// ProbeReplies is the number of probe replies received.
	ProbeReplies metrics.Counter
	// IsHealthy is a binary gauge showing a sessions healthiness.
	IsHealthy metrics.Gauge
	// StateChanges counts the number of state changes for this session.
	StateChanges metrics.Counter
}

SessionMonitorMetrics contains the metrics for the session monitor.

type SessionPolicies

type SessionPolicies []SessionPolicy

SessionPolicies is a list of session policies.

func LoadSessionPolicies

func LoadSessionPolicies(ctx context.Context, file string,
	parser SessionPolicyParser) (SessionPolicies, error)

LoadSessionPolicies loads the session policies from the given file, and parses it with the given parser.

func (SessionPolicies) Copy

Copy creates a deep copy of the session policies.

func (SessionPolicies) RemoteIAs

func (p SessionPolicies) RemoteIAs() []addr.IA

RemoteIAs returns all IAs that are in the session policies.

type SessionPolicy

type SessionPolicy struct {
	// IA is the ISD-AS number of the remote AS.
	IA addr.IA
	// ID identifies a session policy to a remote AS, i.e., the tuple (IA, ID) is unique.
	ID int
	// TrafficMatcher contains the conditions the IP traffic must satisfy to use
	// this session.
	TrafficMatcher pktcls.Cond
	// PerfPolicy specifies which paths should be preferred (e.g., the path with
	// the lowest latency). If unset, paths with the lowest latency are
	// preferred.
	PerfPolicy policies.PerfPolicy
	// PathPolicy specifies the path properties that paths used for this session
	// must satisfy.
	PathPolicy policies.PathPolicy
	// PathCount  defines the number of paths that can be simultaneously used
	// within a session.
	PathCount int
	// Prefixes contains the network prefixes that are reachable through this
	// session.
	Prefixes []*net.IPNet
}

SessionPolicy specifies the policy for a session towards a remote AS. The policy for a session consists of a - remote IA, identifying the remote this policy is for, - policy id, together with the remote IA uniquely identifying the policy, - traffic class, defined by a traffic matcher, - a path class defined by a path policy, - a performance policy, - a path count, - a remote IA, - a set of prefixes.

func (SessionPolicy) Copy

func (sp SessionPolicy) Copy() SessionPolicy

Copy creates a deep copy.

type SessionPolicyParser

type SessionPolicyParser interface {
	Parse(context.Context, []byte) (SessionPolicies, error)
}

SessionPolicyParser parses a raw session policy.

type TrafficMatcher

type TrafficMatcher struct {
	ID      int
	Matcher pktcls.Cond
}

TrafficMatcher is a traffic matcher with an ID.

type Worker

type Worker interface {
	// Run starts the worker's task and blocks until the worker has finished or it has been
	// shut down via Close.
	Run(context.Context) error
	// Close stops a running worker. If called before the worker has started, the worker
	// will skip its task. In this case, both Run and Close will return nil.
	Close(context.Context) error
}

Worker is a generic interface for goroutines used by the control-plane.

Directories

Path Synopsis
mock_grpc
Package mock_grpc is a generated GoMock package.
Package mock_grpc is a generated GoMock package.
Package mock_control is a generated GoMock package.
Package mock_control is a generated GoMock package.

Jump to

Keyboard shortcuts

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