Skip to content

Commit 5978bb5

Browse files
committed
Avoid manual translation of table names for softnpu
1 parent b31ba90 commit 5978bb5

41 files changed

Lines changed: 1105 additions & 918 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aal/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use serde::Serialize;
1212
use thiserror::Error;
1313

1414
use common::ports::{PortFec, PortMedia, PortPrbsMode, PortSpeed, TxEq};
15+
use common::table::TableType;
1516

1617
mod fuse;
1718
pub use fuse::*;
@@ -264,7 +265,7 @@ pub trait AsicOps {
264265
/// the intermediate representation to the ASIC-specific format expected by the
265266
/// underlying hardware or emulator.
266267
pub trait TableOps<H: AsicOps> {
267-
fn new(hdl: &H, name: &str) -> AsicResult<Self>
268+
fn new(hdl: &H, type_: TableType) -> AsicResult<Self>
268269
where
269270
Self: Sized;
270271

asic/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tofino_asic = [
1313
tofino_stub = []
1414
softnpu = ["softnpu-lib", "dep:propolis"]
1515
chaos = []
16-
multicast = ["aal/multicast"]
16+
multicast = ["aal/multicast", "common/multicast"]
1717

1818
[lib]
1919
# The genpd.rs code generated by bindgen causes the doctest to fail

asic/src/chaos/mod.rs

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use aal::{
1818
SidecarIdentifiers,
1919
};
2020
use common::ports::{PortFec, PortId, PortMedia, PortPrbsMode, PortSpeed};
21+
use common::table::TableType;
2122

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

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

8687
impl TableChaos {
88+
fn add_tables(&mut self, ids: Vec<TableType>, prob: f64) {
89+
for id in ids {
90+
self.values.insert(id, prob);
91+
}
92+
}
93+
8794
/// Create a new chaos table with all known dendrite table identifiers,
8895
/// assigning each a uniform chaos value.
8996
pub fn uniform(v: f64) -> Self {
90-
table_chaos!(
91-
(table::ROUTE_IPV4, v),
92-
(table::ROUTE_IPV6, v),
93-
(table::ARP_IPV4, v),
94-
(table::NEIGHBOR_IPV6, v),
95-
(table::MAC_REWRITE, v),
96-
(table::SWITCH_IPV4_ADDR, v),
97-
(table::SWITCH_IPV6_ADDR, v),
98-
(table::NAT_INGRESS_IPV4, v),
99-
(table::NAT_INGRESS_IPV6, v),
100-
(table::MCAST_NAT_INGRESS_IPV4, v),
101-
(table::MCAST_NAT_INGRESS_IPV6, v),
102-
(table::MCAST_REPLICATION_IPV4, v),
103-
(table::MCAST_REPLICATION_IPV6, v),
104-
(table::MCAST_SRC_FILTER_IPV4, v),
105-
(table::MCAST_SRC_FILTER_IPV6, v),
106-
(table::MCAST_ROUTE_IPV4, v),
107-
(table::MCAST_ROUTE_IPV6, v),
108-
(table::MCAST_MAC_REWRITE, v),
109-
(table::MCAST_DECAP_PORTS, v),
110-
(table::MCAST_PORT_ID_MAPPING, v)
111-
)
97+
let mut tc = TableChaos { values: HashMap::new() };
98+
99+
tc.add_tables(
100+
vec![
101+
TableType::RouteIdxIpv4,
102+
TableType::RouteFwdIpv4,
103+
TableType::RouteIdxIpv6,
104+
TableType::RouteFwdIpv6,
105+
TableType::ArpIpv4,
106+
TableType::NeighborIpv6,
107+
TableType::PortMacAddress,
108+
TableType::PortAddrIpv4,
109+
TableType::PortAddrIpv6,
110+
TableType::NatIngressIpv4,
111+
TableType::NatIngressIpv6,
112+
TableType::UplinkIngress,
113+
TableType::UplinkEgress,
114+
TableType::AttachedSubnetIpv4,
115+
TableType::AttachedSubnetIpv6,
116+
],
117+
v,
118+
);
119+
#[cfg(feature = "multicast")]
120+
tc.add_tables(
121+
vec![
122+
TableType::RouteIpv4Mcast,
123+
TableType::RouteIpv6Mcast,
124+
TableType::McastIpv6,
125+
TableType::McastIpv4SrcFilter,
126+
TableType::McastIpv6SrcFilter,
127+
TableType::NatIngressIpv4Mcast,
128+
TableType::NatIngressIpv6Mcast,
129+
TableType::PortMacAddressMcast,
130+
TableType::McastEgressDecapPorts,
131+
TableType::McastEgressPortMapping,
132+
],
133+
v,
134+
);
135+
tc
112136
}
113137

114138
/// Return a chaos error according to the underlying probability value for
115139
/// the given table `id`.
116140
pub fn unfurled(
117141
&self,
118142
log: &Logger,
119-
id: &str,
143+
id: TableType,
120144
message: &str,
121145
) -> AsicResult<()> {
122-
if let Some(value) = self.values.get(id)
146+
if let Some(value) = self.values.get(&id)
123147
&& *value >= random()
124148
{
125149
slog::error!(log, "chaos table error: {}", message);

asic/src/chaos/table.rs

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,17 @@ use crate::chaos::{Handle, table_unfurl};
1414
use aal::{
1515
ActionParse, AsicError, AsicResult, CounterData, MatchParse, TableOps,
1616
};
17-
18-
// These names line up with the table names in the sidecar P4 program.
19-
pub const ROUTE_IPV4: &str = "pipe.Ingress.l3_router.routes_ipv4";
20-
pub const ROUTE_IPV6: &str = "pipe.Ingress.l3_router.routes_ipv6";
21-
pub const ARP_IPV4: &str = "pipe.Ingress.l3_router.arp_ipv4";
22-
pub const NEIGHBOR_IPV6: &str = "pipe.Ingress.l3_router.neighbor_ipv6";
23-
pub const MAC_REWRITE: &str = "pipe.Ingress.mac_rewrite.mac_rewrite";
24-
pub const SWITCH_IPV4_ADDR: &str = "pipe.Ingress.filter.switch_ipv4_addr";
25-
pub const SWITCH_IPV6_ADDR: &str = "pipe.Ingress.filter.switch_ipv6_addr";
26-
pub const NAT_INGRESS_IPV4: &str = "pipe.Ingress.nat_ingress.ingress_ipv4";
27-
pub const NAT_INGRESS_IPV6: &str = "pipe.Ingress.nat_ingress.ingress_ipv6";
28-
pub(crate) const MCAST_NAT_INGRESS_IPV4: &str =
29-
"pipe.Ingress.nat_ingress.ingress_ipv4_mcast";
30-
pub(crate) const MCAST_NAT_INGRESS_IPV6: &str =
31-
"pipe.Ingress.nat_ingress.ingress_ipv6_mcast";
32-
pub(crate) const MCAST_REPLICATION_IPV4: &str =
33-
"pipe.Ingress.mcast_ingress.mcast_replication_ipv4";
34-
pub(crate) const MCAST_REPLICATION_IPV6: &str =
35-
"pipe.Ingress.mcast_ingress.mcast_replication_ipv6";
36-
pub(crate) const MCAST_SRC_FILTER_IPV4: &str =
37-
"pipe.Ingress.mcast_ingress.mcast_source_filter_ipv4";
38-
pub(crate) const MCAST_SRC_FILTER_IPV6: &str =
39-
"pipe.Ingress.mcast_ingress.mcast_source_filter_ipv6";
40-
pub(crate) const MCAST_ROUTE_IPV4: &str =
41-
"pipe.Ingress.l3_router.MulticastRouter4.tbl";
42-
pub(crate) const MCAST_ROUTE_IPV6: &str =
43-
"pipe.Ingress.l3_router.MulticastRouter6.tbl";
44-
pub(crate) const MCAST_MAC_REWRITE: &str =
45-
"pipe.Egress.mac_rewrite.mac_rewrite";
46-
pub(crate) const MCAST_DECAP_PORTS: &str =
47-
"pipe.Egress.mcast_egress.tbl_decap_ports";
48-
pub(crate) const MCAST_PORT_ID_MAPPING: &str =
49-
"pipe.Egress.mcast_egress.asic_id_to_port";
17+
use common::table::TableType;
5018

5119
pub struct Table {
52-
name: String,
20+
type_: TableType,
5321
keys: Mutex<HashSet<u64>>,
5422
}
5523

5624
impl TableOps<Handle> for Table {
57-
fn new(hdl: &Handle, name: &str) -> AsicResult<Table> {
58-
table_unfurl!(hdl, name, table_new);
59-
Ok(Table { name: name.into(), keys: Mutex::new(HashSet::new()) })
25+
fn new(hdl: &Handle, type_: TableType) -> AsicResult<Table> {
26+
table_unfurl!(hdl, type_, table_new);
27+
Ok(Table { type_, keys: Mutex::new(HashSet::new()) })
6028
}
6129

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

7139
fn clear(&self, hdl: &Handle) -> AsicResult<()> {
72-
table_unfurl!(hdl, &self.name, table_clear);
40+
table_unfurl!(hdl, self.type_, table_clear);
7341
let mut keys = self.keys.lock().unwrap();
7442
*keys = HashSet::new();
7543
Ok(())
@@ -89,7 +57,7 @@ impl TableOps<Handle> for Table {
8957
if keys.contains(&x) {
9058
return Err(AsicError::Exists);
9159
}
92-
table_unfurl!(hdl, &self.name, table_entry_add);
60+
table_unfurl!(hdl, self.type_, table_entry_add);
9361
keys.insert(x);
9462
Ok(())
9563
}
@@ -110,7 +78,7 @@ impl TableOps<Handle> for Table {
11078
"table entry not found".to_string(),
11179
));
11280
}
113-
table_unfurl!(hdl, &self.name, table_entry_update);
81+
table_unfurl!(hdl, self.type_, table_entry_update);
11482
Ok(())
11583
}
11684

@@ -129,7 +97,7 @@ impl TableOps<Handle> for Table {
12997
"table entry not found".to_string(),
13098
));
13199
}
132-
table_unfurl!(hdl, &self.name, table_entry_del);
100+
table_unfurl!(hdl, self.type_, table_entry_del);
133101
keys.remove(&x);
134102
Ok(())
135103
}

0 commit comments

Comments
 (0)