diff options
Diffstat (limited to 'table/destination.go')
-rw-r--r-- | table/destination.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/table/destination.go b/table/destination.go index 131cb129..0e195f83 100644 --- a/table/destination.go +++ b/table/destination.go @@ -27,6 +27,8 @@ import ( "sort" ) +var SelectionOptions config.RouteSelectionOptionsConfig + type BestPathReason string const ( @@ -42,6 +44,7 @@ const ( BPR_ASN BestPathReason = "ASN" BPR_IGP_COST BestPathReason = "IGP Cost" BPR_ROUTER_ID BestPathReason = "Router ID" + BPR_OLDER BestPathReason = "Older" ) func IpToRadixkey(b []byte, max uint8) string { @@ -485,6 +488,10 @@ func (p paths) Less(i, j int) bool { reason = BPR_IGP_COST } if better == nil { + better = compareByAge(path1, path2) + reason = BPR_OLDER + } + if better == nil { var e error = nil better, e = compareByRouterID(path1, path2) if e != nil { @@ -720,11 +727,11 @@ func compareByRouterID(path1, path2 *Path) (*Path, error) { // If both paths are from eBGP peers, then according to RFC we need // not tie break using router id. - if !path1.IsIBGP() && !path2.IsIBGP() { + if !SelectionOptions.ExternalCompareRouterId && !path1.IsIBGP() && !path2.IsIBGP() { return nil, nil } - if path1.IsIBGP() != path2.IsIBGP() { + if !SelectionOptions.ExternalCompareRouterId && path1.IsIBGP() != path2.IsIBGP() { return nil, fmt.Errorf("This method does not support comparing ebgp with ibgp path") } @@ -743,6 +750,20 @@ func compareByRouterID(path1, path2 *Path) (*Path, error) { } } +func compareByAge(path1, path2 *Path) *Path { + if !path1.IsIBGP() && !path2.IsIBGP() && !SelectionOptions.ExternalCompareRouterId { + age1 := path1.info.timestamp.UnixNano() + age2 := path2.info.timestamp.UnixNano() + if age1 == age2 { + return nil + } else if age1 < age2 { + return path1 + } + return path2 + } + return nil +} + func (dest *Destination) String() string { return fmt.Sprintf("Destination NLRI: %s", dest.nlri.String()) } |