Skip to content

Commit 66823a7

Browse files
committed
Plumbed a demo method.
1 parent e0324c0 commit 66823a7

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

bin/opteadm/src/bin/opteadm.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use oxide_vpc::api::ClearVirt2PhysReq;
3131
use oxide_vpc::api::DelRouterEntryReq;
3232
use oxide_vpc::api::DelRouterEntryResp;
3333
use oxide_vpc::api::DhcpCfg;
34+
use oxide_vpc::api::DumpFlowStatsResp;
3435
use oxide_vpc::api::ExternalIpCfg;
3536
use oxide_vpc::api::Filters as FirewallFilters;
3637
use oxide_vpc::api::FirewallAction;
@@ -276,6 +277,13 @@ enum Command {
276277
#[arg(long = "dir")]
277278
direction: Option<Direction>,
278279
},
280+
281+
/// XXX TEMP
282+
DumpFlowStats {
283+
/// The OPTE port to read...
284+
#[arg(short)]
285+
port: String,
286+
}
279287
}
280288

281289
#[derive(Debug, Parser)]
@@ -859,6 +867,12 @@ fn main() -> anyhow::Result<()> {
859867
})?;
860868
}
861869
}
870+
871+
// XXX TEMP
872+
Command::DumpFlowStats { port } => {
873+
let DumpFlowStatsResp{ data } = hdl.dump_flowstats(&port)?;
874+
println!("{data}");
875+
}
862876
}
863877

864878
Ok(())

crates/opte-api/src/cmd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ pub enum OpteCmd {
5050
SetExternalIps = 80, // set xde external IPs for a port
5151
AllowCidr = 90, // allow ip block through gateway tx/rx
5252
RemoveCidr = 91, // deny ip block through gateway tx/rx
53+
54+
// TEMP
55+
DumpFlowStats = 34,
5356
}
5457

5558
impl TryFrom<c_int> for OpteCmd {

lib/opte-ioctl/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use oxide_vpc::api::DelRouterEntryReq;
3535
use oxide_vpc::api::DelRouterEntryResp;
3636
use oxide_vpc::api::DeleteXdeReq;
3737
use oxide_vpc::api::DhcpCfg;
38+
use oxide_vpc::api::DumpFlowStatsResp;
3839
use oxide_vpc::api::DumpVirt2BoundaryReq;
3940
use oxide_vpc::api::DumpVirt2BoundaryResp;
4041
use oxide_vpc::api::DumpVirt2PhysReq;
@@ -383,6 +384,16 @@ impl OpteHdl {
383384
Some(&DumpUftReq { port_name: port_name.to_string() }),
384385
)
385386
}
387+
388+
/// TEMP METHOD
389+
pub fn dump_flowstats(&self, port_name: &str) -> Result<DumpFlowStatsResp, Error> {
390+
let cmd = OpteCmd::DumpFlowStats;
391+
run_cmd_ioctl(
392+
self.device.as_raw_fd(),
393+
cmd,
394+
Some(&DumpUftReq { port_name: port_name.to_string() }),
395+
)
396+
}
386397
}
387398

388399
pub fn run_cmd_ioctl<T, R>(

lib/opte/src/engine/port/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ impl<N: NetworkImpl> Port<N> {
10241024
Ok(DumpTcpFlowsResp { flows: data.tcp_flows.dump() })
10251025
}
10261026

1027-
#[cfg(any(feature = "std", test))]
10281027
/// XXX TEST METHOD
10291028
pub fn dump_flow_stats(&self) -> Result<String> {
10301029
let data = self.data.read();

lib/opte/src/engine/stat.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::engine::flow_table::Ttl;
1414
use alloc::collections::BTreeMap;
1515
use alloc::collections::BTreeSet;
1616
use alloc::collections::btree_map::Entry;
17+
use alloc::string::String;
1718
use alloc::sync::Arc;
1819
use alloc::sync::Weak;
1920
use alloc::vec::Vec;
@@ -503,7 +504,7 @@ impl StatTree {
503504
});
504505
}
505506

506-
#[cfg(any(feature = "std", test))]
507+
// TEMP
507508
pub fn dump(&self) -> String {
508509
let mut out = String::new();
509510
out.push_str("--Roots--\n");
@@ -525,9 +526,12 @@ impl StatTree {
525526
for (id, stat) in &self.flows {
526527
// let d: ApiFlowStat<InnerFlowId> = stat.as_ref().into();
527528
let d: ApiPktCounter = (&stat.as_ref().shared.stats).into();
529+
let parents: Vec<_> =
530+
stat.parents.iter().map(|v| v.stats.id()).collect();
528531
out.push_str(&format!("\t{id}/{} ->\n", stat.dir));
529532
out.push_str(&format!("\t\t{:?} {d:?}\n", stat.shared.stats.id));
530-
out.push_str(&format!("\t\tparents {:?}\n\n", stat.bases));
533+
out.push_str(&format!("\t\tparents {:?}\n", parents));
534+
out.push_str(&format!("\t\tbases {:?}\n\n", stat.bases));
531535
}
532536
out.push_str("----\n");
533537
out

lib/oxide-vpc/src/api.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,14 @@ pub struct FirewallRule {
650650
pub priority: u16,
651651
}
652652

653+
// TEMP
654+
#[derive(Debug, Deserialize, Serialize)]
655+
pub struct DumpFlowStatsResp {
656+
pub data: String,
657+
}
658+
659+
impl CmdOk for DumpFlowStatsResp {}
660+
653661
impl FromStr for FirewallRule {
654662
type Err = String;
655663

xde/src/xde.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,22 @@ unsafe extern "C" fn xde_ioc_opte_cmd(karg: *mut c_void, mode: c_int) -> c_int {
690690
let resp = remove_cidr_hdlr(&mut env);
691691
hdlr_resp(&mut env, resp)
692692
}
693+
694+
// TEMP
695+
OpteCmd::DumpFlowStats => {
696+
let resp = flow_stats_hdlr(&mut env);
697+
hdlr_resp(&mut env, resp)
698+
}
699+
}
700+
}
701+
702+
#[unsafe(no_mangle)]
703+
fn flow_stats_hdlr(env: &mut IoctlEnvelope) -> Result<oxide_vpc::api::DumpFlowStatsResp, OpteError> {
704+
let req: oxide_vpc::api::DumpUftReq = env.copy_in_req()?;
705+
let devs = xde_devs().read();
706+
match devs.get_by_name(&req.port_name) {
707+
Some(dev) => dev.port.dump_flow_stats().map(|data| oxide_vpc::api::DumpFlowStatsResp {data}),
708+
None => Err(OpteError::PortNotFound(req.port_name)),
693709
}
694710
}
695711

0 commit comments

Comments
 (0)