use crate::{
core::{
debug::Annotations,
layout::{BitRange, Layout},
},
dataplane_path::{
onehop::layout::OneHopPathLayout,
standard::layout::{StdPathDataLayout, StdPathMetaLayout},
types::PathType,
},
header::layout::{AddressHeaderLayout, CommonHeaderLayout, ScionHeaderLayout},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ScionHeaderPathLayout {
Standard(StdPathMetaLayout, StdPathDataLayout),
OneHop(OneHopPathLayout),
Empty,
Unknown {
path_type: PathType,
range: BitRange,
},
}
impl ScionHeaderPathLayout {
pub const MAX_SIZE_BYTES: usize = ScionHeaderLayout::MAX_SIZE_BYTES
- CommonHeaderLayout::SIZE_BYTES
- AddressHeaderLayout::MIN_SIZE_BYTES;
#[inline]
pub const fn path_type(&self) -> PathType {
match self {
ScionHeaderPathLayout::Standard(..) => PathType::Scion,
ScionHeaderPathLayout::OneHop(_) => PathType::OneHop,
ScionHeaderPathLayout::Empty => PathType::Empty,
ScionHeaderPathLayout::Unknown { path_type, .. } => *path_type,
}
}
#[inline]
pub fn annotations(&self) -> Annotations {
let mut annotations = Annotations::new();
match self {
ScionHeaderPathLayout::Standard(meta_layout, data_layout) => {
annotations.extend(meta_layout.annotations());
annotations.extend(data_layout.annotations());
}
ScionHeaderPathLayout::OneHop(layout) => {
annotations.extend(layout.annotations());
}
ScionHeaderPathLayout::Empty => {}
ScionHeaderPathLayout::Unknown { range, .. } => {
annotations.add("Unknown Path".to_string(), vec![(*range, "unknown")])
}
};
annotations
}
}
impl Layout for ScionHeaderPathLayout {
#[inline]
fn size_bytes(&self) -> usize {
match self {
ScionHeaderPathLayout::Standard(meta, data_layout) => {
meta.size_bytes() + data_layout.size_bytes()
}
ScionHeaderPathLayout::OneHop(onehop_layout) => onehop_layout.size_bytes(),
ScionHeaderPathLayout::Empty => 0,
ScionHeaderPathLayout::Unknown { range, .. } => range.size_bytes(),
}
}
}
impl From<StdPathDataLayout> for ScionHeaderPathLayout {
#[inline]
fn from(data_layout: StdPathDataLayout) -> Self {
ScionHeaderPathLayout::Standard(StdPathMetaLayout, data_layout)
}
}