2019-06-06 18:37:40 +03:00
|
|
|
// Package router provides an interface for micro network routers
|
|
|
|
package router
|
|
|
|
|
|
|
|
// Router is micro network router
|
|
|
|
type Router interface {
|
|
|
|
// Initi initializes Router with options
|
|
|
|
Init(...Option) error
|
|
|
|
// Options returns Router options
|
|
|
|
Options() Options
|
2019-06-07 01:29:24 +03:00
|
|
|
// Add adds new entry into routing table
|
2019-06-10 01:09:38 +03:00
|
|
|
Add(Entry) error
|
2019-06-07 01:29:24 +03:00
|
|
|
// Remove removes entry from the routing table
|
2019-06-10 01:09:38 +03:00
|
|
|
Remove(Entry) error
|
2019-06-07 01:29:24 +03:00
|
|
|
// Update updates entry in the routing table
|
2019-06-10 01:09:38 +03:00
|
|
|
Update(...EntryOption) error
|
2019-06-07 01:29:24 +03:00
|
|
|
// Lookup queries the routing table and returns matching entries
|
|
|
|
Lookup(Query) ([]*Entry, error)
|
|
|
|
// Table returns routing table
|
2019-06-07 15:29:09 +03:00
|
|
|
Table() Table
|
2019-06-10 01:09:38 +03:00
|
|
|
// Address returns the router bind adddress
|
2019-06-07 01:29:24 +03:00
|
|
|
Address() string
|
2019-06-10 01:09:38 +03:00
|
|
|
// Network returns router's micro network bind address
|
2019-06-07 19:20:22 +03:00
|
|
|
Network() string
|
2019-06-06 18:37:40 +03:00
|
|
|
// String implemens fmt.Stringer interface
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2019-06-07 15:29:09 +03:00
|
|
|
// RIB is Routing Information Base
|
|
|
|
type RIB interface {
|
|
|
|
// String returns debug info
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
2019-06-10 01:09:38 +03:00
|
|
|
// EntryOption is used to define routing entry options
|
|
|
|
type EntryOption func(*EntryOptions)
|
2019-06-06 18:37:40 +03:00
|
|
|
|
2019-06-10 01:09:38 +03:00
|
|
|
// QueryOption is used to define query options
|
2019-06-07 01:29:24 +03:00
|
|
|
type QueryOption func(*QueryOptions)
|
2019-06-06 18:37:40 +03:00
|
|
|
|
|
|
|
// NewRouter creates new Router and returns it
|
|
|
|
func NewRouter(opts ...Option) Router {
|
2019-06-07 15:29:09 +03:00
|
|
|
// set default options
|
2019-06-07 01:29:24 +03:00
|
|
|
ropts := Options{
|
2019-06-07 20:04:48 +03:00
|
|
|
// Default table
|
|
|
|
Table: NewTable(),
|
2019-06-06 18:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
2019-06-07 01:29:24 +03:00
|
|
|
o(&ropts)
|
2019-06-06 18:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return newRouter(opts...)
|
|
|
|
}
|