Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scmp): add enums for error and info messages #141

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading