Skip to content

Commit

Permalink
Fixed u8/u16 and range Thrift conversions (opencomputeproject#188)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Kokhan <andriy.kokhan@gmail.com>
Signed-off-by: selldinesh <dinesh.sellappan@keysight.com>
  • Loading branch information
andriy-kokhan authored and selldinesh committed Oct 3, 2023
1 parent ea4fc3c commit fce3ed0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/sc-standalone-deb10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,10 @@ jobs:
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v test_l2_basic_dd.py
- name: Run thrift unit tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ut/test_vrf_ut.py ut/test_bridge_ut.py ut/test_acl_ut.py
- name: Run thrift unit tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k \
"(test_switch_ut and not sai_map_list_t and not sai_system_port_config_list_t) or (test_port_ut and not sai_map_list_t)"
- name: Run thrift sairedis tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "test_sairec"
- name: Run thrift API tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "api/test"
5 changes: 5 additions & 0 deletions .github/workflows/sc-standalone-deb11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,10 @@ jobs:
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v test_l2_basic_dd.py
- name: Run thrift unit tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ut/test_vrf_ut.py ut/test_bridge_ut.py ut/test_acl_ut.py
- name: Run thrift unit tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k \
"(test_switch_ut and not sai_map_list_t and not sai_system_port_config_list_t) or (test_port_ut and not sai_map_list_t)"
- name: Run thrift sairedis tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "test_sairec"
- name: Run thrift API tests
run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "api/test"
34 changes: 31 additions & 3 deletions common/sai_client/sai_thrift_client/sai_thrift_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ def convert_attribute_name_to_thrift(attr):
"""
return re.search('SAI_.*_ATTR_(.*)', attr).group(1).lower()

@staticmethod
def convert_u8_to_thrift(u8_str):
# Thrift does not support unsigned int notation.
# The values gt than 0x7F should be converted into the signed values.
value = int(u8_str, 0)
if value > 0x7F:
return -((~value & 0xFF) + 1)
return value

@staticmethod
def convert_u16_to_thrift(u16_str):
# Thrift does not support unsigned int notation.
# The values gt than 0x7FFF should be converted into the signed values.
value = int(u16_str, 0)
if value > 0x7FFF:
return -((~value & 0xFFFF) + 1)
return value

@staticmethod
def convert_value_to_thrift(value, attr_name=None, value_type=None):
"""
Expand All @@ -73,7 +91,13 @@ def convert_value_to_thrift(value, attr_name=None, value_type=None):
actual_value = getattr(sai_headers, value, None)
if actual_value != None:
return actual_value
return 0 if value == '' else int(value, 0)
if value == '':
return 0
if value_type == 'u8':
return ThriftConverter.convert_u8_to_thrift(value)
elif value_type == 'u16':
return ThriftConverter.convert_u16_to_thrift(value)
return int(value, 0)
if value_type in [ 'booldata' ]:
return value.lower() == "true" or value == "0"
elif value_type in [ 'mac', 'ipv4', 'ipv6', 'chardata' ]:
Expand Down Expand Up @@ -163,7 +187,7 @@ def sai_int_range(value_type, range):
"""
splitted = range.split(',')
sai_thrift_class = getattr(ttypes, 'sai_thrift_{}_range_t'.format(value_type[:-5]))
return sai_thrift_class(min=splitted[0], max=splitted[1])
return sai_thrift_class(min=int(splitted[0]), max=int(splitted[1]))

@staticmethod
def sai_qos_map_params(value):
Expand Down Expand Up @@ -373,11 +397,15 @@ def convert_value_from_thrift(value, attr_name, obj_type=None):
sai_thrift_ip_address_t('192.168.0.1'...), "ipaddr" => "192.168.0.1"
"""
value_type = ThriftConverter.get_attribute_type(attr_name)
if value_type in [ 's8', 'u8', 's16', 'u16',
if value_type in [ 's8', 's16',
'u32', 's64', 'u64',
'ptr', 'mac', 'ipv4', 'ipv6',
'chardata' ]:
return str(value)
elif value_type == 'u8':
return str(value) if value > 0 else str(value & 0xFF)
elif value_type == 'u16':
return str(value) if value > 0 else str(value & 0xFFFF)
elif value_type in [ 's32' ]:
actual_value = ThriftConverter.get_str_by_enum(obj_type, attr_name, value)
if actual_value != None:
Expand Down

0 comments on commit fce3ed0

Please sign in to comment.