router

package
v0.0.0-...-a63dcda Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package router provides a network routing control plane

Index

Constants

View Source
const (
	// AdvertiseEventsTick is time interval in which the router advertises route updates
	AdvertiseEventsTick = 5 * time.Second
	// AdvertiseTableTick is time interval in which router advertises all routes found in routing table
	AdvertiseTableTick = 1 * time.Minute
	// AdvertiseFlushTick is time the yet unconsumed advertisements are flush i.e. discarded
	AdvertiseFlushTick = 15 * time.Second
	// AdvertSuppress is advert suppression threshold
	AdvertSuppress = 2000.0
	// AdvertRecover is advert recovery threshold
	AdvertRecover = 750.0
	// DefaultAdvertTTL is default advertisement TTL
	DefaultAdvertTTL = 1 * time.Minute
	// DeletePenalty penalises route deletion
	DeletePenalty = 1000.0
	// UpdatePenalty penalises route updates
	UpdatePenalty = 500.0
	// PenaltyHalfLife is the time the advert penalty decays to half its value
	PenaltyHalfLife = 2.0
	// MaxSuppressTime defines time after which the suppressed advert is deleted
	MaxSuppressTime = 5 * time.Minute
)

Variables

View Source
var (
	// DefaultAddress is default router address
	DefaultAddress = ":9093"
	// DefaultNetwork is default micro network
	DefaultNetwork = "go.micro"
)
View Source
var (
	// DefaultRouter is default network router
	DefaultRouter = NewRouter()
)
View Source
var (
	// PenaltyDecay is a coefficient which controls the speed the advert penalty decays
	PenaltyDecay = math.Log(2) / PenaltyHalfLife
)

Functions

This section is empty.

Types

type Advert struct {
	// Id is the router Id
	Id string
	// Type is type of advert
	Type AdvertType
	// Timestamp marks the time when the update is sent
	Timestamp time.Time
	// TTL is Advert TTL
	TTL time.Duration
	// Events is a list of routing table events to advertise
	Events []*table.Event
}

Advert contains a list of events advertised by the router to the network

type AdvertType

type AdvertType int

AdvertType is route advertisement type

const (
	// Announce is advertised when the router announces itself
	Announce AdvertType = iota
	// Update advertises route updates
	Update
)

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 Network

func Network(n string) Option

Network sets router network

func Registry

func Registry(r registry.Registry) Option

Registry sets the local registry

func Table

func Table(t table.Table) Option

Table sets the routing table

type Options

type Options struct {
	// Id is router id
	Id string
	// Address is router address
	Address string
	// Gateway is network gateway
	Gateway string
	// Network is network address
	Network string
	// Registry is the local registry
	Registry registry.Registry
	// Table is routing table
	Table table.Table
}

Options are router options

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns router default options

type Router

type Router interface {
	// Router provides a routing table
	table.Table
	// Init initializes the router with options
	Init(...Option) error
	// Options returns the router options
	Options() Options
	// Advertise advertises routes to the network
	Advertise() (<-chan *Advert, error)
	// Process processes incoming adverts
	Process(*Advert) error
	// Status returns router status
	Status() Status
	// Stop stops the router
	Stop() error
	// Returns the router implementation
	String() string
}

Router is an interface for a routing control plane

func NewRouter

func NewRouter(opts ...Option) Router

NewRouter creates new Router and returns it

type Status

type Status struct {
	// Error is router error
	Error error
	// Code defines router status
	Code StatusCode
}

Status is router status

type StatusCode

type StatusCode int

StatusCode defines router status

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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