- let attr_set = self.routes.lock().unwrap().get_route_attrs(addr);
- let mut paths: Vec<(ASPath, u32, u32)> = Vec::new();
- for attrs in attr_set.iter() {
- let mut as4_path = None;
- let mut as_path = None;
- let mut pref = 100;
- let mut med = 0;
- for attr in attrs.iter() {
- match attr {
- PathAttribute::AS4_PATH(path) => as4_path = Some(path),
- PathAttribute::AS_PATH(path) => as_path = Some(path),
- PathAttribute::LOCAL_PREF(p) => pref = *p,
- PathAttribute::MULTI_EXIT_DISC(m) => med = *m,
- _ => {},
- }
- }
- if let Some(path) = as4_path.or(as_path) {
- paths.push((path.clone(), pref, med));
+ let mut path_vecs = self.routes.lock().unwrap().get_route_attrs(addr).clone();
+ path_vecs.sort_unstable_by(|path_a, path_b| {
+ path_a.pref.cmp(&path_b.pref)
+ .then(path_b.path.len().cmp(&path_a.path.len()))
+ .then(path_b.med.cmp(&path_a.med))
+ });
+ // TODO: Find last common ASN among all paths
+ *path_vecs[0].path.last().unwrap_or(&0)
+ }
+
+ pub fn disconnect(&self) {
+ self.shutdown.store(true, Ordering::Relaxed);
+ }
+
+ fn map_attrs(mut attrs: Vec<PathAttribute>) -> Option<Route> {
+ let mut as4_path = None;
+ let mut as_path = None;
+ let mut pref = 100;
+ let mut med = 0;
+ for attr in attrs.drain(..) {
+ match attr {
+ PathAttribute::AS4_PATH(path) => as4_path = Some(path),
+ PathAttribute::AS_PATH(path) => as_path = Some(path),
+ PathAttribute::LOCAL_PREF(p) => pref = p,
+ PathAttribute::MULTI_EXIT_DISC(m) => med = m,
+ _ => {},