From d87fbb6e2fe7dfde163e714b17155d11e7b1bd79 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Wed, 16 Jul 2025 13:02:31 +0100 Subject: [PATCH 1/3] OMDB commands for sled-agent NIC endpoints --- dev-tools/omdb/src/bin/omdb/sled_agent.rs | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/dev-tools/omdb/src/bin/omdb/sled_agent.rs b/dev-tools/omdb/src/bin/omdb/sled_agent.rs index fcba039ac75..a3064577601 100644 --- a/dev-tools/omdb/src/bin/omdb/sled_agent.rs +++ b/dev-tools/omdb/src/bin/omdb/sled_agent.rs @@ -12,6 +12,8 @@ use anyhow::bail; use clap::Args; use clap::Subcommand; use sled_agent_client::types::ChickenSwitchDestroyOrphanedDatasets; +use sled_agent_client::types::Flow; +use uuid::Uuid; /// Arguments to the "omdb sled-agent" subcommand #[derive(Debug, Args)] @@ -36,6 +38,10 @@ enum SledAgentCommands { #[clap(subcommand)] Zones(ZoneCommands), + /// print information about network interfaces + #[clap(subcommand)] + Nics(NicCommands), + /// print information about the local bootstore node #[clap(subcommand)] Bootstore(BootstoreCommands), @@ -52,6 +58,19 @@ enum ZoneCommands { List, } +#[derive(Debug, Subcommand)] +enum NicCommands { + /// Print list of all known OPTE ports + List, + /// Print all flow stats currently seen on a given OPTE port + Flows(FlowStatsArgs), +} + +#[derive(Debug, Args)] +pub struct FlowStatsArgs { + nic_id: Uuid, +} + #[derive(Debug, Subcommand)] enum BootstoreCommands { /// Show the internal state of the local bootstore node @@ -102,6 +121,12 @@ impl SledAgentArgs { SledAgentCommands::Zones(ZoneCommands::List) => { cmd_zones_list(&client).await } + SledAgentCommands::Nics(NicCommands::List) => { + cmd_nics_list(&client).await + } + SledAgentCommands::Nics(NicCommands::Flows(args)) => { + cmd_nics_flows(&client, args).await + } SledAgentCommands::Bootstore(BootstoreCommands::Status) => { cmd_bootstore_status(&client).await } @@ -151,6 +176,51 @@ async fn cmd_zones_list( Ok(()) } +/// Runs `omdb sled-agent nics list` +async fn cmd_nics_list( + client: &sled_agent_client::Client, +) -> Result<(), anyhow::Error> { + let response = client.nic_ids_list().await.context("listing nics")?; + let nics = response.into_inner(); + + println!("nics:"); + if nics.is_empty() { + println!(" "); + } + for nic in &nics { + println!(" {}", nic); + } + + Ok(()) +} + +/// Runs `omdb sled-agent nics list` +async fn cmd_nics_flows( + client: &sled_agent_client::Client, + FlowStatsArgs { nic_id }: &FlowStatsArgs, +) -> Result<(), anyhow::Error> { + let response = + client.nic_flows_list(nic_id).await.context("listing nics")?; + let flows = response.into_inner(); + + println!("flows:"); + if flows.is_empty() { + println!(" "); + } + for Flow { metadata, in_stat, out_stat } in &flows { + println!(" {} ({}):", metadata.flow_id, metadata.created_at); + println!(" internal key {:?}", metadata.internal_key); + println!(" external key {:?}", metadata.external_key); + println!(" opened on {:?}", metadata.initial_packet); + println!(" allowed in by {:?}", metadata.admitted_by_in); + println!(" allowed out by {:?}", metadata.admitted_by_out); + println!(" in_stats {:?}", in_stat); + println!(" out_stats {:?}", out_stat); + } + + Ok(()) +} + /// Runs `omdb sled-agent bootstore status` async fn cmd_bootstore_status( client: &sled_agent_client::Client, From f9ce6a02a4ce2aaf8e2b61f19e9d54991d9a26ae Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Wed, 16 Jul 2025 18:41:37 +0100 Subject: [PATCH 2/3] Better align printing. --- dev-tools/omdb/src/bin/omdb/sled_agent.rs | 4 +++- illumos-utils/src/opte/stat.rs | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dev-tools/omdb/src/bin/omdb/sled_agent.rs b/dev-tools/omdb/src/bin/omdb/sled_agent.rs index a3064577601..e73f9e4bbaa 100644 --- a/dev-tools/omdb/src/bin/omdb/sled_agent.rs +++ b/dev-tools/omdb/src/bin/omdb/sled_agent.rs @@ -212,10 +212,12 @@ async fn cmd_nics_flows( println!(" internal key {:?}", metadata.internal_key); println!(" external key {:?}", metadata.external_key); println!(" opened on {:?}", metadata.initial_packet); + println!(" forwarded via {:?}", metadata.forwarded); println!(" allowed in by {:?}", metadata.admitted_by_in); println!(" allowed out by {:?}", metadata.admitted_by_out); println!(" in_stats {:?}", in_stat); - println!(" out_stats {:?}", out_stat); + println!(" out_stats {:?}", out_stat); + println!("+---------------------+"); } Ok(()) diff --git a/illumos-utils/src/opte/stat.rs b/illumos-utils/src/opte/stat.rs index e1d4b505311..990fab65a9b 100644 --- a/illumos-utils/src/opte/stat.rs +++ b/illumos-utils/src/opte/stat.rs @@ -295,7 +295,6 @@ async fn run_port_stat(state: Arc) { return; } - // TODO: log on error. tokio::select! { _ = flow_collect.tick() => { if let Err(e) = state.collect_flows() { From 3bb2636d01a57c51868cd36acdbe8ea970aa78f2 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Fri, 18 Jul 2025 16:47:11 +0100 Subject: [PATCH 3/3] Missed expectorate. --- dev-tools/omdb/tests/usage_errors.out | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-tools/omdb/tests/usage_errors.out b/dev-tools/omdb/tests/usage_errors.out index ddb4b2bba10..5f32b169a48 100644 --- a/dev-tools/omdb/tests/usage_errors.out +++ b/dev-tools/omdb/tests/usage_errors.out @@ -1058,6 +1058,7 @@ Usage: omdb sled-agent [OPTIONS] Commands: zones print information about zones + nics print information about network interfaces bootstore print information about the local bootstore node chicken-switch control "chicken switches" (potentially-destructive sled-agent behavior that can be toggled on or off via `omdb`)