Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Ze Gan <[email protected]>
  • Loading branch information
Pterosaur committed Jun 3, 2024
1 parent 52c4dcf commit 999f4f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dash-pipeline/SAI/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ namespace dash

int leadingNonZeroBits(const sai_ip6_t& ipv6);

inline bool isIpv6Prefix(const sai_ip_prefix_t &value)
{
return value.addr_family == SAI_IP_ADDR_FAMILY_IPV6;
}

inline bool isIpv6Prefix(const sai_attribute_value_t &value)
{
return isIpv6Prefix(value.ipprefix);
}

template<typename T>
void ipPrefixSetVal(const sai_attribute_value_t &value, T &t, int bits = -1)
{
Expand Down
21 changes: 21 additions & 0 deletions dash-pipeline/SAI/templates/saiapi.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ static sai_status_t dash_sai_create_{{ table.name }}(
auto mf_exact = mf->mutable_exact();
{{key.field}}SetVal(attr_list[i].value, mf_exact, {{key.bitwidth}});
{% elif key.match_type == 'lpm' %}
{% if key.field == 'ipPrefix' %}
if (isIpv6Prefix(attr_list[i].value))
{
DASH_LOG_WARN("BMv2 doesn't support LPM IPv6 prefix action, So skip this action set");
return SAI_STATUS_SUCCESS;
}
{% endif %}
auto mf_lpm = mf->mutable_lpm();
{{key.field}}SetVal(attr_list[i].value, mf_lpm, {{key.bitwidth}});
{% elif key.match_type == 'list' %}
Expand Down Expand Up @@ -401,6 +408,13 @@ static sai_status_t dash_sai_create_{{ table.name }}(
{{key.field}}SetVal(static_cast<uint{{key.bitwidth}}_t>(tableEntry->{{ key.name | lower }}), mf_exact, {{key.bitwidth}});
{% endif %}
{% elif key.match_type == 'lpm' %}
{% if key.field == 'ipPrefix' %}
if (isIpv6Prefix(tableEntry->{{ key.name | lower }}))
{
DASH_LOG_WARN("BMv2 doesn't support LPM IPv6 prefix action, So skip this action set");
return SAI_STATUS_SUCCESS;
}
{% endif %}
auto mf_lpm = mf->mutable_lpm();
{{key.field}}SetVal(tableEntry->{{ key.name | lower }}, mf_lpm, {{key.bitwidth}});
{% elif key.match_type == 'ternary' %}
Expand Down Expand Up @@ -582,6 +596,13 @@ static sai_status_t dash_sai_remove_{{ table.name }}(
{% endif %}
//{{key.field}}SetVal(tableEntry->{{ key.name | lower }}, mf_exact, {{key.bitwidth}});
{% elif key.match_type == 'lpm' %}
{% if key.field == 'ipPrefix' %}
if (isIpv6Prefix(tableEntry->{{ key.name | lower }}))
{
DASH_LOG_WARN("BMv2 doesn't support LPM IPv6 prefix action, So skip this action set");
return SAI_STATUS_SUCCESS;
}
{% endif %}
auto mf_lpm = mf->mutable_lpm();
{{key.field}}SetVal(tableEntry->{{ key.name | lower }}, mf_lpm, {{key.bitwidth}});
{% elif key.match_type == 'ternary' %}
Expand Down

0 comments on commit 999f4f1

Please sign in to comment.