use netlink_packet_core::{Emitable, Parseable};
use crate::{
link::{
link_flag::LinkFlags, InfoData, InfoKind, InfoVlan, LinkAttribute,
LinkHeader, LinkInfo, LinkLayerType, LinkMessage, LinkMessageBuffer,
VlanFlags, VlanProtocol, VlanQosMapping,
},
AddressFamily,
};
#[test]
fn test_parsing_link_vlan() {
let raw = vec![
0x00, 0x00, 0x01, 0x00, 0x22, 0x00, 0x00, 0x00, 0x43, 0x10, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x12, 0x00, 0x09, 0x00, 0x01, 0x00, 0x76, 0x6c, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x06, 0x00, 0x05, 0x00, 0x81, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x65, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, ];
let expected = LinkMessage {
header: LinkHeader {
interface_family: AddressFamily::Unspec,
index: 34,
link_layer_type: LinkLayerType::Ether,
flags: LinkFlags::Broadcast
| LinkFlags::LowerUp
| LinkFlags::Multicast
| LinkFlags::Running
| LinkFlags::Up,
change_mask: LinkFlags::empty(),
},
attributes: vec![LinkAttribute::LinkInfo(vec![
LinkInfo::Kind(InfoKind::Vlan),
LinkInfo::Data(InfoData::Vlan(vec![
InfoVlan::Protocol(VlanProtocol::Ieee8021Q),
InfoVlan::Id(101),
InfoVlan::Flags((VlanFlags::ReorderHdr, VlanFlags::all())),
InfoVlan::IngressQos(vec![VlanQosMapping::Mapping(6, 7)]),
InfoVlan::EgressQos(vec![VlanQosMapping::Mapping(4, 5)]),
])),
])],
};
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);
}