use sciparse::{
address::socket_addr::ScionSocketAddr,
core::{encode::WireEncode, view::View},
dataplane_path::model::DpPath,
packet::{classify::ClassifiedPacketView, model::ScionUdpPacket, view::ScionRawPacketView},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let buf = ScionUdpPacket::new(
"[1-1,2.2.2.2]:1234".parse::<ScionSocketAddr>()?,
"[1-1,3.3.3.3]:5678".parse::<ScionSocketAddr>()?,
DpPath::Empty, b"payload".to_vec(),
)
.try_encode_to_vec()?;
let (packet, _rest): (&ScionRawPacketView, &[u8]) = ScionRawPacketView::try_from_slice(&buf)?;
match packet.header().next_header() {
sciparse::payload::ProtocolNumber::Udp => {
let udp_packet = packet.try_as_udp()?;
println!("Received a UDP packet: {:?}", udp_packet);
}
sciparse::payload::ProtocolNumber::Scmp => {
let scmp_packet = packet.try_as_scmp()?;
println!("Received a SCMP packet: {:?}", scmp_packet);
}
sciparse::payload::ProtocolNumber::Tcp => {
println!("Received a TCP packet: {:?}", packet);
}
sciparse::payload::ProtocolNumber::Hbh => {
println!("Received a HBH packet extension: {:?}", packet);
}
sciparse::payload::ProtocolNumber::E2e => {
println!("Received an E2E packet extension: {:?}", packet);
}
sciparse::payload::ProtocolNumber::Bfd => {
println!("Received a BFD packet extension: {:?}", packet);
}
sciparse::payload::ProtocolNumber::Other(_) => {
println!("Received a packet with unknown next header: {:?}", packet);
}
}
match packet.try_classify()? {
ClassifiedPacketView::Udp(udp) => {
println!("Received a UDP packet: {:?}", udp);
}
ClassifiedPacketView::Scmp(scmp) => {
println!("Received a SCMP packet: {:?}", scmp);
}
ClassifiedPacketView::Other(scion_packet_view) => {
println!(
"Received packet with unexpected next header: {:?}",
scion_packet_view
);
}
}
Ok(())
}