Skip to content

Commit

Permalink
feat(scmp): add enums for error and info messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mlegner committed Feb 7, 2024
1 parent e9d674c commit 74e09d3
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 99 deletions.
19 changes: 15 additions & 4 deletions crates/scion-proto/src/packet/scmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::{
error::ScmpEncodeError,
FlowId,
InadequateBufferSize,
MessageChecksum,
ScionHeaders,
ScionPacket,
ScionPacketRaw,
Expand All @@ -14,7 +15,14 @@ use crate::{
address::ScionAddr,
packet::ByEndpoint,
path::{DataplanePath, Path},
scmp::{ScmpDecodeError, ScmpMessage, ScmpTracerouteRequest, ScmpType, SCMP_PROTOCOL_NUMBER},
scmp::{
ScmpDecodeError,
ScmpMessage,
ScmpMessageBase,
ScmpTracerouteRequest,
ScmpType,
SCMP_PROTOCOL_NUMBER,
},
wire_encoding::{WireDecode, WireEncodeVec},
};

Expand All @@ -27,11 +35,14 @@ pub struct ScionPacketScmp {
pub message: ScmpMessage,
}

impl ScionPacketScmp {
/// Returns the SCMP message type.
pub fn get_type(&self) -> ScmpType {
impl ScmpMessageBase for ScionPacketScmp {
fn get_type(&self) -> ScmpType {
self.message.get_type()
}

fn code(&self) -> u8 {
self.message.code()
}
}

impl ScionPacketScmp {
Expand Down
10 changes: 10 additions & 0 deletions crates/scion-proto/src/scmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ pub trait ScmpMessageBase {
fn code(&self) -> u8 {
0
}

/// Returns true iff `self` is an error message.
fn is_error(&self) -> bool {
self.get_type().is_error()
}

/// Returns true iff `self` is an informational message.
fn is_informational(&self) -> bool {
self.get_type().is_informational()
}
}

/// SCION protocol number for SCMP.
Expand Down
Loading

0 comments on commit 74e09d3

Please sign in to comment.