diff options
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() |