2019-07-08 16:51:55 +01:00
|
|
|
package table
|
2019-06-09 23:09:38 +01:00
|
|
|
|
2019-06-18 18:33:05 +01:00
|
|
|
import (
|
2019-07-05 19:15:32 +01:00
|
|
|
"hash/fnv"
|
2019-06-18 18:33:05 +01:00
|
|
|
)
|
2019-06-12 22:30:42 +01:00
|
|
|
|
2019-06-13 15:12:07 +01:00
|
|
|
var (
|
2019-07-09 15:45:42 +01:00
|
|
|
// DefaultLink is default network link
|
|
|
|
DefaultLink = "local"
|
2019-07-08 16:16:50 +01:00
|
|
|
// DefaultLocalMetric is default route cost metric for the local network
|
2019-06-13 15:12:07 +01:00
|
|
|
DefaultLocalMetric = 1
|
2019-07-08 16:16:50 +01:00
|
|
|
// DefaultNetworkMetric is default route cost metric for the micro network
|
2019-06-13 15:12:07 +01:00
|
|
|
DefaultNetworkMetric = 10
|
|
|
|
)
|
|
|
|
|
2019-06-19 21:22:14 +01:00
|
|
|
// Route is network route
|
|
|
|
type Route struct {
|
2019-07-09 15:45:42 +01:00
|
|
|
// Service is destination service name
|
|
|
|
Service string
|
|
|
|
// Address is service node address
|
|
|
|
Address string
|
2019-06-26 16:03:19 +01:00
|
|
|
// Gateway is route gateway
|
|
|
|
Gateway string
|
2019-07-08 16:16:50 +01:00
|
|
|
// Network is network address
|
2019-06-10 19:50:54 +01:00
|
|
|
Network string
|
2019-07-09 15:45:42 +01:00
|
|
|
// Link is network link
|
|
|
|
Link string
|
2019-06-19 21:22:14 +01:00
|
|
|
// Metric is the route cost metric
|
2019-06-09 23:09:38 +01:00
|
|
|
Metric int
|
|
|
|
}
|
2019-06-18 18:33:05 +01:00
|
|
|
|
2019-07-05 19:15:32 +01:00
|
|
|
// Hash returns route hash sum.
|
|
|
|
func (r *Route) Hash() uint64 {
|
|
|
|
h := fnv.New64()
|
|
|
|
h.Reset()
|
2019-07-09 15:45:42 +01:00
|
|
|
h.Write([]byte(r.Service + r.Address + r.Gateway + r.Network + r.Link))
|
2019-07-05 19:15:32 +01:00
|
|
|
|
|
|
|
return h.Sum64()
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:16:50 +01:00
|
|
|
// String returns human readable route
|
2019-07-05 19:15:32 +01:00
|
|
|
func (r Route) String() string {
|
2019-07-09 16:17:18 +01:00
|
|
|
return "route"
|
2019-06-18 18:33:05 +01:00
|
|
|
}
|