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-08-28 01:08:35 +03:00
|
|
|
// DefaultLocalMetric is default route cost for a local route
|
2019-10-23 14:53:36 +03:00
|
|
|
DefaultLocalMetric int64 = 1
|
2019-06-13 17:12:07 +03:00
|
|
|
)
|
|
|
|
|
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-08-28 01:08:35 +03:00
|
|
|
// Router is router id
|
|
|
|
Router 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-10-23 14:53:36 +03:00
|
|
|
Metric int64
|
2019-06-10 01:09:38 +03:00
|
|
|
}
|
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-08-28 01:08:35 +03:00
|
|
|
h.Write([]byte(r.Service + r.Address + r.Gateway + r.Network + r.Router + r.Link))
|
2019-07-05 21:15:32 +03:00
|
|
|
return h.Sum64()
|
|
|
|
}
|