Skip to content

Commit

Permalink
feat: add sequence number custom column (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Feb 1, 2024
1 parent fc56ff0 commit 1fac330
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/backend/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ pub struct Hop {
last_src_port: u16,
/// The destination port for last probe for this hop.
last_dest_port: u16,
/// The sequence number for the last probe for this hop.
last_sequence: u16,
/// The history of round trip times across the last N rounds.
samples: Vec<Duration>,
/// The ICMP extensions for this hop.
Expand Down Expand Up @@ -252,14 +254,21 @@ impl Hop {
self.jinta
}

/// The source port for last probe for this hop.
pub fn last_src_port(&self) -> u16 {
self.last_src_port
}

/// The destination port for last probe for this hop.
pub fn last_dest_port(&self) -> u16 {
self.last_dest_port
}

/// The sequence number for the last probe for this hop.
pub fn last_sequence(&self) -> u16 {
self.last_sequence
}

/// The last N samples.
pub fn samples(&self) -> &[Duration] {
&self.samples
Expand Down Expand Up @@ -287,6 +296,7 @@ impl Default for Hop {
jinta: 0f64,
last_src_port: 0_u16,
last_dest_port: 0_u16,
last_sequence: 0_u16,
mean: 0f64,
m2: 0f64,
samples: Vec::default(),
Expand Down Expand Up @@ -411,6 +421,7 @@ impl TraceData {
hop.extensions = complete.extensions.clone();
hop.last_src_port = complete.src_port.0;
hop.last_dest_port = complete.dest_port.0;
hop.last_sequence = complete.sequence.0;
}
ProbeState::Awaited(awaited) => {
self.update_lowest_ttl(awaited.ttl);
Expand All @@ -424,6 +435,7 @@ impl TraceData {
}
self.hops[index].last_src_port = awaited.src_port.0;
self.hops[index].last_dest_port = awaited.dest_port.0;
self.hops[index].last_sequence = awaited.sequence.0;
}
ProbeState::NotSent | ProbeState::Skipped => {}
}
Expand Down
4 changes: 4 additions & 0 deletions src/config/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub enum TuiColumn {
LastSrcPort,
/// The destination port for last probe for this hop.
LastDestPort,
/// The sequence number for the last probe for this hop.
LastSeq,
}

impl TryFrom<char> for TuiColumn {
Expand All @@ -107,6 +109,7 @@ impl TryFrom<char> for TuiColumn {
'i' => Ok(Self::Jinta),
'S' => Ok(Self::LastSrcPort),
'P' => Ok(Self::LastDestPort),
'Q' => Ok(Self::LastSeq),
c => Err(anyhow!(format!("unknown column code: {c}"))),
}
}
Expand All @@ -132,6 +135,7 @@ impl Display for TuiColumn {
Self::Jinta => write!(f, "i"),
Self::LastSrcPort => write!(f, "S"),
Self::LastDestPort => write!(f, "P"),
Self::LastSeq => write!(f, "Q"),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub enum Column {
LastSrcPort,
/// The destination port for last probe for this hop.
LastDestPort,
/// The sequence number for the last probe for this hop.
LastSeq,
}

impl From<Column> for char {
Expand All @@ -113,6 +115,7 @@ impl From<Column> for char {
Column::Jinta => 'i',
Column::LastSrcPort => 'S',
Column::LastDestPort => 'P',
Column::LastSeq => 'Q',
}
}
}
Expand All @@ -137,6 +140,7 @@ impl From<TuiColumn> for Column {
TuiColumn::Jinta => Self::Jinta,
TuiColumn::LastSrcPort => Self::LastSrcPort,
TuiColumn::LastDestPort => Self::LastDestPort,
TuiColumn::LastSeq => Self::LastSeq,
}
}
}
Expand All @@ -161,6 +165,7 @@ impl Display for Column {
Self::Jinta => write!(f, "Jint"),
Self::LastSrcPort => write!(f, "Sprt"),
Self::LastDestPort => write!(f, "Dprt"),
Self::LastSeq => write!(f, "Seq"),
}
}
}
Expand All @@ -187,6 +192,7 @@ impl Column {
Self::Jinta => ColumnWidth::Fixed(8),
Self::LastSrcPort => ColumnWidth::Fixed(7),
Self::LastDestPort => ColumnWidth::Fixed(7),
Self::LastSeq => ColumnWidth::Fixed(7),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/render/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fn new_cell(
Column::Jinta => render_float_cell(Some(hop.jinta()), 1),
Column::LastSrcPort => render_port_cell(hop.last_src_port()),
Column::LastDestPort => render_port_cell(hop.last_dest_port()),
Column::LastSeq => render_usize_cell(usize::from(hop.last_sequence())),
}
}

Expand Down

0 comments on commit 1fac330

Please sign in to comment.