pub mod encode;
pub mod scmp;
pub mod udp;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum ProtocolNumber {
Tcp = 6,
Udp = 17,
Hbh = 43,
E2e = 201,
Scmp = 202,
Bfd = 203,
Other(u8),
}
impl From<u8> for ProtocolNumber {
fn from(value: u8) -> Self {
match value {
6 => ProtocolNumber::Tcp,
43 => ProtocolNumber::Hbh,
201 => ProtocolNumber::E2e,
17 => ProtocolNumber::Udp,
202 => ProtocolNumber::Scmp,
203 => ProtocolNumber::Bfd,
other => ProtocolNumber::Other(other),
}
}
}
impl From<ProtocolNumber> for u8 {
fn from(value: ProtocolNumber) -> Self {
match value {
ProtocolNumber::Tcp => 6,
ProtocolNumber::Udp => 17,
ProtocolNumber::Hbh => 43,
ProtocolNumber::E2e => 201,
ProtocolNumber::Scmp => 202,
ProtocolNumber::Bfd => 203,
ProtocolNumber::Other(other) => other,
}
}
}
#[cfg(feature = "proptest")]
pub mod ptest {
use ::proptest::prelude::*;
use super::*;
#[derive(Debug, Clone)]
pub struct ArbitraryProtocolNumberParams {
pub tcp: u32,
pub udp: u32,
pub hbh: u32,
pub e2e: u32,
pub scmp: u32,
pub bfd: u32,
pub other: u32,
}
impl Default for ArbitraryProtocolNumberParams {
fn default() -> Self {
Self {
tcp: 1,
udp: 1,
hbh: 1,
e2e: 1,
scmp: 1,
bfd: 1,
other: 1,
}
}
}
impl Arbitrary for ProtocolNumber {
type Parameters = ArbitraryProtocolNumberParams;
type Strategy = BoxedStrategy<Self>;
fn arbitrary_with(params: Self::Parameters) -> Self::Strategy {
prop_oneof![
params.tcp => Just(ProtocolNumber::Tcp),
params.udp => Just(ProtocolNumber::Udp),
params.hbh => Just(ProtocolNumber::Hbh),
params.e2e => Just(ProtocolNumber::E2e),
params.scmp => Just(ProtocolNumber::Scmp),
params.bfd => Just(ProtocolNumber::Bfd),
params.other => any::<u8>().prop_map(|v| {
let mut v = v;
while !matches!(ProtocolNumber::from(v), ProtocolNumber::Other(_)) {
v = v.wrapping_add(1);
}
ProtocolNumber::Other(v)
}),
]
.boxed()
}
}
}