Skip to content

Commit

Permalink
Convert the tx/rx power unit to the dBm unit (#377)
Browse files Browse the repository at this point in the history
* JIRA-SONIC-7072: Convert the tx/rx power unit to the dBm unit in get_transceiver_bulk_status().

The tx/rx power unit in the eeprom is mW, and the tx/rx power unit for the API is dBm.
It should be converted to the dBm in get_transceiver_bulk_status().

Signed-off-by: chiourung_huang <[email protected]>


---------

Signed-off-by: chiourung_huang <[email protected]>
Co-authored-by: Prince George <[email protected]>
  • Loading branch information
2 people authored and StormLiangMS committed Sep 3, 2023
1 parent 5af6f9f commit 384177c
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 6 deletions.
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_xcvr/api/public/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def get_transceiver_bulk_status(self):

for i in range(1, self.NUM_CHANNELS + 1):
bulk_status["tx%dbias" % i] = tx_bias[i - 1]
bulk_status["rx%dpower" % i] = rx_power[i - 1]
bulk_status["tx%dpower" % i] = tx_power[i - 1]
bulk_status["rx%dpower" % i] = self.mw_to_dbm(rx_power[i - 1]) if rx_power[i - 1] != 'N/A' else 'N/A'
bulk_status["tx%dpower" % i] = self.mw_to_dbm(tx_power[i - 1]) if tx_power[i - 1] != 'N/A' else 'N/A'

return bulk_status

Expand Down
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_xcvr/api/public/sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def get_transceiver_bulk_status(self):

for i in range(1, self.NUM_CHANNELS + 1):
bulk_status["tx%dbias" % i] = tx_bias[i - 1]
bulk_status["rx%dpower" % i] = rx_power[i - 1]
bulk_status["tx%dpower" % i] = tx_power[i - 1]
bulk_status["rx%dpower" % i] = self.mw_to_dbm(rx_power[i - 1]) if rx_power[i - 1] != 'N/A' else 'N/A'
bulk_status["tx%dpower" % i] = self.mw_to_dbm(tx_power[i - 1]) if tx_power[i - 1] != 'N/A' else 'N/A'

# Added to avoid failing xcvrd. Ideally xcvrd should be fixed so that this is not necessary
for i in range(2, 5):
Expand Down
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_xcvr/api/public/sff8636.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def get_transceiver_bulk_status(self):

for i in range(1, self.NUM_CHANNELS + 1):
bulk_status["tx%dbias" % i] = tx_bias[i - 1]
bulk_status["rx%dpower" % i] = rx_power[i - 1]
bulk_status["tx%dpower" % i] = tx_power[i - 1]
bulk_status["rx%dpower" % i] = self.mw_to_dbm(rx_power[i - 1]) if rx_power[i - 1] != 'N/A' else 'N/A'
bulk_status["tx%dpower" % i] = self.mw_to_dbm(tx_power[i - 1]) if tx_power[i - 1] != 'N/A' else 'N/A'

return bulk_status

Expand Down
47 changes: 47 additions & 0 deletions tests/sonic_xcvr/test_sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,50 @@ def test_get_transceiver_status(self, mock_response, expected):
self.api.get_tx_disable.return_value = mock_response[3]
result = self.api.get_transceiver_status()
assert result == expected

@pytest.mark.parametrize("mock_response, expected",[
(
[
50,
3.3,
[70, 70, 70, 70],
[0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1],
True, True, True, True, True, True
],
{
'temperature': 50,
'voltage': 3.3,
'tx1power': -10.0, 'tx2power': -10.0, 'tx3power': -10.0, 'tx4power': -10.0,
'rx1power': -10.0, 'rx2power': -10.0, 'rx3power': -10.0, 'rx4power': -10.0,
'tx1bias': 70, 'tx2bias': 70, 'tx3bias': 70, 'tx4bias': 70,
}
)
])
def test_get_transceiver_bulk_status(self, mock_response, expected):
self.api.get_module_temperature = MagicMock()
self.api.get_module_temperature.return_value = mock_response[0]
self.api.get_voltage = MagicMock()
self.api.get_voltage.return_value = mock_response[1]
self.api.get_tx_bias = MagicMock()
self.api.get_tx_bias.return_value = mock_response[2]
self.api.get_rx_power = MagicMock()
self.api.get_rx_power.return_value = mock_response[3]
self.api.get_tx_power = MagicMock()
self.api.get_tx_power.return_value = mock_response[4]
self.api.get_rx_los_support = MagicMock()
self.api.get_rx_los_support.return_value = mock_response[5]
self.api.get_tx_fault_support = MagicMock()
self.api.get_tx_fault_support.return_value = mock_response[6]
self.api.get_tx_disable_support = MagicMock()
self.api.get_tx_disable_support.return_value = mock_response[7]
self.api.get_tx_bias_support = MagicMock()
self.api.get_tx_bias_support.return_value = mock_response[8]
self.api.get_tx_power_support = MagicMock()
self.api.get_tx_power_support.return_value = mock_response[9]
self.api.get_rx_power_support = MagicMock()
self.api.get_rx_power_support.return_value = mock_response[10]
result = self.api.get_transceiver_bulk_status()
assert result == expected


46 changes: 46 additions & 0 deletions tests/sonic_xcvr/test_sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,49 @@ def test_get_transceiver_status(self, mock_response, expected):
self.api.get_tx_disable.return_value = mock_response[3]
result = self.api.get_transceiver_status()
assert result == expected

@pytest.mark.parametrize("mock_response, expected",[
(
[
50,
3.3,
[70],
[0.1],
[0.1],
True, True, True, True, True, True
],
{
'temperature': 50,
'voltage': 3.3,
'tx1power': -10.0, 'tx2power': 'N/A', 'tx3power': 'N/A', 'tx4power': 'N/A',
'rx1power': -10.0, 'rx2power': 'N/A', 'rx3power': 'N/A', 'rx4power': 'N/A',
'tx1bias': 70, 'tx2bias': 'N/A', 'tx3bias': 'N/A', 'tx4bias': 'N/A',
}
)
])
def test_get_transceiver_bulk_status(self, mock_response, expected):
self.api.get_module_temperature = MagicMock()
self.api.get_module_temperature.return_value = mock_response[0]
self.api.get_voltage = MagicMock()
self.api.get_voltage.return_value = mock_response[1]
self.api.get_tx_bias = MagicMock()
self.api.get_tx_bias.return_value = mock_response[2]
self.api.get_rx_power = MagicMock()
self.api.get_rx_power.return_value = mock_response[3]
self.api.get_tx_power = MagicMock()
self.api.get_tx_power.return_value = mock_response[4]
self.api.get_rx_los_support = MagicMock()
self.api.get_rx_los_support.return_value = mock_response[5]
self.api.get_tx_fault_support = MagicMock()
self.api.get_tx_fault_support.return_value = mock_response[6]
self.api.get_tx_disable_support = MagicMock()
self.api.get_tx_disable_support.return_value = mock_response[7]
self.api.get_tx_bias_support = MagicMock()
self.api.get_tx_bias_support.return_value = mock_response[8]
self.api.get_tx_power_support = MagicMock()
self.api.get_tx_power_support.return_value = mock_response[9]
self.api.get_rx_power_support = MagicMock()
self.api.get_rx_power_support.return_value = mock_response[10]
result = self.api.get_transceiver_bulk_status()
assert result == expected

46 changes: 46 additions & 0 deletions tests/sonic_xcvr/test_sff8636.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,49 @@ def test_get_transceiver_status(self, mock_response, expected):
self.api.get_tx_disable.return_value = mock_response[3]
result = self.api.get_transceiver_status()
assert result == expected

@pytest.mark.parametrize("mock_response, expected",[
(
[
50,
3.3,
[70, 70, 70, 70],
[0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1],
True, True, True, True, True, True
],
{
'temperature': 50,
'voltage': 3.3,
'tx1power': -10.0, 'tx2power': -10.0, 'tx3power': -10.0, 'tx4power': -10.0,
'rx1power': -10.0, 'rx2power': -10.0, 'rx3power': -10.0, 'rx4power': -10.0,
'tx1bias': 70, 'tx2bias': 70, 'tx3bias': 70, 'tx4bias': 70,
}
)
])
def test_get_transceiver_bulk_status(self, mock_response, expected):
self.api.get_module_temperature = MagicMock()
self.api.get_module_temperature.return_value = mock_response[0]
self.api.get_voltage = MagicMock()
self.api.get_voltage.return_value = mock_response[1]
self.api.get_tx_bias = MagicMock()
self.api.get_tx_bias.return_value = mock_response[2]
self.api.get_rx_power = MagicMock()
self.api.get_rx_power.return_value = mock_response[3]
self.api.get_tx_power = MagicMock()
self.api.get_tx_power.return_value = mock_response[4]
self.api.get_rx_los_support = MagicMock()
self.api.get_rx_los_support.return_value = mock_response[5]
self.api.get_tx_fault_support = MagicMock()
self.api.get_tx_fault_support.return_value = mock_response[6]
self.api.get_tx_disable_support = MagicMock()
self.api.get_tx_disable_support.return_value = mock_response[7]
self.api.get_tx_bias_support = MagicMock()
self.api.get_tx_bias_support.return_value = mock_response[8]
self.api.get_tx_power_support = MagicMock()
self.api.get_tx_power_support.return_value = mock_response[9]
self.api.get_rx_power_support = MagicMock()
self.api.get_rx_power_support.return_value = mock_response[10]
result = self.api.get_transceiver_bulk_status()
assert result == expected

0 comments on commit 384177c

Please sign in to comment.