|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +//! Microbenchmark entry point for the production seccomp network broker. |
| 5 | + |
| 6 | +use std::net::SocketAddr; |
| 7 | + |
| 8 | +use clap::{Parser, Subcommand}; |
| 9 | +use openshell_sandbox::perf::{BenchmarkOptions, Layer, Protocol}; |
| 10 | + |
| 11 | +#[derive(Debug, Parser)] |
| 12 | +#[command( |
| 13 | + about = "Measure native and seccomp-filtered socket performance", |
| 14 | + long_about = "Measure native and seccomp-filtered socket performance. UDP unconnected means destination-bearing SOCK_DGRAM traffic, not SOCK_RAW. General external UDP and SOCK_RAW are currently denied by the sandbox." |
| 15 | +)] |
| 16 | +struct Cli { |
| 17 | + /// Benchmark layer: native, filtered, or all. |
| 18 | + #[arg(long, default_value = "all", value_parser = ["native", "filtered", "all"])] |
| 19 | + layer: String, |
| 20 | + /// Protocol: tcp-connect, tcp-stream, udp-connected, udp-unconnected, or all. |
| 21 | + #[arg( |
| 22 | + long, |
| 23 | + default_value = "all", |
| 24 | + value_parser = ["tcp-connect", "tcp-stream", "udp-connected", "udp-unconnected", "all"] |
| 25 | + )] |
| 26 | + protocol: String, |
| 27 | + #[arg(long, default_value_t = 10_000)] |
| 28 | + iterations: u64, |
| 29 | + #[arg(long, default_value_t = 1_000)] |
| 30 | + warmup: u64, |
| 31 | + #[arg(long, default_value_t = 1)] |
| 32 | + concurrency: usize, |
| 33 | + #[arg(long, default_value_t = 64)] |
| 34 | + payload_bytes: usize, |
| 35 | + #[command(subcommand)] |
| 36 | + command: Option<Command>, |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Debug, Subcommand)] |
| 40 | +enum Command { |
| 41 | + #[command(hide = true)] |
| 42 | + Worker { |
| 43 | + #[arg(long)] |
| 44 | + protocol: Protocol, |
| 45 | + #[arg(long)] |
| 46 | + target: SocketAddr, |
| 47 | + #[arg(long)] |
| 48 | + iterations: u64, |
| 49 | + #[arg(long)] |
| 50 | + warmup: u64, |
| 51 | + #[arg(long)] |
| 52 | + concurrency: usize, |
| 53 | + #[arg(long)] |
| 54 | + payload_bytes: usize, |
| 55 | + }, |
| 56 | +} |
| 57 | + |
| 58 | +fn main() -> anyhow::Result<()> { |
| 59 | + let cli = Cli::parse(); |
| 60 | + if let Some(Command::Worker { |
| 61 | + protocol, |
| 62 | + target, |
| 63 | + iterations, |
| 64 | + warmup, |
| 65 | + concurrency, |
| 66 | + payload_bytes, |
| 67 | + }) = cli.command |
| 68 | + { |
| 69 | + let report = openshell_sandbox::perf::run_worker( |
| 70 | + protocol, |
| 71 | + target, |
| 72 | + iterations, |
| 73 | + warmup, |
| 74 | + concurrency, |
| 75 | + payload_bytes, |
| 76 | + )?; |
| 77 | + println!("{}", serde_json::to_string(&report)?); |
| 78 | + return Ok(()); |
| 79 | + } |
| 80 | + |
| 81 | + let options = BenchmarkOptions { |
| 82 | + layers: Layer::selection(&cli.layer)?, |
| 83 | + protocols: Protocol::selection(&cli.protocol)?, |
| 84 | + iterations: cli.iterations, |
| 85 | + warmup: cli.warmup, |
| 86 | + concurrency: cli.concurrency, |
| 87 | + payload_bytes: cli.payload_bytes, |
| 88 | + }; |
| 89 | + for report in openshell_sandbox::perf::run(options)? { |
| 90 | + println!("{}", serde_json::to_string(&report)?); |
| 91 | + } |
| 92 | + Ok(()) |
| 93 | +} |
0 commit comments