2019-06-21 18:17:12 +03:00
|
|
|
// Package router provides a network routing control plane
|
2019-06-06 18:37:40 +03:00
|
|
|
package router
|
|
|
|
|
2019-06-28 13:53:55 +03:00
|
|
|
import "time"
|
|
|
|
|
2019-06-28 00:52:51 +03:00
|
|
|
var (
|
|
|
|
// DefaultRouter is default network router
|
|
|
|
DefaultRouter = NewRouter()
|
|
|
|
)
|
|
|
|
|
2019-06-21 18:17:12 +03:00
|
|
|
// Router is an interface for a routing control plane
|
2019-06-06 18:37:40 +03:00
|
|
|
type Router interface {
|
2019-06-13 00:30:42 +03:00
|
|
|
// Init initializes the router with options
|
2019-06-06 18:37:40 +03:00
|
|
|
Init(...Option) error
|
2019-06-13 00:30:42 +03:00
|
|
|
// Options returns the router options
|
2019-06-06 18:37:40 +03:00
|
|
|
Options() Options
|
2019-06-20 15:04:58 +03:00
|
|
|
// ID returns the id of the router
|
2019-06-17 01:09:59 +03:00
|
|
|
ID() string
|
2019-06-20 15:04:58 +03:00
|
|
|
// Table returns the routing table
|
2019-06-07 15:29:09 +03:00
|
|
|
Table() Table
|
2019-06-13 14:09:49 +03:00
|
|
|
// Address returns the router adddress
|
2019-06-07 01:29:24 +03:00
|
|
|
Address() string
|
2019-06-20 15:04:58 +03:00
|
|
|
// Network returns the network address of the router
|
2019-06-07 19:20:22 +03:00
|
|
|
Network() string
|
2019-06-28 00:52:51 +03:00
|
|
|
// Advertise starts advertising routes to the network
|
2019-06-28 13:53:55 +03:00
|
|
|
Advertise() (<-chan *Update, error)
|
2019-06-28 00:52:51 +03:00
|
|
|
// Update updates the routing table
|
2019-06-28 13:53:55 +03:00
|
|
|
Update(*Update) error
|
2019-06-13 00:30:42 +03:00
|
|
|
// Stop stops the router
|
2019-06-12 01:59:25 +03:00
|
|
|
Stop() error
|
2019-06-07 15:29:09 +03:00
|
|
|
// String returns debug info
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2019-06-28 13:53:55 +03:00
|
|
|
// Update is sent by the router to the network
|
|
|
|
type Update struct {
|
2019-06-28 00:52:51 +03:00
|
|
|
// ID is the source router ID
|
|
|
|
ID string
|
2019-06-28 13:53:55 +03:00
|
|
|
// Timestamp marks the time when update is sent
|
|
|
|
Timestamp time.Time
|
2019-06-28 00:52:51 +03:00
|
|
|
// Event defines advertisement even
|
|
|
|
Event *Event
|
|
|
|
}
|
|
|
|
|
2019-06-10 01:09:38 +03:00
|
|
|
// Option used by the router
|
2019-06-06 18:37:40 +03:00
|
|
|
type Option func(*Options)
|
|
|
|
|
|
|
|
// NewRouter creates new Router and returns it
|
|
|
|
func NewRouter(opts ...Option) Router {
|
|
|
|
return newRouter(opts...)
|
|
|
|
}
|