2019-06-06 18:37:40 +03:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Options allows to set Router options
|
|
|
|
type Options struct {
|
2019-06-10 21:50:54 +03:00
|
|
|
// ID is router ID
|
|
|
|
ID string
|
2019-06-07 15:29:09 +03:00
|
|
|
// Address is router address
|
|
|
|
Address string
|
2019-06-10 21:50:54 +03:00
|
|
|
// GossipAddr is router gossip address
|
|
|
|
GossipAddr string
|
|
|
|
// NetworkAddr defines micro network address
|
|
|
|
NetworkAddr string
|
2019-06-07 15:29:09 +03:00
|
|
|
// RIB is Routing Information Base
|
|
|
|
RIB RIB
|
|
|
|
// Table is routing table
|
|
|
|
Table Table
|
2019-06-06 18:37:40 +03:00
|
|
|
// Context stores arbitrary options
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
2019-06-10 21:50:54 +03:00
|
|
|
// ID sets Router ID
|
|
|
|
func ID(id string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.ID = id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 01:59:25 +03:00
|
|
|
// Address sets router address
|
2019-06-07 19:20:22 +03:00
|
|
|
func Address(a string) Option {
|
2019-06-07 15:29:09 +03:00
|
|
|
return func(o *Options) {
|
2019-06-07 19:20:22 +03:00
|
|
|
o.Address = a
|
2019-06-07 15:29:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 01:59:25 +03:00
|
|
|
// GossipAddr sets router gossip address
|
|
|
|
func GossipAddr(a string) Option {
|
2019-06-10 21:50:54 +03:00
|
|
|
return func(o *Options) {
|
|
|
|
o.GossipAddr = a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 01:59:25 +03:00
|
|
|
// NetworkAddr sets router network address
|
2019-06-10 21:50:54 +03:00
|
|
|
func NetworkAddr(n string) Option {
|
2019-06-07 15:29:09 +03:00
|
|
|
return func(o *Options) {
|
2019-06-10 21:50:54 +03:00
|
|
|
o.NetworkAddr = n
|
2019-06-07 19:20:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RIBase allows to configure RIB
|
|
|
|
func RIBase(r RIB) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.RIB = r
|
2019-06-07 15:29:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RoutingTable allows to specify custom routing table
|
|
|
|
func RoutingTable(t Table) Option {
|
2019-06-07 01:29:24 +03:00
|
|
|
return func(o *Options) {
|
2019-06-07 15:29:09 +03:00
|
|
|
o.Table = t
|
2019-06-07 01:29:24 +03:00
|
|
|
}
|
|
|
|
}
|