Skip to content

Commit

Permalink
test: use raw socket in SCMP integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
mlegner committed Jan 24, 2024
1 parent 8db3d9d commit 4e9eb4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/scion-proto/src/packet/scmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<T: Buf> WireDecode<T> for ScionPacketScmp {
}
}

impl WireEncodeVec<3> for ScionPacketScmp {
impl WireEncodeVec<3> for &ScionPacketScmp {
type Error = InadequateBufferSize;

fn encode_with_unchecked(&self, buffer: &mut bytes::BytesMut) -> [Bytes; 3] {
Expand Down
4 changes: 2 additions & 2 deletions crates/scion-proto/src/scmp/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ impl TryFrom<ScmpMessageRaw> for ScmpMessage {
}
}

impl WireDecode<Bytes> for ScmpMessage {
impl<T: Buf> WireDecode<T> for ScmpMessage {
type Error = ScmpDecodeError;

fn decode(data: &mut Bytes) -> Result<Self, Self::Error> {
fn decode(data: &mut T) -> Result<Self, Self::Error> {
ScmpMessageRaw::decode(data)?.try_into()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use scion::{
daemon::{get_daemon_address, DaemonClient},
dispatcher::{get_dispatcher_path, DispatcherStream},
socket::RawSocket,
};
use scion_proto::{
address::{ScionAddr, SocketAddr},
Expand All @@ -21,6 +21,8 @@ async fn scmp_traceroute() -> TestResult {
source: "1-ff00:0:111,127.0.0.17".parse().unwrap(),
destination: "1-ff00:0:112,::1".parse().unwrap(),
};

let (raw_socket, _port) = RawSocket::bind(SocketAddr::new(endpoints.source, 0)).await?;
let daemon_client = DaemonClient::connect(&get_daemon_address())
.await
.expect("should be able to connect");
Expand All @@ -31,21 +33,17 @@ async fn scmp_traceroute() -> TestResult {
.unwrap();
println!("Forward path: {:?}", path_forward.dataplane_path);

let mut stream = DispatcherStream::connect(get_dispatcher_path()).await?;
let _local_address = stream
.register(SocketAddr::new(endpoints.source, 0))
.await?;

let request = ScionPacketScmp::new_traceroute_request(&endpoints, &path_forward, 1, 1, 3)?;

stream
.send_packet_via(path_forward.underlay_next_hop, request.clone())
raw_socket
.send_packet_via(path_forward.underlay_next_hop, &request)
.await?;

let mut packet = tokio::time::timeout(TIMEOUT, stream.receive_packet()).await??;
let scion_packet_scmp = ScionPacketScmp::decode(&mut packet.content)?;
let scmp_message = scion_packet_scmp.message;
assert!(scmp_message.verify_checksum(&scion_packet_scmp.headers.address));
let mut buffer = [0_u8; 1500];

let (payload_length, _common_header, address_header) =
tokio::time::timeout(TIMEOUT, raw_socket.recv_with_headers(&mut buffer)).await??;
let scmp_message = ScmpMessage::decode(&mut buffer[..payload_length].as_ref())?;
assert!(scmp_message.verify_checksum(&address_header));

let ScmpMessage::TracerouteReply(reply) = scmp_message else {
panic!("Unexpected SCMP reply received.")
Expand Down

0 comments on commit 4e9eb4e

Please sign in to comment.