engine

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	Routes map[string]*Route
	// minimum interval between changing states
	MinFlapInterval time.Duration
	// delay between interface up and announcing it to world
	UpDelay time.Duration
	// delay between downing interface and announcement
	DownDelay time.Duration
	// how often to repeat already up announcements
	ReAnnounce time.Duration
	// how often to repeat already up withdraws
	ReWithdraw time.Duration

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(r RouteEngine) (e *Engine, err error)

func (*Engine) RegisterRoute

func (e *Engine) RegisterRoute(route string, nexthop string, extra string, healthcheck RouteHealthcheck) (err error)

register route each route also needs to have healthcheck implementing RouteHealthcheck interface each route will be set ONCE, which means any subsequent changes to same tuple of route+nexthop will be ignored. Drop it before if you want to change config

func (*Engine) UpdateState

func (e *Engine) UpdateState()

type Route

type Route struct {
	// route
	Route string
	// next hop of the route
	NextHop string
	// extra parameters
	Extra string
	// whether route was announced
	Announced bool
	// whether route target is up
	Up              bool
	LastUp          time.Time
	LastDown        time.Time
	LastAnnounced   time.Time
	LastWithdrawn   time.Time
	LastStateChange time.Time
	UpCount         int
	DownCount       int
	// 0-100 score that tracks how often routes flap. 1 flap is worth 10 points, deduced 1 each time state is steady
	FlapScore int

	sync.Mutex
	// contains filtered or unexported fields
}

Route represents single route object. "Extra" is not used as a key so there can be no 2 routes with same extra field

func NewRoute

func NewRoute(route string, nexthop string, extra string, check RouteHealthcheck) (r *Route, err error)

func (*Route) Check

func (r *Route) Check() bool

func (*Route) SetAnnounced

func (r *Route) SetAnnounced()

func (*Route) SetDown

func (r *Route) SetDown()

func (*Route) SetUp

func (r *Route) SetUp()

func (*Route) SetWithdrawn

func (r *Route) SetWithdrawn()

func (*Route) String

func (r *Route) String() string

type RouteEngine

type RouteEngine interface {
	AnnounceRoute(route string, nexthop string, extra ...string) (err error)
	WithdrawRoute(route string, nexthop string, extra ...string) (err error)
}

type RouteHealthcheck

type RouteHealthcheck interface {
	IsRouteUp(route string, nexthop string) bool
}

Jump to

Keyboard shortcuts

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