Skip to content

Commit

Permalink
[CMIS] Add an enable parameter to eliminate the need for loopback mod…
Browse files Browse the repository at this point in the history
…es with the -none suffix

Signed-off-by: xinyu <xinyu0123@gmail.com>
  • Loading branch information
xinyulin committed Sep 3, 2024
1 parent dd39936 commit 9faee1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
31 changes: 12 additions & 19 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,35 +1279,28 @@ def set_media_output_loopback(self, lane_mask, enable):
else:
return self.xcvr_eeprom.write(consts.MEDIA_OUTPUT_LOOPBACK, media_output_val & ~lane_mask)

def set_loopback_mode(self, loopback_mode, lane_mask = 0xff):
def set_loopback_mode(self, loopback_mode, lane_mask = 0xff, enable = False):
'''
This function sets the module loopback mode.
Args:
- loopback_mode (str): Specifies the loopback mode. It must be one of the following:
1. "none"
2. "host-side-input-none"
3. "host-side-output-none"
4. "media-side-input-none"
5. "media-side-output-none"
6. "host-side-input"
7. "host-side-output"
8. "media-side-input"
9. "media-side-output"
2. "host-side-input"
3. "host-side-output"
4. "media-side-input"
5. "media-side-output"
- lane_mask (int): A bitmask representing the lanes to which the loopback mode should
be applied. Default 0xFF applies to all lanes.
- enable (bool): Whether to enable or disable the loopback mode. Default False.
Returns:
- bool: True if the operation succeeds, False otherwise.
'''
loopback_functions = {
'host-side-input-none': (self.set_host_input_loopback, False),
'host-side-output-none': (self.set_host_output_loopback, False),
'media-side-input-none': (self.set_media_input_loopback, False),
'media-side-output-none': (self.set_media_output_loopback, False),
'host-side-input': (self.set_host_input_loopback, True),
'host-side-output': (self.set_host_output_loopback, True),
'media-side-input': (self.set_media_input_loopback, True),
'media-side-output': (self.set_media_output_loopback, True)
'host-side-input': self.set_host_input_loopback,
'host-side-output': self.set_host_output_loopback,
'media-side-input': self.set_media_input_loopback,
'media-side-output': self.set_media_output_loopback,
}

if loopback_mode == 'none':
Expand All @@ -1318,8 +1311,8 @@ def set_loopback_mode(self, loopback_mode, lane_mask = 0xff):
self.set_media_output_loopback(0xff, False)
])

if loopback_mode in loopback_functions:
func, enable = loopback_functions[loopback_mode]
func = loopback_functions.get(loopback_mode)
if func:
return func(lane_mask, enable)

logger.error('Invalid loopback mode:%s, lane_mask:%#x', loopback_mode, lane_mask)
Expand Down
18 changes: 9 additions & 9 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,15 +1206,15 @@ def test_set_media_output_loopback(self, input_param, mock_response, expected):

@pytest.mark.parametrize("input_param, mock_response, expected",[
(['none', 0], True, True),
(['host-side-input', 0x0F], True, True),
(['host-side-output', 0x0F], True, True),
(['media-side-input', 0x0F], True, True),
(['media-side-output', 0x0F], True, True),
(['host-side-input-none', 0xF0], True, True),
(['host-side-output-none', 0xF0], True, True),
(['media-side-input-none', 0xF0], True, True),
(['media-side-output-none', 0xF0], True, True),
(['', 0xF0], True, False),
(['host-side-input', 0x0F, True], True, True),
(['host-side-output', 0x0F, True], True, True),
(['media-side-input', 0x0F, True], True, True),
(['media-side-output', 0x0F, True], True, True),
(['host-side-input', 0xF0, False], True, True),
(['host-side-output', 0xF0, False], True, True),
(['media-side-input', 0xF0, False], True, True),
(['media-side-output', 0xF0, False], True, True),
(['', 0xF0, False], True, False),
])
def test_set_loopback_mode(self, input_param, mock_response, expected):
Expand Down

0 comments on commit 9faee1a

Please sign in to comment.