diff options
author | Jordan Whited <jwhited@subspace.com> | 2020-08-10 09:43:54 -0700 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2020-08-12 20:56:11 +0900 |
commit | a4d5d004cc3d97c90de0c2d91f2312525e055d68 (patch) | |
tree | 88f5d6ed07117fa3ebd048c70db03ace2e5a6f1b /internal/pkg/table/destination.go | |
parent | c6f0eba8f4d8544ede83c70d6b5f07560ff6c7ce (diff) |
best path selection - compare neigh addr
Diffstat (limited to 'internal/pkg/table/destination.go')
-rw-r--r-- | internal/pkg/table/destination.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/pkg/table/destination.go b/internal/pkg/table/destination.go index 2880f662..0b438d78 100644 --- a/internal/pkg/table/destination.go +++ b/internal/pkg/table/destination.go @@ -50,6 +50,7 @@ const ( BPR_ROUTER_ID BPR_OLDER BPR_NON_LLGR_STALE + BPR_NEIGH_ADDR ) var BestPathReasonStringMap = map[BestPathReason]string{ @@ -68,6 +69,7 @@ var BestPathReasonStringMap = map[BestPathReason]string{ BPR_ROUTER_ID: "Router ID", BPR_OLDER: "Older", BPR_NON_LLGR_STALE: "no LLGR Stale", + BPR_NEIGH_ADDR: "Neighbor Address", } func (r *BestPathReason) String() string { @@ -481,6 +483,10 @@ func (dst *Destination) sort() BestPathReason { reason = BPR_ROUTER_ID } if better == nil { + better = compareByNeighborAddress(path1, path2) + reason = BPR_NEIGH_ADDR + } + if better == nil { reason = BPR_UNKNOWN better = path1 } @@ -918,6 +924,31 @@ func compareByRouterID(path1, path2 *Path) (*Path, error) { } } +func compareByNeighborAddress(path1, path2 *Path) *Path { + // Select the route received from the peer with the lowest peer address as + // per RFC 4271 9.1.2.2. g + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByNeighborAddress") + + p1 := path1.GetSource().Address + if p1 == nil { + return path1 + } + p2 := path2.GetSource().Address + if p2 == nil { + return path2 + } + + cmp := bytes.Compare(p1, p2) + if cmp < 0 { + return path1 + } else if cmp > 0 { + return path2 + } + return nil +} + func compareByAge(path1, path2 *Path) *Path { if !path1.IsIBGP() && !path2.IsIBGP() && !SelectionOptions.ExternalCompareRouterId { age1 := path1.GetTimestamp().UnixNano() |