Function fcp_switching::operation::switch [] [src]

pub fn switch(
    label: &Label,
    director_length: u8,
    reversed_origin_iface: &Director
) -> (Label, RoutingDecision)

Performs a switch operation on the label (using constant director length), as defined by https://github.com/cjdelisle/cjdns/blob/cjdns-v17.4/doc/Whitepaper.md#operation : extracts the director and shifts the other bits to the right, and put the reversed origin interface at the left of the label

Examples

Canonical case, inspired from https://github.com/cjdelisle/cjdns/blob/cjdns-v17.4/doc/Whitepaper.md#example :

let mut label: Label = label_from_u64(0b000000000000000000000000000000000_0001_011010_100101101_10111_0100011);

let (label, decision) = switch(&label, 7, &0b1000000);
assert_eq!(RoutingDecision::Forward(0b0100011), decision);
assert_eq!(0b1000000_000000000000000000000000000000000_0001_011010_100101101_10111, u64_from_label(label));

let (label, decision) = switch(&label, 5, &0b11001);
assert_eq!(RoutingDecision::Forward(0b10111), decision);
assert_eq!(0b11001_1000000_000000000000000000000000000000000_0001_011010_100101101, u64_from_label(label));

let (label, decision) = switch(&label, 9, &0b110110011);
assert_eq!(RoutingDecision::Forward(0b100101101), decision);
assert_eq!(0b110110011_11001_1000000_000000000000000000000000000000000_0001_011010, u64_from_label(label));

let (label, decision) = switch(&label, 6, &0b010101);
assert_eq!(RoutingDecision::Forward(0b011010), decision);
assert_eq!(0b010101_110110011_11001_1000000_000000000000000000000000000000000_0001, u64_from_label(label));

let (label, decision) = switch(&label, 4, &0b0110);
assert_eq!(RoutingDecision::SelfInterface(0b0001), decision);
assert_eq!(0b0110_010101_110110011_11001_1000000_000000000000000000000000000000000, u64_from_label(label));

Supports non-canonical self-interfaces:

let label: Label = label_from_u64(0b010101_110110011_11001_1000000_0000000000000000000000000000000_110001);
let (label, decision) = switch(&label, 6, &0b100110);
assert_eq!(RoutingDecision::SelfInterface(0b110001), decision);
assert_eq!(0b100110_010101_110110011_11001_1000000_0000000000000000000000000000000, u64_from_label(label));