Skip to content
Merged
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.

7 changes: 7 additions & 0 deletions cli/bin/cmdtree_dp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ fn cmd_show_config_summary() -> Node {
root
}

fn cmd_show_tech() -> Node {
Node::new("tech")
.desc("Dump dataplanes state")
.action(CliAction::ShowTech as u16)
}

fn cmd_show() -> Node {
let mut root: Node = Node::new("show");
root += cmd_show_router();
Expand All @@ -301,6 +307,7 @@ fn cmd_show() -> Node {
root += cmd_show_flow_filter();
root += cmd_show_gateway();
root += cmd_show_config_summary();
root += cmd_show_tech();
root
}
fn cmd_loglevel() -> Node {
Expand Down
80 changes: 44 additions & 36 deletions cli/src/cliproto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,46 +121,42 @@ impl CliResponse {

#[repr(u16)]
#[allow(unused)]
#[derive(Debug, Clone, Serialize, Deserialize, EnumIter)]
#[derive(Debug, Clone, Serialize, Deserialize, EnumIter, PartialEq)]
pub enum CliAction {
Clear = 0,
Connect,
Disconnect,
Help,
Quit,

// config
ShowConfigSummary,

// config: gateways & communities
ShowGatewayGroups,
ShowGatewayCommunities,

// config: tracing
ShowTracingTargets,
ShowTracingTagGroups,
SetLoglevel,

// cpi
// config: vpcs & peerings
ShowVpc,
ShowVpcPeerings,

// router: Eventlog
RouterEventLog,

// router: cpi
ShowCpiStats,
CpiRequestRefresh,

// frrmi
// router: frrmi
ShowFrrmiStats,
ShowFrrmiLastConfig,
FrrmiApplyLastConfig,

// Eventlog
RouterEventLog,

// flow table
ShowFlowTable,

// flow filter
ShowFlowFilter,

// vpcs
ShowVpc,
ShowVpcPeerings,

// pipelines
ShowPipeline,
ShowPipelineStages,
ShowPipelineStats,

// router
// router: internal state
ShowRouterInterfaces,
ShowRouterInterfaceAddresses,
ShowRouterVrfs,
Expand All @@ -177,25 +173,37 @@ pub enum CliAction {
ShowRouterIpv4FibGroups,
ShowRouterIpv6FibGroups,

// DPDK
ShowDpdkPort,
ShowDpdkPortStats,

// kernel
ShowKernelInterfaces,

// nat
// NF: nat
ShowPortForwarding,
ShowStaticNat,
ShowMasquerading,

// gateways
ShowGatewayGroups,
ShowGatewayCommunities,
// NF: flow table
ShowFlowTable,

// config
ShowConfigSummary,
// NF: flow filter
ShowFlowFilter,

// internal config
ShowConfigInternal,

ShowTech,

/* == Not supported yet == */
// pipelines
ShowPipeline,
ShowPipelineStages,
ShowPipelineStats,

// kernel
ShowKernelInterfaces,

// DPDK
ShowDpdkPort,
ShowDpdkPortStats,

// loglevel
SetLoglevel,
}

impl CliAction {
Expand Down
2 changes: 1 addition & 1 deletion common/src/cliprovider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl CliString for &str {}
pub struct Heading<T>(pub T);
impl<T: CliString> Display for Heading<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, " {:^100}", format!(" {} ", self.0))
writeln!(f, " {:^100}", format!(" {} ", self.0))
}
}

Expand Down
4 changes: 2 additions & 2 deletions flow-entry/src/flow_table/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ impl Display for FlowTable {
for entry in table.iter() {
let key = entry.key();
match entry.value().upgrade() {
Some(value) => writeln!(f, "key = {key}\ndata = {value}")?,
None => writeln!(f, "key = {key} NONE")?,
Some(value) => writeln!(f, "{key}\n{value}")?,
None => writeln!(f, "{key}: NONE")?,
}
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion flow-filter/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Display implementations

use common::cliprovider::{CliData, CliDataProvider};
use common::cliprovider::{CliData, CliDataProvider, Heading};
use indenter::indented;

use std::collections::BTreeMap;
Expand All @@ -21,6 +21,8 @@ impl CliDataProvider for FlowFilterTable {

impl Display for FlowFilterTable {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Heading("Flow filter").fmt(f)?;

// Collect into a BTreeMap to get a deterministic order when dumping the entries
writeln!(f, "subtable for TCP/UDP:")?;
for (src_vpcd, table) in self
Expand Down
80 changes: 80 additions & 0 deletions net/src/flows/display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Open Network Fabric Authors

//! Flow keys

use super::flow_info::{FlowInfo, FlowInfoLocked};
use super::flow_key::{FlowKey, FlowKeyData};

use std::fmt::Display;
use std::time::Instant;

impl Display for FlowKeyData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(vpcd) = self.src_vpcd() {
write!(f, "from: {vpcd},")?;
}
let ports = self.ports();
let proto = self.proto();
let src_ip = self.src_ip();
let dst_ip = self.dst_ip();
if let Some((src_port, dst_port)) = ports {
write!(f, "{src_ip}:{src_port} -> {dst_ip}:{dst_port} {proto}")?;
} else {
write!(f, "{src_ip} -> {dst_ip} {proto}")?;
}
if let Some(id) = self.icmp_id() {
write!(f, " id:{id}")?;
}
Ok(())
}
}

impl Display for FlowKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FlowKey::Unidirectional(data) => write!(f, "{data}"),
}
}
}

impl Display for FlowInfoLocked {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(data) = &self.dst_vpcd {
writeln!(f, " dst-vpcd:{data}")?;
}
if let Some(data) = &self.port_fw_state {
writeln!(f, " port-forwarding:{data}")?;
}
if let Some(data) = &self.nat_state {
writeln!(f, " nat-state:{data}")?;
}
Ok(())
}
}

impl Display for FlowInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let expires_at = self.expires_at();
let expires_in = expires_at.saturating_duration_since(Instant::now());
let genid = self.genid();

if let Ok(info) = self.locked.try_read() {
write!(f, "{info}")?;
} else {
write!(f, "could not lock!")?;
}
let has_related = self
.related
.as_ref()
.and_then(std::sync::Weak::upgrade)
.map_or("no", |_| "yes");

writeln!(
f,
" status: {:?}, expires in {}s, related: {has_related}, genid: {genid}",
self.status(),
expires_in.as_secs(),
)
}
}
41 changes: 0 additions & 41 deletions net/src/flows/flow_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,44 +392,3 @@ impl FlowInfo {
.store(status, std::sync::atomic::Ordering::Relaxed);
}
}

impl Display for FlowInfoLocked {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(data) = &self.dst_vpcd {
writeln!(f, " dst-vpcd:{data}")?;
}
if let Some(data) = &self.port_fw_state {
writeln!(f, " port-forwarding:{data}")?;
}
if let Some(data) = &self.nat_state {
writeln!(f, " nat-state:{data}")?;
}
Ok(())
}
}

impl Display for FlowInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let expires_at = self.expires_at.load(Ordering::Relaxed);
let expires_in = expires_at.saturating_duration_since(Instant::now());
let genid = self.genid();
writeln!(f)?;
if let Ok(info) = self.locked.try_read() {
write!(f, "{info}")?;
} else {
write!(f, "could not lock!")?;
}
let has_related = self
.related
.as_ref()
.and_then(std::sync::Weak::upgrade)
.map_or("no", |_| "yes");

writeln!(
f,
" status: {:?}, expires in {}s, related: {has_related}, genid: {genid}",
self.status,
expires_in.as_secs(),
)
}
}
8 changes: 8 additions & 0 deletions net/src/flows/flow_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ impl FlowKeyData {
&self.dst_ip
}

#[must_use]
pub fn icmp_id(&self) -> Option<u16> {
match &self.proto_key_info {
IpProtoKey::Icmp(IcmpProtoKey::QueryMsgData(id)) => Some(*id),
_ => None,
}
}

#[must_use]
pub fn src_port(&self) -> Option<NonZero<u16>> {
match self.proto_key_info {
Expand Down
53 changes: 0 additions & 53 deletions net/src/flows/flow_key_display.rs

This file was deleted.

2 changes: 1 addition & 1 deletion net/src/flows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub mod atomic_instant;
pub mod flow_info;
pub mod flow_info_item;

pub mod display;
pub mod flow_key;
pub mod flow_key_display;

pub use atomic_instant::AtomicInstant;
pub use flow_info::*;
Expand Down
Loading
Loading