Skip to content

WIP: Flowstats #744

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

Draft
wants to merge 8 commits into
base: optehdl-cleanup
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions bin/opteadm/src/bin/opteadm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use oxide_vpc::api::ClearVirt2PhysReq;
use oxide_vpc::api::DelRouterEntryReq;
use oxide_vpc::api::DelRouterEntryResp;
use oxide_vpc::api::DhcpCfg;
use oxide_vpc::api::DumpFlowStatsResp;
use oxide_vpc::api::ExternalIpCfg;
use oxide_vpc::api::Filters as FirewallFilters;
use oxide_vpc::api::FirewallAction;
Expand Down Expand Up @@ -276,6 +277,13 @@ enum Command {
#[arg(long = "dir")]
direction: Option<Direction>,
},

/// XXX TEMP
DumpFlowStats {
/// The OPTE port to read...
#[arg(short)]
port: String,
},
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -859,6 +867,12 @@ fn main() -> anyhow::Result<()> {
})?;
}
}

// XXX TEMP
Command::DumpFlowStats { port } => {
let DumpFlowStatsResp { data } = hdl.dump_flowstats(&port)?;
println!("{data}");
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/opte-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ingot.workspace = true
ipnetwork = { workspace = true, optional = true }
postcard.workspace = true
serde.workspace = true
uuid.workspace = true

[dependencies.smoltcp]
workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/opte-api/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum OpteCmd {
SetExternalIps = 80, // set xde external IPs for a port
AllowCidr = 90, // allow ip block through gateway tx/rx
RemoveCidr = 91, // deny ip block through gateway tx/rx

// TEMP
DumpFlowStats = 34,
}

impl TryFrom<c_int> for OpteCmd {
Expand Down
4 changes: 3 additions & 1 deletion crates/opte-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod encap;
pub mod ip;
pub mod mac;
pub mod ndp;
pub mod stat;
pub mod tcp;
pub mod ulp;

Expand All @@ -38,6 +39,7 @@ pub use encap::*;
pub use ip::*;
pub use mac::*;
pub use ndp::*;
pub use stat::*;
pub use tcp::*;
pub use ulp::*;

Expand All @@ -51,7 +53,7 @@ pub use ulp::*;
///
/// We rely on CI and the check-api-version.sh script to verify that
/// this number is incremented anytime the oxide-api code changes.
pub const API_VERSION: u64 = 36;
pub const API_VERSION: u64 = 37;

/// Major version of the OPTE package.
pub const MAJOR_VERSION: u64 = 0;
Expand Down
38 changes: 38 additions & 0 deletions crates/opte-api/src/stat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Copyright 2025 Oxide Computer Company

//! Types for handling flow stats from the ioctl API.

use crate::Direction;
use alloc::vec::Vec;
use serde::Deserialize;
use serde::Serialize;
use uuid::Uuid;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct FlowStat<FlowId> {
pub partner: FlowId,
pub dir: Direction,
pub bases: Vec<Uuid>,
pub stats: PacketCounter,
}

#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
pub struct PacketCounter {
pub created_at: u64,
pub pkts_in: u64,
pub bytes_in: u64,
pub pkts_out: u64,
pub bytes_out: u64,
}

#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
pub struct FullCounter {
pub allow: u64,
pub deny: u64,
pub hairpin: u64,
pub packets: PacketCounter,
}
14 changes: 14 additions & 0 deletions lib/opte-ioctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use oxide_vpc::api::DelRouterEntryReq;
use oxide_vpc::api::DelRouterEntryResp;
use oxide_vpc::api::DeleteXdeReq;
use oxide_vpc::api::DhcpCfg;
use oxide_vpc::api::DumpFlowStatsResp;
use oxide_vpc::api::DumpVirt2BoundaryReq;
use oxide_vpc::api::DumpVirt2BoundaryResp;
use oxide_vpc::api::DumpVirt2PhysReq;
Expand Down Expand Up @@ -383,6 +384,19 @@ impl OpteHdl {
Some(&DumpUftReq { port_name: port_name.to_string() }),
)
}

/// TEMP METHOD
pub fn dump_flowstats(
&self,
port_name: &str,
) -> Result<DumpFlowStatsResp, Error> {
let cmd = OpteCmd::DumpFlowStats;
run_cmd_ioctl(
self.device.as_raw_fd(),
cmd,
Some(&DumpUftReq { port_name: port_name.to_string() }),
)
}
}

pub fn run_cmd_ioctl<T, R>(
Expand Down
6 changes: 3 additions & 3 deletions lib/opte-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ fn oxide_net_builder(
let dhcp = base_dhcp_config();

firewall::setup(&mut pb, fw_limit).expect("failed to add firewall layer");
gateway::setup(&pb, cfg, vpc_map, fw_limit, &dhcp)
gateway::setup(&mut pb, cfg, vpc_map, fw_limit, &dhcp)
.expect("failed to setup gateway layer");
router::setup(&pb, cfg, one_limit).expect("failed to add router layer");
router::setup(&mut pb, cfg, one_limit).expect("failed to add router layer");
nat::setup(&mut pb, cfg, snat_limit).expect("failed to add nat layer");
overlay::setup(&pb, cfg, v2p, v2b, one_limit)
overlay::setup(&mut pb, cfg, v2p, v2b, one_limit)
.expect("failed to add overlay layer");
pb
}
Expand Down
5 changes: 5 additions & 0 deletions lib/opte-test-utils/src/port_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ pub fn print_port(
write_hr(&mut out)?;
writeln!(&mut out, "{:#?}", port.stats_snap())?;

// ================================================================
// Print the Better Stats
// ================================================================
writeln!(&mut out, "{}", port.dump_flow_stats().unwrap())?;

write_hrb(&mut out)?;
writeln!(&mut out)?;

Expand Down
1 change: 1 addition & 0 deletions lib/opte/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ itertools = { workspace = true, optional = true }
postcard.workspace = true
serde.workspace = true
tabwriter = { workspace = true, optional = true }
uuid.workspace = true
usdt = { workspace = true, optional = true }
zerocopy = { workspace = true, optional = true }

Expand Down
Loading