@@ -67,18 +67,31 @@ pub fn bestpaths(
67
67
return Some ( s. into_iter ( ) . take ( max) . cloned ( ) . collect ( ) ) ;
68
68
}
69
69
70
- // Begin comparison of BGP Path Attributes
70
+ // None of the remaining paths are static.
71
+ // Begin comparison of BGP Path Attributes.
72
+ Some ( bgp_bestpaths ( b, max) )
73
+ }
71
74
72
- // Filter down to paths that are not stale. The `min_set_by_key` method
73
- // allows us to assign "not stale" paths to the `0` set, and "stale" paths
74
- // to the `1` set. The method will then return the `0` set.
75
- let candidates = b. into_iter ( ) . min_set_by_key ( |path| match path. bgp {
76
- Some ( ref bgp) => match bgp. stale {
77
- Some ( _) => 1 ,
78
- None => 0 ,
79
- } ,
80
- None => 0 ,
81
- } ) ;
75
+ /// The BGP-specific portion of the bestpath algorithm. This evaluates BGP path
76
+ /// attributes in order to determine up to `max` suitable paths.
77
+ pub fn bgp_bestpaths (
78
+ candidates : BTreeSet < & Path > ,
79
+ max : usize ,
80
+ ) -> BTreeSet < Path > {
81
+ // Filter down to paths that are not stale (Graceful Restart).
82
+ // The `min_set_by_key` method allows us to assign "not stale" paths to the
83
+ // `0` set, and "stale" paths to the `1` set. The method will then return
84
+ // the `0` set if any "not stale" paths exist.
85
+ let candidates =
86
+ candidates
87
+ . into_iter ( )
88
+ . min_set_by_key ( |path| match path. bgp {
89
+ Some ( ref bgp) => match bgp. stale {
90
+ Some ( _) => 1 ,
91
+ None => 0 ,
92
+ } ,
93
+ None => 0 ,
94
+ } ) ;
82
95
83
96
// Filter down to paths with the highest local preference
84
97
let candidates =
@@ -113,7 +126,7 @@ pub fn bestpaths(
113
126
} ) ;
114
127
115
128
// Return up to max elements
116
- Some ( candidates. take ( max) . cloned ( ) . collect ( ) )
129
+ candidates. take ( max) . cloned ( ) . collect ( )
117
130
}
118
131
119
132
#[ cfg( test) ]
0 commit comments