Skip to content

Commit

Permalink
[sai-gen] Add range match type support in SAI generation script. (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f authored Dec 14, 2023
1 parent 252c898 commit 1cff93f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class SAITypeSolver:
"sai_u16_list_t": SAITypeInfo("sai_u16_list_t", "u16list"),
"sai_u32_list_t": SAITypeInfo("sai_u32_list_t", "u32list"),
"sai_ip_prefix_list_t": SAITypeInfo("sai_ip_prefix_list_t", "ipprefixlist"),
"sai_u32_range_t": SAITypeInfo("sai_u32_range_t", "u32range"),
"sai_u8_range_list_t": SAITypeInfo("sai_u8_range_list_t", "u8rangelist"),
"sai_u16_range_list_t": SAITypeInfo("sai_u16_range_list_t", "u16rangelist"),
"sai_u32_range_list_t": SAITypeInfo("sai_u32_range_list_t", "u32rangelist"),
Expand Down Expand Up @@ -153,6 +154,8 @@ def get_match_key_sai_type(match_type, key_size):
return SAITypeSolver.__get_lpm_match_key_sai_type(key_size)
elif match_type == 'list':
return SAITypeSolver.__get_list_match_key_sai_type(key_size)
elif match_type == 'range':
return SAITypeSolver.__get_range_sai_type(key_size)
elif match_type == 'range_list':
return SAITypeSolver.__get_range_list_sai_type(key_size)
else:
Expand Down Expand Up @@ -187,6 +190,19 @@ def __get_list_match_key_sai_type(key_size):

return SAITypeSolver.get_sai_type(sai_type_name)

@staticmethod
def __get_range_sai_type(key_size):
sai_type_name = ""

# In SAI, all ranges that having smaller size than 32-bits are passed as 32-bits, such as port ranges and etc.
# So, we convert all ranges that is smaller than 32-bits to sai_u32_range_t by default.
if key_size <= 32:
sai_type_name = 'sai_u32_range_t'
else:
raise ValueError(f'key_size={key_size} is not supported')

return SAITypeSolver.get_sai_type(sai_type_name)

@staticmethod
def __get_range_list_sai_type(key_size):
sai_type_name = ""
Expand Down Expand Up @@ -970,4 +986,4 @@ def __get_uniq_sai_api(self, sai_api):
print(json.dumps(dash_sai_exts, indent=2))

# Generate and update all SAI files
SAIGenerator(dash_sai_exts).generate()
SAIGenerator(dash_sai_exts).generate()

0 comments on commit 1cff93f

Please sign in to comment.