use icenet_core::{LinkKind, NodeId, TrafficClass}; use icenet_routing::{Link, choose_path}; #[test] fn bulk_never_uses_slow_radio() { let nodes = [NodeId(1), NodeId(2), NodeId(3)]; let links = [ Link { a: nodes[0], b: nodes[1], kind: LinkKind::SlowRadio, enabled: true, }, Link { a: nodes[1], b: nodes[2], kind: LinkKind::SlowRadio, enabled: true, }, ]; assert!( choose_path( &nodes, &links, nodes[0], nodes[2], TrafficClass::Bulk, 50_000 ) .is_none() ); assert!(choose_path(&nodes, &links, nodes[0], nodes[2], TrafficClass::Text, 10).is_some()); } #[test] fn chooses_fast_route_when_bulk_is_allowed() { let nodes = [NodeId(1), NodeId(2), NodeId(3)]; let links = [ Link { a: nodes[0], b: nodes[1], kind: LinkKind::FastWireless, enabled: true, }, Link { a: nodes[1], b: nodes[2], kind: LinkKind::Wired, enabled: true, }, ]; let chosen = choose_path( &nodes, &links, nodes[0], nodes[2], TrafficClass::Bulk, 5_000_000, ); assert_eq!(chosen.expect("connected").nodes, nodes); } #[test] fn disabled_bridge_breaks_route() { let nodes = [NodeId(1), NodeId(2)]; let links = [Link { a: nodes[0], b: nodes[1], kind: LinkKind::Wired, enabled: false, }]; assert!(choose_path(&nodes, &links, nodes[0], nodes[1], TrafficClass::Text, 5).is_none()); } #[test] fn equal_cost_paths_use_a_stable_lexicographic_tie_break() { let nodes = [NodeId(1), NodeId(2), NodeId(3), NodeId(4)]; let forward = [ Link { a: nodes[0], b: nodes[1], kind: LinkKind::Wired, enabled: true, }, Link { a: nodes[1], b: nodes[3], kind: LinkKind::Wired, enabled: true, }, Link { a: nodes[0], b: nodes[2], kind: LinkKind::Wired, enabled: true, }, Link { a: nodes[2], b: nodes[3], kind: LinkKind::Wired, enabled: true, }, ]; let mut reversed = forward; reversed.reverse(); for links in [&forward, &reversed] { let path = choose_path(&nodes, links, nodes[0], nodes[3], TrafficClass::Text, 10) .expect("diamond is connected"); assert_eq!(path.nodes, [NodeId(1), NodeId(2), NodeId(4)]); } }