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