diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-26 20:29:00 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-26 20:29:00 +0200 |
commit | ad2d7d2e0d71d9ce530dead21ac9b70f3f678911 (patch) | |
tree | 6235c9e9b1782e62d0672ea4cfe3a310670a0ba1 /src | |
parent | b3be3cf5af2e4d8498c88360c61f7cf0c17c9ceb (diff) |
add IPv6CP (de)serialization tests
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 340 |
1 files changed, 340 insertions, 0 deletions
@@ -1614,4 +1614,344 @@ mod tests { ); Ok(()) } + + #[test] + fn test_serialize_ipv6cp_configure_request() -> Result<()> { + let configure_request = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_request( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()], + )), + ); + + let mut buf = Vec::new(); + configure_request.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x01, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_configure_request() -> Result<()> { + let mut configure_request = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x01, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, + ]; + configure_request.deserialize(&mut buf.as_ref())?; + + assert_eq!( + configure_request, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_request( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()] + )) + ) + ); + Ok(()) + } + + #[test] + fn test_serialize_ipv6cp_configure_ack() -> Result<()> { + let configure_ack = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_ack( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()], + )), + ); + + let mut buf = Vec::new(); + configure_ack.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x02, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_configure_ack() -> Result<()> { + let mut configure_ack = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x02, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, + ]; + configure_ack.deserialize(&mut buf.as_ref())?; + + assert_eq!( + configure_ack, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_ack( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()] + )) + ) + ); + Ok(()) + } + + #[test] + fn test_serialize_ipv6cp_configure_nak() -> Result<()> { + let configure_nak = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_nak( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()], + )), + ); + + let mut buf = Vec::new(); + configure_nak.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x03, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_configure_nak() -> Result<()> { + let mut configure_nak = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x03, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, + ]; + configure_nak.deserialize(&mut buf.as_ref())?; + + assert_eq!( + configure_nak, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_nak( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()] + )) + ) + ); + Ok(()) + } + + #[test] + fn test_serialize_ipv6cp_configure_reject() -> Result<()> { + let configure_reject = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_reject( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()], + )), + ); + + let mut buf = Vec::new(); + configure_reject.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x04, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_configure_reject() -> Result<()> { + let mut configure_reject = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x10, 0x80, 0x57, 0x04, 0x41, 0x00, 0x0e, 0x01, 0x0a, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, + ]; + configure_reject.deserialize(&mut buf.as_ref())?; + + assert_eq!( + configure_reject, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_configure_reject( + 0x41, + vec![Ipv6cpOpt::InterfaceId(0x7766554433221100).into()] + )) + ) + ); + Ok(()) + } + + #[test] + fn test_serialize_ipv6cp_terminate_request() -> Result<()> { + let terminate_request = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_terminate_request(0x41, vec![0x13, 0x37])), + ); + + let mut buf = Vec::new(); + terminate_request.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0x57, 0x05, 0x41, 0x00, 0x06, 0x13, 0x37 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_terminate_request() -> Result<()> { + let mut terminate_request = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0x57, 0x05, 0x41, 0x00, 0x08, 0x13, 0x37, + ]; + terminate_request.deserialize(&mut buf.as_ref())?; + + assert_eq!( + terminate_request, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_terminate_request(0x41, vec![0x13, 0x37])) + ) + ); + Ok(()) + } + + #[test] + fn test_serialize_ipv6cp_terminate_ack() -> Result<()> { + let terminate_ack = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_terminate_ack(0x41, vec![0x13, 0x37])), + ); + + let mut buf = Vec::new(); + terminate_ack.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0x57, 0x06, 0x41, 0x00, 0x06, 0x13, 0x37 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_terminate_ack() -> Result<()> { + let mut terminate_ack = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0x57, 0x06, 0x41, 0x00, 0x06, 0x13, 0x37, + ]; + terminate_ack.deserialize(&mut buf.as_ref())?; + + assert_eq!( + terminate_ack, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_terminate_ack(0x41, vec![0x13, 0x37])) + ) + ); + Ok(()) + } + + #[test] + fn test_serialize_ipv6cp_code_reject() -> Result<()> { + let code_reject = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_code_reject(0x41, vec![0x13, 0x37])), + ); + + let mut buf = Vec::new(); + code_reject.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0x57, 0x07, 0x41, 0x00, 0x06, 0x13, 0x37 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipv6cp_code_reject() -> Result<()> { + let mut code_reject = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0x57, 0x07, 0x41, 0x00, 0x06, 0x13, 0x37, + ]; + code_reject.deserialize(&mut buf.as_ref())?; + + assert_eq!( + code_reject, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipv6cp(Ipv6cpPkt::new_code_reject(0x41, vec![0x13, 0x37])) + ) + ); + Ok(()) + } } |