2019-06-21 16:17:12 +01:00
|
|
|
// Package router provides a network routing control plane
|
2024-09-20 17:54:17 +03:00
|
|
|
package router
|
2019-06-06 16:37:40 +01:00
|
|
|
|
2019-07-08 16:51:55 +01:00
|
|
|
import (
|
2020-07-27 13:22:00 +01:00
|
|
|
"errors"
|
2019-07-08 16:51:55 +01:00
|
|
|
)
|
2019-06-28 11:53:55 +01:00
|
|
|
|
2019-08-20 12:48:51 +01:00
|
|
|
var (
|
2020-11-03 01:08:23 +03:00
|
|
|
// DefaultRouter is the global default router
|
2024-12-09 16:23:25 +03:00
|
|
|
DefaultRouter = NewRouter()
|
2019-08-20 12:48:51 +01:00
|
|
|
// DefaultNetwork is default micro network
|
2020-06-24 11:09:16 +01:00
|
|
|
DefaultNetwork = "micro"
|
2020-07-27 13:22:00 +01:00
|
|
|
// 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")
|
2019-08-20 12:48:51 +01:00
|
|
|
)
|
|
|
|
|
2019-06-21 16:17:12 +01:00
|
|
|
// Router is an interface for a routing control plane
|
2019-06-06 16:37:40 +01:00
|
|
|
type Router interface {
|
2021-01-29 13:17:32 +03:00
|
|
|
Name() string
|
2019-06-12 22:30:42 +01:00
|
|
|
// Init initializes the router with options
|
2019-06-06 16:37:40 +01:00
|
|
|
Init(...Option) error
|
2019-06-12 22:30:42 +01:00
|
|
|
// Options returns the router options
|
2019-06-06 16:37:40 +01:00
|
|
|
Options() Options
|
2019-07-29 18:57:40 +01:00
|
|
|
// The routing table
|
|
|
|
Table() Table
|
2019-07-25 23:52:54 +01:00
|
|
|
// Lookup queries routes in the routing table
|
2019-10-09 17:13:52 +01:00
|
|
|
Lookup(...QueryOption) ([]Route, error)
|
2019-07-25 23:52:54 +01:00
|
|
|
// Watch returns a watcher which tracks updates to the routing table
|
2019-07-25 23:19:05 +01:00
|
|
|
Watch(opts ...WatchOption) (Watcher, error)
|
2020-06-24 11:09:16 +01:00
|
|
|
// Close the router
|
|
|
|
Close() error
|
2019-07-10 07:56:52 +01:00
|
|
|
// Returns the router implementation
|
2019-06-07 13:29:09 +01:00
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2019-08-20 21:11:27 +01:00
|
|
|
// Table is an interface for routing table
|
2019-07-29 18:57:40 +01:00
|
|
|
type Table interface {
|
|
|
|
// Create new route in the routing table
|
|
|
|
Create(Route) error
|
2019-08-20 21:11:27 +01:00
|
|
|
// Delete existing route from the routing table
|
2019-07-29 18:57:40 +01:00
|
|
|
Delete(Route) error
|
2019-08-20 21:11:27 +01:00
|
|
|
// Update route in the routing table
|
2019-07-29 18:57:40 +01:00
|
|
|
Update(Route) error
|
2019-08-20 21:11:27 +01:00
|
|
|
// List all routes in the table
|
2019-07-29 18:57:40 +01:00
|
|
|
List() ([]Route, error)
|
2019-08-20 21:11:27 +01:00
|
|
|
// Query routes in the routing table
|
2019-10-09 17:13:52 +01:00
|
|
|
Query(...QueryOption) ([]Route, error)
|
2019-07-29 18:57:40 +01:00
|
|
|
}
|
|
|
|
|
2019-07-03 19:50:07 +01:00
|
|
|
// Option used by the router
|
|
|
|
type Option func(*Options)
|
|
|
|
|
2019-07-24 17:16:52 +01:00
|
|
|
// StatusCode defines router status
|
|
|
|
type StatusCode int
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|