Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Ze Gan <zegan@microsoft.com>
  • Loading branch information
Pterosaur committed Jun 4, 2024
1 parent 31acaec commit b7a3541
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
22 changes: 22 additions & 0 deletions dash-pipeline/SAI/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,25 @@ int dash::utils::leadingNonZeroBits(const sai_ip6_t& ipv6)

return 0;
}


int dash::utils::getPrefixLength(const sai_ip_prefix_t &value)
{
switch(value.addr_family)
{
case SAI_IP_ADDR_FAMILY_IPV4:
// LPM entry match field prefix length calculation needs to be fixed to accomodate 128 bit size.
// So the 96 is added to the prefix length.
return leadingNonZeroBits(htonl(value.mask.ip4)) + 96;
case SAI_IP_ADDR_FAMILY_IPV6:
return leadingNonZeroBits(value.mask.ip6);
default:
assert(0 && "unrecognzed value.ipaddr.addr_family");
}
return 0;
}

int dash::utils::getPrefixLength(const sai_attribute_value_t &value)
{
return getPrefixLength(value.ipprefix);
}
23 changes: 3 additions & 20 deletions dash-pipeline/SAI/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,26 +238,9 @@ namespace dash

int leadingNonZeroBits(const sai_ip6_t& ipv6);

inline int getPrefixLength(const sai_ip_prefix_t &value)
{
switch(value.addr_family)
{
case SAI_IP_ADDR_FAMILY_IPV4:
// LPM entry match field prefix length calculation needs to be fixed to accomodate 128 bit size.
// So the 96 is added to the prefix length.
return leadingNonZeroBits(htonl(value.mask.ip4)) + 96;
case SAI_IP_ADDR_FAMILY_IPV6:
return leadingNonZeroBits(value.mask.ip6);
default:
assert(0 && "unrecognzed value.ipaddr.addr_family");
}
return 0;
}

inline int getPrefixLength(const sai_attribute_value_t &value)
{
return getPrefixLength(value.ipprefix);
}
int getPrefixLength(const sai_ip_prefix_t &value);

int getPrefixLength(const sai_attribute_value_t &value);

template<typename T>
void ipPrefixSetVal(const sai_attribute_value_t &value, T &t, int bits = -1)
Expand Down

0 comments on commit b7a3541

Please sign in to comment.