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