1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![deny(missing_docs)]
use crate::{EncodingScheme, LabelBits, RoutingLabel};
#[derive(Debug, PartialEq, Eq)]
pub struct PathHop<'a, L: LabelBits> {
pub label_p: Option<RoutingLabel<L>>,
pub label_n: Option<RoutingLabel<L>>,
pub encoding_scheme: &'a EncodingScheme,
}
impl<'a, L: LabelBits> PathHop<'a, L> {
pub fn new(label_p: Option<RoutingLabel<L>>, label_n: Option<RoutingLabel<L>>, encoding_scheme: &'a EncodingScheme) -> Self {
PathHop {
label_p,
label_n,
encoding_scheme,
}
}
}
#[cfg(test)]
mod tests {
use crate::{schemes, EncodingScheme, LabelBits, PathHop, RoutingLabel};
fn hop<L: LabelBits>(label_p_bits: L, label_n_bits: L, encoding_scheme: &EncodingScheme) -> PathHop<L> {
let label_p = RoutingLabel::try_new(label_p_bits);
let label_n = RoutingLabel::try_new(label_n_bits);
PathHop::new(label_p, label_n, encoding_scheme)
}
#[test]
fn path_hop_creation() {
assert_eq!(
hop(2_u64, 2_u64, &schemes::V358),
PathHop {
label_p: Some(RoutingLabel::try_new(2_u64).expect("bad test data")),
label_n: Some(RoutingLabel::try_new(2_u64).expect("bad test data")),
encoding_scheme: &schemes::V358,
}
);
assert_eq!(
hop(0_u64, 2_u64, &schemes::V358),
PathHop {
label_p: None,
label_n: Some(RoutingLabel::try_new(2_u64).expect("bad test data")),
encoding_scheme: &schemes::V358,
}
);
assert_eq!(
hop(3_u64, 0_u64, &schemes::V358),
PathHop {
label_p: Some(RoutingLabel::try_new(3_u64).expect("bad test data")),
label_n: None,
encoding_scheme: &schemes::V358,
}
);
}
}