Skip to content

Commit 949450e

Browse files
committed
Move bgp-specific steps into its own bestpath helper
Signed-off-by: Trey Aspelund <[email protected]>
1 parent bf6f725 commit 949450e

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

rdb/src/bestpath.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,31 @@ pub fn bestpaths(
6767
return Some(s.into_iter().take(max).cloned().collect());
6868
}
6969

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+
}
7174

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+
});
8295

8396
// Filter down to paths with the highest local preference
8497
let candidates =
@@ -113,7 +126,7 @@ pub fn bestpaths(
113126
});
114127

115128
// Return up to max elements
116-
Some(candidates.take(max).cloned().collect())
129+
candidates.take(max).cloned().collect()
117130
}
118131

119132
#[cfg(test)]

0 commit comments

Comments
 (0)