router

package
v3.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package router provides a network routing control plane

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLink is default network link
	DefaultLink = "local"
	// DefaultLocalMetric is default route cost for a local route
	DefaultLocalMetric int64 = 1
)
View Source
var (
	// DefaultRouter is the global default router
	DefaultRouter Router = NewRouter()
	// DefaultNetwork is default micro network
	DefaultNetwork = "micro"
	// ErrRouteNotFound is returned when no route was found in the routing table
	ErrRouteNotFound = errors.New("route not found")
	// ErrDuplicateRoute is returned when the route already exists
	ErrDuplicateRoute = errors.New("duplicate route")
)
View Source
var ErrWatcherStopped = errors.New("watcher stopped")

ErrWatcherStopped is returned when routing table watcher has been stopped

Functions

This section is empty.

Types

type Event

type Event struct {
	// Timestamp is event timestamp
	Timestamp time.Time
	// Id of the event
	Id string
	// Route is table route
	Route Route
	// Type defines type of event
	Type EventType
}

Event is returned by a call to Next on the watcher.

type EventType

type EventType int

EventType defines routing table event

const (
	// Create is emitted when a new route has been created
	Create EventType = iota
	// Delete is emitted when an existing route has been deleted
	Delete
	// Update is emitted when an existing route has been updated
	Update
)

func (EventType) String

func (t EventType) String() string

String returns human readable event type

type Option

type Option func(*Options)

Option used by the router

func Address

func Address(a string) Option

Address sets router service address

func Gateway

func Gateway(g string) Option

Gateway sets network gateway

func Id

func Id(id string) Option

Id sets Router Id

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Name added in v3.2.0

func Name(n string) Option

Name of the router

func Network

func Network(n string) Option

Network sets router network

func Precache

func Precache() Option

Precache the routes

func Register added in v3.2.0

func Register(r register.Register) Option

Register sets the local register

type Options

type Options struct {
	Logger   logger.Logger
	Context  context.Context
	Register register.Register
	Name     string
	Gateway  string
	Network  string
	Id       string
	Address  string
	Precache bool
}

Options are router options

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns router default options

type QueryOption

type QueryOption func(*QueryOptions)

QueryOption sets routing table query options

func QueryAddress

func QueryAddress(a string) QueryOption

QueryAddress sets service to query

func QueryGateway

func QueryGateway(g string) QueryOption

QueryGateway sets gateway address to query

func QueryLink(link string) QueryOption

QueryLink sets the link to query

func QueryNetwork

func QueryNetwork(n string) QueryOption

QueryNetwork sets network name to query

func QueryRouter

func QueryRouter(r string) QueryOption

QueryRouter sets router id to query

func QueryService

func QueryService(s string) QueryOption

QueryService sets service to query

type QueryOptions

type QueryOptions struct {
	// Service is destination service name
	Service string
	// Address of the service
	Address string
	// Gateway is route gateway
	Gateway string
	// Network is network address
	Network string
	// Router is router id
	Router string
	// Link to query
	Link string
}

QueryOptions are routing table query options TODO replace with Filter(Route) bool

func NewQuery

func NewQuery(opts ...QueryOption) QueryOptions

NewQuery creates new query and returns it

type Route

type Route struct {
	// Metadata for the route
	Metadata metadata.Metadata
	// Service is destination service name
	Service string
	// Gateway is route gateway
	Gateway string
	// Network is network address
	Network string
	// Router is router id
	Router string
	// Link is network link
	Link string
	// Address is service node address
	Address string
	// Metric is the route cost metric
	Metric int64
}

Route is network route

func (*Route) Hash

func (r *Route) Hash() uint64

Hash returns route hash sum.

type Router

type Router interface {
	Name() string
	// Init initializes the router with options
	Init(...Option) error
	// Options returns the router options
	Options() Options
	// The routing table
	Table() Table
	// Lookup queries routes in the routing table
	Lookup(...QueryOption) ([]Route, error)
	// Watch returns a watcher which tracks updates to the routing table
	Watch(opts ...WatchOption) (Watcher, error)
	// Close the router
	Close() error
	// Returns the router implementation
	String() string
}

Router is an interface for a routing control plane

func NewRouter added in v3.3.4

func NewRouter(opts ...Option) Router

NewRouter returns an initialized dns router

type StatusCode

type StatusCode int

StatusCode defines router status

const (
	// Running means the router is up and running
	Running StatusCode = iota
	// Stopped means the router has been stopped
	Stopped
	// Error means the router has encountered error
	Error
)

type Table

type Table interface {
	// Create new route in the routing table
	Create(Route) error
	// Delete existing route from the routing table
	Delete(Route) error
	// Update route in the routing table
	Update(Route) error
	// List all routes in the table
	List() ([]Route, error)
	// Query routes in the routing table
	Query(...QueryOption) ([]Route, error)
}

Table is an interface for routing table

type WatchOption

type WatchOption func(*WatchOptions)

WatchOption is used to define what routes to watch in the table

func WatchService

func WatchService(s string) WatchOption

WatchService sets what service routes to watch Service is the microservice name

type WatchOptions

type WatchOptions struct {
	// Service allows to watch specific service routes
	Service string
}

WatchOptions are table watcher options TODO: expand the options to watch based on other criteria

type Watcher

type Watcher interface {
	// Next is a blocking call that returns watch result
	Next() (*Event, error)
	// Chan returns event channel
	Chan() (<-chan *Event, error)
	// Stop stops watcher
	Stop()
}

Watcher defines routing table watcher interface Watcher returns updates to the routing table

Jump to

Keyboard shortcuts

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