Skip to content

Commit 71a9ee5

Browse files
[bluefield] Add platform-api implementation. (#27)
Signed-off-by: Oleksandr Ivantsiv <[email protected]>
1 parent 15553ab commit 71a9ee5

File tree

23 files changed

+1244
-2
lines changed

23 files changed

+1244
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"chassis": {
3+
"name": "Nvidia-MBF2H536C",
4+
"components": [],
5+
"fans": [],
6+
"fan_drawers": [],
7+
"psus": [],
8+
"thermals": [],
9+
"sfps": [
10+
{
11+
"name": "p0"
12+
},
13+
{
14+
"name": "p1"
15+
}
16+
]
17+
},
18+
"interfaces": {
19+
"Ethernet0": {
20+
"index": "1,1,1,1",
21+
"lanes": "0,1,2,3",
22+
"breakout_modes": {
23+
"1x100G": ["etp1"]
24+
}
25+
},
26+
"Ethernet4": {
27+
"index": "2,2,2,2",
28+
"lanes": "4,5,6,7",
29+
"breakout_modes": {
30+
"1x100G": ["etp2"]
31+
}
32+
}
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"chassis": {
3+
"name": "Nvidia-MBF2H516A",
4+
"components": [],
5+
"fans": [],
6+
"fan_drawers": [],
7+
"psus": [],
8+
"thermals": [],
9+
"sfps": [
10+
{
11+
"name": "p0"
12+
},
13+
{
14+
"name": "p1"
15+
}
16+
]
17+
},
18+
"interfaces": {
19+
"Ethernet0": {
20+
"index": "1,1,1,1",
21+
"lanes": "0,1,2,3",
22+
"breakout_modes": {
23+
"1x100G": ["etp1"]
24+
}
25+
},
26+
"Ethernet4": {
27+
"index": "2,2,2,2",
28+
"lanes": "4,5,6,7",
29+
"breakout_modes": {
30+
"1x100G": ["etp2"]
31+
}
32+
}
33+
}
34+
}

files/build_templates/sonic_debian_extension.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,13 @@ sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $MLNX_
846846
sudo rm -rf $FILESYSTEM_ROOT/$MLNX_SONIC_PLATFORM_PY3_WHEEL_NAME
847847
{% endif %}
848848

849+
{% if sonic_asic_platform == "nvidia-bluefield" %}
850+
SONIC_PLATFORM_PY3_WHEEL_NAME=$(basename {{platform_api_py3_wheel_path}})
851+
sudo cp {{platform_api_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PLATFORM_PY3_WHEEL_NAME
852+
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_PLATFORM_PY3_WHEEL_NAME
853+
sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PLATFORM_PY3_WHEEL_NAME
854+
{% endif %}
855+
849856
{%- if SONIC_ROUTING_STACK == "frr" %}
850857
sudo mkdir $FILESYSTEM_ROOT/etc/sonic/frr
851858
sudo touch $FILESYSTEM_ROOT/etc/sonic/frr/frr.conf
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.pyc
2+
.cache/
3+
*/test-results.xml
4+
*/htmlcov/
5+
*/coverage.xml
6+
*/.coverage
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
##
2+
## Copyright (c) 2020-2022 NVIDIA CORPORATION & AFFILIATES.
3+
## Apache-2.0
4+
##
5+
## Licensed under the Apache License, Version 2.0 (the "License");
6+
## you may not use this file except in compliance with the License.
7+
## You may obtain a copy of the License at
8+
##
9+
## http://www.apache.org/licenses/LICENSE-2.0
10+
##
11+
## Unless required by applicable law or agreed to in writing, software
12+
## distributed under the License is distributed on an "AS IS" BASIS,
13+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
## See the License for the specific language governing permissions and
15+
## limitations under the License.
16+
##
17+
[pytest]
18+
addopts = --cov=sonic_platform --cov-report html --cov-report term --cov-report xml --junitxml=test-results.xml -vv
19+
filterwarnings =
20+
ignore::DeprecationWarning
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[aliases]
2+
test=pytest
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Copyright (c) 2019-2022 NVIDIA CORPORATION & AFFILIATES.
3+
# Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
from setuptools import setup
18+
19+
setup(
20+
name='platform-api',
21+
version='1.0',
22+
description='SONiC platform API implementation on NVIDIA BlueField platform',
23+
license='Apache 2.0',
24+
author='NVIDIA SONiC Team',
25+
author_email='[email protected]',
26+
url='https://github.com/Azure/sonic-buildimage',
27+
maintainer='Oleksandr Ivantsiv',
28+
maintainer_email='[email protected]',
29+
packages=[
30+
'sonic_platform',
31+
'tests'
32+
],
33+
setup_requires= [
34+
'pytest-runner'
35+
],
36+
tests_require = [
37+
'pytest',
38+
'mock>=2.0.0'
39+
],
40+
classifiers=[
41+
'Development Status :: 3 - Alpha',
42+
'Environment :: Plugins',
43+
'Intended Audience :: Developers',
44+
'Intended Audience :: Information Technology',
45+
'Intended Audience :: System Administrators',
46+
'License :: OSI Approved :: Apache Software License',
47+
'Natural Language :: English',
48+
'Operating System :: POSIX :: Linux',
49+
'Programming Language :: Python :: 3.7',
50+
'Topic :: Utilities',
51+
],
52+
keywords='sonic SONiC platform PLATFORM',
53+
test_suite='setup.get_test_suite'
54+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
3+
# Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
__all__ = ["platform", "chassis"]
18+
from sonic_platform import *
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#
2+
# Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
3+
# Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
try:
19+
from sonic_platform_base.chassis_base import ChassisBase
20+
from sonic_py_common.logger import Logger
21+
import os
22+
from functools import reduce
23+
24+
from . import utils
25+
from .device_data import DeviceDataManager
26+
from .sfp import Sfp
27+
from .eeprom import Eeprom
28+
except ImportError as e:
29+
raise ImportError(str(e) + "- required module not found")
30+
31+
MAX_SELECT_DELAY = 3600
32+
33+
34+
# Global logger class instance
35+
logger = Logger()
36+
37+
38+
class Chassis(ChassisBase):
39+
"""Platform-specific Chassis class"""
40+
41+
def __init__(self):
42+
super(Chassis, self).__init__()
43+
44+
# Initialize DMI data
45+
self.dmi_data = None
46+
47+
self.device_data = DeviceDataManager()
48+
self._initialize_sfp()
49+
self.sfp_event = None
50+
self._eeprom = Eeprom()
51+
logger.log_info("Chassis loaded successfully")
52+
53+
def _initialize_sfp(self):
54+
self._sfp_list = []
55+
56+
sfp_count = self.get_num_sfps()
57+
for index in range(sfp_count):
58+
sfp_module = Sfp(index, self.device_data.get_sfp_data(index))
59+
self._sfp_list.append(sfp_module)
60+
61+
def get_sfp(self, index):
62+
return super(Chassis, self).get_sfp(index - 1)
63+
64+
def get_num_sfps(self):
65+
"""
66+
Retrieves the number of sfps available on this chassis
67+
68+
Returns:
69+
An integer, the number of sfps available on this chassis
70+
"""
71+
return self.device_data.get_sfp_count()
72+
73+
def get_eeprom(self):
74+
"""
75+
Retreives eeprom device on this chassis
76+
77+
Returns:
78+
An object derived from WatchdogBase representing the hardware
79+
eeprom device
80+
"""
81+
return self._eeprom
82+
83+
def get_name(self):
84+
"""
85+
Retrieves the name of the device
86+
87+
Returns:
88+
string: The name of the device
89+
"""
90+
return self._eeprom.get_product_name()
91+
92+
def get_model(self):
93+
"""
94+
Retrieves the model number (or part number) of the device
95+
96+
Returns:
97+
string: Model/part number of device
98+
"""
99+
return self._eeprom.get_part_number()
100+
101+
def get_base_mac(self):
102+
"""
103+
Retrieves the base MAC address for the chassis
104+
105+
Returns:
106+
A string containing the MAC address in the format
107+
'XX:XX:XX:XX:XX:XX'
108+
"""
109+
return self._eeprom.get_base_mac()
110+
111+
def get_serial(self):
112+
"""
113+
Retrieves the hardware serial number for the chassis
114+
115+
Returns:
116+
A string containing the hardware serial number for this chassis.
117+
"""
118+
return self._eeprom.get_serial_number()
119+
120+
def get_system_eeprom_info(self):
121+
"""
122+
Retrieves the full content of system EEPROM information for the chassis
123+
124+
Returns:
125+
A dictionary where keys are the type code defined in
126+
OCP ONIE TlvInfo EEPROM format and values are their corresponding
127+
values.
128+
"""
129+
return self._eeprom.get_system_eeprom_info()
130+
131+
def get_revision(self):
132+
"""
133+
Retrieves the hardware revision of the device
134+
135+
Returns:
136+
string: Revision value of device
137+
"""
138+
return self._eeprom.get_revision()
139+
140+
def get_position_in_parent(self):
141+
"""
142+
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
143+
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
144+
Returns:
145+
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
146+
"""
147+
return -1
148+
149+
def is_replaceable(self):
150+
"""
151+
Indicate whether this device is replaceable.
152+
Returns:
153+
bool: True if it is replaceable.
154+
"""
155+
return False

0 commit comments

Comments
 (0)