Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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.

2 changes: 2 additions & 0 deletions aal/src/match_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ impl TryFrom<&ValueTypes> for u8 {
}
}

unwrap_value_entry!(u8);

impl From<u16> for ValueTypes {
fn from(v: u16) -> ValueTypes {
ValueTypes::U64(v as u64)
Expand Down
63 changes: 58 additions & 5 deletions asic/src/softnpu/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,16 @@ impl TableOps<Handle> for Table {
action_data.action.as_str(),
) {
// TODO: implement mappings for natv6 actions
(TableType::PortAddrIpv4, "claimv4") => ("local", Vec::new()),
(TableType::PortAddrIpv6, "claimv6") => ("local", Vec::new()),
// sidecar-lite's local action carries the routing table id;
// IPv4 switch addresses belong to the default table.
(TableType::PortAddrIpv4, "claimv4") => ("local", vec![0]),
(TableType::PortAddrIpv6, "claimv6") => {
let table_id = u8::try_from(
&action_data.arg_by_name("routing_table_id")?.value,
)
.map_err(|e| AsicError::InvalidArg(e.into()))?;
("local", vec![table_id])
}
(TableType::RouteIdxIpv4, "index") => {
let mut params = Vec::new();
for arg in action_data.args.iter() {
Expand Down Expand Up @@ -632,10 +640,10 @@ fn keyset_data(match_data: Vec<MatchEntryField>, table: TableType) -> Vec<u8> {
serialize_value_type(&x, &mut data);
keyset_data.extend_from_slice(&data[..2]);
}
TableType::RouteIdxIpv4 => {
// "idx" => exact => bit<16>
TableType::RouteIdxIpv4 | TableType::RouteIdxIpv6 => {
// "routing_table_id" => exact => bit<8>
serialize_value_type(&x, &mut data);
keyset_data.extend_from_slice(&data[..2]);
keyset_data.push(data[0]);
}
TableType::NatIngressIpv4 => {
// "dst_addr" => hdr.ipv4.dst: exact => bit<32>
Expand Down Expand Up @@ -725,3 +733,48 @@ fn serialize_value_type_be(x: &ValueTypes, data: &mut Vec<u8>) {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

fn route_key(
table_id: u8,
prefix: ValueTypes,
len: u16,
) -> Vec<MatchEntryField> {
vec![
MatchEntryField {
name: "routing_table_id".into(),
value: MatchEntryValue::Value(table_id.into()),
},
MatchEntryField {
name: "dst_addr".into(),
value: MatchEntryValue::Lpm(aal::MatchLpm { prefix, len }),
},
]
}

#[test]
fn route_index_serializes_composite_key() {
assert_eq!(
keyset_data(
route_key(2, ValueTypes::U64(0xc000_0200), 24),
TableType::RouteIdxIpv4,
),
[2, 192, 0, 2, 0, 24]
);

let prefix = 0x20010db8000000000000000000000000u128.to_be_bytes();
let mut expected = vec![3];
expected.extend_from_slice(&prefix);
expected.push(32);
assert_eq!(
keyset_data(
route_key(3, ValueTypes::Ptr(prefix.to_vec()), 32),
TableType::RouteIdxIpv6,
),
expected
);
}
}
1 change: 1 addition & 0 deletions dpd-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2024"
dpd-types-versions.workspace = true
dropshot.workspace = true
dropshot-api-manager-types.workspace = true
uuid.workspace = true
Loading
Loading