Skip to content
Open
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
3 changes: 2 additions & 1 deletion aal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::Serialize;
use thiserror::Error;

use common::ports::{PortFec, PortMedia, PortPrbsMode, PortSpeed, TxEq};
use common::table::TableType;

mod fuse;
pub use fuse::*;
Expand Down Expand Up @@ -264,7 +265,7 @@ pub trait AsicOps {
/// the intermediate representation to the ASIC-specific format expected by the
/// underlying hardware or emulator.
pub trait TableOps<H: AsicOps> {
fn new(hdl: &H, name: &str) -> AsicResult<Self>
fn new(hdl: &H, type_: TableType) -> AsicResult<Self>
where
Self: Sized;

Expand Down
2 changes: 1 addition & 1 deletion asic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tofino_asic = [
tofino_stub = []
softnpu = ["softnpu-lib", "dep:propolis"]
chaos = []
multicast = ["aal/multicast"]
multicast = ["aal/multicast", "common/multicast"]

[lib]
# The genpd.rs code generated by bindgen causes the doctest to fail
Expand Down
74 changes: 49 additions & 25 deletions asic/src/chaos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use aal::{
SidecarIdentifiers,
};
use common::ports::{PortFec, PortId, PortMedia, PortPrbsMode, PortSpeed};
use common::table::TableType;

use crate::Identifiers;
pub use crate::faux_fsm::FsmState;
Expand Down Expand Up @@ -68,7 +69,7 @@ impl Chaos {
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct TableChaos {
/// Track a set of chaos probabilities keyed by strings.
pub values: HashMap<String, f64>,
pub values: HashMap<TableType, f64>,
}

/// A convenience function for creating chaos tables.
Expand All @@ -84,42 +85,65 @@ macro_rules! table_chaos {
}

impl TableChaos {
fn add_tables(&mut self, ids: Vec<TableType>, prob: f64) {
for id in ids {
self.values.insert(id, prob);
}
}

/// Create a new chaos table with all known dendrite table identifiers,
/// assigning each a uniform chaos value.
pub fn uniform(v: f64) -> Self {
table_chaos!(
(table::ROUTE_IPV4, v),
(table::ROUTE_IPV6, v),
(table::ARP_IPV4, v),
(table::NEIGHBOR_IPV6, v),
(table::MAC_REWRITE, v),
(table::SWITCH_IPV4_ADDR, v),
(table::SWITCH_IPV6_ADDR, v),
(table::NAT_INGRESS_IPV4, v),
(table::NAT_INGRESS_IPV6, v),
(table::MCAST_NAT_INGRESS_IPV4, v),
(table::MCAST_NAT_INGRESS_IPV6, v),
(table::MCAST_REPLICATION_IPV4, v),
(table::MCAST_REPLICATION_IPV6, v),
(table::MCAST_SRC_FILTER_IPV4, v),
(table::MCAST_SRC_FILTER_IPV6, v),
(table::MCAST_ROUTE_IPV4, v),
(table::MCAST_ROUTE_IPV6, v),
(table::MCAST_MAC_REWRITE, v),
(table::MCAST_DECAP_PORTS, v),
(table::MCAST_PORT_ID_MAPPING, v)
)
let mut tc = TableChaos { values: HashMap::new() };

tc.add_tables(
vec![
TableType::RouteIdxIpv4,
TableType::RouteFwdIpv4,
TableType::RouteIdxIpv6,
TableType::RouteFwdIpv6,
TableType::ArpIpv4,
TableType::NeighborIpv6,
TableType::PortMacAddress,
TableType::PortAddrIpv4,
TableType::PortAddrIpv6,
TableType::NatIngressIpv4,
TableType::NatIngressIpv6,
TableType::UplinkIngress,
TableType::UplinkEgress,
TableType::AttachedSubnetIpv4,
TableType::AttachedSubnetIpv6,
],
v,
);
#[cfg(feature = "multicast")]
tc.add_tables(
vec![
TableType::RouteIpv4Mcast,
TableType::RouteIpv6Mcast,
TableType::McastIpv6,
TableType::McastIpv4SrcFilter,
TableType::McastIpv6SrcFilter,
TableType::NatIngressIpv4Mcast,
TableType::NatIngressIpv6Mcast,
TableType::PortMacAddressMcast,
TableType::McastEgressDecapPorts,
TableType::McastEgressPortMapping,
],
v,
);
tc
}

/// Return a chaos error according to the underlying probability value for
/// the given table `id`.
pub fn unfurled(
&self,
log: &Logger,
id: &str,
id: TableType,
message: &str,
) -> AsicResult<()> {
if let Some(value) = self.values.get(id)
if let Some(value) = self.values.get(&id)
&& *value >= random()
{
slog::error!(log, "chaos table error: {}", message);
Expand Down
50 changes: 9 additions & 41 deletions asic/src/chaos/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,17 @@ use crate::chaos::{Handle, table_unfurl};
use aal::{
ActionParse, AsicError, AsicResult, CounterData, MatchParse, TableOps,
};

// These names line up with the table names in the sidecar P4 program.
pub const ROUTE_IPV4: &str = "pipe.Ingress.l3_router.routes_ipv4";
pub const ROUTE_IPV6: &str = "pipe.Ingress.l3_router.routes_ipv6";
pub const ARP_IPV4: &str = "pipe.Ingress.l3_router.arp_ipv4";
pub const NEIGHBOR_IPV6: &str = "pipe.Ingress.l3_router.neighbor_ipv6";
pub const MAC_REWRITE: &str = "pipe.Ingress.mac_rewrite.mac_rewrite";
pub const SWITCH_IPV4_ADDR: &str = "pipe.Ingress.filter.switch_ipv4_addr";
pub const SWITCH_IPV6_ADDR: &str = "pipe.Ingress.filter.switch_ipv6_addr";
pub const NAT_INGRESS_IPV4: &str = "pipe.Ingress.nat_ingress.ingress_ipv4";
pub const NAT_INGRESS_IPV6: &str = "pipe.Ingress.nat_ingress.ingress_ipv6";
pub(crate) const MCAST_NAT_INGRESS_IPV4: &str =
"pipe.Ingress.nat_ingress.ingress_ipv4_mcast";
pub(crate) const MCAST_NAT_INGRESS_IPV6: &str =
"pipe.Ingress.nat_ingress.ingress_ipv6_mcast";
pub(crate) const MCAST_REPLICATION_IPV4: &str =
"pipe.Ingress.mcast_ingress.mcast_replication_ipv4";
pub(crate) const MCAST_REPLICATION_IPV6: &str =
"pipe.Ingress.mcast_ingress.mcast_replication_ipv6";
pub(crate) const MCAST_SRC_FILTER_IPV4: &str =
"pipe.Ingress.mcast_ingress.mcast_source_filter_ipv4";
pub(crate) const MCAST_SRC_FILTER_IPV6: &str =
"pipe.Ingress.mcast_ingress.mcast_source_filter_ipv6";
pub(crate) const MCAST_ROUTE_IPV4: &str =
"pipe.Ingress.l3_router.MulticastRouter4.tbl";
pub(crate) const MCAST_ROUTE_IPV6: &str =
"pipe.Ingress.l3_router.MulticastRouter6.tbl";
pub(crate) const MCAST_MAC_REWRITE: &str =
"pipe.Egress.mac_rewrite.mac_rewrite";
pub(crate) const MCAST_DECAP_PORTS: &str =
"pipe.Egress.mcast_egress.tbl_decap_ports";
pub(crate) const MCAST_PORT_ID_MAPPING: &str =
"pipe.Egress.mcast_egress.asic_id_to_port";
use common::table::TableType;

pub struct Table {
name: String,
type_: TableType,
keys: Mutex<HashSet<u64>>,
}

impl TableOps<Handle> for Table {
fn new(hdl: &Handle, name: &str) -> AsicResult<Table> {
table_unfurl!(hdl, name, table_new);
Ok(Table { name: name.into(), keys: Mutex::new(HashSet::new()) })
fn new(hdl: &Handle, type_: TableType) -> AsicResult<Table> {
table_unfurl!(hdl, type_, table_new);
Ok(Table { type_, keys: Mutex::new(HashSet::new()) })
}

fn size(&self) -> usize {
Expand All @@ -69,7 +37,7 @@ impl TableOps<Handle> for Table {
}

fn clear(&self, hdl: &Handle) -> AsicResult<()> {
table_unfurl!(hdl, &self.name, table_clear);
table_unfurl!(hdl, self.type_, table_clear);
let mut keys = self.keys.lock().unwrap();
*keys = HashSet::new();
Ok(())
Expand All @@ -89,7 +57,7 @@ impl TableOps<Handle> for Table {
if keys.contains(&x) {
return Err(AsicError::Exists);
}
table_unfurl!(hdl, &self.name, table_entry_add);
table_unfurl!(hdl, self.type_, table_entry_add);
keys.insert(x);
Ok(())
}
Expand All @@ -110,7 +78,7 @@ impl TableOps<Handle> for Table {
"table entry not found".to_string(),
));
}
table_unfurl!(hdl, &self.name, table_entry_update);
table_unfurl!(hdl, self.type_, table_entry_update);
Ok(())
}

Expand All @@ -129,7 +97,7 @@ impl TableOps<Handle> for Table {
"table entry not found".to_string(),
));
}
table_unfurl!(hdl, &self.name, table_entry_del);
table_unfurl!(hdl, self.type_, table_entry_del);
keys.remove(&x);
Ok(())
}
Expand Down
Loading