diff --git a/src/rust/uisp_integration/src/strategies/full2.rs b/src/rust/uisp_integration/src/strategies/full2.rs index df4d51bc..af71ee53 100644 --- a/src/rust/uisp_integration/src/strategies/full2.rs +++ b/src/rust/uisp_integration/src/strategies/full2.rs @@ -9,7 +9,8 @@ use crate::ethernet_advisory::apply_ethernet_rate_cap; use crate::ip_ranges::IpRanges; use crate::strategies::common::UispData; use crate::strategies::full2::directionality::{ - build_device_capacity_map, build_device_link_meta_map, directed_caps_mbps, + LinkTopology, build_device_capacity_map, build_device_link_meta_map, + directed_caps_mbps_with_topology, }; use crate::strategies::full2::graph_mapping::GraphMapping; use crate::strategies::full2::link_mapping::LinkMapping; @@ -1018,6 +1019,9 @@ fn add_device_links_to_graph( ) { let meta_by_id = build_device_link_meta_map(&uisp_data.devices_raw); let caps_by_id = build_device_capacity_map(&uisp_data.devices); + // Build once per import: the site assignment is the primary orientation + // signal; labels remain the fallback for east/west and missing topology. + let topology = LinkTopology::from_uisp_data(&uisp_data.sites, &uisp_data.devices); for link in uisp_data.data_links_raw.iter() { let Some(from_device) = &link.from.device else { @@ -1054,9 +1058,14 @@ fn add_device_links_to_graph( let id_a = from_device.identification.id.as_str(); let id_b = to_device.identification.id.as_str(); - let (cap_ab, cap_ba) = if let Some((cap_ab, cap_ba)) = - directed_caps_mbps(&meta_by_id, &caps_by_id, config, id_a, id_b) - { + let (cap_ab, cap_ba) = if let Some((cap_ab, cap_ba)) = directed_caps_mbps_with_topology( + &meta_by_id, + Some(&topology), + &caps_by_id, + config, + id_a, + id_b, + ) { (cap_ab, cap_ba) } else { warn!( diff --git a/src/rust/uisp_integration/src/strategies/full2/directionality.rs b/src/rust/uisp_integration/src/strategies/full2/directionality.rs index 76aaaf21..d0a0e274 100644 --- a/src/rust/uisp_integration/src/strategies/full2/directionality.rs +++ b/src/rust/uisp_integration/src/strategies/full2/directionality.rs @@ -1,8 +1,126 @@ -use crate::uisp_types::UispDevice; +use crate::uisp_types::{UispDevice, UispSite}; use lqos_config::Config; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use uisp::Device; +/// Site latitude differences below this are treated as east/west (no +/// north/south winner). ~1e-5 degrees is about one metre, so ordinary +/// geocoding noise does not flip a link. +const LATITUDE_EPSILON: f32 = 1e-5; + +#[derive(Debug, Clone)] +struct SiteTopology { + latitude: Option, + parent_id: Option, +} + +/// The UISP site assignment is the orientation signal we trust first. +#[derive(Debug, Clone, Default)] +pub(crate) struct LinkTopology { + site_by_id: HashMap, + site_id_by_device_id: HashMap, +} + +impl LinkTopology { + pub(crate) fn from_uisp_data(sites: &[UispSite], devices: &[UispDevice]) -> Self { + let site_by_id = sites + .iter() + .map(|site| { + ( + site.id.clone(), + SiteTopology { + latitude: site.latitude, + parent_id: site.uisp_parent_id.clone(), + }, + ) + }) + .collect(); + let site_id_by_device_id = devices + .iter() + .filter(|device| !device.site_id.is_empty()) + .map(|device| (device.id.clone(), device.site_id.clone())) + .collect(); + Self { + site_by_id, + site_id_by_device_id, + } + } + + /// Topology-first orientation: + /// 1. parent/upstream site wins; + /// 2. otherwise the northern site wins when there is a real latitude delta; + /// 3. otherwise None, letting the label-based fallback decide. + fn orientation(&self, id_a: &str, id_b: &str) -> Option { + let site_a = self.site_id_by_device_id.get(id_a)?; + let site_b = self.site_id_by_device_id.get(id_b)?; + if site_a == site_b { + return None; + } + if self.is_ancestor(site_a, site_b) { + return Some(LinkOrientation::AIsAp); + } + if self.is_ancestor(site_b, site_a) { + return Some(LinkOrientation::BIsAp); + } + + let lat_a = self.site_by_id.get(site_a)?.latitude?; + let lat_b = self.site_by_id.get(site_b)?.latitude?; + if (lat_a - lat_b).abs() <= LATITUDE_EPSILON { + return None; + } + if lat_a > lat_b { + Some(LinkOrientation::AIsAp) + } else { + Some(LinkOrientation::BIsAp) + } + } + + fn is_ancestor(&self, ancestor: &str, descendant: &str) -> bool { + let mut current = descendant; + let mut seen = HashSet::new(); + loop { + if !seen.insert(current.to_string()) { + return false; + } + let Some(site) = self.site_by_id.get(current) else { + return false; + }; + let Some(parent) = site.parent_id.as_deref() else { + return false; + }; + if parent == ancestor { + return true; + } + current = parent; + } + } + + #[cfg(test)] + fn from_test_sites( + sites: &[(&str, Option, Option<&str>)], + device_sites: &[(&str, &str)], + ) -> Self { + Self { + site_by_id: sites + .iter() + .map(|(id, latitude, parent_id)| { + ( + (*id).to_string(), + SiteTopology { + latitude: *latitude, + parent_id: parent_id.map(str::to_string), + }, + ) + }) + .collect(), + site_id_by_device_id: device_sites + .iter() + .map(|(device, site)| ((*device).to_string(), (*site).to_string())) + .collect(), + } + } +} + #[derive(Debug, Clone)] pub(crate) struct DeviceLinkMeta { pub(crate) ap_device_id: Option, @@ -79,6 +197,21 @@ pub(crate) fn classify_ap_station( id_a: &str, id_b: &str, ) -> Option { + classify_ap_station_with_topology(meta_by_id, None, id_a, id_b) +} + +pub(crate) fn classify_ap_station_with_topology( + meta_by_id: &HashMap, + topology: Option<&LinkTopology>, + id_a: &str, + id_b: &str, +) -> Option { + if let Some(topology) = topology + && let Some(orientation) = topology.orientation(id_a, id_b) + { + return Some(orientation); + } + let meta_a = meta_by_id.get(id_a)?; let meta_b = meta_by_id.get(id_b)?; @@ -154,7 +287,18 @@ pub(crate) fn directed_caps_mbps( id_a: &str, id_b: &str, ) -> Option<(u64, u64)> { - let orientation = classify_ap_station(meta_by_id, id_a, id_b)?; + directed_caps_mbps_with_topology(meta_by_id, None, caps_by_id, config, id_a, id_b) +} + +pub(crate) fn directed_caps_mbps_with_topology( + meta_by_id: &HashMap, + topology: Option<&LinkTopology>, + caps_by_id: &HashMap, + config: &Config, + id_a: &str, + id_b: &str, +) -> Option<(u64, u64)> { + let orientation = classify_ap_station_with_topology(meta_by_id, topology, id_a, id_b)?; let (a_down, a_up) = caps_by_id.get(id_a).copied().unwrap_or(( config.queues.generated_pn_download_mbps, @@ -447,4 +591,154 @@ mod tests { Some(LinkOrientation::BIsAp) ); } + + #[test] + fn topology_north_site_wins_over_inverted_labels() { + // The radio at the northern site is the AP even when both ends carry + // misleading station/AP labels. This is the ISP-reported Wave case. + let a = mk_raw_device("a", Some("station"), Some("sta-ptp"), Some("b")); + let b = mk_raw_device("b", Some("ap"), Some("ap-ptp"), Some("a")); + let meta = build_device_link_meta_map(&[a, b]); + let topology = LinkTopology::from_test_sites( + &[("north", Some(40.0), None), ("south", Some(39.0), None)], + &[("a", "north"), ("b", "south")], + ); + let cfg = Config::default(); + let caps = caps_map(&[("a", 193, 61), ("b", 193, 61)]); + + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::AIsAp) + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "b", "a"), + Some(LinkOrientation::BIsAp) + ); + assert_eq!( + directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "a", "b"), + Some((193, 61)) + ); + assert_eq!( + directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "b", "a"), + Some((61, 193)) + ); + } + + #[test] + fn topology_parent_site_wins_over_north_site_and_labels() { + // Site hierarchy is stronger than latitude: the upstream/parent site is + // the AP even if the child site is further north. + let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); + let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); + let meta = build_device_link_meta_map(&[a, b]); + let topology = LinkTopology::from_test_sites( + &[ + ("parent", Some(39.0), None), + ("child", Some(40.0), Some("parent")), + ], + &[("a", "child"), ("b", "parent")], + ); + let cfg = Config::default(); + let caps = caps_map(&[("a", 193, 61), ("b", 193, 61)]); + + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::BIsAp) + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "b", "a"), + Some(LinkOrientation::AIsAp) + ); + assert_eq!( + directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "a", "b"), + Some((61, 193)) + ); + } + + #[test] + fn east_west_link_falls_back_to_labels() { + // Same latitude (within the epsilon): there is no north/south winner, + // so the existing label policy decides. + let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); + let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); + let meta = build_device_link_meta_map(&[a, b]); + let topology = LinkTopology::from_test_sites( + &[("east", Some(40.0), None), ("west", Some(40.0), None)], + &[("a", "east"), ("b", "west")], + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::AIsAp) + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "b", "a"), + Some(LinkOrientation::BIsAp) + ); + } + + #[test] + fn latitude_noise_does_not_override_labels() { + let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); + let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); + let meta = build_device_link_meta_map(&[a, b]); + let topology = LinkTopology::from_test_sites( + &[ + ("a-site", Some(40.0), None), + ("b-site", Some(40.000001), None), + ], + &[("a", "a-site"), ("b", "b-site")], + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::AIsAp) + ); + } + + #[test] + fn missing_site_coordinates_fall_back_to_labels() { + let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); + let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); + let meta = build_device_link_meta_map(&[a, b]); + let topology = LinkTopology::from_test_sites( + &[("a-site", None, None), ("b-site", None, None)], + &[("a", "a-site"), ("b", "b-site")], + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::AIsAp) + ); + } + + #[test] + fn missing_device_site_assignment_falls_back_to_labels() { + let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); + let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); + let meta = build_device_link_meta_map(&[a, b]); + let topology = + LinkTopology::from_test_sites(&[("a-site", Some(40.0), None)], &[("a", "a-site")]); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::AIsAp) + ); + } + + #[test] + fn parent_cycle_does_not_hang_topology_resolution() { + // Invalid UISP data: both sites point at each other. The visited set + // must break the walk; the first parent edge still gives a stable answer. + let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); + let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); + let meta = build_device_link_meta_map(&[a, b]); + let topology = LinkTopology::from_test_sites( + &[ + ("a-site", Some(39.0), Some("b-site")), + ("b-site", Some(40.0), Some("a-site")), + ], + &[("a", "a-site"), ("b", "b-site")], + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + Some(LinkOrientation::AIsAp) + ); + } } -- knotmirror 0.0.1 From 8a108d09a31cc1d6dc3b33c1f7c5b0ee7551d7c4 Mon Sep 17 00:00:00 2001 From: rchac Date: Sun, 25 Oct 2026 18:55:18 -0600 Subject: [PATCH 2/2] fix(uisp): remove latitude tiebreak and decline invalid cycles Final topology-first orientation: upstream/ancestor wins; peer/same-site falls back to the #1184 labels; both-ancestor (cycle) returns Invalid independent of argument order. Content is the reviewed v3 implementation (directionality.rs sha256 f2d39fc9). --- .../src/strategies/full2/directionality.rs | 191 +++++++----------- 1 file changed, 78 insertions(+), 113 deletions(-) diff --git a/src/rust/uisp_integration/src/strategies/full2/directionality.rs b/src/rust/uisp_integration/src/strategies/full2/directionality.rs index d0a0e274..16418289 100644 --- a/src/rust/uisp_integration/src/strategies/full2/directionality.rs +++ b/src/rust/uisp_integration/src/strategies/full2/directionality.rs @@ -3,14 +3,8 @@ use lqos_config::Config; use std::collections::{HashMap, HashSet}; use uisp::Device; -/// Site latitude differences below this are treated as east/west (no -/// north/south winner). ~1e-5 degrees is about one metre, so ordinary -/// geocoding noise does not flip a link. -const LATITUDE_EPSILON: f32 = 1e-5; - #[derive(Debug, Clone)] struct SiteTopology { - latitude: Option, parent_id: Option, } @@ -29,7 +23,6 @@ impl LinkTopology { ( site.id.clone(), SiteTopology { - latitude: site.latitude, parent_id: site.uisp_parent_id.clone(), }, ) @@ -46,32 +39,30 @@ impl LinkTopology { } } - /// Topology-first orientation: - /// 1. parent/upstream site wins; - /// 2. otherwise the northern site wins when there is a real latitude delta; - /// 3. otherwise None, letting the label-based fallback decide. - fn orientation(&self, id_a: &str, id_b: &str) -> Option { - let site_a = self.site_id_by_device_id.get(id_a)?; - let site_b = self.site_id_by_device_id.get(id_b)?; + /// Topology-first orientation: only the upstream/parent site wins. + /// Peer and same-site links return None so the label-based fallback + /// (#1184) decides. Invalid data with both ancestry directions true also + /// returns None, independent of argument order. + fn orientation(&self, id_a: &str, id_b: &str) -> TopologyDecision { + let Some(site_a) = self.site_id_by_device_id.get(id_a) else { + return TopologyDecision::Fallback; + }; + let Some(site_b) = self.site_id_by_device_id.get(id_b) else { + return TopologyDecision::Fallback; + }; if site_a == site_b { - return None; - } - if self.is_ancestor(site_a, site_b) { - return Some(LinkOrientation::AIsAp); + return TopologyDecision::Fallback; } - if self.is_ancestor(site_b, site_a) { - return Some(LinkOrientation::BIsAp); - } - - let lat_a = self.site_by_id.get(site_a)?.latitude?; - let lat_b = self.site_by_id.get(site_b)?.latitude?; - if (lat_a - lat_b).abs() <= LATITUDE_EPSILON { - return None; - } - if lat_a > lat_b { - Some(LinkOrientation::AIsAp) - } else { - Some(LinkOrientation::BIsAp) + match ( + self.is_ancestor(site_a, site_b), + self.is_ancestor(site_b, site_a), + ) { + (true, false) => TopologyDecision::Resolved(LinkOrientation::AIsAp), + (false, true) => TopologyDecision::Resolved(LinkOrientation::BIsAp), + // Both directions true is invalid UISP data; declining keeps the + // answer independent of argument order. + (true, true) => TopologyDecision::Invalid, + (false, false) => TopologyDecision::Fallback, } } @@ -96,18 +87,14 @@ impl LinkTopology { } #[cfg(test)] - fn from_test_sites( - sites: &[(&str, Option, Option<&str>)], - device_sites: &[(&str, &str)], - ) -> Self { + fn from_test_sites(sites: &[(&str, Option<&str>)], device_sites: &[(&str, &str)]) -> Self { Self { site_by_id: sites .iter() - .map(|(id, latitude, parent_id)| { + .map(|(id, parent_id)| { ( (*id).to_string(), SiteTopology { - latitude: *latitude, parent_id: parent_id.map(str::to_string), }, ) @@ -134,6 +121,15 @@ pub(crate) enum LinkOrientation { BIsAp, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum TopologyDecision { + Resolved(LinkOrientation), + /// No topology answer; let the #1184 label classifier decide. + Fallback, + /// Invalid/ambiguous topology; decline rather than fall through to labels. + Invalid, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum RadioRole { Ap, @@ -206,10 +202,12 @@ pub(crate) fn classify_ap_station_with_topology( id_a: &str, id_b: &str, ) -> Option { - if let Some(topology) = topology - && let Some(orientation) = topology.orientation(id_a, id_b) - { - return Some(orientation); + if let Some(topology) = topology { + match topology.orientation(id_a, id_b) { + TopologyDecision::Resolved(orientation) => return Some(orientation), + TopologyDecision::Invalid => return None, + TopologyDecision::Fallback => {} + } } let meta_a = meta_by_id.get(id_a)?; @@ -593,53 +591,19 @@ mod tests { } #[test] - fn topology_north_site_wins_over_inverted_labels() { - // The radio at the northern site is the AP even when both ends carry - // misleading station/AP labels. This is the ISP-reported Wave case. - let a = mk_raw_device("a", Some("station"), Some("sta-ptp"), Some("b")); - let b = mk_raw_device("b", Some("ap"), Some("ap-ptp"), Some("a")); - let meta = build_device_link_meta_map(&[a, b]); - let topology = LinkTopology::from_test_sites( - &[("north", Some(40.0), None), ("south", Some(39.0), None)], - &[("a", "north"), ("b", "south")], - ); - let cfg = Config::default(); - let caps = caps_map(&[("a", 193, 61), ("b", 193, 61)]); - - assert_eq!( - classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), - Some(LinkOrientation::AIsAp) - ); - assert_eq!( - classify_ap_station_with_topology(&meta, Some(&topology), "b", "a"), - Some(LinkOrientation::BIsAp) - ); - assert_eq!( - directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "a", "b"), - Some((193, 61)) - ); - assert_eq!( - directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "b", "a"), - Some((61, 193)) - ); - } - - #[test] - fn topology_parent_site_wins_over_north_site_and_labels() { - // Site hierarchy is stronger than latitude: the upstream/parent site is - // the AP even if the child site is further north. + fn upstream_site_wins_over_conflicting_labels() { + // The parent/upstream site is the AP even when its device is labelled + // station and the child device is labelled AP. Asymmetric capacities + // prove that the selected end's capacity tuple is used. let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); let meta = build_device_link_meta_map(&[a, b]); let topology = LinkTopology::from_test_sites( - &[ - ("parent", Some(39.0), None), - ("child", Some(40.0), Some("parent")), - ], + &[("parent", None), ("child", Some("parent"))], &[("a", "child"), ("b", "parent")], ); let cfg = Config::default(); - let caps = caps_map(&[("a", 193, 61), ("b", 193, 61)]); + let caps = caps_map(&[("a", 50, 20), ("b", 193, 61)]); assert_eq!( classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), @@ -651,20 +615,24 @@ mod tests { ); assert_eq!( directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "a", "b"), - Some((61, 193)) + Some((20, 50)) + ); + assert_eq!( + directed_caps_mbps_with_topology(&meta, Some(&topology), &caps, &cfg, "b", "a"), + Some((50, 20)) ); } #[test] - fn east_west_link_falls_back_to_labels() { - // Same latitude (within the epsilon): there is no north/south winner, - // so the existing label policy decides. + fn peer_sites_fall_back_to_labels() { + // Neither site is upstream. Site assignment alone must not orient the + // link; the #1184 label classifier decides. let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); let meta = build_device_link_meta_map(&[a, b]); let topology = LinkTopology::from_test_sites( - &[("east", Some(40.0), None), ("west", Some(40.0), None)], - &[("a", "east"), ("b", "west")], + &[("north-site", None), ("south-site", None)], + &[("a", "north-site"), ("b", "south-site")], ); assert_eq!( classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), @@ -677,16 +645,13 @@ mod tests { } #[test] - fn latitude_noise_does_not_override_labels() { + fn same_site_assignment_falls_back_to_labels() { let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); let meta = build_device_link_meta_map(&[a, b]); let topology = LinkTopology::from_test_sites( - &[ - ("a-site", Some(40.0), None), - ("b-site", Some(40.000001), None), - ], - &[("a", "a-site"), ("b", "b-site")], + &[("same-site", None)], + &[("a", "same-site"), ("b", "same-site")], ); assert_eq!( classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), @@ -695,16 +660,22 @@ mod tests { } #[test] - fn missing_site_coordinates_fall_back_to_labels() { - let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); - let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); - let meta = build_device_link_meta_map(&[a, b]); + fn ap_south_of_station_resolves_by_labels() { + // Regression for the removed geographic rule: the southern peer is the + // AP here, and labels must resolve it in both argument orders. + let station = mk_raw_device("station", Some("station"), Some("sta-ptp"), None); + let ap = mk_raw_device("ap", Some("ap"), Some("ap-ptp"), None); + let meta = build_device_link_meta_map(&[station, ap]); let topology = LinkTopology::from_test_sites( - &[("a-site", None, None), ("b-site", None, None)], - &[("a", "a-site"), ("b", "b-site")], + &[("north-site", None), ("south-site", None)], + &[("station", "north-site"), ("ap", "south-site")], ); assert_eq!( - classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), + classify_ap_station_with_topology(&meta, Some(&topology), "station", "ap"), + Some(LinkOrientation::BIsAp) + ); + assert_eq!( + classify_ap_station_with_topology(&meta, Some(&topology), "ap", "station"), Some(LinkOrientation::AIsAp) ); } @@ -714,8 +685,7 @@ mod tests { let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); let meta = build_device_link_meta_map(&[a, b]); - let topology = - LinkTopology::from_test_sites(&[("a-site", Some(40.0), None)], &[("a", "a-site")]); + let topology = LinkTopology::from_test_sites(&[("a-site", None)], &[("a", "a-site")]); assert_eq!( classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), Some(LinkOrientation::AIsAp) @@ -723,22 +693,17 @@ mod tests { } #[test] - fn parent_cycle_does_not_hang_topology_resolution() { - // Invalid UISP data: both sites point at each other. The visited set - // must break the walk; the first parent edge still gives a stable answer. + fn parent_cycle_returns_none_both_orders() { + // Invalid UISP data: both sites point at each other. Topology must + // decline rather than let argument order choose a winner. let a = mk_raw_device("a", Some("ap"), Some("ap-ptp"), None); let b = mk_raw_device("b", Some("station"), Some("sta-ptp"), None); let meta = build_device_link_meta_map(&[a, b]); let topology = LinkTopology::from_test_sites( - &[ - ("a-site", Some(39.0), Some("b-site")), - ("b-site", Some(40.0), Some("a-site")), - ], + &[("a-site", Some("b-site")), ("b-site", Some("a-site"))], &[("a", "a-site"), ("b", "b-site")], ); - assert_eq!( - classify_ap_station_with_topology(&meta, Some(&topology), "a", "b"), - Some(LinkOrientation::AIsAp) - ); + assert!(classify_ap_station_with_topology(&meta, Some(&topology), "a", "b").is_none()); + assert!(classify_ap_station_with_topology(&meta, Some(&topology), "b", "a").is_none()); } }