use netlink_packet_core::{Emitable, Parseable};
use crate::{
link::{
link_flag::LinkFlags, InfoBatAdv, InfoData, InfoKind, LinkAttribute,
LinkHeader, LinkInfo, LinkLayerType, LinkMessage, LinkMessageBuffer,
},
AddressFamily,
};
#[test]
fn test_parsing_link_batadv_with_ra() {
#[rustfmt::skip]
let raw = vec![
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x09, 0x00, 0x03, 0x00,
0x62, 0x61, 0x74, 0x30,
0x00, 0x00, 0x00, 0x00,
0x24, 0x00, 0x12, 0x00,
0x0b, 0x00, 0x01, 0x00,
0x62, 0x61, 0x74, 0x61,
0x64, 0x76, 0x00, 0x00,
0x14, 0x00, 0x02, 0x00,
0x0e, 0x00, 0x01, 0x00,
0x42, 0x41, 0x54, 0x4d,
0x41, 0x4e, 0x5f, 0x49,
0x56, 0x00, 0x00, 0x00,
];
let expected = LinkMessage {
header: LinkHeader {
interface_family: AddressFamily::Unspec,
index: 0,
link_layer_type: LinkLayerType::default(),
flags: LinkFlags::empty(),
change_mask: LinkFlags::empty(),
},
attributes: vec![
LinkAttribute::IfName("bat0".to_string()),
LinkAttribute::LinkInfo(vec![
LinkInfo::Kind(InfoKind::BatAdv),
LinkInfo::Data(InfoData::BatAdv(vec![InfoBatAdv::AlgoName(
"BATMAN_IV".to_string(),
)])),
]),
],
};
assert_eq!(
expected,
LinkMessage::parse(&LinkMessageBuffer::new(&raw)).unwrap()
);
let mut buf = vec![0; expected.buffer_len()];
expected.emit(&mut buf);
assert_eq!(buf, raw);
}