Skip to content

Commit 923f9ee

Browse files
committed
Plumbed a demo method.
1 parent c73611f commit 923f9ee

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
@@ -32,6 +32,7 @@ use oxide_vpc::api::ClearVirt2PhysReq;
3232
use oxide_vpc::api::DelRouterEntryReq;
3333
use oxide_vpc::api::DelRouterEntryResp;
3434
use oxide_vpc::api::DhcpCfg;
35+
use oxide_vpc::api::DumpFlowStatsResp;
3536
use oxide_vpc::api::ExternalIpCfg;
3637
use oxide_vpc::api::Filters as FirewallFilters;
3738
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
@@ -49,6 +49,9 @@ pub enum OpteCmd {
4949
SetExternalIps = 80, // set xde external IPs for a port
5050
AllowCidr = 90, // allow ip block through gateway tx/rx
5151
RemoveCidr = 91, // deny ip block through gateway tx/rx
52+
53+
// TEMP
54+
DumpFlowStats = 34,
5255
}
5356

5457
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
@@ -34,6 +34,7 @@ use oxide_vpc::api::DelRouterEntryReq;
3434
use oxide_vpc::api::DelRouterEntryResp;
3535
use oxide_vpc::api::DeleteXdeReq;
3636
use oxide_vpc::api::DhcpCfg;
37+
use oxide_vpc::api::DumpFlowStatsResp;
3738
use oxide_vpc::api::DumpVirt2BoundaryResp;
3839
use oxide_vpc::api::DumpVirt2PhysResp;
3940
use oxide_vpc::api::IpCidr;
@@ -368,6 +369,16 @@ impl OpteHdl {
368369
Some(&DumpUftReq { port_name: port_name.to_string() }),
369370
)
370371
}
372+
373+
/// TEMP METHOD
374+
pub fn dump_flowstats(&self, port_name: &str) -> Result<DumpFlowStatsResp, Error> {
375+
let cmd = OpteCmd::DumpFlowStats;
376+
run_cmd_ioctl(
377+
self.device.as_raw_fd(),
378+
cmd,
379+
Some(&DumpUftReq { port_name: port_name.to_string() }),
380+
)
381+
}
371382
}
372383

373384
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
@@ -641,6 +641,14 @@ pub struct FirewallRule {
641641
pub priority: u16,
642642
}
643643

644+
// TEMP
645+
#[derive(Debug, Deserialize, Serialize)]
646+
pub struct DumpFlowStatsResp {
647+
pub data: String,
648+
}
649+
650+
impl CmdOk for DumpFlowStatsResp {}
651+
644652
impl FromStr for FirewallRule {
645653
type Err = String;
646654

xde/src/xde.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,22 @@ unsafe extern "C" fn xde_ioc_opte_cmd(karg: *mut c_void, mode: c_int) -> c_int {
684684
let resp = remove_cidr_hdlr(&mut env);
685685
hdlr_resp(&mut env, resp)
686686
}
687+
688+
// TEMP
689+
OpteCmd::DumpFlowStats => {
690+
let resp = flow_stats_hdlr(&mut env);
691+
hdlr_resp(&mut env, resp)
692+
}
693+
}
694+
}
695+
696+
#[unsafe(no_mangle)]
697+
fn flow_stats_hdlr(env: &mut IoctlEnvelope) -> Result<oxide_vpc::api::DumpFlowStatsResp, OpteError> {
698+
let req: oxide_vpc::api::DumpUftReq = env.copy_in_req()?;
699+
let devs = xde_devs().read();
700+
match devs.get_by_name(&req.port_name) {
701+
Some(dev) => dev.port.dump_flow_stats().map(|data| oxide_vpc::api::DumpFlowStatsResp {data}),
702+
None => Err(OpteError::PortNotFound(req.port_name)),
687703
}
688704
}
689705

0 commit comments

Comments
 (0)